Search in sources :

Example 1 with XmlType

use of javax.xml.bind.annotation.XmlType in project midpoint by Evolveum.

the class PrismBeanInspector method determineNamespaceUncached.

private String determineNamespaceUncached(Class<? extends Object> beanClass) {
    XmlType xmlType = beanClass.getAnnotation(XmlType.class);
    if (xmlType == null) {
        return null;
    }
    String namespace = xmlType.namespace();
    if (BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        XmlSchema xmlSchema = beanClass.getPackage().getAnnotation(XmlSchema.class);
        namespace = xmlSchema.namespace();
    }
    if (StringUtils.isBlank(namespace) || BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        return null;
    }
    return namespace;
}
Also used : XmlSchema(javax.xml.bind.annotation.XmlSchema) XmlType(javax.xml.bind.annotation.XmlType)

Example 2 with XmlType

use of javax.xml.bind.annotation.XmlType in project midpoint by Evolveum.

the class PrismBeanInspector method findTypeNameUncached.

private QName findTypeNameUncached(Field field, Class contentClass, String schemaNamespace) {
    if (field != null) {
        XmlSchemaType xmlSchemaType = field.getAnnotation(XmlSchemaType.class);
        if (xmlSchemaType != null) {
            return new QName(xmlSchemaType.namespace(), xmlSchemaType.name());
        }
    }
    QName typeName = XsdTypeMapper.getJavaToXsdMapping(contentClass);
    if (typeName != null) {
        return typeName;
    }
    // TODO the following code is similar to determineTypeForClass
    XmlType xmlType = (XmlType) contentClass.getAnnotation(XmlType.class);
    if (xmlType != null) {
        String propTypeLocalPart = xmlType.name();
        String propTypeNamespace = xmlType.namespace();
        if (propTypeNamespace.equals(BeanMarshaller.DEFAULT_PLACEHOLDER)) {
            PrismSchema schema = prismContext.getSchemaRegistry().findSchemaByCompileTimeClass(contentClass);
            if (schema != null && schema.getNamespace() != null) {
                // should be non-null for properly initialized schemas
                propTypeNamespace = schema.getNamespace();
            } else {
                // schemaNamespace is only a poor indicator of required namespace (consider e.g. having c:UserType in apit:ObjectListType)
                // so we use it only if we couldn't find anything else
                propTypeNamespace = schemaNamespace;
            }
        }
        return new QName(propTypeNamespace, propTypeLocalPart);
    }
    return null;
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) QName(javax.xml.namespace.QName) XmlSchemaType(javax.xml.bind.annotation.XmlSchemaType) XmlType(javax.xml.bind.annotation.XmlType)

Example 3 with XmlType

use of javax.xml.bind.annotation.XmlType in project midpoint by Evolveum.

the class PrismBeanInspector method determineTypeForClassUncached.

private QName determineTypeForClassUncached(Class<? extends Object> beanClass) {
    XmlType xmlType = beanClass.getAnnotation(XmlType.class);
    if (xmlType == null) {
        return null;
    }
    String namespace = xmlType.namespace();
    if (BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        XmlSchema xmlSchema = beanClass.getPackage().getAnnotation(XmlSchema.class);
        namespace = xmlSchema.namespace();
    }
    if (StringUtils.isBlank(namespace) || BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        return null;
    }
    return new QName(namespace, xmlType.name());
}
Also used : XmlSchema(javax.xml.bind.annotation.XmlSchema) QName(javax.xml.namespace.QName) XmlType(javax.xml.bind.annotation.XmlType)

Example 4 with XmlType

use of javax.xml.bind.annotation.XmlType in project spring-framework by spring-projects.

the class Jaxb2CollectionHttpMessageConverter method canRead.

/**
	 * {@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);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) XmlType(javax.xml.bind.annotation.XmlType) MediaType(org.springframework.http.MediaType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) XmlType(javax.xml.bind.annotation.XmlType)

Example 5 with XmlType

use of javax.xml.bind.annotation.XmlType in project camel by apache.

the class CoreEipAnnotationProcessor method processModelClass.

protected void processModelClass(final ProcessingEnvironment processingEnv, final RoundEnvironment roundEnv, final TypeElement classElement) {
    final String javaTypeName = canonicalClassName(classElement.getQualifiedName().toString());
    String packageName = javaTypeName.substring(0, javaTypeName.lastIndexOf("."));
    // skip abstract classes
    if (classElement.getModifiers().contains(Modifier.ABSTRACT)) {
        return;
    }
    // skip unwanted classes which are "abstract" holders
    if (skipUnwanted) {
        if (classElement.getQualifiedName().toString().equals(ONE_OF_TYPE_NAME)) {
            return;
        }
    }
    final XmlRootElement rootElement = classElement.getAnnotation(XmlRootElement.class);
    if (rootElement == null) {
        return;
    }
    String aName = rootElement.name();
    if (isNullOrEmpty(aName) || "##default".equals(aName)) {
        XmlType typeElement = classElement.getAnnotation(XmlType.class);
        aName = typeElement.name();
    }
    final String name = aName;
    // lets use the xsd name as the file name
    String fileName;
    if (isNullOrEmpty(name) || "##default".equals(name)) {
        fileName = classElement.getSimpleName().toString() + ".json";
    } else {
        fileName = name + ".json";
    }
    // write json schema
    Func1<PrintWriter, Void> handler = new Func1<PrintWriter, Void>() {

        @Override
        public Void call(PrintWriter writer) {
            writeJSonSchemeDocumentation(processingEnv, writer, roundEnv, classElement, rootElement, javaTypeName, name);
            return null;
        }
    };
    processFile(processingEnv, packageName, fileName, handler);
}
Also used : XmlRootElement(javax.xml.bind.annotation.XmlRootElement) XmlType(javax.xml.bind.annotation.XmlType) PrintWriter(java.io.PrintWriter)

Aggregations

XmlType (javax.xml.bind.annotation.XmlType)31 QName (javax.xml.namespace.QName)11 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)10 Method (java.lang.reflect.Method)9 Field (java.lang.reflect.Field)7 XmlSchema (javax.xml.bind.annotation.XmlSchema)7 ArrayList (java.util.ArrayList)6 XmlAccessType (javax.xml.bind.annotation.XmlAccessType)5 XmlAccessorOrder (javax.xml.bind.annotation.XmlAccessorOrder)4 ParameterizedType (java.lang.reflect.ParameterizedType)3 Type (java.lang.reflect.Type)3 JAXBException (javax.xml.bind.JAXBException)3 XmlElement (javax.xml.bind.annotation.XmlElement)3 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)3 PrintWriter (java.io.PrintWriter)2 Annotation (java.lang.annotation.Annotation)2 GenericArrayType (java.lang.reflect.GenericArrayType)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 JAXBContext (javax.xml.bind.JAXBContext)2