summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-osgi/src
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-06 18:44:52 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-06 18:44:52 +0000
commit2e38df6f597d2e1555957f090749a01a78259ca0 (patch)
tree5ce8a747fe5e0c433e718f869dffca2959298c45 /java/sca/modules/implementation-osgi/src
parent1c2980fe064a325e4f30cbd7ce846f39a5edd2a4 (diff)
Work in progress, not compiling yet
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@751031 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-osgi/src')
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java7
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java45
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiInstanceWrapper.java298
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiRemotableInvoker.java136
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java36
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiPropertyTestCase.java46
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java47
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java7
8 files changed, 54 insertions, 568 deletions
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java
index dd7da7f60e..d9641def69 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java
@@ -40,15 +40,12 @@ public class OSGiImplementationImpl extends ImplementationImpl implements OSGiIm
private String bundleVersion;
private Bundle osgiBundle;
- private String[] imports;
private Hashtable<String, List<ComponentProperty>> referenceProperties;
private Hashtable<String, List<ComponentProperty>> serviceProperties;
private Hashtable<String, List<ComponentProperty>> referenceCallbackProperties;
private Hashtable<String, List<ComponentProperty>> serviceCallbackProperties;
- private String[] classList;
-
private FactoryExtensionPoint modelFactories;
@@ -59,18 +56,14 @@ public class OSGiImplementationImpl extends ImplementationImpl implements OSGiIm
public OSGiImplementationImpl(FactoryExtensionPoint modelFactories,
String bundleSymbolicName,
String bundleVersion,
- String[] imports,
- String[] classList,
Hashtable<String, List<ComponentProperty>> refProperties,
Hashtable<String, List<ComponentProperty>> serviceProperties) {
super();
this.bundleSymbolicName = bundleSymbolicName;
this.bundleVersion = bundleVersion;
- this.imports = imports;
this.referenceProperties = refProperties;
this.serviceProperties = serviceProperties;
- this.classList = classList;
this.modelFactories = modelFactories;
}
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
index 4f545eb57e..89e60dff13 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
@@ -42,7 +42,6 @@ import org.apache.tuscany.sca.assembly.ComponentProperty;
import org.apache.tuscany.sca.assembly.ComponentReference;
import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.Multiplicity;
-import org.apache.tuscany.sca.assembly.Property;
import org.apache.tuscany.sca.assembly.Reference;
import org.apache.tuscany.sca.assembly.Service;
import org.apache.tuscany.sca.context.RequestContextFactory;
@@ -57,11 +56,8 @@ import org.apache.tuscany.sca.core.scope.ScopeRegistry;
import org.apache.tuscany.sca.core.scope.ScopedImplementationProvider;
import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent;
import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
-import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
import org.apache.tuscany.sca.implementation.java.IntrospectionException;
-import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory;
import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation;
-import org.apache.tuscany.sca.implementation.osgi.context.OSGiAnnotations;
import org.apache.tuscany.sca.implementation.osgi.impl.OSGiImplementationImpl;
import org.apache.tuscany.sca.interfacedef.Interface;
import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
@@ -102,8 +98,7 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider,
// Maximum milliseconds to wait for services to be registered into OSGi service registry
private static final long SERVICE_TIMEOUT_MILLIS = 300000;
- private OSGiImplementationImpl implementation;
- private OSGiAnnotations osgiAnnotations;
+ private OSGiImplementation implementation;
private Hashtable<RuntimeWire, Reference> referenceWires = new Hashtable<RuntimeWire, Reference>();
private Hashtable<RuntimeWire, ComponentReference> componentReferenceWires =
new Hashtable<RuntimeWire, ComponentReference>();
@@ -113,8 +108,6 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider,
private AtomicInteger startBundleEntryCount = new AtomicInteger();
private AtomicInteger processAnnotationsEntryCount = new AtomicInteger();
- private JavaPropertyValueObjectFactory propertyValueFactory;
-
private Hashtable<String, Object> componentProperties = new Hashtable<String, Object>();
private RuntimeComponent runtimeComponent;
@@ -183,29 +176,10 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider,
return runtimeComponent;
}
- protected OSGiImplementationImpl getImplementation() {
+ protected OSGiImplementation getImplementation() {
return implementation;
}
- // Create a property table from the list of properties
- // The source properties are properties read from <property/> elements
- // Create property values in the table of the appropriate class based
- // on the property type specified.
- private void processProperties(List<?> props, Hashtable<String, Object> propsTable) {
-
- if (props != null) {
- for (Object p : props) {
-
- Property prop = (Property)p;
- Class javaType = SimpleTypeMapperImpl.getJavaType(prop.getXSDType());
- ObjectFactory<?> objFactory = propertyValueFactory.createValueFactory(prop, prop.getValue(), javaType);
- Object value = objFactory.getInstance();
-
- propsTable.put(prop.getName(), value);
- }
- }
- }
-
private String getOSGiFilter(Hashtable<String, Object> props) {
String filter = "";
@@ -1008,19 +982,19 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider,
}
public Scope getScope() {
- return osgiAnnotations.getScope();
+ return Scope.COMPOSITE;
}
public boolean isEagerInit() {
- return osgiAnnotations.isEagerInit();
+ return false;
}
public long getMaxAge() {
- return osgiAnnotations.getMaxAge();
+ return 0l;
}
public long getMaxIdleTime() {
- return osgiAnnotations.getMaxIdleTime();
+ return 0l;
}
protected ScopeContainer<?> getScopeContainer() {
@@ -1034,12 +1008,7 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider,
boolean isRemotable = serviceInterface.isRemotable();
Invoker invoker = new OSGiTargetInvoker(operation, this, service);
- if (isRemotable) {
- return new OSGiRemotableInvoker(osgiAnnotations, dataBindingRegistry, operation, this, service);
- } else {
- return invoker;
- }
-
+ return invoker;
}
public Invoker createInvoker(RuntimeComponentService service, Operation operation) {
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiInstanceWrapper.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiInstanceWrapper.java
deleted file mode 100644
index a0a207b43b..0000000000
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiInstanceWrapper.java
+++ /dev/null
@@ -1,298 +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.implementation.osgi.runtime;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Random;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-
-import org.apache.tuscany.sca.assembly.ComponentService;
-import org.apache.tuscany.sca.core.factory.InstanceWrapper;
-import org.apache.tuscany.sca.core.scope.Scope;
-import org.apache.tuscany.sca.core.scope.TargetDestructionException;
-import org.apache.tuscany.sca.core.scope.TargetInitializationException;
-import org.apache.tuscany.sca.implementation.osgi.context.OSGiAnnotations;
-import org.apache.tuscany.sca.interfacedef.Interface;
-import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
-import org.oasisopen.sca.annotation.Destroy;
-import org.oasisopen.sca.annotation.Init;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.ServiceReference;
-
-/**
- * InstanceWrapper for creating instances for OSGi components.
- * This class needs to implement InstanceWrapper since the wrapper is stored in
- * the scope container. But getInstance() is called on this wrapper only through the
- * OSGi target invoker. OSGiTargetInvoker always invokes getInstance for a specific
- * service since one OSGi SCA component can associate different objects with
- * different services (this is different from Java SCA components which always associate
- * a single component instance with multiple services).
- *
- * @version $Rev$ $Date$
- */
-public class OSGiInstanceWrapper<T> implements InstanceWrapper<T> {
- private static final Random RANDOM_NUMBER_GENERATOR = new Random();
-
- private OSGiAnnotations annotationProcessor;
- private OSGiImplementationProvider provider;
- private BundleContext bundleContext;
- private Hashtable<Object, InstanceInfo<T>> instanceInfoList = new Hashtable<Object, InstanceInfo<T>>();
-
- // Dummy bundles are used to create a new service object for scopes other than COMPOSITE
- private Bundle dummyReferenceBundle;
-
- public OSGiInstanceWrapper(OSGiImplementationProvider provider,
- OSGiAnnotations annotationProcessor,
- BundleContext bundleContext) {
-
- this.provider = provider;
- this.annotationProcessor = annotationProcessor;
- this.bundleContext = bundleContext;
- }
-
- public synchronized T getInstance(ComponentService service) throws TargetInitializationException {
-
- // If an instance corresponding to this service has already been created, return the instance.
- if (instanceInfoList.get(service) != null)
- return instanceInfoList.get(service).osgiInstance;
-
- // There is no strict relation between service and callback instances. The instance semantics
- // actually applies to the component instance in SCA. But for OSGi services, the callback
- // is just another OSGi service, and could correspond to any of the service instances in
- // the component. To implement the SCA scope semantics for callbacks, OSGi callbacks
- // should also be made on the service object which implements the callback. The following code
- // finds the first possible callback instance based on the interfaces implemented by the service
- // objects in this component. Note that the interfaces are checked by name rather than using
- // instanceof since the class seen by Tuscany could be from a different classloader from that
- // used by the bundle.
- if (service.isCallback()) {
- Iterator<InstanceInfo<T>> instances = instanceInfoList.values().iterator();
- while (instances.hasNext()) {
- InstanceInfo<T> instanceInfo = instances.next();
- Interface interfaze = service.getInterfaceContract().getInterface();
- if (interfaze instanceof JavaInterface && ((JavaInterface)interfaze).getJavaClass() != null) {
- String interfaceName = ((JavaInterface)interfaze).getJavaClass().getName();
- Class[] interfaces = instanceInfo.osgiInstance.getClass().getInterfaces();
- for (Class clazz : interfaces) {
- if (clazz.getName().equals(interfaceName)) {
- return instanceInfo.osgiInstance;
- }
- }
-
- }
-
- }
- }
-
- Bundle refBundle = provider.startBundle(true);
-
- // For scopes other than composite, the service object is obtained using a dummy reference
- // bundle to guarantee that a new instance is created each time. This combined with the Tuscany
- // scope container code guarantee SCA scope semantics for OSGi components as long as service
- // factories are used.
- if (!annotationProcessor.getScope().equals(Scope.COMPOSITE)) {
- refBundle = getDummyReferenceBundle();
- }
-
- InstanceInfo<T> instanceInfo = new InstanceInfo<T>();
-
- instanceInfo.refBundleContext = refBundle.getBundleContext();
-
- instanceInfo.osgiInstance = getInstanceObject(instanceInfo, service);
-
- try {
-
- if (!isInitialized(instanceInfo.osgiInstance)) {
-
- annotationProcessor.injectProperties(instanceInfo.osgiInstance);
- callLifecycleMethod(instanceInfo.osgiInstance, Init.class);
-
- instanceInfo.isFirstInstance = true;
- }
-
- instanceInfoList.put(service, instanceInfo);
-
- } catch (Exception e) {
- throw new TargetInitializationException(e);
- }
-
- return instanceInfo.osgiInstance;
- }
-
- // This method is provided purely to implement InstanceWrapper interface, and is never called.
- public T getInstance() {
-
- return null;
- }
-
- public void start() throws TargetInitializationException {
-
- if (provider.isEagerInit()) {
- List<ComponentService> services = provider.getRuntimeComponent().getServices();
- for (ComponentService service : services) {
- getInstance(service);
- }
- }
- }
-
- public synchronized void stop() throws TargetDestructionException {
-
- for (InstanceInfo<T> instanceInfo : instanceInfoList.values()) {
- if (instanceInfo.osgiInstance != null && instanceInfo.osgiServiceReference != null) {
-
- try {
-
- if (instanceInfo.isFirstInstance)
- callLifecycleMethod(instanceInfo.osgiInstance, Destroy.class);
-
- instanceInfo.refBundleContext.ungetService(instanceInfo.osgiServiceReference);
-
- instanceInfo.osgiInstance = null;
- instanceInfo.osgiServiceReference = null;
-
- } catch (Exception e) {
- throw new TargetDestructionException(e);
- }
- }
- }
- instanceInfoList.clear();
- if (dummyReferenceBundle != null) {
- try {
- dummyReferenceBundle.uninstall();
- } catch (BundleException e) {
- throw new TargetDestructionException(e);
- }
- dummyReferenceBundle = null;
- }
- }
-
- @SuppressWarnings("unchecked")
- private T getInstanceObject(InstanceInfo<T> instanceInfo, ComponentService service) {
-
- /**
- * Since implementation.osgi is not well integrated with the OSGi lifecycle
- * it is possible that the service is deactivated before the service instance
- * is obtained when using declarative services. Retry in this case.
- */
- int maxRetries = 10;
- for (int i = 0; i < maxRetries; i++) {
- instanceInfo.osgiServiceReference = provider.getOSGiServiceReference(service);
- if (instanceInfo.osgiServiceReference == null)
- return null;
- T obj = (T)instanceInfo.refBundleContext.getService(instanceInfo.osgiServiceReference);
- if (obj != null)
- return obj;
- }
- return null;
- }
-
- private Bundle getDummyReferenceBundle() throws TargetInitializationException {
-
- if (dummyReferenceBundle != null)
- return dummyReferenceBundle;
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
-
- String EOL = System.getProperty("line.separator");
- String bundleName = "dummy.sca." + RANDOM_NUMBER_GENERATOR.nextInt();
-
- String manifestStr =
- "Manifest-Version: 1.0" + EOL
- + "Bundle-ManifestVersion: 2"
- + EOL
- + "Bundle-Name: "
- + bundleName
- + EOL
- + "Bundle-SymbolicName: "
- + bundleName
- + EOL
- + "Bundle-Version: "
- + "1.0.0"
- + EOL
- + "Bundle-Localization: plugin"
- + EOL;
-
- StringBuilder manifestBuf = new StringBuilder();
- manifestBuf.append(manifestStr);
-
- try {
- ByteArrayInputStream manifestStream = new ByteArrayInputStream(manifestBuf.toString().getBytes());
- Manifest manifest = new Manifest();
- manifest.read(manifestStream);
-
- JarOutputStream jarOut = new JarOutputStream(out, manifest);
-
- jarOut.close();
- out.close();
-
- ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-
- dummyReferenceBundle = bundleContext.installBundle("file://" + bundleName + ".jar", in);
-
- dummyReferenceBundle.start();
-
- } catch (Exception e) {
- throw new TargetInitializationException(e);
- }
-
- return dummyReferenceBundle;
-
- }
-
- private void callLifecycleMethod(Object instance, Class<? extends Annotation> annotationClass) throws Exception {
-
- Method method = null;
- if (annotationClass == Init.class) {
- method = annotationProcessor.getInitMethod(instance);
- } else if (annotationClass == Destroy.class) {
- method = annotationProcessor.getDestroyMethod(instance);
- }
-
- if (method != null) {
- method.setAccessible(true);
- method.invoke(instance);
- }
- }
-
- private boolean isInitialized(Object instance) {
- for (InstanceInfo<?> info : instanceInfoList.values()) {
- if (info.osgiInstance == instance)
- return true;
- }
- return false;
- }
-
- private static class InstanceInfo<T> {
- private T osgiInstance;
- private ServiceReference osgiServiceReference;
- private BundleContext refBundleContext;
- private boolean isFirstInstance;
-
- }
-
-}
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiRemotableInvoker.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiRemotableInvoker.java
deleted file mode 100644
index b74e98bcfd..0000000000
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiRemotableInvoker.java
+++ /dev/null
@@ -1,136 +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.implementation.osgi.runtime;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.IdentityHashMap;
-import java.util.Map;
-
-import org.apache.tuscany.sca.databinding.DataBinding;
-import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
-import org.apache.tuscany.sca.interfacedef.DataType;
-import org.apache.tuscany.sca.interfacedef.Operation;
-import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
-import org.apache.tuscany.sca.invocation.Message;
-import org.apache.tuscany.sca.runtime.RuntimeComponentService;
-
-/**
- * An interceptor to enforce pass-by-value semantics for remotable interfaces
- *
- * @version $Rev$ $Date$
- */
-public class OSGiRemotableInvoker extends OSGiTargetInvoker implements DataExchangeSemantics {
-
- private DataBindingExtensionPoint registry;
- private Operation operation;
-
- /**
- * @param registry
- * @param operation
- * @param method
- * @param component
- */
- public OSGiRemotableInvoker(OSGiAnnotations osgiAnnotations,
- DataBindingExtensionPoint registry,
- Operation operation,
- OSGiImplementationProvider provider,
- RuntimeComponentService service) {
- super(operation, provider, service);
- this.registry = registry;
- this.operation = operation;
- }
-
- @Override
- public Object invokeMethod(Object targetObject, Method m, Message msg) throws InvocationTargetException {
-
- Object result;
- if (osgiAnnotations.isAllowsPassByReference(targetObject, m)) {
- result = super.invokeMethod(targetObject, m, msg);
- } else {
- Object obj = msg.getBody();
- msg.setBody(copy((Object[])obj));
-
- result = super.invokeMethod(targetObject, m, msg);
-
- if (operation.getOutputType() != null) {
- String dataBindingId = operation.getOutputType().getDataBinding();
- DataBinding dataBinding = registry.getDataBinding(dataBindingId);
- result = copy(result, operation.getOutputType(), dataBinding);
- }
- }
- return result;
- }
-
- public Object[] copy(Object[] args) {
- if (args == null) {
- return null;
- }
- Object[] copiedArgs = new Object[args.length];
- Map<Object, Object> map = new IdentityHashMap<Object, Object>();
- for (int i = 0; i < args.length; i++) {
- if (args[i] == null) {
- copiedArgs[i] = null;
- } else {
- Object copiedArg = map.get(args[i]);
- if (copiedArg != null) {
- copiedArgs[i] = copiedArg;
- } else {
- DataType dt = operation.getInputType().getLogical().get(i);
- String dataBindingId = dt.getDataBinding();
- DataBinding dataBinding = registry.getDataBinding(dataBindingId);
- copiedArg = copy(args[i], dt, dataBinding);
- map.put(args[i], copiedArg);
- copiedArgs[i] = copiedArg;
- }
- }
- }
- return copiedArgs;
- }
-
- public Object copy(Object arg, DataType dataType, DataBinding argDataBinding) {
- if (arg == null) {
- return null;
- }
- Object copiedArg;
- if (argDataBinding != null) {
- copiedArg = argDataBinding.copy(arg, dataType, operation);
- } else {
- copiedArg = arg;
- dataType = registry.introspectType(arg, operation);
- if (dataType != null) {
- DataBinding binding = registry.getDataBinding(dataType.getDataBinding());
- if (binding != null) {
- copiedArg = binding.copy(arg, dataType, operation);
- }
- }
- // FIXME: What to do if it's not recognized?
- }
- return copiedArg;
- }
-
- /**
- * @see org.apache.tuscany.sca.invocation.PassByValueAware#allowsPassByReference()
- */
- public boolean allowsPassByReference() {
- return true;
- }
-
-}
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
index 46667d4abc..d10af49147 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
@@ -22,7 +22,6 @@ import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI;
import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
-import static org.apache.tuscany.sca.assembly.xml.Constants.SCA11_TUSCANY_NS;
import java.util.ArrayList;
import java.util.Hashtable;
@@ -61,7 +60,6 @@ import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.monitor.Problem.Severity;
-import org.apache.tuscany.sca.monitor.impl.ProblemImpl;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Version;
@@ -79,13 +77,13 @@ import org.w3c.dom.Node;
* @version $Rev$ $Date$
*/
public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiImplementation> {
+ public final static String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903";
+ public final static String SCA11_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1";
public static final QName IMPLEMENTATION_OSGI = new QName(SCA11_TUSCANY_NS, "implementation.osgi");
private static final String BUNDLE_SYMBOLICNAME = "bundleSymbolicName";
private static final String BUNDLE_VERSION = "bundleVersion";
- private static final String CLASSES = "classes";
- private static final String IMPORTS = "imports";
private static final QName PROPERTIES_QNAME = new QName(SCA11_TUSCANY_NS, "properties");
private static final QName PROPERTY_QNAME = new QName(SCA11_TUSCANY_NS, "property");
@@ -112,8 +110,12 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm
private void error(String message, Object model, Exception ex) {
if (monitor != null) {
Problem problem =
- new ProblemImpl(this.getClass().getName(), "impl-osgi-validation-messages", Severity.ERROR, model,
- message, ex);
+ monitor.createProblem(this.getClass().getName(),
+ "impl-osgi-validation-messages",
+ Severity.ERROR,
+ model,
+ message,
+ ex);
monitor.problem(problem);
}
}
@@ -128,8 +130,12 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm
private void error(String message, Object model, Object... messageParameters) {
if (monitor != null) {
Problem problem =
- new ProblemImpl(this.getClass().getName(), "impl-osgi-validation-messages", Severity.ERROR, model,
- message, (Object[])messageParameters);
+ monitor.createProblem(this.getClass().getName(),
+ "impl-osgi-validation-messages",
+ Severity.ERROR,
+ model,
+ message,
+ (Object[])messageParameters);
monitor.problem(problem);
}
}
@@ -157,18 +163,6 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm
String bundleSymbolicName = reader.getAttributeValue(null, BUNDLE_SYMBOLICNAME);
String bundleVersion = reader.getAttributeValue(null, BUNDLE_VERSION);
- String imports = reader.getAttributeValue(null, IMPORTS);
- String[] importList;
- if (imports != null)
- importList = tokenize(imports);
- else
- importList = new String[0];
- String classes = reader.getAttributeValue(null, CLASSES);
- String[] classList;
- if (classes != null)
- classList = tokenize(classes);
- else
- classList = new String[0];
Hashtable<String, List<ComponentProperty>> refProperties = new Hashtable<String, List<ComponentProperty>>();
Hashtable<String, List<ComponentProperty>> serviceProperties = new Hashtable<String, List<ComponentProperty>>();
@@ -211,7 +205,7 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm
}
OSGiImplementationImpl implementation =
- new OSGiImplementationImpl(modelFactories, bundleSymbolicName, bundleVersion, importList, classList,
+ new OSGiImplementationImpl(modelFactories, bundleSymbolicName, bundleVersion,
refProperties, serviceProperties);
implementation.setCallbackProperties(refCallbackProperties, serviceCallbackProperties);
diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiPropertyTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiPropertyTestCase.java
deleted file mode 100644
index 16c2b538cb..0000000000
--- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiPropertyTestCase.java
+++ /dev/null
@@ -1,46 +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.implementation.osgi.runtime;
-
-import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestBundles;
-import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestInterface;
-import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestWithPropertyImpl;
-
-/**
- *
- * Test the execution of an OSGi implementation type
- *
- * @version $Rev$ $Date$
- */
-public class OSGiPropertyTestCase extends OSGiTestCase {
-
- @Override
- protected void setUp() throws Exception {
-
- className = OSGiTestWithPropertyImpl.class.getName();
- compositeName = "osgiproptest.composite";
-
- OSGiTestBundles.createBundle("target/test-classes/OSGiTestService.jar",
- OSGiTestInterface.class,
- OSGiTestWithPropertyImpl.class);
-
- }
-
-}
diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java
index fa592e8b41..7ea598707d 100644
--- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java
+++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java
@@ -19,13 +19,19 @@
package org.apache.tuscany.sca.implementation.osgi.runtime;
+import java.io.File;
import java.lang.reflect.Proxy;
-import junit.framework.TestCase;
-
import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestBundles;
import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestImpl;
import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestInterface;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.equinox.launcher.Contribution;
+import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
*
@@ -33,39 +39,46 @@ import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestInterface;
*
* @version $Rev$ $Date$
*/
-public class OSGiTestCase extends TestCase {
-
- protected String className;
- protected String compositeName;
-
- protected void setUp() throws Exception {
-
+public class OSGiTestCase {
+ private static NodeLauncher host;
+ private static Node node;
+ protected static String className;
+ protected static String compositeName;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ host = NodeLauncher.newInstance();
className = OSGiTestImpl.class.getName();
compositeName = "osgitest.composite";
OSGiTestBundles.createBundle("target/test-classes/OSGiTestService.jar",
OSGiTestInterface.class,
OSGiTestImpl.class);
+ node =
+ host.createNode("osgitest.composite", new Contribution("c1", new File("target/test-classes").toURI()
+ .toString()));
+ node.start();
}
- @Override
- protected void tearDown() throws Exception {
- OSGiRuntime.stop();
+ @AfterClass
+ public static void tearDown() throws Exception {
+ if (host != null) {
+ node.stop();
+ host.destroy();
+ }
}
+ @Test
public void testOSGiComponent() throws Exception {
- SCADomain scaDomain = SCADomain.newInstance(compositeName);
- OSGiTestInterface testService = scaDomain.getService(OSGiTestInterface.class, "OSGiTestServiceComponent");
+ OSGiTestInterface testService = node.getService(OSGiTestInterface.class, "OSGiTestServiceComponent");
assert (testService != null);
assert (testService instanceof Proxy);
String str = testService.testService();
- assertEquals(className, str);
-
- scaDomain.close();
+ Assert.assertEquals(className, str);
}
diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java
index 99268bde5f..a31842b6a3 100644
--- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java
+++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java
@@ -37,7 +37,7 @@ import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
-import org.apache.tuscany.sca.implementation.osgi.impl.OSGiImplementationImpl;
+import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation;
import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestBundles;
import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestImpl;
import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestInterface;
@@ -110,13 +110,10 @@ public class OSGiReadImplTestCase extends TestCase {
XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
reader.next();
- OSGiImplementationImpl osgiImpl = (OSGiImplementationImpl)staxProcessor.read(reader);
+ OSGiImplementation osgiImpl = (OSGiImplementation)staxProcessor.read(reader);
assertEquals(osgiImpl.getBundleSymbolicName(), "OSGiTestService");
assertEquals(osgiImpl.getBundleVersion(), "2.0.0");
- assertTrue(osgiImpl.getImports().length == 2);
- assertEquals(osgiImpl.getImports()[0], "import1.jar");
- assertEquals(osgiImpl.getImports()[1], "import2.jar");
}
}