use of javax.xml.bind.annotation.XmlType in project cxf by apache.
the class SchemaCollectionContextProxy method getTypeQName.
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);
}
use of javax.xml.bind.annotation.XmlType in project camel by apache.
the class TypeNameStrategy method findQNameForSoapActionOrType.
/**
* @return determine element name by using the XmlType.name() of the type to
* be marshalled and the XmlSchema.namespace() of the package-info
*/
public QName findQNameForSoapActionOrType(String soapAction, Class<?> type) {
XmlType xmlType = type.getAnnotation(XmlType.class);
if (xmlType == null || xmlType.name() == null) {
throw new RuntimeException("The type " + type.getName() + " needs to have an XmlType annotation with name");
}
String nameSpace = xmlType.namespace();
if ("##default".equals(nameSpace)) {
XmlSchema xmlSchema = type.getPackage().getAnnotation(XmlSchema.class);
if (xmlSchema != null) {
nameSpace = xmlSchema.namespace();
}
}
// prefer name from the XmlType, and fallback to XmlRootElement
String localName = xmlType.name();
if (ObjectHelper.isEmpty(localName)) {
XmlRootElement root = type.getAnnotation(XmlRootElement.class);
if (root != null) {
localName = root.name();
}
}
return new QName(nameSpace, localName);
}
use of javax.xml.bind.annotation.XmlType in project camel by apache.
the class XmlRootElementPreferringElementNameStrategy method findQNameForSoapActionOrType.
@Override
public QName findQNameForSoapActionOrType(String soapAction, Class<?> type) {
XmlType xmlType = type.getAnnotation(XmlType.class);
if (xmlType == null || xmlType.name() == null) {
throw new RuntimeException("The type " + type.getName() + " needs to have an XmlType annotation with name");
}
// prefer name+ns from the XmlRootElement, and fallback to XmlType
String localName = null;
String nameSpace = null;
XmlRootElement root = type.getAnnotation(XmlRootElement.class);
if (root != null) {
localName = ObjectHelper.isEmpty(localName) ? root.name() : localName;
nameSpace = isInValidNamespace(nameSpace) ? root.namespace() : nameSpace;
}
if (ObjectHelper.isEmpty(localName)) {
localName = xmlType.name();
}
if (isInValidNamespace(nameSpace)) {
XmlSchema xmlSchema = type.getPackage().getAnnotation(XmlSchema.class);
if (xmlSchema != null) {
nameSpace = xmlSchema.namespace();
}
}
if (isInValidNamespace(nameSpace)) {
nameSpace = xmlType.namespace();
}
if (ObjectHelper.isEmpty(localName) || isInValidNamespace(nameSpace)) {
throw new IllegalStateException("Unable to determine localName or namespace for type <" + type.getName() + ">");
}
return new QName(nameSpace, localName);
}
use of javax.xml.bind.annotation.XmlType in project cxf by apache.
the class CorbaStreamFaultOutInterceptor method getRaisesType.
protected RaisesType getRaisesType(OperationType opType, String exClassName, Throwable ex) {
RaisesType result = null;
List<RaisesType> exList = opType.getRaises();
result = findRaisesType(exList, exClassName);
if (result == null) {
// if doc-literal, the part element name should be used, but for RPC, the message part name
try {
Method faultMethod = ex.getClass().getMethod("getFaultInfo");
if (faultMethod != null) {
Class<?> faultClass = faultMethod.getReturnType();
XmlType exType = faultClass.getAnnotation(XmlType.class);
exClassName = exType.name();
result = findRaisesType(exList, exClassName);
}
} catch (Exception exp) {
// Ignore it
}
}
return result;
}
use of javax.xml.bind.annotation.XmlType in project cxf by apache.
the class WrapperBeanAnnotator method annotate.
public void annotate(final JavaAnnotatable clz) {
WrapperBeanClass beanClass = null;
if (clz instanceof WrapperBeanClass) {
beanClass = (WrapperBeanClass) clz;
} else {
throw new RuntimeException("WrapperBeanAnnotator expect JavaClass as input");
}
JAnnotation xmlRootElement = new JAnnotation(XmlRootElement.class);
xmlRootElement.addElement(new JAnnotationElement("name", beanClass.getElementName().getLocalPart()));
xmlRootElement.addElement(new JAnnotationElement("namespace", beanClass.getElementName().getNamespaceURI()));
JAnnotation xmlAccessorType = new JAnnotation(XmlAccessorType.class);
xmlAccessorType.addElement(new JAnnotationElement(null, XmlAccessType.FIELD));
XmlType tp = null;
if (sourceClass != null) {
tp = sourceClass.getAnnotation(XmlType.class);
}
JAnnotation xmlType = new JAnnotation(XmlType.class);
if (tp == null) {
xmlType.addElement(new JAnnotationElement("name", beanClass.getElementName().getLocalPart()));
xmlType.addElement(new JAnnotationElement("namespace", beanClass.getElementName().getNamespaceURI()));
} else {
if (!"##default".equals(tp.name())) {
xmlType.addElement(new JAnnotationElement("name", tp.name()));
}
if (!"##default".equals(tp.namespace())) {
xmlType.addElement(new JAnnotationElement("namespace", tp.namespace()));
}
if (!StringUtils.isEmpty(tp.factoryMethod())) {
xmlType.addElement(new JAnnotationElement("factoryMethod", tp.factoryMethod()));
}
if (tp.propOrder().length != 1 || !StringUtils.isEmpty(tp.propOrder()[0])) {
xmlType.addElement(new JAnnotationElement("propOrder", tp.propOrder()));
}
}
List<String> props = new ArrayList<>();
for (JavaField f : beanClass.getFields()) {
props.add(f.getParaName());
}
if (props.size() > 1) {
xmlType.addElement(new JAnnotationElement("propOrder", props));
}
// Revisit: why annotation is string?
beanClass.addAnnotation(xmlRootElement);
beanClass.addAnnotation(xmlAccessorType);
beanClass.addAnnotation(xmlType);
}
Aggregations