private void validateNode(org.w3c.dom.Node node) { if (getSchema() != null) { Validator validator = getSchema().newValidator(); validator.setErrorHandler(getErrorHandler()); try { validator.validate(new DOMSource(node)); } catch (Exception e) { throw XMLMarshalException.validateException(e); } } }
@Override public Object getXMLNode(Object obj) { if (null == obj) { throw new IllegalArgumentException(); } if(obj instanceof JAXBElement && !(obj instanceof WrappedValue)) { return xmlBinder.getXMLNode(((JAXBElement)obj).getValue()); } return xmlBinder.getXMLNode(obj); }
@Override public Object updateXML(Object obj, Object xmlNode) { if (null == obj || null == xmlNode) { throw new IllegalArgumentException(); } if (obj instanceof JAXBElement && !(obj instanceof WrappedValue)) { obj = ((JAXBElement) obj).getValue(); } xmlBinder.updateXML(obj, ((Element) xmlNode)); return xmlNode; }
public XMLRoot unmarshal(org.w3c.dom.Node node, Class javaClass) { validateNode(node); reader.setDocPresPolicy(documentPreservationPolicy); return buildXMLRootFromObject(saxUnmarshaller.unmarshal(reader, node, javaClass)); }
if (!isXMLRoot) { domRecord = new DOMRecord(desc.getDefaultRootElement(), desc.getNamespaceResolver()); domRecord.setDocPresPolicy(getDocumentPreservationPolicy()); Node n = this.marshaller.objectToXML(obj, node, desc, domRecord, isXMLRoot, this.getDocumentPreservationPolicy()); validateNode(n);
/** * Updates the object associated with the provided node to reflect any changed made to that node. * If this Binder has no object associated with the given node, then no operation is performed. * @param node */ public void updateObject(org.w3c.dom.Node node) { if (node.getNodeType() == Node.DOCUMENT_NODE) { node = ((Document) node).getDocumentElement(); } Object cachedObject = documentPreservationPolicy.getObjectForNode(node); if (cachedObject != null) { unmarshal(node); } else { throw XMLMarshalException.objectNotFoundInCache(node.getNodeName()); } }
public JAXBBinder(JAXBContext xmlContext, XMLMarshaller marshaller, XMLUnmarshaller unmarshaller) { this.xmlBinder = xmlContext.getXMLContext().createBinder(marshaller, unmarshaller); this.xmlBinder.getDocumentPreservationPolicy().setNodeOrderingPolicy(new RelativePositionOrderingPolicy()); this.xmlBinder.setErrorHandler(new JAXBErrorHandler(JAXBContext.DEFAULT_VALIDATION_EVENT_HANDLER)); }
xmlBinder.updateObject((Node) obj); Object updatedObj = xmlBinder.getObject((Node) obj); Descriptor desc = (Descriptor) xmlBinder.getMarshaller().getXMLContext().getSession().getClassDescriptor(updatedObj);
/** * Create a new XMLBinder * @return an XMLBinder based on this XMLContext */ public XMLBinder createBinder() { return new XMLBinder(this); }
@Override public Schema getSchema() { return this.xmlBinder.getSchema(); }
@Override public ValidationEventHandler getEventHandler() { JAXBErrorHandler jaxbErrorHandler = (JAXBErrorHandler) xmlBinder.getErrorHandler(); return jaxbErrorHandler.getValidationEventHandler(); }
/** * This method will unmarshal the provided node into mapped java objects. The original node * will be cached rather than thrown away. * @param node * @return The root object unmarshalled from the provided node. */ public Object unmarshal(org.w3c.dom.Node node) { validateNode(node); reader.setDocPresPolicy(documentPreservationPolicy); Object toReturn = saxUnmarshaller.unmarshal(reader, node); return toReturn; }
@Override public Object getProperty(String propName) throws PropertyException { if (null == propName) { throw new IllegalArgumentException(); } if (propName.equals(Marshaller.JAXB_ENCODING)) { return this.xmlBinder.getMarshaller().getEncoding(); } if (propName.equals(Marshaller.JAXB_FORMATTED_OUTPUT)) { return this.xmlBinder.getMarshaller().isFormattedOutput(); } if (propName.equals(Marshaller.JAXB_FRAGMENT)) { return this.xmlBinder.getMarshaller().isFragment(); } if (propName.equals(Marshaller.JAXB_SCHEMA_LOCATION)) { return this.xmlBinder.getMarshaller().getSchemaLocation(); } if (propName.equals(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION)) { return this.xmlBinder.getMarshaller().getNoNamespaceSchemaLocation(); } throw new PropertyException(propName); }
if (!isXMLRoot) { domRecord = new DOMRecord(desc.getDefaultRootElement(), desc.getNamespaceResolver()); domRecord.setDocPresPolicy(getDocumentPreservationPolicy()); Node n = this.marshaller.objectToXML(obj, node, desc, domRecord, isXMLRoot, this.getDocumentPreservationPolicy()); validateNode(n);
/** * Updates the object associated with the provided node to reflect any changed made to that node. * If this Binder has no object associated with the given node, then no operation is performed. * @param node */ public void updateObject(org.w3c.dom.Node node) { if (node.getNodeType() == Node.DOCUMENT_NODE) { node = ((Document) node).getDocumentElement(); } Object cachedObject = documentPreservationPolicy.getObjectForNode(node); if (cachedObject != null) { unmarshal(node); } else { throw XMLMarshalException.objectNotFoundInCache(node.getNodeName()); } }
public XMLRoot unmarshal(org.w3c.dom.Node node, Class javaClass) { validateNode(node); reader.setDocPresPolicy(documentPreservationPolicy); return buildXMLRootFromObject(saxUnmarshaller.unmarshal(reader, node, javaClass)); }
public JAXBBinder(JAXBContext xmlContext, XMLMarshaller marshaller, XMLUnmarshaller unmarshaller) { this.xmlBinder = xmlContext.getXMLContext().createBinder(marshaller, unmarshaller); this.xmlBinder.getDocumentPreservationPolicy().setNodeOrderingPolicy(new RelativePositionOrderingPolicy()); this.xmlBinder.setErrorHandler(new JAXBErrorHandler(JAXBContext.DEFAULT_VALIDATION_EVENT_HANDLER)); }
xmlBinder.updateObject((Node) obj); Object updatedObj = xmlBinder.getObject((Node) obj); Descriptor desc = (Descriptor) xmlBinder.getMarshaller().getXMLContext().getSession().getClassDescriptor(updatedObj);
/** * Create a new XMLBinder with supplied marshaller and unmarshaller instances. * @return an XMLBinder based on this XMLContext, */ public XMLBinder createBinder(XMLMarshaller marshaller, XMLUnmarshaller unmarshaller) { return new XMLBinder(this, marshaller, unmarshaller); }
public Schema getSchema() { return this.xmlBinder.getSchema(); }