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,191 @@
/*
* 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.util;
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.XSContentType;
import com.sun.xml.internal.xsom.XSElementDecl;
import com.sun.xml.internal.xsom.XSFacet;
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.XSIdentityConstraint;
import com.sun.xml.internal.xsom.XSXPath;
import com.sun.xml.internal.xsom.visitor.XSFunction;
/**
* Extract the name of the components.
*
* @author <ul><li>Ryan Shoemaker, Sun Microsystems, Inc.</li></ul>
*/
public class ComponentNameFunction implements XSFunction<String> {
// delegate to this object to get the localized name of the component type
private NameGetter nameGetter = new NameGetter(null);
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#annotation(XSAnnotation)
*/
public String annotation(XSAnnotation ann) {
// unnamed component
return nameGetter.annotation( ann );
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#attGroupDecl(XSAttGroupDecl)
*/
public String attGroupDecl(XSAttGroupDecl decl) {
String name = decl.getName();
if( name == null ) name = "";
return name + " " + nameGetter.attGroupDecl( decl );
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#attributeDecl(XSAttributeDecl)
*/
public String attributeDecl(XSAttributeDecl decl) {
String name = decl.getName();
if( name == null ) name = "";
return name + " " + nameGetter.attributeDecl( decl );
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#attributeUse(XSAttributeUse)
*/
public String attributeUse(XSAttributeUse use) {
// unnamed component
return nameGetter.attributeUse( use );
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#complexType(XSComplexType)
*/
public String complexType(XSComplexType type) {
String name = type.getName();
if( name == null ) name = "anonymous";
return name + " " + nameGetter.complexType( type );
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#schema(XSSchema)
*/
public String schema(XSSchema schema) {
return nameGetter.schema( schema ) + " \"" + schema.getTargetNamespace()+"\"";
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#facet(XSFacet)
*/
public String facet(XSFacet facet) {
String name = facet.getName();
if( name == null ) name = "";
return name + " " + nameGetter.facet( facet );
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#notation(XSNotation)
*/
public String notation(XSNotation notation) {
String name = notation.getName();
if( name == null ) name = "";
return name + " " + nameGetter.notation( notation );
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSContentTypeFunction#simpleType(XSSimpleType)
*/
public String simpleType(XSSimpleType simpleType) {
String name = simpleType.getName();
if( name == null ) name = "anonymous";
return name + " " + nameGetter.simpleType( simpleType );
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSContentTypeFunction#particle(XSParticle)
*/
public String particle(XSParticle particle) {
// unnamed component
return nameGetter.particle( particle );
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSContentTypeFunction#empty(XSContentType)
*/
public String empty(XSContentType empty) {
// unnamed component
return nameGetter.empty( empty );
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSTermFunction#wildcard(XSWildcard)
*/
public String wildcard(XSWildcard wc) {
// unnamed component
return nameGetter.wildcard( wc );
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSTermFunction#modelGroupDecl(XSModelGroupDecl)
*/
public String modelGroupDecl(XSModelGroupDecl decl) {
String name = decl.getName();
if( name == null ) name = "";
return name + " " + nameGetter.modelGroupDecl( decl );
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSTermFunction#modelGroup(XSModelGroup)
*/
public String modelGroup(XSModelGroup group) {
// unnamed component
return nameGetter.modelGroup( group );
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSTermFunction#elementDecl(XSElementDecl)
*/
public String elementDecl(XSElementDecl decl) {
String name = decl.getName();
if( name == null ) name = "";
return name + " " + nameGetter.elementDecl( decl );
}
public String identityConstraint(XSIdentityConstraint decl) {
return decl.getName()+" "+nameGetter.identityConstraint(decl);
}
public String xpath(XSXPath xpath) {
return nameGetter.xpath(xpath);
}
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright (c) 2014, 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.util;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.MessageFormat;
import java.util.ResourceBundle;
import java.util.WeakHashMap;
/**
* Simple utility ensuring that the value is cached only in case it is non-internal implementation
*/
abstract class ContextClassloaderLocal<V> {
private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
public V get() throws Error {
ClassLoader tccl = getContextClassLoader();
V instance = CACHE.get(tccl);
if (instance == null) {
instance = createNewInstance();
CACHE.put(tccl, instance);
}
return instance;
}
public void set(V instance) {
CACHE.put(getContextClassLoader(), instance);
}
protected abstract V initialValue() throws Exception;
private V createNewInstance() {
try {
return initialValue();
} catch (Exception e) {
throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
}
}
private static String format(String property, Object... args) {
String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
return MessageFormat.format(text, args);
}
private static ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) {
}
return cl;
}
});
}
}

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.
*/
package com.sun.xml.internal.xsom.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
/**
* {@link Collection} that returns the view of objects which are actually fetched
* lazily from an {@link Iterator}.
*
* @author Kohsuke Kawaguchi
*/
public class DeferedCollection<T> implements Collection<T> {
/**
* The iterator that lazily evaluates SCD query.
*/
private final Iterator<T> result;
/**
* Stores values that are already fetched from {@link #result}.
*/
private final List<T> archive = new ArrayList<T>();
public DeferedCollection(Iterator<T> result) {
this.result = result;
}
public boolean isEmpty() {
if(archive.isEmpty())
fetch();
return archive.isEmpty();
}
public int size() {
fetchAll();
return archive.size();
}
public boolean contains(Object o) {
if(archive.contains(o))
return true;
while(result.hasNext()) {
T value = result.next();
archive.add(value);
if(value.equals(o))
return true;
}
return false;
}
public boolean containsAll(Collection<?> c) {
for (Object o : c) {
if(!contains(o))
return false;
}
return true;
}
public Iterator<T> iterator() {
return new Iterator<T>() {
int idx=0;
public boolean hasNext() {
if(idx<archive.size())
return true;
return result.hasNext();
}
public T next() {
if(idx==archive.size())
fetch();
if(idx==archive.size())
throw new NoSuchElementException();
return archive.get(idx++);
}
public void remove() {
// TODO
}
};
}
public Object[] toArray() {
fetchAll();
return archive.toArray();
}
public <T>T[] toArray(T[] a) {
fetchAll();
return archive.toArray(a);
}
private void fetchAll() {
while(result.hasNext())
archive.add(result.next());
}
/**
* Fetches another item from {@link
*/
private void fetch() {
if(result.hasNext())
archive.add(result.next());
}
// mutation methods are unsupported
public boolean add(T o) {
throw new UnsupportedOperationException();
}
public boolean remove(Object o) {
throw new UnsupportedOperationException();
}
public boolean addAll(Collection<? extends T> c) {
throw new UnsupportedOperationException();
}
public boolean removeAll(Collection<?> c) {
throw new UnsupportedOperationException();
}
public boolean retainAll(Collection<?> c) {
throw new UnsupportedOperationException();
}
public void clear() {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,119 @@
/*
* Copyright (c) 1997, 2014, 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.util;
import com.sun.xml.internal.xsom.XSAnnotation;
import com.sun.xml.internal.xsom.parser.AnnotationContext;
import com.sun.xml.internal.xsom.parser.AnnotationParser;
import com.sun.xml.internal.xsom.parser.AnnotationParserFactory;
import javax.xml.XMLConstants;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.ContentHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
/**
* {@link AnnotationParserFactory} that parses annotations into a W3C DOM.
*
* <p>
* If you use this parser factory, you'll get {@link Element} that represents
* &lt;xs:annotation> from {@link XSAnnotation#getAnnotation()}.
*
* <p>
* When multiple &lt;xs:annotation>s are found for the given schema component,
* you'll see all &lt;xs:appinfo>s and &lt;xs:documentation>s combined under
* one &lt;xs:annotation> element.
*
* @author Kohsuke Kawaguchi
*/
public class DomAnnotationParserFactory implements AnnotationParserFactory {
public AnnotationParser create() {
return new AnnotationParserImpl();
}
public AnnotationParser create(boolean disableSecureProcessing) {
return new AnnotationParserImpl(disableSecureProcessing);
}
private static final ContextClassloaderLocal<SAXTransformerFactory> stf = new ContextClassloaderLocal<SAXTransformerFactory>() {
@Override
protected SAXTransformerFactory initialValue() throws Exception {
return (SAXTransformerFactory) SAXTransformerFactory.newInstance();
}
};
private static class AnnotationParserImpl extends AnnotationParser {
/**
* Identity transformer used to parse SAX into DOM.
*/
private final TransformerHandler transformer;
private DOMResult result;
AnnotationParserImpl() {
this(false);
}
AnnotationParserImpl(boolean disableSecureProcessing) {
try {
SAXTransformerFactory factory = stf.get();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, disableSecureProcessing);
transformer = factory.newTransformerHandler();
} catch (TransformerConfigurationException e) {
throw new Error(e); // impossible
}
}
public ContentHandler getContentHandler(AnnotationContext context, String parentElementName, ErrorHandler errorHandler, EntityResolver entityResolver) {
result = new DOMResult();
transformer.setResult(result);
return transformer;
}
public Object getResult(Object existing) {
Document dom = (Document)result.getNode();
Element e = dom.getDocumentElement();
if(existing instanceof Element) {
// merge all the children
Element prev = (Element) existing;
Node anchor = e.getFirstChild();
while(prev.getFirstChild()!=null) {
Node move = prev.getFirstChild();
e.insertBefore(e.getOwnerDocument().adoptNode(move), anchor );
}
}
return e;
}
}
}

View File

@@ -0,0 +1,164 @@
/*
* 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.util;
import java.util.Locale;
import java.util.ResourceBundle;
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.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.XSIdentityConstraint;
import com.sun.xml.internal.xsom.XSXPath;
import com.sun.xml.internal.xsom.visitor.XSFunction;
/**
* Gets the human-readable name of a schema component.
*
* <p>
* This is a function object that returns {@link String}.
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
*/
public class NameGetter implements XSFunction<String> {
/**
* Initializes a NameGetter so that it will return
* messages in the specified locale.
*/
public NameGetter( Locale _locale ) {
this.locale = _locale;
}
private final Locale locale;
/**
* An instance that gets names in the default locale.
* This instance is provided just for convenience.
*/
public final static XSFunction theInstance = new NameGetter(null);
/**
* Gets the name of the specified component in the default locale.
* This method is just a wrapper.
*/
public static String get( XSComponent comp ) {
return (String)comp.apply(theInstance);
}
public String annotation(XSAnnotation ann) {
return localize("annotation");
}
public String attGroupDecl(XSAttGroupDecl decl) {
return localize("attGroupDecl");
}
public String attributeUse(XSAttributeUse use) {
return localize("attributeUse");
}
public String attributeDecl(XSAttributeDecl decl) {
return localize("attributeDecl");
}
public String complexType(XSComplexType type) {
return localize("complexType");
}
public String schema(XSSchema schema) {
return localize("schema");
}
public String facet(XSFacet facet) {
return localize("facet");
}
public String simpleType(XSSimpleType simpleType) {
return localize("simpleType");
}
public String particle(XSParticle particle) {
return localize("particle");
}
public String empty(XSContentType empty) {
return localize("empty");
}
public String wildcard(XSWildcard wc) {
return localize("wildcard");
}
public String modelGroupDecl(XSModelGroupDecl decl) {
return localize("modelGroupDecl");
}
public String modelGroup(XSModelGroup group) {
return localize("modelGroup");
}
public String elementDecl(XSElementDecl decl) {
return localize("elementDecl");
}
public String notation( XSNotation n ) {
return localize("notation");
}
public String identityConstraint(XSIdentityConstraint decl) {
return localize("idConstraint");
}
public String xpath(XSXPath xpath) {
return localize("xpath");
}
private String localize( String key ) {
ResourceBundle rb;
if(locale==null)
rb = ResourceBundle.getBundle(NameGetter.class.getName());
else
rb = ResourceBundle.getBundle(NameGetter.class.getName(),locale);
return rb.getString(key);
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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.util;
import java.util.Set;
import com.sun.xml.internal.xsom.XSType;
/**
* A very simple TypeSet.
*
* The contains method returns true if the set explicitly contains an
* instance of the specified XSType.
*
* @author <a href="mailto:Ryan.Shoemaker@Sun.COM">Ryan Shoemaker</a>, Sun Microsystems, Inc.
*/
public class SimpleTypeSet extends TypeSet {
private final Set typeSet;
public SimpleTypeSet(Set s) {
typeSet = s;
}
/* (non-Javadoc)
* @see com.sun.xml.internal.xsom.util.TypeSet#contains(com.sun.xml.internal.xsom.XSDeclaration)
*/
public boolean contains(XSType type) {
return typeSet.contains(type);
}
}

View File

@@ -0,0 +1,66 @@
/*
* 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.util;
import com.sun.xml.internal.xsom.XSType;
/**
* Perform a transitive closure operation on a type to determine if it
* belongs to this set.
*
* The contains method returns true if the TypeSet contains an instance
* of the specified XSType or any of the base types of the XSType.
*
* @author <a href="mailto:Ryan.Shoemaker@Sun.COM">Ryan Shoemaker</a>, Sun Microsystems, Inc.
*/
public class TypeClosure extends TypeSet {
private final TypeSet typeSet;
public TypeClosure(TypeSet typeSet) {
this.typeSet = typeSet;
}
/* (non-Javadoc)
* @see com.sun.xml.internal.xsom.util.TypeSet#contains(com.sun.xml.internal.xsom.XSDeclaration)
*
* transitive closure variation on the contains method.
*/
public boolean contains(XSType type) {
if( typeSet.contains(type) ) {
return true;
} else {
XSType baseType = type.getBaseType();
if( baseType == null ) {
return false;
} else {
// climb the super type hierarchy
return contains(baseType);
}
}
}
}

View File

@@ -0,0 +1,79 @@
/*
* 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.util;
import com.sun.xml.internal.xsom.XSType;
/**
* A simple abstraction for a set of Types that defines containment functions.
*
* @author <a href="mailto:Ryan.Shoemaker@Sun.COM">Ryan Shoemaker</a>, Sun Microsystems, Inc.
*/
public abstract class TypeSet {
/**
* Return true if this TypeSet contains the specified type.
*
* Concrete implementations of this method determine what it
* means for the TypeSet to "contain" a type.
*
* @param type the type
* @return true iff this TypeSet contains the specified type
*/
public abstract boolean contains(XSType type);
/**
* Calculate the TypeSet formed by the intersection of two
* other TypeSet objects.
*
* @param a a TypeSet
* @param b another TypeSet
* @return the intersection of a and b
*/
public static TypeSet intersection(final TypeSet a, final TypeSet b) {
return new TypeSet(){
public boolean contains(XSType type) {
return a.contains(type) && b.contains(type);
}
};
}
/**
* Calculate the TypeSet formed by the union of two
* other TypeSet objects.
*
* @param a a TypeSet
* @param b another TypeSet
* @return the union of a and b
*/
public static TypeSet union(final TypeSet a, final TypeSet b) {
return new TypeSet(){
public boolean contains(XSType type) {
return a.contains(type) || b.contains(type);
}
};
}
}

View File

@@ -0,0 +1,181 @@
/*
* 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.util;
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.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.XSIdentityConstraint;
import com.sun.xml.internal.xsom.XSXPath;
import com.sun.xml.internal.xsom.visitor.XSFunction;
/**
* Utility implementation of {@link XSFunction} that returns
* {@link Boolean} to find something from schema objects.
*
* <p>
* This implementation returns <code>Boolean.FALSE</code> from
* all of the methods. The derived class is expected to override
* some of the methods to actually look for something.
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
*/
public class XSFinder implements XSFunction<Boolean> {
/**
* Invokes this object as a visitor with the specified component.
*/
public final boolean find( XSComponent c ) {
return c.apply(this);
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#annotation(com.sun.xml.internal.xsom.XSAnnotation)
*/
public Boolean annotation(XSAnnotation ann) {
return Boolean.FALSE;
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#attGroupDecl(com.sun.xml.internal.xsom.XSAttGroupDecl)
*/
public Boolean attGroupDecl(XSAttGroupDecl decl) {
return Boolean.FALSE;
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#attributeDecl(com.sun.xml.internal.xsom.XSAttributeDecl)
*/
public Boolean attributeDecl(XSAttributeDecl decl) {
return Boolean.FALSE;
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#attributeUse(com.sun.xml.internal.xsom.XSAttributeUse)
*/
public Boolean attributeUse(XSAttributeUse use) {
return Boolean.FALSE;
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#complexType(com.sun.xml.internal.xsom.XSComplexType)
*/
public Boolean complexType(XSComplexType type) {
return Boolean.FALSE;
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#schema(com.sun.xml.internal.xsom.XSSchema)
*/
public Boolean schema(XSSchema schema) {
return Boolean.FALSE;
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#facet(com.sun.xml.internal.xsom.XSFacet)
*/
public Boolean facet(XSFacet facet) {
return Boolean.FALSE;
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSFunction#notation(com.sun.xml.internal.xsom.XSNotation)
*/
public Boolean notation(XSNotation notation) {
return Boolean.FALSE;
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSContentTypeFunction#simpleType(com.sun.xml.internal.xsom.XSSimpleType)
*/
public Boolean simpleType(XSSimpleType simpleType) {
return Boolean.FALSE;
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSContentTypeFunction#particle(com.sun.xml.internal.xsom.XSParticle)
*/
public Boolean particle(XSParticle particle) {
return Boolean.FALSE;
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSContentTypeFunction#empty(com.sun.xml.internal.xsom.XSContentType)
*/
public Boolean empty(XSContentType empty) {
return Boolean.FALSE;
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSTermFunction#wildcard(com.sun.xml.internal.xsom.XSWildcard)
*/
public Boolean wildcard(XSWildcard wc) {
return Boolean.FALSE;
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSTermFunction#modelGroupDecl(com.sun.xml.internal.xsom.XSModelGroupDecl)
*/
public Boolean modelGroupDecl(XSModelGroupDecl decl) {
return Boolean.FALSE;
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSTermFunction#modelGroup(com.sun.xml.internal.xsom.XSModelGroup)
*/
public Boolean modelGroup(XSModelGroup group) {
return Boolean.FALSE;
}
/**
* @see com.sun.xml.internal.xsom.visitor.XSTermFunction#elementDecl(com.sun.xml.internal.xsom.XSElementDecl)
*/
public Boolean elementDecl(XSElementDecl decl) {
return Boolean.FALSE;
}
public Boolean identityConstraint(XSIdentityConstraint decl) {
return Boolean.FALSE;
}
public Boolean xpath(XSXPath xpath) {
return Boolean.FALSE;
}
}

View File

@@ -0,0 +1,136 @@
/*
* 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.util;
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.XSContentType;
import com.sun.xml.internal.xsom.XSElementDecl;
import com.sun.xml.internal.xsom.XSFacet;
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.XSIdentityConstraint;
import com.sun.xml.internal.xsom.XSXPath;
import com.sun.xml.internal.xsom.visitor.XSFunction;
/**
* Filter implementation of XSFilter.
* This class forwards all the method calls to another XSFunction.
*
* <p>
* This class is intended to be derived by client application
* to add some meaningful behavior.
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
*/
public class XSFunctionFilter<T> implements XSFunction<T> {
/** This object will receive all forwarded calls. */
protected XSFunction<T> core;
public XSFunctionFilter( XSFunction<T> _core ) {
this.core = _core;
}
public XSFunctionFilter() {}
public T annotation(XSAnnotation ann) {
return core.annotation(ann);
}
public T attGroupDecl(XSAttGroupDecl decl) {
return core.attGroupDecl(decl);
}
public T attributeDecl(XSAttributeDecl decl) {
return core.attributeDecl(decl);
}
public T attributeUse(XSAttributeUse use) {
return core.attributeUse(use);
}
public T complexType(XSComplexType type) {
return core.complexType(type);
}
public T schema(XSSchema schema) {
return core.schema(schema);
}
public T facet(XSFacet facet) {
return core.facet(facet);
}
public T notation(XSNotation notation) {
return core.notation(notation);
}
public T simpleType(XSSimpleType simpleType) {
return core.simpleType(simpleType);
}
public T particle(XSParticle particle) {
return core.particle(particle);
}
public T empty(XSContentType empty) {
return core.empty(empty);
}
public T wildcard(XSWildcard wc) {
return core.wildcard(wc);
}
public T modelGroupDecl(XSModelGroupDecl decl) {
return core.modelGroupDecl(decl);
}
public T modelGroup(XSModelGroup group) {
return core.modelGroup(group);
}
public T elementDecl(XSElementDecl decl) {
return core.elementDecl(decl);
}
public T identityConstraint(XSIdentityConstraint decl) {
return core.identityConstraint(decl);
}
public T xpath(XSXPath xpath) {
return core.xpath(xpath);
}
}