Examples of ValidationContext


Examples of org.jibx.schema.validation.ValidationContext

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

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

                }
                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

Examples of org.jibx.schema.validation.ValidationContext

            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

Examples of org.jibx.schema.validation.ValidationContext

        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

Examples of org.jibx.schema.validation.ValidationContext

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

Examples of org.jibx.schema.validation.ValidationContext

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

Examples of org.jibx.schema.validation.ValidationContext

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

Examples of org.jibx.schema.validation.ValidationContext

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

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, 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
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.