0N/A/*
2362N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A/*
0N/A * Copyright (C) 2004-2011
0N/A *
0N/A * Permission is hereby granted, free of charge, to any person obtaining a copy
0N/A * of this software and associated documentation files (the "Software"), to deal
0N/A * in the Software without restriction, including without limitation the rights
0N/A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0N/A * copies of the Software, and to permit persons to whom the Software is
0N/A * furnished to do so, subject to the following conditions:
0N/A *
0N/A * The above copyright notice and this permission notice shall be included in
0N/A * all copies or substantial portions of the Software.
0N/A *
0N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0N/A * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0N/A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
0N/A * THE SOFTWARE.
0N/A */
0N/Apackage com.sun.xml.internal.rngom.binary;
0N/A
0N/Aimport com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
0N/Aimport com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
0N/Aimport org.xml.sax.Locator;
0N/Aimport org.xml.sax.SAXException;
0N/Aimport org.xml.sax.SAXParseException;
0N/A
0N/Apublic class RefPattern extends Pattern {
0N/A private Pattern p;
0N/A private Locator refLoc;
0N/A private String name;
0N/A private int checkRecursionDepth = -1;
0N/A private boolean combineImplicit = false;
0N/A private byte combineType = COMBINE_NONE;
0N/A private byte replacementStatus = REPLACEMENT_KEEP;
0N/A private boolean expanded = false;
0N/A
0N/A static final byte REPLACEMENT_KEEP = 0;
0N/A static final byte REPLACEMENT_REQUIRE = 1;
0N/A static final byte REPLACEMENT_IGNORE = 2;
0N/A
0N/A static final byte COMBINE_NONE = 0;
0N/A static final byte COMBINE_CHOICE = 1;
0N/A static final byte COMBINE_INTERLEAVE = 2;
0N/A
0N/A RefPattern(String name) {
0N/A this.name = name;
0N/A }
0N/A
0N/A Pattern getPattern() {
0N/A return p;
0N/A }
0N/A
0N/A void setPattern(Pattern p) {
0N/A this.p = p;
0N/A }
0N/A
0N/A Locator getRefLocator() {
0N/A return refLoc;
0N/A }
0N/A
0N/A void setRefLocator(Locator loc) {
0N/A this.refLoc = loc;
0N/A }
0N/A
0N/A @Override
0N/A void checkRecursion(int depth) throws SAXException {
0N/A if (checkRecursionDepth == -1) {
0N/A checkRecursionDepth = depth;
0N/A p.checkRecursion(depth);
0N/A checkRecursionDepth = -2;
0N/A }
0N/A else if (depth == checkRecursionDepth)
0N/A // XXX try to recover from this?
0N/A throw new SAXParseException(SchemaBuilderImpl.localizer.message("recursive_reference", name),
0N/A refLoc);
0N/A }
0N/A
0N/A @Override
0N/A Pattern expand(SchemaPatternBuilder b) {
0N/A if (!expanded) {
0N/A p = p.expand(b);
0N/A expanded = true;
0N/A }
0N/A return p;
0N/A }
0N/A
0N/A boolean samePattern(Pattern other) {
0N/A return false;
0N/A }
0N/A
0N/A public void accept(PatternVisitor visitor) {
0N/A p.accept(visitor);
0N/A }
0N/A
0N/A public Object apply(PatternFunction f) {
0N/A return f.caseRef(this);
0N/A }
0N/A
0N/A byte getReplacementStatus() {
0N/A return replacementStatus;
0N/A }
0N/A
0N/A void setReplacementStatus(byte replacementStatus) {
0N/A this.replacementStatus = replacementStatus;
0N/A }
0N/A
0N/A boolean isCombineImplicit() {
0N/A return combineImplicit;
0N/A }
0N/A
0N/A void setCombineImplicit() {
0N/A combineImplicit = true;
0N/A }
0N/A
0N/A byte getCombineType() {
0N/A return combineType;
0N/A }
0N/A
0N/A void setCombineType(byte combineType) {
0N/A this.combineType = combineType;
0N/A }
0N/A
0N/A String getName() {
0N/A return name;
0N/A }
0N/A}
0N/A