Package org.jibx.schema.elements

Examples of org.jibx.schema.elements.SchemaElement


     */
    public void prevalidate(ValidationContext vctx) {
        if (m_ref != null && m_name != null) {
            vctx.addError("Cannot use both 'ref' and 'name'", getOwner());
        }
        SchemaElement schema = vctx.getCurrentSchema();
        String ens = schema.getEffectiveNamespace();
        QNameConverter.patchQNameNamespace(ens, m_ref);
    }
View Full Code Here


     *
     * @param iter schema iterator
     */
    public void setDefaultPrefixes(Iterator iter) {
        while (iter.hasNext()) {
            SchemaElement schema = (SchemaElement)iter.next();
            ArrayList decls = schema.getNamespaceDeclarations();
            for (int i = 0; i < decls.size(); i++) {
                String prefix = (String)decls.get(i++);
                m_bindingDirectory.addDefaultPrefix((String)decls.get(i), prefix);
            }
        }
View Full Code Here

        m_packageDirectory = new PackageOrganizer(m_targetDir, dfltpack);
       
        // link each schema to a customization, creating a default customization if necessary
        int count = 0;
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            ISchemaResolver resolver = schema.getResolver();
            s_logger.debug("Assigning customization for schema " + ++count + ": " + resolver.getName());
            SchemasetCustom owner = findSchemaset(schema, m_global);
            SchemaCustom custom = owner.forceCustomization(resolver.getName(), resolver.getId(), schema,
                m_validationContext);
            custom.validate(m_validationContext);
            String pname = custom.getPackage();
            PackageHolder holder = null;
            if (pname == null) {
                String uri = schema.getEffectiveNamespace();
                if (uri == null) {
                    uri = "";
                }
                holder = m_packageDirectory.getPackageForUri(uri);
            } else {
View Full Code Here

     */
    private boolean processExtensions() {
       
        // first clear all the cross reference information
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            int count = schema.getChildCount();
            for (int i = 0; i < count; i++) {
                SchemaBase child = schema.getChild(i);
                Object obj = child.getExtension();
                if (obj instanceof GlobalExtension) {
                    ((GlobalExtension)obj).resetDependencies();
                }
            }
        }
       
        // process each loaded schema for deletions and cross referencing
        int index = 0;
        m_validationContext.clearTraversed();
        boolean modified = false;
        // Level level = TreeWalker.setLogging(s_logger.getLevel());
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            m_validationContext.enterSchema(schema);
            s_logger.debug("Applying extensions to schema " + ++index + ": " + schema.getResolver().getName());
            int count = schema.getChildCount();
            boolean instmod = false;
            for (int i = 0; i < count; i++) {
                SchemaBase child = schema.getChild(i);
                Object obj = child.getExtension();
                if (obj instanceof GlobalExtension) {
                   
                    // apply extension to global definition element
                    ComponentExtension exten = (ComponentExtension)obj;
                    if (exten.isRemoved()) {
                       
                        // just eliminate this definition from the schema
                        schema.detachChild(i);
                        instmod = true;
                       
                    } else {
                       
                        // process the definition to remove references to deleted components
                        exten.applyAndCountUsage(m_validationContext);
                       
                    }
                }
            }
            if (instmod) {
                schema.compactChildren();
                modified = true;
            }
            m_validationContext.exitSchema();
           
        }
View Full Code Here

        while (processExtensions() || modified) {
           
            // normalize all the schema definitions
            modified = false;
            for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
                SchemaElement schema = (SchemaElement)iter.next();
                int count = schema.getChildCount();
                boolean instmod = false;
                for (int i = 0; i < count; i++) {
                    SchemaBase child = schema.getChild(i);
                    Object obj = child.getExtension();
                    if (obj instanceof GlobalExtension) {
                        GlobalExtension global = (GlobalExtension)obj;
                        global.normalize();
                        if (global.isRemoved() ||
                            (!global.isIncluded() && global.isPreferInline() && global.getOverrideType() != null)) {
                           
                            // just eliminate this definition from the schema
                            schema.detachChild(i);
                            instmod = true;
                           
                        }
                    }
                }
                if (instmod) {
                    schema.compactChildren();
                    modified = true;
                }
            }
           
        }
       
        // finish by flagging global definitions requiring separate classes
        TreeWalker wlkr = new TreeWalker(null, new SchemaContextTracker());
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            SchemaCustom custom = ((SchemaExtension)schema.getExtension()).getCustom();
            if (custom.isGenerateAll()) {
                int count = schema.getChildCount();
                for (int i = 0; i < count; i++) {
                   
                    // check if this global needs a class
                    SchemaBase comp = schema.getChild(i);
                    boolean include = false;
                    switch (comp.type()) {
/*                        case SchemaBase.ATTRIBUTE_TYPE:
                            include = !custom.isAttributeInlined();
                            break;  */
 
View Full Code Here

    public void pruneDefinitions() {
       
        // start by recursively checking for removable global definitions
        int index = 0;
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            s_logger.debug("Checking for unused definitions in schema " + ++index + ": "
                + schema.getResolver().getName());
            int count = schema.getChildCount();
            for (int i = 0; i < count; i++) {
                SchemaBase child = schema.getChild(i);
                Object exten = child.getExtension();
                if (exten instanceof GlobalExtension) {
                   
                    // check if global definition is unused and not specifically required
                    ((GlobalExtension)exten).checkRemovable();
                   
                }
            }
        }
       
        // next remove all the definitions flagged in the first step
        index = 0;
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            s_logger.debug("Deleting unused definitions in schema " + ++index + ": " + schema.getResolver().getName());
            int count = schema.getChildCount();
            boolean modified = false;
            for (int i = 0; i < count; i++) {
                SchemaBase child = schema.getChild(i);
                Object exten = child.getExtension();
                if (exten instanceof GlobalExtension && ((ComponentExtension)exten).isRemoved()) {
                   
                    // remove the definition from schema
                    schema.detachChild(i);
                    modified = true;
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug(" Removed definition " + ((INamed)child).getQName());
                    }
                   
                }
            }
            if (modified) {
                schema.compactChildren();
            }
        }
    }
View Full Code Here

    private ArrayList buildItemStructures() {
        ArrayList items = new ArrayList();
        ItemVisitor itembuilder = new ItemVisitor();
        int index = 0;
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            m_validationContext.enterSchema(schema);
            s_logger.info("Building item structure for schema " + ++index + ": " + schema.getResolver().getName());
            int count = schema.getChildCount();
            for (int i = 0; i < count; i++) {
                SchemaBase child = schema.getChild(i);
                if (child.getExtension() instanceof GlobalExtension) {
                   
                    // create the definition
                    GlobalExtension global = (GlobalExtension)child.getExtension();
                    DefinitionItem definition = global.getDefinition();
View Full Code Here

            compactGroups(definition);
           
            // build the binding component for this definition
            ClassHolder clas = (ClassHolder)definition.getGenerateClass();
            OpenAttrBase comp = definition.getSchemaComponent();
            SchemaElement schema = comp.getSchema();
            BindingHolder holder = m_bindingDirectory.getRequiredBinding(schema);
            if (definition.isEnumeration()) {
               
                // construct format and add to binding
                FormatElement format = new FormatElement();
                format.setTypeName(clas.getBindingName());
                format.setQName(definition.getQName());
                ((EnumerationClassHolder)clas).setBinding(format);
                m_bindingDirectory.addFormat(format);
               
            } else {
               
                // construct mapping element
                MappingElementBase mapping = new MappingElement();
                mapping.setClassName(clas.getBindingName());
                if (comp.type() == SchemaBase.ELEMENT_TYPE) {
                   
                    // abstract or concrete mapping for element
                    ElementElement element = (ElementElement)comp;
                    setName(element.getEffectiveQName(), mapping, holder);
                    mapping.setAbstract(element.isAbstract());
                    QName group = element.getSubstitutionGroup();
                    if (group != null) {
                        ElementElement base = m_validationContext.findElement(group);
                        DefinitionItem basedef = ((GlobalExtension)base.getExtension()).getDefinition();
                        mapping.setExtendsName(basedef.getGenerateClass().getFullName());
                    }
                   
                } else {
                   
                    // abstract mapping for type definition or group
                    mapping.setAbstract(true);
                    QName qname = definition.getQName();
                    mapping.setTypeQName(qname);
                    String uri = qname.getUri();
                    if (uri != null) {
                        m_bindingDirectory.addTypeNameReference(holder, uri, schema);
                    }
                   
                }
               
                // add the mapping to binding and set on class
                holder.addMapping(mapping);
                ((StructureClassHolder)clas).setBinding(mapping);
                DefinitionItem elementdef = (DefinitionItem)typeinst.get(definition);
                if (elementdef != null) {
                   
                    // create mapping for element name linked to type
                    ElementElement element = (ElementElement)elementdef.getSchemaComponent();
                    SchemaElement elschema = element.getSchema();
                    MappingElementBase elmapping = new MappingElement();
                    elmapping.setClassName(clas.getBindingName());
                    elmapping.setAbstract(element.isAbstract());
                   
                    // handle linking to substitution group head using extends mapping
View Full Code Here

        Map namebindings = new HashMap();
        Map nsbindings = new HashMap();
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
           
            // check binding handling for schema
            SchemaElement schema = (SchemaElement)iter.next();
            SchemaExtension exten = (SchemaExtension)schema.getExtension();
            String uri = schema.getEffectiveNamespace();
            String prefix = exten.getPrefix();
            BindingHolder holder;
            String name = exten.getBindingFileName();
            boolean dflt = schema.isElementQualifiedDefault() || uri == null;
            if (name != null) {
               
                // specific binding name, create the binding or link to existing
                holder = (BindingHolder)namebindings.get(name);
                if (holder == null) {
View Full Code Here

     * @param handler
     */
    private static void listSchemas(SchemaElement[] schemas, ValidationContext vctx, ProblemHandler handler) {
        Set topset = new HashSet();
        for (int i = 0; i < schemas.length; i++) {
            SchemaElement schema = schemas[i];
            topset.add(schema);
            handler.report(" " + "top-level schema " + schema.getResolver().getName());
        }
        for (Iterator iter = vctx.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            if (!topset.contains(schema)) {
                handler.report(" " + "referenced schema " + schema.getResolver().getName());
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.jibx.schema.elements.SchemaElement

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.