Package org.apache.webbeans.annotation

Examples of org.apache.webbeans.annotation.WebBeansAnnotation


     * @param errorMessage error message
     * @return new annotation
     */
    private static WebBeansAnnotation createInjectionPointAnnotation(List<Attribute> attrs, Class<? extends Annotation> annotClazz, String valueText, String errorMessage)
    {
        WebBeansAnnotation annotation = JavassistProxyFactory.createNewAnnotationProxy(annotClazz);
        boolean isValueAttrDefined = false;
        for (Attribute attr : attrs)
        {
            String attrName = attr.getName();
            String attrValue = attr.getValue();

            if (!isValueAttrDefined)
            {
                if (attrName.equals("value"))
                {
                    isValueAttrDefined = true;
                }
            }

            Class returnType = null;
            try
            {
                returnType = annotClazz.getDeclaredMethod(attrName, new Class[] {}).getReturnType();
                Object value = null;
                if (returnType.isPrimitive())
                {
                    value = ClassUtil.isValueOkForPrimitiveOrWrapper(returnType, attrValue);
                }
                else if (returnType.equals(String.class))
                {
                    value = attrValue;
                }
                else if (returnType.equals(Class.class))
                {
                    value = ClassUtil.getClassFromName(attrValue);

                }
                else if (returnType.isEnum())
                {
                    value = ClassUtil.isValueOkForEnum(returnType, attrValue);
                }
                else
                {
                    throw new WebBeansConfigurationException(errorMessage + "Annotation with type : " + annotClazz.getName() + " with member : " + attrName + " does not have sutiable member return type");
                }

                if (value == null)
                {
                    throw new WebBeansConfigurationException(errorMessage + "Annotation with type : " + annotClazz.getName() + " with member : " + attrName + " value does not defined correctly");
                }

                annotation.setMemberValue(attrName, value);

            }
            catch (SecurityException e)
            {
                throw new WebBeansException(e);

            }
            catch (NoSuchMethodException e)
            {
                throw new WebBeansConfigurationException(errorMessage + "Annotation with type : " + annotClazz.getName() + " does not have member with name : " + attrName);
            }
        }

        if (!isValueAttrDefined)
        {
            if (valueText != null && !valueText.equals(""))
            {
                annotation.setMemberValue("value", valueText);
            }
        }

        return annotation;
    }
View Full Code Here


     * @param errorMessage error message
     * @return new annotation
     */
    private static WebBeansAnnotation createInjectionPointAnnotation(List<Attribute> attrs, Class<? extends Annotation> annotClazz, String valueText, String errorMessage)
    {
        WebBeansAnnotation annotation = JavassistProxyFactory.createNewAnnotationProxy(annotClazz);
        boolean isValueAttrDefined = false;
        for (Attribute attr : attrs)
        {
            String attrName = attr.getName();
            String attrValue = attr.getValue();

            if (!isValueAttrDefined)
            {
                if (attrName.equals("value"))
                {
                    isValueAttrDefined = true;
                }
            }

            Class returnType = null;
            try
            {
                returnType = annotClazz.getDeclaredMethod(attrName, new Class[] {}).getReturnType();
                Object value = null;
                if (returnType.isPrimitive())
                {
                    value = ClassUtil.isValueOkForPrimitiveOrWrapper(returnType, attrValue);
                }
                else if (returnType.equals(String.class))
                {
                    value = attrValue;
                }
                else if (returnType.equals(Class.class))
                {
                    value = ClassUtil.getClassFromName(attrValue);

                }
                else if (returnType.isEnum())
                {
                    value = ClassUtil.isValueOkForEnum(returnType, attrValue);
                }
                else
                {
                    throw new WebBeansConfigurationException(errorMessage + "Annotation with type : " + annotClazz.getName() + " with member : " + attrName + " does not have sutiable member return type");
                }

                if (value == null)
                {
                    throw new WebBeansConfigurationException(errorMessage + "Annotation with type : " + annotClazz.getName() + " with member : " + attrName + " value does not defined correctly");
                }

                annotation.setMemberValue(attrName, value);

            }
            catch (SecurityException e)
            {
                throw new WebBeansException(e);

            }
            catch (NoSuchMethodException e)
            {
                throw new WebBeansConfigurationException(errorMessage + "Annotation with type : " + annotClazz.getName() + " does not have member with name : " + attrName);
            }
        }

        if (!isValueAttrDefined)
        {
            if (valueText != null && !valueText.equals(""))
            {
                annotation.setMemberValue("value", valueText);
            }
        }

        return annotation;
    }
View Full Code Here

    @Test
    public void testAnnotationLiteral()
    {
        Annotation annotation = AnnotatedClass.class.getAnnotation(AnnotationWithBindingMember.class);
        WebBeansAnnotation webBeansAnnotation = new WebBeansAnnotation(AnnotationWithBindingMember.class);

        LiteralType al = new LiteralType()
        {

            public int number()
            {
                // TODO Auto-generated method stub
                return 5;
            }

            public String value()
            {
                return "Gurkan";
            }

        };

        webBeansAnnotation.setMemberValue("value", "Gurkan");
        webBeansAnnotation.setMemberValue("number", 5);

        Assert.assertTrue(annotation.equals(al));

    }
View Full Code Here

    @Test
    public void testAnnotationWebBeans()
    {
        Annotation annotation = AnnotatedClass.class.getAnnotation(AnnotationWithBindingMember.class);
        Annotation defAnnotation = DefaultAnnotatedClass.class.getAnnotation(AnnotationWithBindingMember.class);
        WebBeansAnnotation webBeansAnnotation = JavassistProxyFactory.createNewAnnotationProxy(AnnotationWithBindingMember.class);

        webBeansAnnotation.setMemberValue("value", "Gurkan");
        webBeansAnnotation.setMemberValue("number", 5);

        Assert.assertTrue(annotation.equals(webBeansAnnotation));
        Assert.assertTrue(webBeansAnnotation.equals(annotation));

        WebBeansAnnotation webBeansAnnotation2 = JavassistProxyFactory.createNewAnnotationProxy(AnnotationWithBindingMember.class);

        Assert.assertTrue(webBeansAnnotation2.equals(defAnnotation));
        Assert.assertTrue(defAnnotation.equals(webBeansAnnotation2));
        Assert.assertTrue(!webBeansAnnotation2.equals(annotation));
        Assert.assertTrue(!annotation.equals(webBeansAnnotation2));
    }
View Full Code Here

        return result;
    }

    public static WebBeansAnnotation createNewAnnotationProxy(Class<? extends Annotation> annotationType)
    {
        WebBeansAnnotation result = null;

        try
        {
            ProxyFactory pf = new ProxyFactory();
            pf.setInterfaces(new Class<?>[] { annotationType, Annotation.class });
            pf.setSuperclass(WebBeansAnnotation.class);
            pf.setHandler(new WebBeansAnnotation(annotationType));

            result = (WebBeansAnnotation) pf.create(new Class[] { Class.class }, new Object[] { annotationType });

        }
        catch (Exception e)
View Full Code Here

       
    }
   
    public static WebBeansAnnotation createNewAnnotationProxy(Class<? extends Annotation> annotationType)
    {
        WebBeansAnnotation result = null;

        try
        {
            ProxyFactory pf = new ProxyFactory();
            pf.setInterfaces(new Class<?>[] { annotationType, Annotation.class });
            pf.setSuperclass(WebBeansAnnotation.class);

            result = (WebBeansAnnotation) pf.create(new Class[] { Class.class }, new Object[] { annotationType });
            ((ProxyObject)result).setHandler(new WebBeansAnnotation(annotationType));
        }
        catch (Exception e)
        {
            WebBeansUtil.throwRuntimeExceptions(e);
        }
View Full Code Here

     * @param errorMessage error message
     * @return new annotation
     */
    private static WebBeansAnnotation createInjectionPointAnnotation(NamedNodeMap attrs, Class<? extends Annotation> annotClazz, String valueText, String errorMessage)
    {
        WebBeansAnnotation annotation = JavassistProxyFactory.createNewAnnotationProxy(annotClazz);
        boolean isValueAttrDefined = false;
        for (int i = 0; i < attrs.getLength(); i++)
        {
            Attr attr = (Attr) attrs.item(i);
            String attrName = attr.getName();
            String attrValue = attr.getValue();

            if (!isValueAttrDefined)
            {
                if (attrName.equals("value"))
                {
                    isValueAttrDefined = true;
                }
            }

            Class returnType = null;
            try
            {
                returnType = SecurityUtil.doPrivilegedGetDeclaredMethod(annotClazz, attrName, new Class[]{}).getReturnType();
                Object value = null;
                if (returnType.isPrimitive())
                {
                    value = ClassUtil.isValueOkForPrimitiveOrWrapper(returnType, attrValue);
                }
                else if (returnType.equals(String.class))
                {
                    value = attrValue;
                }
                else if (returnType.equals(Class.class))
                {
                    value = ClassUtil.getClassFromName(attrValue);

                }
                else if (returnType.isEnum())
                {
                    value = ClassUtil.isValueOkForEnum(returnType, attrValue);
                }
                else
                {
                    throw new WebBeansConfigurationException(
                            errorMessage + "Annotation with type : " + annotClazz.getName() + " with member : " + attrName + " does not have sutiable member return type");
                }

                if (value == null)
                {
                    throw new WebBeansConfigurationException(
                            errorMessage + "Annotation with type : " + annotClazz.getName() + " with member : " + attrName + " value does not defined correctly");
                }

                annotation.setMemberValue(attrName, value);

            }
            catch (SecurityException e)
            {
                throw new WebBeansException(e);

            }
            catch (NoSuchMethodException e)
            {
                throw new WebBeansConfigurationException(errorMessage + "Annotation with type : " + annotClazz.getName() + " does not have member with name : " + attrName);
            }
        }

        if (!isValueAttrDefined)
        {
            if (valueText != null && !valueText.equals(""))
            {
                annotation.setMemberValue("value", valueText);
            }
        }

        return annotation;
    }
View Full Code Here

       
    }
   
    public static WebBeansAnnotation createNewAnnotationProxy(Class<? extends Annotation> annotationType)
    {
        WebBeansAnnotation result = null;

        try
        {
            ProxyFactory pf = new ProxyFactory();
            pf.setInterfaces(new Class<?>[] { annotationType, Annotation.class });
            pf.setSuperclass(WebBeansAnnotation.class);
            pf.setHandler(new WebBeansAnnotation(annotationType));

            result = (WebBeansAnnotation) pf.create(new Class[] { Class.class }, new Object[] { annotationType });

        }
        catch (Exception e)
View Full Code Here

    @Test
    public void testAnnotationLiteral()
    {
        Annotation annotation = AnnotatedClass.class.getAnnotation(AnnotationWithBindingMember.class);
        WebBeansAnnotation webBeansAnnotation = new WebBeansAnnotation(AnnotationWithBindingMember.class);

        LiteralType al = new LiteralType()
        {

            public int number()
            {
                // TODO Auto-generated method stub
                return 5;
            }

            public String value()
            {
                return "Gurkan";
            }

        };

        webBeansAnnotation.setMemberValue("value", "Gurkan");
        webBeansAnnotation.setMemberValue("number", 5);

        Assert.assertTrue(annotation.equals(al));

    }
View Full Code Here

    @Test
    public void testAnnotationWebBeans()
    {
        Annotation annotation = AnnotatedClass.class.getAnnotation(AnnotationWithBindingMember.class);
        Annotation defAnnotation = DefaultAnnotatedClass.class.getAnnotation(AnnotationWithBindingMember.class);
        WebBeansAnnotation webBeansAnnotation = JavassistProxyFactory.createNewAnnotationProxy(AnnotationWithBindingMember.class);

        webBeansAnnotation.setMemberValue("value", "Gurkan");
        webBeansAnnotation.setMemberValue("number", 5);

        Assert.assertTrue(annotation.equals(webBeansAnnotation));
        Assert.assertTrue(webBeansAnnotation.equals(annotation));

        WebBeansAnnotation webBeansAnnotation2 = JavassistProxyFactory.createNewAnnotationProxy(AnnotationWithBindingMember.class);

        Assert.assertTrue(webBeansAnnotation2.equals(defAnnotation));
        Assert.assertTrue(defAnnotation.equals(webBeansAnnotation2));
        Assert.assertTrue(!webBeansAnnotation2.equals(annotation));
        Assert.assertTrue(!annotation.equals(webBeansAnnotation2));
    }
View Full Code Here

TOP

Related Classes of org.apache.webbeans.annotation.WebBeansAnnotation

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.