001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.xml.internal.rngom.binary;
027:
028: import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
029: import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
030: import org.xml.sax.Locator;
031: import org.xml.sax.SAXException;
032: import org.xml.sax.SAXParseException;
033:
034: public class RefPattern extends Pattern {
035: private Pattern p;
036: private Locator refLoc;
037: private String name;
038: private int checkRecursionDepth = -1;
039: private boolean combineImplicit = false;
040: private byte combineType = COMBINE_NONE;
041: private byte replacementStatus = REPLACEMENT_KEEP;
042: private boolean expanded = false;
043:
044: static final byte REPLACEMENT_KEEP = 0;
045: static final byte REPLACEMENT_REQUIRE = 1;
046: static final byte REPLACEMENT_IGNORE = 2;
047:
048: static final byte COMBINE_NONE = 0;
049: static final byte COMBINE_CHOICE = 1;
050: static final byte COMBINE_INTERLEAVE = 2;
051:
052: RefPattern(String name) {
053: this .name = name;
054: }
055:
056: Pattern getPattern() {
057: return p;
058: }
059:
060: void setPattern(Pattern p) {
061: this .p = p;
062: }
063:
064: Locator getRefLocator() {
065: return refLoc;
066: }
067:
068: void setRefLocator(Locator loc) {
069: this .refLoc = loc;
070: }
071:
072: void checkRecursion(int depth) throws SAXException {
073: if (checkRecursionDepth == -1) {
074: checkRecursionDepth = depth;
075: p.checkRecursion(depth);
076: checkRecursionDepth = -2;
077: } else if (depth == checkRecursionDepth)
078: // XXX try to recover from this?
079: throw new SAXParseException(SchemaBuilderImpl.localizer
080: .message("recursive_reference", name), refLoc);
081: }
082:
083: Pattern expand(SchemaPatternBuilder b) {
084: if (!expanded) {
085: p = p.expand(b);
086: expanded = true;
087: }
088: return p;
089: }
090:
091: boolean samePattern(Pattern other) {
092: return false;
093: }
094:
095: public void accept(PatternVisitor visitor) {
096: p.accept(visitor);
097: }
098:
099: public Object apply(PatternFunction f) {
100: return f.caseRef(this );
101: }
102:
103: byte getReplacementStatus() {
104: return replacementStatus;
105: }
106:
107: void setReplacementStatus(byte replacementStatus) {
108: this .replacementStatus = replacementStatus;
109: }
110:
111: boolean isCombineImplicit() {
112: return combineImplicit;
113: }
114:
115: void setCombineImplicit() {
116: combineImplicit = true;
117: }
118:
119: byte getCombineType() {
120: return combineType;
121: }
122:
123: void setCombineType(byte combineType) {
124: this .combineType = combineType;
125: }
126:
127: String getName() {
128: return name;
129: }
130: }
|