Author: rfeng
Date: Fri Sep 14 17:09:01 2007
New Revision: 575831

URL: http://svn.apache.org/viewvc?rev=575831&view=rev
Log:
Add a few missing files (was: Apply the patch from Rajini Sivaram  for 
TUSCANY-1701. Thank you, Rajini.)

Added:
    
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiAnnotations.java
   (with props)
    
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyInjector.java
   (with props)
    
incubator/tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgiproptest.composite

Added: 
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiAnnotations.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiAnnotations.java?rev=575831&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiAnnotations.java
 (added)
+++ 
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiAnnotations.java
 Fri Sep 14 17:09:01 2007
@@ -0,0 +1,315 @@
+/*
+ * 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.context;
+
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Hashtable;
+
+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.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.injection.JavaPropertyValueObjectFactory;
+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;
+import 
org.apache.tuscany.sca.implementation.java.introspect.impl.ConversationProcessor;
+import 
org.apache.tuscany.sca.implementation.java.introspect.impl.DestroyProcessor;
+import 
org.apache.tuscany.sca.implementation.java.introspect.impl.EagerInitProcessor;
+import 
org.apache.tuscany.sca.implementation.java.introspect.impl.HeuristicPojoProcessor;
+import 
org.apache.tuscany.sca.implementation.java.introspect.impl.InitProcessor;
+import 
org.apache.tuscany.sca.implementation.java.introspect.impl.PolicyProcessor;
+import 
org.apache.tuscany.sca.implementation.java.introspect.impl.PropertyProcessor;
+import 
org.apache.tuscany.sca.implementation.java.introspect.impl.ReferenceProcessor;
+import 
org.apache.tuscany.sca.implementation.java.introspect.impl.ResourceProcessor;
+import 
org.apache.tuscany.sca.implementation.java.introspect.impl.ServiceProcessor;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+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.
+ * Instead if the list of implementation classes is specified in 
<implementation.osgi/>,
+ * the classes are introspected when the bundle is resolved. The classes are 
loaded using
+ * the bundle classloader, and hence the delay in annotation processing is 
inevitable.
+ * There is one other difference compared to implementation.java. While 
instances (and
+ * the instance class) are associated with a component in Java, all Java 
annotations from
+ * the component implementation class apply to all the component instances. In 
OSGi, 
+ * instances are associated with services, and a bundle can register multiple 
services.
+ * Hence annotations from classes need to be stored separately so that the 
right ones
+ * can be associated with the service instance.
+ */
+public class OSGiAnnotations  {
+    
+    private Scope scope = Scope.COMPOSITE;
+    private boolean isEagerInit;
+    
+    private String[] classList;
+    
+    private Bundle[] bundles;    
+    
+    private RuntimeComponent runtimeComponent;
+    private JavaPropertyValueObjectFactory propertyValueFactory;
+    private ProxyFactory proxyFactory;
+    
+    private JavaImplementationFactory javaImplementationFactory;
+    private JavaInterfaceFactory javaInterfaceFactory; 
+    private PolicyFactory policyFactory;
+    private RequestContextFactory requestContextFactory;
+    
+    private Hashtable<Class<?>, JavaImplementation> javaAnnotationInfo = 
+        new Hashtable<Class<?>, JavaImplementation>();
+    private Hashtable<JavaImplementation, OSGiPropertyInjector> 
propertyInjectors = 
+        new Hashtable<JavaImplementation, OSGiPropertyInjector>();
+    
+    private long maxAge = Long.MAX_VALUE;
+    private long maxIdleTime = Long.MAX_VALUE;
+    
+    private boolean annotationsProcessed;
+    
+    
+    
+    public OSGiAnnotations(ModelFactoryExtensionPoint 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;
+        for (String className : classList) {
+            for (Bundle bundle : bundles) {
+                try {
+                    Class<?> clazz = bundle.loadClass(className);
+ 
+                    processAnnotations(clazz);
+                    
+                    break;
+                    
+                } catch (ClassNotFoundException e) {                    
+                }
+            }
+        }
+    }
+    
+    
+    public void injectProperties(Object instance) {
+        JavaImplementation javaImpl = getAnnotationInfo(instance);
+        if (javaImpl != null) {
+            OSGiPropertyInjector injector = propertyInjectors.get(javaImpl);
+            if (injector != null)
+                injector.injectProperties(instance);
+        }
+    }
+
+
+    public Scope getScope() {
+        return scope;
+    }
+    
+   
+
+    public boolean isAllowsPassByReference(Object instance, Method method) {
+        
+        JavaImplementation javaImpl = getAnnotationInfo(instance);
+        if (javaImpl == null) {
+            return false;
+        }
+        if (javaImpl.isAllowsPassByReference()) {
+            return true;
+        }
+        return javaImpl.isAllowsPassByReference(method);
+    }
+    
+    
+    public boolean isEagerInit() {
+        return isEagerInit;
+    }
+
+    public long getMaxAge() {
+        return maxAge;
+    }
+
+    public long getMaxIdleTime() {
+        return maxIdleTime;
+    }
+    
+    public Method getInitMethod(Object instance) {
+        JavaImplementation javaImpl = getAnnotationInfo(instance);
+        return javaImpl == null? null : javaImpl.getInitMethod();
+    }
+    
+
+    public Method getDestroyMethod(Object instance) {
+        JavaImplementation javaImpl = getAnnotationInfo(instance);
+        return javaImpl == null? null : javaImpl.getDestroyMethod();       
+    }
+    
+
+    /*
+     * Get the annotation corresponding to an instance
+     * Note that this can be null since annotations are processed from 
implementation
+     * classes in bundles only if the class names are provided in 
<implementation.osgi/>
+     * 
+     */
+    private JavaImplementation getAnnotationInfo(Object instance) {
+        for (Class clazz : javaAnnotationInfo.keySet()) {
+            if (clazz.isInstance(instance)) {
+                return javaAnnotationInfo.get(clazz);
+            }
+        }
+        
+        try {
+            return processAnnotations(instance.getClass());
+        } catch (IntrospectionException e) {
+            // e.printStackTrace();
+        }
+        
+        return null;
+    }
+    
+
+    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);
+
+        propertyInjectors.put(javaImpl, propertyInjector);
+
+        if (javaImpl.isEagerInit())
+            isEagerInit = true;
+        if (javaImpl.getMaxAge() != Long.MAX_VALUE)
+            maxAge = javaImpl.getMaxAge();
+        if (javaImpl.getMaxIdleTime() != Long.MAX_VALUE)
+            maxIdleTime = javaImpl.getMaxIdleTime();
+        if (javaImpl.getJavaScope() != JavaScopeImpl.COMPOSITE)
+            scope = new Scope(javaImpl.getJavaScope().getScope());
+        
+        return javaImpl;
+    }
+        
+    
+    
+    
+    private JavaImplementationFactory  
createJavaImplementationFactory(AssemblyFactory assemblyFactory) {
+        JavaImplementationFactory javaImplementationFactory = new 
DefaultJavaImplementationFactory();
+        
+        // Create the list of class visitors
+        BaseJavaClassVisitor[] extensions =
+            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 
ReferenceProcessor(assemblyFactory, javaInterfaceFactory),
+                                        new ResourceProcessor(assemblyFactory),
+                                        new 
OSGiScopeProcessor(assemblyFactory),
+                                        new ServiceProcessor(assemblyFactory, 
javaInterfaceFactory),
+                                        new 
HeuristicPojoProcessor(assemblyFactory, javaInterfaceFactory),
+                                        new PolicyProcessor(assemblyFactory, 
policyFactory)};
+        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.osoa.sca.annotations.Scope annotation = 
clazz.getAnnotation(org.osoa.sca.annotations.Scope.class);
+            if (annotation == null) {
+                type.setJavaScope(JavaScopeImpl.COMPOSITE);
+                return;
+            }
+            String name = annotation.value();
+            JavaScopeImpl scope;
+            if ("COMPOSITE".equals(name)) {
+                scope = JavaScopeImpl.COMPOSITE;
+            } else if ("SESSION".equals(name)) {
+                scope = JavaScopeImpl.SESSION;
+            } else if ("CONVERSATION".equals(name)) {
+                scope = JavaScopeImpl.CONVERSATION;
+            } else if ("REQUEST".equals(name)) {
+                scope = JavaScopeImpl.REQUEST;
+            } else {
+                scope = new JavaScopeImpl(name);
+            }
+            type.setJavaScope(scope);
+        }
+    }
+
+    
+}

Propchange: 
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiAnnotations.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiAnnotations.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyInjector.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyInjector.java?rev=575831&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyInjector.java
 (added)
+++ 
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyInjector.java
 Fri Sep 14 17:09:01 2007
@@ -0,0 +1,289 @@
+/*
+ * 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.context;
+
+
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+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.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.injection.ArrayMultiplicityObjectFactory;
+import 
org.apache.tuscany.sca.implementation.java.injection.ConversationIDObjectFactory;
+import org.apache.tuscany.sca.implementation.java.injection.FieldInjector;
+import org.apache.tuscany.sca.implementation.java.injection.Injector;
+import 
org.apache.tuscany.sca.implementation.java.injection.InvalidAccessorException;
+import 
org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory;
+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.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.annotations.ConversationID;
+
+
+/**
+ * OSGi property injection support
+ */
+public class OSGiPropertyInjector {
+    
+    
+    private ArrayList<JavaElementImpl> injectionSites = new 
ArrayList<JavaElementImpl>();
+    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 {
+          
+        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) 
+    {
+
+        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);
+                    
+                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);
+                element.setClassifer(ConversationID.class);
+                injectionSites.add(element);
+                factories.put(element, factory);
+            } else if (member instanceof Method) {
+                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());
+            }
+
+        }
+        
+        if (!javaImpl.getCallbackMembers().isEmpty()) {
+            Map<String, List<RuntimeWire>> callbackWires = new HashMap<String, 
List<RuntimeWire>>();
+            for (ComponentService service : component.getServices()) {
+
+                RuntimeComponentReference callbackReference = 
(RuntimeComponentReference)service.getCallbackReference();
+                if (callbackReference != null) {
+                    List<RuntimeWire> wires = 
callbackReference.getRuntimeWires();
+                    if (!wires.isEmpty()) {
+                        
callbackWires.put(wires.get(0).getSource().getInterfaceContract().getInterface().toString(),
 wires);
+                    }
+                }
+            }
+
+            for (Map.Entry<String, 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;
+                }
+                JavaElementImpl element = entry.getValue();
+                ObjectFactory<?> factory = new 
CallbackWireObjectFactory(element.getType(), proxyFactory, wires);
+                if (!(element.getAnchor() instanceof Constructor)) {
+                    injectionSites.add(element);
+                }
+                factories.put(element, factory);
+            }
+        }
+        
+        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);
+               
+            } else {
+                boolean optional = resource.isOptional();
+                String mappedName = resource.getMappedName();
+                objectFactory = new ResourceObjectFactory(type, mappedName, 
optional, null);
+            }
+            factories.put(resource.getElement(), objectFactory);
+            if (!(resource.getElement().getAnchor() instanceof Constructor)) {
+                injectionSites.add(resource.getElement());
+            }
+        }
+        
+        
+    }
+    
+
+    @SuppressWarnings("unchecked")
+    private Injector[] createInjectors() {
+        
+        Injector[] injectors = (Injector[])new Injector[injectionSites.size()];
+
+        int i = 0;
+        for (JavaElementImpl element : injectionSites) {
+            Object obj = factories.get(element);
+            if (obj != null) {
+                if (obj instanceof ObjectFactory) {
+                    ObjectFactory<?> factory = (ObjectFactory<?>)obj;
+                    Member member = (Member)element.getAnchor();
+                    if (element.getElementType() == ElementType.FIELD) {
+                        injectors[i++] = new FieldInjector((Field)member, 
factory);
+                    } else if (element.getElementType() == 
ElementType.PARAMETER && member instanceof Method) {
+                        injectors[i++] = new MethodInjector((Method)member, 
factory);
+                    } else if (member instanceof Constructor) {
+                        // Ignore
+                    } else {
+                        throw new AssertionError(String.valueOf(element));
+                    }
+                } else {
+                    injectors[i++] = createMultiplicityInjector(element, 
(List<ObjectFactory<?>>)obj);
+                }
+            }
+        }
+        return injectors;
+    }
+    
+    @SuppressWarnings("unchecked")
+    protected Injector createMultiplicityInjector(JavaElementImpl element, 
List<ObjectFactory<?>> factories) {
+        Class<?> interfaceType = 
JavaIntrospectionHelper.getBaseType(element.getType(), 
element.getGenericType());
+
+        if (element.getAnchor() instanceof Field) {
+            Field field = (Field)element.getAnchor();
+            if (field.getType().isArray()) {
+                return new FieldInjector(field, new 
ArrayMultiplicityObjectFactory(interfaceType, factories));
+            } else {
+                return new FieldInjector(field, new 
ListMultiplicityObjectFactory(factories));
+            }
+        } else if (element.getAnchor() instanceof Method) {
+            Method method = (Method)element.getAnchor();
+            if (method.getParameterTypes()[0].isArray()) {
+                return new MethodInjector(method, new 
ArrayMultiplicityObjectFactory(interfaceType, factories));
+            } else {
+                return new MethodInjector(method, new 
ListMultiplicityObjectFactory(factories));
+            }
+        } else {
+            throw new InvalidAccessorException("Member must be a field or 
method: " + element.getName());
+        }
+    }
+
+    private static class ComponentContextFactory implements ObjectFactory {
+        
+        RuntimeComponent component;
+        
+        private ComponentContextFactory(RuntimeComponent component) {
+            this.component = component;
+        }
+
+        public Object getInstance() throws ObjectCreationException {
+            return component.getComponentContext();
+        }
+        
+    }
+    
+
+    private static class RequestContextObjectFactory implements ObjectFactory {
+        
+        private RequestContextFactory factory;
+        private ProxyFactory proxyFactory;
+
+        public RequestContextObjectFactory(RequestContextFactory factory) {
+            this(factory, null);
+        }
+
+        public RequestContextObjectFactory(RequestContextFactory factory, 
ProxyFactory proxyFactory) {
+            this.factory = factory;
+            this.proxyFactory = proxyFactory;
+        }
+
+        public RequestContext getInstance() throws ObjectCreationException {
+            if (factory != null) {
+                return factory.createRequestContext();
+            } else {
+                return new RequestContextImpl(proxyFactory);
+            }
+        }
+        
+    }
+    
+}

Propchange: 
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyInjector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyInjector.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgiproptest.composite
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgiproptest.composite?rev=575831&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgiproptest.composite
 (added)
+++ 
incubator/tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgiproptest.composite
 Fri Sep 14 17:09:01 2007
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    * 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.    
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"; 
+           xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0";
+           xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+           name="OSGiTestComposite">
+
+    <component name="OSGiTestServiceComponent">
+        <tuscany:implementation.osgi 
+            bundle="OSGiTestService" 
+            
bundleSymbolicName="org.apache.tuscany.sca.implementation.osgi.test.OSGiTestInterface"
+            
classes="org.apache.tuscany.sca.implementation.osgi.test.OSGiTestWithPropertyImpl"
+        />
+        
+        <property name="currency" type="xsd:string" >USD</property> 
+        <property name="exchangeRate" type="xsd:double" >2.0</property> 
+            
+    </component>
+
+</composite>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to