Example usage for java.lang.reflect Field getAnnotations

List of usage examples for java.lang.reflect Field getAnnotations

Introduction

In this page you can find the example usage for java.lang.reflect Field getAnnotations.

Prototype

public Annotation[] getAnnotations() 

Source Link

Usage

From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java

@Test
public void testWithXmlMimeType() {
    Class<WithXmlMimeType> clazz = WithXmlMimeType.class;
    Assert.assertFalse(clazz.isEnum());//from ww  w . ja  v  a  2  s  .co  m
    Assert.assertNotNull(fieldAnnotationProcessingService);
    Field[] fields = clazz.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName()));
        fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations());
        if ("anythingInAList".equals(field.getName())) {
            Assert.assertTrue(fi.hasXmlMimeType());
            Assert.assertEquals("text/xml", fi.getMimtType());
        }
    }
}

From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java

@Test
public final void testWithXmlAttachmentRef() {
    Class<WithXmlAttachmentRef> clazz = WithXmlAttachmentRef.class;
    Assert.assertFalse(clazz.isEnum());/*  w ww  .  ja v  a 2 s  .c  o m*/
    Assert.assertNotNull(fieldAnnotationProcessingService);
    Field[] fields = clazz.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName()));
        fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations());
        if ("anythingInAList".equals(field.getName())) {
            Assert.assertTrue(fi.hasXmlAttachmentRef());

        }
    }
}

From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java

@Test
public void testWithXmlInlineBinaryData() {
    Class<WithXmlInlineBinaryData> clazz = WithXmlInlineBinaryData.class;
    Assert.assertFalse(clazz.isEnum());//from   w w  w . ja v  a2s .c o  m
    Assert.assertNotNull(fieldAnnotationProcessingService);
    Field[] fields = clazz.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName()));
        fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations());
        if ("anythingInAList".equals(field.getName())) {
            Assert.assertTrue(fi.hasXmlInlineBinaryData());

        }
    }
}

From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java

@Test
public void testWithEnumValue() {
    Class<WithEnumValue> clazz = WithEnumValue.class;
    Assert.assertTrue(clazz.isEnum());//  w  ww  .  j a v  a  2s.  co  m
    Assert.assertNotNull(fieldAnnotationProcessingService);
    Field[] fields = clazz.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName()));
        fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations());
        if ("ONE".equals(field.getName())) {
            Assert.assertTrue(fi.hasXmlEnumValue());

        }
    }
}

From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java

@Test
public final void testWithXmlAttribute() {
    Class<WithXmlAttribute> clazz = WithXmlAttribute.class;
    Assert.assertFalse(clazz.isEnum());/*from w w  w  .jav  a  2  s  .c  om*/
    Assert.assertNotNull(fieldAnnotationProcessingService);
    Field[] fields = clazz.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName()));
        fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations());
        if ("anythingInAList".equals(field.getName())) {
            Assert.assertTrue(fi.hasXmlAttribute());
            Assert.assertEquals("Franz", fi.getAttributeName());
            //                Assert.assertNull(fi.getAttributeNamespace());
        }
    }
}

From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java

@Test
public final void testWithXmlAnyElement() {
    Class<WithXmlAnyElement> clazz = WithXmlAnyElement.class;
    Assert.assertFalse(clazz.isEnum());/*from w ww .j  a  v a2s.c  o  m*/
    Assert.assertNotNull(fieldAnnotationProcessingService);
    Field[] fields = clazz.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName()));
        fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations());
        if ("anythingInAList".equals(field.getName())) {
            Assert.assertTrue(fi.hasXmlAnyElement());
            Assert.assertTrue(fi.getAnyElementLax());
            Assert.assertNull(fi.getAnyElementDomHandler());
        }
    }
}

From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java

@Test
public void testProcessAnnotations() {
    Class<NotASingleField> clazz = NotASingleField.class;
    Assert.assertFalse(clazz.isEnum());//from www  . ja va2s. c  o  m
    Assert.assertNotNull(fieldAnnotationProcessingService);
    Field[] fields = clazz.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName()));
        fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations());
    }
    Method[] methods = clazz.getDeclaredMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(method.getName()));
        fieldAnnotationProcessingService.processAnnotations(fi, method.getAnnotations());
    }
}

From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java

@Test
public final void testWithXmlElementRef() {
    Class<WithXmlElementRef> clazz = WithXmlElementRef.class;
    Assert.assertFalse(clazz.isEnum());/*from   w  w w  .  j av a2  s .  co  m*/
    Assert.assertNotNull(fieldAnnotationProcessingService);
    Field[] fields = clazz.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName()));
        fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations());
        if ("anythingInAList".equals(field.getName())) {
            Assert.assertTrue(fi.hasXmlElementRef());
            Assert.assertEquals("Franz", fi.getElementRefName());
            Assert.assertNull(fi.getElementRefNamespace());
            Assert.assertNull(fi.getElementRefType());
        }
    }
}

From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java

@Test
public void testWithXmlElement() {
    Class<WithXmlElement> clazz = WithXmlElement.class;
    Assert.assertFalse(clazz.isEnum());/*from  w w w  . j  a  v a  2  s .  co  m*/
    Assert.assertNotNull(fieldAnnotationProcessingService);
    Field[] fields = clazz.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName()));
        fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations());
        if ("anythingInAList".equals(field.getName())) {
            Assert.assertTrue(fi.hasXmlElement());
            Assert.assertEquals("Franz", fi.getElementName());
            //                Assert.assertNull(fi.getElementNamespace());
            //                Assert.assertNull(fi.getElementDefaultValue());
            //                Assert.assertNull(fi.getElementType());
        }
    }
}

From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java

@Test
public void testWithXmlElementWrapper() {
    Class<WithXmlElementWrapper> clazz = WithXmlElementWrapper.class;
    Assert.assertFalse(clazz.isEnum());/* w ww.j a  v  a 2s .  c  o  m*/
    Assert.assertNotNull(fieldAnnotationProcessingService);
    Field[] fields = clazz.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName()));
        fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations());
        if ("anythingInAList".equals(field.getName())) {
            Assert.assertTrue(fi.hasXmlElementWrapper());
            Assert.assertEquals("theWrapper", fi.getElementWrapperName());
            Assert.assertNull(fi.getElementWrapperNamespace());
            Assert.assertFalse(fi.getElementWrapperNillable());
            Assert.assertFalse(fi.getElementWrapperRequired());
        }
    }
}