Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2014-08-19 05:12:48 +0000
committerslewis2014-08-19 05:12:48 +0000
commit1a44e5883b1367bc9c0c26f985706a2e27296410 (patch)
treefeb81b042d61fab45deb9b0a3e783b7b807e9dc3
parent90dbf5a743988083fba2daf2f6420a2094e75df0 (diff)
downloadorg.eclipse.ecf-1a44e5883b1367bc9c0c26f985706a2e27296410.tar.gz
org.eclipse.ecf-1a44e5883b1367bc9c0c26f985706a2e27296410.tar.xz
org.eclipse.ecf-1a44e5883b1367bc9c0c26f985706a2e27296410.zip
Removed source, xml, and meta-data from obsolete bundle project
org.eclipse.ecf.provider.endpointdescription.localdiscovery Change-Id: Ib22fdd0afa7334c1b52339dd0e74bcd621f7e607
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/META-INF/MANIFEST.MF15
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/endpointdescription1.xml49
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/readme.txt1
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/Activator.java96
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionDiscoveryContainerAdapter.java195
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionParser.java792
6 files changed, 1 insertions, 1147 deletions
diff --git a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/META-INF/MANIFEST.MF b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/META-INF/MANIFEST.MF
index a8bc081cb..954dd5e85 100644
--- a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/META-INF/MANIFEST.MF
+++ b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/META-INF/MANIFEST.MF
@@ -4,20 +4,5 @@ Bundle-Name: %plugin.name
Bundle-Vendor: %plugin.provider
Bundle-SymbolicName: org.eclipse.ecf.provider.endpointdescription.localdiscovery;singleton:=true
Bundle-Version: 1.0.0.qualifier
-Bundle-Activator: org.eclipse.ecf.provider.internal.endpointdescription.localdiscovery.Activator
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Import-Package: org.eclipse.ecf.core;version="3.0.0",
- org.eclipse.ecf.core.identity;version="3.2.0",
- org.eclipse.ecf.core.provider,
- org.eclipse.ecf.core.security,
- org.eclipse.ecf.discovery;version="4.0.0",
- org.eclipse.ecf.discovery.identity,
- org.eclipse.ecf.osgi.services.remoteserviceadmin,
- org.eclipse.equinox.concurrent.future;version="1.0.0",
- org.osgi.framework;version="1.3.0",
- org.osgi.service.remoteserviceadmin;version="1.0",
- org.osgi.util.tracker
-Bundle-Localization: plugin
-Require-Bundle: org.eclipse.equinox.common
-Requre-Capability: osgi.extender; filter:=(&(osgi.extender=osgi.remoteserviceadmin) (version>=1.1)); effective:=active
diff --git a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/endpointdescription1.xml b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/endpointdescription1.xml
deleted file mode 100644
index 417554f5b..000000000
--- a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/endpointdescription1.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<endpoint-descriptions xmlns="http://www.osgi.org/xmlns/rsa/v1.0.0">
- <endpoint-description>
- <!-- osgi required endpoint description properties -->
- <property name="objectClass" value="com.acme.Foo"/>
- <property name="endpoint.service.id" value="100"/>
- <property name="endpoint.framework.uuid" value="frameworkid.1000"/>
- <property name="endpoint.id" value="http://ws.acme.com:9000/hello"/>
- <property name="service.imported.configs" value="com.acme"/>
-
- <!-- ecf required endpoint description properties -->
- <property name="ecf.endpoint.containerid" value="ecftcp://localhost:3283/server" />
- <property name="ecf.endpoint.containerid.namespace" value="org.eclipse.ecf.core.identity.StringID" />
- <property name="ecf.endpoint.remoteserviceid" value="1000" />
-
- <!-- osgi optional endpoint description properties -->
- <property name="endpoint.package.version.com.acme" value="4.2"/>
- <property name="service.imported.configs" value="com.acme"/>
- <property name="service.intents">
- <list>
- <value>SOAP</value>
- <value>HTTP</value>
- </list>
- </property>
- <property name="integers" value-type="int">
- <array>
- <value> 1 </value>
- <value>2</value>
- <value> 3 </value>
- </array>
- </property>
- <property name="floats" value-type="Float">
- <set>
- <value> 1.45 </value>
- <value>2.0</value>
- <value> 3 </value>
- </set>
- </property>
-
- <property name="com.acme.ws.xml">
- <xml>
- <config xmlns:cfg="http://acme.com/defs" foo="bar">
- <cfg:port>1029</cfg:port>
- <host>www.acme.com</host>
- </config>
- </xml>
- </property>
- </endpoint-description>
-</endpoint-descriptions>
diff --git a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/readme.txt b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/readme.txt
new file mode 100644
index 000000000..78ba67380
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/readme.txt
@@ -0,0 +1 @@
+This bundle is obsolete in favor of the RSA version >= 1.0
diff --git a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/Activator.java b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/Activator.java
deleted file mode 100644
index 13e5b5fe6..000000000
--- a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/Activator.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 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.provider.internal.endpointdescription.localdiscovery;
-
-import javax.xml.parsers.SAXParserFactory;
-
-import org.eclipse.ecf.osgi.services.remoteserviceadmin.IServiceInfoFactory;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.util.tracker.ServiceTracker;
-
-public class Activator implements BundleActivator {
-
- private static BundleContext context;
- private static Activator instance;
-
- private ServiceTracker parserTracker;
-
- private ServiceTracker serviceInfoFactoryTracker;
-
- static BundleContext getContext() {
- return context;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
- * )
- */
- public void start(BundleContext bundleContext) throws Exception {
- Activator.context = bundleContext;
- instance = this;
- }
-
- public synchronized IServiceInfoFactory getServiceInfoFactory() {
- if (instance == null)
- return null;
- if (serviceInfoFactoryTracker == null) {
- serviceInfoFactoryTracker = new ServiceTracker(context,
- IServiceInfoFactory.class.getName(), null);
- serviceInfoFactoryTracker.open();
- }
- return (IServiceInfoFactory) serviceInfoFactoryTracker.getService();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext bundleContext) throws Exception {
- closeServiceInfoFactoryTracker();
- closeSAXParserTracker();
- Activator.context = null;
- instance = null;
- }
-
- public static Activator getDefault() {
- return instance;
- }
-
- public synchronized SAXParserFactory getSAXParserFactory() {
- if (instance == null)
- return null;
- if (parserTracker == null) {
- parserTracker = new ServiceTracker(context,
- SAXParserFactory.class.getName(), null);
- parserTracker.open();
- }
- return (SAXParserFactory) parserTracker.getService();
- }
-
- private synchronized void closeSAXParserTracker() {
- if (parserTracker != null) {
- parserTracker.close();
- parserTracker = null;
- }
- }
-
- private synchronized void closeServiceInfoFactoryTracker() {
- if (serviceInfoFactoryTracker != null) {
- serviceInfoFactoryTracker.close();
- serviceInfoFactoryTracker = null;
- }
- }
-}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionDiscoveryContainerAdapter.java b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionDiscoveryContainerAdapter.java
deleted file mode 100644
index 8be5a2643..000000000
--- a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionDiscoveryContainerAdapter.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 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.provider.internal.endpointdescription.localdiscovery;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.ecf.core.ContainerConnectException;
-import org.eclipse.ecf.core.identity.ID;
-import org.eclipse.ecf.core.security.IConnectContext;
-import org.eclipse.ecf.discovery.AbstractDiscoveryContainerAdapter;
-import org.eclipse.ecf.discovery.DiscoveryContainerConfig;
-import org.eclipse.ecf.discovery.IServiceEvent;
-import org.eclipse.ecf.discovery.IServiceInfo;
-import org.eclipse.ecf.discovery.IServiceTypeEvent;
-import org.eclipse.ecf.discovery.identity.IServiceID;
-import org.eclipse.ecf.discovery.identity.IServiceTypeID;
-
-public class EndpointDescriptionDiscoveryContainerAdapter extends
- AbstractDiscoveryContainerAdapter {
-
- private Map<IServiceID, IServiceInfo> remoteServiceInfos;
-
- public EndpointDescriptionDiscoveryContainerAdapter(String aNamespaceName,
- DiscoveryContainerConfig aConfig) {
- super(aNamespaceName, aConfig);
- remoteServiceInfos = new HashMap<IServiceID, IServiceInfo>();
- }
-
- public IServiceInfo getServiceInfo(IServiceID aServiceID) {
- if (aServiceID == null)
- return null;
- synchronized (remoteServiceInfos) {
- return remoteServiceInfos.get(aServiceID);
- }
- }
-
- public IServiceInfo[] getServices() {
- Collection<IServiceInfo> results = new ArrayList<IServiceInfo>();
- synchronized (remoteServiceInfos) {
- for (IServiceInfo i : remoteServiceInfos.values())
- results.add(i);
- }
- return (IServiceInfo[]) results.toArray(new IServiceInfo[] {});
- }
-
- public IServiceInfo[] getServices(IServiceTypeID aServiceTypeID) {
- Collection<IServiceInfo> results = new ArrayList<IServiceInfo>();
- if (aServiceTypeID == null)
- return (IServiceInfo[]) results.toArray(new IServiceInfo[] {});
- synchronized (remoteServiceInfos) {
- for (IServiceInfo i : remoteServiceInfos.values()) {
- if (i.getServiceID().getServiceTypeID().equals(aServiceTypeID))
- results.add(i);
- }
- }
- return (IServiceInfo[]) results.toArray(new IServiceInfo[] {});
- }
-
- private Collection<IServiceTypeID> getServiceTypesAsCollection() {
- Collection<IServiceTypeID> results = new ArrayList<IServiceTypeID>();
- synchronized (remoteServiceInfos) {
- for (IServiceInfo i : remoteServiceInfos.values())
- results.add(i.getServiceID().getServiceTypeID());
- }
- return results;
- }
-
- public IServiceTypeID[] getServiceTypes() {
- return (IServiceTypeID[]) getServiceTypesAsCollection().toArray(
- new IServiceTypeID[] {});
- }
-
- public void registerService(IServiceInfo serviceInfo) {
- if (serviceInfo == null)
- throw new NullPointerException("serviceInfo cannot be null"); //$NON-NLS-1$
- addServiceInfo(serviceInfo);
- }
-
- private void addServiceInfo(IServiceInfo serviceInfo) {
- IServiceID serviceID = serviceInfo.getServiceID();
- IServiceInfo addResult = null;
- IServiceTypeID serviceTypeAdded = null;
- synchronized (remoteServiceInfos) {
- // First add..
- addResult = remoteServiceInfos.put(serviceID, serviceInfo);
- if (addResult == null) {
- Collection<IServiceTypeID> serviceTypes = getServiceTypesAsCollection();
- IServiceTypeID stID = serviceID.getServiceTypeID();
- if (serviceTypes.contains(stID))
- serviceTypeAdded = stID;
- }
- }
- if (serviceTypeAdded != null)
- fireServiceTypeDiscovered(createDiscoveredServiceTypeEvent(serviceTypeAdded));
- if (addResult == null)
- fireServiceDiscovered(createDiscoveredServiceEvent(serviceInfo));
- }
-
- private IServiceTypeEvent createDiscoveredServiceTypeEvent(
- final IServiceTypeID serviceTypeID) {
- return new IServiceTypeEvent() {
-
- public ID getLocalContainerID() {
- return getID();
- }
-
- public IServiceTypeID getServiceTypeID() {
- return serviceTypeID;
- }
- };
- }
-
- private IServiceEvent createDiscoveredServiceEvent(
- final IServiceInfo serviceInfo) {
- return new IServiceEvent() {
-
- public ID getLocalContainerID() {
- return getID();
- }
-
- public IServiceInfo getServiceInfo() {
- return serviceInfo;
- }
- };
- }
-
- public void unregisterService(IServiceInfo serviceInfo) {
- if (serviceInfo == null)
- throw new NullPointerException("serviceInfo cannot be null"); //$NON-NLS-1$
- removeServiceInfo(serviceInfo);
- }
-
- private void removeServiceInfo(IServiceInfo serviceInfo) {
- IServiceID serviceID = serviceInfo.getServiceID();
- IServiceInfo addResult = null;
- synchronized (remoteServiceInfos) {
- addResult = remoteServiceInfos.remove(serviceID);
- }
- if (addResult == null)
- fireServiceUndiscovered(createUndiscoveredServiceEvent(serviceInfo));
- }
-
- private IServiceEvent createUndiscoveredServiceEvent(
- final IServiceInfo serviceInfo) {
- return new IServiceEvent() {
-
- public ID getLocalContainerID() {
- return getID();
- }
-
- public IServiceInfo getServiceInfo() {
- return serviceInfo;
- }
- };
- }
-
- public void connect(ID targetID, IConnectContext connectContext)
- throws ContainerConnectException {
- // Do nothing...no connection
- }
-
- public ID getConnectedID() {
- return getID();
- }
-
- public void disconnect() {
- // No disconnection
- }
-
- @SuppressWarnings("rawtypes")
- public Object getAdapter(Class adapter) {
- // No adapters supported
- return null;
- }
-
- @Override
- public String getContainerName() {
- return "ecf.discovery.local"; //$NON-NLS-1$
- }
-
- public void dispose() {
- remoteServiceInfos.clear();
- super.dispose();
- }
-}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionParser.java b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionParser.java
deleted file mode 100644
index 0094835f2..000000000
--- a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionParser.java
+++ /dev/null
@@ -1,792 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 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.provider.internal.endpointdescription.localdiscovery;
-
-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;
- }
-
-}

Back to the top