use of javax.xml.bind.annotation.XmlRootElement in project zm-mailbox by Zimbra.
the class JaxbInfo method gatherInfo.
private void gatherInfo() {
XmlAccessorType accessorType;
rootElementName = null;
XmlAccessType accessType = null;
XmlRootElement rootE = jaxbClass.getAnnotation(XmlRootElement.class);
if (rootE != null) {
rootElementName = rootE.name();
}
xmlType = jaxbClass.getAnnotation(XmlType.class);
accessorType = jaxbClass.getAnnotation(XmlAccessorType.class);
if (accessorType == null) {
Package pkg = jaxbClass.getPackage();
accessorType = pkg.getAnnotation(XmlAccessorType.class);
}
if (accessorType != null) {
accessType = accessorType.value();
}
if (accessType == null) {
// Default value for JAXB
accessType = XmlAccessType.PUBLIC_MEMBER;
}
Field[] fields = jaxbClass.getDeclaredFields();
for (Field field : fields) {
XmlTransient xmlTransient = field.getAnnotation(XmlTransient.class);
if (xmlTransient != null) {
continue;
}
Annotation[] fAnnots = field.getAnnotations();
if ((fAnnots == null) || (fAnnots.length == 0)) {
boolean autoFields = (accessType.equals(XmlAccessType.PUBLIC_MEMBER) || accessType.equals(XmlAccessType.FIELD));
if (!autoFields) {
continue;
}
}
processFieldRelatedAnnotations(fAnnots, field.getName(), field.getGenericType());
}
Method[] methods = jaxbClass.getDeclaredMethods();
for (Method method : methods) {
XmlTransient xmlTransient = method.getAnnotation(XmlTransient.class);
if (xmlTransient != null) {
continue;
}
if (!isGetterOrSetter(method)) {
continue;
}
Annotation[] mAnnots = method.getAnnotations();
if ((mAnnots == null) || (mAnnots.length == 0)) {
boolean autoGettersSetters = (accessType.equals(XmlAccessType.PUBLIC_MEMBER) || accessType.equals(XmlAccessType.PROPERTY));
if (!autoGettersSetters) {
continue;
}
}
processFieldRelatedAnnotations(mAnnots, guessFieldNameFromGetterOrSetter(method.getName()), method.getGenericReturnType());
}
}
use of javax.xml.bind.annotation.XmlRootElement in project cxf by apache.
the class WadlGenerator method getJaxbQName.
private QName getJaxbQName(JAXBContextProxy jaxbProxy, Class<?> type, Map<Class<?>, QName> clsMap) {
XmlRootElement root = type.getAnnotation(XmlRootElement.class);
if (root != null) {
return getJaxbQName(root.name(), root.namespace(), type, clsMap);
}
try {
JAXBBeanInfo jaxbInfo = jaxbProxy == null ? null : JAXBUtils.getBeanInfo(jaxbProxy, type);
if (jaxbInfo == null) {
return null;
}
Object instance = type.newInstance();
return getQNameFromParts(jaxbInfo.getElementLocalName(instance), jaxbInfo.getElementNamespaceURI(instance), type, clsMap);
} catch (Exception ex) {
// ignore
}
return null;
}
use of javax.xml.bind.annotation.XmlRootElement in project jbpm by kiegroup.
the class JaxbTaskSerializationTest method uniqueRootElementTest.
@Test
public void uniqueRootElementTest() throws Exception {
Set<String> idSet = new HashSet<String>();
HashMap<String, Class> idClassMap = new HashMap<String, Class>();
for (Class<?> jaxbClass : reflections.getTypesAnnotatedWith(XmlRootElement.class)) {
XmlRootElement rootElemAnno = jaxbClass.getAnnotation(XmlRootElement.class);
String id = rootElemAnno.name();
if ("##default".equals(id)) {
continue;
}
String otherClass = (idClassMap.get(id) == null ? "null" : idClassMap.get(id).getName());
assertTrue("ID '" + id + "' used in both " + jaxbClass.getName() + " and " + otherClass, idSet.add(id));
idClassMap.put(id, jaxbClass);
String className = jaxbClass.getSimpleName();
if (!className.endsWith("Command")) {
continue;
}
String idName = id.replace("-", "");
assertEquals("XML root element name should match class name in " + jaxbClass.getName() + "!", className.toLowerCase(), idName.toLowerCase());
}
}
use of javax.xml.bind.annotation.XmlRootElement in project wso2-synapse by wso2.
the class JsonXMLRootProvider method getXmlRootElementName.
/**
* Calculate root element name for an <code>@XmlRootElement</code>-annotated type.
*
* @param type
* @return element name
*/
protected QName getXmlRootElementName(Class<?> type) {
XmlRootElement xmlRootElement = type.getAnnotation(XmlRootElement.class);
if (xmlRootElement == null) {
return null;
}
String localName;
if ("##default".equals(xmlRootElement.name())) {
localName = Character.toLowerCase(type.getSimpleName().charAt(0)) + type.getSimpleName().substring(1);
} else {
localName = xmlRootElement.name();
}
XmlSchema xmlSchema = type.getPackage().getAnnotation(XmlSchema.class);
String namespaceURI = getNamespaceURI(xmlRootElement, xmlSchema);
return new QName(namespaceURI, localName, getPrefix(namespaceURI, xmlSchema));
}
Aggregations