⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 schemagenerator.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        while (index < m_structureStack.size()) {            NestingElementBase nest =                (NestingElementBase)m_structureStack.peek(index++);            if (nest.getDefinitions() != null) {                return nest.getDefinitions();            }        }        throw new IllegalStateException            ("Internal error: no definition context");    }    /**     * Process a structure component (structure or collection element) with no     * name and no child components. This adds the appropriate type of element     * or any definition to the container schema element.     *      * @param comp structure component to be processed     * @param egroup schema element to contain element definitions     * @param agroup schema element to contain attribute definitions     */    private void defineEmptyStructureComponent(StructureElementBase comp,        Element egroup, Element agroup) {        NestingElementBase parent =            (NestingElementBase)m_structureStack.peek(0);        boolean only = parent.children().size() == 1;        if (comp.type() == ElementBase.COLLECTION_ELEMENT) {                        // collection may define type or not            CollectionElement collection = (CollectionElement)comp;            String itype = collection.getItemTypeClass().getName();            DefinitionContext dctx = getDefinitions();            TemplateElementBase templ = dctx.getSpecificTemplate(itype);            Element element = null;            if (! (templ instanceof MappingElement)) {                if (only) {                    addComment(egroup, " Replace \"any\" with details of " +                        "content to complete schema ");                    element = addChildElement(egroup, "any");                } else {                    addComment(egroup,                        " No mapping for items of collection at " +                        ValidationException.describe(collection) + " ");                    addComment(egroup,                        " Fill in details of content to complete schema ");                }            } else {                element = addChildElement(egroup, "element");                element.setAttribute("ref", "tns:" +                    ((MappingElement)templ).getName());            }            if (element != null) {                element.setAttribute("minOccurs", "0");                element.setAttribute("maxOccurs", "unbounded");            }                    } else {                        // check for reference to a mapped class            StructureElement structure = (StructureElement)comp;            TemplateElementBase templ = structure.getMapAsMapping();            if (! (templ instanceof MappingElement)) {                                // unknown content, leave it to user to fill in details                if (only) {                    addComment(egroup, " Replace \"any\" with details of " +                        "content to complete schema ");                    addChildElement(egroup, "any");                } else {                    addComment(egroup, " No mapping for structure at " +                        ValidationException.describe(structure) + " ");                    addComment(egroup,                        " Fill in details of content here to complete schema ");                }                            } else {                MappingElement mapping = (MappingElement)templ;                if (mapping.isAbstract()) {                                        // check name to be used for instance of type                    String ename = structure.getName();                    if (ename == null) {                        ename = mapping.getName();                    }                    if (ename == null) {                                                // no schema equivalent, embed definition directly                        addComment(egroup, "No schema representation for " +                            "directly-embedded type, inlining definition");                        addComment(egroup, "Add element name to structure at " +                            ValidationException.describe(structure) +                            " to avoid inlining");                        defineList(mapping.children(), egroup, agroup, false);                                            } else {                                                // handle abstract mapping element as reference to type                        Element element = addChildElement(egroup, "element");                        String tname = simpleClassName(mapping.getClassName());                        element.setAttribute("type", "tns:" + tname);                        String name = structure.getName();                        if (name == null) {                            name = mapping.getName();                        }                        element.setAttribute("name", name);                        if (structure.isOptional()) {                            element.setAttribute("minOccurs", "0");                        }                    }                                    } else {                                        // concrete mapping, check for name overridden                    String sname = structure.getName();                    String mname = mapping.getName();                    if (sname != null && !sname.equals(mname)) {                                                // inline definition for overridden name                        addComment(egroup, "No schema representation for " +                            "element reference with different name, inlining " +                            "definition");                        addComment(egroup,                            "Remove name on mapping reference at " +                            ValidationException.describe(structure) +                            " to avoid inlining");                        defineList(mapping.children(), egroup, agroup, false);                                            } else {                                                // use element reference for concrete mapping                        Element element = addChildElement(egroup, "element");                        String tname = simpleClassName(mapping.getClassName());                        element.setAttribute("ref", "tns:" + mname);                        if (structure.isOptional()) {                            element.setAttribute("minOccurs", "0");                        }                    }                                    }            }                    }    }    /**     * Process a structure component (structure or collection element) within a     * list of child components. This adds the appropriate type of element or     * any definition to the container, if necessary calling other methods for     * recursive handling of nested child components.     *      * @param comp structure component to be processed     * @param egroup schema element to contain element definitions     * @param agroup schema element to contain attribute definitions     * @param mult allow any number of occurrences of components flag     */    private void defineStructureComponent(StructureElementBase comp,        Element egroup, Element agroup, boolean mult) {                // check for element defined by binding component        if (comp.getName() != null) {                        // create basic element definition for name            Element element = addChildElement(egroup, "element");            element.setAttribute("name", comp.getName());            if (mult) {                element.setAttribute("minOccurs", "0");                element.setAttribute("maxOccurs", "unbounded");            } else if (comp.isOptional()) {                element.setAttribute("minOccurs", "0");            }                        // check for children present            if (comp.children().size() > 0) {                defineNestedStructure(comp, element);            } else {                                // nest complex type definition for actual content                Element type = addChildElement(element, "complexType");                Element seq = addChildElement(type, "sequence");                                // process the content description                defineEmptyStructureComponent(comp, seq, type);            }                    } else if (comp.children().size() > 0) {                        // handle child components with recursive call            boolean coll = comp.type() == ElementBase.COLLECTION_ELEMENT;            m_structureStack.push(comp);            defineList(comp.children(), egroup, agroup, coll);            m_structureStack.pop();                    } else {                        // handle empty structure definition inline            defineEmptyStructureComponent(comp, egroup, agroup);        }    }    /**     * Create the schema definition list for a binding component list. This     * builds the sequence of elements and attributes defined by the binding     * components, including nested complex types for elements with structure.     *      * @param comps binding component list     * @param egroup schema element to contain element definitions     * @param agroup schema element to contain attribute definitions     * @param mult allow any number of occurrences of components flag     */    private void defineList(ArrayList comps, Element egroup, Element agroup,        boolean mult) {                // handle all nested elements of container        for (int i = 0; i < comps.size(); i++) {            ElementBase child = (ElementBase)comps.get(i);            switch (child.type()) {                                case ElementBase.COLLECTION_ELEMENT:                case ElementBase.STRUCTURE_ELEMENT:                {                    defineStructureComponent((StructureElementBase)child,                        egroup, agroup, mult);                    break;                }                                    case ElementBase.MAPPING_ELEMENT:                {                    // nested mapping definitions not handled                    System.err.println("Error: nested mapping not supported " +                        "(class " + ((MappingElement)child).getClassName() +                        ")");                    break;                }                                    case ElementBase.TEMPLATE_ELEMENT:                {                    // templates to be added once usable in binding                    System.err.println                        ("Error: template component not yet supported");                    break;                }                                    case ElementBase.VALUE_ELEMENT:                {                    // get type information for value                    ValueElement value = (ValueElement)child;                    String tname = value.getType().getName();                    String stype = (String)s_primitiveTypeMap.get(tname);                    if (stype == null) {                        stype = (String)s_objectTypeMap.get(tname);                        if (stype == null) {                            stype = "xsd:string";                        }                    }                                        // build schema element or attribute for value                    Element element;                    int style = value.getStyle();                    if (style == NestingAttributes.ATTRIBUTE_STYLE) {                                                // append attribute as child of type                        element = addChildElement(agroup, "attribute");                        if (!value.isOptional()) {                            element.setAttribute("use", "required");                        }                                            } else if (style == NestingAttributes.ELEMENT_STYLE) {                                                // append simple element as child of grouping                        element = addChildElement(egroup, "element");                        if (mult) {                            element.setAttribute("minOccurs", "0");                            element.setAttribute("maxOccurs", "unbounded");                        } else if (value.isOptional()) {                            element.setAttribute("minOccurs", "0");                        }                                            } else {                                                // other types are not currently handled                        System.err.println("Error: value type " +                            value.getEffectiveStyleName() + " not supported");                        break;                                            }                                        // set common attributes on definition                    element.setAttribute("name", value.getName());                    element.setAttribute("type", stype);                    break;                }            }        }    }    /**     * Create the schema definition for a nested structure. This defines a     * complex type, if necessary calling itself recursively for elements which     * are themselves complex types. In the special case where the container     * element is a mapping which extends an abstract base class this generates     * the complex type as an extension of the base class complex type.     *      * @param container binding definition element containing nested structure     * @param parent schema element to hold the definition     * @return constructed complex type     */    private Element defineNestedStructure(ContainerElementBase container,        Element parent) {                // create complex type as holder for definition        Element type = addChildElement(parent, "complexType");                // check whether ordered or unordered container        Element group;        ArrayList childs = container.children();        if (container.isOrdered()) {                        // define content list as sequence            group = addChildElement(type, "sequence");                        // check for mapping which extends another mapping/*            if (container instanceof MappingElement) {                MappingElement mapping = (MappingElement)container;                MappingElement extended = mapping.getExtendsMapping();                if (extended != null) {                    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -