xswildcarddecl.java

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

JAVA
589
字号
        // if the other wildcard is not expressible, the result is still not expressible        if (wildcard == null)            return null;        // For a wildcard's {namespace constraint} value to be the intensional intersection of        // two other such values (call them O1 and O2): the appropriate case among the following        // must be true:        XSWildcardDecl intersectWildcard = new XSWildcardDecl();        intersectWildcard.fProcessContents = processContents;        // 1 If O1 and O2 are the same value, then that value must be the value.        if (areSame(wildcard)) {            intersectWildcard.fType = fType;            intersectWildcard.fNamespaceList = fNamespaceList;        }        // 2 If either O1 or O2 is any, then the other must be the value.        else if ( (fType == NSCONSTRAINT_ANY) || (wildcard.fType == NSCONSTRAINT_ANY) ) {            // both cannot be ANY, if we have reached here.            XSWildcardDecl other = this;            if (fType == NSCONSTRAINT_ANY)                other = wildcard;            intersectWildcard.fType = other.fType;            intersectWildcard.fNamespaceList = other.fNamespaceList;        }        // -3 If either O1 or O2 is a pair of not and a namespace name and the other is a set of        //    (namespace names or absent), then that set, minus the negated namespace name if        //    it was in the set, must be the value.        // +3 If either O1 or O2 is a pair of not and a namespace name and the other        //    is a set of (namespace names or absent), then that set, minus the negated        //    namespace name if it was in the set, then minus absent if it was in the        //    set, must be the value.        // * when we have not(list), the operation is just list-otherlist        else if ( ((fType == NSCONSTRAINT_NOT) && (wildcard.fType == NSCONSTRAINT_LIST)) ||                  ((fType == NSCONSTRAINT_LIST) && (wildcard.fType == NSCONSTRAINT_NOT)) ) {            String[] list = null;            String[] other = null;            if (fType == NSCONSTRAINT_NOT) {                other = fNamespaceList;                list = wildcard.fNamespaceList;            }            else {                other = wildcard.fNamespaceList;                list = fNamespaceList;            }            int listSize = list.length;            String[] intersect = new String[listSize];            int newSize = 0;            for (int i = 0; i < listSize; i++) {                if (list[i] != other[0] && list[i] != ABSENT)                    intersect[newSize++] = list[i];            }            intersectWildcard.fType = NSCONSTRAINT_LIST;            intersectWildcard.fNamespaceList = new String[newSize];            System.arraycopy(intersect, 0, intersectWildcard.fNamespaceList, 0, newSize);        }        // 4 If both O1 and O2 are sets of (namespace names or absent), then the intersection of those        //   sets must be the value.        else if ( (fType == NSCONSTRAINT_LIST) && (wildcard.fType == NSCONSTRAINT_LIST) ) {            intersectWildcard.fType = NSCONSTRAINT_LIST;            intersectWildcard.fNamespaceList = intersect2sets(fNamespaceList, wildcard.fNamespaceList);        }        // -5 If the two are negations of different namespace names, then the intersection is not expressible.        // +5 If the two are negations of namespace names or absent, then The        //    appropriate case among the following must be true:        //    +5.1 If the two are negations of different namespace names, then the        //         intersection is not expressible.        //    +5.2 If one of the two is a pair of not and absent, the other must be        //         the value.        // * when we have not(list), the operation is just not(onelist+otherlist)        else if (fType == NSCONSTRAINT_NOT && wildcard.fType == NSCONSTRAINT_NOT) {            if (fNamespaceList[0] != ABSENT && wildcard.fNamespaceList[0] != ABSENT)                return null;            XSWildcardDecl other = this;            if (fNamespaceList[0] == ABSENT)                other = wildcard;            intersectWildcard.fType = other.fType;            intersectWildcard.fNamespaceList = other.fNamespaceList;        }        return intersectWildcard;    } // performIntersectionWith    private boolean areSame(XSWildcardDecl wildcard) {        if (fType == wildcard.fType) {            // ##any, true            if (fType == NSCONSTRAINT_ANY)                return true;            // ##other, only check the negated value            // * when we support not(list), we need to check in the same way            //   as for NSCONSTRAINT_LIST.            if (fType == NSCONSTRAINT_NOT)                return fNamespaceList[0] == wildcard.fNamespaceList[0];            // ## list, must have the same length,            // and each item in one list must appear in the other one            // (we are assuming that there are no duplicate items in a list)            if (fNamespaceList.length == wildcard.fNamespaceList.length) {                for (int i=0; i<fNamespaceList.length; i++) {                    if (!elementInSet(fNamespaceList[i], wildcard.fNamespaceList))                        return false;                }                return true;            }        }        return false;    } // areSame    String[] intersect2sets(String[] one, String[] theOther){        String[] result = new String[Math.min(one.length,theOther.length)];        // simple implemention,        int count = 0;        for (int i=0; i<one.length; i++) {            if (elementInSet(one[i], theOther))                result[count++] = one[i];        }        String[] result2 = new String[count];        System.arraycopy(result, 0, result2, 0, count);        return result2;    }    String[] union2sets(String[] one, String[] theOther){        String[] result1 = new String[one.length];        // simple implemention,        int count = 0;        for (int i=0; i<one.length; i++) {            if (!elementInSet(one[i], theOther))                result1[count++] = one[i];        }        String[] result2 = new String[count+theOther.length];        System.arraycopy(result1, 0, result2, 0, count);        System.arraycopy(theOther, 0, result2, count, theOther.length);        return result2;    }    boolean subset2sets(String[] subSet, String[] superSet){        for (int i=0; i<subSet.length; i++) {            if (!elementInSet(subSet[i], superSet))                return false;        }        return true;    }    boolean elementInSet(String ele, String[] set){        boolean found = false;        for (int i=0; i<set.length && !found; i++) {            if (ele==set[i])                found = true;        }        return found;    }    /**     * get the string description of this wildcard     */    private String fDescription = null;    public String toString() {        if (fDescription == null) {            StringBuffer buffer = new StringBuffer();            buffer.append("WC[");            switch (fType) {            case NSCONSTRAINT_ANY:                buffer.append(SchemaSymbols.ATTVAL_TWOPOUNDANY);                break;            case NSCONSTRAINT_NOT:                buffer.append(SchemaSymbols.ATTVAL_TWOPOUNDOTHER);                buffer.append(":\"");                if (fNamespaceList[0] != null)                    buffer.append(fNamespaceList[0]);                buffer.append("\"");                break;            case NSCONSTRAINT_LIST:                if (fNamespaceList.length == 0)                    break;                buffer.append("\"");                if (fNamespaceList[0] != null)                    buffer.append(fNamespaceList[0]);                buffer.append("\"");                for (int i = 1; i < fNamespaceList.length; i++) {                    buffer.append(",\"");                    if (fNamespaceList[i] != null)                        buffer.append(fNamespaceList[i]);                    buffer.append("\"");                }                break;            }            buffer.append("]");            fDescription = buffer.toString();        }        return fDescription;    }        /**     * Get the type of the object, i.e ELEMENT_DECLARATION.     */    public short getType() {        return XSConstants.WILDCARD;    }    /**     * The <code>name</code> of this <code>XSObject</code> depending on the     * <code>XSObject</code> type.     */    public String getName() {        return null;    }    /**     * The namespace URI of this node, or <code>null</code> if it is     * unspecified.  defines how a namespace URI is attached to schema     * components.     */    public String getNamespace() {        return null;    }    /**     * Namespace constraint: A constraint type: any, not, list.     */    public short getConstraintType() {        return fType;    }    /**     * Namespace constraint. For <code>constraintType</code>     * LIST_NSCONSTRAINT, the list contains allowed namespaces. For     * <code>constraintType</code> NOT_NSCONSTRAINT, the list contains     * disallowed namespaces.     */    public StringList getNsConstraintList() {        return new StringListImpl(fNamespaceList, fNamespaceList == null ? 0 : fNamespaceList.length);    }    /**     * {process contents} One of skip, lax or strict. Valid constants values     * are: PC_SKIP, PC_LAX, PC_STRICT.     */    public short getProcessContents() {        return fProcessContents;    }    /**     * String valid of {process contents}. One of "skip", "lax" or "strict".     */    public String getProcessContentsAsString() {        switch (fProcessContents) {            case XSWildcardDecl.PC_SKIP: return "skip";            case XSWildcardDecl.PC_LAX: return "lax";            case XSWildcardDecl.PC_STRICT: return "strict";            default: return "invalid value";        }    }    /**     * Optional. Annotation.     */    public XSAnnotation getAnnotation() {        return fAnnotation;    }	/**	 * @see com.sun.org.apache.xerces.internal.xs.XSObject#getNamespaceItem()	 */	public XSNamespaceItem getNamespaceItem() {        // REVISIT: implement		return null;	}} // class XSWildcardDecl

⌨️ 快捷键说明

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