Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal')
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java198
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/DebugOptions.java37
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Discovery.java595
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointDescriptionBundleTrackerCustomizer.java194
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointDescriptionParser.java796
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointListenerTrackerCustomizer.java60
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/IDUtil.java109
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/LocatorServiceListener.java165
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/LogUtility.java95
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java266
10 files changed, 0 insertions, 2515 deletions
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java
deleted file mode 100644
index 45178c644..000000000
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Composent, Inc. - initial API and implementation
- ******************************************************************************/
-package org.eclipse.ecf.internal.osgi.services.remoteserviceadmin;
-
-import java.util.UUID;
-
-import javax.xml.parsers.SAXParserFactory;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.ecf.core.IContainerManager;
-import org.eclipse.ecf.core.util.LogHelper;
-import org.eclipse.ecf.core.util.SystemLogService;
-import org.eclipse.ecf.osgi.services.remoteserviceadmin.TopologyManager;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
-import org.osgi.util.tracker.ServiceTracker;
-
-public class Activator implements BundleActivator {
-
- public static final String PLUGIN_ID = "org.eclipse.ecf.osgi.services.remoteserviceadmin";
-
- private static BundleContext context;
- private static Activator instance;
-
- static BundleContext getContext() {
- return context;
- }
-
- public static Activator getDefault() {
- return instance;
- }
-
- private Discovery discovery;
- private TopologyManager topologyManager;
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
- * )
- */
- public void start(BundleContext bundleContext) throws Exception {
- Activator.context = bundleContext;
- Activator.instance = this;
- discovery = new Discovery(context);
- topologyManager = new TopologyManager(context, discovery);
- // start topology manager
- topologyManager.start();
- // start discovery
- discovery.start();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext bundleContext) throws Exception {
- if (discovery != null) {
- discovery.close();
- discovery = null;
- }
- if (topologyManager != null) {
- topologyManager.close();
- topologyManager = null;
- }
- stopSAXParserTracker();
- stopLogServiceTracker();
- stopContainerManagerTracker();
- Activator.context = null;
- Activator.instance = null;
- }
-
- public String getFrameworkUUID() {
- if (context == null)
- return null;
- // code get and set the framework uuid property as specified in
- // r2.enterprise.pdf pg 297
- synchronized ("org.osgi.framework.uuid") {
- String result = context.getProperty("org.osgi.framework.uuid");
- if (result == null) {
- UUID newUUID = UUID.randomUUID();
- result = newUUID.toString();
- System.setProperty("org.osgi.framework.uuid",
- newUUID.toString());
- }
- return result;
- }
- }
-
- // Sax parser
-
- private Object saxParserFactoryTrackerLock = new Object();
- private ServiceTracker saxParserFactoryTracker;
-
- public SAXParserFactory getSAXParserFactory() {
- if (instance == null)
- return null;
- synchronized (saxParserFactoryTrackerLock) {
- if (saxParserFactoryTracker == null) {
- saxParserFactoryTracker = new ServiceTracker(context,
- SAXParserFactory.class.getName(), null);
- saxParserFactoryTracker.open();
- }
- return (SAXParserFactory) saxParserFactoryTracker.getService();
- }
- }
-
- private void stopSAXParserTracker() {
- synchronized (saxParserFactoryTrackerLock) {
- if (saxParserFactoryTracker != null) {
- saxParserFactoryTracker.close();
- saxParserFactoryTracker = null;
- }
- }
- }
-
- // Logging
-
- private ServiceTracker logServiceTracker = null;
- private LogService logService = null;
- private Object logServiceTrackerLock = new Object();
-
- public LogService getLogService() {
- if (context == null)
- return null;
- synchronized (logServiceTrackerLock) {
- if (logServiceTracker == null) {
- logServiceTracker = new ServiceTracker(context,
- LogService.class.getName(), null);
- logServiceTracker.open();
- }
- logService = (LogService) logServiceTracker.getService();
- if (logService == null)
- logService = new SystemLogService(PLUGIN_ID);
- return logService;
- }
- }
-
- public void log(IStatus status) {
- if (logService == null)
- logService = getLogService();
- if (logService != null)
- logService.log(null, LogHelper.getLogCode(status),
- LogHelper.getLogMessage(status), status.getException());
- }
-
- public void log(ServiceReference sr, IStatus status) {
- log(sr, LogHelper.getLogCode(status), LogHelper.getLogMessage(status),
- status.getException());
- }
-
- public void log(ServiceReference sr, int level, String message, Throwable t) {
- if (logService == null)
- logService = getLogService();
- if (logService != null)
- logService.log(sr, level, message, t);
- }
-
- private void stopLogServiceTracker() {
- synchronized (logServiceTrackerLock) {
- if (logServiceTracker != null) {
- logServiceTracker.close();
- logServiceTracker = null;
- logService = null;
- }
- }
- }
-
- private ServiceTracker containerManagerTracker;
-
- public IContainerManager getContainerManager() {
- if (containerManagerTracker == null) {
- containerManagerTracker = new ServiceTracker(context,
- IContainerManager.class.getName(), null);
- containerManagerTracker.open();
- }
- return (IContainerManager) containerManagerTracker.getService();
- }
-
- private void stopContainerManagerTracker() {
- if (containerManagerTracker != null) {
- containerManagerTracker.close();
- containerManagerTracker = null;
- }
- }
-}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/DebugOptions.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/DebugOptions.java
deleted file mode 100644
index 906bd1da7..000000000
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/DebugOptions.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Composent, Inc. - initial API and implementation
- ******************************************************************************/
-package org.eclipse.ecf.internal.osgi.services.remoteserviceadmin;
-
-public interface DebugOptions {
-
- public static final String DEBUG = Activator.PLUGIN_ID + "/debug"; //$NON-NLS-1$
-
- public static final String EXCEPTIONS_CATCHING = DEBUG
- + "/exceptions/catching"; //$NON-NLS-1$
-
- public static final String EXCEPTIONS_THROWING = DEBUG
- + "/exceptions/throwing"; //$NON-NLS-1$
-
- public static final String METHODS_ENTERING = DEBUG + "/methods/entering"; //$NON-NLS-1$
-
- public static final String METHODS_EXITING = DEBUG + "/methods/exiting"; //$NON-NLS-1$
-
- public static final String REMOTE_SERVICE_ADMIN = DEBUG
- + "/remoteserviceadmin"; //$NON-NLS-1$
-
- public static final String TOPOLOGY_MANAGER = DEBUG + "/topologymanager"; //$NON-NLS-1$
-
- public static final String CONTAINERSELECTOR = DEBUG + "/containerselector"; //$NON-NLS-1$
-
- public static final String DISCOVERY = DEBUG + "/discovery"; //$NON-NLS-1$
-
- public static final String ENDPOINTDESCRIPTIONREADER = "/endpointdescriptionreader";
-
-}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Discovery.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Discovery.java
deleted file mode 100644
index 37c5018a3..000000000
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Discovery.java
+++ /dev/null
@@ -1,595 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Composent, Inc. - initial API and implementation
- ******************************************************************************/
-package org.eclipse.ecf.internal.osgi.services.remoteserviceadmin;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
-import org.eclipse.ecf.discovery.IDiscoveryLocator;
-import org.eclipse.ecf.discovery.IServiceInfo;
-import org.eclipse.ecf.osgi.services.remoteserviceadmin.DiscoveredEndpointDescriptionFactory;
-import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionReader;
-import org.eclipse.ecf.osgi.services.remoteserviceadmin.IDiscoveredEndpointDescriptionFactory;
-import org.eclipse.ecf.osgi.services.remoteserviceadmin.IEndpointDescriptionReader;
-import org.eclipse.ecf.osgi.services.remoteserviceadmin.IServiceInfoFactory;
-import org.eclipse.ecf.osgi.services.remoteserviceadmin.ServiceInfoFactory;
-import org.eclipse.equinox.concurrent.future.IExecutor;
-import org.eclipse.equinox.concurrent.future.IProgressRunnable;
-import org.eclipse.equinox.concurrent.future.ThreadsExecutor;
-import org.eclipse.osgi.framework.eventmgr.CopyOnWriteIdentityMap;
-import org.eclipse.osgi.framework.eventmgr.EventDispatcher;
-import org.eclipse.osgi.framework.eventmgr.EventManager;
-import org.eclipse.osgi.framework.eventmgr.ListenerQueue;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.remoteserviceadmin.EndpointDescription;
-import org.osgi.service.remoteserviceadmin.EndpointListener;
-import org.osgi.util.tracker.BundleTracker;
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
-
-public class Discovery {
-
- private BundleContext context;
- private IExecutor executor;
-
- // service info factory default
- private ServiceInfoFactory serviceInfoFactory;
- private ServiceRegistration defaultServiceInfoFactoryRegistration;
- // service info factory service tracker
- private Object serviceInfoFactoryTrackerLock = new Object();
- private ServiceTracker serviceInfoFactoryTracker;
-
- // endpoint description factory default
- private DiscoveredEndpointDescriptionFactory defaultEndpointDescriptionFactory;
- private ServiceRegistration defaultEndpointDescriptionFactoryRegistration;
- // endpoint description factory tracker
- private Object endpointDescriptionFactoryTrackerLock = new Object();
- private ServiceTracker endpointDescriptionFactoryTracker;
- // endpointDescriptionReader default
- private ServiceRegistration defaultEndpointDescriptionReaderRegistration;
-
- // For processing synchronous notifications asynchronously
- private EventManager eventManager;
- private ListenerQueue eventQueue;
- private LocatorServiceListener localLocatorServiceListener;
-
- // ECF IDiscoveryLocator tracker
- private ServiceTracker locatorServiceTracker;
- // Locator listeners
- private Map<IDiscoveryLocator, LocatorServiceListener> locatorListeners;
-
- private EndpointListenerTrackerCustomizer endpointListenerTrackerCustomizer;
- private ServiceTracker endpointListenerTracker;
-
- private ServiceTracker advertiserTracker;
- private Object advertiserTrackerLock = new Object();
-
- private BundleTracker bundleTracker;
- private EndpointDescriptionBundleTrackerCustomizer bundleTrackerCustomizer;
-
- public Discovery(BundleContext context) {
- this.context = context;
- this.executor = new ThreadsExecutor();
- }
-
- public void start() {
- // For service info and endpoint description factories
- // set the service ranking to Integer.MIN_VALUE
- // so that any other registered factories will be preferred
- final Properties properties = new Properties();
- properties.put(Constants.SERVICE_RANKING,
- new Integer(Integer.MIN_VALUE));
- serviceInfoFactory = new ServiceInfoFactory();
- defaultServiceInfoFactoryRegistration = context.registerService(
- IServiceInfoFactory.class.getName(), serviceInfoFactory,
- (Dictionary) properties);
- defaultEndpointDescriptionFactory = new DiscoveredEndpointDescriptionFactory();
- defaultEndpointDescriptionFactoryRegistration = context
- .registerService(
- IDiscoveredEndpointDescriptionFactory.class.getName(),
- defaultEndpointDescriptionFactory,
- (Dictionary) properties);
- // setup/register default endpointDescriptionReader
- defaultEndpointDescriptionReaderRegistration = context.registerService(
- IEndpointDescriptionReader.class.getName(),
- new EndpointDescriptionReader(), properties);
-
- // Create thread group, event manager, and eventQueue, and setup to
- // dispatch EndpointListenerEvents
- ThreadGroup eventGroup = new ThreadGroup(
- "EventAdmin Discovery EndpointListener Dispatcher"); //$NON-NLS-1$
- eventGroup.setDaemon(true);
- eventManager = new EventManager(
- "EventAdmin EndpointListener Dispatcher", eventGroup); //$NON-NLS-1$
- eventQueue = new ListenerQueue(eventManager);
- CopyOnWriteIdentityMap listeners = new CopyOnWriteIdentityMap();
- listeners.put(this, this);
- eventQueue.queueListeners(listeners.entrySet(), new EventDispatcher() {
- public void dispatchEvent(Object eventListener,
- Object listenerObject, int eventAction, Object eventObject) {
- final String logMethodName = "dispatchEvent";
- final EndpointListenerEvent event = (EndpointListenerEvent) eventObject;
- final EndpointListener endpointListener = event
- .getEndpointListener();
- final EndpointDescription endpointDescription = event
- .getEndointDescription();
- final String matchingFilter = event.getMatchingFilter();
-
- try {
- if (event.isDiscovered())
- endpointListener.endpointAdded(endpointDescription,
- matchingFilter);
- else
- endpointListener.endpointRemoved(endpointDescription,
- matchingFilter);
- } catch (Exception e) {
- String message = "Exception in EndpointListener listener="
- + endpointListener + " description="
- + endpointDescription + " matchingFilter="
- + matchingFilter;
- logError(logMethodName, message, e);
- } catch (LinkageError e) {
- String message = "LinkageError in EndpointListener listener="
- + endpointListener
- + " description="
- + endpointDescription
- + " matchingFilter="
- + matchingFilter;
- logError(logMethodName, message, e);
- } catch (AssertionError e) {
- String message = "AssertionError in EndpointListener listener="
- + endpointListener
- + " description="
- + endpointDescription
- + " matchingFilter="
- + matchingFilter;
- logError(logMethodName, message, e);
- }
- }
- });
- // Register the endpoint listener tracker, so that endpoint listeners
- // that are subsequently added
- // will then be notified of discovered endpoints
- endpointListenerTrackerCustomizer = new EndpointListenerTrackerCustomizer(
- this);
- endpointListenerTracker = new ServiceTracker(context,
- EndpointListener.class.getName(),
- endpointListenerTrackerCustomizer);
- endpointListenerTracker.open();
-
- locatorListeners = new HashMap();
- localLocatorServiceListener = new LocatorServiceListener(this);
- // Create locator service tracker, so new IDiscoveryLocators can
- // be used to discover endpoint descriptions
- locatorServiceTracker = new ServiceTracker(context,
- IDiscoveryLocator.class.getName(),
- new LocatorTrackerCustomizer());
- locatorServiceTracker.open();
- // Get any existing locators
- Object[] locators = locatorServiceTracker.getServices();
- if (locators != null) {
- // for all of them
- for (int i = 0; i < locators.length; i++) {
- // Add service listener to locator
- openLocator((IDiscoveryLocator) locators[i]);
- }
- }
- // Create bundle tracker for reading local/xml-file endpoint
- // descriptions
- bundleTrackerCustomizer = new EndpointDescriptionBundleTrackerCustomizer(
- context, localLocatorServiceListener);
- bundleTracker = new BundleTracker(context, Bundle.ACTIVE
- | Bundle.STARTING, bundleTrackerCustomizer);
- // This may trigger local endpoint description discovery
- bundleTracker.open();
- }
-
- private void logError(String methodName, String message, Throwable e) {
- LogUtility.logError(methodName, DebugOptions.DISCOVERY,
- this.getClass(), message, e);
- }
-
- public void close() {
- if (bundleTracker != null) {
- bundleTracker.close();
- bundleTracker = null;
- }
- if (bundleTrackerCustomizer != null) {
- bundleTrackerCustomizer.close();
- bundleTrackerCustomizer = null;
- }
-
- // shutdown locatorListeners
- synchronized (locatorListeners) {
- for (IDiscoveryLocator l : locatorListeners.keySet()) {
- LocatorServiceListener locatorListener = locatorListeners
- .get(l);
- if (locatorListener != null) {
- l.removeServiceListener(locatorListener);
- locatorListener.close();
- }
- }
- locatorListeners.clear();
- }
-
- Object[] locators = locatorServiceTracker.getServices();
- if (locators != null) {
- for (int i = 0; i < locators.length; i++) {
- // Add service listener to locator
- shutdownLocator((IDiscoveryLocator) locators[i]);
- }
- }
-
- if (localLocatorServiceListener != null) {
- localLocatorServiceListener.close();
- localLocatorServiceListener = null;
- }
-
- if (endpointListenerTracker != null) {
- endpointListenerTracker.close();
- endpointListenerTracker = null;
- }
- if (endpointListenerTrackerCustomizer != null) {
- endpointListenerTrackerCustomizer.close();
- endpointListenerTrackerCustomizer = null;
- }
-
- // Shutdown asynchronous event manager
- if (eventManager != null) {
- eventManager.close();
- eventManager = null;
- }
-
- synchronized (endpointDescriptionFactoryTrackerLock) {
- if (endpointDescriptionFactoryTracker != null) {
- endpointDescriptionFactoryTracker.close();
- endpointDescriptionFactoryTracker = null;
- }
- }
- if (defaultEndpointDescriptionFactoryRegistration != null) {
- defaultEndpointDescriptionFactoryRegistration.unregister();
- defaultEndpointDescriptionFactoryRegistration = null;
- }
- if (defaultEndpointDescriptionFactory != null) {
- defaultEndpointDescriptionFactory.close();
- defaultEndpointDescriptionFactory = null;
- }
-
- synchronized (serviceInfoFactoryTrackerLock) {
- if (serviceInfoFactoryTracker != null) {
- serviceInfoFactoryTracker.close();
- serviceInfoFactoryTracker = null;
- }
- }
- if (defaultServiceInfoFactoryRegistration != null) {
- defaultServiceInfoFactoryRegistration.unregister();
- defaultServiceInfoFactoryRegistration = null;
- }
- if (serviceInfoFactory != null) {
- serviceInfoFactory.close();
- serviceInfoFactory = null;
- }
- if (defaultEndpointDescriptionReaderRegistration != null) {
- defaultEndpointDescriptionReaderRegistration.unregister();
- defaultEndpointDescriptionReaderRegistration = null;
- }
- if (locatorServiceTracker != null) {
- locatorServiceTracker.close();
- locatorServiceTracker = null;
- }
- synchronized (advertiserTrackerLock) {
- if (advertiserTracker != null) {
- advertiserTracker.close();
- advertiserTracker = null;
- }
- }
- this.executor = null;
- this.context = null;
- }
-
- public IDiscoveryAdvertiser[] getDiscoveryAdvertisers() {
- synchronized (advertiserTrackerLock) {
- if (advertiserTracker == null) {
- advertiserTracker = new ServiceTracker(context,
- IDiscoveryAdvertiser.class.getName(), null);
- advertiserTracker.open();
- }
- }
- ServiceReference[] advertiserRefs = advertiserTracker
- .getServiceReferences();
- if (advertiserRefs == null)
- return null;
- List<IDiscoveryAdvertiser> results = new ArrayList<IDiscoveryAdvertiser>();
- for (int i = 0; i < advertiserRefs.length; i++) {
- results.add((IDiscoveryAdvertiser) context
- .getService(advertiserRefs[i]));
- }
- return results.toArray(new IDiscoveryAdvertiser[results.size()]);
- }
-
- private void openLocator(IDiscoveryLocator locator) {
- if (context == null)
- return;
- synchronized (locatorListeners) {
- LocatorServiceListener locatorListener = new LocatorServiceListener(
- this, locator);
- locatorListeners.put(locator, locatorListener);
- processInitialLocatorServices(locator, locatorListener);
- }
- }
-
- private void shutdownLocator(IDiscoveryLocator locator) {
- if (locator == null || context == null)
- return;
- synchronized (locatorListeners) {
- LocatorServiceListener locatorListener = locatorListeners
- .remove(locator);
- if (locatorListener != null)
- locatorListener.close();
- }
- }
-
- void queueEndpointDescription(
- EndpointListener listener,
- org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription,
- String matchingFilters, boolean discovered) {
- if (eventQueue == null)
- return;
- synchronized (eventQueue) {
- eventQueue
- .dispatchEventAsynchronous(0, new EndpointListenerEvent(
- listener, endpointDescription, matchingFilters,
- discovered));
- }
- }
-
- Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> getAllDiscoveredEndpointDescriptions() {
- Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> result = new ArrayList();
- if (localLocatorServiceListener == null)
- return result;
- // Get local first
- result.addAll(localLocatorServiceListener.getEndpointDescriptions());
- synchronized (locatorListeners) {
- for (IDiscoveryLocator l : locatorListeners.keySet()) {
- LocatorServiceListener locatorListener = locatorListeners
- .get(l);
- result.addAll(locatorListener.getEndpointDescriptions());
- }
- }
- return result;
- }
-
- void queueEndpointDescription(
- org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription,
- boolean discovered) {
- EndpointListenerHolder[] endpointListenerHolders = getMatchingEndpointListenerHolders(endpointDescription);
- if (endpointListenerHolders != null) {
- for (int i = 0; i < endpointListenerHolders.length; i++) {
- queueEndpointDescription(
- endpointListenerHolders[i].getListener(),
- endpointListenerHolders[i].getDescription(),
- endpointListenerHolders[i].getMatchingFilter(),
- discovered);
-
- }
- } else {
- LogUtility.logWarning("queueEndpointDescription",
- DebugOptions.DISCOVERY, this.getClass(),
- "No matching EndpointListeners found for "
- + (discovered ? "discovered" : "undiscovered")
- + " endpointDescription=" + endpointDescription);
- }
-
- }
-
- private void processInitialLocatorServices(final IDiscoveryLocator locator,
- final LocatorServiceListener locatorListener) {
- IProgressRunnable runnable = new IProgressRunnable() {
- public Object run(IProgressMonitor arg0) throws Exception {
- IServiceInfo[] serviceInfos = locator.getServices();
- for (int i = 0; i < serviceInfos.length; i++) {
- locatorListener.handleService(serviceInfos[i], true);
- }
- return null;
- }
- };
- executor.execute(runnable, null);
- }
-
- void shutdownLocators() {
- Object[] locators = locatorServiceTracker.getServices();
- if (locators != null) {
- for (int i = 0; i < locators.length; i++) {
- // Add service listener to locator
- shutdownLocator((IDiscoveryLocator) locators[i]);
- }
- }
- }
-
- private class EndpointListenerEvent {
-
- private EndpointListener endpointListener;
- private org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription;
- private String matchingFilter;
- private boolean discovered;
-
- public EndpointListenerEvent(
- EndpointListener endpointListener,
- org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription,
- String matchingFilter, boolean discovered) {
- this.endpointListener = endpointListener;
- this.endpointDescription = endpointDescription;
- this.matchingFilter = matchingFilter;
- this.discovered = discovered;
- }
-
- public EndpointListener getEndpointListener() {
- return endpointListener;
- }
-
- public org.osgi.service.remoteserviceadmin.EndpointDescription getEndointDescription() {
- return endpointDescription;
- }
-
- public String getMatchingFilter() {
- return matchingFilter;
- }
-
- public boolean isDiscovered() {
- return discovered;
- }
- }
-
- private class LocatorTrackerCustomizer implements ServiceTrackerCustomizer {
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.
- * osgi.framework.ServiceReference)
- */
- public Object addingService(ServiceReference reference) {
- IDiscoveryLocator locator = (IDiscoveryLocator) context
- .getService(reference);
- if (locator != null)
- openLocator(locator);
- return locator;
- }
-
- public void modifiedService(ServiceReference reference, Object service) {
- }
-
- public void removedService(ServiceReference reference, Object service) {
- shutdownLocator((IDiscoveryLocator) service);
- }
- }
-
- public IServiceInfoFactory getServiceInfoFactory() {
- if (context == null)
- return null;
- synchronized (serviceInfoFactoryTrackerLock) {
- if (serviceInfoFactoryTracker == null) {
- serviceInfoFactoryTracker = new ServiceTracker(context,
- IServiceInfoFactory.class.getName(), null);
- serviceInfoFactoryTracker.open();
- }
- }
- return (IServiceInfoFactory) serviceInfoFactoryTracker.getService();
- }
-
- public IDiscoveredEndpointDescriptionFactory getDiscoveredEndpointDescriptionFactory() {
- synchronized (endpointDescriptionFactoryTrackerLock) {
- if (context == null)
- return null;
- if (endpointDescriptionFactoryTracker == null) {
- endpointDescriptionFactoryTracker = new ServiceTracker(context,
- IDiscoveredEndpointDescriptionFactory.class.getName(),
- null);
- endpointDescriptionFactoryTracker.open();
- }
- return (IDiscoveredEndpointDescriptionFactory) endpointDescriptionFactoryTracker
- .getService();
- }
- }
-
- private Object endpointListenerServiceTrackerLock = new Object();
-
- public EndpointListenerHolder[] getMatchingEndpointListenerHolders(
- EndpointDescription description) {
- synchronized (endpointListenerServiceTrackerLock) {
- if (context == null)
- return null;
- return getMatchingEndpointListenerHolders(
- endpointListenerTracker.getServiceReferences(), description);
- }
- }
-
- public class EndpointListenerHolder {
-
- private EndpointListener listener;
- private EndpointDescription description;
- private String matchingFilter;
-
- public EndpointListenerHolder(EndpointListener l,
- EndpointDescription d, String f) {
- this.listener = l;
- this.description = d;
- this.matchingFilter = f;
- }
-
- public EndpointListener getListener() {
- return listener;
- }
-
- public EndpointDescription getDescription() {
- return description;
- }
-
- public String getMatchingFilter() {
- return matchingFilter;
- }
- }
-
- public EndpointListenerHolder[] getMatchingEndpointListenerHolders(
- ServiceReference[] refs, EndpointDescription description) {
- if (refs == null)
- return null;
- List results = new ArrayList();
- for (int i = 0; i < refs.length; i++) {
- EndpointListener listener = (EndpointListener) context
- .getService(refs[i]);
- if (listener == null)
- continue;
- List filters = PropertiesUtil.getStringPlusProperty(
- getMapFromProperties(refs[i]),
- EndpointListener.ENDPOINT_LISTENER_SCOPE);
- String matchingFilter = isMatch(description, filters);
- if (matchingFilter != null)
- results.add(new EndpointListenerHolder(listener, description,
- matchingFilter));
- }
- return (EndpointListenerHolder[]) results
- .toArray(new EndpointListenerHolder[] {});
- }
-
- private String isMatch(EndpointDescription description, List filters) {
- for (Iterator j = filters.iterator(); j.hasNext();) {
- String filter = (String) j.next();
- if (description.matches(filter))
- return filter;
- }
- return null;
- }
-
- private Map getMapFromProperties(ServiceReference ref) {
- Map results = new HashMap();
- String[] keys = ref.getPropertyKeys();
- if (keys != null) {
- for (int i = 0; i < keys.length; i++) {
- results.put(keys[i], ref.getProperty(keys[i]));
- }
- }
- return results;
- }
-
-}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointDescriptionBundleTrackerCustomizer.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointDescriptionBundleTrackerCustomizer.java
deleted file mode 100644
index 270b5e516..000000000
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointDescriptionBundleTrackerCustomizer.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Composent, Inc. - initial API and implementation
- ******************************************************************************/
-package org.eclipse.ecf.internal.osgi.services.remoteserviceadmin;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.ecf.osgi.services.remoteserviceadmin.IEndpointDescriptionReader;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.util.tracker.BundleTrackerCustomizer;
-import org.osgi.util.tracker.ServiceTracker;
-
-public class EndpointDescriptionBundleTrackerCustomizer implements
- BundleTrackerCustomizer {
-
- private static final String REMOTESERVICE_MANIFESTHEADER = "Remote-Service";
- private static final String XML_FILE_PATTERN = "*.xml";
-
- private Map<Long, Collection<org.osgi.service.remoteserviceadmin.EndpointDescription>> bundleDescriptionMap = Collections
- .synchronizedMap(new HashMap<Long, Collection<org.osgi.service.remoteserviceadmin.EndpointDescription>>());
-
- private BundleContext bundleContext;
- private LocatorServiceListener endpointDescriptionHandler;
-
- private Object endpointDescriptionReaderTrackerLock = new Object();
- private ServiceTracker endpointDescriptionReaderTracker;
-
- public EndpointDescriptionBundleTrackerCustomizer(
- BundleContext bundleContext,
- LocatorServiceListener endpointDescriptionHandler) {
- this.bundleContext = bundleContext;
- this.endpointDescriptionHandler = endpointDescriptionHandler;
- }
-
- private IEndpointDescriptionReader getEndpointDescriptionReader() {
- synchronized (endpointDescriptionReaderTrackerLock) {
- if (endpointDescriptionReaderTracker == null) {
- endpointDescriptionReaderTracker = new ServiceTracker(
- bundleContext,
- IEndpointDescriptionReader.class.getName(), null);
- endpointDescriptionReaderTracker.open();
- }
- }
- return (IEndpointDescriptionReader) endpointDescriptionReaderTracker
- .getService();
- }
-
- public Object addingBundle(Bundle bundle, BundleEvent event) {
- handleAddingBundle(bundle);
- return bundle;
- }
-
- private void handleAddingBundle(Bundle bundle) {
- BundleContext context = Activator.getContext();
- if (context == null)
- return;
- String remoteServicesHeaderValue = (String) bundle.getHeaders().get(
- REMOTESERVICE_MANIFESTHEADER);
- if (remoteServicesHeaderValue != null) {
- // First parse into comma-separated values
- String[] paths = remoteServicesHeaderValue.split(",");
- if (paths != null)
- for (int i = 0; i < paths.length; i++)
- handleEndpointDescriptionPath(bundle, paths[i]);
- }
- }
-
- private void handleEndpointDescriptionPath(Bundle bundle,
- String remoteServicesHeaderValue) {
- // if it's empty, ignore
- if ("".equals(remoteServicesHeaderValue))
- return;
- Enumeration<URL> e = null;
- // if it endswith a '/', then scan for *.xml files
- if (remoteServicesHeaderValue.endsWith("/")) {
- e = bundle.findEntries(remoteServicesHeaderValue, XML_FILE_PATTERN,
- false);
- } else {
- // Break into path and filename/pattern
- int lastSlashIndex = remoteServicesHeaderValue.lastIndexOf('/');
- if (lastSlashIndex == -1) {
- // no slash...might be a file name or pattern, assumed to be
- // at root of bundle
- e = bundle.findEntries("/", remoteServicesHeaderValue, false);
- } else {
- String path = remoteServicesHeaderValue.substring(0,
- lastSlashIndex);
- if ("".equals(path)) {
- // path is empty so assume it's root
- path = "/";
- }
- String filePattern = remoteServicesHeaderValue
- .substring(lastSlashIndex + 1);
- e = bundle.findEntries(path, filePattern, false);
- }
- }
- // Now process any found
- Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> endpointDescriptions = new ArrayList<org.osgi.service.remoteserviceadmin.EndpointDescription>();
- if (e != null) {
- while (e.hasMoreElements()) {
- org.osgi.service.remoteserviceadmin.EndpointDescription[] eps = handleEndpointDescriptionFile(
- bundle, e.nextElement());
- if (eps != null)
- for (int i = 0; i < eps.length; i++)
- endpointDescriptions.add(eps[i]);
- }
- }
- // finally, handle them
- if (endpointDescriptions.size() > 0) {
- bundleDescriptionMap.put(new Long(bundle.getBundleId()),
- endpointDescriptions);
- for (org.osgi.service.remoteserviceadmin.EndpointDescription ed : endpointDescriptions)
- endpointDescriptionHandler.handleEndpointDescription(ed, true);
- }
- }
-
- private org.osgi.service.remoteserviceadmin.EndpointDescription[] handleEndpointDescriptionFile(
- Bundle bundle, URL fileURL) {
- InputStream ins = null;
- try {
- IEndpointDescriptionReader endpointDescriptionReader = getEndpointDescriptionReader();
- if (endpointDescriptionReader == null)
- throw new NullPointerException(
- "No endpointDescriptionReader available for handleEndpointDescriptionFile fileURL="
- + fileURL);
- ins = fileURL.openStream();
- return endpointDescriptionReader.readEndpointDescriptions(ins);
- } catch (Exception e) {
- logError("handleEndpointDescriptionFile",
- "Exception creating endpoint descriptions from fileURL="
- + fileURL, e);
- return null;
- } finally {
- if (ins != null)
- try {
- ins.close();
- } catch (IOException e) {
- logError("handleEndpointDescriptionFile",
- "Exception closing endpointDescription input fileURL="
- + fileURL, e);
- }
- }
- }
-
- private void logError(String method, String message, Throwable t) {
- LogUtility.logError(method, DebugOptions.DISCOVERY, this.getClass(),
- new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR,
- message, t));
- }
-
- public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
- }
-
- public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
- handleRemovedBundle(bundle);
- }
-
- private void handleRemovedBundle(Bundle bundle) {
- Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> endpointDescriptions = bundleDescriptionMap
- .remove(new Long(bundle.getBundleId()));
- if (endpointDescriptions != null)
- for (org.osgi.service.remoteserviceadmin.EndpointDescription ed : endpointDescriptions)
- endpointDescriptionHandler.handleEndpointDescription(ed, false);
- }
-
- public void close() {
- synchronized (endpointDescriptionReaderTrackerLock) {
- if (endpointDescriptionReaderTracker != null) {
- endpointDescriptionReaderTracker.close();
- endpointDescriptionReaderTracker = null;
- }
- }
- bundleDescriptionMap.clear();
- bundleContext = null;
- }
-}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointDescriptionParser.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointDescriptionParser.java
deleted file mode 100644
index 49a3b6d9f..000000000
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointDescriptionParser.java
+++ /dev/null
@@ -1,796 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Composent, Inc. - initial API and implementation
- ******************************************************************************/
-package org.eclipse.ecf.internal.osgi.services.remoteserviceadmin;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.DefaultHandler;
-
-public class EndpointDescriptionParser {
-
- private static List<String> multiValueTypes;
-
- static {
- multiValueTypes = Arrays.asList(new String[] { "String", "Long", //$NON-NLS-1$ //$NON-NLS-2$
- "long", "Double", "double", "float", "Float", "int", "Integer", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- "byte", "Byte", "char", "Character", "boolean", "Boolean", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "short", "Short" }); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- private static final String ENDPOINT_DESCRIPTIONS = "endpoint-descriptions"; //$NON-NLS-1$
- private static final String ENDPOINT_DESCRIPTION = "endpoint-description"; //$NON-NLS-1$
- private static final String ENDPOINT_PROPERTY = "property"; //$NON-NLS-1$
- private static final String ENDPOINT_PROPERTY_NAME = "name"; //$NON-NLS-1$
- private static final String ENDPOINT_PROPERTY_VALUE = "value"; //$NON-NLS-1$
- private static final String ENDPOINT_PROPERTY_VALUETYPE = "value-type"; //$NON-NLS-1$
- private static final String ENDPOINT_PROPERTY_ARRAY = "array"; //$NON-NLS-1$
- private static final String ENDPOINT_PROPERTY_LIST = "list"; //$NON-NLS-1$
- private static final String ENDPOINT_PROPERTY_SET = "set"; //$NON-NLS-1$
- private static final String ENDPOINT_PROPERTY_XML = "xml"; //$NON-NLS-1$
-
- public static String[] noAttributes = new String[0];
-
- private XMLReader xmlReader;
- protected Locator locator = null; // document locator, if supported by the
- // parser
-
- class IgnoringHandler extends AbstractHandler {
-
- public IgnoringHandler(AbstractHandler parent) {
- super(parent);
- this.elementHandled = "IgnoringAll"; //$NON-NLS-1$
- }
-
- public void startElement(String name, Attributes attributes) {
- noSubElements(name, attributes);
- }
-
- }
-
- /**
- * Abstract base class for content handlers
- */
- abstract class AbstractHandler extends DefaultHandler {
-
- protected ContentHandler parentHandler = null;
- protected String elementHandled = null;
-
- protected StringBuffer characters = null; // character data inside an
- // element
-
- public AbstractHandler() {
- // Empty constructor for a root handler
- }
-
- public AbstractHandler(ContentHandler parentHandler) {
- this.parentHandler = parentHandler;
- xmlReader.setContentHandler(this);
- }
-
- public AbstractHandler(ContentHandler parentHandler,
- String elementHandled) {
- this.parentHandler = parentHandler;
- xmlReader.setContentHandler(this);
- this.elementHandled = elementHandled;
- }
-
- /**
- * Set the document locator for the parser
- *
- * @see org.xml.sax.ContentHandler#setDocumentLocator
- */
- public void setDocumentLocator(Locator docLocator) {
- locator = docLocator;
- }
-
- public void startElement(String uri, String localName, String qName,
- Attributes attributes) throws SAXException {
- finishCharacters();
- String name = makeSimpleName(localName, qName);
- startElement(name, attributes);
- }
-
- public abstract void startElement(String name, Attributes attributes)
- throws SAXException;
-
- public void invalidElement(String name, Attributes attributes) {
- unexpectedElement(this, name, attributes);
- new IgnoringHandler(this);
- }
-
- public void endElement(String namespaceURI, String localName,
- String qName) {
- finishCharacters();
- finished();
- // Restore the parent content handler
- xmlReader.setContentHandler(parentHandler);
- }
-
- /**
- * An implementation for startElement when there are no sub-elements
- */
- protected void noSubElements(String name, Attributes attributes) {
- unexpectedElement(this, name, attributes);
- // Create a new handler to ignore subsequent nested elements
- new IgnoringHandler(this);
- }
-
- /*
- * Save up character data until endElement or nested startElement
- *
- * @see org.xml.sax.ContentHandler#characters
- */
- public void characters(char[] chars, int start, int length) {
- if (this.characters == null) {
- this.characters = new StringBuffer();
- }
- this.characters.append(chars, start, length);
- }
-
- // Consume the characters accumulated in this.characters.
- // Called before startElement or endElement
- private String finishCharacters() {
- // common case -- no characters or only whitespace
- if (this.characters == null || this.characters.length() == 0) {
- return null;
- }
- if (allWhiteSpace(this.characters)) {
- this.characters.setLength(0);
- return null;
- }
-
- // process the characters
- try {
- String trimmedChars = this.characters.toString().trim();
- if (trimmedChars.length() == 0) {
- // this shouldn't happen due to the test for allWhiteSpace
- // above
- System.err.println("Unexpected non-whitespace characters: " //$NON-NLS-1$
- + trimmedChars);
- return null;
- }
- processCharacters(trimmedChars);
- return trimmedChars;
- } finally {
- this.characters.setLength(0);
- }
- }
-
- // Method to override in the handler of an element with CDATA.
- protected void processCharacters(String data) {
- if (data.length() > 0) {
- unexpectedCharacterData(this, data);
- }
- }
-
- private boolean allWhiteSpace(StringBuffer sb) {
- int length = sb.length();
- for (int i = 0; i < length; i += 1) {
- if (!Character.isWhitespace(sb.charAt(i))) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Called when this element and all elements nested into it have been
- * handled.
- */
- protected void finished() {
- // Do nothing by default
- }
-
- /*
- * A name used to identify the handler.
- */
- public String getName() {
- return (elementHandled != null ? elementHandled : "NoName"); //$NON-NLS-1$
- }
-
- /**
- * Parse the attributes of an element with only required attributes.
- */
- protected String[] parseRequiredAttributes(Attributes attributes,
- String[] required) {
- return parseAttributes(attributes, required, noAttributes);
- }
-
- /**
- * Parse the attributes of an element with a single optional attribute.
- */
- protected String parseOptionalAttribute(Attributes attributes,
- String name) {
- return parseAttributes(attributes, noAttributes,
- new String[] { name })[0];
- }
-
- /**
- * Parse the attributes of an element, given the list of required and
- * optional ones. Return values in same order, null for those not
- * present. Log warnings for extra attributes or missing required
- * attributes.
- */
- protected String[] parseAttributes(Attributes attributes,
- String[] required, String[] optional) {
- String[] result = new String[required.length + optional.length];
- for (int i = 0; i < attributes.getLength(); i += 1) {
- String name = attributes.getLocalName(i);
- String value = attributes.getValue(i).trim();
- int j;
- if ((j = indexOf(required, name)) >= 0) {
- result[j] = value;
- } else if ((j = indexOf(optional, name)) >= 0) {
- result[required.length + j] = value;
- } else {
- unexpectedAttribute(elementHandled, name, value);
- }
- }
- for (int i = 0; i < required.length; i += 1) {
- checkRequiredAttribute(elementHandled, required[i], result[i]);
- }
- return result;
- }
-
- }
-
- SAXParser getParser() throws ParserConfigurationException, SAXException {
- Activator a = Activator.getDefault();
- if (a == null)
- return null;
-
- SAXParserFactory factory = a.getSAXParserFactory();
- if (factory == null) {
- throw new SAXException("Unable to acquire sax parser"); //$NON-NLS-1$
- }
- factory.setNamespaceAware(true);
- factory.setValidating(false);
- try {
- factory.setFeature(
- "http://xml.org/sax/features/string-interning", true); //$NON-NLS-1$
- } catch (SAXException se) {
- // some parsers may not support string interning
- }
- SAXParser theParser = factory.newSAXParser();
- if (theParser == null) {
- throw new SAXException("Unable to create sax parser"); //$NON-NLS-1$
- }
- xmlReader = theParser.getXMLReader();
- return theParser;
- }
-
- abstract class RootHandler extends AbstractHandler {
-
- public RootHandler() {
- super();
- }
-
- public void initialize(DocHandler document, String rootName,
- Attributes attributes) {
- this.parentHandler = document;
- this.elementHandled = rootName;
- handleRootAttributes(attributes);
- }
-
- protected abstract void handleRootAttributes(Attributes attributes);
-
- }
-
- class DocHandler extends AbstractHandler {
-
- RootHandler rootHandler;
-
- public DocHandler(String rootName, RootHandler rootHandler) {
- super(null, rootName);
- this.rootHandler = rootHandler;
- }
-
- public void startElement(String name, Attributes attributes) {
- if (name.equals(elementHandled)) {
- rootHandler.initialize(this, name, attributes);
- xmlReader.setContentHandler(rootHandler);
- } else {
- this.noSubElements(name, attributes);
- }
- }
-
- }
-
- class EndpointDescriptionDocHandler extends DocHandler {
-
- public EndpointDescriptionDocHandler(String rootName,
- RootHandler rootHandler) {
- super(rootName, rootHandler);
- }
-
- public void processingInstruction(String target, String data)
- throws SAXException {
- // do nothing
- }
- }
-
- class EndpointDescriptionsHandler extends RootHandler {
-
- private List<EndpointDescription> endpointDescriptions = new ArrayList<EndpointDescription>();
- private EndpointDescriptionHandler endpointDescriptionHandler;
-
- protected void handleRootAttributes(Attributes attributes) {
- }
-
- public void startElement(String name, Attributes attributes)
- throws SAXException {
- if (ENDPOINT_DESCRIPTION.equals(name)) {
- if (endpointDescriptionHandler == null) {
- endpointDescriptionHandler = new EndpointDescriptionHandler(
- this, attributes, endpointDescriptions);
- } else {
- duplicateElement(this, name, attributes);
- }
- } else {
- invalidElement(name, attributes);
- }
- }
-
- public void endElement(String namespaceURI, String localName,
- String qName) {
- if (elementHandled.equals(localName)) {
- endpointDescriptionHandler = null;
- super.endElement(namespaceURI, localName, qName);
- }
- }
-
- public List<EndpointDescription> getEndpointDescriptions() {
- return endpointDescriptions;
- }
- }
-
- class EndpointDescriptionHandler extends AbstractHandler {
-
- private Map<String, Object> properties;
- private List<EndpointDescription> descriptions;
-
- public EndpointDescriptionHandler(ContentHandler parentHandler,
- Attributes attributes, List<EndpointDescription> descriptions) {
- super(parentHandler, ENDPOINT_DESCRIPTION);
- this.properties = new HashMap<String, Object>();
- this.descriptions = descriptions;
- }
-
- public void startElement(String name, Attributes attributes)
- throws SAXException {
- if (ENDPOINT_PROPERTY.equals(name)) {
- new EndpointPropertyHandler(this, attributes, properties);
- }
- }
-
- public void endElement(String namespaceURI, String localName,
- String qName) {
- if (elementHandled.equals(localName)) {
- this.descriptions.add(new EndpointDescription(properties));
- super.endElement(namespaceURI, localName, qName);
- }
- }
-
- }
-
- abstract class MultiValueHandler extends AbstractHandler {
-
- protected String valueType;
-
- public MultiValueHandler(ContentHandler parentHandler,
- String elementHandled, String valueType) {
- super(parentHandler, elementHandled);
- this.valueType = valueType;
- }
-
- protected Object createValue(String value) {
- if (value == null)
- return null;
- if (valueType.equals("String")) { //$NON-NLS-1$
- return value;
- } else if (valueType.equals("long") || valueType.equals("Long")) { //$NON-NLS-1$ //$NON-NLS-2$
- return Long.valueOf(value);
- } else if (valueType.equals("double") || valueType.equals("Double")) { //$NON-NLS-1$ //$NON-NLS-2$
- return Double.valueOf(value);
- } else if (valueType.equals("float") || valueType.equals("Float")) { //$NON-NLS-1$ //$NON-NLS-2$
- return Float.valueOf(value);
- } else if (valueType.equals("int") || valueType.equals("Integer")) { //$NON-NLS-1$ //$NON-NLS-2$
- return Integer.valueOf(value);
- } else if (valueType.equals("byte") || valueType.equals("Byte")) { //$NON-NLS-1$ //$NON-NLS-2$
- return Byte.valueOf(value);
- } else if (valueType.equals("char") //$NON-NLS-1$
- || valueType.equals("Character")) { //$NON-NLS-1$
- char[] chars = new char[1];
- value.getChars(0, 1, chars, 0);
- return Character.valueOf(chars[0]);
- } else if (valueType.equals("boolean") //$NON-NLS-1$
- || valueType.equals("Boolean")) { //$NON-NLS-1$
- return Boolean.valueOf(value);
- } else if (valueType.equals("short") || valueType.equals("Short")) { //$NON-NLS-1$ //$NON-NLS-2$
- return Short.valueOf(value);
- }
- return null;
- }
-
- public void startElement(String name, Attributes attributes)
- throws SAXException {
- if (ENDPOINT_PROPERTY_VALUE.equals(name)) {
- characters = new StringBuffer();
- }
- }
-
- public void endElement(String namespaceURI, String localName,
- String qName) {
- if (ENDPOINT_PROPERTY_VALUE.equals(localName)) {
- Object value = createValue(processValue((characters == null) ? null
- : characters.toString()));
- if (value != null)
- addValue(value);
- characters = null;
- } else if (elementHandled.equals(localName)) {
- super.endElement(namespaceURI, localName, qName);
- }
- }
-
- private String processValue(String characters) {
- if (characters == null || characters.length() == 0)
- return null;
- if (valueType.equals("String")) //$NON-NLS-1$
- return characters;
- int startIndex = 0;
- while (Character.isWhitespace(characters.charAt(startIndex)))
- startIndex++;
- int endIndex = characters.length() - 1;
- while (Character.isWhitespace(characters.charAt(endIndex)))
- endIndex--;
- return characters.substring(startIndex, endIndex + 1);
- }
-
- protected abstract void addValue(Object value);
-
- public abstract Object getValues();
- }
-
- class ArrayMultiValueHandler extends MultiValueHandler {
-
- private List<Object> values = new ArrayList<Object>();
-
- public ArrayMultiValueHandler(ContentHandler parentHandler,
- String elementHandled, String valueType) {
- super(parentHandler, elementHandled, valueType);
- }
-
- protected Object[] createEmptyArrayOfType() {
- if (valueType.equals("String")) { //$NON-NLS-1$
- return new String[] {};
- } else if (valueType.equals("long") || valueType.equals("Long")) { //$NON-NLS-1$ //$NON-NLS-2$
- return new Long[] {};
- } else if (valueType.equals("double") || valueType.equals("Double")) { //$NON-NLS-1$ //$NON-NLS-2$
- return new Double[] {};
- } else if (valueType.equals("float") || valueType.equals("Float")) { //$NON-NLS-1$ //$NON-NLS-2$
- return new Double[] {};
- } else if (valueType.equals("int") || valueType.equals("Integer")) { //$NON-NLS-1$ //$NON-NLS-2$
- return new Integer[] {};
- } else if (valueType.equals("byte") || valueType.equals("Byte")) { //$NON-NLS-1$ //$NON-NLS-2$
- return new Byte[] {};
- } else if (valueType.equals("char") //$NON-NLS-1$
- || valueType.equals("Character")) { //$NON-NLS-1$
- return new Character[] {};
- } else if (valueType.equals("boolean") //$NON-NLS-1$
- || valueType.equals("Boolean")) { //$NON-NLS-1$
- return new Boolean[] {};
- } else if (valueType.equals("short") || valueType.equals("Short")) { //$NON-NLS-1$ //$NON-NLS-2$
- return new Short[] {};
- } else
- return null;
- }
-
- public Object getValues() {
- return values.toArray(createEmptyArrayOfType());
- }
-
- protected void addValue(Object value) {
- values.add(value);
- }
- }
-
- class ListMultiValueHandler extends MultiValueHandler {
-
- private List<Object> values = new ArrayList<Object>();
-
- public ListMultiValueHandler(ContentHandler parentHandler,
- String elementHandled, String valueType) {
- super(parentHandler, elementHandled, valueType);
- }
-
- public Object getValues() {
- return values;
- }
-
- protected void addValue(Object value) {
- values.add(value);
- }
- }
-
- class SetMultiValueHandler extends MultiValueHandler {
-
- private Set<Object> values = new HashSet<Object>();
-
- public SetMultiValueHandler(ContentHandler parentHandler,
- String elementHandled, String valueType) {
- super(parentHandler, elementHandled, valueType);
- }
-
- public Object getValues() {
- return values;
- }
-
- protected void addValue(Object value) {
- values.add(value);
- }
- }
-
- class XMLValueHandler extends AbstractHandler {
-
- private Map<String, String> nsPrefixMap = new HashMap<String, String>();
- private StringBuffer buf;
-
- public XMLValueHandler(ContentHandler parentHandler) {
- super(parentHandler, ENDPOINT_PROPERTY_XML);
- buf = new StringBuffer();
- }
-
- public void startPrefixMapping(String prefix, String uri)
- throws SAXException {
- nsPrefixMap.put(uri, prefix);
- }
-
- public void startElement(String uri, String localName, String qName,
- Attributes attributes) throws SAXException {
- buf.append("<").append(qName); //$NON-NLS-1$
- for (Iterator<String> i = nsPrefixMap.keySet().iterator(); i
- .hasNext();) {
- String nsURI = (String) i.next();
- String prefix = (String) nsPrefixMap.get(nsURI);
- i.remove();
- if (nsURI != null) {
- buf.append(" xmlns"); //$NON-NLS-1$
- if (prefix != null)
- buf.append(":").append(prefix); //$NON-NLS-1$
- buf.append("=\"").append(nsURI).append("\""); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- for (int i = 0; i < attributes.getLength(); i++) {
- buf.append(" "); //$NON-NLS-1$
- buf.append(attributes.getQName(i))
- .append("=\"").append(attributes.getValue(i)).append("\""); //$NON-NLS-1$ //$NON-NLS-2$
- }
- buf.append(">"); //$NON-NLS-1$
- characters = new StringBuffer();
- }
-
- public void startElement(String name, Attributes attributes)
- throws SAXException {
- // not used
- }
-
- public void endElement(String namespaceURI, String localName,
- String qName) {
- if (elementHandled.equals(localName)) {
- super.endElement(namespaceURI, localName, qName);
- } else {
- if (characters != null)
- buf.append(characters);
- buf.append("</").append(qName).append(">"); //$NON-NLS-1$ //$NON-NLS-2$
- characters = null;
- }
- }
-
- public String getXML() {
- return buf.toString();
- }
- }
-
- class EndpointPropertyHandler extends AbstractHandler {
-
- private Map<String, Object> properties;
- private String name;
- private String valueType = "String"; //$NON-NLS-1$
- private String value;
- private MultiValueHandler multiValueHandler;
- private XMLValueHandler xmlValueHandler;
-
- public EndpointPropertyHandler(ContentHandler parentHandler,
- Attributes attributes, Map<String, Object> properties)
- throws SAXException {
- super(parentHandler, ENDPOINT_PROPERTY);
- name = parseRequiredAttributes(attributes,
- new String[] { ENDPOINT_PROPERTY_NAME })[0];
- value = parseOptionalAttribute(attributes, ENDPOINT_PROPERTY_VALUE);
- String vt = parseOptionalAttribute(attributes,
- ENDPOINT_PROPERTY_VALUETYPE);
- if (vt != null) {
- if (!multiValueTypes.contains(vt))
- throw new SAXException("property element valueType=" + vt //$NON-NLS-1$
- + " not allowed"); //$NON-NLS-1$
- this.valueType = vt;
- }
- this.properties = properties;
- if (value != null) {
- String[] property = new String[] { name, value };
- if (isValidProperty(property)) {
- this.properties.put(property[0], property[1]);
- }
- }
- }
-
- public void startElement(String name, Attributes attributes)
- throws SAXException {
- // Should not happen if value is non-null
- if (value != null)
- throw new SAXException(
- "property element has both value attribute and sub-element"); //$NON-NLS-1$
- if (ENDPOINT_PROPERTY_ARRAY.equals(name)) {
- if (multiValueHandler == null) {
- multiValueHandler = new ArrayMultiValueHandler(this,
- ENDPOINT_PROPERTY_ARRAY, valueType);
- } else {
- duplicateElement(this, name, attributes);
- }
- } else if (ENDPOINT_PROPERTY_LIST.equals(name)) {
- if (multiValueHandler == null) {
- multiValueHandler = new ListMultiValueHandler(this,
- ENDPOINT_PROPERTY_LIST, valueType);
- } else {
- duplicateElement(this, name, attributes);
- }
- } else if (ENDPOINT_PROPERTY_SET.equals(name)) {
- if (multiValueHandler == null) {
- multiValueHandler = new SetMultiValueHandler(this,
- ENDPOINT_PROPERTY_SET, valueType);
- } else {
- duplicateElement(this, name, attributes);
- }
- } else if (ENDPOINT_PROPERTY_XML.equals(name)) {
- // xml
- if (xmlValueHandler == null) {
- xmlValueHandler = new XMLValueHandler(this);
- } else {
- duplicateElement(this, name, attributes);
- }
- } else {
- invalidElement(name, attributes);
- }
- }
-
- public void endElement(String namespaceURI, String localName,
- String qName) {
- if (elementHandled.equals(localName)) {
- if (multiValueHandler != null) {
- properties.put(name, multiValueHandler.getValues());
- multiValueHandler = null;
- } else if (xmlValueHandler != null) {
- properties.put(name, xmlValueHandler.getXML());
- xmlValueHandler = null;
- }
- super.endElement(namespaceURI, localName, qName);
- }
- }
-
- private boolean isValidProperty(String[] property) {
- return (property.length == 2 && property[0] != null && property[1] != null);
- }
- }
-
- public class EndpointDescription {
- private Map<String, Object> properties;
-
- public EndpointDescription(Map<String, Object> properties) {
- this.properties = properties;
- }
-
- public Map<String, Object> getProperties() {
- return properties;
- }
-
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("EndpointDescription [properties="); //$NON-NLS-1$
- builder.append(properties);
- builder.append("]"); //$NON-NLS-1$
- return builder.toString();
- }
-
- }
-
- public synchronized void parse(InputStream input) throws IOException {
- try {
- getParser();
- EndpointDescriptionsHandler endpointDescriptionsHandler = new EndpointDescriptionsHandler();
- xmlReader.setContentHandler(new EndpointDescriptionDocHandler(
- ENDPOINT_DESCRIPTIONS, endpointDescriptionsHandler));
- xmlReader.parse(new InputSource(input));
- endpointDescriptions = endpointDescriptionsHandler
- .getEndpointDescriptions();
- } catch (SAXException e) {
- throw new IOException(e.getMessage());
- } catch (ParserConfigurationException e) {
- throw new IOException(e.getMessage());
- } finally {
- input.close();
- }
-
- }
-
- public static String makeSimpleName(String localName, String qualifiedName) {
- if (localName != null && localName.length() > 0) {
- return localName;
- }
- int nameSpaceIndex = qualifiedName.indexOf(":"); //$NON-NLS-1$
- return (nameSpaceIndex == -1 ? qualifiedName : qualifiedName
- .substring(nameSpaceIndex + 1));
- }
-
- public void unexpectedElement(AbstractHandler handler, String element,
- Attributes attributes) {
- }
-
- public void unexpectedCharacterData(AbstractHandler handler, String cdata) {
- }
-
- public void unexpectedAttribute(String element, String attribute,
- String value) {
- }
-
- static int indexOf(String[] array, String value) {
- for (int i = 0; i < array.length; i += 1) {
- if (value == null ? array[i] == null : value.equals(array[i])) {
- return i;
- }
- }
- return -1;
- }
-
- public void checkRequiredAttribute(String element, String name, Object value) {
- }
-
- public void duplicateElement(AbstractHandler handler, String element,
- Attributes attributes) {
- // ignore the duplicate element entirely because we have already logged
- // it
- new IgnoringHandler(handler);
- }
-
- private List<EndpointDescription> endpointDescriptions;
-
- public List<EndpointDescription> getEndpointDescriptions() {
- return endpointDescriptions;
- }
-
-}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointListenerTrackerCustomizer.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointListenerTrackerCustomizer.java
deleted file mode 100644
index cadc65b7d..000000000
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/EndpointListenerTrackerCustomizer.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Composent, Inc. - initial API and implementation
- ******************************************************************************/
-package org.eclipse.ecf.internal.osgi.services.remoteserviceadmin;
-
-import java.util.Collection;
-
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.remoteserviceadmin.EndpointListener;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
-
-public class EndpointListenerTrackerCustomizer implements
- ServiceTrackerCustomizer {
-
- private Discovery discovery;
-
- public EndpointListenerTrackerCustomizer(Discovery discovery) {
- this.discovery = discovery;
- }
-
- public Object addingService(ServiceReference reference) {
- Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> allDiscoveredEndpointDescriptions = discovery
- .getAllDiscoveredEndpointDescriptions();
- EndpointListener listener = (EndpointListener) Activator.getContext()
- .getService(reference);
- if (listener == null)
- return null;
- for (org.osgi.service.remoteserviceadmin.EndpointDescription ed : allDiscoveredEndpointDescriptions) {
- Discovery.EndpointListenerHolder[] endpointListenerHolders = discovery
- .getMatchingEndpointListenerHolders(
- new ServiceReference[] { reference }, ed);
- if (endpointListenerHolders != null) {
- for (int i = 0; i < endpointListenerHolders.length; i++) {
- discovery.queueEndpointDescription(
- endpointListenerHolders[i].getListener(),
- endpointListenerHolders[i].getDescription(),
- endpointListenerHolders[i].getMatchingFilter(),
- true);
- }
- }
- }
- return listener;
- }
-
- public void modifiedService(ServiceReference reference, Object service) {
- }
-
- public void removedService(ServiceReference reference, Object service) {
- }
-
- public void close() {
- }
-
-}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/IDUtil.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/IDUtil.java
deleted file mode 100644
index 5334ee8b4..000000000
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/IDUtil.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Composent, Inc. - initial API and implementation
- ******************************************************************************/
-package org.eclipse.ecf.internal.osgi.services.remoteserviceadmin;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.ecf.core.identity.ID;
-import org.eclipse.ecf.core.identity.IDCreateException;
-import org.eclipse.ecf.core.identity.IDFactory;
-import org.eclipse.ecf.core.identity.IIDFactory;
-import org.eclipse.ecf.core.identity.Namespace;
-import org.eclipse.ecf.core.identity.StringID;
-import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription;
-
-public class IDUtil {
-
- public static IIDFactory getIDFactory() {
- return IDFactory.getDefault();
- }
-
- public static Namespace getNamespaceByName(String namespaceName) {
- if (namespaceName == null)
- return null;
- return getIDFactory().getNamespaceByName(namespaceName);
- }
-
- public static Namespace findNamespaceByIdName(String idName) {
- if (idName == null)
- return null;
- int colonIndex = idName.indexOf(Namespace.SCHEME_SEPARATOR);
- if (colonIndex <= 0)
- return null;
- String scheme = idName.substring(0, colonIndex);
- // First try to find the Namespace using the protocol directly
- Namespace ns = getNamespaceByName(scheme);
- if (ns == null) {
- // Then try to find by comparing to all Namespace.getScheme()
- ns = findNamespaceByScheme(scheme);
- }
- return ns;
- }
-
- public static Namespace findNamespaceByScheme(String scheme) {
- if (scheme == null)
- return null;
- if (scheme.equals("ecftcp"))
- return getIDFactory().getNamespaceByName(StringID.class.getName());
- List namespaces = getIDFactory().getNamespaces();
- for (Iterator i = namespaces.iterator(); i.hasNext();) {
- Namespace ns = (Namespace) i.next();
- if (scheme.equals(ns.getScheme())) {
- // found it...so return
- return ns;
- }
- }
- // If the scheme is "ecftcp" then we use StringID
- return null;
- }
-
- public static ID createID(Map<String, Object> osgiProperties,
- String namespaceName) throws IDCreateException {
- // We try to get the ID from the OSGi id
- String osgiIdName = PropertiesUtil
- .verifyStringProperty(
- osgiProperties,
- org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_ID);
- if (osgiIdName == null)
- throw new IDCreateException(
- org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_ID
- + " must not be null");
- return createID(namespaceName, osgiIdName);
- }
-
- public static ID createID(String namespaceName, String idName)
- throws IDCreateException {
- Namespace ns = (namespaceName == null) ? getNamespaceByName(namespaceName)
- : findNamespaceByIdName(idName);
- if (ns == null)
- throw new IDCreateException(
- "Cannot find Namespace for namespaceName=" + namespaceName
- + " and idName=" + idName);
- return createID(ns, idName);
- }
-
- public static ID createID(Namespace namespace, String idName)
- throws IDCreateException {
- return getIDFactory().createID(namespace, idName);
- }
-
- public static ID createContainerID(EndpointDescription endpointDescription)
- throws IDCreateException {
- return createID(endpointDescription.getContainerIDNamespace(),
- endpointDescription.getId());
- }
-
- public static ID createID(Namespace namespace, Object[] args)
- throws IDCreateException {
- return getIDFactory().createID(namespace, args);
- }
-}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/LocatorServiceListener.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/LocatorServiceListener.java
deleted file mode 100644
index aa1f051d7..000000000
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/LocatorServiceListener.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Composent, Inc. - initial API and implementation
- ******************************************************************************/
-package org.eclipse.ecf.internal.osgi.services.remoteserviceadmin;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.ecf.discovery.IDiscoveryLocator;
-import org.eclipse.ecf.discovery.IServiceEvent;
-import org.eclipse.ecf.discovery.IServiceInfo;
-import org.eclipse.ecf.discovery.IServiceListener;
-import org.eclipse.ecf.discovery.identity.IServiceID;
-import org.eclipse.ecf.osgi.services.remoteserviceadmin.DiscoveredEndpointDescription;
-import org.eclipse.ecf.osgi.services.remoteserviceadmin.IDiscoveredEndpointDescriptionFactory;
-import org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteConstants;
-
-class LocatorServiceListener implements IServiceListener {
-
- private Object listenerLock = new Object();
- private IDiscoveryLocator locator;
- private Discovery discovery;
-
- private List<org.osgi.service.remoteserviceadmin.EndpointDescription> discoveredEndpointDescriptions = new ArrayList();
-
- public LocatorServiceListener(Discovery discovery) {
- this(discovery, null);
- }
-
- public LocatorServiceListener(Discovery discovery, IDiscoveryLocator locator) {
- this.discovery = discovery;
- this.locator = locator;
- if (locator != null) {
- this.locator.addServiceListener(this);
- }
- }
-
- public void serviceDiscovered(IServiceEvent anEvent) {
- handleService(anEvent.getServiceInfo(), true);
- }
-
- public void serviceUndiscovered(IServiceEvent anEvent) {
- handleService(anEvent.getServiceInfo(), false);
- }
-
- private boolean matchServiceID(IServiceID serviceId) {
- if (Arrays.asList(serviceId.getServiceTypeID().getServices()).contains(
- RemoteConstants.SERVICE_TYPE))
- return true;
- return false;
- }
-
- void handleService(IServiceInfo serviceInfo, boolean discovered) {
- IServiceID serviceID = serviceInfo.getServiceID();
- if (matchServiceID(serviceID))
- handleOSGiServiceEndpoint(serviceID, serviceInfo, discovered);
- }
-
- private void handleOSGiServiceEndpoint(IServiceID serviceId,
- IServiceInfo serviceInfo, boolean discovered) {
- if (locator == null)
- return;
- DiscoveredEndpointDescription discoveredEndpointDescription = getDiscoveredEndpointDescription(
- serviceId, serviceInfo, discovered);
- if (discoveredEndpointDescription != null) {
- handleEndpointDescription(
- discoveredEndpointDescription.getEndpointDescription(),
- discovered);
- } else {
- logWarning("handleOSGiServiceEvent",
- "discoveredEndpointDescription is null for service info="
- + serviceInfo + ",discovered=" + discovered);
- }
- }
-
- public void handleEndpointDescription(
- org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription,
- boolean discovered) {
- synchronized (listenerLock) {
- if (discovered)
- discoveredEndpointDescriptions.add(endpointDescription);
- else
- discoveredEndpointDescriptions.remove(endpointDescription);
-
- discovery.queueEndpointDescription(endpointDescription, discovered);
- }
- }
-
- public Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> getEndpointDescriptions() {
- synchronized (listenerLock) {
- Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> result = new ArrayList<org.osgi.service.remoteserviceadmin.EndpointDescription>();
- result.addAll(discoveredEndpointDescriptions);
- return result;
- }
- }
-
- private void logWarning(String methodName, String message) {
- LogUtility.logWarning(methodName, DebugOptions.DISCOVERY,
- this.getClass(), message);
- }
-
- private void logError(String methodName, String message) {
- logError(methodName, message, null);
- }
-
- private void logError(String methodName, String message, Throwable t) {
- LogUtility.logError(methodName, DebugOptions.DISCOVERY,
- this.getClass(), message, t);
- }
-
- private DiscoveredEndpointDescription getDiscoveredEndpointDescription(
- IServiceID serviceId, IServiceInfo serviceInfo, boolean discovered) {
- // Get IEndpointDescriptionFactory
- final String methodName = "getDiscoveredEndpointDescription";
- IDiscoveredEndpointDescriptionFactory factory = discovery
- .getDiscoveredEndpointDescriptionFactory();
- if (factory == null) {
- logError(
- methodName,
- "No IEndpointDescriptionFactory found, could not create EndpointDescription for "
- + (discovered ? "discovered" : "undiscovered")
- + " serviceInfo=" + serviceInfo);
- return null;
- }
- try {
- // Else get endpoint description factory to create
- // EndpointDescription
- // for given serviceID and serviceInfo
- return (discovered) ? factory.createDiscoveredEndpointDescription(
- locator, serviceInfo) : factory
- .getUndiscoveredEndpointDescription(locator, serviceId);
- } catch (Exception e) {
- logError(
- methodName,
- "Exception calling IEndpointDescriptionFactory."
- + ((discovered) ? "createDiscoveredEndpointDescription"
- : "getUndiscoveredEndpointDescription"), e);
- return null;
- } catch (NoClassDefFoundError e) {
- logError(
- methodName,
- "NoClassDefFoundError calling IEndpointDescriptionFactory."
- + ((discovered) ? "createDiscoveredEndpointDescription"
- : "getUndiscoveredEndpointDescription"), e);
- return null;
- }
- }
-
- public synchronized void close() {
- if (locator != null) {
- locator.removeServiceListener(this);
- locator = null;
- }
- discovery = null;
- discoveredEndpointDescriptions.clear();
- }
-} \ No newline at end of file
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/LogUtility.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/LogUtility.java
deleted file mode 100644
index 5d3ab96ec..000000000
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/LogUtility.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Composent, Inc. - initial API and implementation
- ******************************************************************************/
-package org.eclipse.ecf.internal.osgi.services.remoteserviceadmin;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.ecf.core.util.Trace;
-
-public class LogUtility {
-
- public static void logError(String methodName, String debugOption,
- Class clazz, String message) {
- logError(methodName, debugOption, clazz, message, null);
- traceException(methodName, debugOption, clazz, message, null);
- }
-
- public static void logWarning(String methodName, String debugOption,
- Class clazz, String message) {
- trace(methodName, debugOption, clazz, "WARNING:" + message); //$NON-NLS-1$
- Activator.getDefault().log(
- new Status(IStatus.WARNING, Activator.PLUGIN_ID,
- IStatus.WARNING, clazz.getName() + ":" //$NON-NLS-1$
- + ((methodName == null) ? "<unknown>" //$NON-NLS-1$
- : methodName) + ":" //$NON-NLS-1$
- + ((message == null) ? "<empty>" : message), //$NON-NLS-1$
- null));
- }
-
- public static void logError(String methodName, String debugOption,
- Class clazz, String message, Throwable t) {
- if (t != null)
- traceException(methodName, debugOption, clazz, message, t);
- else
- trace(methodName, debugOption, clazz, message);
- Activator.getDefault().log(
- new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR,
- clazz.getName() + ":" //$NON-NLS-1$
- + ((methodName == null) ? "<unknown>" //$NON-NLS-1$
- : methodName) + ":" //$NON-NLS-1$
- + ((message == null) ? "<empty>" //$NON-NLS-1$
- : message), t));
- }
-
- public static void logWarning(String methodName, String debugOption,
- Class clazz, String message, Throwable t) {
- if (t != null)
- traceException(methodName, debugOption, clazz, message, t);
- else
- trace(methodName, debugOption, clazz, message);
- Activator.getDefault().log(
- new Status(IStatus.WARNING, Activator.PLUGIN_ID,
- IStatus.WARNING, clazz.getName() + ":" //$NON-NLS-1$
- + ((methodName == null) ? "<unknown>" //$NON-NLS-1$
- : methodName) + ":" //$NON-NLS-1$
- + ((message == null) ? "<empty>" //$NON-NLS-1$
- : message), t));
- }
-
- public static void logError(String methodName, String debugOption,
- Class clazz, IStatus status) {
- Throwable t = status.getException();
- if (t != null)
- traceException(methodName, debugOption, clazz, status.getMessage(),
- t);
- else
- trace(methodName, debugOption, clazz, status.getMessage());
- Activator.getDefault().log(status);
- }
-
- public static void logWarning(String methodName, String debugOption,
- Class clazz, IStatus status) {
- logError(methodName, debugOption, clazz, status);
- }
-
- public static void trace(String methodName, String debugOptions,
- Class clazz, String message) {
- Trace.trace(Activator.PLUGIN_ID, debugOptions, clazz, methodName,
- message);
- }
-
- public static void traceException(String methodName, String debugOption,
- Class clazz, String message, Throwable t) {
- Trace.catching(Activator.PLUGIN_ID, debugOption, clazz,
- ((methodName == null) ? "<unknown>" : methodName) + ":" //$NON-NLS-1$ //$NON-NLS-2$
- + ((message == null) ? "<empty>" : message), t); //$NON-NLS-1$
- }
-
-}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java
deleted file mode 100644
index a16cbba20..000000000
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Composent, Inc. - initial API and implementation
- ******************************************************************************/
-package org.eclipse.ecf.internal.osgi.services.remoteserviceadmin;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteConstants;
-import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
-import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration;
-import org.osgi.framework.ServiceReference;
-
-public class PropertiesUtil {
-
- protected static final List osgiProperties = Arrays
- .asList(new String[] {
- // OSGi properties
- org.osgi.framework.Constants.OBJECTCLASS,
- org.osgi.framework.Constants.SERVICE_ID,
- org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_FRAMEWORK_UUID,
- org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_ID,
- org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_SERVICE_ID,
- org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_CONFIGS_SUPPORTED,
- org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_INTENTS_SUPPORTED,
- org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_CONFIGS,
- org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_INTENTS,
- org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_INTENTS_EXTRA,
- org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_EXPORTED_INTERFACES,
- org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_IMPORTED,
- org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_IMPORTED_CONFIGS,
- org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_INTENTS });
-
- protected static final List ecfProperties = Arrays.asList(new String[] {
- // ECF properties
- RemoteConstants.DISCOVERY_DEFAULT_SERVICE_NAME_PREFIX,
- RemoteConstants.DISCOVERY_NAMING_AUTHORITY,
- RemoteConstants.DISCOVERY_PROTOCOLS,
- RemoteConstants.DISCOVERY_SCOPE,
- RemoteConstants.DISCOVERY_SERVICE_NAME,
- RemoteConstants.ENDPOINT_CONNECTTARGET_ID,
- RemoteConstants.ENDPOINT_CONNECTTARGET_ID_NAMESPACE,
- RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE,
- RemoteConstants.ENDPOINT_IDFILTER_IDS,
- RemoteConstants.ENDPOINT_IDFILTER_IDARRAY_COUNT,
- RemoteConstants.ENDPOINT_REMOTESERVICE_FILTER,
- RemoteConstants.ENDPOINT_SERVICE_IMPORTED_CONFIGS_VALUE,
- RemoteConstants.SERVICE_EXPORTED_CONTAINER_CONNECT_CONTEXT,
- RemoteConstants.SERVICE_EXPORTED_CONTAINER_FACTORY_ARGS,
- RemoteConstants.SERVICE_EXPORTED_CONTAINER_ID,
- RemoteConstants.SERVICE_TYPE });
-
- public static String verifyStringProperty(Map properties, String propName) {
- Object r = properties.get(propName);
- try {
- return (String) r;
- } catch (ClassCastException e) {
- IllegalArgumentException iae = new IllegalArgumentException(
- "property value is not a String: " + propName);
- iae.initCause(e);
- throw iae;
- }
- }
-
- public static Object getStringPlusValue(List<String> values) {
- if (values == null)
- return null;
- int valuesSize = values.size();
- switch (valuesSize) {
- case 0:
- return null;
- case 1:
- return values.get(0);
- default:
- return values.toArray(new String[valuesSize]);
- }
- }
-
- public static List getStringPlusProperty(Map properties, String key) {
- Object value = properties.get(key);
- if (value == null) {
- return Collections.EMPTY_LIST;
- }
-
- if (value instanceof String) {
- return Collections.singletonList((String) value);
- }
-
- if (value instanceof String[]) {
- String[] values = (String[]) value;
- List result = new ArrayList(values.length);
- for (int i = 0; i < values.length; i++) {
- if (values[i] != null) {
- result.add(values[i]);
- }
- }
- return Collections.unmodifiableList(result);
- }
-
- if (value instanceof Collection) {
- Collection values = (Collection) value;
- List result = new ArrayList(values.size());
- for (Iterator iter = values.iterator(); iter.hasNext();) {
- Object v = iter.next();
- if (v instanceof String) {
- result.add((String) v);
- }
- }
- return Collections.unmodifiableList(result);
- }
-
- return Collections.EMPTY_LIST;
- }
-
- public static boolean isOSGiProperty(String key) {
- return osgiProperties.contains(key)
- && !key.startsWith(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_PACKAGE_VERSION_);
- }
-
- public static boolean isECFProperty(String key) {
- return ecfProperties.contains(key)
- && !key.startsWith(RemoteConstants.ENDPOINT_IDFILTER_IDARRAY_NAME_)
- && !key.startsWith(RemoteConstants.ENDPOINT_IDFILTER_IDARRAY_NAMESPACE_);
- }
-
- public static boolean isReservedProperty(String key) {
- return isOSGiProperty(key) || isECFProperty(key);
- }
-
- public static Map createMapFromDictionary(Dictionary input) {
- if (input == null)
- return null;
- Map result = new HashMap();
- for (Enumeration e = input.keys(); e.hasMoreElements();) {
- Object key = e.nextElement();
- Object val = input.get(key);
- result.put(key, val);
- }
- return result;
- }
-
- public static Dictionary createDictionaryFromMap(Map propMap) {
- if (propMap == null)
- return null;
- Dictionary result = new Properties();
- for (Iterator i = propMap.keySet().iterator(); i.hasNext();) {
- Object key = i.next();
- Object val = propMap.get(key);
- result.put(key, val);
- }
- return result;
- }
-
- public static Long getLongWithDefault(Map props, String key, Long def) {
- Object o = props.get(key);
- if (o instanceof Long)
- return (Long) o;
- if (o instanceof String)
- return Long.valueOf((String) o);
- return def;
- }
-
- public static String[] getStringArrayWithDefault(
- Map<String, Object> properties, String key, String[] def) {
- Object o = properties.get(key);
- if (o instanceof String) {
- return new String[] { (String) o };
- } else if (o instanceof String[]) {
- return (String[]) o;
- } else if (o instanceof List) {
- List l = (List) o;
- return (String[]) l.toArray(new String[l.size()]);
- }
- return def;
- }
-
- public static String getStringWithDefault(Map props, String key, String def) {
- Object o = props.get(key);
- if (o == null || (!(o instanceof String)))
- return def;
- return (String) o;
- }
-
- public static Map<String, Object> copyProperties(
- ServiceReference serviceReference, Map<String, Object> target) {
- String[] keys = serviceReference.getPropertyKeys();
- for (int i = 0; i < keys.length; i++)
- target.put(keys[i], serviceReference.getProperty(keys[i]));
- return target;
- }
-
- public static Map<String, Object> copyProperties(
- IRemoteServiceRegistration rsRegistration,
- Map<String, Object> target) {
- String[] keys = rsRegistration.getPropertyKeys();
- for (int i = 0; i < keys.length; i++)
- target.put(keys[i], rsRegistration.getProperty(keys[i]));
- return target;
- }
-
- public static Map<String, Object> copyProperties(
- Map<String, Object> source, Map<String, Object> target) {
- for (String key : source.keySet())
- target.put(key, source.get(key));
- return target;
- }
-
- public static Map<String, Object> copyNonECFProperties(
- Map<String, Object> source, Map<String, Object> target) {
- for (String key : source.keySet())
- if (!isECFProperty(key))
- target.put(key, source.get(key));
- return target;
- }
-
- public static Map<String, Object> copyNonReservedProperties(
- Map<String, Object> source, Map<String, Object> target) {
- for (String key : source.keySet())
- if (!isReservedProperty(key))
- target.put(key, source.get(key));
- return target;
- }
-
- public static Map<String, Object> copyNonECFProperties(
- ServiceReference serviceReference, Map<String, Object> target) {
- String[] keys = serviceReference.getPropertyKeys();
- for (int i = 0; i < keys.length; i++)
- if (!isECFProperty(keys[i]))
- target.put(keys[i], serviceReference.getProperty(keys[i]));
- return target;
- }
-
- public static Map<String, Object> copyNonReservedProperties(
- ServiceReference serviceReference, Map<String, Object> target) {
- String[] keys = serviceReference.getPropertyKeys();
- for (int i = 0; i < keys.length; i++)
- if (!isReservedProperty(keys[i]))
- target.put(keys[i], serviceReference.getProperty(keys[i]));
- return target;
- }
-
- public static Map<String, Object> copyNonReservedProperties(
- IRemoteServiceReference rsReference, Map<String, Object> target) {
- String[] keys = rsReference.getPropertyKeys();
- for (int i = 0; i < keys.length; i++)
- if (!isReservedProperty(keys[i]))
- target.put(keys[i], rsReference.getProperty(keys[i]));
- return target;
- }
-
-}

Back to the top