Package org.oasisopen.sca.annotation

Examples of org.oasisopen.sca.annotation.Property


        if (field.isAnnotationPresent(Reference.class)) {
            Reference ref = field.getAnnotation(Reference.class);
            String name = ref.name() != null && !ref.name().equals("") ? ref.name() : field.getName();
            value = ContextHelper.getReference(name, field.getType(), contextLocator.getServletContext());
        } else if (field.isAnnotationPresent(Property.class)) {
            Property prop = field.getAnnotation(Property.class);
            String name = prop.name() != null && !prop.name().equals("") ? prop.name() : field.getName();
            value = ContextHelper.getProperty(name, contextLocator.getServletContext());
        } else if (field.isAnnotationPresent(ComponentName.class)) {
            RuntimeComponent rc = (RuntimeComponent)contextLocator.getServletContext().getAttribute(ContextHelper.COMPONENT_ATTR);
            value = rc.getName();
        } else if (field.isAnnotationPresent(Context.class)) {
View Full Code Here


        final Class<?> clazz = bean.getClass();

        ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() {
            public void doWith(Method method) {

                Property annotation = (Property)method.getAnnotation(getPropertyAnnotationType());

                if (annotation != null) {
                    if (Modifier.isStatic(method.getModifiers())) {
                        throw new IllegalStateException("Property annotation is not supported on static methods");
                    }

                    /*
                    if (Modifier.isPrivate(method.getModifiers())) {
                        throw new IllegalStateException("Property annotation is not supported on private methods");
                    }
                    */

                    if (method.getParameterTypes().length == 0) {
                        throw new IllegalStateException("Property annotation requires at least one argument: " + method);
                    }

                    PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
                    if (pd != null) {
                        String propName = annotation.name();
                        if ("".equals(propName)) {
                            injectProperty(bean, pd, propertyValue.getPropertyObj(pd.getPropertyType(), pd.getName()));
                        } else {
                            injectProperty(bean, pd, propertyValue.getPropertyObj(pd.getPropertyType(), propName));
                        }
                    }
                }
            }
        });

        ReflectionUtils.doWithFields(clazz, new ReflectionUtils.FieldCallback() {
            public void doWith(Field field) {

                Property annotation = (Property)field.getAnnotation(getPropertyAnnotationType());

                if (annotation != null) {
                    if (Modifier.isStatic(field.getModifiers())) {
                        throw new IllegalStateException("Property annotation is not supported on static fields");
                    }

                    /*
                    if (Modifier.isPrivate(field.getModifiers())) {
                        throw new IllegalStateException("Property annotation is not supported on private fields");
                    }
                    */

                    ReflectionUtils.makeAccessible(field);

                    Object propertyObj = null;
                    String propName = annotation.name();
                    if ("".equals(propName)) {
                        propertyObj = propertyValue.getPropertyObj(field.getType(), field.getName());
                    } else {
                        propertyObj = propertyValue.getPropertyObj(field.getType(), propName);
                    }
View Full Code Here

        final Class<?> clazz = bean.getClass();

        ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() {
            public void doWith(Method method) {

                Property annotation = (Property)method.getAnnotation(getPropertyAnnotationType());

                if (annotation != null) {
                    if (Modifier.isStatic(method.getModifiers())) {
                        throw new IllegalStateException("Property annotation is not supported on static methods");
                    }

                    /*
                    if (Modifier.isPrivate(method.getModifiers())) {
                        throw new IllegalStateException("Property annotation is not supported on private methods");
                    }
                    */

                    if (method.getParameterTypes().length == 0) {
                        throw new IllegalStateException("Property annotation requires at least one argument: " + method);
                    }

                    PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
                    if (pd != null) {
                        String propName = annotation.name();
                        if ("".equals(propName)) {
                            injectProperty(bean, pd, propertyValue.getPropertyObj(pd.getPropertyType(), pd.getName()));
                        } else {
                            injectProperty(bean, pd, propertyValue.getPropertyObj(pd.getPropertyType(), propName));
                        }
                    }
                }
            }
        });

        ReflectionUtils.doWithFields(clazz, new ReflectionUtils.FieldCallback() {
            public void doWith(Field field) {

                Property annotation = (Property)field.getAnnotation(getPropertyAnnotationType());

                if (annotation != null) {
                    if (Modifier.isStatic(field.getModifiers())) {
                        throw new IllegalStateException("Property annotation is not supported on static fields");
                    }

                    /*
                    if (Modifier.isPrivate(field.getModifiers())) {
                        throw new IllegalStateException("Property annotation is not supported on private fields");
                    }
                    */

                    ReflectionUtils.makeAccessible(field);

                    Object propertyObj = null;
                    String propName = annotation.name();
                    if ("".equals(propName)) {
                        propertyObj = propertyValue.getPropertyObj(field.getType(), field.getName());
                    } else {
                        propertyObj = propertyValue.getPropertyObj(field.getType(), propName);
                    }
View Full Code Here

                Reference ref = field.getAnnotation(Reference.class);
                String name = ref.name() != null && !ref.name().equals("") ? ref.name() : field.getName();
                Object value = getReference(name, field.getType(), sc);
                setField(instance, field, value);
            } else if (field.isAnnotationPresent(Property.class)) {
                Property prop = field.getAnnotation(Property.class);
                String name = prop.name() != null && !prop.name().equals("") ? prop.name() : field.getName();
                Object value = getProperty(name, sc);
                setField(instance, field, value);
            } else if (field.isAnnotationPresent(ComponentName.class)) {
                RuntimeComponent rc = (RuntimeComponent)sc.getAttribute(COMPONENT_ATTR);
                setField(instance, field, rc.getName());
            } else if (field.isAnnotationPresent(Context.class)) {
                setField(instance, field, getComponentContext(sc));
            }
        }

        for (Method method : clazz.getDeclaredMethods()) {
            if (!method.getName().startsWith("set") || method.getParameterTypes().length != 1) {
                continue;
            }
            String targetName = method.getName().substring(3);
            Class<?> type = method.getParameterTypes()[0];

            if (method.isAnnotationPresent(Reference.class)) {
                Reference ref = method.getAnnotation(Reference.class);
                String name = ref.name() != null && !ref.name().equals("") ? ref.name() : targetName;
                Object value = getReference(name, type, sc);
                setMethod(instance, method, value);
            } else if (method.isAnnotationPresent(Property.class)) {
                Property prop = method.getAnnotation(Property.class);
                String name = prop.name() != null && !prop.name().equals("") ? prop.name() : targetName;
                Object value = getProperty(name, sc);
                setMethod(instance, method, value);
            } else if (method.isAnnotationPresent(ComponentName.class)) {
                RuntimeComponent rc = (RuntimeComponent)sc.getAttribute(COMPONENT_ATTR);
                setMethod(instance, method, rc.getName());
View Full Code Here

        final Class<?> clazz = bean.getClass();      

        ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() {
            public void doWith(Method method) {

                Property annotation = (Property) method.getAnnotation(getPropertyAnnotationType());
               
                if (annotation != null) {
                    if (Modifier.isStatic(method.getModifiers())) {
                        throw new IllegalStateException("Property annotation is not supported on static methods");
                    }
                   
                    if (Modifier.isPrivate(method.getModifiers())) {
                        throw new IllegalStateException("Property annotation is not supported on private methods");
                    }

                    if (method.getParameterTypes().length == 0) {
                        throw new IllegalStateException("Property annotation requires at least one argument: " + method);
                    }
                   
                    PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
                    if (pd != null) {
                        String propName = annotation.name();
                        if ("".equals(propName)) {
                            injectProperty(bean, pd, propertyValue.getPropertyObj(pd.getPropertyType(), pd.getName()));
                        } else {
                            injectProperty(bean, pd, propertyValue.getPropertyObj(pd.getPropertyType(), propName));
                        }
                    }
                }
            }
        });
       
        ReflectionUtils.doWithFields(clazz, new ReflectionUtils.FieldCallback() {
            public void doWith(Field field) {

                Property annotation = (Property) field.getAnnotation(getPropertyAnnotationType());
               
                if (annotation != null) {
                    if (Modifier.isStatic(field.getModifiers())) {
                        throw new IllegalStateException("Property annotation is not supported on static fields");
                    }
                   
                    if (Modifier.isPrivate(field.getModifiers())) {
                        throw new IllegalStateException("Property annotation is not supported on private fields");
                    }

                    ReflectionUtils.makeAccessible(field);
                   
                    Object propertyObj = null;
                    String propName = annotation.name();
                    if ("".equals(propName)) {
                        propertyObj = propertyValue.getPropertyObj(field.getType(), field.getName());                       
                    } else {
                        propertyObj = propertyValue.getPropertyObj(field.getType(), propName);
                    }
View Full Code Here

TOP

Related Classes of org.oasisopen.sca.annotation.Property

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.