Examples of ValidationContext


Examples of org.jibx.schema.validation.ValidationContext

         * @throws JiBXException on error
         */
        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();
View Full Code Here

Examples of org.jibx.schema.validation.ValidationContext

         * @return object
         */
        protected Object createInstance(String cname, UnmarshallingContext ctx) {
           
            // set the class to be used for name converter instance
            ValidationContext vctx = (ValidationContext)ctx.getUserContext();
            if (cname == null) {
                cname = "org.jibx.schema.codegen.extend.DefaultNameConverter";
            }
            try {
               
                // make sure the class implements the required interface
                Class clas = SchemaRootBase.class.getClassLoader().loadClass(cname);
                if (NameConverter.class.isAssignableFrom(clas)) {
                    try {
                       
                        // check for existing name converter instance to pass to constructor
                        SchemaRootBase outer = (SchemaRootBase)ctx.getStackTop();
                        NameConverter prior = outer.getNameConverter();
                        if (prior != null) {
                           
                            // try to create instance of new converter passing old converter
                            try {
                                Constructor cons = clas.getConstructor(new Class[] { prior.getClass() });
                                try {
                                    return cons.newInstance(new Object[] { prior });
                                } catch (IllegalArgumentException e) { /* ignore failure */
                                } catch (InvocationTargetException e) {
                                    vctx.addWarning("Failed passing existing name converter to constructor for class " +
                                        cname + ": " + e.getMessage(), new ProblemLocation(ctx));
                                }
                               
                            } catch (SecurityException e) { /* ignore failure */
                            } catch (NoSuchMethodException e) { /* ignore failure */ }
                        }
                       
                        // just create instance using no-argument constructor
                        return clas.newInstance();
                       
                    } catch (InstantiationException e) {
                        vctx.addError("Error creating instance of class " + cname + ": " + e.getMessage(),
                            new ProblemLocation(ctx));
                    } catch (IllegalAccessException e) {
                        vctx.addError("Unable to access constructor for class " + cname + ": " + e.getMessage(),
                            new ProblemLocation(ctx));
                    }
                } else {
                    vctx.addError("Class " + cname + " does not implement the required NameConverter interface",
                        new ProblemLocation(ctx));
                }
               
            } catch (ClassNotFoundException e) {
                vctx.addError("Unable to find class " + cname + " in classpath", new ProblemLocation(ctx));
            }
            return null;
        }
View Full Code Here

Examples of org.jibx.schema.validation.ValidationContext

         * @return object
         */
        protected Object createInstance(String cname, UnmarshallingContext ctx) {
           
            // check class to be used for class decorator instance
            ValidationContext vctx = (ValidationContext)ctx.getUserContext();
            if (cname == null) {
                vctx.addError("Missing required 'class' attribute", new ProblemLocation(ctx));
            } else {
                try {
                   
                    // make sure the class implements the required interface
                    Class clas = SchemaRootBase.class.getClassLoader().loadClass(cname);
                    if (ClassDecorator.class.isAssignableFrom(clas)) {
                        try {
                            return clas.newInstance();
                        } catch (InstantiationException e) {
                            vctx.addError("Error creating instance of class " + cname + ": " + e.getMessage(),
                                new ProblemLocation(ctx));
                        } catch (IllegalAccessException e) {
                            vctx.addError("Unable to access constructor for class " + cname + ": " + e.getMessage(),
                                new ProblemLocation(ctx));
                        }
                    } else {
                        vctx.addError("Class " + cname + " does not implement the required ClassDecorator interface",
                            new ProblemLocation(ctx));
                    }
                   
                } catch (ClassNotFoundException e) {
                    vctx.addError("Unable to find class " + cname + " in classpath", new ProblemLocation(ctx));
                }
            }
            return null;
        }
View Full Code Here

Examples of org.jibx.schema.validation.ValidationContext

    public static SchemasetCustom loadCustomizations(String path, ProblemHandler handler)
    throws JiBXException, IOException {
       
        // load customizations and check for errors
        SchemasetCustom custom = null;
        ValidationContext vctx = new ValidationContext();
        if (path == null) {
            custom = new SchemasetCustom((SchemasetCustom)null);
        } else {
           
            // unmarshal either a <schema-set> or <schema> element
            IBindingFactory fact = BindingDirectory.getFactory(SchemasetCustom.class);
            IUnmarshallingContext ictx = fact.createUnmarshallingContext();
            FileInputStream is = new FileInputStream(path);
            ictx.setDocument(is, null);
            ictx.setUserContext(vctx);
            Object obj = ictx.unmarshalElement();
            if (obj instanceof SchemasetCustom) {
                custom = (SchemasetCustom)obj;
            } else if (obj instanceof SchemaCustom) {
                custom = new SchemasetCustom((SchemaCustom)obj);
            } else {
                throw new IOException("Customization document root element must be 'schema-set' or 'schema'");
            }
           
        }
        if (vctx.reportProblems(handler)) {
            return null;
        }
        return custom;
    }
View Full Code Here

Examples of org.jibx.schema.validation.ValidationContext

     *
     * @param facets
     * @param ictx
     */
    public void setEnforcedFacets(String[] facets, IUnmarshallingContext ictx) {
        ValidationContext vctx = (ValidationContext)ictx.getUserContext();
        long mask = 0;
        if (facets != null) {
            for (int i = 0; i < facets.length; i++) {
                String facet = facets[i];
                int index = Arrays.binarySearch(FacetElement.FACET_ELEMENT_NAMES, facet);
                if (index >= 0) {
                    mask |= SchemaBase.ELEMENT_MASKS[FacetElement.FACET_ELEMENT_INDEXES[index]];
                } else {
                    vctx.addError("'" + facet + "' is not a facet name", this);
                }
            }
        }
        m_enforcedFacetsMask = mask;
    }
View Full Code Here

Examples of org.jibx.schema.validation.ValidationContext

     *
     * @param facets
     * @param ictx
     */
    public void setIgnoredFacets(String[] facets, IUnmarshallingContext ictx) {
        ValidationContext vctx = (ValidationContext)ictx.getUserContext();
        long mask = 0;
        if (facets != null) {
            for (int i = 0; i < facets.length; i++) {
                String facet = facets[i];
                int index = Arrays.binarySearch(FacetElement.FACET_ELEMENT_NAMES, facet);
                if (index >= 0) {
                    mask |= SchemaBase.ELEMENT_MASKS[FacetElement.FACET_ELEMENT_INDEXES[index]];
                } else {
                    vctx.addError("'" + facet + "' is not a facet name", this);
                }
            }
        }
        m_ignoredFacetsMask = mask;
    }
View Full Code Here

Examples of org.jibx.schema.validation.ValidationContext

     * @param attrs attributes array
     */
    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.schema.validation.ValidationContext

                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.schema.validation.ValidationContext

     */
    public static int convertEnumeration(String text, EnumSet eset, String name, IUnmarshallingContext ictx) {
        if (text == null) {
            return -1;
        } else {
            ValidationContext vctx = (ValidationContext)ictx.getUserContext();
            String nctext = Conversions.deserializeNMTOKEN(text, vctx, ictx.getStackTop());
            int type = eset.getValue(nctext);
            if (type < 0) {
                vctx.addError("Illegal value \"" + text + "\" for '" + name + "' attribute", ictx.getStackTop());
            }
            return type;
        }
    }
View Full Code Here

Examples of org.jibx.schema.validation.ValidationContext

            String ns = uctx.getAttributeNamespace(i);
            if (ns == null || ns.length() == 0) {
               
                // check if schema attribute in allowed set
                if (attrs.indexOf(name) < 0) {
                    ValidationContext vctx = (ValidationContext)ictx.getUserContext();
                    vctx.addError("Undefined attribute " + name, ictx.getStackTop());
                }
               
            } else if (SCHEMA_NAMESPACE.equals(ns)) {
               
                // no attributes from schema namespace are defined
                ValidationContext vctx = (ValidationContext)ictx.getUserContext();
                vctx.addError("Undefined attribute " + name, ictx.getStackTop());
               
            } else if (!extra) {
               
                // warn on non-schema attribute present where forbidden
                ValidationContext vctx = (ValidationContext)ictx.getUserContext();
                String qname = UnmarshallingContext.buildNameString(ns, name);
                vctx.addWarning("Non-schema attribute not allowed " + qname, ictx.getStackTop());
               
            }
        }
    }
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.