Package org.jibx.runtime

Examples of org.jibx.runtime.JiBXException


    /* (non-Javadoc)
     * @see org.jibx.runtime.IUnmarshaller#isPresent(org.jibx.runtime.IUnmarshallingContext)
     */
    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;
        }
View Full Code Here


            list = new ArrayList();
            created = true;
        } else if (obj instanceof List) {
            list = (List)obj;
        } else {
            throw new JiBXException("Supplied object is not a java.util.List");
        }
        if (!(ictx instanceof UnmarshallingContext)) {
            throw new JiBXException
                ("Unmarshalling context not of expected type");
        }
       
        // unmarshal content to document model
        m_unmarshalContext = (UnmarshallingContext)ictx;
        try {
            Node node;
            while ((node = unmarshalNode()) != null) {
                list.add(node);
            }
            if (created && list.isEmpty()) {
                return null;
            } else {
                return list;
            }
    } catch (IOException e) {
            throw new JiBXException("Error reading from document", e);
    }
    }
View Full Code Here

    public void marshal(Object obj, IMarshallingContext ictx)
        throws JiBXException {
       
        // make sure the parameters are as expected
        if (!(obj instanceof Map)) {
            throw new JiBXException("Invalid object type for marshaller");
        } else if (!(ictx instanceof MarshallingContext)) {
            throw new JiBXException("Invalid object type for marshaller");
        } else {
           
            // start by setting up added namespaces
            MarshallingContext ctx = (MarshallingContext)ictx;
            IXMLWriter xwrite = ctx.getXmlWriter();
            int ixsi = xwrite.getNamespaces().length;
            String[][] extens = xwrite.getExtensionNamespaces();
            if (extens != null) {
                for (int i = 0; i < extens.length; i++) {
                    ixsi += extens[i].length;
                }
            }
            xwrite.pushExtensionNamespaces(SCHEMA_NAMESPACE_URIS);
           
            // generate start tag for containing element
            Map map = (Map)obj;
            ctx.startTagNamespaces(m_index, m_name, new int[] { ixsi, ixsi+1 },
                SCHEMA_NAMESPACE_PREFIXES).
                attribute(m_index, SIZE_ATTRIBUTE_NAME, map.size()).
                closeStartContent();
           
            // loop through all entries in hashmap
            Iterator iter = map.entrySet().iterator();
            while (iter.hasNext()) {
               
                // first make sure we have a value
                Map.Entry entry = (Map.Entry)iter.next();
                Object value = entry.getValue();
                if (value != null) {
                   
                    // write element with key attribute
                    ctx.startTagAttributes(m_index, ENTRY_ELEMENT_NAME);
                    ctx.attribute(m_index, KEY_ATTRIBUTE_NAME,
                        entry.getKey().toString());
                   
                    // translate value object class to schema type
                    String tname = value.getClass().getName();
                    int type = s_javaTypesEnum.getValue(tname);
                    if (type < 0) {
                        throw new JiBXException("Value of type " + tname +
                            " with key " + entry.getKey() +
                            " is not a supported type");
                    }
                   
                    // generate xsi:type attribute for value
View Full Code Here

                    break;
                }
            }
        }
        if (xsdlead == null) {
            throw new JiBXException
                ("Missing required schema namespace declaration");
        }
       
        // create new hashmap if needed
        int size = ctx.attributeInt(m_uri, SIZE_ATTRIBUTE_NAME, DEFAULT_SIZE);
        Map map = (Map)obj;
        if (map == null) {
            map = new HashMap(size);
        }
       
        // process all entries present in document
        ctx.parsePastStartTag(m_uri, m_name);
        String tdflt = xsdlead + "string";
        while (ctx.isAt(m_uri, ENTRY_ELEMENT_NAME)) {
           
            // unmarshal key and type from start tag attributes
            Object key = ctx.attributeText(m_uri, KEY_ATTRIBUTE_NAME);
            String tname = ctx.attributeText(XSI_NAMESPACE_URI,
                TYPE_ATTRIBUTE_NAME, tdflt);
           
            // convert type name to type index number
            int type = -1;
            if (tname.startsWith(xsdlead)) {
                type = s_schemaTypesEnum.
                    getValue(tname.substring(xsdlead.length()));
            }
            if (type < 0) {
                throw new JiBXException("Value of type " + tname +
                    " with key " + key + " is not a supported type");
            }
           
            // deserialize content as specified type
            String text = ctx.parseElementText(m_uri, ENTRY_ELEMENT_NAME);
View Full Code Here

        throws JiBXException {
       
        // make sure the parameters are as expected
        if (obj == null) {
            if (m_name == null) {
                throw new JiBXException
                    ("null array not allowed without wrapper");
            }
        } else if (!(ictx instanceof MarshallingContext)) {
            throw new JiBXException("Marshalling context not of expected type");
        } else {
           
            // verify object as a handled array type
            Class clas = obj.getClass();
            if (!clas.isArray()) {
                throw new JiBXException("Invalid object type for marshaller");
            } else {
           
                // start by generating start tag for container
                MarshallingContext ctx = (MarshallingContext)ictx;
                Object[] array = (Object[])obj;
                if (m_name != null) {
                    ctx.startTag(m_index, m_name);
                }
       
                // loop through all entries in array
                for (int i = 0; i < array.length; i++) {
                    Object item = array[i];
                    if (item == null) {
                        throw new JiBXException("Null value at offset " + i +
                            " not supported");
                    } else if (item instanceof IMarshallable) {
                        ((IMarshallable)item).marshal(ctx);
                    } else {
                        throw new JiBXException("Array item of type " +
                            item.getClass().getName() + " does not implement " +
                            "org.jibx.runtime.IMarshallable");
                    }
                }
       
View Full Code Here

    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);
            }
        }
    }
View Full Code Here

     * @see org.jibx.runtime.IUnmarshaller#isPresent(org.jibx.runtime.IUnmarshallingContext)
     */
    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;
View Full Code Here

    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);
    }
    }
View Full Code Here

    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);
            }
        }
    }
View Full Code Here

    /* (non-Javadoc)
     * @see org.jibx.runtime.IUnmarshaller#isPresent(org.jibx.runtime.IUnmarshallingContext)
     */
    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;
        }
View Full Code Here

TOP

Related Classes of org.jibx.runtime.JiBXException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.