Package org.jibx.runtime.impl

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


            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

        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

     */
    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

     */
    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

     */
    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

        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

     */
    private static ClassDecorator classDecoratorFactory(IUnmarshallingContext ictx) {
       
        // get the class to be used for class decorator instance
        ValidationContext vctx = (ValidationContext)ictx.getUserContext();
        UnmarshallingContext ctx = (UnmarshallingContext)ictx;
        String cname = ctx.attributeText(null, "class", null);
        if (cname == null) {
            vctx.addError("Missing required 'class' attribute", new ProblemLocation(ctx));
        } else {
            try {
               
View Full Code Here

         */
        public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException {
           
            // position to start tag and create instance to unmarshal
            ValidationContext vctx = (ValidationContext)ictx.getUserContext();
            UnmarshallingContext ctx = (UnmarshallingContext)ictx;
            ctx.parseToStartTag(null, ELEMENT_NAME);
           
            // accumulate attribute values for constructor
            String check = ctx.attributeText(null, "check-method", null);
            String dser = ctx.attributeText(null, "deserializer", null);
            String format = ctx.attributeText(null, "format-name", null);
            String jclas = ctx.attributeText(null, "java-class", null);
            String ser = ctx.attributeText(null, "serializer", null);
            String stype = ctx.attributeText(null, "type-name");
            boolean valid = true;
            if (jclas == null && format == null) {
               
                // need either 'java-class' or 'format-name', just report error and skip
                vctx.addError("'java-class' attribute is required unless 'format-name' is used", ctx.getStackTop());
                valid = false;
               
            } else if (format != null) {
               
                // check format for existence and consistency
                FormatElement def = (FormatElement)s_nameToFormat.get(format);
                if (def == null) {
                    vctx.addError('\'' + format + "' is not a valid built-in format name", ctx.getStackTop());
                    valid = false;
                } else {
                    if (jclas == null) {
                        jclas = def.getTypeName();
                    }
                }
            }
           
            // look through all attributes of current element
            for (int i = 0; i < ctx.getAttributeCount(); i++) {
               
                // check if nonamespace attribute is in the allowed set
                String name = ctx.getAttributeName(i);
                if (ctx.getAttributeNamespace(i).length() == 0) {
                    if (s_allowedAttributes.indexOf(name) < 0) {
                        vctx.addWarning("Undefined attribute " + name, ctx.getStackTop());
                    }
                }
            }
           
            // skip content, and create and return object instance
            ctx.skipElement();
            if (valid) {
                return new JavaType(stype, null, jclas, format, ser, dser, check);
            } else {
                return null;
            }
View Full Code Here

         */
        public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException {
           
            // position to start tag and create instance to unmarshal
            ValidationContext vctx = (ValidationContext)ictx.getUserContext();
            UnmarshallingContext ctx = (UnmarshallingContext)ictx;
            ctx.parseToStartTag(null, m_name);
            obj = createInstance(ctx.attributeText(null, "class", null), ctx);
            if (obj != null) {
               
                // accumulate all the attribute name-value pairs
                Map map = new HashMap();
                for (int i = 0; i < ctx.getAttributeCount(); i++) {
                    String name = ctx.getAttributeName(i);
                    String value = ctx.getAttributeValue(i);
                    if (ctx.getAttributeNamespace(i).length() == 0) {
                        if (!"class".equals(name)) {
                            map.put(name, value);
                        }
                    } else {
                        vctx.addError("Unknown namespaced attribute '" + name + "'", new ProblemLocation(ctx));
                    }
                }
               
                // create and populate values on instance
                try {
                    ReflectionUtilities.applyKeyValueMap(map, obj);
                } catch (IllegalArgumentException e) {
                    vctx.addError(e.getMessage(), new ProblemLocation(ctx));
                }
            }
           
            // skip element and return unmarshalled decorator instance
            ctx.skipElement();
            return obj;
        }
View Full Code Here

TOP

Related Classes of org.jibx.runtime.impl.UnmarshallingContext

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.