definitioncontext.java
来自「JiBX是一个为Java提供的XML数据绑定框架。它可以和现存的类一起运行」· Java 代码 · 共 473 行 · 第 1/2 页
JAVA
473 行
/** * 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 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); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?