use of org.apache.cxf.jaxrs.ext.xml.XMLName in project tomee by apache.
the class ResourceUtils method checkJaxbType.
private static void checkJaxbType(Class<?> serviceClass, Class<?> type, Type genericType, ResourceTypes types, Annotation[] anns, MessageBodyWriter<?> jaxbWriter, Class<?> jaxbElement) {
boolean isCollection = false;
if (InjectionUtils.isSupportedCollectionOrArray(type)) {
type = InjectionUtils.getActualType(genericType);
isCollection = true;
}
if (type == Object.class && !(genericType instanceof Class) || genericType instanceof TypeVariable) {
Type theType = InjectionUtils.processGenericTypeIfNeeded(serviceClass, Object.class, genericType);
type = InjectionUtils.getActualType(theType);
}
if (type == null || InjectionUtils.isPrimitive(type) || (jaxbElement != null && jaxbElement.isAssignableFrom(type)) || Response.class.isAssignableFrom(type) || type.isInterface()) {
return;
}
MessageBodyWriter<?> writer = jaxbWriter;
if (writer == null) {
JAXBElementProvider<Object> defaultWriter = new JAXBElementProvider<>();
defaultWriter.setMarshallAsJaxbElement(true);
defaultWriter.setXmlTypeAsJaxbElementOnly(true);
writer = defaultWriter;
}
if (writer.isWriteable(type, type, anns, MediaType.APPLICATION_XML_TYPE)) {
types.getAllTypes().put(type, type);
Class<?> genCls = InjectionUtils.getActualType(genericType);
if (genCls != type && genCls != null && genCls != Object.class && !InjectionUtils.isSupportedCollectionOrArray(genCls)) {
types.getAllTypes().put(genCls, genCls);
}
XMLName name = AnnotationUtils.getAnnotation(anns, XMLName.class);
QName qname = name != null ? JAXRSUtils.convertStringToQName(name.value()) : null;
if (isCollection) {
types.getCollectionMap().put(type, qname);
} else {
types.getXmlNameMap().put(type, qname);
}
}
}
use of org.apache.cxf.jaxrs.ext.xml.XMLName in project cxf by apache.
the class WadlGenerator method generateQName.
private void generateQName(StringBuilder sb, ElementQNameResolver qnameResolver, Map<Class<?>, QName> clsMap, Class<?> type, boolean isCollection, Annotation[] annotations) {
if (!isCollection) {
QName typeQName = clsMap.get(type);
if (typeQName != null) {
writeQName(sb, typeQName);
return;
}
}
QName qname = qnameResolver.resolve(type, annotations, Collections.unmodifiableMap(clsMap));
if (qname != null) {
if (!isCollection) {
writeQName(sb, qname);
clsMap.put(type, qname);
} else {
XMLName name = AnnotationUtils.getAnnotation(annotations, XMLName.class);
String localPart;
if (name != null) {
localPart = JAXRSUtils.convertStringToQName(name.value()).getLocalPart();
} else {
localPart = qname.getLocalPart() + "s";
}
QName collectionName = new QName(qname.getNamespaceURI(), localPart, qname.getPrefix());
writeQName(sb, collectionName);
}
}
}
use of org.apache.cxf.jaxrs.ext.xml.XMLName in project cxf by apache.
the class ResourceUtils method checkJaxbType.
private static void checkJaxbType(Class<?> serviceClass, Class<?> type, Type genericType, ResourceTypes types, Annotation[] anns, MessageBodyWriter<?> jaxbWriter, Class<?> jaxbElement) {
boolean isCollection = false;
if (InjectionUtils.isSupportedCollectionOrArray(type)) {
type = InjectionUtils.getActualType(genericType);
isCollection = true;
}
if (type == Object.class && !(genericType instanceof Class) || genericType instanceof TypeVariable) {
Type theType = InjectionUtils.processGenericTypeIfNeeded(serviceClass, Object.class, genericType);
type = InjectionUtils.getActualType(theType);
}
if (type == null || InjectionUtils.isPrimitive(type) || (jaxbElement != null && jaxbElement.isAssignableFrom(type)) || Response.class.isAssignableFrom(type) || type.isInterface()) {
return;
}
MessageBodyWriter<?> writer = jaxbWriter;
if (writer == null) {
JAXBElementProvider<Object> defaultWriter = new JAXBElementProvider<>();
defaultWriter.setMarshallAsJaxbElement(true);
defaultWriter.setXmlTypeAsJaxbElementOnly(true);
writer = defaultWriter;
}
if (writer.isWriteable(type, type, anns, MediaType.APPLICATION_XML_TYPE)) {
types.getAllTypes().put(type, type);
Class<?> genCls = InjectionUtils.getActualType(genericType);
if (genCls != type && genCls != null && genCls != Object.class && !InjectionUtils.isSupportedCollectionOrArray(genCls)) {
types.getAllTypes().put(genCls, genCls);
}
XMLName name = AnnotationUtils.getAnnotation(anns, XMLName.class);
QName qname = name != null ? JAXRSUtils.convertStringToQName(name.value()) : null;
if (isCollection) {
types.getCollectionMap().put(type, qname);
} else {
types.getXmlNameMap().put(type, qname);
}
}
}
Aggregations