/** * Validate the given object. * @param object A single object to validate * @return true if this is a valid object, otherwise false */ public boolean validate(Object object) throws XMLMarshalException { if (object == null) { throw XMLMarshalException.nullArgumentException(); } try { // Create a new XML Record using the object's class name (not fully qualified) as the root String name = ((XMLDescriptor)xmlContext.getSession(object).getDescriptor(object)).getDefaultRootElement(); if (name == null) { String qualifiedName = object.getClass().getName(); int idx = qualifiedName.lastIndexOf('.'); name = qualifiedName.substring(idx + 1); } XMLDescriptor descriptor = marshaller.getDescriptor(object); XMLRoot root = new XMLRoot(); root.setObject(object); root.setLocalName(name); XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform(); Document doc = xmlPlatform.createDocument(); marshaller.marshal(root, doc); return xmlPlatform.validate(doc.getDocumentElement(), descriptor, getErrorHandler()); } catch (XMLPlatformException e) { throw XMLMarshalException.validateException(e); } }
/** * Validate the given object. * @param object A single object to validate * @return true if this is a valid object, otherwise false */ public boolean validate(Object object) throws XMLMarshalException { if (object == null) { throw XMLMarshalException.nullArgumentException(); } try { // Create a new XML Record using the object's class name (not fully qualified) as the root String name = ((XMLDescriptor)xmlContext.getSession(object).getDescriptor(object)).getDefaultRootElement(); if (name == null) { String qualifiedName = object.getClass().getName(); int idx = qualifiedName.lastIndexOf('.'); name = qualifiedName.substring(idx + 1); } XMLDescriptor descriptor = marshaller.getDescriptor(object); Root root = new Root(); root.setObject(object); root.setLocalName(name); XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform(); Document doc = xmlPlatform.createDocument(); marshaller.marshal(root, doc); return xmlPlatform.validate(doc.getDocumentElement(), descriptor, getErrorHandler()); } catch (XMLPlatformException e) { throw XMLMarshalException.validateException(e); } }
/** * Validate the given object. * @param object A single object to validate * @return true if this is a valid object, otherwise false */ public boolean validate(Object object) throws XMLMarshalException { if (object == null) { throw XMLMarshalException.nullArgumentException(); } try { // Create a new XML Record using the object's class name (not fully qualified) as the root String name = ((XMLDescriptor)xmlContext.getSession(object).getDescriptor(object)).getDefaultRootElement(); if (name == null) { String qualifiedName = object.getClass().getName(); int idx = qualifiedName.lastIndexOf('.'); name = qualifiedName.substring(idx + 1); } XMLDescriptor descriptor = marshaller.getDescriptor(object); Root root = new Root(); root.setObject(object); root.setLocalName(name); XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform(); Document doc = xmlPlatform.createDocument(); marshaller.marshal(root, doc); return xmlPlatform.validate(doc.getDocumentElement(), descriptor, getErrorHandler()); } catch (XMLPlatformException e) { throw XMLMarshalException.validateException(e); } }