Package org.apache.tuscany.core.injection

Examples of org.apache.tuscany.core.injection.FieldInjector


    @SuppressWarnings("unchecked")
    public Injector<?> getInjector(ContextResolver resolver) {
        if (method != null) {
            return new MethodInjector(method, new AutowireObjectFactory(method.getParameterTypes()[0], resolver));
        } else {
            return new FieldInjector(field, new AutowireObjectFactory(field.getType(), resolver));
        }
    }
View Full Code Here


        if (method != null) {
            Object monitor = factory.getMonitor(method.getParameterTypes()[0]);
            return new MethodInjector(method, new SingletonObjectFactory<Object>(monitor));
        } else {
            Object monitor = factory.getMonitor(field.getType());
            return new FieldInjector(field, new SingletonObjectFactory<Object>(monitor));
        }
    }
View Full Code Here

    public Injector<?> getInjector(ContextResolver resolver) {
        if (method != null) {
            return new MethodInjector(method, new ContextObjectFactory(resolver));
        } else {
            return new FieldInjector(field, new ContextObjectFactory(resolver));
        }
    }
View Full Code Here

            throw e;
        }
        if (method != null) {
            return new MethodInjector(method, factory);
        }
        return new FieldInjector(field, factory);
    }
View Full Code Here

    public Injector<?> getInjector(ContextResolver resolver) {
        if (method != null) {
            return new MethodInjector(method, new ContextObjectFactory(resolver));
        } else {
            return new FieldInjector(field, new ContextObjectFactory(resolver));
        }
    }
View Full Code Here

    public Injector<?> getEventInvoker(String name) {
        if (method != null) {
            return new MethodInjector(method, new SingletonObjectFactory<Object>(name));
        }else{
            return new FieldInjector(field, new SingletonObjectFactory<Object>(name));
        }
    }
View Full Code Here

        boolean eagerInit = false;
        EventInvoker destroyInvoker = null;
        for (Field field : fields) {
            ComponentName compName = field.getAnnotation(ComponentName.class);
            if (compName != null) {
                Injector injector = new FieldInjector(field, new SingletonObjectFactory(name));
                injectors.add(injector);
            }
            org.osoa.sca.annotations.Context context = field.getAnnotation(org.osoa.sca.annotations.Context.class);
            if (context != null) {
                Injector injector = new FieldInjector(field, new SingletonObjectFactory(moduleComponentContext));
                injectors.add(injector);
            }
        }
        for (Method method : methods) {
            // FIXME Java5
View Full Code Here

            }
        }
        Injector injector = null;
        if (value instanceof DataObject) {
            if (field != null) {
                injector = new FieldInjector(field, new SDOObjectFactory((DataObject) value));
            } else {
                injector = new MethodInjector(method, new SDOObjectFactory((DataObject) value));
            }
        } else if (JavaIntrospectionHelper.isImmutable(type)) {
            if (field != null) {
                injector = new FieldInjector(field, new SingletonObjectFactory<Object>(value));
            } else {
                injector = new MethodInjector(method, new SingletonObjectFactory<Object>(value));
            }
        }
        return injector;
View Full Code Here

            Injector injector;
            // for multiplicities, we need to inject the reference proxy or proxies using an object factory
            // which first delegates to create the proxies and then returns them in the appropriate List or array type
            if (field != null) {
                if (field.getType().isArray()) {
                    injector = new FieldInjector(field, new ArrayMultiplicityObjectFactory(refClass, objectFactories));
                } else {
                    injector = new FieldInjector(field, new ListMultiplicityObjectFactory(objectFactories));
                }
            } else {
                if (method.getParameterTypes()[0].isArray()) {
                    injector = new MethodInjector(method, new ArrayMultiplicityObjectFactory(refClass, objectFactories));
                } else {
                    injector = new MethodInjector(method, new ListMultiplicityObjectFactory(objectFactories));
                }
            }
            return injector;
        } else {
            field = JavaIntrospectionHelper.findClosestMatchingField(refName, refClass, fields);
            if (field == null) {
                // hack for TUSCANY-300
                for (Field current : fields) {
                    Reference annot = current.getAnnotation(Reference.class);
                    if (annot != null) {
                        if (refName.equals(annot.name())) {
                            field = current;
                            break;
                        }
                    }
                }
                if (field == null) {
                    method = JavaIntrospectionHelper.findClosestMatchingMethod(refName, new Class[]{refClass}, methods);
                    if(method == null){
                        // Fix for Tuscany-325
                        method = JavaIntrospectionHelper.findClosestMatchingMethod("set"+refName.substring(0,1).toUpperCase()+ refName.substring(1), new Class[]{refClass}, methods);
                    }
                    if (method == null) {
                        // hack for TUSCANY-300
                        for (Method current : methods) {
                            Reference annot = current.getAnnotation(Reference.class);
                            if (annot != null) {
                                if (refName.equals(annot.name())) {
                                    method = current;
                                    break;
                                }
                            }
                        }
                        if (method == null) {
                            throw new NoAccessorException(refName);
                        }
                    }
                }
            }
            Injector injector;
            if (field != null) {
                injector = new FieldInjector(field, objectFactories.get(0));
            } else {
                injector = new MethodInjector(method, objectFactories.get(0));
            }
            return injector;
        }
View Full Code Here

        }
        Injector injector;
        // FIXME support types other than String
        if (JavaIntrospectionHelper.isImmutable(type)) {
            if (field != null) {
                injector = new FieldInjector(field, new SingletonObjectFactory<Object>(value));
            } else {
                injector = new MethodInjector(method, new SingletonObjectFactory<Object>(value));
            }
        } else {
            if (field != null) {
View Full Code Here

TOP

Related Classes of org.apache.tuscany.core.injection.FieldInjector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.