Java 类javax.xml.bind.annotation.XmlValue 实例源码

项目:cibet    文件:AnnotationUtilTest.java   
@Test
public void typeFromAnnotation() {
   log.debug("start AnnotationUtilTest");
   Class<?> a = AnnotationUtil.getTypeOfAnnotatedFieldOrMethod(Sub4EyesController.class, XmlValue.class);
   Assert.assertTrue(a == long.class);

   Class<?> b = AnnotationUtil.getTypeOfAnnotatedFieldOrMethod(Sub4EyesController.class, XmlTransient.class);
   Assert.assertTrue(b == boolean.class);

   Class<?> b1 = AnnotationUtil.getTypeOfAnnotatedFieldOrMethod(CoreTestBase.class, AfterClass.class);
   Assert.assertTrue(b1 == void.class);

   try {
      AnnotationUtil.getTypeOfAnnotatedFieldOrMethod(Sub4EyesController.class, XmlSchemaType.class);
      Assert.fail();
   } catch (AnnotationNotFoundException e) {
      // okay, annotation is not present
   }
}
项目:cibet    文件:AnnotationUtilTest.java   
@Test
public void valueFromAnnotation() {
   Sub4EyesController contr = new Sub4EyesController();
   Object o1 = AnnotationUtil.getValueOfAnnotatedFieldOrMethod(contr, XmlValue.class);
   Assert.assertTrue((Long) o1 == 43);

   Object o2 = AnnotationUtil.getValueOfAnnotatedFieldOrMethod(contr, XmlTransient.class);
   Assert.assertTrue((Boolean) o2 == true);

   ConfigurationTest test = new ConfigurationTest();
   Object o4 = AnnotationUtil.getValueOfAnnotatedFieldOrMethod(test, AfterClass.class);
   Assert.assertTrue(o4 == null);

   try {
      AnnotationUtil.getValueOfAnnotatedFieldOrMethod(contr, XmlSchemaType.class);
      Assert.fail();
   } catch (AnnotationNotFoundException e) {
      // okay, annotation is not present
   }
}
项目:cibet    文件:AnnotationUtilTest.java   
@Test
public void setValueFromAnnotation() {
   Sub4EyesController co = new Sub4EyesController();
   AnnotationUtil.setValueToAnnotatedFieldOrSetter(co, XmlValue.class, 5);
   Assert.assertTrue(co.getDummy1() == 5);

   AnnotationUtil.setValueToAnnotatedFieldOrSetter(co, XmlElement.class, 33);
   Assert.assertTrue(co.getDummy1() == 33);

   try {
      AnnotationUtil.setValueToAnnotatedFieldOrSetter(co, XmlValue.class, null);
      Assert.fail();
   } catch (IllegalArgumentException e) {
      // okay
   }

   AnnotationUtil.setValueToAnnotatedFieldOrSetter(co, XmlTransient.class, true);
   Assert.assertTrue(co.isDummy2() == true);
   AnnotationUtil.setValueToAnnotatedFieldOrSetter(co, XmlTransient.class, false);
   Assert.assertTrue(co.isDummy2() == false);

}
项目:cibet    文件:AnnotationUtilTest.java   
@Test
public void setValueFromAnnotationSub() {
   SubSub4EyesController co = new SubSub4EyesController();
   AnnotationUtil.setValueToAnnotatedFieldOrSetter(co, XmlValue.class, 5);
   Assert.assertTrue(co.getDummy1() == 5);

   AnnotationUtil.setValueToAnnotatedFieldOrSetter(co, XmlElement.class, 33);
   Assert.assertTrue(co.getDummy1() == 33);

   try {
      AnnotationUtil.setValueToAnnotatedFieldOrSetter(co, XmlValue.class, null);
      Assert.fail();
   } catch (IllegalArgumentException e) {
      // okay
   }

   AnnotationUtil.setValueToAnnotatedFieldOrSetter(co, XmlTransient.class, true);
   Assert.assertTrue(co.isDummy2() == true);
   AnnotationUtil.setValueToAnnotatedFieldOrSetter(co, XmlTransient.class, false);
   Assert.assertTrue(co.isDummy2() == false);

   AnnotationUtil.setValueToAnnotatedFieldOrSetter(co, XmlAnyElement.class, 55);
   Assert.assertTrue(co.getDummy1() == 55);
}
项目:cibet    文件:AnnotationUtilTest.java   
@Test
public void isAnnotationPresentField() throws Exception {
   boolean flag = AnnotationUtil.isFieldOrGetterOrSetterAnnotationPresent(Sub4EyesController.class,
         Sub4EyesController.class.getDeclaredField("dummy1"), XmlValue.class);
   Assert.assertTrue(flag);

   try {
      flag = AnnotationUtil.isFieldOrGetterOrSetterAnnotationPresent(Sub4EyesController.class,
            Sub4EyesController.class.getDeclaredField("noSuchField"), XmlValue.class);
      Assert.fail();
   } catch (Exception e1) {
      Assert.assertTrue(e1 instanceof NoSuchFieldException);
   }

   flag = AnnotationUtil.isFieldOrGetterOrSetterAnnotationPresent(Sub4EyesController.class,
         Sub4EyesController.class.getDeclaredField("dummy2"), XmlTransient.class);
   Assert.assertTrue(flag);

   flag = AnnotationUtil.isFieldOrGetterOrSetterAnnotationPresent(Sub4EyesController.class,
         Sub4EyesController.class.getDeclaredField("dummy2"), XmlValue.class);
   Assert.assertTrue(!flag);

   flag = AnnotationUtil.isFieldOrGetterOrSetterAnnotationPresent(Sub4EyesController.class,
         Sub4EyesController.class.getDeclaredField("dummy1"), XmlElement.class);
   Assert.assertTrue(flag);
}
项目:proarc    文件:TaskParameter.java   
@XmlValue
/* Jackson 2.0 ignores @XmlValue for methods and thus @JsonProperty. */
@JsonProperty
public String getValue() {
    String value = null;
    if (valueType == ValueType.NUMBER) {
        BigDecimal n = getValueNumber();
        value = n == null ? null : n.toPlainString();
    } else if (valueType == ValueType.DATETIME) {
        Timestamp t = getValueDateTime();
        if (t != null) {
            value = ISODateTimeFormat.dateTime().withZoneUTC().print(t.getTime());
        }
    } else if (valueType == ValueType.STRING) {
        value = getValueString();
    } else {
        throw new IllegalStateException("Unsupported type: " + valueType);
    }
    return value;
}
项目:hyperjaxb3    文件:AbstractField.java   
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);
}
项目:OpenJSharp    文件:XmlValueQuick.java   
public Class<XmlValue> annotationType() {
    return XmlValue.class;
}
项目:OpenJSharp    文件:AbstractField.java   
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    /*
    TODO: consider moving this logic to somewhere else
    so that it can be better shared, for how a field gets
    annotated doesn't really depend on how we generate accessors.

    so perhaps we should separate those two.
    */

    // TODO: consider a visitor
    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);

    QName st = prop.getSchemaType();
    if(st!=null)
        field.annotate2(XmlSchemaTypeWriter.class)
            .name(st.getLocalPart())
            .namespace(st.getNamespaceURI());

    if(prop.inlineBinaryData())
        field.annotate(XmlInlineBinaryData.class);
}
项目:openjdk-jdk10    文件:AbstractField.java   
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    /*
    TODO: consider moving this logic to somewhere else
    so that it can be better shared, for how a field gets
    annotated doesn't really depend on how we generate accessors.

    so perhaps we should separate those two.
    */

    // TODO: consider a visitor
    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);

    QName st = prop.getSchemaType();
    if(st!=null)
        field.annotate2(XmlSchemaTypeWriter.class)
            .name(st.getLocalPart())
            .namespace(st.getNamespaceURI());

    if(prop.inlineBinaryData())
        field.annotate(XmlInlineBinaryData.class);
}
项目:openjdk9    文件:AbstractField.java   
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    /*
    TODO: consider moving this logic to somewhere else
    so that it can be better shared, for how a field gets
    annotated doesn't really depend on how we generate accessors.

    so perhaps we should separate those two.
    */

    // TODO: consider a visitor
    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);

    QName st = prop.getSchemaType();
    if(st!=null)
        field.annotate2(XmlSchemaTypeWriter.class)
            .name(st.getLocalPart())
            .namespace(st.getNamespaceURI());

    if(prop.inlineBinaryData())
        field.annotate(XmlInlineBinaryData.class);
}
项目:c2mon    文件:DOMFactory.java   
/**
 * Generates an xml element from this pojo. Translating the fields like described
 * in the class description.
 * @param document The document in which the nodes should be.
 * @param rootName This is to use another name for the root element than the
 * simple class name.
 * @param pojo The pojo to take the fields from.
 * @param attributes The fields which should be used as attributes and not
 * as elements.
 * @return The create element representing the provided pojo.
 * @throws ParserConfigurationException Might throw a ParserConfigurationException.
 * @throws IllegalAccessException Might throw a IllegalAccessException.
 * @throws InstantiationException Might throw a InstantiationException.
 */
public Element generateSimpleElement(final Document document, final String rootName,
        final Object pojo, final List<String> attributes) 
        throws ParserConfigurationException,
        IllegalAccessException, InstantiationException {
    Element rootNode = document.createElementNS(getDefaultNamespace(), rootName);
    List<Field> fields = getNonTransientSimpleFields(pojo.getClass());
    for (Field field : fields) {            
        field.setAccessible(true);
        String fieldName = field.getName();

        if (field.get(pojo) != null) {

            if (!attributes.contains(fieldName)) {

                Element element = document.createElementNS(getDefaultNamespace(), getElementName(field));

                // handle CDATAs
                if (field.isAnnotationPresent(XmlValue.class)) {
                    CDATASection cdata = document.createCDATASection(field.get(pojo).toString());
                    element.appendChild(cdata);
                }
                else {
                  element.setTextContent(field.get(pojo).toString());                    
                }

                rootNode.appendChild(element);                    
            }
            else {
                rootNode.setAttribute(getAttributeName(field), field.get(pojo).toString());
            }
        }
    }
    return rootNode;
}
项目:engerek    文件:XNodeProcessorUtil.java   
public static <T> Field findXmlValueField(Class<T> beanClass) {
    for (Field field: beanClass.getDeclaredFields()) {
        XmlValue xmlValue = field.getAnnotation(XmlValue.class);
        if (xmlValue != null) {
            return field;
        }
    }
    return null;
}
项目:lookaside_java-1.8.0-openjdk    文件:AbstractField.java   
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    /*
    TODO: consider moving this logic to somewhere else
    so that it can be better shared, for how a field gets
    annotated doesn't really depend on how we generate accessors.

    so perhaps we should separate those two.
    */

    // TODO: consider a visitor
    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);

    QName st = prop.getSchemaType();
    if(st!=null)
        field.annotate2(XmlSchemaTypeWriter.class)
            .name(st.getLocalPart())
            .namespace(st.getNamespaceURI());

    if(prop.inlineBinaryData())
        field.annotate(XmlInlineBinaryData.class);
}
项目:cibet    文件:AnnotationUtilTest.java   
@Test
public void isAnnotationPresent() throws Exception {
   boolean flag = AnnotationUtil.isFieldOrSetterAnnotationPresent(Sub4EyesController.class, XmlValue.class);
   Assert.assertTrue(flag);

   flag = AnnotationUtil.isFieldOrSetterAnnotationPresent(SubSub4EyesController.class, XmlValue.class);
   Assert.assertTrue(flag);

   flag = AnnotationUtil.isFieldOrSetterAnnotationPresent(SubSub4EyesController.class, XmlElement.class);
   Assert.assertTrue(flag);
}
项目:Camel    文件:EipAnnotationProcessor.java   
private void processValue(RoundEnvironment roundEnv, TypeElement originalClassType, TypeElement classElement, VariableElement fieldElement, String fieldName, XmlValue value,
    Set<EipOption> eipOptions, String prefix, String modelName) {
    Elements elementUtils = processingEnv.getElementUtils();

    // XmlValue has no name attribute
    String name = fieldName;

    if ("method".equals(modelName) || "tokenize".equals(modelName) || "xtokenize".equals(modelName)) {
        // skip expression attribute on these three languages as they are solely configured using attributes
        if ("expression".equals(name)) {
            return;
        }
    }

    name = prefix + name;
    TypeMirror fieldType = fieldElement.asType();
    String fieldTypeName = fieldType.toString();

    String defaultValue = findDefaultValue(fieldElement, fieldTypeName);
    String docComment = findJavaDoc(elementUtils, fieldElement, fieldName, name, classElement, true);
    boolean required = true;
    // metadata may overrule element required
    required = findRequired(fieldElement, required);

    boolean deprecated = fieldElement.getAnnotation(Deprecated.class) != null;

    EipOption ep = new EipOption(name, "value", fieldTypeName, required, defaultValue, docComment, deprecated, false, null, false, null);
    eipOptions.add(ep);
}
项目:infobip-open-jdk-8    文件:AbstractField.java   
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    /*
    TODO: consider moving this logic to somewhere else
    so that it can be better shared, for how a field gets
    annotated doesn't really depend on how we generate accessors.

    so perhaps we should separate those two.
    */

    // TODO: consider a visitor
    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);

    QName st = prop.getSchemaType();
    if(st!=null)
        field.annotate2(XmlSchemaTypeWriter.class)
            .name(st.getLocalPart())
            .namespace(st.getNamespaceURI());

    if(prop.inlineBinaryData())
        field.annotate(XmlInlineBinaryData.class);
}
项目:Novie    文件:XmlMapEntryType.java   
@XmlValue
public String getValue() {
    if (value == null) {
        return null;
    }
    return value.toString();
}
项目:midpoint    文件:XNodeProcessorUtil.java   
public static <T> Field findXmlValueField(Class<T> beanClass) {
    for (Field field: beanClass.getDeclaredFields()) {
        XmlValue xmlValue = field.getAnnotation(XmlValue.class);
        if (xmlValue != null) {
            return field;
        }
    }
    return null;
}
项目:OLD-OpenJDK8    文件:AbstractField.java   
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    /*
    TODO: consider moving this logic to somewhere else
    so that it can be better shared, for how a field gets
    annotated doesn't really depend on how we generate accessors.

    so perhaps we should separate those two.
    */

    // TODO: consider a visitor
    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);

    QName st = prop.getSchemaType();
    if(st!=null)
        field.annotate2(XmlSchemaTypeWriter.class)
            .name(st.getLocalPart())
            .namespace(st.getNamespaceURI());

    if(prop.inlineBinaryData())
        field.annotate(XmlInlineBinaryData.class);
}
项目:ows-context4j    文件:AtomIcon.java   
/**
 * @return the uri
 */
@XmlValue
public String getUri() {
    if (uri==null)
        return null;
    else
        return uri.toString();
}
项目:ows-context4j    文件:AtomLogo.java   
/**
 * @return the uri
 */
@XmlValue
public String getUri() {
    if (uri==null)
        return null;
    else
        return uri.toString();
}
项目:ph-ubl    文件:MainFindOccurrances.java   
/**
 * Create an XML name from the passed field. It uses the {@link XmlElement},
 * {@link XmlAttribute} and {@link XmlValue} annotations to differentiate.
 *
 * @param aField
 *        Source field
 * @return Never <code>null</code>.
 */
@Nonnull
public static String _getXMLName (@Nonnull final Field aField)
{
  final XmlElement aElement = aField.getAnnotation (XmlElement.class);
  if (aElement != null)
    return "/" + aElement.name ();
  final XmlAttribute aAttr = aField.getAnnotation (XmlAttribute.class);
  if (aAttr != null)
    return "/@" + aAttr.name ();
  if (aField.getAnnotation (XmlValue.class) != null)
    return "/value()";
  throw new IllegalStateException ("Field is neither XML element nor attribute nor value: " + aField);
}
项目:openjdk-icedtea7    文件:AbstractField.java   
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    /*
    TODO: consider moving this logic to somewhere else
    so that it can be better shared, for how a field gets
    annotated doesn't really depend on how we generate accessors.

    so perhaps we should separate those two.
    */

    // TODO: consider a visitor
    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);

    QName st = prop.getSchemaType();
    if(st!=null)
        field.annotate2(XmlSchemaTypeWriter.class)
            .name(st.getLocalPart())
            .namespace(st.getNamespaceURI());

    if(prop.inlineBinaryData())
        field.annotate(XmlInlineBinaryData.class);
}
项目:midpoint    文件:XNodeProcessorUtil.java   
public static <T> Field findXmlValueField(Class<T> beanClass) {
    for (Field field: beanClass.getDeclaredFields()) {
        XmlValue xmlValue = field.getAnnotation(XmlValue.class);
        if (xmlValue != null) {
            return field;
        }
    }
    return null;
}
项目:incubator-netbeans    文件:SQLHistoryEntry.java   
@XmlValue
public String getSql() {
    return sql;
}
项目:family-tree-xml-parser    文件:Entry.java   
@XmlValue
public void setValue(String value) {
  this.value = value;
}
项目:CharmMylynConnector    文件:CharmQueryResult.java   
@XmlValue
public String getGuid() {
    return guid;
}
项目:OpenJSharp    文件:XmlValueQuick.java   
public XmlValueQuick(Locatable upstream, XmlValue core) {
    super(upstream);
    this.core = core;
}
项目:OpenJSharp    文件:XmlValueQuick.java   
protected Quick newInstance(Locatable upstream, Annotation core) {
    return new XmlValueQuick(upstream, ((XmlValue) core));
}
项目:elastic-db-tools-for-java    文件:StoreMapping.java   
@XmlValue
public String getValueString() {
    return this.toString();
}
项目:openjdk-jdk10    文件:XmlValueQuick.java   
public XmlValueQuick(Locatable upstream, XmlValue core) {
    super(upstream);
    this.core = core;
}
项目:openjdk-jdk10    文件:XmlValueQuick.java   
public Class<XmlValue> annotationType() {
    return XmlValue.class;
}
项目:ditb    文件:StorageClusterVersionModel.java   
/**
 * @return the storage cluster version
 */
@XmlValue
public String getVersion() {
  return version;
}
项目:openjdk9    文件:XmlValueQuick.java   
public XmlValueQuick(Locatable upstream, XmlValue core) {
    super(upstream);
    this.core = core;
}
项目:openjdk9    文件:XmlValueQuick.java   
protected Quick newInstance(Locatable upstream, Annotation core) {
    return new XmlValueQuick(upstream, ((XmlValue) core));
}
项目:openjdk9    文件:XmlValueQuick.java   
public Class<XmlValue> annotationType() {
    return XmlValue.class;
}
项目:ipst    文件:PossibleTopology.java   
@XmlValue
public String getId() {
    return id;
}
项目:gradle-golang-plugin    文件:Failure.java   
@XmlValue
public String getContents() {
    return _contents;
}
项目:mycore    文件:MCRViewerConfiguration.java   
@XmlValue
public String getXMLValue() {
    return (value == null) ? "" : value.toString();
}