Author: rfeng
Date: Wed Mar 4 21:58:05 2009
New Revision: 750178
URL: http://svn.apache.org/viewvc?rev=750178&view=rev
Log:
Start to port implementation.osgi into 2.x for RFC 119
Added:
tuscany/java/sca/modules/implementation-osgi/
- copied from r743057,
tuscany/java/sca-contrib/modules/implementation-osgi/
Modified:
tuscany/java/sca/modules/implementation-osgi/pom.xml
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiAnnotations.java
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyInjector.java
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyValueObjectFactory.java
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiInstanceWrapper.java
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiPropertyTestCase.java
tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java
tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java
tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestImpl.java
tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestInterface.java
tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java
tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java
tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java
tuscany/java/sca/modules/implementation-osgi/src/test/resources/OSGiTestService.componentType
tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgiproptest.composite
tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgitest.composite
Modified: tuscany/java/sca/modules/implementation-osgi/pom.xml
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/pom.xml?rev=750178&r1=743057&r2=750178&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi/pom.xml (original)
+++ tuscany/java/sca/modules/implementation-osgi/pom.xml Wed Mar 4 21:58:05
2009
@@ -35,15 +35,15 @@
<dependencies>
<dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.main</artifactId>
- <version>1.0.4</version>
+ <groupId>org.eclipse</groupId>
+ <artifactId>osgi</artifactId>
+ <version>3.3.0-v20070530</version>
+ <scope>compile</scope>
</dependency>
-
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-host-embedded</artifactId>
+ <artifactId>tuscany-node-api</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
@@ -108,30 +108,12 @@
</dependency>
<dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-contribution-osgi</artifactId>
- <version>2.0-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-osgi-runtime</artifactId>
- <version>2.0-SNAPSHOT</version>
- </dependency>
-
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <version>2.2</version>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
Modified:
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java?rev=750178&r1=743057&r2=750178&view=diff
==============================================================================
---
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java
(original)
+++
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementation.java
Wed Mar 4 21:58:05 2009
@@ -18,11 +18,9 @@
*/
package org.apache.tuscany.sca.implementation.osgi;
-import java.util.List;
-
-import org.apache.tuscany.sca.assembly.ComponentProperty;
import org.apache.tuscany.sca.assembly.Extensible;
import org.apache.tuscany.sca.assembly.Implementation;
+import org.osgi.framework.Bundle;
/**
*
@@ -34,12 +32,13 @@
String getBundleSymbolicName();
- String getBundleVersion();
-
- String[] getImports();
+ void setBundleSymbolicName(String name);
- List<ComponentProperty> getReferenceProperties(String referenceName);
+ String getBundleVersion();
- List<ComponentProperty> getServiceProperties(String serviceName);
+ void setBundleVersion(String version);
+
+ Bundle getBundle();
+ void setBundle(Bundle bundle);
}
Modified:
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiAnnotations.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiAnnotations.java?rev=750178&r1=743057&r2=750178&view=diff
==============================================================================
---
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiAnnotations.java
(original)
+++
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiAnnotations.java
Wed Mar 4 21:58:05 2009
@@ -18,7 +18,6 @@
*/
package org.apache.tuscany.sca.implementation.osgi.context;
-
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -27,18 +26,18 @@
import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.context.RequestContextFactory;
-import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.core.invocation.ProxyFactory;
import org.apache.tuscany.sca.core.scope.Scope;
import
org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
import org.apache.tuscany.sca.implementation.java.IntrospectionException;
import org.apache.tuscany.sca.implementation.java.JavaImplementation;
import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
-import org.apache.tuscany.sca.implementation.java.impl.JavaScopeImpl;
+import org.apache.tuscany.sca.implementation.java.JavaScopeImpl;
import
org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory;
+import
org.apache.tuscany.sca.implementation.java.introspect.BaseJavaClassVisitor;
import org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor;
import
org.apache.tuscany.sca.implementation.java.introspect.impl.AllowsPassByReferenceProcessor;
-import
org.apache.tuscany.sca.implementation.java.introspect.impl.BaseJavaClassVisitor;
import
org.apache.tuscany.sca.implementation.java.introspect.impl.ComponentNameProcessor;
import
org.apache.tuscany.sca.implementation.java.introspect.impl.ConstructorProcessor;
import
org.apache.tuscany.sca.implementation.java.introspect.impl.ContextProcessor;
@@ -57,7 +56,6 @@
import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.osgi.framework.Bundle;
-
/**
* OSGi annotation processing
* OSGi bundles are not introspected by OSGiImplementation when a component is
created.
@@ -73,66 +71,61 @@
*
* @version $Rev$ $Date$
*/
-public class OSGiAnnotations {
-
+public class OSGiAnnotations {
+
private Scope scope = Scope.COMPOSITE;
private boolean isEagerInit;
-
+
private String[] classList;
-
- private Bundle[] bundles;
-
+
+ private Bundle[] bundles;
+
private RuntimeComponent runtimeComponent;
private JavaPropertyValueObjectFactory propertyValueFactory;
private ProxyFactory proxyFactory;
-
+
private JavaImplementationFactory javaImplementationFactory;
- private JavaInterfaceFactory javaInterfaceFactory;
+ private JavaInterfaceFactory javaInterfaceFactory;
private PolicyFactory policyFactory;
private RequestContextFactory requestContextFactory;
-
- private Hashtable<Class<?>, JavaImplementation> javaAnnotationInfo =
- new Hashtable<Class<?>, JavaImplementation>();
- private Hashtable<JavaImplementation, OSGiPropertyInjector>
propertyInjectors =
+
+ private Hashtable<Class<?>, JavaImplementation> javaAnnotationInfo = new
Hashtable<Class<?>, JavaImplementation>();
+ private Hashtable<JavaImplementation, OSGiPropertyInjector>
propertyInjectors =
new Hashtable<JavaImplementation, OSGiPropertyInjector>();
-
+
private long maxAge = -1;
private long maxIdleTime = -1;
-
+
private boolean annotationsProcessed;
-
-
-
- public OSGiAnnotations(ModelFactoryExtensionPoint modelFactories,
- String[] classList,
- RuntimeComponent runtimeComponent,
- JavaPropertyValueObjectFactory propertyValueFactory,
- ProxyFactory proxyFactory,
- RequestContextFactory requestContextFactory,
- Bundle mainBundle,
- ArrayList<Bundle> dependentBundles) {
-
-
+
+ public OSGiAnnotations(FactoryExtensionPoint modelFactories,
+ String[] classList,
+ RuntimeComponent runtimeComponent,
+ JavaPropertyValueObjectFactory propertyValueFactory,
+ ProxyFactory proxyFactory,
+ RequestContextFactory requestContextFactory,
+ Bundle mainBundle,
+ ArrayList<Bundle> dependentBundles) {
+
this.classList = classList;
this.runtimeComponent = runtimeComponent;
this.propertyValueFactory = propertyValueFactory;
this.proxyFactory = proxyFactory;
-
+
AssemblyFactory assemblyFactory =
modelFactories.getFactory(AssemblyFactory.class);
this.javaInterfaceFactory =
modelFactories.getFactory(JavaInterfaceFactory.class);
this.javaImplementationFactory =
createJavaImplementationFactory(assemblyFactory);
this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
-
+
bundles = new Bundle[dependentBundles.size() + 1];
bundles[0] = mainBundle;
for (int i = 0; i < dependentBundles.size(); i++)
bundles[i + 1] = dependentBundles.get(i);
-
+
}
-
public void processAnnotations() throws IntrospectionException {
-
+
if (annotationsProcessed)
return;
annotationsProcessed = true;
@@ -140,18 +133,17 @@
for (Bundle bundle : bundles) {
try {
Class<?> clazz = bundle.loadClass(className);
-
+
processAnnotations(clazz);
-
+
break;
-
- } catch (ClassNotFoundException e) {
+
+ } catch (ClassNotFoundException e) {
}
}
}
}
-
-
+
public void injectProperties(Object instance) {
JavaImplementation javaImpl = getAnnotationInfo(instance);
if (javaImpl != null) {
@@ -161,15 +153,12 @@
}
}
-
public Scope getScope() {
return scope;
}
-
-
public boolean isAllowsPassByReference(Object instance, Method method) {
-
+
JavaImplementation javaImpl = getAnnotationInfo(instance);
if (javaImpl == null) {
return false;
@@ -179,8 +168,7 @@
}
return javaImpl.isAllowsPassByReference(method);
}
-
-
+
public boolean isEagerInit() {
return isEagerInit;
}
@@ -192,28 +180,26 @@
public long getMaxIdleTime() {
return maxIdleTime;
}
-
+
public Method getInitMethod(Object instance) {
JavaImplementation javaImpl = getAnnotationInfo(instance);
- return javaImpl == null? null : javaImpl.getInitMethod();
+ return javaImpl == null ? null : javaImpl.getInitMethod();
}
-
public Method getDestroyMethod(Object instance) {
JavaImplementation javaImpl = getAnnotationInfo(instance);
- return javaImpl == null? null : javaImpl.getDestroyMethod();
+ return javaImpl == null ? null : javaImpl.getDestroyMethod();
}
-
/*
* Get the annotation corresponding to an instance
*
*/
private JavaImplementation getAnnotationInfo(final Object instance) {
-
- // The simplest case where the implementation class was listed under the
- // classes attribute of <implementation.osgi/>, or this is the second
call
- // to this method for the implementation class.
+
+ // The simplest case where the implementation class was listed under
the
+ // classes attribute of <implementation.osgi/>, or this is the second
call
+ // to this method for the implementation class.
// Allow privileged access to get classloader. Requires getClassLoader
in security policy.
JavaImplementation javaImpl = AccessController.doPrivileged(new
PrivilegedAction<JavaImplementation>() {
public JavaImplementation run() {
@@ -222,27 +208,26 @@
});
if (javaImpl != null)
return javaImpl;
-
+
// Process annotations from the instance class.
try {
return processAnnotations(instance.getClass());
} catch (IntrospectionException e) {
// e.printStackTrace();
}
-
+
return null;
}
-
- private JavaImplementation processAnnotations(Class<?> clazz)
- throws IntrospectionException {
+ private JavaImplementation processAnnotations(Class<?> clazz) throws
IntrospectionException {
JavaImplementation javaImpl =
javaImplementationFactory.createJavaImplementation(clazz);
javaAnnotationInfo.put(clazz, javaImpl);
- OSGiPropertyInjector propertyInjector = new OSGiPropertyInjector(
- javaImpl, runtimeComponent, propertyValueFactory,
proxyFactory, requestContextFactory);
+ OSGiPropertyInjector propertyInjector =
+ new OSGiPropertyInjector(javaImpl, runtimeComponent,
propertyValueFactory, proxyFactory,
+ requestContextFactory);
propertyInjectors.put(javaImpl, propertyInjector);
@@ -254,28 +239,22 @@
maxIdleTime = javaImpl.getMaxIdleTime();
if (javaImpl.getJavaScope() != JavaScopeImpl.COMPOSITE)
scope = new Scope(javaImpl.getJavaScope().getScope());
-
+
return javaImpl;
}
-
-
-
-
- private JavaImplementationFactory
createJavaImplementationFactory(AssemblyFactory assemblyFactory) {
+
+ private JavaImplementationFactory
createJavaImplementationFactory(AssemblyFactory assemblyFactory) {
JavaImplementationFactory javaImplementationFactory = new
DefaultJavaImplementationFactory();
-
+
// Create the list of class visitors
BaseJavaClassVisitor[] extensions =
- new BaseJavaClassVisitor[] {
- new
ConstructorProcessor(assemblyFactory),
+ new BaseJavaClassVisitor[] {new
ConstructorProcessor(assemblyFactory),
new
AllowsPassByReferenceProcessor(assemblyFactory),
new
ComponentNameProcessor(assemblyFactory),
new ContextProcessor(assemblyFactory),
new
ConversationProcessor(assemblyFactory),
- new DestroyProcessor(assemblyFactory),
- new
EagerInitProcessor(assemblyFactory),
- new InitProcessor(assemblyFactory),
- new PropertyProcessor(assemblyFactory),
+ new DestroyProcessor(assemblyFactory),
new EagerInitProcessor(assemblyFactory),
+ new InitProcessor(assemblyFactory),
new PropertyProcessor(assemblyFactory),
new
ReferenceProcessor(assemblyFactory, javaInterfaceFactory),
new ResourceProcessor(assemblyFactory),
new
OSGiScopeProcessor(assemblyFactory),
@@ -285,21 +264,20 @@
for (JavaClassVisitor extension : extensions) {
javaImplementationFactory.addClassVisitor(extension);
}
-
+
return javaImplementationFactory;
}
-
+
private class OSGiScopeProcessor extends BaseJavaClassVisitor {
-
+
public OSGiScopeProcessor(AssemblyFactory factory) {
super(factory);
}
@Override
- public <T> void visitClass(Class<T> clazz,
- JavaImplementation type)
- throws IntrospectionException {
- org.oasisopen.sca.annotation.Scope annotation =
clazz.getAnnotation(org.oasisopen.sca.annotation.Scope.class);
+ public <T> void visitClass(Class<T> clazz, JavaImplementation type)
throws IntrospectionException {
+ org.oasisopen.sca.annotation.Scope annotation =
+ clazz.getAnnotation(org.oasisopen.sca.annotation.Scope.class);
if (annotation == null) {
type.setJavaScope(JavaScopeImpl.COMPOSITE);
return;
@@ -321,5 +299,4 @@
}
}
-
}
Modified:
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyInjector.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyInjector.java?rev=750178&r1=743057&r2=750178&view=diff
==============================================================================
---
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyInjector.java
(original)
+++
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyInjector.java
Wed Mar 4 21:58:05 2009
@@ -18,7 +18,6 @@
*/
package org.apache.tuscany.sca.implementation.osgi.context;
-
import java.lang.annotation.ElementType;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@@ -34,15 +33,14 @@
import org.apache.tuscany.sca.assembly.ComponentProperty;
import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.context.RequestContextFactory;
-import org.apache.tuscany.sca.core.context.RequestContextImpl;
import org.apache.tuscany.sca.core.factory.ObjectCreationException;
import org.apache.tuscany.sca.core.factory.ObjectFactory;
import org.apache.tuscany.sca.core.invocation.CallbackWireObjectFactory;
import org.apache.tuscany.sca.core.invocation.ProxyFactory;
import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaElementImpl;
import org.apache.tuscany.sca.implementation.java.JavaImplementation;
-import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
-import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl;
+import org.apache.tuscany.sca.implementation.java.JavaResourceImpl;
import
org.apache.tuscany.sca.implementation.java.injection.ArrayMultiplicityObjectFactory;
import
org.apache.tuscany.sca.implementation.java.injection.ConversationIDObjectFactory;
import org.apache.tuscany.sca.implementation.java.injection.FieldInjector;
@@ -52,7 +50,7 @@
import
org.apache.tuscany.sca.implementation.java.injection.ListMultiplicityObjectFactory;
import org.apache.tuscany.sca.implementation.java.injection.MethodInjector;
import
org.apache.tuscany.sca.implementation.java.injection.ResourceObjectFactory;
-import
org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper;
+import
org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
import org.apache.tuscany.sca.runtime.RuntimeWire;
@@ -60,89 +58,82 @@
import org.oasisopen.sca.RequestContext;
import org.oasisopen.sca.annotation.ConversationID;
-
/**
* OSGi property injection support
*
* @version $Rev$ $Date$
*/
public class OSGiPropertyInjector {
-
-
+
private ArrayList<JavaElementImpl> injectionSites = new
ArrayList<JavaElementImpl>();
- private Hashtable<JavaElementImpl, ObjectFactory> factories =
- new Hashtable<JavaElementImpl, ObjectFactory>();
-
+ private Hashtable<JavaElementImpl, ObjectFactory> factories = new
Hashtable<JavaElementImpl, ObjectFactory>();
+
private Injector[] injectors;
-
- public OSGiPropertyInjector(
- JavaImplementation javaImpl,
- RuntimeComponent component,
- JavaPropertyValueObjectFactory propertyValueFactory,
- ProxyFactory proxyFactory,
- RequestContextFactory requestContextFactory) throws
IntrospectionException {
-
+
+ public OSGiPropertyInjector(JavaImplementation javaImpl,
+ RuntimeComponent component,
+ JavaPropertyValueObjectFactory
propertyValueFactory,
+ ProxyFactory proxyFactory,
+ RequestContextFactory requestContextFactory)
throws IntrospectionException {
+
createInjectionSites(javaImpl, component, propertyValueFactory,
proxyFactory, requestContextFactory);
-
+
injectors = createInjectors();
-
+
}
-
@SuppressWarnings("unchecked")
public void injectProperties(Object instance) {
-
+
for (Injector injector : injectors) {
injector.inject(instance);
- }
+ }
}
-
-
+
@SuppressWarnings("unchecked")
- private void createInjectionSites(
- JavaImplementation javaImpl,
- RuntimeComponent component,
- JavaPropertyValueObjectFactory propertyValueFactory,
- ProxyFactory proxyFactory,
- RequestContextFactory requestContextFactory)
- {
+ private void createInjectionSites(JavaImplementation javaImpl,
+ RuntimeComponent component,
+ JavaPropertyValueObjectFactory
propertyValueFactory,
+ ProxyFactory proxyFactory,
+ RequestContextFactory
requestContextFactory) {
List<ComponentProperty> componentProperties =
component.getProperties();
Map<String, JavaElementImpl> propertyMembers =
javaImpl.getPropertyMembers();
-
+
for (ComponentProperty prop : componentProperties) {
JavaElementImpl element = propertyMembers.get(prop.getName());
-
+
if (element != null && !(element.getAnchor() instanceof
Constructor) && prop.getValue() != null) {
- Class propertyJavaType =
JavaIntrospectionHelper.getBaseType(element.getType(),
element.getGenericType());
- ObjectFactory objFactory =
propertyValueFactory.createValueFactory(prop, prop.getValue(),
propertyJavaType);
-
+ Class propertyJavaType =
+ JavaIntrospectionHelper.getBaseType(element.getType(),
element.getGenericType());
+ ObjectFactory objFactory =
+ propertyValueFactory.createValueFactory(prop,
prop.getValue(), propertyJavaType);
+
factories.put(element, objFactory);
injectionSites.add(element);
- }
+ }
}
-
+
for (Member member : javaImpl.getConversationIDMembers()) {
ObjectFactory<String> factory = new ConversationIDObjectFactory();
if (member instanceof Field) {
- JavaElementImpl element = new JavaElementImpl((Field) member);
+ JavaElementImpl element = new JavaElementImpl((Field)member);
element.setClassifer(ConversationID.class);
injectionSites.add(element);
factories.put(element, factory);
} else if (member instanceof Method) {
- JavaElementImpl element = new JavaElementImpl((Method) member,
0);
+ JavaElementImpl element = new JavaElementImpl((Method)member,
0);
element.setName(JavaIntrospectionHelper.toPropertyName(member.getName()));
element.setClassifer(ConversationID.class);
injectionSites.add(element);
factories.put(element, factory);
} else {
- throw new InvalidAccessorException(
- "Member must be a field or method: " +
member.getName());
+ throw new InvalidAccessorException("Member must be a field or
method: " + member.getName());
}
}
-
+
if (!javaImpl.getCallbackMembers().isEmpty()) {
Map<String, List<RuntimeWire>> callbackWires = new HashMap<String,
List<RuntimeWire>>();
for (ComponentService service : component.getServices()) {
@@ -151,20 +142,20 @@
if (callbackReference != null) {
List<RuntimeWire> wires =
callbackReference.getRuntimeWires();
if (!wires.isEmpty()) {
-
callbackWires.put(wires.get(0).getSource().getInterfaceContract().getInterface().toString(),
wires);
+
callbackWires.put(wires.get(0).getSource().getInterfaceContract().getInterface().toString(),
+ wires);
}
}
}
- for (Map.Entry<String, Collection<JavaElementImpl>> entry :
javaImpl.getCallbackMembers()
- .entrySet()) {
+ for (Map.Entry<String, Collection<JavaElementImpl>> entry :
javaImpl.getCallbackMembers().entrySet()) {
List<RuntimeWire> wires = callbackWires.get(entry.getKey());
if (wires == null) {
// this can happen when there are no client wires to a
// component that has a callback
continue;
}
- for(JavaElementImpl element : entry.getValue()) {
+ for (JavaElementImpl element : entry.getValue()) {
ObjectFactory<?> factory = new
CallbackWireObjectFactory(element.getType(), proxyFactory, wires);
if (!(element.getAnchor() instanceof Constructor)) {
injectionSites.add(element);
@@ -173,17 +164,17 @@
}
}
}
-
+
for (JavaResourceImpl resource : javaImpl.getResources().values()) {
-
+
ObjectFactory<?> objectFactory;
Class<?> type = resource.getElement().getType();
if (ComponentContext.class.equals(type)) {
objectFactory = new ComponentContextFactory(component);
-
+
} else if (RequestContext.class.equals(type)) {
- objectFactory = new
RequestContextObjectFactory(requestContextFactory, proxyFactory);
-
+ objectFactory = new
RequestContextObjectFactory(requestContextFactory, proxyFactory, component);
+
} else {
boolean optional = resource.isOptional();
String mappedName = resource.getMappedName();
@@ -194,14 +185,12 @@
injectionSites.add(resource.getElement());
}
}
-
-
+
}
-
@SuppressWarnings("unchecked")
private Injector[] createInjectors() {
-
+
Injector[] injectors = (Injector[])new Injector[injectionSites.size()];
int i = 0;
@@ -227,7 +216,7 @@
}
return injectors;
}
-
+
@SuppressWarnings("unchecked")
protected Injector createMultiplicityInjector(JavaElementImpl element,
List<ObjectFactory<?>> factories) {
Class<?> interfaceType =
JavaIntrospectionHelper.getBaseType(element.getType(),
element.getGenericType());
@@ -252,9 +241,9 @@
}
private static class ComponentContextFactory implements ObjectFactory {
-
+
RuntimeComponent component;
-
+
private ComponentContextFactory(RuntimeComponent component) {
this.component = component;
}
@@ -262,32 +251,26 @@
public Object getInstance() throws ObjectCreationException {
return component.getComponentContext();
}
-
+
}
-
- private static class RequestContextObjectFactory implements ObjectFactory {
-
+ private static class RequestContextObjectFactory implements
ObjectFactory<RequestContext> {
+ private RuntimeComponent component;
private RequestContextFactory factory;
private ProxyFactory proxyFactory;
- public RequestContextObjectFactory(RequestContextFactory factory) {
- this(factory, null);
- }
-
- public RequestContextObjectFactory(RequestContextFactory factory,
ProxyFactory proxyFactory) {
+ public RequestContextObjectFactory(RequestContextFactory factory,
+ ProxyFactory proxyFactory,
+ RuntimeComponent component) {
this.factory = factory;
this.proxyFactory = proxyFactory;
+ this.component = component;
}
public RequestContext getInstance() throws ObjectCreationException {
- if (factory != null) {
- return factory.createRequestContext();
- } else {
- return new RequestContextImpl(proxyFactory);
- }
+ return factory.createRequestContext(component);
}
-
+
}
-
+
}
Modified:
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyValueObjectFactory.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyValueObjectFactory.java?rev=750178&r1=743057&r2=750178&view=diff
==============================================================================
---
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyValueObjectFactory.java
(original)
+++
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyValueObjectFactory.java
Wed Mar 4 21:58:05 2009
@@ -18,7 +18,6 @@
*/
package org.apache.tuscany.sca.implementation.osgi.context;
-
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
@@ -49,16 +48,15 @@
public class OSGiPropertyValueObjectFactory {
protected SimpleTypeMapper simpleTypeMapper = new SimpleTypeMapperImpl();
boolean isSimpleType;
-
-
+
public OSGiPropertyValueObjectFactory() {
}
-
+
public OSGiPropertyValueObjectFactory(Mediator mediator) {
}
-
+
public ObjectFactory createValueFactory(Property property, Object
propertyValue) {
-
+
Class javaType =
SimpleTypeMapperImpl.getJavaType(property.getXSDType());
isSimpleType = isSimpleType(property);
Document doc = (Document)propertyValue;
@@ -69,17 +67,10 @@
if (rootElement.getChildNodes().getLength() > 0) {
value =
rootElement.getChildNodes().item(0).getTextContent();
}
- List<String> values =
- getSimplePropertyValues(value, javaType);
- return new ListObjectFactoryImpl(property,
- values,
- isSimpleType,
- javaType);
- } else {
- return new ListObjectFactoryImpl(property,
- getComplexPropertyValues(doc),
- isSimpleType,
- javaType);
+ List<String> values = getSimplePropertyValues(value, javaType);
+ return new ListObjectFactoryImpl(property, values,
isSimpleType, javaType);
+ } else {
+ return new ListObjectFactoryImpl(property,
getComplexPropertyValues(doc), isSimpleType, javaType);
}
} else {
if (isSimpleType) {
@@ -87,41 +78,34 @@
if (rootElement.getChildNodes().getLength() > 0) {
value =
rootElement.getChildNodes().item(0).getTextContent();
}
- return new ObjectFactoryImpl(property,
- value,
- isSimpleType,
- javaType);
+ return new ObjectFactoryImpl(property, value, isSimpleType,
javaType);
} else {
Object value = getComplexPropertyValues(doc).get(0);
- return new ObjectFactoryImpl(property,
- value,
- isSimpleType,
- javaType);
+ return new ObjectFactoryImpl(property, value, isSimpleType,
javaType);
}
-
+
}
}
-
+
private boolean isSimpleType(Property property) {
if (property.getXSDType() != null) {
return SimpleTypeMapperImpl.isSimpleXSDType(property.getXSDType());
} else {
if (property instanceof Document) {
Document doc = (Document)property;
- Element element = doc.getDocumentElement();
- if (element.getChildNodes().getLength() == 1 &&
- element.getChildNodes().item(0).getNodeType() ==
Node.TEXT_NODE) {
+ Element element = doc.getDocumentElement();
+ if (element.getChildNodes().getLength() == 1 &&
element.getChildNodes().item(0).getNodeType() == Node.TEXT_NODE) {
return true;
}
}
}
return false;
}
-
+
private List<String> getSimplePropertyValues(String concatenatedValue,
Class javaType) {
List<String> propValues = new ArrayList<String>();
StringTokenizer st = null;
- if ( javaType.getName().equals("java.lang.String")) {
+ if (javaType.getName().equals("java.lang.String")) {
st = new StringTokenizer(concatenatedValue, "\"");
} else {
st = new StringTokenizer(concatenatedValue);
@@ -135,19 +119,19 @@
}
return propValues;
}
-
+
private List<Node> getComplexPropertyValues(Document document) {
Element rootElement = document.getDocumentElement();
List<Node> propValues = new ArrayList<Node>();
- for (int count = 0 ; count < rootElement.getChildNodes().getLength() ;
++count) {
+ for (int count = 0; count < rootElement.getChildNodes().getLength();
++count) {
if (rootElement.getChildNodes().item(count).getNodeType() ==
Node.ELEMENT_NODE) {
propValues.add(rootElement.getChildNodes().item(count));
}
}
return propValues;
}
-
- public abstract class ObjectFactoryImplBase implements ObjectFactory {
+
+ public abstract class ObjectFactoryImplBase implements ObjectFactory {
protected SimpleTypeMapper simpleTypeMapper = new
SimpleTypeMapperImpl();
protected Property property;
protected Object propertyValue;
@@ -156,14 +140,14 @@
protected DataType<?> targetDataType;
boolean isSimpleType;
- public ObjectFactoryImplBase(Property property, Object propertyValue,
boolean isSimpleType, Class javaType) {
+ public ObjectFactoryImplBase(Property property, Object propertyValue,
boolean isSimpleType, Class javaType) {
this.isSimpleType = isSimpleType;
this.property = property;
this.propertyValue = propertyValue;
this.javaType = javaType;
sourceDataType =
- new DataTypeImpl<XMLType>(DOMDataBinding.NAME, Node.class,
- new XMLType(null, this.property.getXSDType()));
+ new DataTypeImpl<XMLType>(DOMDataBinding.NAME, Node.class,
+ new XMLType(null,
this.property.getXSDType()));
TypeInfo typeInfo = null;
if (this.property.getXSDType() != null) {
if
(SimpleTypeMapperImpl.isSimpleXSDType(this.property.getXSDType())) {
@@ -184,7 +168,7 @@
}
}
}
-
+
public class ObjectFactoryImpl extends ObjectFactoryImplBase {
public ObjectFactoryImpl(Property property, Object propertyValue,
boolean isSimpleType, Class javaType) {
super(property, propertyValue, isSimpleType, javaType);
@@ -200,8 +184,8 @@
}
}
- public class ListObjectFactoryImpl extends ObjectFactoryImplBase {
- public ListObjectFactoryImpl(Property property, List<?>propertyValues,
boolean isSimpleType, Class javaType) {
+ public class ListObjectFactoryImpl extends ObjectFactoryImplBase {
+ public ListObjectFactoryImpl(Property property, List<?>
propertyValues, boolean isSimpleType, Class javaType) {
super(property, propertyValues, isSimpleType, javaType);
}
@@ -223,4 +207,3 @@
}
}
}
-
Modified:
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java?rev=750178&r1=743057&r2=750178&view=diff
==============================================================================
---
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java
(original)
+++
tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java
Wed Mar 4 21:58:05 2009
@@ -18,15 +18,14 @@
*/
package org.apache.tuscany.sca.implementation.osgi.impl;
-
import java.util.Hashtable;
import java.util.List;
import org.apache.tuscany.sca.assembly.ComponentProperty;
import org.apache.tuscany.sca.assembly.impl.ImplementationImpl;
-import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation;
-
+import org.osgi.framework.Bundle;
/**
* OSGi implementation
@@ -36,32 +35,35 @@
* @version $Rev$ $Date$
*/
public class OSGiImplementationImpl extends ImplementationImpl implements
OSGiImplementation {
-
+
private String bundleSymbolicName;
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 ModelFactoryExtensionPoint modelFactories;
-
- private Object osgiBundle;
-
- public OSGiImplementationImpl(
- ModelFactoryExtensionPoint modelFactories,
- String bundleSymbolicName,
- String bundleVersion,
- String[] imports,
- String[] classList,
- Hashtable<String, List<ComponentProperty>> refProperties,
- Hashtable<String, List<ComponentProperty>> serviceProperties) {
-
+
+ private FactoryExtensionPoint modelFactories;
+
+
+ protected OSGiImplementationImpl(FactoryExtensionPoint modelFactories) {
+ this.modelFactories = modelFactories;
+ }
+
+ 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;
@@ -72,15 +74,14 @@
this.modelFactories = modelFactories;
}
- public void setCallbackProperties(Hashtable<String,
List<ComponentProperty>> refCallbackProperties,
- Hashtable<String, List<ComponentProperty>>
serviceCallbackProperties) {
-
+ public void setCallbackProperties(Hashtable<String,
List<ComponentProperty>> refCallbackProperties,
+ Hashtable<String,
List<ComponentProperty>> serviceCallbackProperties) {
+
this.referenceCallbackProperties = refCallbackProperties;
this.serviceCallbackProperties = serviceCallbackProperties;
-
+
}
-
-
+
public String getBundleSymbolicName() {
return bundleSymbolicName;
}
@@ -92,27 +93,27 @@
public String[] getImports() {
return imports;
}
-
+
public String[] getClassList() {
return classList;
}
-
- public ModelFactoryExtensionPoint getModelFactories() {
+
+ public FactoryExtensionPoint getModelFactories() {
return modelFactories;
}
-
+
public List<ComponentProperty> getReferenceProperties(String
referenceName) {
return referenceProperties.get(referenceName);
}
-
+
public List<ComponentProperty> getServiceProperties(String serviceName) {
return serviceProperties.get(serviceName);
}
-
+
public List<ComponentProperty> getReferenceCallbackProperties(String
referenceName) {
return referenceCallbackProperties.get(referenceName);
}
-
+
public List<ComponentProperty> getServiceCallbackProperties(String
serviceName) {
return serviceCallbackProperties.get(serviceName);
}
@@ -125,12 +126,12 @@
public boolean isAllowsPassByReference() {
return true;
}
-
- public Object getOSGiBundle() {
+
+ public Bundle getOSGiBundle() {
return osgiBundle;
}
- public void setOSGiBundle(Object osgiBundle) {
+ public void setOSGiBundle(Bundle osgiBundle) {
this.osgiBundle = osgiBundle;
}
@@ -144,7 +145,7 @@
@Override
public boolean equals(Object obj) {
-
+
if (!(obj instanceof OSGiImplementationImpl))
return super.equals(obj);
OSGiImplementationImpl impl = (OSGiImplementationImpl)obj;
@@ -156,13 +157,19 @@
return false;
if (!areEqual(serviceCallbackProperties,
impl.serviceCallbackProperties))
return false;
- if (!areEqual(referenceProperties, impl.referenceProperties))
+ if (!areEqual(referenceProperties, impl.referenceProperties))
+ return false;
+ if (!areEqual(referenceCallbackProperties,
impl.referenceCallbackProperties))
return false;
- if (!areEqual(referenceCallbackProperties,
impl.referenceCallbackProperties))
- return false;
return super.equals(obj);
}
-
-
+ public void setBundleSymbolicName(String bundleSymbolicName) {
+ this.bundleSymbolicName = bundleSymbolicName;
+ }
+
+ public void setBundleVersion(String bundleVersion) {
+ this.bundleVersion = bundleVersion;
+ }
+
}