/** * Constructor. Initializes the document used by this * marshaller/unmarshaller instance as the owner of all DOM components. * * @throws JiBXException on error creating document */ protected DomMapperBase() throws JiBXException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); try { m_document = dbf.newDocumentBuilder().newDocument(); } catch (ParserConfigurationException e) { throw new JiBXException("Unable to create DOM document", e); } }
public boolean isPresent(IUnmarshallingContext ctx) throws JiBXException { if (!(ctx instanceof UnmarshallingContext)) { throw new JiBXException ("Unmarshalling context not of expected type"); } else { return ((UnmarshallingContext)ctx).currentEvent() != IXMLReader.END_TAG; } }
public boolean isPresent(IUnmarshallingContext ctx) throws JiBXException { if (!(ctx instanceof UnmarshallingContext)) { throw new JiBXException ("Unmarshalling context not of expected type"); } else { return ((UnmarshallingContext)ctx).currentEvent() != IXMLReader.END_TAG; } }
public boolean isPresent(IUnmarshallingContext ctx) throws JiBXException { if (!(ctx instanceof UnmarshallingContext)) { throw new JiBXException ("Unmarshalling context not of expected type"); } else { return ((UnmarshallingContext)ctx).currentEvent() != IXMLReader.END_TAG; } }
list = (List)obj; } else { throw new JiBXException("Supplied object is not a java.util.List"); throw new JiBXException ("Unmarshalling context not of expected type"); throw new JiBXException("Error reading from document", e);
public boolean isPresent(IUnmarshallingContext ctx) throws JiBXException { if (m_name == null) { if (!(ctx instanceof UnmarshallingContext)) { throw new JiBXException ("Unmarshalling context not of expected type"); } else { return !((UnmarshallingContext)ctx).isEnd(); } } else { return ctx.isAt(m_uri, m_name); } }
public void marshal(Object obj, IMarshallingContext ictx) throws JiBXException { // make sure the parameters are as expected if (!(obj instanceof List)) { throw new JiBXException("Mapped object not a java.util.List"); } else { try { // marshal content list with no indentation m_xmlWriter = ictx.getXmlWriter(); int indent = ictx.getIndent(); ictx.setIndent(-1); m_defaultNamespaceURI = null; for (Iterator iter = ((List)obj).iterator(); iter.hasNext();) { Object item = iter.next(); if (item instanceof Node) { marshalNode((Node)item); } else { throw new JiBXException ("List item is not an org.w3c.dom.Node"); } } ictx.setIndent(indent); } catch (IOException e) { throw new JiBXException("Error writing to document", e); } } }
public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException { // verify the entry conditions if (!(ictx instanceof UnmarshallingContext)) { throw new JiBXException ("Unmarshalling context not of expected type"); } else if (m_name != null && !ictx.isAt(m_uri, m_name)) { ((UnmarshallingContext)ictx).throwStartTagNameError(m_uri, m_name); } // position to element start tag m_unmarshalContext = (UnmarshallingContext)ictx; m_unmarshalContext.toStart(); // unmarshal element to document model try { return unmarshalElement(); } catch (IOException e) { throw new JiBXException("Error reading from document", e); } } }
public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException { // verify the entry conditions if (!(ictx instanceof UnmarshallingContext)) { throw new JiBXException ("Unmarshalling context not of expected type"); } else if (m_name != null && !ictx.isAt(m_uri, m_name)) { ((UnmarshallingContext)ictx).throwStartTagNameError(m_uri, m_name); } // position to element start tag m_unmarshalContext = (UnmarshallingContext)ictx; m_unmarshalContext.toStart(); // unmarshal element to document model try { return unmarshalElement(); } catch (IOException e) { throw new JiBXException("Error reading from document", e); } } }
public boolean isPresent(IUnmarshallingContext ictx) throws JiBXException { if (m_name == null) { if (!(ictx instanceof UnmarshallingContext)) { throw new JiBXException ("Unmarshalling context not of expected type"); } else { UnmarshallingContext ctx = (UnmarshallingContext)ictx; if (ctx.isEnd()) { return false; } else if (m_uri == null) { return true; } else { return !m_uri.equals(ctx.getElementNamespace()); } } } else { return ictx.isAt(m_uri, m_name); } }
public void marshal(Object obj, IMarshallingContext ictx) throws JiBXException { // make sure the parameters are as expected if (!(obj instanceof List)) { throw new JiBXException("Mapped object not a java.util.List"); } else { try { // marshal all content with no indentation m_xmlWriter = ictx.getXmlWriter(); int indent = ictx.getIndent(); ictx.setIndent(-1); m_defaultNamespaceURI = null; marshalContent((List)obj); ictx.setIndent(indent); } catch (IOException e) { throw new JiBXException("Error writing to document", e); } } }
throw new JiBXException("Invalid object type for marshaller"); } else if (!(ictx instanceof MarshallingContext)) { throw new JiBXException("Invalid object type for marshaller"); } else { ctx.endTag(m_index, getEntryElementName()); } else { throw new JiBXException("Mapped value is not marshallable");
/** * Constructor. * * @throws JiBXException on error loading binding information */ public SchemaDocumentationGenerator() throws JiBXException { m_factory = BindingDirectory.getFactory("schema_extract_binding", "org.jibx.schema.codegen"); int index = 0; String[] uris = m_factory.getNamespaces(); m_namespaceSet = new HashSet(); for (int i = 1; i < uris.length; i++) { m_namespaceSet.add(uris[i]); if (SCHEMA_DEFINITIONS_NS.equals(uris[i])) { index = i; } } if (index < 0) { throw new JiBXException("Schema namespace definition not found"); } m_schemaIndex = index; m_schemaPrefix = m_factory.getPrefixes()[index]; m_context = (MarshallingContext)m_factory.createMarshallingContext(); m_context.setIndent(2, COMMENT_LEAD_TEXT, ' '); }
public void marshal(Object obj, IMarshallingContext ctx) throws JiBXException { try { m_schemaContext.setFromContext((MarshallingContext)ctx); ((IMarshallable)obj).marshal(m_schemaContext); m_schemaContext.getXmlWriter().flush(); } catch (IOException e) { throw new JiBXException("Error writing schema", e); } } }
public void marshal(Object obj, IMarshallingContext ictx) throws JiBXException { // make sure the parameters are as expected if (!(obj instanceof Element)) { throw new JiBXException("Mapped object not an org.dom4j.Element"); } else { try { // marshal element and all content with only leading indentation m_xmlWriter = ictx.getXmlWriter(); m_xmlWriter.indent(); int indent = ictx.getIndent(); ictx.setIndent(-1); m_defaultNamespaceURI = null; marshalElement((Element)obj); ictx.setIndent(indent); } catch (IOException e) { throw new JiBXException("Error writing to document", e); } } }
public void marshal(Object obj, IMarshallingContext ictx) throws JiBXException { // make sure the parameters are as expected if (!(obj instanceof Element)) { throw new JiBXException("Mapped object not an org.w3c.dom.Element"); } else { try { // marshal element and all content with only leading indentation m_xmlWriter = ictx.getXmlWriter(); m_xmlWriter.indent(); int indent = ictx.getIndent(); ictx.setIndent(-1); m_defaultNamespaceURI = null; marshalElement((Element)obj); ictx.setIndent(indent); } catch (IOException e) { throw new JiBXException("Error writing to document", e); } } }
public void marshal(Object obj, IMarshallingContext ictx) throws JiBXException { // make sure the parameters are as expected if (!(obj instanceof DocumentFragment)) { throw new JiBXException ("Mapped object not an org.w3c.dom.DocumentFragment"); } else { try { // marshal document fragment with no indentation m_xmlWriter = ictx.getXmlWriter(); int indent = ictx.getIndent(); ictx.setIndent(-1); m_defaultNamespaceURI = null; marshalContent(((DocumentFragment)obj).getChildNodes()); ictx.setIndent(indent); } catch (IOException e) { throw new JiBXException("Error writing to document", e); } } }
public void marshal(Object obj, IMarshallingContext ictx) throws JiBXException { // make sure the parameters are as expected if (obj == null) { return; } else if (!(ictx instanceof MarshallingContext)) { throw new JiBXException("Invalid context type for marshaller"); } else { // generate the element start tag MarshallingContext ctx = (MarshallingContext)ictx; ctx.startTagAttributes(m_index, m_name); // add attribute reference to object ID ctx.attribute(0, getAttributeName(), getIdValue(obj)); // close start tag for empty element ctx.closeStartEmpty(); } }
/** * Post-set method that handles checking attribute combinations and sets the actual member name. * * @throws JiBXException error */ protected void postSet() throws JiBXException { if (m_fieldName != null) { if (m_getName != null || m_setName != null || m_propertyName != null) { throw new JiBXException("'get-name' or 'set-name' or 'property-name' attributes cannot be used together with 'field' attribute on <value> element"); } ClassCustom clas = (ClassCustom)getParent(); setBaseName(memberNameFromField(m_fieldName, clas.getStripPrefixes(), clas.getStripSuffixes())); } else if (m_getName == null && m_setName == null && m_propertyName == null) { throw new JiBXException("Either 'field', 'get-name', 'set-name', or 'property-name' attribute is required on <value> element"); } else { if (m_setName == null) { if (m_getName == null) { setBaseName(m_propertyName); } else { setBaseName(memberNameFromGetMethod(m_getName)); } } else { setBaseName(memberNameFromSetMethod(m_setName)); } } }
/** * Write the binding definitions file(s). This method can only be used after * {@link #buildDataModel(boolean, boolean, Map, Map)} is called. * * @param name root binding definition file name (use customization, or default, if <code>null</code>) * @param pack target package for binding (<code>null</code> if unspecified) * @param pregens pregenerated bindings to be included in root binding * @param handler validation error and code generation problem handler * @throws JiBXException error * @throws IOException error */ public void writeBindings(String name, String pack, List pregens, ProblemHandler handler) throws JiBXException, IOException { if (name == null) { name = m_global.getBindingFileName(); if (name == null) { name = "binding.xml"; } } m_rootHolder = m_bindingDirectory.configureFiles(name, pack, pregens); IClassLocator iloc = new DummyClassLocator(); org.jibx.binding.model.ValidationContext vctx = new org.jibx.binding.model.ValidationContext(iloc); if (m_bindingDirectory.validateBindings(m_rootHolder, m_targetDir, vctx)) { m_bindingDirectory.writeBindings(m_targetDir); } else { reportBindingProblems(vctx, handler); throw new JiBXException("Terminating due to errors in bindings"); } }