javax.xml.bind.annotation.XmlType源码实例Demo

类javax.xml.bind.annotation.XmlType源码实例Demo

下面列出了javax.xml.bind.annotation.XmlType 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cxf   文件: WadlGenerator.java
@Override
public QName resolve(Class<?> type, Annotation[] annotations, Map<Class<?>, QName> clsMap) {
    QName qname = WadlGenerator.this.getJaxbQName(proxy, type, clsMap);
    if (qname == null && supportJaxbXmlType) {
        XmlType root = type.getAnnotation(XmlType.class);
        if (root != null) {
            XMLName name = AnnotationUtils.getAnnotation(annotations, XMLName.class);
            if (name == null) {
                qname = getJaxbQName(root.name(), root.namespace(), type, clsMap);
            } else {
                QName tempQName = JAXRSUtils.convertStringToQName(name.value());
                qname = new QName(tempQName.getNamespaceURI(),
                                  tempQName.getLocalPart(),
                                  getPrefix(tempQName.getNamespaceURI(), clsMap));
            }
        }
    }
    return qname;
}
 
/**
 * {@inheritDoc}
 * <p>Jaxb2CollectionHttpMessageConverter can read a generic
 * {@link Collection} where the generic type is a JAXB type annotated with
 * {@link XmlRootElement} or {@link XmlType}.
 */
@Override
public boolean canRead(Type type, @Nullable Class<?> contextClass, @Nullable MediaType mediaType) {
	if (!(type instanceof ParameterizedType)) {
		return false;
	}
	ParameterizedType parameterizedType = (ParameterizedType) type;
	if (!(parameterizedType.getRawType() instanceof Class)) {
		return false;
	}
	Class<?> rawType = (Class<?>) parameterizedType.getRawType();
	if (!(Collection.class.isAssignableFrom(rawType))) {
		return false;
	}
	if (parameterizedType.getActualTypeArguments().length != 1) {
		return false;
	}
	Type typeArgument = parameterizedType.getActualTypeArguments()[0];
	if (!(typeArgument instanceof Class)) {
		return false;
	}
	Class<?> typeArgumentClass = (Class<?>) typeArgument;
	return (typeArgumentClass.isAnnotationPresent(XmlRootElement.class) ||
			typeArgumentClass.isAnnotationPresent(XmlType.class)) && canRead(mediaType);
}
 
源代码3 项目: freehealth-connector   文件: XmlAsserter.java
@SuppressWarnings("unchecked")
private static String convert(Object obj) {
    try {
        Class clazz = obj.getClass();
        if (!jaxbContextMap.containsKey(clazz)) {
            jaxbContextMap.put(clazz, JAXBContext.newInstance(clazz));
        }
        JAXBContext context = jaxbContextMap.get(clazz);
        Marshaller marshaller = context.createMarshaller();
        StringWriter writer = new StringWriter();
        if (obj.getClass().isAnnotationPresent(XmlRootElement.class)) {
            marshaller.marshal(obj, writer);
        } else if (obj.getClass().isAnnotationPresent(XmlType.class)) {
            JAXBElement jaxbElement = new JAXBElement(new QName("", obj.getClass().getSimpleName()), clazz, obj);
            marshaller.marshal(jaxbElement, writer);
        }
        return writer.toString();
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        Assert.fail(e.getMessage());
    }
    return null;
}
 
源代码4 项目: freehealth-connector   文件: XmlAsserter.java
private static String convert(Object obj) {
   try {
      Class clazz = obj.getClass();
      if (!jaxbContextMap.containsKey(clazz)) {
         jaxbContextMap.put(clazz, JAXBContext.newInstance(clazz));
      }

      JAXBContext context = (JAXBContext)jaxbContextMap.get(clazz);
      Marshaller marshaller = context.createMarshaller();
      StringWriter writer = new StringWriter();
      if (obj.getClass().isAnnotationPresent(XmlRootElement.class)) {
         marshaller.marshal(obj, (Writer)writer);
      } else if (obj.getClass().isAnnotationPresent(XmlType.class)) {
         JAXBElement jaxbElement = new JAXBElement(new QName("", obj.getClass().getSimpleName()), clazz, obj);
         marshaller.marshal(jaxbElement, (Writer)writer);
      }

      return writer.toString();
   } catch (Exception var6) {
      LOG.error(var6.getMessage(), var6);
      Assert.fail(var6.getMessage());
      return null;
   }
}
 
源代码5 项目: freehealth-connector   文件: XmlAsserter.java
@SuppressWarnings("unchecked")
private static String convert(Object obj) {
    try {
        Class clazz = obj.getClass();
        if (!jaxbContextMap.containsKey(clazz)) {
            jaxbContextMap.put(clazz, JAXBContext.newInstance(clazz));
        }
        JAXBContext context = jaxbContextMap.get(clazz);
        Marshaller marshaller = context.createMarshaller();
        StringWriter writer = new StringWriter();
        if (obj.getClass().isAnnotationPresent(XmlRootElement.class)) {
            marshaller.marshal(obj, writer);
        } else if (obj.getClass().isAnnotationPresent(XmlType.class)) {
            JAXBElement jaxbElement = new JAXBElement(new QName("", obj.getClass().getSimpleName()), clazz, obj);
            marshaller.marshal(jaxbElement, writer);
        }
        return writer.toString();
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        Assert.fail(e.getMessage());
    }
    return null;
}
 
源代码6 项目: sis   文件: PropertyComparator.java
/**
 * Uses the {@link XmlType} annotation for defining the property order.
 *
 * @param implementation  the implementation class where to search for {@code XmlType} annotation.
 * @param order           the {@link #order} map where to store the properties order.
 */
private static void defineOrder(Class<?> implementation, final Map<Object,Integer> order) {
    do {
        final XmlType xml = implementation.getAnnotation(XmlType.class);
        if (xml != null) {
            final String[] propOrder = xml.propOrder();
            for (int i=propOrder.length; --i>=0;) {
                /*
                 * Add the entries in reverse order because we are iterating from the child class to
                 * the parent class, and we want the properties in the parent class to be sorted first.
                 * If duplicated properties are found, keep the first occurence (i.e. sort the property
                 * with the most specialized child that declared it).
                 *
                 * We make an exception for ResponsibleParty.role, which should be replaced by Party.role
                 * but this replacement is not yet effective in GeoAPI 3.0.
                 */
                final String prop = propOrder[i];
                if (!"role".equals(prop) || !ResponsibleParty.class.isAssignableFrom(implementation)) {
                    order.putIfAbsent(prop, order.size());
                }
            }
        }
        implementation = implementation.getSuperclass();
    } while (implementation != null);
}
 
源代码7 项目: zstack   文件: DeployerValidator.java
private void validateCollection(Field f, Object obj) throws IllegalArgumentException, IllegalAccessException {
    XmlType xtype = obj.getClass().getAnnotation(XmlType.class);
    if (xtype == null) {
        return;
    }
    String elementName = xtype.name();
    logger.debug(String.format("validating %s->%s", elementName, f.getName()));

    Collection l = (Collection) f.get(obj);
    XmlElement eat = f.getAnnotation(XmlElement.class);
    if (eat != null && (eat.required() && (l == null || l.isEmpty()))) {
        throw new IllegalArgumentException(String.format("field[%s] of element[%s] is mandatory, cannot be missed", f.getName(), elementName));
    }
    XmlAttribute aat = f.getAnnotation(XmlAttribute.class);
    if (aat != null && (aat.required() && (l == null || l.isEmpty()))) {
        throw new IllegalArgumentException(String.format("field[%s] of element[%s] is mandatory, cannot be missed", aat.name(), elementName));
    }

    if (l != null) {
        Object val = l.iterator().next();
        if (val != null) {
            validateObject(val);
        }
    }
}
 
public static Stub convertToStub(JavaLanguageVariable variable, StubTypeTreeRepository typeTreeRepository) {
	Stub stub = new Stub();
	stub.setStubName(variable.getVariableName());
	stub.setRequired(variable.isRequired());
	stub.setMultiOccurs(variable.isMultiOccurs());
	stub.setDescription(variable.getDescription());
	stub.setType(variable.getType());

	Class<?> type = variable.getType();
	if (variable.getType().isArray())
		type = variable.getType().getComponentType();

	if (type.isAnnotationPresent(XmlType.class) && !type.isEnum()) {
		convertFieldsToChildStubs(stub, type, typeTreeRepository);
	}

	return stub;
}
 
/**
 * {@inheritDoc}
 * <p>Jaxb2CollectionHttpMessageConverter can read a generic
 * {@link Collection} where the generic type is a JAXB type annotated with
 * {@link XmlRootElement} or {@link XmlType}.
 */
@Override
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
	if (!(type instanceof ParameterizedType)) {
		return false;
	}
	ParameterizedType parameterizedType = (ParameterizedType) type;
	if (!(parameterizedType.getRawType() instanceof Class)) {
		return false;
	}
	Class<?> rawType = (Class<?>) parameterizedType.getRawType();
	if (!(Collection.class.isAssignableFrom(rawType))) {
		return false;
	}
	if (parameterizedType.getActualTypeArguments().length != 1) {
		return false;
	}
	Type typeArgument = parameterizedType.getActualTypeArguments()[0];
	if (!(typeArgument instanceof Class)) {
		return false;
	}
	Class<?> typeArgumentClass = (Class<?>) typeArgument;
	return (typeArgumentClass.isAnnotationPresent(XmlRootElement.class) ||
			typeArgumentClass.isAnnotationPresent(XmlType.class)) && canRead(mediaType);
}
 
源代码10 项目: cxf   文件: SchemaCollectionContextProxy.java
private QName getTypeQName(Class<?> cls, String namespace) {
    QName qn = TYPE_MAP.get(cls);
    if (qn != null) {
        return qn;
    }
    XmlType xtype = cls.getAnnotation(XmlType.class);
    String tn = xtype == null ? "##default" : xtype.name();
    String tns = xtype == null ? "##default" : xtype.namespace();
    if ("##default".equals(tn)) {
        tn = java.beans.Introspector.decapitalize(cls.getSimpleName());
    }
    if ("##default".equals(tns) || StringUtils.isEmpty(tns)) {
        tns = JAXBUtils.getPackageNamespace(cls);
    }
    if ("##default".equals(tns) || StringUtils.isEmpty(tns)) {
        tns = namespace;
    }
    return new QName(tns, tn);
}
 
源代码11 项目: cxf   文件: AbstractJAXBProvider.java
protected QName getJaxbQName(Class<?> cls, Type type, Object object, boolean pluralName)
    throws Exception {

    if (cls == JAXBElement.class) {
        return object != null ? ((JAXBElement<?>)object).getName() : null;
    }

    XmlRootElement root = cls.getAnnotation(XmlRootElement.class);
    if (root != null) {
        return getQNameFromNamespaceAndName(root.namespace(), root.name(), cls, pluralName);
    } else if (isXmlType(cls)) {
        XmlType xmlType = cls.getAnnotation(XmlType.class);
        return getQNameFromNamespaceAndName(xmlType.namespace(), xmlType.name(), cls, pluralName);
    } else {
        return new QName(getPackageNamespace(cls), cls.getSimpleName());
    }
}
 
源代码12 项目: spring-analysis-note   文件: Jaxb2XmlEncoder.java
@Override
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
	if (super.canEncode(elementType, mimeType)) {
		Class<?> outputClass = elementType.toClass();
		return (outputClass.isAnnotationPresent(XmlRootElement.class) ||
				outputClass.isAnnotationPresent(XmlType.class));
	}
	else {
		return false;
	}
}
 
源代码13 项目: TencentKona-8   文件: TypeInfoImpl.java
/**
 * Parses a (potentially-null) {@link XmlType} annotation on a class
 * and determine the actual value.
 *
 * @param clazz
 *      The class on which the XmlType annotation is checked.
 * @param t
 *      The {@link XmlType} annotation on the clazz. This value
 *      is taken as a parameter to improve the performance for the case where
 *      't' is pre-computed.
 */
protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
    String nsUri="##default";
    String local="##default";
    if(t!=null) {
        nsUri = t.namespace();
        local = t.name();
    }

    if(local.length()==0)
        return null; // anonymous


    if(local.equals("##default"))
        // if defaulted ...
        local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));

    if(nsUri.equals("##default")) {
        // if defaulted ...
        XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
        if(xs!=null)
            nsUri = xs.namespace();
        else {
            nsUri = builder.defaultNsUri;
        }
    }

    return new QName(nsUri.intern(),local.intern());
}
 
源代码14 项目: TencentKona-8   文件: ClassInfoImpl.java
/**
 *  XmlType allows specification of factoryClass and
 *  factoryMethod.  There are to be used if no default
 *  constructor is found.
 *
 * @return
 *      true if the factory method was found. False if not.
 */
private  boolean hasFactoryConstructor(XmlType t){
    if (t == null) return false;

    String method = t.factoryMethod();
    T fClass = reader().getClassValue(t, "factoryClass");
    if (method.length() > 0){
        if(nav().isSameType(fClass, nav().ref(XmlType.DEFAULT.class))){
            fClass = nav().use(clazz);
        }
        for(M m: nav().getDeclaredMethods(nav().asDecl(fClass))){
            //- Find the zero-arg public static method with the required return type
            if (nav().getMethodName(m).equals(method) &&
                nav().isSameType(nav().getReturnType(m), nav().use(clazz)) &&
                nav().getMethodParameters(m).length == 0 &&
                nav().isStaticMethod(m)){
                factoryMethod = m;
                break;
            }
        }
        if (factoryMethod == null){
            builder.reportError(new IllegalAnnotationException(
            Messages.NO_FACTORY_METHOD.format(nav().getClassName(nav().asDecl(fClass)), method), this ));
        }
    } else if(!nav().isSameType(fClass, nav().ref(XmlType.DEFAULT.class))){
        builder.reportError(new IllegalAnnotationException(
            Messages.FACTORY_CLASS_NEEDS_FACTORY_METHOD.format(nav().getClassName(nav().asDecl(fClass))), this ));
    }
    return factoryMethod != null;
}
 
源代码15 项目: TencentKona-8   文件: WebServiceWrapperGenerator.java
private void writeXmlTypeDeclaration(JDefinedClass cls, String typeName, String namespaceUri,
                                     Collection<MemberInfo> members) {
    if (cls == null)
        return;
    JAnnotationUse xmlTypeAnn = cls.annotate(cm.ref(XmlType.class));
    xmlTypeAnn.param("name", typeName);
    xmlTypeAnn.param("namespace", namespaceUri);
    if (members.size() > 1) {
        JAnnotationArrayMember paramArray = xmlTypeAnn.paramArray("propOrder");
        for (MemberInfo memInfo : members) {
            paramArray.param(memInfo.getParamName());
        }
    }
}
 
源代码16 项目: java-technology-stack   文件: Jaxb2XmlEncoder.java
@Override
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
	if (super.canEncode(elementType, mimeType)) {
		Class<?> outputClass = elementType.toClass();
		return (outputClass.isAnnotationPresent(XmlRootElement.class) ||
				outputClass.isAnnotationPresent(XmlType.class));
	}
	else {
		return false;
	}
}
 
源代码17 项目: freehealth-connector   文件: XmlAsserter.java
private static String toString(Object obj) {
    if (obj.getClass().isAnnotationPresent(XmlType.class)) {
        return convert(obj);
    } else if (obj instanceof InputStream) {
        return convert((InputStream) obj);
    }
    LOG.info("obj instanceof " + obj.getClass().getName() + " using default toString() method.");
    return obj.toString();

}
 
源代码18 项目: openjdk-8   文件: WebServiceWrapperGenerator.java
private void writeXmlTypeDeclaration(JDefinedClass cls, String typeName, String namespaceUri,
                                     Collection<MemberInfo> members) {
    if (cls == null)
        return;
    JAnnotationUse xmlTypeAnn = cls.annotate(cm.ref(XmlType.class));
    xmlTypeAnn.param("name", typeName);
    xmlTypeAnn.param("namespace", namespaceUri);
    if (members.size() > 1) {
        JAnnotationArrayMember paramArray = xmlTypeAnn.paramArray("propOrder");
        for (MemberInfo memInfo : members) {
            paramArray.param(memInfo.getParamName());
        }
    }
}
 
源代码19 项目: jdk8u60   文件: TypeInfoImpl.java
/**
 * Parses a (potentially-null) {@link XmlType} annotation on a class
 * and determine the actual value.
 *
 * @param clazz
 *      The class on which the XmlType annotation is checked.
 * @param t
 *      The {@link XmlType} annotation on the clazz. This value
 *      is taken as a parameter to improve the performance for the case where
 *      't' is pre-computed.
 */
protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
    String nsUri="##default";
    String local="##default";
    if(t!=null) {
        nsUri = t.namespace();
        local = t.name();
    }

    if(local.length()==0)
        return null; // anonymous


    if(local.equals("##default"))
        // if defaulted ...
        local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));

    if(nsUri.equals("##default")) {
        // if defaulted ...
        XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
        if(xs!=null)
            nsUri = xs.namespace();
        else {
            nsUri = builder.defaultNsUri;
        }
    }

    return new QName(nsUri.intern(),local.intern());
}
 
源代码20 项目: jdk8u60   文件: WebServiceWrapperGenerator.java
private void writeXmlTypeDeclaration(JDefinedClass cls, String typeName, String namespaceUri,
                                     Collection<MemberInfo> members) {
    if (cls == null)
        return;
    JAnnotationUse xmlTypeAnn = cls.annotate(cm.ref(XmlType.class));
    xmlTypeAnn.param("name", typeName);
    xmlTypeAnn.param("namespace", namespaceUri);
    if (members.size() > 1) {
        JAnnotationArrayMember paramArray = xmlTypeAnn.paramArray("propOrder");
        for (MemberInfo memInfo : members) {
            paramArray.param(memInfo.getParamName());
        }
    }
}
 
源代码21 项目: jaxb2-rich-contract-plugin   文件: PluginContext.java
private static String getNamespaceUri(final Class<?> boundClass) {
	final XmlRootElement elementAnnotation = boundClass.getAnnotation(XmlRootElement.class);
	if (elementAnnotation != null && !"##default".equals(elementAnnotation.namespace())) {
		return elementAnnotation.namespace();
	} else {
		final XmlType xmlTypeAnnotation = boundClass.getAnnotation(XmlType.class);
		if (xmlTypeAnnotation != null && !"##default".equals(xmlTypeAnnotation.namespace())) {
			return xmlTypeAnnotation.namespace();
		} else {
			return getNamespaceUri(boundClass.getPackage());
		}
	}
}
 
源代码22 项目: openjdk-jdk8u   文件: TypeInfoImpl.java
/**
 * Parses a (potentially-null) {@link XmlType} annotation on a class
 * and determine the actual value.
 *
 * @param clazz
 *      The class on which the XmlType annotation is checked.
 * @param t
 *      The {@link XmlType} annotation on the clazz. This value
 *      is taken as a parameter to improve the performance for the case where
 *      't' is pre-computed.
 */
protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
    String nsUri="##default";
    String local="##default";
    if(t!=null) {
        nsUri = t.namespace();
        local = t.name();
    }

    if(local.length()==0)
        return null; // anonymous


    if(local.equals("##default"))
        // if defaulted ...
        local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));

    if(nsUri.equals("##default")) {
        // if defaulted ...
        XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
        if(xs!=null)
            nsUri = xs.namespace();
        else {
            nsUri = builder.defaultNsUri;
        }
    }

    return new QName(nsUri.intern(),local.intern());
}
 
源代码23 项目: openjdk-jdk8u   文件: ClassInfoImpl.java
/**
 *  XmlType allows specification of factoryClass and
 *  factoryMethod.  There are to be used if no default
 *  constructor is found.
 *
 * @return
 *      true if the factory method was found. False if not.
 */
private  boolean hasFactoryConstructor(XmlType t){
    if (t == null) return false;

    String method = t.factoryMethod();
    T fClass = reader().getClassValue(t, "factoryClass");
    if (method.length() > 0){
        if(nav().isSameType(fClass, nav().ref(XmlType.DEFAULT.class))){
            fClass = nav().use(clazz);
        }
        for(M m: nav().getDeclaredMethods(nav().asDecl(fClass))){
            //- Find the zero-arg public static method with the required return type
            if (nav().getMethodName(m).equals(method) &&
                nav().isSameType(nav().getReturnType(m), nav().use(clazz)) &&
                nav().getMethodParameters(m).length == 0 &&
                nav().isStaticMethod(m)){
                factoryMethod = m;
                break;
            }
        }
        if (factoryMethod == null){
            builder.reportError(new IllegalAnnotationException(
            Messages.NO_FACTORY_METHOD.format(nav().getClassName(nav().asDecl(fClass)), method), this ));
        }
    } else if(!nav().isSameType(fClass, nav().ref(XmlType.DEFAULT.class))){
        builder.reportError(new IllegalAnnotationException(
            Messages.FACTORY_CLASS_NEEDS_FACTORY_METHOD.format(nav().getClassName(nav().asDecl(fClass))), this ));
    }
    return factoryMethod != null;
}
 
源代码24 项目: openjdk-jdk8u   文件: WebServiceWrapperGenerator.java
private void writeXmlTypeDeclaration(JDefinedClass cls, String typeName, String namespaceUri,
                                     Collection<MemberInfo> members) {
    if (cls == null)
        return;
    JAnnotationUse xmlTypeAnn = cls.annotate(cm.ref(XmlType.class));
    xmlTypeAnn.param("name", typeName);
    xmlTypeAnn.param("namespace", namespaceUri);
    if (members.size() > 1) {
        JAnnotationArrayMember paramArray = xmlTypeAnn.paramArray("propOrder");
        for (MemberInfo memInfo : members) {
            paramArray.param(memInfo.getParamName());
        }
    }
}
 
源代码25 项目: netbeans   文件: ReflectionHelper.java
public static boolean isComplexType(String className, ClassLoader runtimeClassLoader) {
    try {
        Class<?> type = Class.forName(className, true, runtimeClassLoader);
        Class xmlType = Class.forName(XmlType.class.getName(), true, runtimeClassLoader);

        Annotation xmlAnnotation = type.getAnnotation(xmlType);
        boolean isEnumeration = isEnumeration(className, runtimeClassLoader);

        return xmlAnnotation != null && !isEnumeration;
    } catch (ClassNotFoundException cnfe) {
        return false;
    }
}
 
源代码26 项目: openjdk-jdk8u-backup   文件: TypeInfoImpl.java
/**
 * Parses a (potentially-null) {@link XmlType} annotation on a class
 * and determine the actual value.
 *
 * @param clazz
 *      The class on which the XmlType annotation is checked.
 * @param t
 *      The {@link XmlType} annotation on the clazz. This value
 *      is taken as a parameter to improve the performance for the case where
 *      't' is pre-computed.
 */
protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
    String nsUri="##default";
    String local="##default";
    if(t!=null) {
        nsUri = t.namespace();
        local = t.name();
    }

    if(local.length()==0)
        return null; // anonymous


    if(local.equals("##default"))
        // if defaulted ...
        local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));

    if(nsUri.equals("##default")) {
        // if defaulted ...
        XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
        if(xs!=null)
            nsUri = xs.namespace();
        else {
            nsUri = builder.defaultNsUri;
        }
    }

    return new QName(nsUri.intern(),local.intern());
}
 
源代码27 项目: openjdk-jdk8u-backup   文件: ClassInfoImpl.java
/**
 *  XmlType allows specification of factoryClass and
 *  factoryMethod.  There are to be used if no default
 *  constructor is found.
 *
 * @return
 *      true if the factory method was found. False if not.
 */
private  boolean hasFactoryConstructor(XmlType t){
    if (t == null) return false;

    String method = t.factoryMethod();
    T fClass = reader().getClassValue(t, "factoryClass");
    if (method.length() > 0){
        if(nav().isSameType(fClass, nav().ref(XmlType.DEFAULT.class))){
            fClass = nav().use(clazz);
        }
        for(M m: nav().getDeclaredMethods(nav().asDecl(fClass))){
            //- Find the zero-arg public static method with the required return type
            if (nav().getMethodName(m).equals(method) &&
                nav().isSameType(nav().getReturnType(m), nav().use(clazz)) &&
                nav().getMethodParameters(m).length == 0 &&
                nav().isStaticMethod(m)){
                factoryMethod = m;
                break;
            }
        }
        if (factoryMethod == null){
            builder.reportError(new IllegalAnnotationException(
            Messages.NO_FACTORY_METHOD.format(nav().getClassName(nav().asDecl(fClass)), method), this ));
        }
    } else if(!nav().isSameType(fClass, nav().ref(XmlType.DEFAULT.class))){
        builder.reportError(new IllegalAnnotationException(
            Messages.FACTORY_CLASS_NEEDS_FACTORY_METHOD.format(nav().getClassName(nav().asDecl(fClass))), this ));
    }
    return factoryMethod != null;
}
 
private void writeXmlTypeDeclaration(JDefinedClass cls, String typeName, String namespaceUri,
                                     Collection<MemberInfo> members) {
    if (cls == null)
        return;
    JAnnotationUse xmlTypeAnn = cls.annotate(cm.ref(XmlType.class));
    xmlTypeAnn.param("name", typeName);
    xmlTypeAnn.param("namespace", namespaceUri);
    if (members.size() > 1) {
        JAnnotationArrayMember paramArray = xmlTypeAnn.paramArray("propOrder");
        for (MemberInfo memInfo : members) {
            paramArray.param(memInfo.getParamName());
        }
    }
}
 
源代码29 项目: jaxb2-rich-contract-plugin   文件: PluginContext.java
private static String getLocalName(final Class<?> boundClass) {
	final XmlRootElement elementAnnotation = boundClass.getAnnotation(XmlRootElement.class);
	if (elementAnnotation != null && !"##default".equals(elementAnnotation.name())) {
		return elementAnnotation.name();
	} else {
		final XmlType xmlTypeAnnotation = boundClass.getAnnotation(XmlType.class);
		if (xmlTypeAnnotation != null && !"##default".equals(xmlTypeAnnotation.name())) {
			return xmlTypeAnnotation.name();
		} else {
			return boundClass.getSimpleName();
		}
	}
}
 
源代码30 项目: herd   文件: RestControllerProcessor.java
/**
 * Gets the XmlType annotation from the specified class. If the XmlType doesn't exist, an exception will be thrown.
 *
 * @param clazz the class with the XmlType annotation.
 *
 * @return the XmlType.
 * @throws MojoExecutionException if the class isn't an XmlType.
 */
private XmlType getXmlType(Class<?> clazz) throws MojoExecutionException
{
    XmlType xmlType = clazz.getAnnotation(XmlType.class);
    if (xmlType == null)
    {
        throw new MojoExecutionException("Class \"" + clazz.getName() + "\" is not of XmlType.");
    }
    return xmlType;
}
 
源代码评论
动弹
沙发等你来抢
 类方法
 同包方法