List of utility methods to do XML JAXB Context
void | clearContextCache() clear Context Cache for (SoftReference<JAXBContext> i : contextCache.values())
i.clear();
contextCache.clear();
|
JAXBContext | createContext(final Class> bind) Returns a cached JAXB Context. JAXBContext context = null; SoftReference<JAXBContext> ref = contextCache.get(bind); if (ref != null) { context = ref.get(); if (context == null) contextCache.remove(bind); if (context != null) ... |
JAXBContext | createJaxbContextFor(Object obj, Class>[] classes) create Jaxb Context For Set<Class<?>> classSet = new HashSet<>(); classSet.addAll(Arrays.asList(classes)); classSet.add(obj.getClass()); return JAXBContext.newInstance(classSet.toArray(new Class<?>[0])); |
JAXBContext | createRIContext(Class> clss[], String defaultNS) create RI Context try { Class<?> cls; Map<String, Object> map = new HashMap<String, Object>(); try { cls = Class.forName("com.sun.xml.bind.v2.ContextFactory"); if (defaultNS != null) { map.put("com.sun.xml.bind.defaultNamespaceRemap", defaultNS); } catch (ClassNotFoundException e) { cls = Class.forName("com.sun.xml.internal.bind.v2.ContextFactory"); if (defaultNS != null) { map.put("com.sun.xml.internal.bind.defaultNamespaceRemap", defaultNS); Method meth = cls.getMethod("createContext", clss.getClass(), Map.class); return (JAXBContext) meth.invoke(null, clss, map); } catch (Exception e) { throw new JAXBException(e); |
T | fromXML(JAXBContext context, String requestXML) Unmarshalls the specified XML document to a call request object. StringReader sr = new StringReader(requestXML); T result = null; Unmarshaller um = context.createUnmarshaller(); result = (T) um.unmarshal(sr); return result; |
File | generateTemporarySchemaFile(JAXBContext context) generate Temporary Schema File final File tempFile = File.createTempFile("jaxb-junit-report-schema", ".xsd"); context.generateSchema(new SchemaOutputResolver() { @Override public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException { StreamResult result = new StreamResult(tempFile); result.setSystemId(tempFile.toURI().toURL().toString()); return result; }); return tempFile; |
JAXBContext | getCachedContext(String pkg) get Cached Context JAXBContext ctx = _ctxMap.get(pkg); if (ctx == null) { ctx = JAXBContext.newInstance(pkg); _ctxMap.put(pkg, ctx); return ctx; |
JAXBContext | getContext() get Context if (context == null) { context = JAXBContext.newInstance("org.opentestsystem.rdw.common.model.trt"); return context; |
JAXBContext | getContext() Returns the JAXBContext for this format. if (JAXB == null) initContext(Thread.currentThread().getContextClassLoader()); return JAXB; |
JAXBContext | getContext() get Context if (JAXB_CONTEXT == null) { throw new IllegalStateException("JAXB has not been initialized"); return JAXB_CONTEXT; |