From 8f89f16ccc43b38cdb42f64efc7396aa64b9a1f7 Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 2 Sep 2009 22:09:41 +0000 Subject: Remove the need to extend EndpointDescription git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@810712 13f79535-47bb-0310-9956-ffa450edef68 --- .../discovery/impl/DomainDiscoveryService.java | 8 +- .../discovery/impl/LocalDiscoveryService.java | 3 +- .../remoteadmin/impl/EndpointDescriptionImpl.java | 148 --------------------- .../service/remoteadmin/impl/EndpointHelper.java | 67 ++++++++++ .../remoteadmin/impl/EndpointIntrospector.java | 9 +- .../remoteadmin/impl/OSGiServiceExporter.java | 4 +- .../remoteadmin/impl/RemoteControllerImpl.java | 2 +- .../calculator/dosgi/sca/META-INF/MANIFEST.MF | 2 + .../dosgi/sca/OSGI-INF/sca/calculator.composite | 2 +- 9 files changed, 80 insertions(+), 165 deletions(-) delete mode 100644 java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointDescriptionImpl.java create mode 100644 java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointHelper.java (limited to 'java/sca/modules/node-impl-osgi') diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java index cd091f3258..d9c88d3071 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java @@ -19,12 +19,13 @@ package org.apache.tuscany.sca.osgi.service.discovery.impl; +import static org.apache.tuscany.sca.osgi.service.remoteadmin.impl.EndpointHelper.createEndpointDescription; + import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation; import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription; -import org.apache.tuscany.sca.osgi.service.remoteadmin.impl.EndpointDescriptionImpl; import org.apache.tuscany.sca.runtime.EndpointListener; import org.apache.tuscany.sca.runtime.EndpointRegistry; import org.osgi.framework.BundleContext; @@ -82,11 +83,6 @@ public class DomainDiscoveryService extends AbstractDiscoveryService implements } } - private EndpointDescription createEndpointDescription(Endpoint endpoint) { - EndpointDescription description = new EndpointDescriptionImpl(endpoint); - return description; - } - public void endpointRemoved(Endpoint endpoint) { /* if (!endpoint.isRemote()) { diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java index 6d4a60de6f..69ac7b4776 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java @@ -51,7 +51,6 @@ import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription; import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteConstants; -import org.apache.tuscany.sca.osgi.service.remoteadmin.impl.EndpointDescriptionImpl; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; @@ -162,7 +161,7 @@ public class LocalDiscoveryService extends AbstractDiscoveryService implements B props.put(RemoteConstants.ENDPOINT_URI, UUID.randomUUID().toString()); } - EndpointDescription sed = new EndpointDescriptionImpl(props); + EndpointDescription sed = new EndpointDescription(props); return sed; } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointDescriptionImpl.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointDescriptionImpl.java deleted file mode 100644 index d294bcfadf..0000000000 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointDescriptionImpl.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.osgi.service.remoteadmin.impl; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.logging.Logger; - -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.interfacedef.Interface; -import org.apache.tuscany.sca.interfacedef.java.JavaInterface; -import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription; -import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteConstants; -import org.apache.tuscany.sca.policy.Intent; -import org.osgi.framework.Constants; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.Version; - -/** - * Implementation of {@link EndpointDescription} - */ -public class EndpointDescriptionImpl extends EndpointDescription { - private static final Logger logger = Logger.getLogger(EndpointDescriptionImpl.class.getName()); - private Endpoint endpoint; - - /** - * @param properties - * @throws IllegalArgumentException - */ - public EndpointDescriptionImpl(Map properties) throws IllegalArgumentException { - super(properties); - this.endpoint = (Endpoint)getProperties().get(Endpoint.class.getName()); - } - - /** - * @param ref - * @throws IllegalArgumentException - */ - public EndpointDescriptionImpl(ServiceReference ref) throws IllegalArgumentException { - super(ref); - this.endpoint = (Endpoint)getProperties().get(Endpoint.class.getName()); - } - - public EndpointDescriptionImpl(Collection interfaces, String remoteServiceId, String uri) { - super(getProperties(interfaces, remoteServiceId, uri)); - this.endpoint = (Endpoint)getProperties().get(Endpoint.class.getName()); - } - - private static Map getProperties(Collection interfaces, String remoteServiceId, String uri) { - Map props = new HashMap(); - props.put(Constants.OBJECTCLASS, interfaces.toArray(new String[interfaces.size()])); - props.put(RemoteConstants.ENDPOINT_REMOTE_SERVICE_ID, remoteServiceId); - props.put(RemoteConstants.ENDPOINT_URI, uri); - return props; - } - - public EndpointDescriptionImpl(Endpoint endpoint) { - this(getProperties(endpoint)); - this.endpoint = endpoint; - } - - /** - * @see org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription#getConfigurationTypes() - */ - public List getConfigurationTypes() { - return Collections.singletonList("sca"); - } - - /** - * @see org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription#getIntents() - */ - public List getIntents() { - List intents = new ArrayList(); - for (Intent intent : endpoint.getRequiredIntents()) { - intents.add(intent.getName().toString()); - } - return intents; - } - - /** - * @see org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription#getInterfaceVersion(java.lang.String) - */ - public Version getInterfaceVersion(String name) { - return Version.emptyVersion; - } - - private static List getInterfaces(Endpoint endpoint) { - Interface intf = endpoint.getInterfaceContract().getInterface(); - JavaInterface javaInterface = (JavaInterface)intf; - return Collections.singletonList(javaInterface.getName()); - } - - private static Map getProperties(Endpoint endpoint) { - Map props = new HashMap(); - props.put(RemoteConstants.ENDPOINT_URI, endpoint.getURI()); - props.put(RemoteConstants.ENDPOINT_REMOTE_SERVICE_ID, UUID.randomUUID().toString()); - props.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, new String[] {"sca"}); - props.put(Endpoint.class.getName(), endpoint); - List interfaces = getInterfaces(endpoint); - props.put(Constants.OBJECTCLASS, interfaces.toArray(new String[interfaces.size()])); - return props; - } - - /** - * @see org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription#getRemoteServiceID() - */ - public String getRemoteServiceID() { - return null; // endpoint.getService().getExtensions(); - } - - /** - * @see org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription#getURI() - */ - public String getURI() { - if (endpoint != null) { - return endpoint.getURI(); - } else { - return super.getURI(); - } - } - - public Endpoint getEndpoint() { - return endpoint; - } - -} diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointHelper.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointHelper.java new file mode 100644 index 0000000000..e847680fda --- /dev/null +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointHelper.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.osgi.service.remoteadmin.impl; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription; +import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteConstants; +import org.osgi.framework.Constants; + +/** + * Implementation of {@link EndpointDescription} + */ +public class EndpointHelper { + private EndpointHelper() { + } + + public static EndpointDescription createEndpointDescription(Endpoint endpoint) { + return new EndpointDescription(getProperties(endpoint)); + } + + private static List getInterfaces(Endpoint endpoint) { + Interface intf = endpoint.getInterfaceContract().getInterface(); + JavaInterface javaInterface = (JavaInterface)intf; + return Collections.singletonList(javaInterface.getName()); + } + + private static Map getProperties(Endpoint endpoint) { + Map props = new HashMap(); + props.put(RemoteConstants.ENDPOINT_URI, endpoint.getURI()); + props.put(RemoteConstants.ENDPOINT_REMOTE_SERVICE_ID, UUID.randomUUID().toString()); + props.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, new String[] {"sca"}); + props.put(Endpoint.class.getName(), endpoint); + List interfaces = getInterfaces(endpoint); + props.put(Constants.OBJECTCLASS, interfaces.toArray(new String[interfaces.size()])); + return props; + } + + public static Endpoint getEndpoint(EndpointDescription endpointDescription) { + return (Endpoint)endpointDescription.getProperties().get(Endpoint.class.getName()); + } + +} diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointIntrospector.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointIntrospector.java index 39e7457e2e..289c0e22f2 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointIntrospector.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointIntrospector.java @@ -292,12 +292,9 @@ public class EndpointIntrospector { } public Contribution introspect(Bundle bundle, EndpointDescription endpoint) throws Exception { - if (endpoint instanceof EndpointDescriptionImpl) { - EndpointDescriptionImpl impl = (EndpointDescriptionImpl)endpoint; - Endpoint ep = impl.getEndpoint(); - if (ep != null) { - return introspect(bundle, ep); - } + Endpoint ep = (Endpoint) endpoint.getProperties().get(Endpoint.class.getName()); + if (ep != null) { + return introspect(bundle, ep); } Map properties = endpoint.getProperties(); List remoteInterfaces = endpoint.getInterfaces(); diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/OSGiServiceExporter.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/OSGiServiceExporter.java index 5a381f0b67..b2260de34d 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/OSGiServiceExporter.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/OSGiServiceExporter.java @@ -19,6 +19,8 @@ package org.apache.tuscany.sca.osgi.service.remoteadmin.impl; +import static org.apache.tuscany.sca.osgi.service.remoteadmin.impl.EndpointHelper.createEndpointDescription; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -93,7 +95,7 @@ public class OSGiServiceExporter implements ServiceTrackerCustomizer, LifeCycleL Component component = contribution.getDeployables().get(0).getComponents().get(0); ComponentService service = component.getServices().get(0); for (Endpoint endpoint : service.getEndpoints()) { - EndpointDescription endpointDescription = new EndpointDescriptionImpl(endpoint); + EndpointDescription endpointDescription = createEndpointDescription(endpoint); ExportRegistration exportRegistration = new ExportRegistrationImpl(node, reference, endpointDescription); exportedServices.add(exportRegistration); diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/RemoteControllerImpl.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/RemoteControllerImpl.java index 1c57c0ec1a..3c4e0747f9 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/RemoteControllerImpl.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/RemoteControllerImpl.java @@ -352,7 +352,7 @@ public class RemoteControllerImpl implements ListenerHook, RemoteAdminListener, Map props = new HashMap(endpoint.getProperties()); props.put(Bundle.class.getName(), bundle); props.put(Constants.OBJECTCLASS, new String[] {interfaceClass.getName()}); - EndpointDescription description = new EndpointDescriptionImpl(props); + EndpointDescription description = new EndpointDescription(props); if (admins != null) { for (Object ra : admins) { diff --git a/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/sca/META-INF/MANIFEST.MF b/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/sca/META-INF/MANIFEST.MF index 0153fc6997..60dc54014a 100644 --- a/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/sca/META-INF/MANIFEST.MF +++ b/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/sca/META-INF/MANIFEST.MF @@ -8,3 +8,5 @@ Eclipse-LazyStart: false Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt Bundle-DocURL: http://www.apache.org/ Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 +Import-Package: calculator.dosgi;version="1.0.0", + calculator.dosgi.operations;version="1.0.0" diff --git a/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/sca/OSGI-INF/sca/calculator.composite b/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/sca/OSGI-INF/sca/calculator.composite index f48262bdb4..43f101e799 100644 --- a/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/sca/OSGI-INF/sca/calculator.composite +++ b/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/sca/OSGI-INF/sca/calculator.composite @@ -48,6 +48,7 @@ --> + @@ -64,7 +65,6 @@ - -- cgit v1.2.3