@Test public void testGetXmlElementDeclMethod() { JsonXMLRootProvider provider = new JsonXMLRootProvider(); Assert.assertNull(provider.getXmlElementDeclMethod(SampleRootElement.class)); Assert.assertNull(provider.getXmlElementDeclMethod(EmptyType.class)); Assert.assertNotNull(provider.getXmlElementDeclMethod(SampleType.class)); }
protected Method getXmlElementDeclMethod(Class<?> type) { XmlType xmlType = type.getAnnotation(XmlType.class); if (xmlType == null) { return null; } Class<?> factoryClass = xmlType.factoryClass(); if (factoryClass == XmlType.DEFAULT.class) { String defaultObjectFactoryName = type.getPackage().getName() + ".ObjectFactory"; try { factoryClass = Thread.currentThread().getContextClassLoader().loadClass(defaultObjectFactoryName); } catch (Exception e) { factoryClass = type; } } if (factoryClass.getAnnotation(XmlRegistry.class) == null) { return null; } XmlSchema xmlSchema = type.getPackage().getAnnotation(XmlSchema.class); String namespaceURI = getNamespaceURI(xmlType, xmlSchema); for (Method method : factoryClass.getDeclaredMethods()) { XmlElementDecl xmlElementDecl = method.getAnnotation(XmlElementDecl.class); if (xmlElementDecl != null && namespaceURI.equals(getNamespaceURI(xmlElementDecl, xmlSchema))) { if (method.getReturnType() == JAXBElement.class) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length == 1 && parameterTypes[0] == type) { return method; } } } } return null; }
JsonXMLRootProvider { protected Method getXmlElementDeclMethod(Class<?> type) { XmlType xmlType = type.getAnnotation(XmlType.class); if (xmlType == null) { return null; } Class<?> factoryClass = xmlType.factoryClass(); if (factoryClass == XmlType.DEFAULT.class) { String defaultObjectFactoryName = type.getPackage().getName() + ".ObjectFactory"; try { factoryClass = Thread.currentThread().getContextClassLoader().loadClass(defaultObjectFactoryName); } catch (Exception e) { factoryClass = type; } } if (factoryClass.getAnnotation(XmlRegistry.class) == null) { return null; } XmlSchema xmlSchema = type.getPackage().getAnnotation(XmlSchema.class); String namespaceURI = getNamespaceURI(xmlType, xmlSchema); for (Method method : factoryClass.getDeclaredMethods()) { XmlElementDecl xmlElementDecl = method.getAnnotation(XmlElementDecl.class); if (xmlElementDecl != null && namespaceURI.equals(getNamespaceURI(xmlElementDecl, xmlSchema))) { if (method.getReturnType() == JAXBElement.class) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length == 1 && parameterTypes[0] == type) { return method; } } } } return null; } }
JsonXMLRootProvider { protected Method getXmlElementDeclMethod(Class<?> type) { XmlType xmlType = type.getAnnotation(XmlType.class); if (xmlType == null) { return null; } Class<?> factoryClass = xmlType.factoryClass(); if (factoryClass == XmlType.DEFAULT.class) { String defaultObjectFactoryName = type.getPackage().getName() + ".ObjectFactory"; try { factoryClass = Thread.currentThread().getContextClassLoader().loadClass(defaultObjectFactoryName); } catch (Exception e) { factoryClass = type; } } if (factoryClass.getAnnotation(XmlRegistry.class) == null) { return null; } XmlSchema xmlSchema = type.getPackage().getAnnotation(XmlSchema.class); String namespaceURI = getNamespaceURI(xmlType, xmlSchema); for (Method method : factoryClass.getDeclaredMethods()) { XmlElementDecl xmlElementDecl = method.getAnnotation(XmlElementDecl.class); if (xmlElementDecl != null && namespaceURI.equals(getNamespaceURI(xmlElementDecl, xmlSchema))) { if (method.getReturnType() == JAXBElement.class) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length == 1 && parameterTypes[0] == type) { return method; } } } } return null; }  }
JsonXMLRootProvider { protected Method getXmlElementDeclMethod(Class<?> type) { XmlType xmlType = type.getAnnotation(XmlType.class); if (xmlType == null) { return null; } Class<?> factoryClass = xmlType.factoryClass(); if (factoryClass == XmlType.DEFAULT.class) { String defaultObjectFactoryName = type.getPackage().getName() + ".ObjectFactory"; try { factoryClass = Thread.currentThread().getContextClassLoader().loadClass(defaultObjectFactoryName); } catch (Exception e) { factoryClass = type; } } if (factoryClass.getAnnotation(XmlRegistry.class) == null) { return null; } XmlSchema xmlSchema = type.getPackage().getAnnotation(XmlSchema.class); String namespaceURI = getNamespaceURI(xmlType, xmlSchema); for (Method method : factoryClass.getDeclaredMethods()) { XmlElementDecl xmlElementDecl = method.getAnnotation(XmlElementDecl.class); if (xmlElementDecl != null && namespaceURI.equals(getNamespaceURI(xmlElementDecl, xmlSchema))) { if (method.getReturnType() == JAXBElement.class) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length == 1 && parameterTypes[0] == type) { return method; } } } } return null; }  QName getName(Class<?> type); JAXBElement<?> createElement(Class<?> type, Object value); }
JsonXMLRootProvider { protected Method getXmlElementDeclMethod(Class<?> type) { XmlType xmlType = type.getAnnotation(XmlType.class); if (xmlType == null) { return null; } Class<?> factoryClass = xmlType.factoryClass(); if (factoryClass == XmlType.DEFAULT.class) { String defaultObjectFactoryName = type.getPackage().getName() + ".ObjectFactory"; try { factoryClass = Thread.currentThread().getContextClassLoader().loadClass(defaultObjectFactoryName); } catch (Exception e) { factoryClass = type; } } if (factoryClass.getAnnotation(XmlRegistry.class) == null) { return null; } XmlSchema xmlSchema = type.getPackage().getAnnotation(XmlSchema.class); String namespaceURI = getNamespaceURI(xmlType, xmlSchema); for (Method method : factoryClass.getDeclaredMethods()) { XmlElementDecl xmlElementDecl = method.getAnnotation(XmlElementDecl.class); if (xmlElementDecl != null && namespaceURI.equals(getNamespaceURI(xmlElementDecl, xmlSchema))) { if (method.getReturnType() == JAXBElement.class) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length == 1 && parameterTypes[0] == type) { return method; } } } } return null; }  QName getName(Class<?> type); JAXBElement<?> createElement(Class<?> type, Object value);  }