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

📄 schemadetaildirectory.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }    }    /**     * Create the detail information for a &lt;mapping>. This creates the detail     * information and adds it to the map, then analyzes the structure of the     * mapping to find references to other mappings and to enumeration types.     *     * @param map     * @return detail     */    private SchemaMappingDetail addDetail(MappingElement map) {                // check structure of mapping definition for schema type extension        MappingElement base = null;        ArrayList contents = map.getContentComponents();        if (contents.size() > 0) {                        // type extension requires reference as first content component            Object content = contents.get(0);            if (content instanceof StructureElement) {                StructureElement struct = (StructureElement)content;                if (isTypeDerivation(struct)) {                    base = (MappingElement)struct.getEffectiveMapping();                }            }        }                // next search recursively for text and/or child element components        //  this is done at this point (with loop recursion, if needed) so        //  that the flags can be set when creating the detail instance        boolean haschild = false;        boolean hastext = false;        ArrayList expands = new ArrayList();        expands.add(map);        for (int i = 0; i < expands.size(); i++) {                        // check for container with element name or text content            ContainerElementBase contain =                (ContainerElementBase)expands.get(i);            contents = contain.getContentComponents();            for (int j = 0; j < contents.size(); j++) {                IComponent comp = (IComponent)contents.get(j);                if (comp.hasName()) {                                        // component with name means child element                    haschild = true;                                    } else if (comp instanceof ValueElement) {                                        // value with no name implies text content                    hastext = true;                                    } else if (comp instanceof CollectionElement) {                                        // collection implies child element (repeating)                    haschild = true;                                    } else {                                        // structure, check for mapping reference                    StructureElement struct = (StructureElement)comp;                    if (struct.children().size() > 0) {                                                // add container structure to expansion list                        expands.add(comp);                                            } else {                        MappingElement ref =                            (MappingElement)struct.getEffectiveMapping();                        if (ref != null) {                                                        // mapping element reference, check if named                            if (ref.getName() != null) {                                haschild = true;                            } else {                                expands.add(ref);                            }                        }                    }                }            }        }                // get the names for this mapping        ClassCustom custom =            m_custom.forceClassCustomization(map.getClassName());        QName tname = map.getTypeQName();        if (tname == null) {            tname = custom.getTypeQName();        }        QName oname = null;        String name = map.getName();        if (name == null) {            oname = custom.getElementQName();        } else {            oname = new QName(map.getNamespace().getUri(), name);        }                // add new mapping detail based on information found        SchemaMappingDetail detail =            new SchemaMappingDetail(map, haschild, hastext, base, tname, oname);        m_mappingMap.put(map, detail);                // check for mapping to element name        if (map.getName() == null) {                        // require base type generation as type            if (base != null) {                SchemaMappingDetail basedetail = forceMappingDetail(base);                basedetail.setType(true);            }                    } else {                        // force generating an element for this mapping            detail.setElement(true);        }                // error if mapping extension doesn't map to type extension        MappingElement extended = map.getExtendsMapping();        if (extended != null) {            if (base == null ||                !base.getClassName().equals(extended.getClassName())) {                m_context.addError("'extends' mapping not usable as schema extension base", map);            } else {                                // flag generation as element in substitution group                SchemaMappingDetail extdetail = forceMappingDetail(extended);                extdetail.setElement(true);                detail.setSubstitution(extdetail.getOtherName());                detail.setElement(true);            }        }                // process all references from this mapping        checkReferences(map, base == null ? 0 : 1);        return detail;    }        /**     * Find detail information for a &lt;mapping>. If this is the first time a     * particular mapping was requested, a new detail information will be     * created for that mapping and returned.     *     * @param map     * @return detail     */    protected SchemaMappingDetail forceMappingDetail(MappingElement map) {        SchemaMappingDetail detail = (SchemaMappingDetail)m_mappingMap.get(map);        if (detail == null) {            detail = addDetail(map);        }        return detail;    }        /**     * Get detail information for a &lt;mapping>. If the detail information     * does not exist, this throws an exception.     *     * @param map     * @return detail     */    public SchemaMappingDetail getMappingDetail(MappingElement map) {        SchemaMappingDetail detail = (SchemaMappingDetail)m_mappingMap.get(map);        if (detail == null) {            throw new IllegalStateException("Detail not found");        } else {            return detail;        }    }        /**     * Get detail information for a simple type. If the detail information     * does not exist, this throws an exception.     *     * @param type     * @return detail     */    public SchemaEnumDetail getSimpleDetail(String type) {        SchemaEnumDetail detail = (SchemaEnumDetail)m_enumMap.get(type);        if (detail == null) {            throw new IllegalStateException("Detail not found");        } else {            return detail;        }    }        /**     * Get all complex type details.     *     * @return collection of {@link SchemaMappingDetail}     */    public Collection getComplexDetails() {        return m_mappingMap.values();    }        /**     * Get all simple type details.     *     * @return collection of {@link SchemaEnumDetail}     */    public Collection getSimpleDetails() {        return m_enumMap.values();    }    /**     * Model visitor for analyzing the structure of bindings and determining the     * appropriate schema components.     */    public class AnalysisVisitor extends ModelVisitor    {        /** Validation context running this visitor. */        private final ValidationContext m_context;                /**         * Constructor.         *          * @param vctx validation context that will run this visitor         */        public AnalysisVisitor(ValidationContext vctx) {            m_context = vctx;        }        /**         * Visit mapping element. This just adds the mapping definition, if not         * already added.         *          * @param node          * @return expansion flag         */        public boolean visit(MappingElement node) {                        // check for nested mapping            if (!(m_context.getParentElement() instanceof BindingElement)) {                m_context.addWarning("No schema equivalent for nested type definitions - converting to global type");            }                        // add the definition            forceMappingDetail(node);            return super.visit(node);        }        /**         * Visit structure or collection element. This just stops the expansion,         * since the content of mapping definitions is processed at the time the         * mapping is added.         *          * @param node          * @return <code>false</code> to block further expansion         */        public boolean visit(StructureElementBase node) {            return false;        }    }}

⌨️ 快捷键说明

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