Examples of UnmarshallingContext


Examples of org.jibx.runtime.impl.UnmarshallingContext

        String fpath = url.toExternalForm();
        if (paths.add(fpath)) {
            try {
               
                // access the included binding as input stream
                UnmarshallingContext ictx = new UnmarshallingContext();
                ictx.setDocument(url.openStream(), null);
               
                // get basic name and package information from binding
                ictx.parseToStartTag(URI_ELEMENTS, BINDING_ELEMENT);
                String fname = org.jibx.binding.Utility.fileName(path);
                String name = ictx.attributeText(URI_ATTRIBUTES, BINDING_NAME,
                    org.jibx.binding.Utility.bindingFromFileName(fname));
                int major = ictx.attributeInt(URI_ATTRIBUTES,
                    BINDING_MAJORVER, 0);
                int minor = ictx.attributeInt(URI_ATTRIBUTES,
                    BINDING_MINORVER, 0);
                String tpack = ictx.attributeText(URI_ATTRIBUTES,
                    BINDING_PACKAGE, null);
                boolean direct = ctx.attributeBoolean(URI_ATTRIBUTES,
                    INCLUDE_PRECOMPILED, false);
                if (direct && tpack == null) {
                    throw new JiBXException("package attribute is required for precompiled binding");
                }
                if (direct) {
                   
                    // load and add binding factory for precompiled binding
                    factory = BindingDirectory.getFactory(name, tpack,
                        ClassFile.getClassLoader());
                    nsxlate = bdef.addPrecompiledBinding(factory, major, minor);
                }
                   
               
                // unmarshal namespaces (to apply to these mappings, only)
                ictx.parsePastStartTag(URI_ELEMENTS, BINDING_ELEMENT);
                ArrayList nss = new ArrayList(nslist);
                while (ictx.isAt(URI_ELEMENTS, NAMESPACE_ELEMENT)) {
                    nss.add(unmarshalNamespace(ictx));
                }
               
                // process any format definitions (for global context)
                precomp = precomp || direct;
                unmarshalFormats(ictx, precomp, bdef.getDefinitionContext());
               
                // check for nested includes
                while (ictx.isAt(URI_ELEMENTS, INCLUDE_ELEMENT)) {
                    unmarshalInclude(ictx, precomp, bdef, url, nss, paths,
                        factory, nsxlate);
                }
               
                // process all mappings defined in included binding
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

            // initialize namespace and special classes
            GlobalCustom global = (GlobalCustom)obj;
            global.initClasses();
           
            // unmarshal the wrapper element directly
            UnmarshallingContext ctx = (UnmarshallingContext)ictx;
            while (ctx.isStart()) {
               
                // check type of child present
                String element = ctx.getName();
                if (PackageCustom.ELEMENT_NAME.equals(element)) {
                    unmarshalPackage(global, null, ctx);
                } else if (ClassCustom.ELEMENT_NAME.equals(element)) {
                    unmarshalClass(global, null, ctx);
                } else {
                    global.internalAddExtensionChild(ctx.unmarshalElement());
                }
               
            }
            return global;
        }
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

        }
        if (valid) {
            try {
               
                // construct the binding definition code generator
                UnmarshallingContext uctx = new UnmarshallingContext();
                uctx.setDocument(new ByteArrayInputStream(data), fname, null);
                if (cf != null) {
                   
                    // set target root and package for created classes
                    if (bname == null) {
                        bname = sname;
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

        String[] bindings) {
        m_attributeUri = uri;
        m_attributeName = name;
        m_versionTexts = versions;
        m_versionBindings = bindings;
        m_context = new UnmarshallingContext();
        m_outputIndent = -1;
    }
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

            if (version.equals(m_versionTexts[i])) {
               
                // version found, create unmarshaller for the associated binding
                IBindingFactory fact = BindingDirectory.
                    getFactory(m_versionBindings[i], clas);
                UnmarshallingContext context =
                    (UnmarshallingContext)fact.createUnmarshallingContext();
               
                // return object unmarshalled using binding for document version
                context.setFromContext(m_context);
                return context.unmarshalElement();
               
            }
        }
       
        // error if unknown version in document
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

        m_ref3 = qname;
    }
   
    protected void getNamespaces(IUnmarshallingContext ictx)
        throws JiBXException {
        UnmarshallingContext ctx = (UnmarshallingContext)ictx;
        int count = ctx.getNamespaceCount();
        if (count > 0) {
            m_namespaces = new ArrayList();
            for (int i = 0; i < count; i++) {
                m_namespaces.add(ctx.getNamespacePrefix(i));
                m_namespaces.add(ctx.getNamespaceUri(i));
            }
        } else {
            m_namespaces = null;
        }
    }
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

     */
    public Object unmarshal(Object obj, IUnmarshallingContext ictx)
        throws JiBXException {
       
        // make sure we're at the appropriate start tag
        UnmarshallingContext ctx = (UnmarshallingContext)ictx;
        if (!ctx.isAt(m_uri, m_name)) {
            return null;
        }
       
        // get object reference for ID
        obj = ctx.attributeExistingIDREF(null, getAttributeName(), 0);
       
        // skip past the element
        ctx.parsePastEndTag(m_uri, m_name);
        return obj;
    }
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

     */
    public Object unmarshal(Object obj, IUnmarshallingContext ictx)
        throws JiBXException {
       
        // make sure we're at the appropriate start tag
        UnmarshallingContext ctx = (UnmarshallingContext)ictx;
        if (!ctx.isAt(m_uri, m_name)) {
            ctx.throwStartTagNameError(m_uri, m_name);
        }
       
        // lookup the prefixes assigned to required namespaces
        int nscnt = ctx.getActiveNamespaceCount();
        String xsdlead = null;
        for (int i = nscnt-1; i >= 0; i--) {
            String uri = ctx.getActiveNamespaceUri(i);
            if (XSD_NAMESPACE_URI.equals(uri)) {
                String prefix = ctx.getActiveNamespacePrefix(i);
                if (!"".equals(prefix)) {
                    xsdlead = prefix + ':';
                    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);
            Object value = null;
            switch (type) {
               
                case BOOLEAN_TYPE:
                    value = Utility.parseBoolean(text) ?
                        Boolean.TRUE : Boolean.FALSE;
                    break;
                   
                case BYTE_TYPE:
                    value = new Byte(Utility.parseByte(text));
                    break;
                   
                case DOUBLE_TYPE:
                    value = new Double(Utility.parseDouble(text));
                    break;
                   
                case FLOAT_TYPE:
                    value = new Float(Utility.parseFloat(text));
                    break;
                   
                case INT_TYPE:
                    value = new Integer(Utility.parseInt(text));
                    break;
                   
                case LONG_TYPE:
                    value = new Long(Utility.parseLong(text));
                    break;
                   
                case SHORT_TYPE:
                    value = new Short(Utility.parseShort(text));
                    break;
                   
                case DATETIME_TYPE:
                    value = Utility.deserializeDateTime(text);
                    break;
                   
//#!j2me{
                case DATE_TYPE:
                    value = Utility.deserializeSqlDate(text);
                    break;
                   
                case TIME_TYPE:
                    value = Utility.deserializeSqlTime(text);
                    break;
//#j2me}
                   
                case BYTERRAY_TYPE:
                    value = Utility.deserializeBase64(text);
                    break;
                   
                case DECIMAL_TYPE:
                    value = new BigDecimal(text);
                    break;
                   
                case INTEGER_TYPE:
                    value = new BigInteger(text);
                    break;
                   
                case STRING_TYPE:
                    value = text;
                    break;
            }
           
            // add key-value pair to map
            map.put(key, value);
        }
       
        // finish by skipping past wrapper end tag
        ctx.parsePastEndTag(m_uri, m_name);
        return map;
    }
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

     */
    public Object unmarshal(Object obj, IUnmarshallingContext ictx)
        throws JiBXException {
       
        // make sure we're at the appropriate start tag
        UnmarshallingContext ctx = (UnmarshallingContext)ictx;
        if (m_name != null) {
            if (ctx.isAt(m_uri, m_name)) {
                ctx.parsePastStartTag(m_uri, m_name);
            } else {
                return null;
            }
        }
       
        // create new array if needed
        if (m_holder == null) {
            m_holder = new ArrayList();
        }
       
        // process all items present in document
        while (!ctx.isEnd()) {
            Object item = ctx.unmarshalElement();
            m_holder.add(item);
        }
       
        // discard close tag if used
        if (m_name != null) {
            ctx.parsePastEndTag(m_uri, m_name);
        }
       
        // return array containing all items
        Object[] result = m_holder.toArray(m_baseArray);
        m_holder.clear();
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

        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);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.