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

📄 definitioncontext.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                return new ValidationProblem                    ("Namespace prefix conflict for prefix '" + prefix +                    '\'', def);            }        }        return null;    }    /**     * Add namespace declaration to set defined at this level. This method     * treats all namespaces as though they were declared with default="none".     *     * @param def namespace definition to be added (duplicates ignored)     * @param ref binding element referencing the namespace     * @return problem information, or <code>null</code> if no problem     */    public ValidationProblem addImpliedNamespace(NamespaceElement def,        ElementBase ref) {        String uri = def.getUri();        NamespaceElement dup = checkDuplicatePrefix(def);        DefinitionContext ctx = this;        String prefix = def.getPrefix();        while (dup == null && (ctx = ctx.getContaining()) != null) {            dup = getNamespaceForPrefix(prefix);        }        if (dup == null) {                        // check for no definition of same URI with prefix            NamespaceElement prior = (NamespaceElement)m_uriMap.get(uri);            if (prior == null || prior.getPrefix() == null) {                                // no conflicts, add it                internalAddNamespace(def);            }                    } else if (!uri.equals(dup.getUri())) {            if (prefix == null) {                return new ValidationProblem                    ("Default namespace conflict on mapping reference", ref);            } else {                return new ValidationProblem                    ("Namespace conflict on mapping reference, for prefix '" + prefix +                    '\'', ref);            }        }        return null;    }    /**     * Get namespace definition for element name.     * TODO: handle multiple prefixes for namespace, proper screening     *     * @param name attribute group defining name     * @return namespace definition, or <code>null</code> if none that matches     */    public NamespaceElement getElementNamespace(NameAttributes name) {        String uri = name.getUri();        String prefix = name.getPrefix();        NamespaceElement ns = null;        if (uri != null) {            if (m_uriMap != null) {                ns = (NamespaceElement)m_uriMap.get(uri);                if (ns != null && prefix != null) {                    if (!prefix.equals(ns.getPrefix())) {                        ns = null;                    }                }            }        } else if (prefix != null) {            if (m_prefixMap != null) {                ns = (NamespaceElement)m_prefixMap.get(prefix);            }        } else {            ns = m_elementDefault;        }        if (ns == null && m_outerContext != null) {            ns = m_outerContext.getElementNamespace(name);        }        return ns;    }    /**     * Get namespace definition for attribute name.     * TODO: handle multiple prefixes for namespace, proper screening     *     * @param name attribute group defining name     * @return namespace definition, or <code>null</code> if none that matches     */    public NamespaceElement getAttributeNamespace(NameAttributes name) {        String uri = name.getUri();        String prefix = name.getPrefix();        NamespaceElement ns = null;        if (uri != null) {            if (m_uriMap != null) {                ns = (NamespaceElement)m_uriMap.get(uri);                if (ns != null && prefix != null) {                    if (!prefix.equals(ns.getPrefix())) {                        ns = null;                    }                }            }        } else if (prefix != null) {            if (m_prefixMap != null) {                ns = (NamespaceElement)m_prefixMap.get(prefix);            }        } else {            ns = m_attributeDefault;        }        if (ns == null && m_outerContext != null) {            ns = m_outerContext.getAttributeNamespace(name);        }        return ns;    }        /**     * Add format to set defined at this level.     *     * @param def format definition element to be added     * @param vctx validation context in use     */    public void addFormat(FormatElement def, ValidationContext vctx) {        if (m_formatContext == null) {            m_formatContext =                new ClassHierarchyContext(getContainingFormatContext());        }        if (def.isDefaultFormat()) {            IClass clas = def.getType();            m_formatContext.addTypedComponent(clas, def, vctx);        }        String label = def.getLabel();        if (label != null) {            m_formatContext.addNamedComponent(label, def, vctx);        }    }    /**     * Get specific format definition for type. Finds with an exact match     * on the class name, checking the containing definitions if a format     * is not found at this level.     *     * @param type fully qualified class name to be converted     * @return conversion definition for class, or <code>null</code> if not     * found     */    public FormatElement getSpecificFormat(String type) {        ClassHierarchyContext ctx = getFormatContext();        if (ctx == null) {            return null;        } else {            return (FormatElement)ctx.getSpecificComponent(type);        }    }        /**     * Get named format definition. Finds the format with the supplied     * name, checking the containing definitions if the format is not found     * at this level.     *     * @param name conversion name to be found     * @return conversion definition with specified name, or <code>null</code>     * if no conversion with that name     */    public FormatElement getNamedFormat(String name) {        ClassHierarchyContext ctx = getFormatContext();        if (ctx == null) {            return null;        } else {            return (FormatElement)ctx.getNamedComponent(name);        }    }    /**     * Get best format definition for class. Finds the format based on the     * inheritance hierarchy for the supplied class. If a specific format for     * the actual class is not found (either in this or a containing level) this     * returns the most specific superclass format.     *     * @param clas information for target conversion class     * @return conversion definition for class, or <code>null</code> if no     * compatible conversion defined     */    public FormatElement getBestFormat(IClass clas) {        ClassHierarchyContext ctx = getFormatContext();        if (ctx == null) {            return null;        } else {            return (FormatElement)ctx.getMostSpecificComponent(clas);        }    }        /**     * Add mapped name to set defined at this level.     *      * @param name mapped name     * @param def mapping definition     * @param vctx validation context      */    public void addMappedName(NameAttributes name, MappingElement def,        ValidationContext vctx) {        if (m_mappingMap == null) {            m_mappingMap = new HashMap();        }        if (m_mappingMap.containsKey(name)) {            if (vctx.isInBinding()) {                vctx.addError                    ("Duplicate mapping name not allowed for unmarshalling");            }        } else {            m_mappingMap.put(name, def);        }    }    /**     * Add template or mapping to set defined at this level.     *     * @param def template definition element to be added     * @param vctx validation context in use     */    public void addTemplate(TemplateElementBase def, ValidationContext vctx) {        if (m_templateContext == null) {            m_templateContext =                new ClassHierarchyContext(getContainingTemplateContext());        }        if (def.isDefaultTemplate()) {            IClass clas = def.getHandledClass();            m_templateContext.addTypedComponent(clas, def, vctx);        }        if (def instanceof TemplateElement) {            TemplateElement tdef = (TemplateElement)def;            if (tdef.getLabel() != null) {                m_templateContext.addNamedComponent(tdef.getLabel(), def, vctx);            }        } else {            // TODO: Remove for 2.0            MappingElement mdef = (MappingElement)def;            if (mdef.getTypeName() != null) {                m_templateContext.addNamedComponent(mdef.getTypeName(),                    def, vctx);            }        }    }    /**     * Get specific template definition for type. Finds with an exact match     * on the class name, checking the containing definitions if a template     * is not found at this level.     *     * @param type fully qualified class name to be converted     * @return template definition for type, or <code>null</code> if not     * found     */    public TemplateElementBase getSpecificTemplate(String type) {        ClassHierarchyContext ctx = getTemplateContext();        if (ctx == null) {            return null;        } else {            return (TemplateElementBase)ctx.getSpecificComponent(type);        }    }        /**     * Get named template definition. Finds the template with the supplied     * name, checking the containing definitions if the template is not found     * at this level.     * TODO: Make this specific to TemplateElement in 2.0     *     * @param name conversion name to be found     * @return template definition for class, or <code>null</code> if no     * template with that name     */    public TemplateElementBase getNamedTemplate(String name) {        ClassHierarchyContext ctx = getTemplateContext();        if (ctx == null) {            return null;        } else {            return (TemplateElementBase)ctx.getNamedComponent(name);        }    }    /**     * Checks if a class is compatible with one or more templates. This checks     * based on the inheritance hierarchy for the supplied class, looks for the     * class or interface itself as well as any subclasses or implementations.     *     * @param clas information for target class     * @return <code>true</code> if compatible type, <code>false</code> if not     */    public boolean isCompatibleTemplateType(IClass clas) {        ClassHierarchyContext chctx = getTemplateContext();        if (chctx == null) {            return false;        } else {            return chctx.isCompatibleType(clas);        }    }        /**     * Add named structure to set defined in this context. For named structures     * only the definition context associated with the binding element should be     * used. This is a kludge, but will go away in 2.0.     *     * @param def structure definition     * @return problem information, or <code>null</code> if no problem     */    public ValidationProblem addNamedStructure(ContainerElementBase def) {        // create structure if not already done        if (m_namedStructureMap == null) {            m_namedStructureMap = new HashMap();        }        // check for conflict on label before adding to definitions        String label = def.getLabel();        if (m_namedStructureMap.get(label) == null) {            m_namedStructureMap.put(label, def);            return null;        } else {            return new ValidationProblem("Duplicate label \"" + label + '"',                def);        }    }    /**     * Get labeled structure definition within this context. For named     * structures only the definition context associated with the binding     * element should be used. This is a kludge, but will go away in 2.0.     *      * @param label structure definition label     * @return structure definition with specified label, or <code>null</code>     * if not defined     */    public ContainerElementBase getNamedStructure(String label) {        if (m_namedStructureMap == null) {            return null;        } else {            return (ContainerElementBase)m_namedStructureMap.get(label);        }    }        /**     * Get the namespaces defined in this context     *     * @return namespace definitions (may be <code>null</code> if none)     */    public ArrayList getNamespaces() {        return m_namespaces;    }}

⌨️ 快捷键说明

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