Examples of UnmarshallingContext


Examples of org.jibx.runtime.impl.UnmarshallingContext

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

Examples of org.jibx.runtime.impl.UnmarshallingContext

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

Examples of org.jibx.runtime.impl.UnmarshallingContext

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

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 (isPresent(ctx)) {
           
            // make sure there's a name for the document being parsed
            if (ctx.getDocumentName() == null) {
                throw new JiBXException("Unable to process include without " +
                    "base document name " + ctx.buildPositionString());
            } else {
               
                // check for conditionals on include
                boolean use = true;
                String name = ctx.attributeText(ATTR_NAMESPACE,
                    IFDEF_NAME, null);
                if (name != null) {
                    use = getValue(name, ctx) != null;
                }
                name = ctx.attributeText(ATTR_NAMESPACE, IFNDEF_NAME, null);
                if (use && name != null) {
                    use = getValue(name, ctx) == null;
                }
               
                // get the remaining attribute values and ditch element
                String path = ctx.attributeText(ATTR_NAMESPACE, PATH_NAME);
                String access =
                    ctx.attributeText(ATTR_NAMESPACE, ACCESSDIR_NAME);
                String label = ctx.attributeText(ATTR_NAMESPACE,
                    LABEL_NAME, null);
                ctx.parsePastElement(ELEMENT_NAMESPACE, INCLUDE_NAME);
               
                // check if this include is active
                if (use) {
                   
                    // find the file to be included
                    int index = ctx.getStackDepth() - 1;
                    Builder build = (Builder)ctx.getStackObject(index);
                    File config = Component.
                        applyFilePath(build.getSourceRoot(), path);
                    File root = config.getParentFile();
                   
                    // create new unmarshalling context for included file
                    UnmarshallingContext inctx = (UnmarshallingContext)
                        BindingDirectory.getFactory(Site.class).
                        createUnmarshallingContext();
                    try {
                        inctx.setDocument(new FileInputStream
                            (new File(root, path)), path, null);
                    } catch (FileNotFoundException e) {
                        throw new JiBXException("Include file " + path +
                            " not found " + ctx.buildPositionString());
                    }
                   
                    // unmarshal the included document
                    obj = inctx.unmarshalElement();
                    if (obj instanceof Site) {
                        return new Menu((Site)obj, root, access, label);
                    } else if (obj instanceof Menu) {
                        return new Menu((Menu)obj, root, access, label);
                    } else {
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);
        }
       
        // create new hashmap if needed
        int size = ctx.attributeInt(m_uri, SIZE_ATTRIBUTE_NAME, DEFAULT_SIZE);
        HashMap map = (HashMap)obj;
        if (map == null) {
            map = new HashMap(size);
        }
       
        // process all entries present in document
        ctx.parsePastStartTag(m_uri, m_name);
        while (ctx.isAt(m_uri, ENTRY_ELEMENT_NAME)) {
            Object key = ctx.attributeText(m_uri, KEY_ATTRIBUTE_NAME, null);
            ctx.parsePastStartTag(m_uri, ENTRY_ELEMENT_NAME);
            Object value = ctx.unmarshalElement();
            map.put(key, value);
            ctx.parsePastEndTag(m_uri, ENTRY_ELEMENT_NAME);
        }
        ctx.parsePastEndTag(m_uri, m_name);
        return map;
    }
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

     */
    protected void validateAttributes(IUnmarshallingContext ictx, StringArray attrs) {
       
        // setup for attribute access
        ValidationContext vctx = (ValidationContext)ictx.getUserContext();
        UnmarshallingContext uctx = (UnmarshallingContext)ictx;
       
        // loop through all attributes of current element
        for (int i = 0; i < uctx.getAttributeCount(); i++) {
           
            // check if nonamespace attribute is in the allowed set
            String name = uctx.getAttributeName(i);
            if (uctx.getAttributeNamespace(i).length() == 0) {
                if (attrs.indexOf(name) < 0) {
                    vctx.addWarning("Undefined attribute " + name, this);
                }
            }
        }
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

     * @throws JiBXException on error in document
     */
    public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException {
       
        // make sure current element name matches an allowed schema element
        UnmarshallingContext ctx = (UnmarshallingContext)ictx;
        String name = ctx.getElementName();
        int index = Arrays.binarySearch(SchemaBase.ELEMENT_NAMES, name);
        if (index >= 0) {
           
            // check the type of element
            long mask = SchemaBase.ELEMENT_MASKS[index];
            StringArray attrs = null;
            if ((mask & s_namedIgnorableValueMask) != 0) {
                attrs = s_namedIgnorableValueAttributes;
            } else if ((mask & s_namedValueMask) != 0) {
                attrs = s_namedValueAttributes;
            } else if ((mask & s_unnamedValueMask) != 0) {
                attrs = s_unnamedValueAttributes;
            } else if ((mask & s_typeDefinitionMask) != 0) {
                attrs = s_typeDefinitionAttributes;
            } else if ((mask & s_simpleNestingMask) != 0) {
                attrs = s_baseAttributes;
            } else if ((mask & s_deletableLeafMask) != 0) {
                attrs = s_ignorableAttributes;
            }
            if (attrs != null) {
               
                // create an instance and unmarshal with the appropriate handling
                ComponentCustom comp = new ComponentCustom(name,
                    (NestingCustomBase)CustomBase.getContainingObject(ictx));
                comp.validateAttributes(ictx, attrs);
                ctx.getUnmarshaller("component-custom").unmarshal(comp, ctx);
                ctx.parsePastCurrentEndTag(null, name);
                return comp;
               
            } else {
               
                // report a validation error for unsupported element
                ValidationContext vctx = (ValidationContext)ictx.getUserContext();
                vctx.addFatal("No customizations allowed", new ProblemLocation(ictx));
               
            }
        } else {
           
            // report a validation error for unknown element
            ValidationContext vctx = (ValidationContext)ictx.getUserContext();
            vctx.addFatal("Unknown element", new ProblemLocation(ictx));
           
        }
        ctx.skipElement();
        return null;
    }
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

        // handle basic validation
        readNamespaces(ictx);
        validateAttributes(ictx, true, attrs);
       
        // loop through all attributes of current element
        UnmarshallingContext uctx = (UnmarshallingContext)ictx;
        clearExtraAttributes();
        for (int i = 0; i < uctx.getAttributeCount(); i++) {
           
            // collect attributes from non-schema namespaces
            String ns = uctx.getAttributeNamespace(i);
            if (ns != null && ns.length() > 0 && !SCHEMA_NAMESPACE.equals(ns)) {
                addExtraAttribute(uctx.getAttributeName(i), ns,
                    uctx.getAttributeValue(i));
            }
        }
    }
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

     * @param ictx
     * @return created instance
     * @throws JiBXException
     */
    private static FaultCustom throwsFactory(IUnmarshallingContext ictx) throws JiBXException {
        UnmarshallingContext uctx = (UnmarshallingContext)ictx;
        Object parent = uctx.getStackTop();
        int depth = 0;
        if (parent instanceof Collection) {
            parent = uctx.getStackObject(++depth);
        }
        return new FaultCustom((OperationCustom)parent, uctx.attributeText(null, "class"));
    }
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;
        } else {
           
            // check for reference to existing ID
            String id = ctx.attributeText(null, getAttributeName(), null);
            if (id == null) {
               
                // no ID value supplied, unmarshal full definition
                obj = ctx.unmarshalElement();
               
            } else {
               
                // find object based on ID
                obj = ctx.findID(id, 0);
                ctx.parsePastEndTag(m_uri, m_name);
                if (obj == null) {
                    ctx.throwStartTagException("Reference to undefined ID " +
                        id);
                }
            }
        }
        return obj;
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.