@Override public JAXBContext createContext(Annotation[] parameterAnnotations, Class... classes) throws JAXBException { Set<Class<?>> classes1 = Collections.emptySet(); if (classes != null && classes.length != 0) { classes1 = new HashSet<Class<?>>(); for (Class<?> type : classes) { if (type == null) continue; classes1.add(type); Class<?> factory = findDefaultObjectFactoryClass(type); if (factory != null) classes1.add(factory); } } Class<?>[] classArray = classes1.toArray(new Class[classes1.size()]); return createContextObject(parameterAnnotations, classArray); }
public JAXBContext createXmlTypeContext(Annotation[] parameterAnnotations, Class... classes) throws JAXBException { HashSet<String> packages = new HashSet<String>(); for (Class type : classes) { packages.add(type.getPackage().getName()); } boolean first = true; StringBuilder contextPath = new StringBuilder(); for (String pkg : packages) { if (first) first = false; else contextPath.append(':'); contextPath.append(pkg); } return createContextObject(parameterAnnotations, contextPath.toString()); }
if (typeAnnotation == null) return null; if (!typeAnnotation.factoryClass().equals(XmlType.DEFAULT.class)) return null; final StringBuilder b = new StringBuilder(getPackageName(type)); b.append(OBJECT_FACTORY_NAME); Class<?> factoryClass;
/** * Attempts to locate {@link XmlRegistry} for the XML type. Usually, a class named ObjectFactory is located * in the same package as the type we're trying to marshall. This method simply locates this class and * instantiates it if found. * * @param type type class * @return object factory instance */ public static Object findObjectFactory(Class<?> type) { try { Class<?> factoryClass = AbstractJAXBContextFinder.findDefaultObjectFactoryClass(type); if (factoryClass != null && factoryClass.isAnnotationPresent(XmlRegistry.class)) { return factoryClass.newInstance(); } else { throw new JAXBMarshalException(Messages.MESSAGES.validXmlRegistryCouldNotBeLocated()); } } catch (InstantiationException | IllegalAccessException e) { throw new JAXBMarshalException(e); } }