diff options
author | slewis | 2007-09-05 19:27:05 +0000 |
---|---|---|
committer | slewis | 2007-09-05 19:27:05 +0000 |
commit | 7d965d115e1e9fa08777655b92c4f32a95c551e0 (patch) | |
tree | 8ab7d95a7743c732f6a06c507680039bd9afdca0 | |
parent | 77e9d1ba8f4ec8c0efc6be4c24e50f5ed822f44c (diff) | |
download | org.eclipse.ecf-7d965d115e1e9fa08777655b92c4f32a95c551e0.tar.gz org.eclipse.ecf-7d965d115e1e9fa08777655b92c4f32a95c551e0.tar.xz org.eclipse.ecf-7d965d115e1e9fa08777655b92c4f32a95c551e0.zip |
Code formatting, string externalization and miscellaneous cleanup.
12 files changed, 140 insertions, 194 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/.settings/org.eclipse.core.resources.prefs b/providers/bundles/org.eclipse.ecf.provider.jmdns/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index cda81003b..000000000 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Thu Nov 09 13:45:16 PST 2006 -eclipse.preferences.version=1 -encoding//src/org/eclipse/ecf/internal/provider/jmdns/messages.properties=8859_1 diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/META-INF/MANIFEST.MF b/providers/bundles/org.eclipse.ecf.provider.jmdns/META-INF/MANIFEST.MF index adde547b1..b84d20e89 100644 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/META-INF/MANIFEST.MF +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/META-INF/MANIFEST.MF @@ -18,5 +18,6 @@ Export-Package: com.strangeberry.jmdns.tools, org.eclipse.ecf.internal.provider.jmdns;x-internal:=true, org.eclipse.ecf.provider.jmdns.container, org.eclipse.ecf.provider.jmdns.identity -Import-Package: org.osgi.framework;version="1.3.0", +Import-Package: org.eclipse.osgi.util;version="1.1.0", + org.osgi.framework;version="1.3.0", org.osgi.util.tracker;version="1.3.2" diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/plugin.xml b/providers/bundles/org.eclipse.ecf.provider.jmdns/plugin.xml index 4581f4467..d232114f8 100644 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/plugin.xml +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/plugin.xml @@ -15,7 +15,7 @@ <namespace class="org.eclipse.ecf.provider.jmdns.identity.JMDNSNamespace" description="JMDNS Namespace" - name="zeroconf.jmdns"/> + name="ecf.namespace.jmdns"/> </extension> </plugin> diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/JMDNSDebugOptions.java b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/JMDNSDebugOptions.java index fe1409605..4389e1696 100644 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/JMDNSDebugOptions.java +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/JMDNSDebugOptions.java @@ -10,15 +10,11 @@ package org.eclipse.ecf.internal.provider.jmdns; public interface JMDNSDebugOptions { - public static final String DEBUG = JMDNSPlugin.getDefault().getBundle() - .getSymbolicName() - + "/debug"; //$NON-NLS-1$ + public static final String DEBUG = JMDNSPlugin.getDefault().getBundle().getSymbolicName() + "/debug"; //$NON-NLS-1$ - public static final String EXCEPTIONS_CATCHING = DEBUG - + "/exceptions/catching"; //$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 EXCEPTIONS_THROWING = DEBUG + "/exceptions/throwing"; //$NON-NLS-1$ public static final String METHODS_ENTERING = DEBUG + "/methods/entering"; //$NON-NLS-1$ diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/JMDNSPlugin.java b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/JMDNSPlugin.java index b44d0b41e..a91aa7ddd 100644 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/JMDNSPlugin.java +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/JMDNSPlugin.java @@ -25,11 +25,8 @@ public class JMDNSPlugin implements BundleActivator { private static JMDNSPlugin plugin; private BundleContext context = null; - - public static final String PLUGIN_ID = "org.eclipse.ecf.provider.jmdns"; - - public static final String NAMESPACE_IDENTIFIER = Messages - .getString("JMDNSPlugin.namespace.identifier"); //$NON-NLS-1$ + + public static final String PLUGIN_ID = "org.eclipse.ecf.provider.jmdns"; //$NON-NLS-1$ /** * The constructor. @@ -44,12 +41,10 @@ public class JMDNSPlugin implements BundleActivator { public IAdapterManager getAdapterManager() { // First, try to get the adapter manager via if (adapterManagerTracker == null) { - adapterManagerTracker = new ServiceTracker(this.context, - IAdapterManager.class.getName(), null); + adapterManagerTracker = new ServiceTracker(this.context, IAdapterManager.class.getName(), null); adapterManagerTracker.open(); } - IAdapterManager adapterManager = (IAdapterManager) adapterManagerTracker - .getService(); + IAdapterManager adapterManager = (IAdapterManager) adapterManagerTracker.getService(); // Then, if the service isn't there, try to get from Platform class via // PlatformHelper class if (adapterManager == null) @@ -65,9 +60,12 @@ public class JMDNSPlugin implements BundleActivator { } protected Bundle getBundle() { - if (context == null) return null; - else return context.getBundle(); + if (context == null) + return null; + else + return context.getBundle(); } + /** * This method is called when the plug-in is stopped */ @@ -90,8 +88,4 @@ public class JMDNSPlugin implements BundleActivator { return plugin; } - public String getNamespaceIdentifier() { - return NAMESPACE_IDENTIFIER; - } - } diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/Messages.java b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/Messages.java index bda516eb9..1cde53681 100644 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/Messages.java +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/Messages.java @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2004 Composent, Inc. and others. + * Copyright (c) 2007 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 @@ -8,24 +8,27 @@ * Contributors: * Composent, Inc. - initial API and implementation *****************************************************************************/ + package org.eclipse.ecf.internal.provider.jmdns; -import java.util.MissingResourceException; -import java.util.ResourceBundle; +import org.eclipse.osgi.util.NLS; -public class Messages { +/** + * + */ +public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.ecf.internal.provider.jmdns.messages"; //$NON-NLS-1$ - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle - .getBundle(BUNDLE_NAME); - - private Messages() { + public static String ContainerInstantiator_EXCEPTION_CONTAINER_CREATE; + public static String ContainerInstantiator_EXCEPTION_GETTING_INETADDRESS; + public static String JMDNSDiscoveryContainer_EXCEPTION_ALREADY_CONNECTED; + public static String JMDNSDiscoveryContainer_EXCEPTION_CREATE_JMDNS_INSTANCE; + public static String JMDNSDiscoveryContainer_EXCEPTION_REGISTER_SERVICE; + public static String JMDNSDiscoveryContainer_JMDNS_LOCAL_SUFFIX; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); } - public static String getString(String key) { - try { - return RESOURCE_BUNDLE.getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } + private Messages() { } } diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/messages.properties b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/messages.properties index 95270b46b..a52ee55d8 100644 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/messages.properties +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/messages.properties @@ -1 +1,6 @@ -JMDNSPlugin.namespace.identifier=zeroconf.jmdns +JMDNSDiscoveryContainer_EXCEPTION_ALREADY_CONNECTED=Already connected +JMDNSDiscoveryContainer_EXCEPTION_CREATE_JMDNS_INSTANCE=Exception creating JmDNS instance +JMDNSDiscoveryContainer_JMDNS_LOCAL_SUFFIX=.local. +JMDNSDiscoveryContainer_EXCEPTION_REGISTER_SERVICE=registerService +ContainerInstantiator_EXCEPTION_CONTAINER_CREATE=Exception making JMDNS container +ContainerInstantiator_EXCEPTION_GETTING_INETADDRESS=Exception getting InetAddress for JMDNS container diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/ContainerInstantiator.java b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/ContainerInstantiator.java index 8ca3bcca9..c3addb140 100644 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/ContainerInstantiator.java +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/ContainerInstantiator.java @@ -18,6 +18,7 @@ import org.eclipse.ecf.core.IContainer; import org.eclipse.ecf.core.identity.IDCreateException; import org.eclipse.ecf.core.provider.IContainerInstantiator; import org.eclipse.ecf.discovery.IDiscoveryContainerAdapter; +import org.eclipse.ecf.internal.provider.jmdns.Messages; public class ContainerInstantiator implements IContainerInstantiator { @@ -25,31 +26,26 @@ public class ContainerInstantiator implements IContainerInstantiator { super(); } - public IContainer createInstance(ContainerTypeDescription description, - Object[] args) throws ContainerCreateException { + public IContainer createInstance(ContainerTypeDescription description, Object[] args) throws ContainerCreateException { try { JMDNSDiscoveryContainer container = new JMDNSDiscoveryContainer(); return container; } catch (IDCreateException e) { - ContainerCreateException excep = new ContainerCreateException( - "Exception making JMDNS container"); + ContainerCreateException excep = new ContainerCreateException(Messages.ContainerInstantiator_EXCEPTION_CONTAINER_CREATE); excep.setStackTrace(e.getStackTrace()); throw excep; } catch (IOException e) { - ContainerCreateException excep = new ContainerCreateException( - "Exception getting InetAddress for JMDNS container"); + ContainerCreateException excep = new ContainerCreateException(Messages.ContainerInstantiator_EXCEPTION_GETTING_INETADDRESS); excep.setStackTrace(e.getStackTrace()); throw excep; } } - public String[] getSupportedAdapterTypes( - ContainerTypeDescription description) { - return new String[] { IDiscoveryContainerAdapter.class.getName() }; + public String[] getSupportedAdapterTypes(ContainerTypeDescription description) { + return new String[] {IDiscoveryContainerAdapter.class.getName()}; } - public Class[][] getSupportedParameterTypes( - ContainerTypeDescription description) { + public Class[][] getSupportedParameterTypes(ContainerTypeDescription description) { return new Class[0][0]; } diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSDiscoveryContainer.java b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSDiscoveryContainer.java index 5b2c7a81f..5068113f0 100644 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSDiscoveryContainer.java +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSDiscoveryContainer.java @@ -52,37 +52,32 @@ import org.eclipse.ecf.discovery.service.IDiscoveryService; import org.eclipse.ecf.internal.provider.jmdns.JMDNSDebugOptions; import org.eclipse.ecf.internal.provider.jmdns.JMDNSPlugin; import org.eclipse.ecf.internal.provider.jmdns.Messages; +import org.eclipse.ecf.provider.jmdns.identity.JMDNSNamespace; import org.eclipse.ecf.provider.jmdns.identity.JMDNSServiceID; -public class JMDNSDiscoveryContainer extends AbstractContainer implements IContainer, - IDiscoveryService, ServiceListener, ServiceTypeListener { +public class JMDNSDiscoveryContainer extends AbstractContainer implements IContainer, IDiscoveryService, ServiceListener, ServiceTypeListener { public static final int DEFAULT_REQUEST_TIMEOUT = 3000; - protected static String JMDNS_NAMESPACE_ID = Messages - .getString("JMDNSPlugin.namespace.identifier"); //$NON-NLS-1$; - private ContainerConfig config = null; + private static int instanceCount = 0; + + private ID localID = null; private InetAddress intf = null; private JmDNS jmdns = null; - private Map serviceListeners = new HashMap(); - private Vector serviceTypeListeners = new Vector(); + private final Map serviceListeners = new HashMap(); + private final Vector serviceTypeListeners = new Vector(); public JMDNSDiscoveryContainer() throws IOException, IDCreateException { this(null); } public ID getID() { - if (config == null) - return null; - else - return config.getID(); + return localID; } - public JMDNSDiscoveryContainer(InetAddress addr) throws IOException, - IDCreateException { + public JMDNSDiscoveryContainer(InetAddress addr) throws IOException, IDCreateException { super(); intf = (addr == null) ? InetAddress.getLocalHost() : addr; - this.config = new ContainerConfig(IDFactory.getDefault() - .createStringID(JMDNSDiscoveryContainer.class.getName())); + this.localID = IDFactory.getDefault().createStringID(intf.toString() + ";" + instanceCount++); //$NON-NLS-1$ } /* (non-Javadoc) @@ -117,42 +112,39 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta } protected void fireServiceAdded(ServiceEvent arg0) { - IServiceInfo iinfo = createIServiceInfoFromServiceEvent(arg0); + final IServiceInfo iinfo = createIServiceInfoFromServiceEvent(arg0); synchronized (serviceListeners) { - Vector v = (Vector) serviceListeners.get(arg0.getType()); + final Vector v = (Vector) serviceListeners.get(arg0.getType()); if (v != null) { - for (Iterator i = v.iterator(); i.hasNext();) { - IServiceListener l = (IServiceListener) i.next(); - l.serviceAdded(new ServiceContainerEvent(iinfo, config - .getID())); + for (final Iterator i = v.iterator(); i.hasNext();) { + final IServiceListener l = (IServiceListener) i.next(); + l.serviceAdded(new ServiceContainerEvent(iinfo, getID())); } } } } protected void fireServiceRemoved(ServiceEvent arg0) { - IServiceInfo iinfo = createIServiceInfoFromServiceEvent(arg0); + final IServiceInfo iinfo = createIServiceInfoFromServiceEvent(arg0); synchronized (serviceListeners) { - Vector v = (Vector) serviceListeners.get(arg0.getType()); + final Vector v = (Vector) serviceListeners.get(arg0.getType()); if (v != null) { - for (Iterator i = v.iterator(); i.hasNext();) { - IServiceListener l = (IServiceListener) i.next(); - l.serviceRemoved(new ServiceContainerEvent(iinfo, config - .getID())); + for (final Iterator i = v.iterator(); i.hasNext();) { + final IServiceListener l = (IServiceListener) i.next(); + l.serviceRemoved(new ServiceContainerEvent(iinfo, getID())); } } } } protected void fireServiceResolved(ServiceEvent arg0) { - IServiceInfo iinfo = createIServiceInfoFromServiceEvent(arg0); + final IServiceInfo iinfo = createIServiceInfoFromServiceEvent(arg0); synchronized (serviceListeners) { - Vector v = (Vector) serviceListeners.get(arg0.getType()); + final Vector v = (Vector) serviceListeners.get(arg0.getType()); if (v != null) { - for (Iterator i = v.iterator(); i.hasNext();) { - IServiceListener l = (IServiceListener) i.next(); - l.serviceResolved(new ServiceContainerEvent(iinfo, config - .getID())); + for (final Iterator i = v.iterator(); i.hasNext();) { + final IServiceListener l = (IServiceListener) i.next(); + l.serviceResolved(new ServiceContainerEvent(iinfo, getID())); } } } @@ -160,11 +152,9 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta protected void fireServiceTypeAdded(ServiceEvent arg0) { synchronized (serviceTypeListeners) { - for (Iterator i = serviceTypeListeners.iterator(); i.hasNext();) { - IServiceTypeListener l = (IServiceTypeListener) i.next(); - l.serviceTypeAdded(new ServiceContainerEvent( - createIServiceInfoFromServiceEvent(arg0), config - .getID())); + for (final Iterator i = serviceTypeListeners.iterator(); i.hasNext();) { + final IServiceTypeListener l = (IServiceTypeListener) i.next(); + l.serviceTypeAdded(new ServiceContainerEvent(createIServiceInfoFromServiceEvent(arg0), getID())); } } } @@ -173,25 +163,18 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta * @see org.eclipse.ecf.core.IContainer#getConnectedID() */ public ID getConnectedID() { - return null; + return getID(); } /* (non-Javadoc) * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServiceInfo(org.eclipse.ecf.discovery.identity.IServiceID, int) */ public IServiceInfo getServiceInfo(IServiceID service, int timeout) { - Trace.entering(JMDNSPlugin.PLUGIN_ID, - JMDNSDebugOptions.METHODS_ENTERING, this.getClass(), - "getServiceInfo", - new Object[] { service, new Integer(timeout) }); + Trace.entering(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.METHODS_ENTERING, this.getClass(), "getServiceInfo", new Object[] {service, new Integer(timeout)}); //$NON-NLS-1$ IServiceInfo result = null; if (jmdns != null) - result = createIServiceInfoFromServiceInfo(jmdns - .getServiceInfo(service.getServiceType(), service - .getServiceName(), timeout)); - Trace.exiting(JMDNSPlugin.PLUGIN_ID, - JMDNSDebugOptions.METHODS_ENTERING, this.getClass(), - "getServiceInfo", result); + result = createIServiceInfoFromServiceInfo(jmdns.getServiceInfo(service.getServiceType(), service.getServiceName(), timeout)); + Trace.exiting(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.METHODS_ENTERING, this.getClass(), "getServiceInfo", result); //$NON-NLS-1$ return result; } @@ -201,7 +184,7 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta public IServiceInfo[] getServices(String type) { IServiceInfo svs[] = new IServiceInfo[0]; if (jmdns != null) { - ServiceInfo[] svcs = jmdns.list(type); + final ServiceInfo[] svcs = jmdns.list(type); if (svcs != null) { svs = new IServiceInfo[svcs.length]; for (int i = 0; i < svcs.length; i++) { @@ -215,22 +198,19 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta /* (non-Javadoc) * @see org.eclipse.ecf.core.IContainer#connect(org.eclipse.ecf.core.identity.ID, org.eclipse.ecf.core.security.IConnectContext) */ - public void connect(ID groupID, IConnectContext joinContext) - throws ContainerConnectException { + public void connect(ID groupID, IConnectContext joinContext) throws ContainerConnectException { if (this.jmdns != null) - throw new ContainerConnectException("Already connected"); - fireContainerEvent(new ContainerConnectingEvent(this.getID(), groupID, - joinContext)); + throw new ContainerConnectException(Messages.JMDNSDiscoveryContainer_EXCEPTION_ALREADY_CONNECTED); + fireContainerEvent(new ContainerConnectingEvent(this.getID(), groupID, joinContext)); try { this.jmdns = new JmDNS(intf); jmdns.addServiceTypeListener(this); if (groupID != null && groupID instanceof JMDNSServiceID) { - ServiceID svcid = (ServiceID) groupID; + final ServiceID svcid = (ServiceID) groupID; jmdns.addServiceListener(svcid.getServiceType(), this); } - } catch (IOException e) { - ContainerConnectException soe = new ContainerConnectException( - "Exception creating JmDNS instance"); + } catch (final IOException e) { + final ContainerConnectException soe = new ContainerConnectException(Messages.JMDNSDiscoveryContainer_EXCEPTION_CREATE_JMDNS_INSTANCE); throw soe; } fireContainerEvent(new ContainerConnectedEvent(this.getID(), groupID)); @@ -240,41 +220,35 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta * @see org.eclipse.ecf.core.IContainer#disconnect() */ public void disconnect() { - fireContainerEvent(new ContainerDisconnectingEvent(this.getID(), - getConnectedID())); + fireContainerEvent(new ContainerDisconnectingEvent(this.getID(), getConnectedID())); if (this.jmdns != null) { jmdns.close(); jmdns = null; } - fireContainerEvent(new ContainerDisconnectedEvent(this.getID(), - getConnectedID())); + fireContainerEvent(new ContainerDisconnectedEvent(this.getID(), getConnectedID())); } protected IServiceInfo createIServiceInfoFromServiceEvent(ServiceEvent event) { - ServiceID sID = createServiceID(event.getType(), event.getName()); - ServiceInfo sinfo = event.getInfo(); + final ServiceID sID = createServiceID(event.getType(), event.getName()); + final ServiceInfo sinfo = event.getInfo(); if (sinfo != null) { return createIServiceInfoFromServiceInfo(sinfo); } - IServiceInfo newInfo = new JMDNSServiceInfo(null, sID, -1, -1, -1, - new ServiceProperties()); + final IServiceInfo newInfo = new JMDNSServiceInfo(null, sID, -1, -1, -1, new ServiceProperties()); return newInfo; } - protected IServiceInfo createIServiceInfoFromServiceInfo( - final ServiceInfo serviceInfo) { + protected IServiceInfo createIServiceInfoFromServiceInfo(final ServiceInfo serviceInfo) { if (serviceInfo == null) return null; - ServiceID sID = createServiceID(serviceInfo.getType(), serviceInfo - .getName()); - InetAddress addr = serviceInfo.getAddress(); - int port = serviceInfo.getPort(); - int priority = serviceInfo.getPriority(); - int weight = serviceInfo.getWeight(); - Properties props = new Properties(); - for (Enumeration e = serviceInfo.getPropertyNames(); e - .hasMoreElements();) { - String name = (String) e.nextElement(); + final ServiceID sID = createServiceID(serviceInfo.getType(), serviceInfo.getName()); + final InetAddress addr = serviceInfo.getAddress(); + final int port = serviceInfo.getPort(); + final int priority = serviceInfo.getPriority(); + final int weight = serviceInfo.getWeight(); + final Properties props = new Properties(); + for (final Enumeration e = serviceInfo.getPropertyNames(); e.hasMoreElements();) { + final String name = (String) e.nextElement(); Object value = serviceInfo.getPropertyString(name); if (value == null) value = serviceInfo.getPropertyBytes(name); @@ -282,7 +256,7 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta props.put(name, value); } final ServiceProperties svcProperties = new ServiceProperties(props); - IServiceProperties newProps = new IServiceProperties() { + final IServiceProperties newProps = new IServiceProperties() { public Enumeration getPropertyNames() { return svcProperties.getPropertyNames(); } @@ -311,52 +285,44 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta return svcProperties.setPropertyString(name, value); } }; - IServiceInfo newInfo = new JMDNSServiceInfo(addr, sID, port, priority, - weight, newProps); + final IServiceInfo newInfo = new JMDNSServiceInfo(addr, sID, port, priority, weight, newProps); return newInfo; } protected ServiceID createServiceID(String type, String name) { ServiceID id = null; try { - id = (ServiceID) IDFactory.getDefault().createID( - JMDNS_NAMESPACE_ID, new Object[] { type, name }); - } catch (IDCreateException e) { + id = (ServiceID) IDFactory.getDefault().createID(JMDNSNamespace.NAME, new Object[] {type, name}); + } catch (final IDCreateException e) { // Should never happen - Trace.catching(JMDNSPlugin.PLUGIN_ID, - JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), - "createServiceID", e); + Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "createServiceID", e); //$NON-NLS-1$ } return id; } - protected ServiceInfo createServiceInfoFromIServiceInfo( - IServiceInfo serviceInfo) { + protected ServiceInfo createServiceInfoFromIServiceInfo(IServiceInfo serviceInfo) { if (serviceInfo == null) return null; - IServiceID sID = serviceInfo.getServiceID(); - Hashtable props = new Hashtable(); - IServiceProperties svcProps = serviceInfo.getServiceProperties(); + final IServiceID sID = serviceInfo.getServiceID(); + final Hashtable props = new Hashtable(); + final IServiceProperties svcProps = serviceInfo.getServiceProperties(); if (svcProps != null) { - for (Enumeration e = svcProps.getPropertyNames(); e - .hasMoreElements();) { - String key = (String) e.nextElement(); - Object val = svcProps.getProperty(key); + for (final Enumeration e = svcProps.getPropertyNames(); e.hasMoreElements();) { + final String key = (String) e.nextElement(); + final Object val = svcProps.getProperty(key); if (val != null) { props.put(key, val); } } } - ServiceInfo si = new ServiceInfo(sID.getServiceType(), sID - .getServiceName(), serviceInfo.getPort(), serviceInfo - .getPriority(), serviceInfo.getWeight(), props); + final ServiceInfo si = new ServiceInfo(sID.getServiceType(), sID.getServiceName(), serviceInfo.getPort(), serviceInfo.getPriority(), serviceInfo.getWeight(), props); return si; } protected String prepareSvcTypeForBonjour(String svcType) { String result = svcType; - if (svcType.endsWith(".local.")) { - result = svcType.substring(0, svcType.indexOf(".local.")); + if (svcType.endsWith(Messages.JMDNSDiscoveryContainer_JMDNS_LOCAL_SUFFIX)) { + result = svcType.substring(0, svcType.indexOf(Messages.JMDNSDiscoveryContainer_JMDNS_LOCAL_SUFFIX)); } return result; } @@ -367,8 +333,8 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta public void registerService(IServiceInfo serviceInfo) throws ECFException { try { registerServiceWithJmDNS(serviceInfo); - } catch (IOException e) { - throw new ECFException("registerService",e); + } catch (final IOException e) { + throw new ECFException(Messages.JMDNSDiscoveryContainer_EXCEPTION_REGISTER_SERVICE, e); } } @@ -382,11 +348,9 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta } } - protected void registerServiceWithJmDNS(IServiceInfo serviceInfo) - throws IOException { + protected void registerServiceWithJmDNS(IServiceInfo serviceInfo) throws IOException { if (jmdns != null) { - jmdns - .registerService(createServiceInfoFromIServiceInfo(serviceInfo)); + jmdns.registerService(createServiceInfoFromIServiceInfo(serviceInfo)); } } @@ -397,7 +361,7 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta if (type == null || listener == null) return; synchronized (serviceListeners) { - Vector v = (Vector) serviceListeners.get(type); + final Vector v = (Vector) serviceListeners.get(type); if (v == null) { return; } @@ -417,8 +381,7 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta */ public void requestServiceInfo(IServiceID service, int timeout) { if (jmdns != null) { - jmdns.requestServiceInfo(service.getServiceType(), service - .getServiceName(), timeout); + jmdns.requestServiceInfo(service.getServiceType(), service.getServiceName(), timeout); } } @@ -426,10 +389,8 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta if (jmdns != null) { try { fireServiceAdded(arg0); - } catch (Exception e) { - Trace.catching(JMDNSPlugin.PLUGIN_ID, - JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), - "serviceAdded", e); + } catch (final Exception e) { + Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "serviceAdded", e); //$NON-NLS-1$ } } } @@ -438,10 +399,8 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta if (jmdns != null) { try { fireServiceRemoved(arg0); - } catch (Exception e) { - Trace.catching(JMDNSPlugin.PLUGIN_ID, - JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), - "serviceRemoved", e); + } catch (final Exception e) { + Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "serviceRemoved", e); //$NON-NLS-1$ } } } @@ -450,10 +409,8 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta if (jmdns != null) { try { fireServiceResolved(arg0); - } catch (Exception e) { - Trace.catching(JMDNSPlugin.PLUGIN_ID, - JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), - "serviceResolved", e); + } catch (final Exception e) { + Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "serviceResolved", e); //$NON-NLS-1$ } } } @@ -462,10 +419,8 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta if (jmdns != null) { try { fireServiceTypeAdded(arg0); - } catch (Exception e) { - Trace.catching(JMDNSPlugin.PLUGIN_ID, - JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), - "serviceResolved", e); + } catch (final Exception e) { + Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "serviceResolved", e); //$NON-NLS-1$ } } } @@ -475,8 +430,7 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta */ public void unregisterService(IServiceInfo serviceInfo) { if (jmdns != null) { - jmdns - .unregisterService(createServiceInfoFromIServiceInfo(serviceInfo)); + jmdns.unregisterService(createServiceInfoFromIServiceInfo(serviceInfo)); } } @@ -484,7 +438,7 @@ public class JMDNSDiscoveryContainer extends AbstractContainer implements IConta * @see org.eclipse.ecf.core.IContainer#getConnectNamespace() */ public Namespace getConnectNamespace() { - return IDFactory.getDefault().getNamespaceByName(JMDNS_NAMESPACE_ID); + return IDFactory.getDefault().getNamespaceByName(JMDNSNamespace.NAME); } } diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSServiceInfo.java b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSServiceInfo.java index 6d04caa92..aeae537c8 100644 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSServiceInfo.java +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSServiceInfo.java @@ -19,17 +19,15 @@ import org.eclipse.ecf.discovery.identity.ServiceID; public class JMDNSServiceInfo extends ServiceInfo { private static final long serialVersionUID = -5229813165370975600L; - public static final String PROP_PROTOCOL_NAME = "protocol"; - public static final String PROP_PATH_NAME = "path"; - public static final String SLASH = "/"; + public static final String PROP_PROTOCOL_NAME = "protocol"; //$NON-NLS-1$ + public static final String PROP_PATH_NAME = "path"; //$NON-NLS-1$ + public static final String SLASH = "/"; //$NON-NLS-1$ - public JMDNSServiceInfo(InetAddress address, ServiceID id, int port, - int priority, int weight, IServiceProperties props) { + public JMDNSServiceInfo(InetAddress address, ServiceID id, int port, int priority, int weight, IServiceProperties props) { super(address, id, port, priority, weight, props); } - public JMDNSServiceInfo(InetAddress address, String type, int port, - int priority, int weight, IServiceProperties props) { + public JMDNSServiceInfo(InetAddress address, String type, int port, int priority, int weight, IServiceProperties props) { super(address, type, port, priority, weight, props); } diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSNamespace.java b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSNamespace.java index dff5d6363..25f6b745a 100644 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSNamespace.java +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSNamespace.java @@ -17,10 +17,12 @@ import org.eclipse.ecf.core.identity.Namespace; public class JMDNSNamespace extends Namespace { private static final long serialVersionUID = 1L; - private static final String JMDNS_SCHEME = "jmdns"; + private static final String JMDNS_SCHEME = "jmdns"; //$NON-NLS-1$ + + public static final String NAME = "ecf.namespace.jmdns"; //$NON-NLS-1$ public ID createInstance(Object[] args) throws IDCreateException { - String type = (String) args[0]; + final String type = (String) args[0]; String name = null; if (args.length > 1) { name = (String) args[1]; @@ -38,6 +40,6 @@ public class JMDNSNamespace extends Namespace { * @see org.eclipse.ecf.core.identity.Namespace#getSupportedParameterTypesForCreateInstance() */ public Class[][] getSupportedParameterTypes() { - return new Class[][] { { String.class }, { String.class, String.class } }; + return new Class[][] { {String.class}, {String.class, String.class}}; } } diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSServiceID.java b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSServiceID.java index 5e3df809b..f9c8e3cb5 100644 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSServiceID.java +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSServiceID.java @@ -15,7 +15,7 @@ import org.eclipse.ecf.discovery.identity.ServiceID; public class JMDNSServiceID extends ServiceID { - private static final String DELIMITER = "."; + private static final String DELIMITER = "."; //$NON-NLS-1$ private static final long serialVersionUID = 1L; public JMDNSServiceID(Namespace namespace, String type, String name) { |