feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
public class AfterPattern extends BinaryPattern {
AfterPattern(Pattern p1, Pattern p2) {
super(false,
combineHashCode(AFTER_HASH_CODE, p1.hashCode(), p2.hashCode()),
p1,
p2);
}
boolean isNotAllowed() {
return p1.isNotAllowed();
}
public Object apply(PatternFunction f) {
return f.caseAfter(this);
}
public void accept(PatternVisitor visitor) {
visitor.visitAfter(p1,p2);
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.nc.ChoiceNameClass;
import com.sun.xml.internal.rngom.nc.NameClass;
class Alphabet {
private NameClass nameClass;
boolean isEmpty() {
return nameClass == null;
}
void addElement(NameClass nc) {
if (nameClass == null)
nameClass = nc;
else if (nc != null)
nameClass = new ChoiceNameClass(nameClass, nc);
}
void addAlphabet(Alphabet a) {
addElement(a.nameClass);
}
void checkOverlap(Alphabet a) throws RestrictionViolationException {
if (nameClass != null
&& a.nameClass != null
&& nameClass.hasOverlapWith(a.nameClass))
throw new RestrictionViolationException("interleave_element_overlap");
}
}

View File

@@ -0,0 +1,144 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
import com.sun.xml.internal.rngom.nc.NameClass;
import com.sun.xml.internal.rngom.nc.SimpleNameClass;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
public final class AttributePattern extends Pattern {
private NameClass nameClass;
private Pattern p;
private Locator loc;
AttributePattern(NameClass nameClass, Pattern value, Locator loc) {
super(false,
EMPTY_CONTENT_TYPE,
combineHashCode(ATTRIBUTE_HASH_CODE,
nameClass.hashCode(),
value.hashCode()));
this.nameClass = nameClass;
this.p = value;
this.loc = loc;
}
Pattern expand(SchemaPatternBuilder b) {
Pattern ep = p.expand(b);
if (ep != p)
return b.makeAttribute(nameClass, ep, loc);
else
return this;
}
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
throws RestrictionViolationException {
switch (context) {
case START_CONTEXT:
throw new RestrictionViolationException("start_contains_attribute");
case ELEMENT_CONTEXT:
if (nameClass.isOpen())
throw new RestrictionViolationException("open_name_class_not_repeated");
break;
case ELEMENT_REPEAT_GROUP_CONTEXT:
throw new RestrictionViolationException("one_or_more_contains_group_contains_attribute");
case ELEMENT_REPEAT_INTERLEAVE_CONTEXT:
throw new RestrictionViolationException("one_or_more_contains_interleave_contains_attribute");
case LIST_CONTEXT:
throw new RestrictionViolationException("list_contains_attribute");
case ATTRIBUTE_CONTEXT:
throw new RestrictionViolationException("attribute_contains_attribute");
case DATA_EXCEPT_CONTEXT:
throw new RestrictionViolationException("data_except_contains_attribute");
}
if (!dad.addAttribute(nameClass)) {
if (nameClass instanceof SimpleNameClass)
throw new RestrictionViolationException("duplicate_attribute_detail", ((SimpleNameClass)nameClass).name);
else
throw new RestrictionViolationException("duplicate_attribute");
}
try {
p.checkRestrictions(ATTRIBUTE_CONTEXT, null, null);
}
catch (RestrictionViolationException e) {
e.maybeSetLocator(loc);
throw e;
}
}
boolean samePattern(Pattern other) {
if (!(other instanceof AttributePattern))
return false;
AttributePattern ap = (AttributePattern)other;
return nameClass.equals(ap.nameClass)&& p == ap.p;
}
void checkRecursion(int depth) throws SAXException {
p.checkRecursion(depth);
}
public void accept(PatternVisitor visitor) {
visitor.visitAttribute(nameClass, p);
}
public Object apply(PatternFunction f) {
return f.caseAttribute(this);
}
public Pattern getContent() {
return p;
}
public NameClass getNameClass() {
return nameClass;
}
public Locator getLocator() {
return loc;
}
}

View File

@@ -0,0 +1,121 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import org.xml.sax.SAXException;
import java.util.Collection;
import java.util.List;
import java.util.ArrayList;
public abstract class BinaryPattern extends Pattern {
protected final Pattern p1;
protected final Pattern p2;
BinaryPattern(boolean nullable, int hc, Pattern p1, Pattern p2) {
super(nullable, Math.max(p1.getContentType(), p2.getContentType()), hc);
this.p1 = p1;
this.p2 = p2;
}
void checkRecursion(int depth) throws SAXException {
p1.checkRecursion(depth);
p2.checkRecursion(depth);
}
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
throws RestrictionViolationException {
p1.checkRestrictions(context, dad, alpha);
p2.checkRestrictions(context, dad, alpha);
}
boolean samePattern(Pattern other) {
if (getClass() != other.getClass())
return false;
BinaryPattern b = (BinaryPattern)other;
return p1 == b.p1 && p2 == b.p2;
}
public final Pattern getOperand1() {
return p1;
}
public final Pattern getOperand2() {
return p2;
}
/**
* Adds all the children of this pattern to the given collection.
*
* <p>
* For example, if this pattern is (A|B|C), it adds A, B, and C
* to the collection, even though internally it's represented
* as (A|(B|C)).
*/
public final void fillChildren( Collection col ) {
fillChildren(getClass(),p1,col);
fillChildren(getClass(),p2,col);
}
/**
* Same as {@link #fillChildren(Collection)} but returns an array.
*/
public final Pattern[] getChildren() {
List lst = new ArrayList();
fillChildren(lst);
return (Pattern[]) lst.toArray(new Pattern[lst.size()]);
}
private void fillChildren( Class c, Pattern p, Collection col ) {
if(p.getClass()==c) {
BinaryPattern bp = (BinaryPattern)p;
bp.fillChildren(c,bp.p1,col);
bp.fillChildren(c,bp.p2,col);
} else {
col.add(p);
}
}
}

View File

@@ -0,0 +1,91 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
public class ChoicePattern extends BinaryPattern {
ChoicePattern(Pattern p1, Pattern p2) {
super(p1.isNullable() || p2.isNullable(),
combineHashCode(CHOICE_HASH_CODE, p1.hashCode(), p2.hashCode()),
p1,
p2);
}
Pattern expand(SchemaPatternBuilder b) {
Pattern ep1 = p1.expand(b);
Pattern ep2 = p2.expand(b);
if (ep1 != p1 || ep2 != p2)
return b.makeChoice(ep1, ep2);
else
return this;
}
boolean containsChoice(Pattern p) {
return p1.containsChoice(p) || p2.containsChoice(p);
}
public void accept(PatternVisitor visitor) {
visitor.visitChoice(p1, p2);
}
public Object apply(PatternFunction f) {
return f.caseChoice(this);
}
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
throws RestrictionViolationException {
if (dad != null)
dad.startChoice();
p1.checkRestrictions(context, dad, alpha);
if (dad != null)
dad.alternative();
p2.checkRestrictions(context, dad, alpha);
if (dad != null)
dad.endChoice();
}
}

View File

@@ -0,0 +1,95 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
import org.relaxng.datatype.Datatype;
import org.xml.sax.Locator;
public class DataExceptPattern extends DataPattern {
private Pattern except;
private Locator loc;
DataExceptPattern(Datatype dt, Pattern except, Locator loc) {
super(dt);
this.except = except;
this.loc = loc;
}
boolean samePattern(Pattern other) {
if (!super.samePattern(other))
return false;
return except.samePattern(((DataExceptPattern)other).except);
}
@Override
public void accept(PatternVisitor visitor) {
visitor.visitDataExcept(getDatatype(), except);
}
@Override
public Object apply(PatternFunction f) {
return f.caseDataExcept(this);
}
@Override
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
throws RestrictionViolationException {
super.checkRestrictions(context, dad, alpha);
try {
except.checkRestrictions(DATA_EXCEPT_CONTEXT, null, null);
}
catch (RestrictionViolationException e) {
e.maybeSetLocator(loc);
throw e;
}
}
Pattern getExcept() {
return except;
}
}

View File

@@ -0,0 +1,91 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
import org.relaxng.datatype.Datatype;
public class DataPattern extends StringPattern {
private Datatype dt;
DataPattern(Datatype dt) {
super(combineHashCode(DATA_HASH_CODE, dt.hashCode()));
this.dt = dt;
}
boolean samePattern(Pattern other) {
if (other.getClass() != this.getClass())
return false;
return dt.equals(((DataPattern)other).dt);
}
public void accept(PatternVisitor visitor) {
visitor.visitData(dt);
}
public Object apply(PatternFunction f) {
return f.caseData(this);
}
Datatype getDatatype() {
return dt;
}
boolean allowsAnyString() {
return false;
// return dt instanceof Datatype2 && ((Datatype2)dt).alwaysValid();
}
@Override
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
throws RestrictionViolationException {
switch (context) {
case START_CONTEXT:
throw new RestrictionViolationException("start_contains_data");
}
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import java.util.ArrayList;
import java.util.List;
import com.sun.xml.internal.rngom.nc.NameClass;
class DuplicateAttributeDetector {
private List nameClasses = new ArrayList();
private Alternative alternatives = null;
private static class Alternative {
private int startIndex;
private int endIndex;
private Alternative parent;
private Alternative(int startIndex, Alternative parent) {
this.startIndex = startIndex;
this.endIndex = startIndex;
this.parent = parent;
}
}
boolean addAttribute(NameClass nc) {
int lim = nameClasses.size();
for (Alternative a = alternatives; a != null; a = a.parent) {
for (int i = a.endIndex; i < lim; i++)
if (nc.hasOverlapWith((NameClass) nameClasses.get(i)))
return false;
lim = a.startIndex;
}
for (int i = 0; i < lim; i++)
if (nc.hasOverlapWith((NameClass) nameClasses.get(i)))
return false;
nameClasses.add(nc);
return true;
}
void startChoice() {
alternatives = new Alternative(nameClasses.size(), alternatives);
}
void alternative() {
alternatives.endIndex = nameClasses.size();
}
void endChoice() {
alternatives = alternatives.parent;
}
}

View File

@@ -0,0 +1,146 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
import com.sun.xml.internal.rngom.nc.NameClass;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
public final class ElementPattern extends Pattern {
private Pattern p;
private NameClass origNameClass;
private NameClass nameClass;
private boolean expanded = false;
private boolean checkedRestrictions = false;
private Locator loc;
ElementPattern(NameClass nameClass, Pattern p, Locator loc) {
super(false,
ELEMENT_CONTENT_TYPE,
combineHashCode(ELEMENT_HASH_CODE,
nameClass.hashCode(),
p.hashCode()));
this.nameClass = nameClass;
this.origNameClass = nameClass;
this.p = p;
this.loc = loc;
}
@Override
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
throws RestrictionViolationException {
if (alpha != null)
alpha.addElement(origNameClass);
if (checkedRestrictions)
return;
switch (context) {
case DATA_EXCEPT_CONTEXT:
throw new RestrictionViolationException("data_except_contains_element");
case LIST_CONTEXT:
throw new RestrictionViolationException("list_contains_element");
case ATTRIBUTE_CONTEXT:
throw new RestrictionViolationException("attribute_contains_element");
}
checkedRestrictions = true;
try {
p.checkRestrictions(ELEMENT_CONTEXT, new DuplicateAttributeDetector(), null);
}
catch (RestrictionViolationException e) {
checkedRestrictions = false;
e.maybeSetLocator(loc);
throw e;
}
}
@Override
Pattern expand(SchemaPatternBuilder b) {
if (!expanded) {
expanded = true;
p = p.expand(b);
if (p.isNotAllowed())
nameClass = NameClass.NULL;
}
return this;
}
boolean samePattern(Pattern other) {
if (!(other instanceof ElementPattern))
return false;
ElementPattern ep = (ElementPattern)other;
return nameClass.equals(ep.nameClass) && p == ep.p;
}
@Override
void checkRecursion(int depth) throws SAXException {
p.checkRecursion(depth + 1);
}
public void accept(PatternVisitor visitor) {
visitor.visitElement(nameClass, p);
}
public Object apply(PatternFunction f) {
return f.caseElement(this);
}
void setContent(Pattern p) {
this.p = p;
}
public Pattern getContent() {
return p;
}
public NameClass getNameClass() {
return nameClass;
}
public Locator getLocator() {
return loc;
}
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
public class EmptyPattern extends Pattern {
EmptyPattern() {
super(true, EMPTY_CONTENT_TYPE, EMPTY_HASH_CODE);
}
boolean samePattern(Pattern other) {
return other instanceof EmptyPattern;
}
public void accept(PatternVisitor visitor) {
visitor.visitEmpty();
}
public Object apply(PatternFunction f) {
return f.caseEmpty(this);
}
@Override
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
throws RestrictionViolationException {
switch (context) {
case DATA_EXCEPT_CONTEXT:
throw new RestrictionViolationException("data_except_contains_empty");
case START_CONTEXT:
throw new RestrictionViolationException("start_contains_empty");
}
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
public class ErrorPattern extends Pattern {
ErrorPattern() {
super(false, EMPTY_CONTENT_TYPE, ERROR_HASH_CODE);
}
boolean samePattern(Pattern other) {
return other instanceof ErrorPattern;
}
public void accept(PatternVisitor visitor) {
visitor.visitError();
}
public Object apply(PatternFunction f) {
return f.caseError(this);
}
}

View File

@@ -0,0 +1,92 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.binary.visitor.*;
public class GroupPattern extends BinaryPattern {
GroupPattern(Pattern p1, Pattern p2) {
super(p1.isNullable() && p2.isNullable(),
combineHashCode(GROUP_HASH_CODE, p1.hashCode(), p2.hashCode()),
p1,
p2);
}
@Override
Pattern expand(SchemaPatternBuilder b) {
Pattern ep1 = p1.expand(b);
Pattern ep2 = p2.expand(b);
if (ep1 != p1 || ep2 != p2)
return b.makeGroup(ep1, ep2);
else
return this;
}
@Override
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha) throws RestrictionViolationException {
switch (context) {
case START_CONTEXT:
throw new RestrictionViolationException("start_contains_group");
case DATA_EXCEPT_CONTEXT:
throw new RestrictionViolationException("data_except_contains_group");
}
super.checkRestrictions(context == ELEMENT_REPEAT_CONTEXT
? ELEMENT_REPEAT_GROUP_CONTEXT
: context,
dad,
alpha);
if (context != LIST_CONTEXT
&& !contentTypeGroupable(p1.getContentType(), p2.getContentType()))
throw new RestrictionViolationException("group_string");
}
public void accept(PatternVisitor visitor) {
visitor.visitGroup(p1, p2);
}
public Object apply(PatternFunction f) {
return f.caseGroup(this);
}
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
public class InterleavePattern extends BinaryPattern {
InterleavePattern(Pattern p1, Pattern p2) {
super(p1.isNullable() && p2.isNullable(),
combineHashCode(INTERLEAVE_HASH_CODE, p1.hashCode(), p2.hashCode()),
p1,
p2);
}
@Override
Pattern expand(SchemaPatternBuilder b) {
Pattern ep1 = p1.expand(b);
Pattern ep2 = p2.expand(b);
if (ep1 != p1 || ep2 != p2)
return b.makeInterleave(ep1, ep2);
else
return this;
}
@Override
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
throws RestrictionViolationException {
switch (context) {
case START_CONTEXT:
throw new RestrictionViolationException("start_contains_interleave");
case DATA_EXCEPT_CONTEXT:
throw new RestrictionViolationException("data_except_contains_interleave");
case LIST_CONTEXT:
throw new RestrictionViolationException("list_contains_interleave");
}
if (context == ELEMENT_REPEAT_CONTEXT)
context = ELEMENT_REPEAT_INTERLEAVE_CONTEXT;
Alphabet a1;
if (alpha != null && alpha.isEmpty())
a1 = alpha;
else
a1 = new Alphabet();
p1.checkRestrictions(context, dad, a1);
if (a1.isEmpty())
p2.checkRestrictions(context, dad, a1);
else {
Alphabet a2 = new Alphabet();
p2.checkRestrictions(context, dad, a2);
a1.checkOverlap(a2);
if (alpha != null) {
if (alpha != a1)
alpha.addAlphabet(a1);
alpha.addAlphabet(a2);
}
}
if (context != LIST_CONTEXT
&& !contentTypeGroupable(p1.getContentType(), p2.getContentType()))
throw new RestrictionViolationException("interleave_string");
if (p1.getContentType() == MIXED_CONTENT_TYPE
&& p2.getContentType() == MIXED_CONTENT_TYPE)
throw new RestrictionViolationException("interleave_text_overlap");
}
public void accept(PatternVisitor visitor) {
visitor.visitInterleave(p1, p2);
}
public Object apply(PatternFunction f) {
return f.caseInterleave(this);
}
}

View File

@@ -0,0 +1,115 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
public class ListPattern extends Pattern {
Pattern p;
Locator locator;
ListPattern(Pattern p, Locator locator) {
super(false,
DATA_CONTENT_TYPE,
combineHashCode(LIST_HASH_CODE, p.hashCode()));
this.p = p;
this.locator = locator;
}
@Override
Pattern expand(SchemaPatternBuilder b) {
Pattern ep = p.expand(b);
if (ep != p)
return b.makeList(ep, locator);
else
return this;
}
@Override
void checkRecursion(int depth) throws SAXException {
p.checkRecursion(depth);
}
boolean samePattern(Pattern other) {
return (other instanceof ListPattern
&& p == ((ListPattern)other).p);
}
public void accept(PatternVisitor visitor) {
visitor.visitList(p);
}
public Object apply(PatternFunction f) {
return f.caseList(this);
}
@Override
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
throws RestrictionViolationException {
switch (context) {
case DATA_EXCEPT_CONTEXT:
throw new RestrictionViolationException("data_except_contains_list");
case START_CONTEXT:
throw new RestrictionViolationException("start_contains_list");
case LIST_CONTEXT:
throw new RestrictionViolationException("list_contains_list");
}
try {
p.checkRestrictions(LIST_CONTEXT, dad, null);
}
catch (RestrictionViolationException e) {
e.maybeSetLocator(locator);
throw e;
}
}
Pattern getOperand() {
return p;
}
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
public class NotAllowedPattern extends Pattern {
NotAllowedPattern() {
super(false, EMPTY_CONTENT_TYPE, NOT_ALLOWED_HASH_CODE);
}
@Override
boolean isNotAllowed() {
return true;
}
boolean samePattern(Pattern other) {
// needs to work for UnexpandedNotAllowedPattern
return other.getClass() == this.getClass();
}
public void accept(PatternVisitor visitor) {
visitor.visitNotAllowed();
}
public Object apply(PatternFunction f) {
return f.caseNotAllowed(this);
}
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
import org.xml.sax.SAXException;
public class OneOrMorePattern extends Pattern {
Pattern p;
OneOrMorePattern(Pattern p) {
super(p.isNullable(),
p.getContentType(),
combineHashCode(ONE_OR_MORE_HASH_CODE, p.hashCode()));
this.p = p;
}
@Override
Pattern expand(SchemaPatternBuilder b) {
Pattern ep = p.expand(b);
if (ep != p)
return b.makeOneOrMore(ep);
else
return this;
}
@Override
void checkRecursion(int depth) throws SAXException {
p.checkRecursion(depth);
}
@Override
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
throws RestrictionViolationException {
switch (context) {
case START_CONTEXT:
throw new RestrictionViolationException("start_contains_one_or_more");
case DATA_EXCEPT_CONTEXT:
throw new RestrictionViolationException("data_except_contains_one_or_more");
}
p.checkRestrictions(context == ELEMENT_CONTEXT
? ELEMENT_REPEAT_CONTEXT
: context,
dad,
alpha);
if (context != LIST_CONTEXT
&& !contentTypeGroupable(p.getContentType(), p.getContentType()))
throw new RestrictionViolationException("one_or_more_string");
}
boolean samePattern(Pattern other) {
return (other instanceof OneOrMorePattern
&& p == ((OneOrMorePattern)other).p);
}
public void accept(PatternVisitor visitor) {
visitor.visitOneOrMore(p);
}
public Object apply(PatternFunction f) {
return f.caseOneOrMore(this);
}
Pattern getOperand() {
return p;
}
}

View File

@@ -0,0 +1,161 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
import org.xml.sax.SAXException;
public abstract class Pattern implements ParsedPattern {
private boolean nullable;
private int hc;
private int contentType;
static final int TEXT_HASH_CODE = 1;
static final int ERROR_HASH_CODE = 3;
static final int EMPTY_HASH_CODE = 5;
static final int NOT_ALLOWED_HASH_CODE = 7;
static final int CHOICE_HASH_CODE = 11;
static final int GROUP_HASH_CODE = 13;
static final int INTERLEAVE_HASH_CODE = 17;
static final int ONE_OR_MORE_HASH_CODE = 19;
static final int ELEMENT_HASH_CODE = 23;
static final int VALUE_HASH_CODE = 27;
static final int ATTRIBUTE_HASH_CODE = 29;
static final int DATA_HASH_CODE = 31;
static final int LIST_HASH_CODE = 37;
static final int AFTER_HASH_CODE = 41;
static int combineHashCode(int hc1, int hc2, int hc3) {
return hc1 * hc2 * hc3;
}
static int combineHashCode(int hc1, int hc2) {
return hc1 * hc2;
}
static final int EMPTY_CONTENT_TYPE = 0;
static final int ELEMENT_CONTENT_TYPE = 1;
static final int MIXED_CONTENT_TYPE = 2;
static final int DATA_CONTENT_TYPE = 3;
Pattern(boolean nullable, int contentType, int hc) {
this.nullable = nullable;
this.contentType = contentType;
this.hc = hc;
}
Pattern() {
this.nullable = false;
this.hc = hashCode();
this.contentType = EMPTY_CONTENT_TYPE;
}
void checkRecursion(int depth) throws SAXException { }
Pattern expand(SchemaPatternBuilder b) {
return this;
}
/**
* Returns true if the pattern is nullable.
*
* <p>
* A pattern is nullable when it can match the empty sequence.
*/
public final boolean isNullable() {
return nullable;
}
boolean isNotAllowed() {
return false;
}
static final int START_CONTEXT = 0;
static final int ELEMENT_CONTEXT = 1;
static final int ELEMENT_REPEAT_CONTEXT = 2;
static final int ELEMENT_REPEAT_GROUP_CONTEXT = 3;
static final int ELEMENT_REPEAT_INTERLEAVE_CONTEXT = 4;
static final int ATTRIBUTE_CONTEXT = 5;
static final int LIST_CONTEXT = 6;
static final int DATA_EXCEPT_CONTEXT = 7;
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
throws RestrictionViolationException {
}
// Know that other is not null
abstract boolean samePattern(Pattern other);
final int patternHashCode() {
return hc;
}
final int getContentType() {
return contentType;
}
boolean containsChoice(Pattern p) {
return this == p;
}
public abstract void accept(PatternVisitor visitor);
public abstract Object apply(PatternFunction f);
// DPattern applyForPattern(PatternFunction f) {
// return (DPattern)apply(f);
// }
static boolean contentTypeGroupable(int ct1, int ct2) {
if (ct1 == EMPTY_CONTENT_TYPE || ct2 == EMPTY_CONTENT_TYPE)
return true;
if (ct1 == DATA_CONTENT_TYPE || ct2 == DATA_CONTENT_TYPE)
return false;
return true;
}
}

View File

@@ -0,0 +1,137 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
public class PatternBuilder {
private final EmptyPattern empty;
protected final NotAllowedPattern notAllowed;
protected final PatternInterner interner;
public PatternBuilder() {
empty = new EmptyPattern();
notAllowed = new NotAllowedPattern();
interner = new PatternInterner();
}
public PatternBuilder(PatternBuilder parent) {
empty = parent.empty;
notAllowed = parent.notAllowed;
interner = new PatternInterner(parent.interner);
}
Pattern makeEmpty() {
return empty;
}
Pattern makeNotAllowed() {
return notAllowed;
}
Pattern makeGroup(Pattern p1, Pattern p2) {
if (p1 == empty)
return p2;
if (p2 == empty)
return p1;
if (p1 == notAllowed || p2 == notAllowed)
return notAllowed;
if (false && p1 instanceof GroupPattern) {
GroupPattern sp = (GroupPattern)p1;
return makeGroup(sp.p1, makeGroup(sp.p2, p2));
}
Pattern p = new GroupPattern(p1, p2);
return interner.intern(p);
}
Pattern makeInterleave(Pattern p1, Pattern p2) {
if (p1 == empty)
return p2;
if (p2 == empty)
return p1;
if (p1 == notAllowed || p2 == notAllowed)
return notAllowed;
if (false && p1 instanceof InterleavePattern) {
InterleavePattern ip = (InterleavePattern)p1;
return makeInterleave(ip.p1, makeInterleave(ip.p2, p2));
}
if (false) {
if (p2 instanceof InterleavePattern) {
InterleavePattern ip = (InterleavePattern)p2;
if (p1.hashCode() > ip.p1.hashCode())
return makeInterleave(ip.p1, makeInterleave(p1, ip.p2));
}
else if (p1.hashCode() > p2.hashCode())
return makeInterleave(p2, p1);
}
Pattern p = new InterleavePattern(p1, p2);
return interner.intern(p);
}
Pattern makeChoice(Pattern p1, Pattern p2) {
if (p1 == empty && p2.isNullable())
return p2;
if (p2 == empty && p1.isNullable())
return p1;
Pattern p = new ChoicePattern(p1, p2);
return interner.intern(p);
}
Pattern makeOneOrMore(Pattern p) {
if (p == empty
|| p == notAllowed
|| p instanceof OneOrMorePattern)
return p;
Pattern p1 = new OneOrMorePattern(p);
return interner.intern(p1);
}
Pattern makeOptional(Pattern p) {
return makeChoice(p, empty);
}
Pattern makeZeroOrMore(Pattern p) {
return makeOptional(makeOneOrMore(p));
}
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
final class PatternInterner {
private static final int INIT_SIZE = 256;
private static final float LOAD_FACTOR = 0.3f;
private Pattern[] table;
private int used;
private int usedLimit;
PatternInterner() {
table = null;
used = 0;
usedLimit = 0;
}
PatternInterner(PatternInterner parent) {
table = parent.table;
if (table != null)
table = (Pattern[]) table.clone();
used = parent.used;
usedLimit = parent.usedLimit;
}
@SuppressWarnings("empty-statement")
Pattern intern(Pattern p) {
int h;
if (table == null) {
table = new Pattern[INIT_SIZE];
usedLimit = (int) (INIT_SIZE * LOAD_FACTOR);
h = firstIndex(p);
} else {
for (h = firstIndex(p); table[h] != null; h = nextIndex(h)) {
if (p.samePattern(table[h]))
return table[h];
}
}
if (used >= usedLimit) {
// rehash
Pattern[] oldTable = table;
table = new Pattern[table.length << 1];
for (int i = oldTable.length; i > 0;) {
--i;
if (oldTable[i] != null) {
int j;
for (j = firstIndex(oldTable[i]);
table[j] != null;
j = nextIndex(j));
table[j] = oldTable[i];
}
}
for (h = firstIndex(p); table[h] != null; h = nextIndex(h));
usedLimit = (int) (table.length * LOAD_FACTOR);
}
used++;
table[h] = p;
return p;
}
private int firstIndex(Pattern p) {
return p.patternHashCode() & (table.length - 1);
}
private int nextIndex(int i) {
return i == 0 ? table.length - 1 : i - 1;
}
}

View File

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

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import javax.xml.namespace.QName;
import org.xml.sax.Locator;
final class RestrictionViolationException extends Exception {
private String messageId;
private Locator loc;
private QName name;
RestrictionViolationException(String messageId) {
this.messageId = messageId;
}
RestrictionViolationException(String messageId, QName name) {
this.messageId = messageId;
this.name = name;
}
String getMessageId() {
return messageId;
}
Locator getLocator() {
return loc;
}
void maybeSetLocator(Locator loc) {
if (this.loc == null)
this.loc = loc;
}
QName getName() {
return name;
}
}

View File

@@ -0,0 +1,792 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2012
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import com.sun.xml.internal.rngom.ast.builder.Annotations;
import com.sun.xml.internal.rngom.ast.builder.BuildException;
import com.sun.xml.internal.rngom.ast.builder.CommentList;
import com.sun.xml.internal.rngom.ast.builder.DataPatternBuilder;
import com.sun.xml.internal.rngom.ast.builder.Div;
import com.sun.xml.internal.rngom.ast.builder.ElementAnnotationBuilder;
import com.sun.xml.internal.rngom.ast.builder.Grammar;
import com.sun.xml.internal.rngom.ast.builder.GrammarSection;
import com.sun.xml.internal.rngom.ast.builder.Include;
import com.sun.xml.internal.rngom.ast.builder.IncludedGrammar;
import com.sun.xml.internal.rngom.ast.builder.NameClassBuilder;
import com.sun.xml.internal.rngom.ast.builder.SchemaBuilder;
import com.sun.xml.internal.rngom.ast.builder.Scope;
import com.sun.xml.internal.rngom.ast.om.Location;
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
import com.sun.xml.internal.rngom.ast.om.ParsedNameClass;
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
import com.sun.xml.internal.rngom.ast.util.LocatorImpl;
import com.sun.xml.internal.rngom.dt.builtin.BuiltinDatatypeLibraryFactory;
import com.sun.xml.internal.rngom.dt.CascadingDatatypeLibraryFactory;
import com.sun.xml.internal.rngom.nc.NameClass;
import com.sun.xml.internal.rngom.nc.NameClassBuilderImpl;
import com.sun.xml.internal.rngom.parse.Context;
import com.sun.xml.internal.rngom.parse.IllegalSchemaException;
import com.sun.xml.internal.rngom.parse.Parseable;
import com.sun.xml.internal.rngom.util.Localizer;
import org.relaxng.datatype.Datatype;
import org.relaxng.datatype.DatatypeBuilder;
import org.relaxng.datatype.DatatypeException;
import org.relaxng.datatype.DatatypeLibrary;
import org.relaxng.datatype.DatatypeLibraryFactory;
import org.relaxng.datatype.ValidationContext;
import org.relaxng.datatype.helpers.DatatypeLibraryLoader;
import org.xml.sax.ErrorHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class SchemaBuilderImpl implements SchemaBuilder, ElementAnnotationBuilder, CommentList {
private final SchemaBuilderImpl parent;
private boolean hadError = false;
private final SchemaPatternBuilder pb;
private final DatatypeLibraryFactory datatypeLibraryFactory;
private final String inheritNs;
private final ErrorHandler eh;
private final OpenIncludes openIncludes;
private final NameClassBuilder ncb = new NameClassBuilderImpl();
static final Localizer localizer = new Localizer(SchemaBuilderImpl.class);
static class OpenIncludes {
final String uri;
final OpenIncludes parent;
OpenIncludes(String uri, OpenIncludes parent) {
this.uri = uri;
this.parent = parent;
}
}
public ParsedPattern expandPattern(ParsedPattern _pattern)
throws BuildException, IllegalSchemaException {
Pattern pattern = (Pattern) _pattern;
if (!hadError) {
try {
pattern.checkRecursion(0);
pattern = pattern.expand(pb);
pattern.checkRestrictions(Pattern.START_CONTEXT, null, null);
if (!hadError) {
return pattern;
}
} catch (SAXParseException e) {
error(e);
} catch (SAXException e) {
throw new BuildException(e);
} catch (RestrictionViolationException e) {
if (e.getName() != null) {
error(e.getMessageId(), e.getName().toString(), e
.getLocator());
} else {
error(e.getMessageId(), e.getLocator());
}
}
}
throw new IllegalSchemaException();
}
/**
*
* @param eh Error handler to receive errors while building the schema.
*/
public SchemaBuilderImpl(ErrorHandler eh) {
this(eh,
new CascadingDatatypeLibraryFactory(new DatatypeLibraryLoader(),
new BuiltinDatatypeLibraryFactory(new DatatypeLibraryLoader())),
new SchemaPatternBuilder());
}
/**
*
* @param eh Error handler to receive errors while building the schema.
* @param datatypeLibraryFactory This is consulted to locate datatype
* libraries.
* @param pb Used to build patterns.
*/
public SchemaBuilderImpl(ErrorHandler eh,
DatatypeLibraryFactory datatypeLibraryFactory,
SchemaPatternBuilder pb) {
this.parent = null;
this.eh = eh;
this.datatypeLibraryFactory = datatypeLibraryFactory;
this.pb = pb;
this.inheritNs = "";
this.openIncludes = null;
}
private SchemaBuilderImpl(String inheritNs,
String uri,
SchemaBuilderImpl parent) {
this.parent = parent;
this.eh = parent.eh;
this.datatypeLibraryFactory = parent.datatypeLibraryFactory;
this.pb = parent.pb;
this.inheritNs = inheritNs;
this.openIncludes = new OpenIncludes(uri, parent.openIncludes);
}
public NameClassBuilder getNameClassBuilder() {
return ncb;
}
public ParsedPattern makeChoice(List patterns, Location loc, Annotations anno)
throws BuildException {
if (patterns.isEmpty()) {
throw new IllegalArgumentException();
}
Pattern result = (Pattern) patterns.get(0);
for (int i = 1; i < patterns.size(); i++) {
result = pb.makeChoice(result, (Pattern) patterns.get(i));
}
return result;
}
public ParsedPattern makeInterleave(List patterns, Location loc, Annotations anno)
throws BuildException {
if (patterns.isEmpty()) {
throw new IllegalArgumentException();
}
Pattern result = (Pattern) patterns.get(0);
for (int i = 1; i < patterns.size(); i++) {
result = pb.makeInterleave(result, (Pattern) patterns.get(i));
}
return result;
}
public ParsedPattern makeGroup(List patterns, Location loc, Annotations anno)
throws BuildException {
if (patterns.isEmpty()) {
throw new IllegalArgumentException();
}
Pattern result = (Pattern) patterns.get(0);
for (int i = 1; i < patterns.size(); i++) {
result = pb.makeGroup(result, (Pattern) patterns.get(i));
}
return result;
}
public ParsedPattern makeOneOrMore(ParsedPattern p, Location loc, Annotations anno)
throws BuildException {
return pb.makeOneOrMore((Pattern) p);
}
public ParsedPattern makeZeroOrMore(ParsedPattern p, Location loc, Annotations anno)
throws BuildException {
return pb.makeZeroOrMore((Pattern) p);
}
public ParsedPattern makeOptional(ParsedPattern p, Location loc, Annotations anno)
throws BuildException {
return pb.makeOptional((Pattern) p);
}
public ParsedPattern makeList(ParsedPattern p, Location loc, Annotations anno)
throws BuildException {
return pb.makeList((Pattern) p, (Locator) loc);
}
public ParsedPattern makeMixed(ParsedPattern p, Location loc, Annotations anno)
throws BuildException {
return pb.makeMixed((Pattern) p);
}
public ParsedPattern makeEmpty(Location loc, Annotations anno) {
return pb.makeEmpty();
}
public ParsedPattern makeNotAllowed(Location loc, Annotations anno) {
return pb.makeUnexpandedNotAllowed();
}
public ParsedPattern makeText(Location loc, Annotations anno) {
return pb.makeText();
}
public ParsedPattern makeErrorPattern() {
return pb.makeError();
}
// public ParsedNameClass makeErrorNameClass() {
// return new ErrorNameClass();
// }
public ParsedPattern makeAttribute(ParsedNameClass nc, ParsedPattern p, Location loc, Annotations anno)
throws BuildException {
return pb.makeAttribute((NameClass) nc, (Pattern) p, (Locator) loc);
}
public ParsedPattern makeElement(ParsedNameClass nc, ParsedPattern p, Location loc, Annotations anno)
throws BuildException {
return pb.makeElement((NameClass) nc, (Pattern) p, (Locator) loc);
}
private class DummyDataPatternBuilder implements DataPatternBuilder {
public void addParam(String name, String value, Context context, String ns, Location loc, Annotations anno)
throws BuildException {
}
public ParsedPattern makePattern(Location loc, Annotations anno)
throws BuildException {
return pb.makeError();
}
public ParsedPattern makePattern(ParsedPattern except, Location loc, Annotations anno)
throws BuildException {
return pb.makeError();
}
public void annotation(ParsedElementAnnotation ea) {
}
}
private static class ValidationContextImpl implements ValidationContext {
private ValidationContext vc;
private String ns;
ValidationContextImpl(ValidationContext vc, String ns) {
this.vc = vc;
this.ns = ns.length() == 0 ? null : ns;
}
public String resolveNamespacePrefix(String prefix) {
return prefix.length() == 0 ? ns : vc.resolveNamespacePrefix(prefix);
}
public String getBaseUri() {
return vc.getBaseUri();
}
public boolean isUnparsedEntity(String entityName) {
return vc.isUnparsedEntity(entityName);
}
public boolean isNotation(String notationName) {
return vc.isNotation(notationName);
}
}
private class DataPatternBuilderImpl implements DataPatternBuilder {
private DatatypeBuilder dtb;
DataPatternBuilderImpl(DatatypeBuilder dtb) {
this.dtb = dtb;
}
public void addParam(String name, String value, Context context, String ns, Location loc, Annotations anno)
throws BuildException {
try {
dtb.addParameter(name, value, new ValidationContextImpl(context, ns));
} catch (DatatypeException e) {
String detail = e.getMessage();
int pos = e.getIndex();
String displayedParam;
if (pos == DatatypeException.UNKNOWN) {
displayedParam = null;
} else {
displayedParam = displayParam(value, pos);
}
if (displayedParam != null) {
if (detail != null) {
error("invalid_param_detail_display", detail, displayedParam, (Locator) loc);
} else {
error("invalid_param_display", displayedParam, (Locator) loc);
}
} else if (detail != null) {
error("invalid_param_detail", detail, (Locator) loc);
} else {
error("invalid_param", (Locator) loc);
}
}
}
String displayParam(String value, int pos) {
if (pos < 0) {
pos = 0;
} else if (pos > value.length()) {
pos = value.length();
}
return localizer.message("display_param", value.substring(0, pos), value.substring(pos));
}
public ParsedPattern makePattern(Location loc, Annotations anno)
throws BuildException {
try {
return pb.makeData(dtb.createDatatype());
} catch (DatatypeException e) {
String detail = e.getMessage();
if (detail != null) {
error("invalid_params_detail", detail, (Locator) loc);
} else {
error("invalid_params", (Locator) loc);
}
return pb.makeError();
}
}
public ParsedPattern makePattern(ParsedPattern except, Location loc, Annotations anno)
throws BuildException {
try {
return pb.makeDataExcept(dtb.createDatatype(), (Pattern) except, (Locator) loc);
} catch (DatatypeException e) {
String detail = e.getMessage();
if (detail != null) {
error("invalid_params_detail", detail, (Locator) loc);
} else {
error("invalid_params", (Locator) loc);
}
return pb.makeError();
}
}
public void annotation(ParsedElementAnnotation ea) {
}
}
public DataPatternBuilder makeDataPatternBuilder(String datatypeLibrary, String type, Location loc)
throws BuildException {
DatatypeLibrary dl = datatypeLibraryFactory.createDatatypeLibrary(datatypeLibrary);
if (dl == null) {
error("unrecognized_datatype_library", datatypeLibrary, (Locator) loc);
} else {
try {
return new DataPatternBuilderImpl(dl.createDatatypeBuilder(type));
} catch (DatatypeException e) {
String detail = e.getMessage();
if (detail != null) {
error("unsupported_datatype_detail", datatypeLibrary, type, detail, (Locator) loc);
} else {
error("unrecognized_datatype", datatypeLibrary, type, (Locator) loc);
}
}
}
return new DummyDataPatternBuilder();
}
public ParsedPattern makeValue(String datatypeLibrary, String type, String value, Context context, String ns,
Location loc, Annotations anno) throws BuildException {
DatatypeLibrary dl = datatypeLibraryFactory.createDatatypeLibrary(datatypeLibrary);
if (dl == null) {
error("unrecognized_datatype_library", datatypeLibrary, (Locator) loc);
} else {
try {
DatatypeBuilder dtb = dl.createDatatypeBuilder(type);
try {
Datatype dt = dtb.createDatatype();
Object obj = dt.createValue(value, new ValidationContextImpl(context, ns));
if (obj != null) {
return pb.makeValue(dt, obj);
}
error("invalid_value", value, (Locator) loc);
} catch (DatatypeException e) {
String detail = e.getMessage();
if (detail != null) {
error("datatype_requires_param_detail", detail, (Locator) loc);
} else {
error("datatype_requires_param", (Locator) loc);
}
}
} catch (DatatypeException e) {
error("unrecognized_datatype", datatypeLibrary, type, (Locator) loc);
}
}
return pb.makeError();
}
static class GrammarImpl implements Grammar, Div, IncludedGrammar {
private final SchemaBuilderImpl sb;
private final Hashtable defines;
private final RefPattern startRef;
private final Scope parent;
private GrammarImpl(SchemaBuilderImpl sb, Scope parent) {
this.sb = sb;
this.parent = parent;
this.defines = new Hashtable();
this.startRef = new RefPattern(null);
}
protected GrammarImpl(SchemaBuilderImpl sb, GrammarImpl g) {
this.sb = sb;
parent = g.parent;
startRef = g.startRef;
defines = g.defines;
}
public ParsedPattern endGrammar(Location loc, Annotations anno) throws BuildException {
for (Enumeration e = defines.keys();
e.hasMoreElements();) {
String name = (String) e.nextElement();
RefPattern rp = (RefPattern) defines.get(name);
if (rp.getPattern() == null) {
sb.error("reference_to_undefined", name, rp.getRefLocator());
rp.setPattern(sb.pb.makeError());
}
}
Pattern start = startRef.getPattern();
if (start == null) {
sb.error("missing_start_element", (Locator) loc);
start = sb.pb.makeError();
}
return start;
}
public void endDiv(Location loc, Annotations anno) throws BuildException {
// nothing to do
}
public ParsedPattern endIncludedGrammar(Location loc, Annotations anno) throws BuildException {
return null;
}
public void define(String name, GrammarSection.Combine combine, ParsedPattern pattern, Location loc, Annotations anno)
throws BuildException {
define(lookup(name), combine, pattern, loc);
}
private void define(RefPattern rp, GrammarSection.Combine combine, ParsedPattern pattern, Location loc)
throws BuildException {
switch (rp.getReplacementStatus()) {
case RefPattern.REPLACEMENT_KEEP:
if (combine == null) {
if (rp.isCombineImplicit()) {
if (rp.getName() == null) {
sb.error("duplicate_start", (Locator) loc);
} else {
sb.error("duplicate_define", rp.getName(), (Locator) loc);
}
} else {
rp.setCombineImplicit();
}
} else {
byte combineType = (combine == COMBINE_CHOICE ? RefPattern.COMBINE_CHOICE : RefPattern.COMBINE_INTERLEAVE);
if (rp.getCombineType() != RefPattern.COMBINE_NONE
&& rp.getCombineType() != combineType) {
if (rp.getName() == null) {
sb.error("conflict_combine_start", (Locator) loc);
} else {
sb.error("conflict_combine_define", rp.getName(), (Locator) loc);
}
}
rp.setCombineType(combineType);
}
Pattern p = (Pattern) pattern;
if (rp.getPattern() == null) {
rp.setPattern(p);
} else if (rp.getCombineType() == RefPattern.COMBINE_INTERLEAVE) {
rp.setPattern(sb.pb.makeInterleave(rp.getPattern(), p));
} else {
rp.setPattern(sb.pb.makeChoice(rp.getPattern(), p));
}
break;
case RefPattern.REPLACEMENT_REQUIRE:
rp.setReplacementStatus(RefPattern.REPLACEMENT_IGNORE);
break;
case RefPattern.REPLACEMENT_IGNORE:
break;
}
}
public void topLevelAnnotation(ParsedElementAnnotation ea) throws BuildException {
}
public void topLevelComment(CommentList comments) throws BuildException {
}
private RefPattern lookup(String name) {
if (name == START) {
return startRef;
}
return lookup1(name);
}
private RefPattern lookup1(String name) {
RefPattern p = (RefPattern) defines.get(name);
if (p == null) {
p = new RefPattern(name);
defines.put(name, p);
}
return p;
}
public ParsedPattern makeRef(String name, Location loc, Annotations anno) throws BuildException {
RefPattern p = lookup1(name);
if (p.getRefLocator() == null && loc != null) {
p.setRefLocator((Locator) loc);
}
return p;
}
public ParsedPattern makeParentRef(String name, Location loc, Annotations anno) throws BuildException {
// TODO: do this check by the caller
if (parent == null) {
sb.error("parent_ref_outside_grammar", (Locator) loc);
return sb.makeErrorPattern();
}
return parent.makeRef(name, loc, anno);
}
public Div makeDiv() {
return this;
}
public Include makeInclude() {
return new IncludeImpl(sb, this);
}
}
static class Override {
Override(RefPattern prp, Override next) {
this.prp = prp;
this.next = next;
}
RefPattern prp;
Override next;
byte replacementStatus;
}
private static class IncludeImpl implements Include, Div {
private SchemaBuilderImpl sb;
private Override overrides;
private GrammarImpl grammar;
private IncludeImpl(SchemaBuilderImpl sb, GrammarImpl grammar) {
this.sb = sb;
this.grammar = grammar;
}
public void define(String name, GrammarSection.Combine combine, ParsedPattern pattern, Location loc, Annotations anno)
throws BuildException {
RefPattern rp = grammar.lookup(name);
overrides = new Override(rp, overrides);
grammar.define(rp, combine, pattern, loc);
}
public void endDiv(Location loc, Annotations anno) throws BuildException {
// nothing to do
}
public void topLevelAnnotation(ParsedElementAnnotation ea) throws BuildException {
// nothing to do
}
public void topLevelComment(CommentList comments) throws BuildException {
}
public Div makeDiv() {
return this;
}
public void endInclude(Parseable current, String uri, String ns,
Location loc, Annotations anno) throws BuildException {
for (OpenIncludes inc = sb.openIncludes;
inc != null;
inc = inc.parent) {
if (inc.uri.equals(uri)) {
sb.error("recursive_include", uri, (Locator) loc);
return;
}
}
for (Override o = overrides; o != null; o = o.next) {
o.replacementStatus = o.prp.getReplacementStatus();
o.prp.setReplacementStatus(RefPattern.REPLACEMENT_REQUIRE);
}
try {
SchemaBuilderImpl isb = new SchemaBuilderImpl(ns, uri, sb);
current.parseInclude(uri, isb, new GrammarImpl(isb, grammar), ns);
for (Override o = overrides; o != null; o = o.next) {
if (o.prp.getReplacementStatus() == RefPattern.REPLACEMENT_REQUIRE) {
if (o.prp.getName() == null) {
sb.error("missing_start_replacement", (Locator) loc);
} else {
sb.error("missing_define_replacement", o.prp.getName(), (Locator) loc);
}
}
}
} catch (IllegalSchemaException e) {
sb.noteError();
} finally {
for (Override o = overrides; o != null; o = o.next) {
o.prp.setReplacementStatus(o.replacementStatus);
}
}
}
public Include makeInclude() {
return null;
}
}
public Grammar makeGrammar(Scope parent) {
return new GrammarImpl(this, parent);
}
public ParsedPattern annotate(ParsedPattern p, Annotations anno) throws BuildException {
return p;
}
public ParsedPattern annotateAfter(ParsedPattern p, ParsedElementAnnotation e) throws BuildException {
return p;
}
public ParsedPattern commentAfter(ParsedPattern p, CommentList comments) throws BuildException {
return p;
}
public ParsedPattern makeExternalRef(Parseable current, String uri, String ns, Scope scope,
Location loc, Annotations anno)
throws BuildException {
for (OpenIncludes inc = openIncludes;
inc != null;
inc = inc.parent) {
if (inc.uri.equals(uri)) {
error("recursive_include", uri, (Locator) loc);
return pb.makeError();
}
}
try {
return current.parseExternal(uri, new SchemaBuilderImpl(ns, uri, this), scope, ns);
} catch (IllegalSchemaException e) {
noteError();
return pb.makeError();
}
}
public Location makeLocation(String systemId, int lineNumber, int columnNumber) {
return new LocatorImpl(systemId, lineNumber, columnNumber);
}
public Annotations makeAnnotations(CommentList comments, Context context) {
return this;
}
public ElementAnnotationBuilder makeElementAnnotationBuilder(String ns, String localName, String prefix,
Location loc, CommentList comments, Context context) {
return this;
}
public CommentList makeCommentList() {
return this;
}
public void addComment(String value, Location loc) throws BuildException {
}
public void addAttribute(String ns, String localName, String prefix, String value, Location loc) {
// nothing needed
}
public void addElement(ParsedElementAnnotation ea) {
// nothing needed
}
public void addComment(CommentList comments) throws BuildException {
// nothing needed
}
public void addLeadingComment(CommentList comments) throws BuildException {
// nothing needed
}
public ParsedElementAnnotation makeElementAnnotation() {
return null;
}
public void addText(String value, Location loc, CommentList comments) throws BuildException {
}
public boolean usesComments() {
return false;
}
private void error(SAXParseException message) throws BuildException {
noteError();
try {
if (eh != null) {
eh.error(message);
}
} catch (SAXException e) {
throw new BuildException(e);
}
}
private void error(String key, Locator loc) throws BuildException {
error(new SAXParseException(localizer.message(key), loc));
}
private void error(String key, String arg, Locator loc) throws BuildException {
error(new SAXParseException(localizer.message(key, arg), loc));
}
private void error(String key, String arg1, String arg2, Locator loc) throws BuildException {
error(new SAXParseException(localizer.message(key, arg1, arg2), loc));
}
private void error(String key, String arg1, String arg2, String arg3, Locator loc) throws BuildException {
error(new SAXParseException(localizer.message(key, new Object[]{arg1, arg2, arg3}), loc));
}
private void noteError() {
if (!hadError && parent != null) {
parent.noteError();
}
hadError = true;
}
}

View File

@@ -0,0 +1,149 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.nc.NameClass;
import org.relaxng.datatype.Datatype;
import org.xml.sax.Locator;
public class SchemaPatternBuilder extends PatternBuilder {
private boolean idTypes;
private final Pattern unexpandedNotAllowed =
new NotAllowedPattern() {
@Override
boolean isNotAllowed() {
return false;
}
@Override
Pattern expand(SchemaPatternBuilder b) {
return b.makeNotAllowed();
}
};
private final TextPattern text = new TextPattern();
private final PatternInterner schemaInterner = new PatternInterner();
public SchemaPatternBuilder() { }
public boolean hasIdTypes() {
return idTypes;
}
Pattern makeElement(NameClass nameClass, Pattern content, Locator loc) {
Pattern p = new ElementPattern(nameClass, content, loc);
return schemaInterner.intern(p);
}
Pattern makeAttribute(NameClass nameClass, Pattern value, Locator loc) {
if (value == notAllowed)
return value;
Pattern p = new AttributePattern(nameClass, value, loc);
return schemaInterner.intern(p);
}
Pattern makeData(Datatype dt) {
noteDatatype(dt);
Pattern p = new DataPattern(dt);
return schemaInterner.intern(p);
}
Pattern makeDataExcept(Datatype dt, Pattern except, Locator loc) {
noteDatatype(dt);
Pattern p = new DataExceptPattern(dt, except, loc);
return schemaInterner.intern(p);
}
Pattern makeValue(Datatype dt, Object obj) {
noteDatatype(dt);
Pattern p = new ValuePattern(dt, obj);
return schemaInterner.intern(p);
}
Pattern makeText() {
return text;
}
@Override
Pattern makeOneOrMore(Pattern p) {
if (p == text)
return p;
return super.makeOneOrMore(p);
}
Pattern makeUnexpandedNotAllowed() {
return unexpandedNotAllowed;
}
Pattern makeError() {
Pattern p = new ErrorPattern();
return schemaInterner.intern(p);
}
@Override
Pattern makeChoice(Pattern p1, Pattern p2) {
if (p1 == notAllowed || p1 == p2)
return p2;
if (p2 == notAllowed)
return p1;
return super.makeChoice(p1, p2);
}
Pattern makeList(Pattern p, Locator loc) {
if (p == notAllowed)
return p;
Pattern p1 = new ListPattern(p, loc);
return schemaInterner.intern(p1);
}
Pattern makeMixed(Pattern p) {
return makeInterleave(text, p);
}
private void noteDatatype(Datatype dt) {
if (dt.getIdType() != Datatype.ID_TYPE_NULL)
idTypes = true;
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
abstract class StringPattern extends Pattern {
StringPattern(int hc) {
super(false, DATA_CONTENT_TYPE, hc);
}
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
public class TextPattern extends Pattern {
TextPattern() {
super(true, MIXED_CONTENT_TYPE, TEXT_HASH_CODE);
}
boolean samePattern(Pattern other) {
return other instanceof TextPattern;
}
public void accept(PatternVisitor visitor) {
visitor.visitText();
}
public Object apply(PatternFunction f) {
return f.caseText(this);
}
@Override
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
throws RestrictionViolationException {
switch (context) {
case DATA_EXCEPT_CONTEXT:
throw new RestrictionViolationException("data_except_contains_text");
case START_CONTEXT:
throw new RestrictionViolationException("start_contains_text");
case LIST_CONTEXT:
throw new RestrictionViolationException("list_contains_text");
}
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary;
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
import org.relaxng.datatype.Datatype;
public class ValuePattern extends StringPattern {
Object obj;
Datatype dt;
ValuePattern(Datatype dt, Object obj) {
super(combineHashCode(VALUE_HASH_CODE, obj.hashCode()));
this.dt = dt;
this.obj = obj;
}
boolean samePattern(Pattern other) {
if (getClass() != other.getClass())
return false;
if (!(other instanceof ValuePattern))
return false;
return (dt.equals(((ValuePattern)other).dt)
&& dt.sameValue(obj, ((ValuePattern)other).obj));
}
public void accept(PatternVisitor visitor) {
visitor.visitValue(dt, obj);
}
public Object apply(PatternFunction f) {
return f.caseValue(this);
}
@Override
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
throws RestrictionViolationException {
switch (context) {
case START_CONTEXT:
throw new RestrictionViolationException("start_contains_value");
}
}
Datatype getDatatype() {
return dt;
}
Object getValue() {
return obj;
}
}

View File

@@ -0,0 +1,118 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary.visitor;
import com.sun.xml.internal.rngom.binary.Pattern;
import com.sun.xml.internal.rngom.nc.NameClass;
import java.util.HashSet;
import java.util.Set;
/**
* Visits a pattern and creates a list of possible child elements.
*
* <p>
* One can use a similar technique to introspect a pattern.
*
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
*/
public class ChildElementFinder extends PatternWalker {
private final Set children = new HashSet();
/**
* Represents a child element.
*/
public static class Element {
public final NameClass nc;
public final Pattern content;
public Element(NameClass nc, Pattern content) {
this.nc = nc;
this.content = content;
}
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Element)) return false;
final Element element = (Element) o;
if (content != null ? !content.equals(element.content) : element.content != null) return false;
if (nc != null ? !nc.equals(element.nc) : element.nc != null) return false;
return true;
}
public int hashCode() {
int result;
result = (nc != null ? nc.hashCode() : 0);
result = 29 * result + (content != null ? content.hashCode() : 0);
return result;
}
}
/**
* Returns a set of {@link Element}.
*/
public Set getChildren() {
return children;
}
public void visitElement(NameClass nc, Pattern content) {
children.add(new Element(nc,content));
}
public void visitAttribute(NameClass ns, Pattern value) {
// there will be no element inside attribute,
// so don't go in there.
}
public void visitList(Pattern p) {
// there will be no element inside a list,
// so don't go in there.
}
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary.visitor;
import com.sun.xml.internal.rngom.binary.AfterPattern;
import com.sun.xml.internal.rngom.binary.AttributePattern;
import com.sun.xml.internal.rngom.binary.ChoicePattern;
import com.sun.xml.internal.rngom.binary.DataExceptPattern;
import com.sun.xml.internal.rngom.binary.DataPattern;
import com.sun.xml.internal.rngom.binary.ElementPattern;
import com.sun.xml.internal.rngom.binary.EmptyPattern;
import com.sun.xml.internal.rngom.binary.ErrorPattern;
import com.sun.xml.internal.rngom.binary.GroupPattern;
import com.sun.xml.internal.rngom.binary.InterleavePattern;
import com.sun.xml.internal.rngom.binary.ListPattern;
import com.sun.xml.internal.rngom.binary.NotAllowedPattern;
import com.sun.xml.internal.rngom.binary.OneOrMorePattern;
import com.sun.xml.internal.rngom.binary.RefPattern;
import com.sun.xml.internal.rngom.binary.TextPattern;
import com.sun.xml.internal.rngom.binary.ValuePattern;
public interface PatternFunction {
Object caseEmpty(EmptyPattern p);
Object caseNotAllowed(NotAllowedPattern p);
Object caseError(ErrorPattern p);
Object caseGroup(GroupPattern p);
Object caseInterleave(InterleavePattern p);
Object caseChoice(ChoicePattern p);
Object caseOneOrMore(OneOrMorePattern p);
Object caseElement(ElementPattern p);
Object caseAttribute(AttributePattern p);
Object caseData(DataPattern p);
Object caseDataExcept(DataExceptPattern p);
Object caseValue(ValuePattern p);
Object caseText(TextPattern p);
Object caseList(ListPattern p);
Object caseRef(RefPattern p);
Object caseAfter(AfterPattern p);
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary.visitor;
import com.sun.xml.internal.rngom.binary.Pattern;
import com.sun.xml.internal.rngom.nc.NameClass;
import org.relaxng.datatype.Datatype;
public interface PatternVisitor {
void visitEmpty();
void visitNotAllowed();
void visitError();
void visitAfter(Pattern p1, Pattern p2);
void visitGroup(Pattern p1, Pattern p2);
void visitInterleave(Pattern p1, Pattern p2);
void visitChoice(Pattern p1, Pattern p2);
void visitOneOrMore(Pattern p);
void visitElement(NameClass nc, Pattern content);
void visitAttribute(NameClass ns, Pattern value);
void visitData(Datatype dt);
void visitDataExcept(Datatype dt, Pattern except);
void visitValue(Datatype dt, Object obj);
void visitText();
void visitList(Pattern p);
}

View File

@@ -0,0 +1,115 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Copyright (C) 2004-2011
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sun.xml.internal.rngom.binary.visitor;
import com.sun.xml.internal.rngom.binary.Pattern;
import com.sun.xml.internal.rngom.nc.NameClass;
import org.relaxng.datatype.Datatype;
/**
* Walks the pattern tree.
*
* @author
* Kohsuke Kawaguchi (kk@kohsuke.org)
*/
public class PatternWalker implements PatternVisitor {
public void visitEmpty() {
}
public void visitNotAllowed() {
}
public void visitError() {
}
public void visitGroup(Pattern p1, Pattern p2) {
visitBinary(p1, p2);
}
protected void visitBinary(Pattern p1, Pattern p2) {
p1.accept(this);
p2.accept(this);
}
public void visitInterleave(Pattern p1, Pattern p2) {
visitBinary(p1, p2);
}
public void visitChoice(Pattern p1, Pattern p2) {
visitBinary(p1, p2);
}
public void visitOneOrMore(Pattern p) {
p.accept(this);
}
public void visitElement(NameClass nc, Pattern content) {
content.accept(this);
}
public void visitAttribute(NameClass ns, Pattern value) {
value.accept(this);
}
public void visitData(Datatype dt) {
}
public void visitDataExcept(Datatype dt, Pattern except) {
}
public void visitValue(Datatype dt, Object obj) {
}
public void visitText() {
}
public void visitList(Pattern p) {
p.accept(this);
}
public void visitAfter(Pattern p1, Pattern p2) {
}
}