protected final JAXBContext createJaxbContext() throws JAXBException { if (!StringUtils.hasLength(getContextPath())) { throw new IllegalArgumentException("contextPath is required"); } if (logger.isInfoEnabled()) { logger.info("Creating JAXBContext with context path [" + getContextPath() + "]"); } return classLoader != null ? JAXBContext.newInstance(getContextPath(), classLoader) : JAXBContext.newInstance(getContextPath()); }
public void marshal(Object graph, Result result) { if (TraxUtils.isStaxResult(result)) { XMLStreamWriter streamWriter = TraxUtils.getXMLStreamWriter(result); if (streamWriter != null) { result = new StaxResult(streamWriter); } else { XMLEventWriter eventWriter = TraxUtils.getXMLEventWriter(result); if (eventWriter != null) { result = new StaxResult(eventWriter); } else { throw new IllegalArgumentException( "StAXResult contains neither XMLStreamWriter nor XMLEventWriter"); } } } try { createMarshaller().marshal(graph, result); } catch (JAXBException ex) { throw convertJaxbException(ex); } }
public Object unmarshal(Source source) { if (TraxUtils.isStaxSource(source)) { XMLStreamReader streamReader = TraxUtils.getXMLStreamReader(source); if (streamReader != null) { source = new StaxSource(streamReader); } else { XMLEventReader eventReader = TraxUtils.getXMLEventReader(source); if (eventReader != null) { source = new StaxSource(eventReader); } else { throw new IllegalArgumentException( "StAXSource contains neither XMLStreamReader nor XMLEventReader"); } } } try { return createUnmarshaller().unmarshal(source); } catch (JAXBException ex) { throw convertJaxbException(ex); } }
public boolean supports(Class clazz) { if (!Element.class.isAssignableFrom(clazz)) { return false; } if (StringUtils.hasLength(getContextPath())) { String className = ClassUtils.getQualifiedName(clazz); int lastDotIndex = className.lastIndexOf('.'); if (lastDotIndex == -1) { return false; } String packageName = className.substring(0, lastDotIndex); String[] contextPaths = StringUtils.tokenizeToStringArray(getContextPath(), ":"); for (int i = 0; i < contextPaths.length; i++) { if (contextPaths[i].equals(packageName)) { return true; } } return false; } return false; }