Package org.apache.tapestry5.ioc

Examples of org.apache.tapestry5.ioc.AnnotationProvider


    public static AnnotationProvider toAnnotationProvider(final Method element)
    {
        if (element == null)
            return NULL_ANNOTATION_PROVIDER;

        return new AnnotationProvider()
        {
            public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
            {
                return element.getAnnotation(annotationClass);
            }
View Full Code Here


        {
            public Object answer() throws Throwable
            {
                Object[] args = EasyMock.getCurrentArguments();

                AnnotationProvider ap = (AnnotationProvider) args[1];

                // Verify that annotations on the field are accessible.

                assertNotNull(ap.getAnnotation(Builtin.class));

                return ss;
            }
        };
View Full Code Here

        {
            public Object answer() throws Throwable
            {
                Object[] args = EasyMock.getCurrentArguments();

                AnnotationProvider ap = (AnnotationProvider) args[1];

                // Verify that annotations on the field are accessible.

                assertNotNull(ap.getAnnotation(Builtin.class));

                return ss;
            }
        };
View Full Code Here

        return defaultProvider.defaultTranslatorBinding("value", resources);
    }

    final AnnotationProvider defaultAnnotationProvider()
    {
        return new AnnotationProvider()
        {
            public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
            {
                return resources.getParameterAnnotation("value", annotationClass);
            }
View Full Code Here

                throw new RuntimeException(String.format("Method %s.%s() returns void.", activeClass.getName(),
                        methodName));

            Type returnType = GenericsUtils.extractActualType(activeType, method);

            return new Term(returnType, toUniqueId(method), new AnnotationProvider()
            {
                public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
                {
                    return method.getAnnotation(annotationClass);
                }
View Full Code Here

        final Annotation[] annotations = descriptor.getAnnotations();

        if (annotations != null)
        {
            AnnotationProvider provider = new AnnotationProvider()
            {
                public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
                {
                    for (Object a : annotations)
                    {
                        if (annotationClass.isInstance(a)) return annotationClass.cast(a);
                    }

                    return null;
                }
            };

            if (provider.getAnnotation(Inject.class) != null || provider.getAnnotation(InjectService.class) != null)
                return registry.getObject(objectType, provider);
        }

        return super.resolveDependency(descriptor, beanName, autowiredBeanNames, typeConverter);
    }
View Full Code Here

    public <T> T getObject(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator,
            Module localModule)
    {
        lock.check();

        AnnotationProvider effectiveProvider = annotationProvider != null ? annotationProvider
                : new NullAnnotationProvider();

        // We do a check here for known marker/type combinations, so that you can use a marker
        // annotation
        // to inject into a contribution method that contributes to MasterObjectProvider.
View Full Code Here

    }

    private static Object calculateInjection(Class injectionType, Type genericType, final Annotation[] annotations,
            ObjectLocator locator, InjectionResources resources)
    {
        AnnotationProvider provider = new AnnotationProvider()
        {
            public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
            {
                return findAnnotation(annotations, annotationClass);
            }
        };

        // At some point, it would be nice to eliminate InjectService, and rely
        // entirely on service interface type and point-of-injection markers.

        InjectService is = provider.getAnnotation(InjectService.class);

        if (is != null)
        {
            String serviceId = is.value();

            return locator.getService(serviceId, injectionType);
        }

        // In the absence of @InjectService, try some autowiring. First, does the
        // parameter type match one of the resources (the parameter defaults)?

        if (provider.getAnnotation(Inject.class) == null)
        {
            Object result = resources.findResource(injectionType, genericType);

            if (result != null)
                return result;
View Full Code Here

                // Ignore all static fields.

                if (Modifier.isStatic(f.getModifiers()))
                    continue;

                final AnnotationProvider ap = new AnnotationProvider()
                {
                    public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
                    {
                        return f.getAnnotation(annotationClass);
                    }
                };

                String description = String.format("Calculating injection value for field '%s' (%s)", f.getName(),
                        ClassFabUtils.toJavaClassName(f.getType()));

                tracker.run(description, new Runnable()
                {
                    public void run()
                    {
                        final Class<?> fieldType = f.getType();

                        InjectService is = ap.getAnnotation(InjectService.class);
                        if (is != null)
                        {
                            inject(object, f, locator.getService(is.value(), fieldType));
                            return;
                        }

                        if (ap.getAnnotation(Inject.class) != null)
                        {
                            inject(object, f, locator.getObject(fieldType, ap));
                            return;
                        }

                        if (ap.getAnnotation(InjectResource.class) != null)
                        {
                            Object value = resources.findResource(fieldType, f.getGenericType());

                            if (value == null)
                                throw new RuntimeException(UtilMessages.injectResourceFailure(f.getName(), fieldType));
View Full Code Here

        {
            public Object answer() throws Throwable
            {
                Object[] args = EasyMock.getCurrentArguments();

                AnnotationProvider ap = (AnnotationProvider) args[1];

                // Verify that annotations on the field are accessible.

                assertNotNull(ap.getAnnotation(Builtin.class));

                return ss;
            }
        };
View Full Code Here

TOP

Related Classes of org.apache.tapestry5.ioc.AnnotationProvider

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.