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;
}
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;
}
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());
}
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);
}
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);
}
Aggregations