xsmodelimpl.java

来自「JAVA 所有包」· Java 代码 · 共 481 行 · 第 1/2 页

JAVA
481
字号
                    break;                case XSConstants.ATTRIBUTE_GROUP:                    tables[i] = fGrammarList[i].fGlobalAttrGrpDecls;                    break;                case XSConstants.MODEL_GROUP_DEFINITION:                    tables[i] = fGrammarList[i].fGlobalGroupDecls;                    break;                case XSConstants.NOTATION_DECLARATION:                    tables[i] = fGrammarList[i].fGlobalNotationDecls;                    break;                }            }            // for complex/simple types, create a special implementation,            // which take specific types out of the hash table            if (objectType == XSTypeDefinition.COMPLEX_TYPE ||                objectType == XSTypeDefinition.SIMPLE_TYPE) {                fGlobalComponents[objectType] = new XSNamedMap4Types(fNamespaces, tables, fGrammarCount, objectType);            }            else {                fGlobalComponents[objectType] = new XSNamedMapImpl(fNamespaces, tables, fGrammarCount);            }        }                return fGlobalComponents[objectType];    }    /**     * Convenience method. Returns a list of top-level component declarations      * that are defined within the specified namespace, i.e. element      * declarations, attribute declarations, etc.      * @param objectType The type of the declaration, i.e.      *   <code>ELEMENT_DECLARATION</code>.     * @param namespace The namespace to which the declaration belongs or      *   <code>null</code> (for components with no target namespace).     * @return  A list of top-level definitions of the specified type in      *   <code>objectType</code> and defined in the specified      *   <code>namespace</code> or an empty <code>XSNamedMap</code>.      */    public synchronized XSNamedMap getComponentsByNamespace(short objectType,                                                            String namespace) {        if (objectType <= 0 || objectType > MAX_COMP_IDX ||            !GLOBAL_COMP[objectType]) {            return XSNamedMapImpl.EMPTY_MAP;        }                // try to find the grammar        int i = 0;        if (namespace != null) {            for (; i < fGrammarCount; ++i) {                if (namespace.equals(fNamespaces[i]))                    break;            }        }        else {            for (; i < fGrammarCount; ++i) {                if (fNamespaces[i] == null)                    break;             }        }        if (i == fGrammarCount)            return XSNamedMapImpl.EMPTY_MAP;                // get the hashtable for this type of components        if (fNSComponents[i][objectType] == null) {            SymbolHash table = null;            switch (objectType) {            case XSConstants.TYPE_DEFINITION:            case XSTypeDefinition.COMPLEX_TYPE:            case XSTypeDefinition.SIMPLE_TYPE:                table = fGrammarList[i].fGlobalTypeDecls;                break;            case XSConstants.ATTRIBUTE_DECLARATION:                table = fGrammarList[i].fGlobalAttrDecls;                break;            case XSConstants.ELEMENT_DECLARATION:                table = fGrammarList[i].fGlobalElemDecls;                break;            case XSConstants.ATTRIBUTE_GROUP:                table = fGrammarList[i].fGlobalAttrGrpDecls;                break;            case XSConstants.MODEL_GROUP_DEFINITION:                table = fGrammarList[i].fGlobalGroupDecls;                break;            case XSConstants.NOTATION_DECLARATION:                table = fGrammarList[i].fGlobalNotationDecls;                break;            }                        // for complex/simple types, create a special implementation,            // which take specific types out of the hash table            if (objectType == XSTypeDefinition.COMPLEX_TYPE ||                objectType == XSTypeDefinition.SIMPLE_TYPE) {                fNSComponents[i][objectType] = new XSNamedMap4Types(namespace, table, objectType);            }            else {                fNSComponents[i][objectType] = new XSNamedMapImpl(namespace, table);            }        }                return fNSComponents[i][objectType];    }    /**     * Convenience method. Returns a top-level simple or complex type     * definition.     * @param name The name of the definition.     * @param namespace The namespace of the definition, otherwise null.     * @return An <code>XSTypeDefinition</code> or null if such definition     *   does not exist.     */    public XSTypeDefinition getTypeDefinition(String name,                                              String namespace) {        SchemaGrammar sg = (SchemaGrammar)fGrammarMap.get(null2EmptyString(namespace));        if (sg == null)            return null;        return (XSTypeDefinition)sg.fGlobalTypeDecls.get(name);    }    /**     * Convenience method. Returns a top-level attribute declaration.     * @param name The name of the declaration.     * @param namespace The namespace of the definition, otherwise null.     * @return A top-level attribute declaration or null if such declaration     *   does not exist.     */    public XSAttributeDeclaration getAttributeDeclaration(String name,                                                   String namespace) {        SchemaGrammar sg = (SchemaGrammar)fGrammarMap.get(null2EmptyString(namespace));        if (sg == null)            return null;        return (XSAttributeDeclaration)sg.fGlobalAttrDecls.get(name);    }    /**     * Convenience method. Returns a top-level element declaration.     * @param name The name of the declaration.     * @param namespace The namespace of the definition, otherwise null.     * @return A top-level element declaration or null if such declaration     *   does not exist.     */    public XSElementDeclaration getElementDeclaration(String name,                                               String namespace) {        SchemaGrammar sg = (SchemaGrammar)fGrammarMap.get(null2EmptyString(namespace));        if (sg == null)            return null;        return (XSElementDeclaration)sg.fGlobalElemDecls.get(name);    }    /**     * Convenience method. Returns a top-level attribute group definition.     * @param name The name of the definition.     * @param namespace The namespace of the definition, otherwise null.     * @return A top-level attribute group definition or null if such     *   definition does not exist.     */    public XSAttributeGroupDefinition getAttributeGroup(String name,                                                        String namespace) {        SchemaGrammar sg = (SchemaGrammar)fGrammarMap.get(null2EmptyString(namespace));        if (sg == null)            return null;        return (XSAttributeGroupDefinition)sg.fGlobalAttrGrpDecls.get(name);    }    /**     * Convenience method. Returns a top-level model group definition.     *     * @param name      The name of the definition.     * @param namespace The namespace of the definition, otherwise null.     * @return A top-level model group definition definition or null if such     *         definition does not exist.     */    public XSModelGroupDefinition getModelGroupDefinition(String name,                                                          String namespace) {        SchemaGrammar sg = (SchemaGrammar)fGrammarMap.get(null2EmptyString(namespace));        if (sg == null)            return null;        return (XSModelGroupDefinition)sg.fGlobalGroupDecls.get(name);    }    /**     * @see com.sun.org.apache.xerces.internal.xs.XSModel#getNotationDeclaration(String, String)     */    public XSNotationDeclaration getNotationDeclaration(String name,                                                 String namespace) {        SchemaGrammar sg = (SchemaGrammar)fGrammarMap.get(null2EmptyString(namespace));        if (sg == null)            return null;        return (XSNotationDeclaration)sg.fGlobalNotationDecls.get(name);    }    /**     *  {annotations} A set of annotations.     */    public synchronized XSObjectList getAnnotations() {        if(fAnnotations != null)             return fAnnotations;        // do this in two passes to avoid inaccurate array size        int totalAnnotations = 0;        for (int i = 0; i < fGrammarCount; i++) {            totalAnnotations += fGrammarList[i].fNumAnnotations;        }        XSAnnotationImpl [] annotations = new XSAnnotationImpl [totalAnnotations];        int currPos = 0;        for (int i = 0; i < fGrammarCount; i++) {            SchemaGrammar currGrammar = fGrammarList[i];            if (currGrammar.fNumAnnotations > 0) {                System.arraycopy(currGrammar.fAnnotations, 0, annotations, currPos, currGrammar.fNumAnnotations);                currPos += currGrammar.fNumAnnotations;            }        }        fAnnotations = new XSObjectListImpl(annotations, annotations.length);        return fAnnotations;    }    private static final String null2EmptyString(String str) {        return str == null ? XMLSymbols.EMPTY_STRING : str;    }        /**     * REVISIT: to expose identity constraints from XSModel.     * For now, we only expose whether there are any IDCs.     * We also need to add these methods to the public     * XSModel interface.     */    public boolean hasIDConstraints() {        return fHasIDC;    }    /**     * REVISIT: to expose substitution group of a given element.     * We need to add this to the XSModel interface.     */    public XSObjectList getSubstitutionGroup(XSElementDeclaration head) {        return (XSObjectList)fSubGroupMap.get(head);    }} // class XSModelImpl

⌨️ 快捷键说明

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