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

📄 definitioncontext.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            }        }        return null;    }    /**     * Get mapping definition for class. Finds the mapping for a fully     * qualified class name, throwing an exception if no mapping is defined.     * This can only be used during the linkage phase.     *     * @param name fully qualified class name     * @return mapping definition for class, or <code>null</code> if not defined     */    public IMapping getClassMapping(String name) {        // check for class mapping defined at this level        IMapping def = getMappingAtLevel(name);        if (def == null && m_context != null) {            // try finding definition at higher level            def = m_context.getClassMapping(name);                    }        return def;    }    /**     * Get nested structure by name. Finds the nested structure with the given     * name, throwing an exception if no component with that name is defined.     *     * @param name component name to be found     * @return component with given name     * @throws JiBXException if name not defined     */    public IComponent getNamedStructure(String name) throws JiBXException {        // check for named component defined at this level        IComponent comp = null;        if (m_namedStructureMap != null) {            comp = (IComponent)m_namedStructureMap.get(name);        }        if (comp == null) {            if (m_context == null) {                throw new JiBXException("Referenced label \"" + name +                    "\" not defined");             } else {                comp = m_context.getNamedStructure(name);            }        }        return comp;    }    /**     * Get mapping definitions at level.     *     * @return mapping definitions, <code>null</code> if none defined at level     */    public ArrayList getMappings() {        return m_mappings;    }    /**     * Get specific conversion definition for type. Finds with an exact match     * on the class name, checking the containing definitions if a conversion     * is not found at this level.     *     * @param name fully qualified class name to be converted     * @return conversion definition for class, or <code>null</code> if not     * found     */    public StringConversion getSpecificConversion(String name) {        StringConversion conv = (StringConversion)m_convertMap.get(name);        if (conv == null && m_context != null) {            conv = m_context.getSpecificConversion(name);        }        return conv;    }    /**     * Get conversion definition for class. Finds the conversion based on a     * fully qualified class name. If a specific conversion for the actual     * class is not found (either in this or a containing level) this returns     * the generic object conversion.     *     * @param clas information for target conversion class     * @return conversion definition for class     */    public StringConversion getConversion(ClassFile clas) {                // use conversions for superclasses only         StringConversion conv = getSpecificConversion(clas.getName());        if (conv == null) {            return BindingDefinition.s_objectConversion;        } else {            return conv;        }    }    /**     * Get named conversion definition. Finds the conversion with the supplied     * name, checking the containing definitions if the conversion is not found     * at this level.     *     * @param name conversion name to be found     * @return conversion definition for class     */    public StringConversion getNamedConversion(QName name) {        StringConversion conv = (StringConversion)m_formatMap.get(name);        if (conv == null && m_context != null) {            conv = m_context.getNamedConversion(name);        }        return conv;    }    /**     * Add named conversion. Checks for duplicate conversions defined within     * a level with the same name.     *     * @param name format name for this conversion     * @param conv conversion definition for class     * @throws JiBXException if duplicate conversion definition     */    public void addConversion(QName name, StringConversion conv)        throws JiBXException {        if (m_formatMap.put(name, conv) != null) {            throw new JiBXException("Duplicate conversion defined with name " +                name);        }    }    /**     * Set specific conversion definition for type. Sets the conversion based     * on a type signature, checking for duplicate conversions defined within     * a level.     *     * @param conv conversion definition for class     * @throws JiBXException if duplicate conversion definition     */    public void setConversion(StringConversion conv)        throws JiBXException {        if (m_convertMap.put(conv.getTypeName(), conv) != null) {            throw new JiBXException("Duplicate conversion defined for type " +                conv.getTypeName());        }    }    /**     * Sets a named conversion definition.     *     * @param name format name for this conversion     * @param conv conversion definition for class     * @throws JiBXException if duplicate conversion definition     */    public void setNamedConversion(QName name, StringConversion conv)        throws JiBXException {        addConversion(name, conv);    }    /**     * Sets a conversion definition by both type and name. Both the type and     * name are checked for duplicate conversions defined within a level.     *     * @param name format name for this conversion     * @param conv conversion definition for class     * @throws JiBXException if duplicate conversion definition     */    public void setDefaultConversion(QName name, StringConversion conv)        throws JiBXException {        addConversion(name, conv);        setConversion(conv);    }        /**     * Check if one or more namespaces are defined in this context.     *     * @return <code>true</code> if namespaces are defined, <code>false</code>     * if not     */    public boolean hasNamespace() {        return m_namespaces != null && m_namespaces.size() > 0;    }        /**     * Get the namespaces defined in this context     *     * @return namespace definitions (may be <code>null</code> if none)     */    public ArrayList getNamespaces() {        return m_namespaces;    }    /**     * Internal method to generate code to fill array with namespace indexes.     * The code generated to this point must have the array reference on the     * stack.     *     * @param nss namespaces to be handled     * @param mb method builder for generated code     */    private void genFillNamespaceIndexes(ArrayList nss, MethodBuilder mb) {        if (nss != null) {            for (int i = 0; i < nss.size(); i++) {                mb.appendDUP();                mb.appendLoadConstant(i);                mb.appendLoadConstant                    (((NamespaceDefinition)nss.get(i)).getIndex());                mb.appendIASTORE();            }        }    }    /**     * Internal method to generate code to fill array with namespace prefixes.     * The code generated to this point must have the array reference on the     * stack.     *     * @param nss namespaces to be handled     * @param mb method builder for generated code     */    private void genFillNamespacePrefixes(ArrayList nss, MethodBuilder mb) {        if (nss != null) {            for (int i = 0; i < nss.size(); i++) {                mb.appendDUP();                mb.appendLoadConstant(i);                String prefix = ((NamespaceDefinition)nss.get(i)).getPrefix();                if (prefix == null) {                    prefix = "";                }                mb.appendLoadConstant(prefix);                mb.appendAASTORE();            }        }    }    /**     * Generate code for loading namespace index and URI arrays. The code     * creates the arrays and leaves the references on the stack.     *     * @param mb method builder for generated code     */    public void genLoadNamespaces(MethodBuilder mb) {                // first create the array of namespace indexes        int count = m_namespaces == null ? 0 : m_namespaces.size();        mb.appendLoadConstant(count);        mb.appendCreateArray("int");        genFillNamespaceIndexes(m_namespaces, mb);                // next create the array of prefixes        mb.appendLoadConstant(count);        mb.appendCreateArray("java.lang.String");        genFillNamespacePrefixes(m_namespaces, mb);    }    /**     * Generate code. Executes code generation for each top-level mapping     * defined in this binding, which in turn propagates the code generation     * all the way down.     *     * @param verbose flag for verbose output     * @param force create marshaller/unmarshaller even for abstract non-base     * mappings flag     * @throws JiBXException if error in transformation     */    public void generateCode(boolean verbose, boolean force)        throws JiBXException {        if (m_mappings != null) {            for (int i = 0; i < m_mappings.size(); i++) {                IMapping mapping = (IMapping)m_mappings.get(i);                if (verbose) {                    System.out.println("Generating code for mapping " +                        mapping.getBoundType());                }                ((IMapping)m_mappings.get(i)).generateCode(force);            }        }    }        /**     * Links extension mappings to their base mappings. This must be done before     * the more general linking step in order to determine which abstract     * mappings are standalone and which are extended by other mappings     *     * @throws JiBXException if error in linking     */    public void linkMappings() throws JiBXException {                // check if any mappings are defined        if (m_mappings != null) {            for (int i = 0; i < m_mappings.size(); i++) {                Object obj = m_mappings.get(i);                if (obj instanceof MappingDefinition) {                    ((MappingDefinition)obj).linkMappings();                }            }        }    }        /**     * Set linkages between binding components. This is called after all the     * basic information has been set up. All linkage to higher level     * components should be done by this method, in order to prevent problems     * due to the order of definitions between components. For the definition     * context this calls the same method on all mappings defined in this     * context.     *     * @throws JiBXException if error in configuration     */    public void setLinkages() throws JiBXException {                // check if any mappings are defined        if (m_mappings != null) {            for (int i = 0; i < m_mappings.size(); i++) {                Object obj = m_mappings.get(i);                if (obj instanceof MappingDefinition) {                    ((MappingDefinition)obj).setLinkages();                }            }        }    }        // DEBUG    public void print(int depth) {        BindingDefinition.indent(depth);        System.out.print("context");        if (m_namespaces != null) {            System.out.print(" (ns#=" + m_namespaces.size() + ')');        }        if (m_mappings != null) {            System.out.print(" (mp#=" + m_mappings.size() + ')');        }        if (m_namedStructureMap != null) {            System.out.print(" (nm#=" + m_namedStructureMap.size() + ')');        }        if (m_convertMap != null) {            System.out.print(" (cv#=" + m_convertMap.size() + ')');        }        if (m_formatMap != null) {            System.out.print(" (fm#=" + m_formatMap.size() + ')');        }        System.out.println();        if (m_namespaces != null) {            for (int i = 0; i < m_namespaces.size(); i++) {                NamespaceDefinition ndef =                    (NamespaceDefinition)m_namespaces.get(i);                ndef.print(depth+1);            }        }        if (m_mappings != null) {            for (int i = 0; i < m_mappings.size(); i++) {                Object obj = m_mappings.get(i);                if (obj instanceof MappingDefinition) {                    MappingDefinition mdef = (MappingDefinition)obj;                    mdef.print(depth+1);                } else if (obj instanceof MappingDirect) {                    MappingDirect mdir = (MappingDirect)obj;                    mdir.print(depth+1);                } else {                    BindingDefinition.indent(depth+1);                    System.out.println("unexpected type " +                        obj.getClass().getName());                }            }        }    }}

⌨️ 快捷键说明

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