Package org.jibx.schema

Examples of org.jibx.schema.TreeWalker


     * @param schemas schemas to be validated
     */
    public void validateSchemas(SchemaElement[] schemas) {
       
        // validate the schemas and report any problems
        TreeWalker wlkr = new TreeWalker(m_validationContext, m_validationContext);
        s_logger.debug("Beginning schema prevalidation pass");
        m_validationContext.clearTraversed();
        s_logger.debug("Beginning schema prevalidation pass");
        for (int i = 0; i < schemas.length; i++) {
            wlkr.walkSchema(schemas[i], new PrevalidationVisitor(m_validationContext));
            s_logger.debug("After prevalidation schema " + schemas[i].getResolver().getName() +
                " has effective namespace " + schemas[i].getEffectiveNamespace());
        }
        s_logger.debug("Beginning name registration pass");
        m_validationContext.clearTraversed();
        for (int i = 0; i < schemas.length; i++) {
            wlkr.walkSchema(schemas[i], new NameRegistrationVisitor(m_validationContext));
        }
        s_logger.debug("Beginning name merge pass");
        m_validationContext.clearTraversed();
        for (int i = 0; i < schemas.length; i++) {
            wlkr.walkSchema(schemas[i], new NameMergeVisitor(m_validationContext));
        }
        s_logger.debug("Beginning validation pass");
        m_validationContext.clearTraversed();
        for (int i = 0; i < schemas.length; i++) {
            wlkr.walkSchema(schemas[i], new ValidationVisitor(m_validationContext));
            s_logger.debug("After validation schema " + schemas[i].getResolver().getName() +
                " has effective namespace " + schemas[i].getEffectiveNamespace());
        }
    }
View Full Code Here


                    }
                }
            }
           
        };
        TreeWalker wlkr = new TreeWalker(null, new SchemaContextTracker());
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            wlkr.walkElement((SchemaElement)iter.next(), visitor);
        }
       
        // validate the customizations
        m_global.validate(m_validationContext);
       
View Full Code Here

        for (Iterator iter = vctx.iterateSchemas(); iter.hasNext();) {
            ((SchemaElement)iter.next()).getRegister().reset();
        }
       
        // run full schema validation
        TreeWalker wlkr = new TreeWalker(vctx, vctx);
        s_logger.debug("Beginning schema prevalidation pass");
        vctx.clearTraversed();
        s_logger.debug("Beginning schema prevalidation pass");
        for (int i = 0; i < schemas.length; i++) {
            wlkr.walkSchema(schemas[i], new PrevalidationVisitor(vctx));
            s_logger.debug("After prevalidation schema " + schemas[i].getResolver().getName() +
                " has effective namespace " + schemas[i].getEffectiveNamespace());
        }
        s_logger.debug("Beginning name registration pass");
        vctx.clearTraversed();
        for (int i = 0; i < schemas.length; i++) {
            wlkr.walkSchema(schemas[i], new NameRegistrationVisitor(vctx));
        }
        s_logger.debug("Beginning name merge pass");
        vctx.clearTraversed();
        for (int i = 0; i < schemas.length; i++) {
            wlkr.walkSchema(schemas[i], new NameMergeVisitor(vctx));
        }
        s_logger.debug("Beginning validation pass");
        vctx.clearTraversed();
        for (int i = 0; i < schemas.length; i++) {
            wlkr.walkSchema(schemas[i], new ValidationVisitor(vctx));
            s_logger.debug("After validation schema " + schemas[i].getResolver().getName() +
                " has effective namespace " + schemas[i].getEffectiveNamespace());
        }
    }
View Full Code Here

     * other schemas referenced by the schema.
     *
     * @param schema
     */
    public void countSchemaTree(SchemaElement schema) {
        TreeWalker wlkr = new TreeWalker(null, m_visitor.getListener());
        wlkr.walkSchema(schema, m_visitor);
    }
View Full Code Here

            s_logger.debug("adding reference closure for " + SchemaUtils.describeComponent(comp));
            int base = m_newReferences.size();
            countUse(comp);
           
            // loop processing new components until no more new components found
            TreeWalker wlkr = new TreeWalker(null, m_tracker);
            while (m_newReferences.size() > base) {
                int limit = m_newReferences.size();
                if (base > 0) {
                    s_logger.debug(" found " + (limit-base) + " new references in expansion pass");
                }
                for (int i = base; i < limit; i++) {
                   
                    // make sure component is a user type (not schema type)
                    AnnotatedBase ref = (AnnotatedBase)m_newReferences.get(i);
                    OpenAttrBase parent = ref.getParent();
                    if (parent instanceof SchemaElement) {
                       
                        // expand reference from this component
                        s_logger.debug(" adding reference closure for " + SchemaUtils.describeComponent(ref));
                        m_tracker.setNameRegister(((SchemaElement)parent).getRegister());
                        wlkr.walkElement(ref, this);
                       
                    } else {
                        s_logger.debug(" reference closure with non-global definition " + ref);
                    }
                }
View Full Code Here

            // 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) {
                        return false;
                    }
                   
                    public boolean visit(ComplexTypeElement node) {
                        typeschemas.put(node.getQName(), holder);
                        return false;
                    }
                   
                    public boolean visit(ElementElement node) {
                        elemschemas.put(node.getQName(), holder);
                        return false;
                    }
                   
                };
                wlkr.walkChildren(schema, visitor);
            }
           
            // build set of binding definitions provided on command line
            final Set bindings = new HashSet();
            errors = ResourceMatcher.matchPaths(new File("."), null, parms.getUseBindings(),
                new ResourceMatcher.ReportMatch() {
                    public void foundMatch(String path, URL url) {
                        bindings.add(url);
                    }
                });
            if (errors.size() > 0) {
                for (Iterator iter = errors.iterator(); iter.hasNext();) {
                    System.err.println(iter.next());
                }
                System.exit(3);
            }
           
            // build maps of type and element mappings from bindings
            Map classelems = new HashMap();
            Map classtypes = new HashMap();
            for (Iterator iter = bindings.iterator(); iter.hasNext();) {
                URL url = (URL)iter.next();
                processPregeneratedBinding(url, classelems, classtypes);
            }
           
            // generate services, bindings, and WSDLs
            Jibx2Wsdl inst = new Jibx2Wsdl(parms);
            ArrayList extras = new ArrayList(parms.getExtraTypes());
            ArrayList classes = parms.getGlobal().getUnmarshalledClasses();
            for (int i = 0; i < classes.size(); i++) {
                ClassCustom clas = (ClassCustom)classes.get(i);
                if (clas.isForceMapping()) {
                    extras.add(clas.getName());
                }
            }
            List wsdls = inst.generate(parms.getExtraArgs(), extras, classelems, elemschemas, classtypes, typeschemas,
                exists);
            if (wsdls != null) {
               
                // write the schemas and WSDLS
                SchemaGen.writeSchemas(parms.getGeneratePath(), inst.m_uriSchemaMap.values());
                WsdlWriter writer = new WsdlWriter();
                for (Iterator iter = wsdls.iterator(); iter.hasNext();) {
                    Definitions def = (Definitions)iter.next();
                    File file = new File(parms.getGeneratePath(), def.getServiceName() + ".wsdl");
                    writer.writeWSDL(def, new FileOutputStream(file));
                }
               
                // find existing schemas referenced (directly or indirectly) from WSDL schemas
                final Set needschemas = new HashSet();
                SchemaVisitor visitor = new SchemaVisitor() {
                   
                    private int m_existsDepth;
                   
                    public void exit(SchemaElement node) {
                        if (exists.contains(node)) {
                            m_existsDepth--;
                        }
                    }

                    public boolean visit(SchemaBase node) {
                        return false;
                    }

                    public boolean visit(SchemaElement node) {
                        if (exists.contains(node)) {
                            m_existsDepth++;
                        }
                        return true;
                    }

                    public boolean visit(SchemaLocationBase node) {
                        SchemaElement schema = node.getReferencedSchema();
                        if (needschemas.contains(schema)) {
                            return false;
                        } else {
                            if (m_existsDepth > 0 || exists.contains(schema)) {
                                needschemas.add(schema);
                            }
                            return true;
                        }
                    }
                   
                };
                for (int i = 0; i < wsdls.size(); i++) {
                    Definitions def = (Definitions)wsdls.get(i);
                    ArrayList schemas = def.getSchemas();
                    for (int j = 0; j < schemas.size(); j++) {
                        wlkr.walkChildren((SchemaBase)schemas.get(0), visitor);
                    }
                }
               
                // copy all referenced schemas to target directory
                byte[] buff = new byte[4096];
View Full Code Here

        }
        DefinitionItem definition = new DefinitionItem(comp);
        m_group = definition;
        m_global = (GlobalExtension)comp.getExtension();
        m_global.setDefinition(definition);
        TreeWalker wlkr = new TreeWalker(null, new SchemaContextTracker());
        wlkr.walkElement(comp, this);
        if (s_logger.isDebugEnabled()) {
            m_nestingDepth--;
            s_logger.debug(SchemaUtils.getIndentation(m_nestingDepth) + "Completed structure for global definition " +
                SchemaUtils.describeComponent(comp) + " with " + m_group.getChildCount() + " child items");
        }
View Full Code Here

        GroupItem hold = m_group;
        m_group = hold.addGroup(comp);
        m_group.setEnumeration(isenum);
       
        // walk the nested definition to add details to structure
        TreeWalker wlkr = new TreeWalker(null, new SchemaContextTracker());
        wlkr.walkChildren(comp, this);
       
        // return the structure
        GroupItem ret = m_group;
        if (s_logger.isDebugEnabled()) {
            m_nestingDepth--;
View Full Code Here

     * Strip the annotation components (at any level) from a schema definitions.
     */
    public void stripAnnotations() {
           
        // first delete all annotation children of the schema element itself
        TreeWalker wlkr = new TreeWalker(null, new SchemaContextTracker());
        for (int i = 0; i < m_schema.getChildCount(); i++) {
            if (m_schema.getChild(i).type() == SchemaBase.ANNOTATION_TYPE) {
                m_schema.detachChild(i);
            }
        }
        m_schema.compactChildren();
       
        // now remove all embedded annotations within any definitions
        wlkr.walkSchema(m_schema, new AnnotationDeletionVisitor());
    }
View Full Code Here

        // Level level = TreeWalker.setLogging(s_logger.getLevel());
        Set foundset = Collections.EMPTY_SET;
        if (m_includes != null || m_excludes != null) {
            foundset = new HashSet();
        }
        TreeWalker wlkr = new TreeWalker(null, new SchemaContextTracker());
        for (Iterator iter = globals.iterator(); iter.hasNext();) {
            OpenAttrBase global = (OpenAttrBase)iter.next();
            if (global instanceof INamed) {
               
                // set up the basic global definition extension
                GlobalExtension exten = new GlobalExtension(m_extension, global);
                String name = ((INamed)global).getName();
                boolean exclude = exclset.contains(name);
                exten.setRemoved(exclude);
                if (exclude) {
                    foundset.add(name);
                }
                boolean include = inclset.contains(name);
                exten.setIncluded(include);
                if (include) {
                    foundset.add(name);
                }
               
                // initialize extensions for full tree of non-excluded global definition components
                if (!exten.isRemoved()) {
                    extendGlobal(builder, wlkr, exten);
                } else if (global.type() == SchemaBase.SIMPLETYPE_TYPE ||
                    global.type() == SchemaBase.COMPLEXTYPE_TYPE) {
                    setReplacement(((INamed)global).getQName(), null);
                }
            }
        }
        // TreeWalker.setLogging(level);
       
        // report any names not found
        if (foundset.size() < exclset.size() + inclset.size()) {
            Set mergeset = new HashSet();
            mergeset.addAll(exclset);
            mergeset.addAll(inclset);
            for (Iterator iterator = mergeset.iterator(); iterator.hasNext();) {
                String name = (String)iterator.next();
                if (!foundset.contains(name)) {
                    vctx.addWarning("Name '" + name + "' not found in schema", this);
                }
            }
        }
       
        // use child customizations to amend the generated extensions
        int size = getChildren().size();
        for (int i = 0; i < size; i++) {
            ComponentCustom custom = (ComponentCustom)getChildren().get(i);
            SchemaPath path = custom.buildPath(vctx);
            if (path != null) {
                if (path.isWildStart()) {
                    vctx.addError("Top level customizations cannot use wildcard as first step", custom);
                } else {
                   
                    // match only the first path step
                    OpenAttrBase match = path.partialMatchUnique(0, 0, m_schema);
                    if (s_logger.isDebugEnabled()) {
                        if (match == null) {
                            s_logger.debug("No global schema component found for customization " + custom);
                        } else {
                            s_logger.debug("Matched customization " + custom + " to global schema component "
                                + SchemaUtils.describeComponent(match));
                        }
                    }
                    if (match != null) {
                        String name = ((INamed)match).getName();
                        GlobalExtension exten = (GlobalExtension)match.getExtension();
                        if (custom.isExcluded()) {
                           
                            // check if customization applies to descendant of global definition component
                            if (path.getPathLength() == 1) {
                               
                                // force exclude if generation skipped by customization
                                if (exten.isIncluded()) {
                                    vctx.addWarning("Name '" + name
                                        + "' is on include list for schema, but excluded by customization", custom);
                                }
                                exten.setIncluded(false);
                                exten.setRemoved(true);
                               
                            } else {
                               
                                // apply customization to target component extension(s)
                                applyRemainingCustomizationPath(path, match, custom, vctx);
                               
                            }
                           
                        } else {
                           
                            // check for customization for global excluded at schema level
                            if (exten.isRemoved()) {
                                vctx.addWarning("Name '" + name
                                    + "' is on excludes list for schema, but has a customization", custom);
                                exten.setRemoved(false);
                                extendGlobal(builder, wlkr, exten);
                            }
                           
                            // check if customization applies to descendant of global definition component
                            if (path.getPathLength() > 1) {
                                applyRemainingCustomizationPath(path, match, custom, vctx);
                            } else {
                                custom.apply((ComponentExtension)match.getExtension(), vctx);
                            }
                           
                        }
                    }
                }
            }
        }
       
        // flag extensions for facets to be removed from schema
        SchemaVisitor visitor = new FacetRemoverVisitor(this);
        for (Iterator iter = globals.iterator(); iter.hasNext();) {
            OpenAttrBase global = (OpenAttrBase)iter.next();
            ComponentExtension exten = (ComponentExtension)global.getExtension();
            if (exten != null && !exten.isRemoved()) {
                wlkr.walkElement(global, visitor);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.jibx.schema.TreeWalker

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.