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,187 @@
/*
* Copyright (c) 1997, 2011, 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.
*/
package com.sun.xml.internal.xsom.impl.scd;
import com.sun.xml.internal.xsom.XSAnnotation;
import com.sun.xml.internal.xsom.XSAttGroupDecl;
import com.sun.xml.internal.xsom.XSAttributeDecl;
import com.sun.xml.internal.xsom.XSAttributeUse;
import com.sun.xml.internal.xsom.XSComplexType;
import com.sun.xml.internal.xsom.XSComponent;
import com.sun.xml.internal.xsom.XSContentType;
import com.sun.xml.internal.xsom.XSElementDecl;
import com.sun.xml.internal.xsom.XSFacet;
import com.sun.xml.internal.xsom.XSIdentityConstraint;
import com.sun.xml.internal.xsom.XSModelGroup;
import com.sun.xml.internal.xsom.XSModelGroupDecl;
import com.sun.xml.internal.xsom.XSNotation;
import com.sun.xml.internal.xsom.XSParticle;
import com.sun.xml.internal.xsom.XSSchema;
import com.sun.xml.internal.xsom.XSSimpleType;
import com.sun.xml.internal.xsom.XSWildcard;
import com.sun.xml.internal.xsom.XSXPath;
import com.sun.xml.internal.xsom.visitor.XSFunction;
import java.util.Iterator;
/**
* Partial default implementation of {@link Axis}.
*
* <p>
* {@link XSParticle}s are skipped in SCD, so this class compensates that.
* For example, when we are considering a path from {@link XSComplexType},
* we need to also consider a path from its content type particle (if any.)
*
* @author Kohsuke Kawaguchi
*/
abstract class AbstractAxisImpl<T extends XSComponent> implements Axis<T>, XSFunction<Iterator<T>> {
/**
* Creates a singleton list.
*/
protected final Iterator<T> singleton(T t) {
return Iterators.singleton(t);
}
protected final Iterator<T> union(T... items) {
return new Iterators.Array<T>(items);
}
protected final Iterator<T> union(Iterator<? extends T> first, Iterator<? extends T> second) {
return new Iterators.Union<T>(first,second);
}
public Iterator<T> iterator(XSComponent contextNode) {
return contextNode.apply(this);
}
/**
* Gets the prefix of the axis, like "foo::".
*/
public String getName() {
return toString();
}
/**
* Default implementation that simply delegate sto {@link #iterator(XSComponent)}
*/
public Iterator<T> iterator(Iterator<? extends XSComponent> contextNodes) {
return new Iterators.Map<T,XSComponent>(contextNodes) {
protected Iterator<? extends T> apply(XSComponent u) {
return iterator(u);
}
};
}
public boolean isModelGroup() {
return false;
}
public Iterator<T> annotation(XSAnnotation ann) {
return empty();
}
public Iterator<T> attGroupDecl(XSAttGroupDecl decl) {
return empty();
}
public Iterator<T> attributeDecl(XSAttributeDecl decl) {
return empty();
}
public Iterator<T> attributeUse(XSAttributeUse use) {
return empty();
}
public Iterator<T> complexType(XSComplexType type) {
// compensate particle
XSParticle p = type.getContentType().asParticle();
if(p!=null)
return particle(p);
else
return empty();
}
public Iterator<T> schema(XSSchema schema) {
return empty();
}
public Iterator<T> facet(XSFacet facet) {
return empty();
}
public Iterator<T> notation(XSNotation notation) {
return empty();
}
public Iterator<T> identityConstraint(XSIdentityConstraint decl) {
return empty();
}
public Iterator<T> xpath(XSXPath xpath) {
return empty();
}
public Iterator<T> simpleType(XSSimpleType simpleType) {
return empty();
}
public Iterator<T> particle(XSParticle particle) {
return empty();
}
public Iterator<T> empty(XSContentType empty) {
return empty();
}
public Iterator<T> wildcard(XSWildcard wc) {
return empty();
}
public Iterator<T> modelGroupDecl(XSModelGroupDecl decl) {
return empty();
}
public Iterator<T> modelGroup(XSModelGroup group) {
// compensate for particles that are ignored in SCD
return new Iterators.Map<T,XSParticle>(group.iterator()) {
protected Iterator<? extends T> apply(XSParticle p) {
return particle(p);
}
};
}
public Iterator<T> elementDecl(XSElementDecl decl) {
return empty();
}
/**
* Returns an empty list.
*/
protected final Iterator<T> empty() {
return Iterators.empty();
}
}

View File

@@ -0,0 +1,579 @@
/*
* Copyright (c) 1997, 2011, 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.
*/
package com.sun.xml.internal.xsom.impl.scd;
import com.sun.xml.internal.xsom.XSAttContainer;
import com.sun.xml.internal.xsom.XSAttGroupDecl;
import com.sun.xml.internal.xsom.XSAttributeDecl;
import com.sun.xml.internal.xsom.XSAttributeUse;
import com.sun.xml.internal.xsom.XSComplexType;
import com.sun.xml.internal.xsom.XSComponent;
import com.sun.xml.internal.xsom.XSElementDecl;
import com.sun.xml.internal.xsom.XSFacet;
import com.sun.xml.internal.xsom.XSIdentityConstraint;
import com.sun.xml.internal.xsom.XSListSimpleType;
import com.sun.xml.internal.xsom.XSModelGroup;
import com.sun.xml.internal.xsom.XSModelGroup.Compositor;
import com.sun.xml.internal.xsom.XSModelGroupDecl;
import com.sun.xml.internal.xsom.XSNotation;
import com.sun.xml.internal.xsom.XSParticle;
import com.sun.xml.internal.xsom.XSRestrictionSimpleType;
import com.sun.xml.internal.xsom.XSSchema;
import com.sun.xml.internal.xsom.XSSimpleType;
import com.sun.xml.internal.xsom.XSType;
import com.sun.xml.internal.xsom.XSUnionSimpleType;
import com.sun.xml.internal.xsom.XSWildcard;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* Axis of traversal.
*
* @param <T>
* The kind of components that this axis may return.
*
* @author Kohsuke Kawaguchi
*/
public interface Axis<T extends XSComponent> {
Iterator<T> iterator(XSComponent contextNode);
Iterator<T> iterator(Iterator<? extends XSComponent> contextNodes);
/**
* Returns true if this is one of the model group axis.
*/
boolean isModelGroup();
/**
* Pseudo-axis that selects all the {@link XSSchema}s in the current set.
* Used to implement the absolute path expression
*/
public static final Axis<XSSchema> ROOT = new Axis<XSSchema>() {
public Iterator<XSSchema> iterator(XSComponent contextNode) {
return contextNode.getRoot().iterateSchema();
}
public Iterator<XSSchema> iterator(Iterator<? extends XSComponent> contextNodes) {
if(!contextNodes.hasNext())
return Iterators.empty();
else
// this assumes that all current nodes belong to the same owner.
return iterator(contextNodes.next());
}
public boolean isModelGroup() {
return false;
}
public String toString() {
return "root::";
}
};
/**
* Pseudo-axis that visits all skipped intermediate steps.
* Those are:
* <ol>
* <li>complex type reachable from element
* <li>model groups
* <li>combination of above.
* </ol>
*/
public static final Axis<XSComponent> INTERMEDIATE_SKIP = new AbstractAxisImpl<XSComponent>() {
public Iterator<XSComponent> elementDecl(XSElementDecl decl) {
XSComplexType ct = decl.getType().asComplexType();
if(ct==null)
return empty();
else {
// also pick up model groups inside this complex type
return new Iterators.Union<XSComponent>(singleton(ct),complexType(ct));
}
}
public Iterator<XSComponent> modelGroupDecl(XSModelGroupDecl decl) {
return descendants(decl.getModelGroup());
}
public Iterator<XSComponent> particle(XSParticle particle) {
return descendants(particle.getTerm().asModelGroup());
}
/**
* Iterate all descendant model groups of the given model group, including itself.
*/
private Iterator<XSComponent> descendants(XSModelGroup mg) {
// TODO: write a tree iterator
// for now, we do it eagerly because I'm lazy
List<XSComponent> r = new ArrayList<XSComponent>();
visit(mg,r);
return r.iterator();
}
private void visit(XSModelGroup mg, List<XSComponent> r) {
// since model groups never form a cycle, no cycle check is needed
r.add(mg);
for (XSParticle p : mg) {
XSModelGroup child = p.getTerm().asModelGroup();
if(child!=null)
visit(child,r);
}
}
public String toString() {
return "(intermediateSkip)";
}
};
/**
* All descendants reachable via default axes. Used to implement the "//" semantics.
*
* So far the default axes together are guaranteed not to cause any cycle, so
* no cycle check is needed (if it's needed, the life would be much harder!)
*/
public static final Axis<XSComponent> DESCENDANTS = new Axis<XSComponent>() {
public Iterator<XSComponent> iterator(XSComponent contextNode) {
return new Visitor().iterator(contextNode);
}
public Iterator<XSComponent> iterator(Iterator<? extends XSComponent> contextNodes) {
return new Visitor().iterator(contextNodes);
}
public boolean isModelGroup() {
return false;
}
/**
* Stateful visitor that remembers what's already traversed, to reduce the search space.
*/
final class Visitor extends AbstractAxisImpl<XSComponent> {
private final Set<XSComponent> visited = new HashSet<XSComponent>();
/**
* Recursively apply the {@link Axis#DESCENDANTS} axis.
*/
final class Recursion extends Iterators.Map<XSComponent,XSComponent> {
public Recursion(Iterator<? extends XSComponent> core) {
super(core);
}
protected Iterator<XSComponent> apply(XSComponent u) {
return DESCENDANTS.iterator(u);
}
}
public Iterator<XSComponent> schema(XSSchema schema) {
if(visited.add(schema))
return ret( schema, new Recursion(schema.iterateElementDecls()));
else
return empty();
}
public Iterator<XSComponent> elementDecl(XSElementDecl decl) {
if(visited.add(decl))
return ret(decl, iterator(decl.getType()) );
else
return empty();
}
public Iterator<XSComponent> simpleType(XSSimpleType type) {
if(visited.add(type))
return ret(type, FACET.iterator(type));
else
return empty();
}
public Iterator<XSComponent> complexType(XSComplexType type) {
if(visited.add(type))
return ret(type, iterator(type.getContentType()));
else
return empty();
}
public Iterator<XSComponent> particle(XSParticle particle) {
if(visited.add(particle))
return ret(particle, iterator(particle.getTerm()));
else
return empty();
}
public Iterator<XSComponent> modelGroupDecl(XSModelGroupDecl decl) {
if(visited.add(decl))
return ret(decl, iterator(decl.getModelGroup()));
else
return empty();
}
public Iterator<XSComponent> modelGroup(XSModelGroup group) {
if(visited.add(group))
return ret(group, new Recursion(group.iterator()));
else
return empty();
}
public Iterator<XSComponent> attGroupDecl(XSAttGroupDecl decl) {
if(visited.add(decl))
return ret(decl, new Recursion(decl.iterateAttributeUses()));
else
return empty();
}
public Iterator<XSComponent> attributeUse(XSAttributeUse use) {
if(visited.add(use))
return ret(use, iterator(use.getDecl()));
else
return empty();
}
public Iterator<XSComponent> attributeDecl(XSAttributeDecl decl) {
if(visited.add(decl))
return ret(decl, iterator(decl.getType()));
else
return empty();
}
private Iterator<XSComponent> ret( XSComponent one, Iterator<? extends XSComponent> rest ) {
return union(singleton(one),rest);
}
}
public String toString() {
return "/";
}
};
public static final Axis<XSSchema> X_SCHEMA = new Axis<XSSchema>() {
public Iterator<XSSchema> iterator(XSComponent contextNode) {
return Iterators.singleton(contextNode.getOwnerSchema());
}
public Iterator<XSSchema> iterator(Iterator<? extends XSComponent> contextNodes) {
return new Iterators.Adapter<XSSchema,XSComponent>(contextNodes) {
protected XSSchema filter(XSComponent u) {
return u.getOwnerSchema();
}
};
}
public boolean isModelGroup() {
return false;
}
public String toString() {
return "x-schema::";
}
};
public static final Axis<XSElementDecl> SUBSTITUTION_GROUP = new AbstractAxisImpl<XSElementDecl>() {
public Iterator<XSElementDecl> elementDecl(XSElementDecl decl) {
return singleton(decl.getSubstAffiliation());
}
public String toString() {
return "substitutionGroup::";
}
};
public static final Axis<XSAttributeDecl> ATTRIBUTE = new AbstractAxisImpl<XSAttributeDecl>() {
public Iterator<XSAttributeDecl> complexType(XSComplexType type) {
return attributeHolder(type);
}
public Iterator<XSAttributeDecl> attGroupDecl(XSAttGroupDecl decl) {
return attributeHolder(decl);
}
private Iterator<XSAttributeDecl> attributeHolder(final XSAttContainer atts) {
// TODO: check spec. is this correct?
return new Iterators.Adapter<XSAttributeDecl,XSAttributeUse>(atts.iterateAttributeUses()) {
protected XSAttributeDecl filter(XSAttributeUse u) {
return u.getDecl();
}
};
}
public Iterator<XSAttributeDecl> schema(XSSchema schema) {
return schema.iterateAttributeDecls();
}
public String toString() {
return "@";
}
};
public static final Axis<XSElementDecl> ELEMENT = new AbstractAxisImpl<XSElementDecl>() {
public Iterator<XSElementDecl> particle(XSParticle particle) {
return singleton(particle.getTerm().asElementDecl());
}
public Iterator<XSElementDecl> schema(XSSchema schema) {
return schema.iterateElementDecls();
}
public Iterator<XSElementDecl> modelGroupDecl(XSModelGroupDecl decl) {
return modelGroup(decl.getModelGroup());
}
//public Iterator<XSElementDecl> modelGroup(XSModelGroup group) {
// return new Iterators.Map<XSElementDecl,XSParticle>(group.iterator()) {
// protected Iterator<XSElementDecl> apply(XSParticle p) {
// return particle(p);
// }
// };
//}
@Override
public String getName() {
return "";
}
public String toString() {
return "element::";
}
};
public static final Axis<XSType> TYPE_DEFINITION = new AbstractAxisImpl<XSType>() {
public Iterator<XSType> schema(XSSchema schema) {
return schema.iterateTypes();
}
public Iterator<XSType> attributeDecl(XSAttributeDecl decl) {
return singleton(decl.getType());
}
public Iterator<XSType> elementDecl(XSElementDecl decl) {
return singleton(decl.getType());
}
public String toString() {
return "~";
}
};
public static final Axis<XSType> BASETYPE = new AbstractAxisImpl<XSType>() {
public Iterator<XSType> simpleType(XSSimpleType type) {
return singleton(type.getBaseType());
}
public Iterator<XSType> complexType(XSComplexType type) {
return singleton(type.getBaseType());
}
public String toString() {
return "baseType::";
}
};
public static final Axis<XSSimpleType> PRIMITIVE_TYPE = new AbstractAxisImpl<XSSimpleType>() {
public Iterator<XSSimpleType> simpleType(XSSimpleType type) {
return singleton(type.getPrimitiveType());
}
public String toString() {
return "primitiveType::";
}
};
public static final Axis<XSSimpleType> ITEM_TYPE = new AbstractAxisImpl<XSSimpleType>() {
public Iterator<XSSimpleType> simpleType(XSSimpleType type) {
XSListSimpleType baseList = type.getBaseListType();
if(baseList==null) return empty();
return singleton(baseList.getItemType());
}
public String toString() {
return "itemType::";
}
};
public static final Axis<XSSimpleType> MEMBER_TYPE = new AbstractAxisImpl<XSSimpleType>() {
public Iterator<XSSimpleType> simpleType(XSSimpleType type) {
XSUnionSimpleType baseUnion = type.getBaseUnionType();
if(baseUnion ==null) return empty();
return baseUnion.iterator();
}
public String toString() {
return "memberType::";
}
};
public static final Axis<XSComponent> SCOPE = new AbstractAxisImpl<XSComponent>() {
public Iterator<XSComponent> complexType(XSComplexType type) {
return singleton(type.getScope());
}
// TODO: attribute declaration has a scope, too.
// TODO: element declaration has a scope
public String toString() {
return "scope::";
}
};
public static final Axis<XSAttGroupDecl> ATTRIBUTE_GROUP = new AbstractAxisImpl<XSAttGroupDecl>() {
public Iterator<XSAttGroupDecl> schema(XSSchema schema) {
return schema.iterateAttGroupDecls();
}
public String toString() {
return "attributeGroup::";
}
};
public static final Axis<XSModelGroupDecl> MODEL_GROUP_DECL = new AbstractAxisImpl<XSModelGroupDecl>() {
public Iterator<XSModelGroupDecl> schema(XSSchema schema) {
return schema.iterateModelGroupDecls();
}
public Iterator<XSModelGroupDecl> particle(XSParticle particle) {
return singleton(particle.getTerm().asModelGroupDecl());
}
public String toString() {
return "group::";
}
};
public static final Axis<XSIdentityConstraint> IDENTITY_CONSTRAINT = new AbstractAxisImpl<XSIdentityConstraint>() {
public Iterator<XSIdentityConstraint> elementDecl(XSElementDecl decl) {
return decl.getIdentityConstraints().iterator();
}
public Iterator<XSIdentityConstraint> schema(XSSchema schema) {
// TODO: iterate all elements in this schema (local or global!) and its identity constraints
return super.schema(schema);
}
public String toString() {
return "identityConstraint::";
}
};
public static final Axis<XSIdentityConstraint> REFERENCED_KEY = new AbstractAxisImpl<XSIdentityConstraint>() {
public Iterator<XSIdentityConstraint> identityConstraint(XSIdentityConstraint decl) {
return singleton(decl.getReferencedKey());
}
public String toString() {
return "key::";
}
};
public static final Axis<XSNotation> NOTATION = new AbstractAxisImpl<XSNotation>() {
public Iterator<XSNotation> schema(XSSchema schema) {
return schema.iterateNotations();
}
public String toString() {
return "notation::";
}
};
public static final Axis<XSWildcard> WILDCARD = new AbstractAxisImpl<XSWildcard>() {
public Iterator<XSWildcard> particle(XSParticle particle) {
return singleton(particle.getTerm().asWildcard());
}
public String toString() {
return "any::";
}
};
public static final Axis<XSWildcard> ATTRIBUTE_WILDCARD = new AbstractAxisImpl<XSWildcard>() {
public Iterator<XSWildcard> complexType(XSComplexType type) {
return singleton(type.getAttributeWildcard());
}
public Iterator<XSWildcard> attGroupDecl(XSAttGroupDecl decl) {
return singleton(decl.getAttributeWildcard());
}
public String toString() {
return "anyAttribute::";
}
};
public static final Axis<XSFacet> FACET = new AbstractAxisImpl<XSFacet>() {
public Iterator<XSFacet> simpleType(XSSimpleType type) {
// TODO: it's not clear if "facets" mean all inherited facets or just declared facets
XSRestrictionSimpleType r = type.asRestriction();
if(r!=null)
return r.iterateDeclaredFacets();
else
return empty();
}
public String toString() {
return "facet::";
}
};
public static final Axis<XSModelGroup> MODELGROUP_ALL = new ModelGroupAxis(Compositor.ALL);
public static final Axis<XSModelGroup> MODELGROUP_CHOICE = new ModelGroupAxis(Compositor.CHOICE);
public static final Axis<XSModelGroup> MODELGROUP_SEQUENCE = new ModelGroupAxis(Compositor.SEQUENCE);
public static final Axis<XSModelGroup> MODELGROUP_ANY = new ModelGroupAxis(null);
static final class ModelGroupAxis extends AbstractAxisImpl<XSModelGroup> {
private final XSModelGroup.Compositor compositor;
ModelGroupAxis(Compositor compositor) {
this.compositor = compositor;
}
@Override
public boolean isModelGroup() {
return true;
}
public Iterator<XSModelGroup> particle(XSParticle particle) {
return filter(particle.getTerm().asModelGroup());
}
public Iterator<XSModelGroup> modelGroupDecl(XSModelGroupDecl decl) {
return filter(decl.getModelGroup());
}
private Iterator<XSModelGroup> filter(XSModelGroup mg) {
if(mg==null)
return empty();
if(mg.getCompositor() == compositor || compositor == null)
return singleton(mg);
else
return empty();
}
public String toString() {
if(compositor==null)
return "model::*";
else
return "model::"+compositor;
}
}
}

View File

@@ -0,0 +1,215 @@
/*
* Copyright (c) 1997, 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.
*/
package com.sun.xml.internal.xsom.impl.scd;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;
/**
* Various convenient {@link Iterator} implementations.
* @author Kohsuke Kawaguchi
*/
public class Iterators {
static abstract class ReadOnly<T> implements Iterator<T> {
public final void remove() {
throw new UnsupportedOperationException();
}
}
// we need to run on JDK 1.4
private static final Iterator EMPTY = Collections.EMPTY_LIST.iterator();
public static <T> Iterator<T> empty() {
return EMPTY;
}
public static <T> Iterator<T> singleton(T value) {
return new Singleton<T>(value);
}
/**
* {@link Iterator} that returns a single (or no) value.
*/
static final class Singleton<T> extends ReadOnly<T> {
private T next;
Singleton(T next) {
this.next = next;
}
public boolean hasNext() {
return next!=null;
}
public T next() {
T r = next;
next = null;
return r;
}
}
/**
* {@link Iterator} that wraps another {@link Iterator} and changes its type.
*/
public static abstract class Adapter<T,U> extends ReadOnly<T> {
private final Iterator<? extends U> core;
public Adapter(Iterator<? extends U> core) {
this.core = core;
}
public boolean hasNext() {
return core.hasNext();
}
public T next() {
return filter(core.next());
}
protected abstract T filter(U u);
}
/**
* For each U, apply U->Iterator&lt;T> function and then iterate all
* the resulting T.
*/
public static abstract class Map<T,U> extends ReadOnly<T> {
private final Iterator<? extends U> core;
private Iterator<? extends T> current;
protected Map(Iterator<? extends U> core) {
this.core = core;
}
public boolean hasNext() {
while(current==null || !current.hasNext()) {
if(!core.hasNext())
return false; // nothing more to enumerate
current = apply(core.next());
}
return true;
}
public T next() {
return current.next();
}
protected abstract Iterator<? extends T> apply(U u);
}
/**
* Filter out objects from another iterator.
*/
public static abstract class Filter<T> extends ReadOnly<T> {
private final Iterator<? extends T> core;
private T next;
protected Filter(Iterator<? extends T> core) {
this.core = core;
}
/**
* Return true to retain the value.
*/
protected abstract boolean matches(T value);
public boolean hasNext() {
while(core.hasNext() && next==null) {
next = core.next();
if(!matches(next))
next = null;
}
return next!=null;
}
public T next() {
if(next==null) throw new NoSuchElementException();
T r = next;
next = null;
return r;
}
}
/**
* Only return unique items.
*/
static final class Unique<T> extends Filter<T> {
private Set<T> values = new HashSet<T>();
public Unique(Iterator<? extends T> core) {
super(core);
}
protected boolean matches(T value) {
return values.add(value);
}
}
/**
* Union of two iterators.
*/
public static final class Union<T> extends ReadOnly<T> {
private final Iterator<? extends T> first,second;
public Union(Iterator<? extends T> first, Iterator<? extends T> second) {
this.first = first;
this.second = second;
}
public boolean hasNext() {
return first.hasNext() || second.hasNext();
}
public T next() {
if(first.hasNext()) return first.next();
else return second.next();
}
}
/**
* Array iterator.
*/
public static final class Array<T> extends ReadOnly<T> {
private final T[] items;
private int index=0;
public Array(T[] items) {
this.items = items;
}
public boolean hasNext() {
return index<items.length;
}
public T next() {
return items[index++];
}
}
}

View File

@@ -0,0 +1,219 @@
/*
* Copyright (c) 1997, 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.
*/
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */
package com.sun.xml.internal.xsom.impl.scd;
import java.util.List;
/**
* This exception is thrown when parse errors are encountered.
* You can explicitly create objects of this exception type by
* calling the method generateParseException in the generated
* parser.
*
* You can modify this class to customize your error reporting
* mechanisms so long as you retain the public fields.
*/
public class ParseException extends Exception {
/**
* This constructor is used by the method "generateParseException"
* in the generated parser. Calling this constructor generates
* a new object of this type with the fields "currentToken",
* "expectedTokenSequences", and "tokenImage" set. The boolean
* flag "specialConstructor" is also set to true to indicate that
* this constructor was used to create this object.
* This constructor calls its super class with the empty string
* to force the "toString" method of parent class "Throwable" to
* print the error message in the form:
* ParseException: <result of getMessage>
*/
public ParseException(Token currentTokenVal,
int[][] expectedTokenSequencesVal,
List<String> tokenImageVal
)
{
super("");
specialConstructor = true;
currentToken = currentTokenVal;
expectedTokenSequences = expectedTokenSequencesVal;
tokenImage = tokenImageVal;
}
/**
* The following constructors are for use by you for whatever
* purpose you can think of. Constructing the exception in this
* manner makes the exception behave in the normal way - i.e., as
* documented in the class "Throwable". The fields "errorToken",
* "expectedTokenSequences", and "tokenImage" do not contain
* relevant information. The JavaCC generated code does not use
* these constructors.
*/
public ParseException() {
super();
specialConstructor = false;
}
public ParseException(String message) {
super(message);
specialConstructor = false;
}
/**
* This variable determines which constructor was used to create
* this object and thereby affects the semantics of the
* "getMessage" method (see below).
*/
protected boolean specialConstructor;
/**
* This is the last token that has been consumed successfully. If
* this object has been created due to a parse error, the token
* followng this token will (therefore) be the first error token.
*/
public Token currentToken;
/**
* Each entry in this array is an array of integers. Each array
* of integers represents a sequence of tokens (by their ordinal
* values) that is expected at this point of the parse.
*/
public int[][] expectedTokenSequences;
/**
* This is a reference to the "tokenImage" array of the generated
* parser within which the parse error occurred. This array is
* defined in the generated ...Constants interface.
*/
public List<String> tokenImage;
/**
* This method has the standard behavior when this object has been
* created using the standard constructors. Otherwise, it uses
* "currentToken" and "expectedTokenSequences" to generate a parse
* error message and returns it. If this object has been created
* due to a parse error, and you do not catch it (it gets thrown
* from the parser), then this method is called during the printing
* of the final stack trace, and hence the correct error message
* gets displayed.
*/
public String getMessage() {
if (!specialConstructor) {
return super.getMessage();
}
StringBuffer expected = new StringBuffer();
int maxSize = 0;
for (int i = 0; i < expectedTokenSequences.length; i++) {
if (maxSize < expectedTokenSequences[i].length) {
maxSize = expectedTokenSequences[i].length;
}
for (int j = 0; j < expectedTokenSequences[i].length; j++) {
expected.append(tokenImage.get(expectedTokenSequences[i][j])).append(" ");
}
if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
expected.append("...");
}
expected.append(eol).append(" ");
}
String retval = "Encountered \"";
Token tok = currentToken.next;
for (int i = 0; i < maxSize; i++) {
if (i != 0) retval += " ";
if (tok.kind == 0) {
retval += tokenImage.get(0);
break;
}
retval += add_escapes(tok.image);
tok = tok.next;
}
retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
retval += "." + eol;
if (expectedTokenSequences.length == 1) {
retval += "Was expecting:" + eol + " ";
} else {
retval += "Was expecting one of:" + eol + " ";
}
retval += expected.toString();
return retval;
}
/**
* The end of line string for this machine.
*/
protected String eol = System.getProperty("line.separator", "\n");
/**
* Used to convert raw characters to their escaped version
* when these raw version cannot be used as part of an ASCII
* string literal.
*/
protected String add_escapes(String str) {
StringBuffer retval = new StringBuffer();
char ch;
for (int i = 0; i < str.length(); i++) {
switch (str.charAt(i))
{
case 0 :
continue;
case '\b':
retval.append("\\b");
continue;
case '\t':
retval.append("\\t");
continue;
case '\n':
retval.append("\\n");
continue;
case '\f':
retval.append("\\f");
continue;
case '\r':
retval.append("\\r");
continue;
case '\"':
retval.append("\\\"");
continue;
case '\'':
retval.append("\\\'");
continue;
case '\\':
retval.append("\\\\");
continue;
default:
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
String s = "0000" + Integer.toString(ch, 16);
retval.append("\\u" + s.substring(s.length() - 4, s.length()));
} else {
retval.append(ch);
}
continue;
}
}
return retval.toString();
}
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 1997, 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.
*/
package com.sun.xml.internal.xsom.impl.scd;
import com.sun.xml.internal.xsom.SCD;
import com.sun.xml.internal.xsom.XSComponent;
import java.util.Iterator;
/**
* Schema component designator.
*
* @author Kohsuke Kawaguchi
*/
public final class SCDImpl extends SCD {
/**
* SCD is fundamentally a list of steps.
*/
private final Step[] steps;
/**
* The original textual SCD representation.
*/
private final String text;
public SCDImpl(String text, Step[] steps) {
this.text = text;
this.steps = steps;
}
public Iterator<XSComponent> select(Iterator<? extends XSComponent> contextNode) {
Iterator<XSComponent> nodeSet = (Iterator)contextNode;
int len = steps.length;
for( int i=0; i<len; i++ ) {
if(i!=0 && i!=len-1 && !steps[i-1].axis.isModelGroup() && steps[i].axis.isModelGroup()) {
// expand the current nodeset by adding abbreviatable complex type and model groups.
// note that such expansion is not allowed to occure in in between model group axes.
// TODO: this step is not needed if the next step is known not to react to
// complex type nor model groups, such as, say Axis.FACET
nodeSet = new Iterators.Unique<XSComponent>(
new Iterators.Map<XSComponent,XSComponent>(nodeSet) {
protected Iterator<XSComponent> apply(XSComponent u) {
return new Iterators.Union<XSComponent>(
Iterators.singleton(u),
Axis.INTERMEDIATE_SKIP.iterator(u) );
}
}
);
}
nodeSet = steps[i].evaluate(nodeSet);
}
return nodeSet;
}
public String toString() {
return text;
}
}

View File

@@ -0,0 +1,562 @@
/*
* Copyright (c) 1997, 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.
*/
/* Generated By:JavaCC: Do not edit this line. SCDParser.java */
package com.sun.xml.internal.xsom.impl.scd;
import java.util.*;
import java.io.*;
import com.sun.xml.internal.xsom.impl.UName;
import javax.xml.namespace.*;
public class SCDParser implements SCDParserConstants {
private NamespaceContext nsc;
public SCDParser(String text,NamespaceContext nsc) {
this(new StringReader(text));
this.nsc = nsc;
}
private String trim(String s) {
return s.substring(1,s.length()-1);
}
private String resolvePrefix(String prefix) throws ParseException {
try {
String r=nsc.getNamespaceURI(prefix);
// grrr!!
if(prefix.equals(""))
return r;
if(!r.equals(""))
return r;
} catch( IllegalArgumentException e ) {
; // report an error
}
throw new ParseException("Unbound prefix: "+prefix);
}
// "[^:]+"
final public UName QName() throws ParseException {
Token p,l=null;
p = jj_consume_token(NCNAME);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case 15:
jj_consume_token(15);
l = jj_consume_token(NCNAME);
break;
default:
jj_la1[0] = jj_gen;
;
}
if(l==null)
{if (true) return new UName(resolvePrefix(""),p.image);}
else
{if (true) return new UName(resolvePrefix(p.image),l.image);}
throw new Error("Missing return statement in function");
}
final public String Prefix() throws ParseException {
Token p;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case NCNAME:
p = jj_consume_token(NCNAME);
{if (true) return resolvePrefix(p.image);}
break;
default:
jj_la1[1] = jj_gen;
{if (true) return resolvePrefix("");}
}
throw new Error("Missing return statement in function");
}
final public List RelativeSchemaComponentPath() throws ParseException {
List steps = new ArrayList();
Step s;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case 16:
case 17:
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case 16:
jj_consume_token(16);
steps.add(new Step.Any(Axis.ROOT));
break;
case 17:
jj_consume_token(17);
steps.add(new Step.Any(Axis.DESCENDANTS));
break;
default:
jj_la1[2] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
default:
jj_la1[3] = jj_gen;
;
}
s = Step();
steps.add(s);
label_1:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case 16:
case 17:
;
break;
default:
jj_la1[4] = jj_gen;
break label_1;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case 16:
jj_consume_token(16);
break;
case 17:
jj_consume_token(17);
steps.add(new Step.Any(Axis.DESCENDANTS));
break;
default:
jj_la1[5] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
s = Step();
steps.add(s);
}
{if (true) return steps;}
throw new Error("Missing return statement in function");
}
final public Step Step() throws ParseException {
Step s; String p; Token n;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case 18:
case 19:
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case 18:
jj_consume_token(18);
break;
case 19:
jj_consume_token(19);
break;
default:
jj_la1[6] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
s = NameOrWildcard(Axis.ATTRIBUTE);
break;
case NCNAME:
case 20:
case 45:
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case 20:
jj_consume_token(20);
break;
default:
jj_la1[7] = jj_gen;
;
}
s = NameOrWildcard(Axis.ELEMENT);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case NUMBER:
Predicate(s);
break;
default:
jj_la1[8] = jj_gen;
;
}
break;
case 21:
jj_consume_token(21);
s = NameOrWildcard(Axis.SUBSTITUTION_GROUP);
break;
case 22:
case 23:
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case 22:
jj_consume_token(22);
break;
case 23:
jj_consume_token(23);
break;
default:
jj_la1[9] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
s = NameOrWildcardOrAnonymous(Axis.TYPE_DEFINITION);
break;
case 24:
jj_consume_token(24);
s = NameOrWildcard(Axis.BASETYPE);
break;
case 25:
jj_consume_token(25);
s = NameOrWildcard(Axis.PRIMITIVE_TYPE);
break;
case 26:
jj_consume_token(26);
s = NameOrWildcardOrAnonymous(Axis.ITEM_TYPE);
break;
case 27:
jj_consume_token(27);
s = NameOrWildcardOrAnonymous(Axis.MEMBER_TYPE);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case NUMBER:
Predicate(s);
break;
default:
jj_la1[10] = jj_gen;
;
}
break;
case 28:
jj_consume_token(28);
s = NameOrWildcardOrAnonymous(Axis.SCOPE);
break;
case 29:
jj_consume_token(29);
s = NameOrWildcard(Axis.ATTRIBUTE_GROUP);
break;
case 30:
jj_consume_token(30);
s = NameOrWildcard(Axis.MODEL_GROUP_DECL);
break;
case 31:
jj_consume_token(31);
s = NameOrWildcard(Axis.IDENTITY_CONSTRAINT);
break;
case 32:
jj_consume_token(32);
s = NameOrWildcard(Axis.REFERENCED_KEY);
break;
case 33:
jj_consume_token(33);
s = NameOrWildcard(Axis.NOTATION);
break;
case 34:
jj_consume_token(34);
s=new Step.Any(Axis.MODELGROUP_SEQUENCE);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case NUMBER:
Predicate(s);
break;
default:
jj_la1[11] = jj_gen;
;
}
break;
case 35:
jj_consume_token(35);
s=new Step.Any(Axis.MODELGROUP_CHOICE);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case NUMBER:
Predicate(s);
break;
default:
jj_la1[12] = jj_gen;
;
}
break;
case 36:
jj_consume_token(36);
s=new Step.Any(Axis.MODELGROUP_ALL);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case NUMBER:
Predicate(s);
break;
default:
jj_la1[13] = jj_gen;
;
}
break;
case 37:
jj_consume_token(37);
s=new Step.Any(Axis.MODELGROUP_ANY);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case NUMBER:
Predicate(s);
break;
default:
jj_la1[14] = jj_gen;
;
}
break;
case 38:
jj_consume_token(38);
s=new Step.Any(Axis.WILDCARD);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case NUMBER:
Predicate(s);
break;
default:
jj_la1[15] = jj_gen;
;
}
break;
case 39:
jj_consume_token(39);
s=new Step.Any(Axis.ATTRIBUTE_WILDCARD);
break;
case 40:
jj_consume_token(40);
s=new Step.Any(Axis.FACET);
break;
case 41:
jj_consume_token(41);
n = jj_consume_token(FACETNAME);
s=new Step.Facet(Axis.FACET,n.image);
break;
case 42:
jj_consume_token(42);
s=new Step.Any(Axis.DESCENDANTS);
break;
case 43:
jj_consume_token(43);
p = Prefix();
s=new Step.Schema(Axis.X_SCHEMA,p);
break;
case 44:
jj_consume_token(44);
s=new Step.Any(Axis.X_SCHEMA);
break;
default:
jj_la1[16] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return s;}
throw new Error("Missing return statement in function");
}
final public Step NameOrWildcard(Axis a) throws ParseException {
UName un;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case NCNAME:
un = QName();
{if (true) return new Step.Named(a,un);}
break;
case 45:
jj_consume_token(45);
{if (true) return new Step.Any(a);}
break;
default:
jj_la1[17] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public Step NameOrWildcardOrAnonymous(Axis a) throws ParseException {
UName un;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case NCNAME:
un = QName();
{if (true) return new Step.Named(a,un);}
break;
case 45:
jj_consume_token(45);
{if (true) return new Step.Any(a);}
break;
case 46:
jj_consume_token(46);
{if (true) return new Step.AnonymousType(a);}
break;
default:
jj_la1[18] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public int Predicate(Step s) throws ParseException {
Token t;
t = jj_consume_token(NUMBER);
{if (true) return s.predicate=Integer.parseInt(trim(t.image));}
throw new Error("Missing return statement in function");
}
public SCDParserTokenManager token_source;
SimpleCharStream jj_input_stream;
public Token token, jj_nt;
private int jj_ntk;
private int jj_gen;
final private int[] jj_la1 = new int[19];
static private int[] jj_la1_0;
static private int[] jj_la1_1;
static {
jj_la1_0();
jj_la1_1();
}
private static void jj_la1_0() {
jj_la1_0 = new int[] {0x8000,0x1000,0x30000,0x30000,0x30000,0x30000,0xc0000,0x100000,0x2000,0xc00000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0xfffc1000,0x1000,0x1000,};
}
private static void jj_la1_1() {
jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3fff,0x2000,0x6000,};
}
public SCDParser(java.io.InputStream stream) {
this(stream, null);
}
public SCDParser(java.io.InputStream stream, String encoding) {
try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
token_source = new SCDParserTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 19; i++) jj_la1[i] = -1;
}
public void ReInit(java.io.InputStream stream) {
ReInit(stream, null);
}
public void ReInit(java.io.InputStream stream, String encoding) {
try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
token_source.ReInit(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 19; i++) jj_la1[i] = -1;
}
public SCDParser(java.io.Reader stream) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
token_source = new SCDParserTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 19; i++) jj_la1[i] = -1;
}
public void ReInit(java.io.Reader stream) {
jj_input_stream.ReInit(stream, 1, 1);
token_source.ReInit(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 19; i++) jj_la1[i] = -1;
}
public SCDParser(SCDParserTokenManager tm) {
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 19; i++) jj_la1[i] = -1;
}
public void ReInit(SCDParserTokenManager tm) {
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 19; i++) jj_la1[i] = -1;
}
final private Token jj_consume_token(int kind) throws ParseException {
Token oldToken;
if ((oldToken = token).next != null) token = token.next;
else token = token.next = token_source.getNextToken();
jj_ntk = -1;
if (token.kind == kind) {
jj_gen++;
return token;
}
token = oldToken;
jj_kind = kind;
throw generateParseException();
}
final public Token getNextToken() {
if (token.next != null) token = token.next;
else token = token.next = token_source.getNextToken();
jj_ntk = -1;
jj_gen++;
return token;
}
final public Token getToken(int index) {
Token t = token;
for (int i = 0; i < index; i++) {
if (t.next != null) t = t.next;
else t = t.next = token_source.getNextToken();
}
return t;
}
final private int jj_ntk() {
if ((jj_nt=token.next) == null)
return (jj_ntk = (token.next=token_source.getNextToken()).kind);
else
return (jj_ntk = jj_nt.kind);
}
private java.util.Vector jj_expentries = new java.util.Vector();
private int[] jj_expentry;
private int jj_kind = -1;
public ParseException generateParseException() {
jj_expentries.removeAllElements();
boolean[] la1tokens = new boolean[47];
for (int i = 0; i < 47; i++) {
la1tokens[i] = false;
}
if (jj_kind >= 0) {
la1tokens[jj_kind] = true;
jj_kind = -1;
}
for (int i = 0; i < 19; i++) {
if (jj_la1[i] == jj_gen) {
for (int j = 0; j < 32; j++) {
if ((jj_la1_0[i] & (1<<j)) != 0) {
la1tokens[j] = true;
}
if ((jj_la1_1[i] & (1<<j)) != 0) {
la1tokens[32+j] = true;
}
}
}
}
for (int i = 0; i < 47; i++) {
if (la1tokens[i]) {
jj_expentry = new int[1];
jj_expentry[0] = i;
jj_expentries.addElement(jj_expentry);
}
}
int[][] exptokseq = new int[jj_expentries.size()][];
for (int i = 0; i < jj_expentries.size(); i++) {
exptokseq[i] = (int[])jj_expentries.elementAt(i);
}
return new ParseException(token, exptokseq, tokenImage);
}
final public void enable_tracing() {
}
final public void disable_tracing() {
}
}

View File

@@ -0,0 +1,98 @@
/*
* Copyright (c) 1997, 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.
*/
/* Generated By:JavaCC: Do not edit this line. SCDParserConstants.java */
package com.sun.xml.internal.xsom.impl.scd;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public interface SCDParserConstants {
int EOF = 0;
int Letter = 6;
int BaseChar = 7;
int Ideographic = 8;
int CombiningChar = 9;
int UnicodeDigit = 10;
int Extender = 11;
int NCNAME = 12;
int NUMBER = 13;
int FACETNAME = 14;
int DEFAULT = 0;
static final List<String> tokenImage = Collections.unmodifiableList(Arrays.asList(
new String[] {
"<EOF>",
"\" \"",
"\"\\t\"",
"\"\\n\"",
"\"\\r\"",
"\"\\f\"",
"<Letter>",
"<BaseChar>",
"<Ideographic>",
"<CombiningChar>",
"<UnicodeDigit>",
"<Extender>",
"<NCNAME>",
"<NUMBER>",
"<FACETNAME>",
"\":\"",
"\"/\"",
"\"//\"",
"\"attribute::\"",
"\"@\"",
"\"element::\"",
"\"substitutionGroup::\"",
"\"type::\"",
"\"~\"",
"\"baseType::\"",
"\"primitiveType::\"",
"\"itemType::\"",
"\"memberType::\"",
"\"scope::\"",
"\"attributeGroup::\"",
"\"group::\"",
"\"identityContraint::\"",
"\"key::\"",
"\"notation::\"",
"\"model::sequence\"",
"\"model::choice\"",
"\"model::all\"",
"\"model::*\"",
"\"any::*\"",
"\"anyAttribute::*\"",
"\"facet::*\"",
"\"facet::\"",
"\"component::*\"",
"\"x-schema::\"",
"\"x-schema::*\"",
"\"*\"",
"\"0\"",
}));
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,464 @@
/*
* Copyright (c) 1997, 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.
*/
/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 4.0 */
package com.sun.xml.internal.xsom.impl.scd;
/**
* An implementation of interface CharStream, where the stream is assumed to
* contain only ASCII characters (without unicode processing).
*/
public class SimpleCharStream
{
public static final boolean staticFlag = false;
int bufsize;
int available;
int tokenBegin;
public int bufpos = -1;
protected int bufline[];
protected int bufcolumn[];
protected int column = 0;
protected int line = 1;
protected boolean prevCharIsCR = false;
protected boolean prevCharIsLF = false;
protected java.io.Reader inputStream;
protected char[] buffer;
protected int maxNextCharInd = 0;
protected int inBuf = 0;
protected int tabSize = 8;
protected void setTabSize(int i) { tabSize = i; }
protected int getTabSize(int i) { return tabSize; }
protected void ExpandBuff(boolean wrapAround)
{
char[] newbuffer = new char[bufsize + 2048];
int newbufline[] = new int[bufsize + 2048];
int newbufcolumn[] = new int[bufsize + 2048];
try
{
if (wrapAround)
{
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
System.arraycopy(buffer, 0, newbuffer,
bufsize - tokenBegin, bufpos);
buffer = newbuffer;
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
bufline = newbufline;
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
bufcolumn = newbufcolumn;
maxNextCharInd = (bufpos += (bufsize - tokenBegin));
}
else
{
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
buffer = newbuffer;
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
bufline = newbufline;
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
bufcolumn = newbufcolumn;
maxNextCharInd = (bufpos -= tokenBegin);
}
}
catch (Throwable t)
{
throw new Error(t.getMessage());
}
bufsize += 2048;
available = bufsize;
tokenBegin = 0;
}
protected void FillBuff() throws java.io.IOException
{
if (maxNextCharInd == available)
{
if (available == bufsize)
{
if (tokenBegin > 2048)
{
bufpos = maxNextCharInd = 0;
available = tokenBegin;
}
else if (tokenBegin < 0)
bufpos = maxNextCharInd = 0;
else
ExpandBuff(false);
}
else if (available > tokenBegin)
available = bufsize;
else if ((tokenBegin - available) < 2048)
ExpandBuff(true);
else
available = tokenBegin;
}
int i;
try {
if ((i = inputStream.read(buffer, maxNextCharInd,
available - maxNextCharInd)) == -1)
{
inputStream.close();
throw new java.io.IOException();
}
else
maxNextCharInd += i;
return;
}
catch(java.io.IOException e) {
--bufpos;
backup(0);
if (tokenBegin == -1)
tokenBegin = bufpos;
throw e;
}
}
public char BeginToken() throws java.io.IOException
{
tokenBegin = -1;
char c = readChar();
tokenBegin = bufpos;
return c;
}
protected void UpdateLineColumn(char c)
{
column++;
if (prevCharIsLF)
{
prevCharIsLF = false;
line += (column = 1);
}
else if (prevCharIsCR)
{
prevCharIsCR = false;
if (c == '\n')
{
prevCharIsLF = true;
}
else
line += (column = 1);
}
switch (c)
{
case '\r' :
prevCharIsCR = true;
break;
case '\n' :
prevCharIsLF = true;
break;
case '\t' :
column--;
column += (tabSize - (column % tabSize));
break;
default :
break;
}
bufline[bufpos] = line;
bufcolumn[bufpos] = column;
}
public char readChar() throws java.io.IOException
{
if (inBuf > 0)
{
--inBuf;
if (++bufpos == bufsize)
bufpos = 0;
return buffer[bufpos];
}
if (++bufpos >= maxNextCharInd)
FillBuff();
char c = buffer[bufpos];
UpdateLineColumn(c);
return (c);
}
/**
* @deprecated
* @see #getEndColumn
*/
public int getColumn() {
return bufcolumn[bufpos];
}
/**
* @deprecated
* @see #getEndLine
*/
public int getLine() {
return bufline[bufpos];
}
public int getEndColumn() {
return bufcolumn[bufpos];
}
public int getEndLine() {
return bufline[bufpos];
}
public int getBeginColumn() {
return bufcolumn[tokenBegin];
}
public int getBeginLine() {
return bufline[tokenBegin];
}
public void backup(int amount) {
inBuf += amount;
if ((bufpos -= amount) < 0)
bufpos += bufsize;
}
public SimpleCharStream(java.io.Reader dstream, int startline,
int startcolumn, int buffersize)
{
inputStream = dstream;
line = startline;
column = startcolumn - 1;
available = bufsize = buffersize;
buffer = new char[buffersize];
bufline = new int[buffersize];
bufcolumn = new int[buffersize];
}
public SimpleCharStream(java.io.Reader dstream, int startline,
int startcolumn)
{
this(dstream, startline, startcolumn, 4096);
}
public SimpleCharStream(java.io.Reader dstream)
{
this(dstream, 1, 1, 4096);
}
public void ReInit(java.io.Reader dstream, int startline,
int startcolumn, int buffersize)
{
inputStream = dstream;
line = startline;
column = startcolumn - 1;
if (buffer == null || buffersize != buffer.length)
{
available = bufsize = buffersize;
buffer = new char[buffersize];
bufline = new int[buffersize];
bufcolumn = new int[buffersize];
}
prevCharIsLF = prevCharIsCR = false;
tokenBegin = inBuf = maxNextCharInd = 0;
bufpos = -1;
}
public void ReInit(java.io.Reader dstream, int startline,
int startcolumn)
{
ReInit(dstream, startline, startcolumn, 4096);
}
public void ReInit(java.io.Reader dstream)
{
ReInit(dstream, 1, 1, 4096);
}
public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
{
this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
}
public SimpleCharStream(java.io.InputStream dstream, int startline,
int startcolumn, int buffersize)
{
this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
}
public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
int startcolumn) throws java.io.UnsupportedEncodingException
{
this(dstream, encoding, startline, startcolumn, 4096);
}
public SimpleCharStream(java.io.InputStream dstream, int startline,
int startcolumn)
{
this(dstream, startline, startcolumn, 4096);
}
public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
{
this(dstream, encoding, 1, 1, 4096);
}
public SimpleCharStream(java.io.InputStream dstream)
{
this(dstream, 1, 1, 4096);
}
public void ReInit(java.io.InputStream dstream, String encoding, int startline,
int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
{
ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
}
public void ReInit(java.io.InputStream dstream, int startline,
int startcolumn, int buffersize)
{
ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
}
public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
{
ReInit(dstream, encoding, 1, 1, 4096);
}
public void ReInit(java.io.InputStream dstream)
{
ReInit(dstream, 1, 1, 4096);
}
public void ReInit(java.io.InputStream dstream, String encoding, int startline,
int startcolumn) throws java.io.UnsupportedEncodingException
{
ReInit(dstream, encoding, startline, startcolumn, 4096);
}
public void ReInit(java.io.InputStream dstream, int startline,
int startcolumn)
{
ReInit(dstream, startline, startcolumn, 4096);
}
public String GetImage()
{
if (bufpos >= tokenBegin)
return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
else
return new String(buffer, tokenBegin, bufsize - tokenBegin) +
new String(buffer, 0, bufpos + 1);
}
public char[] GetSuffix(int len)
{
char[] ret = new char[len];
if ((bufpos + 1) >= len)
System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
else
{
System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
len - bufpos - 1);
System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
}
return ret;
}
public void Done()
{
buffer = null;
bufline = null;
bufcolumn = null;
}
/**
* Method to adjust line and column numbers for the start of a token.
*/
public void adjustBeginLineColumn(int newLine, int newCol)
{
int start = tokenBegin;
int len;
if (bufpos >= tokenBegin)
{
len = bufpos - tokenBegin + inBuf + 1;
}
else
{
len = bufsize - tokenBegin + bufpos + 1 + inBuf;
}
int i = 0, j = 0, k = 0;
int nextColDiff = 0, columnDiff = 0;
while (i < len &&
bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
{
bufline[j] = newLine;
nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
bufcolumn[j] = newCol + columnDiff;
columnDiff = nextColDiff;
i++;
}
if (i < len)
{
bufline[j] = newLine++;
bufcolumn[j] = newCol + columnDiff;
while (i++ < len)
{
if (bufline[j = start % bufsize] != bufline[++start % bufsize])
bufline[j] = newLine++;
else
bufline[j] = newLine;
}
}
line = bufline[j];
column = bufcolumn[j];
}
}

View File

@@ -0,0 +1,187 @@
/*
* Copyright (c) 1997, 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.
*/
package com.sun.xml.internal.xsom.impl.scd;
import com.sun.xml.internal.xsom.XSComponent;
import com.sun.xml.internal.xsom.XSDeclaration;
import com.sun.xml.internal.xsom.XSFacet;
import com.sun.xml.internal.xsom.XSType;
import com.sun.xml.internal.xsom.SCD;
import com.sun.xml.internal.xsom.XSSchema;
import com.sun.xml.internal.xsom.impl.UName;
import java.util.Iterator;
/**
* Building block of {@link SCD}.
*
* @author Kohsuke Kawaguchi
*/
public abstract class Step<T extends XSComponent> {
public final Axis<? extends T> axis;
/**
* 'Predicate' in SCD designates the index of the item. -1 if there's no predicate.
* Predicate starts from 1.
*
* <p>
* Because of the parsing order this parameter cannot be marked
* final, even though it's immutable once it's parsed.
*/
int predicate = -1;
protected Step(Axis<? extends T> axis) {
this.axis = axis;
}
/**
* Perform filtering (which is different depending on the kind of step.)
*/
protected abstract Iterator<? extends T> filter( Iterator<? extends T> base );
/**
* Evaluate this step against the current node set
* and returns matched nodes.
*/
public final Iterator<T> evaluate(Iterator<XSComponent> nodeSet) {
// list up the whole thing
Iterator<T> r = new Iterators.Map<T,XSComponent>(nodeSet) {
protected Iterator<? extends T> apply(XSComponent contextNode) {
return filter(axis.iterator(contextNode));
}
};
// avoid duplicates
r = new Iterators.Unique<T>(r);
if(predicate>=0) {
T item=null;
for( int i=predicate; i>0; i-- ) {
if(!r.hasNext())
return Iterators.empty();
item = r.next();
}
return new Iterators.Singleton<T>(item);
}
return r;
}
/**
* Matches any name.
*/
static final class Any extends Step<XSComponent> {
public Any(Axis<? extends XSComponent> axis) {
super(axis);
}
// no filtering.
protected Iterator<? extends XSComponent> filter(Iterator<? extends XSComponent> base) {
return base;
}
}
private static abstract class Filtered<T extends XSComponent> extends Step<T> {
protected Filtered(Axis<? extends T> axis) {
super(axis);
}
protected Iterator<T> filter(Iterator<? extends T> base) {
return new Iterators.Filter<T>(base) {
protected boolean matches(T d) {
return match(d);
}
};
}
protected abstract boolean match(T d);
}
/**
* Matches a particular name.
*/
static final class Named extends Filtered<XSDeclaration> {
private final String nsUri;
private final String localName;
public Named(Axis<? extends XSDeclaration> axis, UName n) {
this(axis,n.getNamespaceURI(),n.getName());
}
public Named(Axis<? extends XSDeclaration> axis, String nsUri, String localName) {
super(axis);
this.nsUri = nsUri;
this.localName = localName;
}
protected boolean match(XSDeclaration d) {
return d.getName().equals(localName) && d.getTargetNamespace().equals(nsUri);
}
}
/**
* Matches anonymous types.
*/
static final class AnonymousType extends Filtered<XSType> {
public AnonymousType(Axis<? extends XSType> axis) {
super(axis);
}
protected boolean match(XSType node) {
return node.isLocal();
}
}
/**
* Matches a particular kind of facets.
*/
static final class Facet extends Filtered<XSFacet> {
private final String name;
public Facet(Axis<XSFacet> axis, String facetName) {
super(axis);
this.name = facetName;
}
protected boolean match(XSFacet f) {
return f.getName().equals(name);
}
}
/**
* Matches a schema in a particular namespace.
*/
static final class Schema extends Filtered<XSSchema> {
private final String uri;
public Schema(Axis<XSSchema> axis, String uri) {
super(axis);
this.uri = uri;
}
protected boolean match(XSSchema d) {
return d.getTargetNamespace().equals(uri);
}
}
}

View File

@@ -0,0 +1,106 @@
/*
* Copyright (c) 1997, 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.
*/
/* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */
package com.sun.xml.internal.xsom.impl.scd;
/**
* Describes the input token stream.
*/
public class Token {
/**
* An integer that describes the kind of this token. This numbering
* system is determined by JavaCCParser, and a table of these numbers is
* stored in the file ...Constants.java.
*/
public int kind;
/**
* beginLine and beginColumn describe the position of the first character
* of this token; endLine and endColumn describe the position of the
* last character of this token.
*/
public int beginLine, beginColumn, endLine, endColumn;
/**
* The string image of the token.
*/
public String image;
/**
* A reference to the next regular (non-special) token from the input
* stream. If this is the last token from the input stream, or if the
* token manager has not read tokens beyond this one, this field is
* set to null. This is true only if this token is also a regular
* token. Otherwise, see below for a description of the contents of
* this field.
*/
public Token next;
/**
* This field is used to access special tokens that occur prior to this
* token, but after the immediately preceding regular (non-special) token.
* If there are no such special tokens, this field is set to null.
* When there are more than one such special token, this field refers
* to the last of these special tokens, which in turn refers to the next
* previous special token through its specialToken field, and so on
* until the first special token (whose specialToken field is null).
* The next fields of special tokens refer to other special tokens that
* immediately follow it (without an intervening regular token). If there
* is no such token, this field is null.
*/
public Token specialToken;
/**
* Returns the image.
*/
public String toString()
{
return image;
}
/**
* Returns a new Token object, by default. However, if you want, you
* can create and return subclass objects based on the value of ofKind.
* Simply add the cases to the switch for all those special cases.
* For example, if you have a subclass of Token called IDToken that
* you want to create if ofKind is ID, simlpy add something like :
*
* case MyParserConstants.ID : return new IDToken();
*
* to the following switch statement. Then you can cast matchedToken
* variable to the appropriate type and use it in your lexical actions.
*/
public static final Token newToken(int ofKind)
{
switch(ofKind)
{
default : return new Token();
}
}
}

View File

@@ -0,0 +1,158 @@
/*
* Copyright (c) 1997, 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.
*/
/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
package com.sun.xml.internal.xsom.impl.scd;
public class TokenMgrError extends Error
{
/*
* Ordinals for various reasons why an Error of this type can be thrown.
*/
/**
* Lexical error occured.
*/
static final int LEXICAL_ERROR = 0;
/**
* An attempt wass made to create a second instance of a static token manager.
*/
static final int STATIC_LEXER_ERROR = 1;
/**
* Tried to change to an invalid lexical state.
*/
static final int INVALID_LEXICAL_STATE = 2;
/**
* Detected (and bailed out of) an infinite loop in the token manager.
*/
static final int LOOP_DETECTED = 3;
/**
* Indicates the reason why the exception is thrown. It will have
* one of the above 4 values.
*/
int errorCode;
/**
* Replaces unprintable characters by their espaced (or unicode escaped)
* equivalents in the given string
*/
protected static final String addEscapes(String str) {
StringBuffer retval = new StringBuffer();
char ch;
for (int i = 0; i < str.length(); i++) {
switch (str.charAt(i))
{
case 0 :
continue;
case '\b':
retval.append("\\b");
continue;
case '\t':
retval.append("\\t");
continue;
case '\n':
retval.append("\\n");
continue;
case '\f':
retval.append("\\f");
continue;
case '\r':
retval.append("\\r");
continue;
case '\"':
retval.append("\\\"");
continue;
case '\'':
retval.append("\\\'");
continue;
case '\\':
retval.append("\\\\");
continue;
default:
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
String s = "0000" + Integer.toString(ch, 16);
retval.append("\\u" + s.substring(s.length() - 4, s.length()));
} else {
retval.append(ch);
}
continue;
}
}
return retval.toString();
}
/**
* Returns a detailed message for the Error when it is thrown by the
* token manager to indicate a lexical error.
* Parameters :
* EOFSeen : indicates if EOF caused the lexicl error
* curLexState : lexical state in which this error occured
* errorLine : line number when the error occured
* errorColumn : column number when the error occured
* errorAfter : prefix that was seen before this error occured
* curchar : the offending character
* Note: You can customize the lexical error message by modifying this method.
*/
protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
return("Lexical error at line " +
errorLine + ", column " +
errorColumn + ". Encountered: " +
(EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
"after : \"" + addEscapes(errorAfter) + "\"");
}
/**
* You can also modify the body of this method to customize your error messages.
* For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
* of end-users concern, so you can return something like :
*
* "Internal Error : Please file a bug report .... "
*
* from this method for such cases in the release version of your parser.
*/
public String getMessage() {
return super.getMessage();
}
/*
* Constructors of various flavors follow.
*/
public TokenMgrError() {
}
public TokenMgrError(String message, int reason) {
super(message);
errorCode = reason;
}
public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
}
}