Package org.jibx.schema.validation

Examples of org.jibx.schema.validation.ValidationContext


     */
    protected boolean loadCustomizations(String path) throws JiBXException, IOException {
       
        // load customizations and check for errors
        String[] spaths = (String[])m_sourcePaths.toArray(new String[m_sourcePaths.size()]);
        ValidationContext vctx = new ValidationContext();
        loadCustomizations(path, new ClassSourceLocator(spaths), vctx);
        ArrayList probs = vctx.getProblems();
        if (probs.size() > 0) {
            for (int i = 0; i < probs.size(); i++) {
                ValidationProblem prob = (ValidationProblem)probs.get(i);
                System.out.print(prob.getSeverity() >=
                    ValidationProblem.ERROR_LEVEL ? "Error: " : "Warning: ");
                System.out.println(prob.getDescription());
            }
            if (vctx.getErrorCount() > 0 || vctx.getFatalCount() > 0) {
                return false;
            }
        }
        return true;
    }
View Full Code Here


     * @return root element
     * @throws Exception
     */
    protected GlobalCustom readCustom(InputStream is) throws Exception {
        IUnmarshallingContext ictx = m_bindingFactory.createUnmarshallingContext();
        ValidationContext vctx = new ValidationContext();
        ictx.setDocument(is, null);
        ictx.setUserContext(vctx);
        GlobalCustom custom = new GlobalCustom();
        ((IUnmarshallable)custom).unmarshal(ictx);
        List problems = vctx.getProblems();
        if (problems.size() > 0) {
            StringBuffer buff = new StringBuffer();
            for (int i = 0; i < problems.size(); i++) {
                ValidationProblem prob = (ValidationProblem)problems.get(i);
                buff.append(prob.getSeverity() >=
View Full Code Here

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

                }
                System.exit(1);
            }
           
            // load and validate schemas
            ValidationContext vctx = new ValidationContext();
            ValidationUtils.load(resolves, null, vctx);
            ProblemMultiHandler handler = new ProblemMultiHandler();
            handler.addHandler(new ProblemConsoleLister());
            handler.addHandler(new ProblemLogLister(s_logger));
            if (vctx.reportProblems(handler)) {
                System.exit(2);
            }
           
            // build maps from qualified names to schema holders, and from schema to resolver (necessary since a new
            //  resolver will be set during the WSDL generation processing)
            final Map elemschemas = new HashMap();
            final Map typeschemas = new HashMap();
            final Set exists = new HashSet();
            TreeWalker wlkr = new TreeWalker(null, new SchemaContextTracker());
            for (Iterator iter = resolves.iterator(); iter.hasNext();) {
                SchemaElement schema = vctx.getSchemaById(((ISchemaResolver)iter.next()).getId());
                exists.add(schema);
                final SchemaHolder holder = new SchemaHolder(schema);
                SchemaVisitor visitor = new SchemaVisitor() {
                   
                    public boolean visit(SchemaBase node) {
View Full Code Here

            String ns = uctx.getAttributeNamespace(i);
            if (ns == null || ns.length() == 0) {
               
                // check if no-namespace attribute in allowed set
                if (attrs.indexOf(name) < 0) {
                    ValidationContext vctx = (ValidationContext)ictx.getUserContext();
                    vctx.addError("Undefined attribute " + name, ictx.getStackTop());
                }
               
            } else if (WSDL_NAMESPACE_URI.equals(ns)) {
               
                // no unknown attributes from definition namespace are defined
                ValidationContext vctx = (ValidationContext)ictx.getUserContext();
                vctx.addError("Undefined attribute " + name, ictx.getStackTop());
               
            } else if (!other) {
               
                // warn on non-WSDL attribute present where forbidden
                ValidationContext vctx = (ValidationContext)ictx.getUserContext();
                String qname = UnmarshallingContext.buildNameString(ns, name);
                vctx.addWarning("Non-WSDL attribute not allowed " + qname, ictx.getStackTop());
               
            }
        }
    }
View Full Code Here

        m_global = parms.getCustomRoot();
        m_global.setSubstitutions(DEFAULT_REPLACEMENTS);
        m_schemaRoot = parms.getSchemaRoot();
        m_schemaDir = parms.getSchemaDir();
        m_targetDir = parms.getGeneratePath();
        m_validationContext = new ValidationContext();
    }
View Full Code Here

    protected ValidationContext m_validationContext;
   
    protected NameRegister m_nameRegister;
   
    protected void setUp() throws Exception {
        m_validationContext = new ValidationContext();
    }
View Full Code Here

     * @throws IOException
     */
    protected boolean loadCustomizations(String path) throws JiBXException, IOException {
       
        // load customizations and check for errors
        ValidationContext vctx = new ValidationContext();
        m_customRoot = new SchemasetCustom((SchemasetCustom)null);
        if (path != null) {
            IBindingFactory fact = BindingDirectory.getFactory(SchemasetCustom.class);
            IUnmarshallingContext ictx = fact.createUnmarshallingContext();
            FileInputStream is = new FileInputStream(path);
            ictx.setDocument(is, null);
            ictx.setUserContext(vctx);
            ((IUnmarshallable)m_customRoot).unmarshal(ictx);
        }
        ArrayList probs = vctx.getProblems();
        if (probs.size() > 0) {
            for (int i = 0; i < probs.size(); i++) {
                ValidationProblem prob = (ValidationProblem)probs.get(i);
                System.out.print(prob.getSeverity() >=
                    ValidationProblem.ERROR_LEVEL ? "Error: " : "Warning: ");
                System.out.println(prob.getDescription());
            }
            if (vctx.getErrorCount() > 0 || vctx.getFatalCount() > 0) {
                return false;
            }
        }
        return true;
    }
View Full Code Here

     * @param ictx
     */
    private void setNameConverter(NameConverter nconv, IUnmarshallingContext ictx) {
        if (nconv != null) {
            if (m_nameConverter != null) {
                ValidationContext vctx = (ValidationContext)ictx.getUserContext();
                vctx.addWarning("Repeated 'name-converter' element overrides previous setting", new ProblemLocation(ictx));
            }
            m_nameConverter = nconv;
        }
    }
View Full Code Here

     * @return class decorator instance, or <code>null</code> if error
     */
    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 {
               
                // make sure the class implements the required interface
                Class clas = SchemaRootBase.class.getClassLoader().loadClass(cname);
                if (ClassDecorator.class.isAssignableFrom(clas)) {
                    vctx.addError("Class " + cname + " does not implement the required IClassDecorator interface",
                        new ProblemLocation(ictx));
                } else {
                    try {
                        return (ClassDecorator)clas.newInstance();
                    } catch (InstantiationException e) {
                        vctx.addError("Error creating instance of class " + cname + ": " + e.getMessage(),
                            new ProblemLocation(ictx));
                    } catch (IllegalAccessException e) {
                        vctx.addError("Unable to access constructor for class " + cname + ": " + e.getMessage(),
                            new ProblemLocation(ictx));
                    }
                }
               
            } catch (ClassNotFoundException e) {
                vctx.addError("Unable to find class " + cname + " in classpath", new ProblemLocation(ictx));
            }
        }
        return null;
    }
View Full Code Here

TOP

Related Classes of org.jibx.schema.validation.ValidationContext

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.