feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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.tools.internal.xjc.util;
|
||||
|
||||
import com.sun.codemodel.internal.ClassType;
|
||||
import com.sun.codemodel.internal.JClassAlreadyExistsException;
|
||||
import com.sun.codemodel.internal.JClassContainer;
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.codemodel.internal.JJavaName;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.tools.internal.xjc.ErrorReceiver;
|
||||
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* Create new {@link JDefinedClass} and report class collision errors,
|
||||
* if necessary.
|
||||
*
|
||||
* This is just a helper class that simplifies the class name collision
|
||||
* detection. This object maintains no state, so it is OK to use
|
||||
* multiple instances of this.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public final class CodeModelClassFactory {
|
||||
|
||||
/** errors are reported to this object. */
|
||||
private ErrorReceiver errorReceiver;
|
||||
|
||||
/** unique id generator. */
|
||||
private int ticketMaster = 0;
|
||||
|
||||
|
||||
public CodeModelClassFactory( ErrorReceiver _errorReceiver ) {
|
||||
this.errorReceiver = _errorReceiver;
|
||||
}
|
||||
|
||||
public JDefinedClass createClass( JClassContainer parent, String name, Locator source ) {
|
||||
return createClass( parent, JMod.PUBLIC, name, source );
|
||||
}
|
||||
public JDefinedClass createClass( JClassContainer parent, int mod, String name, Locator source ) {
|
||||
return createClass(parent,mod,name,source,ClassType.CLASS);
|
||||
}
|
||||
|
||||
public JDefinedClass createInterface( JClassContainer parent, String name, Locator source ) {
|
||||
return createInterface( parent, JMod.PUBLIC, name, source );
|
||||
}
|
||||
public JDefinedClass createInterface( JClassContainer parent, int mod, String name, Locator source ) {
|
||||
return createClass(parent,mod,name,source,ClassType.INTERFACE);
|
||||
}
|
||||
public JDefinedClass createClass(
|
||||
JClassContainer parent, String name, Locator source, ClassType kind ) {
|
||||
return createClass(parent,JMod.PUBLIC,name,source,kind);
|
||||
}
|
||||
public JDefinedClass createClass(
|
||||
JClassContainer parent, int mod, String name, Locator source, ClassType kind ) {
|
||||
|
||||
if(!JJavaName.isJavaIdentifier(name)) {
|
||||
// report the error
|
||||
errorReceiver.error( new SAXParseException(
|
||||
Messages.format( Messages.ERR_INVALID_CLASSNAME, name ), source ));
|
||||
return createDummyClass(parent);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if(parent.isClass() && kind==ClassType.CLASS)
|
||||
mod |= JMod.STATIC;
|
||||
|
||||
JDefinedClass r = parent._class(mod,name,kind);
|
||||
// use the metadata field to store the source location,
|
||||
// so that we can report class name collision errors.
|
||||
r.metadata = source;
|
||||
|
||||
return r;
|
||||
} catch( JClassAlreadyExistsException e ) {
|
||||
// class collision.
|
||||
JDefinedClass cls = e.getExistingClass();
|
||||
|
||||
// report the error
|
||||
errorReceiver.error( new SAXParseException(
|
||||
Messages.format( Messages.ERR_CLASSNAME_COLLISION, cls.fullName() ),
|
||||
(Locator)cls.metadata ));
|
||||
errorReceiver.error( new SAXParseException(
|
||||
Messages.format( Messages.ERR_CLASSNAME_COLLISION_SOURCE, name ),
|
||||
source ));
|
||||
|
||||
if( !name.equals(cls.name()) ) {
|
||||
// on Windows, FooBar and Foobar causes name collision
|
||||
errorReceiver.error( new SAXParseException(
|
||||
Messages.format( Messages.ERR_CASE_SENSITIVITY_COLLISION,
|
||||
name, cls.name() ), null ) );
|
||||
}
|
||||
|
||||
if(Util.equals((Locator)cls.metadata,source)) {
|
||||
errorReceiver.error( new SAXParseException(
|
||||
Messages.format( Messages.ERR_CHAMELEON_SCHEMA_GONE_WILD ),
|
||||
source ));
|
||||
}
|
||||
|
||||
return createDummyClass(parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a dummy class to recover from an error.
|
||||
*
|
||||
* We won't generate the code, so the client will never see this class
|
||||
* getting generated.
|
||||
*/
|
||||
private JDefinedClass createDummyClass(JClassContainer parent) {
|
||||
try {
|
||||
return parent._class("$$$garbage$$$"+(ticketMaster++));
|
||||
} catch( JClassAlreadyExistsException ee ) {
|
||||
return ee.getExistingClass();
|
||||
}
|
||||
}
|
||||
}
|
||||
141
jdkSrc/jdk8/com/sun/tools/internal/xjc/util/DOMUtils.java
Normal file
141
jdkSrc/jdk8/com/sun/tools/internal/xjc/util/DOMUtils.java
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* DOMUtils.java
|
||||
*
|
||||
* Created on May 7th 2002
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.xjc.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.w3c.dom.DOMException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Vivek Pandey
|
||||
* @version 1.0
|
||||
*
|
||||
*/
|
||||
public class DOMUtils {
|
||||
/** Gets the fist child of the given name, or null. */
|
||||
public static Element getFirstChildElement( Element parent, String nsUri, String localPart ) {
|
||||
NodeList children = parent.getChildNodes();
|
||||
for( int i=0; i<children.getLength(); i++ ) {
|
||||
Node item = children.item(i);
|
||||
if(!(item instanceof Element )) continue;
|
||||
|
||||
if(nsUri.equals(item.getNamespaceURI())
|
||||
&& localPart.equals(item.getLocalName()) )
|
||||
return (Element)item;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Gets the child elements of the given name. */
|
||||
public static Element[] getChildElements(Element parent, String nsUri, String localPart ) {
|
||||
ArrayList a = new ArrayList();
|
||||
NodeList children = parent.getChildNodes();
|
||||
for( int i=0; i<children.getLength(); i++ ) {
|
||||
Node item = children.item(i);
|
||||
if(!(item instanceof Element )) continue;
|
||||
|
||||
if(nsUri.equals(item.getNamespaceURI())
|
||||
&& localPart.equals(item.getLocalName()) )
|
||||
a.add(item);
|
||||
}
|
||||
return (Element[]) a.toArray(new Element[a.size()]);
|
||||
}
|
||||
|
||||
/** Gets all the child elements. */
|
||||
public static Element[] getChildElements( Element parent ) {
|
||||
ArrayList a = new ArrayList();
|
||||
NodeList children = parent.getChildNodes();
|
||||
for( int i=0; i<children.getLength(); i++ ) {
|
||||
Node item = children.item(i);
|
||||
if(!(item instanceof Element )) continue;
|
||||
|
||||
a.add(item);
|
||||
}
|
||||
return (Element[]) a.toArray(new Element[a.size()]);
|
||||
}
|
||||
|
||||
|
||||
public static String getElementText(Element element) throws DOMException{
|
||||
for (Node child = element.getFirstChild(); child != null;
|
||||
child = child.getNextSibling()) {
|
||||
if(child.getNodeType() == Node.TEXT_NODE)
|
||||
return child.getNodeValue();
|
||||
}
|
||||
return element.getNodeValue();
|
||||
}
|
||||
|
||||
public static Element getElement(Document parent, String name){
|
||||
NodeList children = parent.getElementsByTagName(name);
|
||||
if(children.getLength() >= 1)
|
||||
return (Element)children.item(0);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Element getElement(Document parent, QName qname){
|
||||
NodeList children = parent.getElementsByTagNameNS(qname.getNamespaceURI(), qname.getLocalPart());
|
||||
if(children.getLength() >= 1)
|
||||
return (Element)children.item(0);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Element getElement(Document parent, String namespaceURI,
|
||||
String localName) {
|
||||
NodeList children = parent.getElementsByTagNameNS(namespaceURI, localName);
|
||||
if(children.getLength() >= 1)
|
||||
return (Element)children.item(0);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Element[] getElements(NodeList children) {
|
||||
Element[] elements = null;
|
||||
int len = 0;
|
||||
for (int i = 0; i < children.getLength(); ++i) {
|
||||
if (elements == null)
|
||||
elements = new Element[1];
|
||||
if (elements.length == len) {
|
||||
Element[] buf = new Element[elements.length + 1];
|
||||
System.arraycopy(elements, 0, buf, 0, elements.length);
|
||||
elements = buf;
|
||||
}
|
||||
elements[len++] = (Element)children.item(i);
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.tools.internal.xjc.util;
|
||||
|
||||
import com.sun.tools.internal.xjc.ErrorReceiver;
|
||||
import com.sun.tools.internal.xjc.api.ErrorListener;
|
||||
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* Filter implementation of the ErrorReceiver.
|
||||
*
|
||||
* If an error is encountered, this filter sets a flag.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class ErrorReceiverFilter extends ErrorReceiver {
|
||||
|
||||
public ErrorReceiverFilter() {}
|
||||
|
||||
public ErrorReceiverFilter( ErrorListener h ) {
|
||||
setErrorReceiver(h);
|
||||
}
|
||||
|
||||
private ErrorListener core;
|
||||
public void setErrorReceiver( ErrorListener handler ) {
|
||||
core = handler;
|
||||
}
|
||||
|
||||
private boolean hadError = false;
|
||||
public final boolean hadError() { return hadError; }
|
||||
|
||||
public void info(SAXParseException exception) {
|
||||
if(core!=null) core.info(exception);
|
||||
}
|
||||
|
||||
public void warning(SAXParseException exception) {
|
||||
if(core!=null) core.warning(exception);
|
||||
}
|
||||
|
||||
public void error(SAXParseException exception) {
|
||||
hadError = true;
|
||||
if(core!=null) core.error(exception);
|
||||
}
|
||||
|
||||
public void fatalError(SAXParseException exception) {
|
||||
hadError = true;
|
||||
if(core!=null) core.fatalError(exception);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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.tools.internal.xjc.util;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* ContentHandler that "forks" the incoming SAX2 events to
|
||||
* two ContentHandlers.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a>
|
||||
*/
|
||||
public class ForkContentHandler implements ContentHandler {
|
||||
|
||||
/**
|
||||
* Creates a ForkContentHandler.
|
||||
*
|
||||
* @param first
|
||||
* This handler will receive a SAX event first.
|
||||
* @param second
|
||||
* This handler will receive a SAX event after the first handler
|
||||
* receives it.
|
||||
*/
|
||||
public ForkContentHandler( ContentHandler first, ContentHandler second ) {
|
||||
lhs = first;
|
||||
rhs = second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates ForkContentHandlers so that the specified handlers
|
||||
* will receive SAX events in the order of the array.
|
||||
*/
|
||||
public static ContentHandler create( ContentHandler[] handlers ) {
|
||||
if(handlers.length==0)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
ContentHandler result = handlers[0];
|
||||
for( int i=1; i<handlers.length; i++ )
|
||||
result = new ForkContentHandler( result, handlers[i] );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private final ContentHandler lhs,rhs;
|
||||
|
||||
public void setDocumentLocator (Locator locator) {
|
||||
lhs.setDocumentLocator(locator);
|
||||
rhs.setDocumentLocator(locator);
|
||||
}
|
||||
|
||||
public void startDocument() throws SAXException {
|
||||
lhs.startDocument();
|
||||
rhs.startDocument();
|
||||
}
|
||||
|
||||
public void endDocument () throws SAXException {
|
||||
lhs.endDocument();
|
||||
rhs.endDocument();
|
||||
}
|
||||
|
||||
public void startPrefixMapping (String prefix, String uri) throws SAXException {
|
||||
lhs.startPrefixMapping(prefix,uri);
|
||||
rhs.startPrefixMapping(prefix,uri);
|
||||
}
|
||||
|
||||
public void endPrefixMapping (String prefix) throws SAXException {
|
||||
lhs.endPrefixMapping(prefix);
|
||||
rhs.endPrefixMapping(prefix);
|
||||
}
|
||||
|
||||
public void startElement (String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
lhs.startElement(uri,localName,qName,attributes);
|
||||
rhs.startElement(uri,localName,qName,attributes);
|
||||
}
|
||||
|
||||
public void endElement (String uri, String localName, String qName) throws SAXException {
|
||||
lhs.endElement(uri,localName,qName);
|
||||
rhs.endElement(uri,localName,qName);
|
||||
}
|
||||
|
||||
public void characters (char ch[], int start, int length) throws SAXException {
|
||||
lhs.characters(ch,start,length);
|
||||
rhs.characters(ch,start,length);
|
||||
}
|
||||
|
||||
public void ignorableWhitespace (char ch[], int start, int length) throws SAXException {
|
||||
lhs.ignorableWhitespace(ch,start,length);
|
||||
rhs.ignorableWhitespace(ch,start,length);
|
||||
}
|
||||
|
||||
public void processingInstruction (String target, String data) throws SAXException {
|
||||
lhs.processingInstruction(target,data);
|
||||
rhs.processingInstruction(target,data);
|
||||
}
|
||||
|
||||
public void skippedEntity (String name) throws SAXException {
|
||||
lhs.skippedEntity(name);
|
||||
rhs.skippedEntity(name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.tools.internal.xjc.util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* {@link EntityResolver} that delegates to two {@link EntityResolver}s.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class ForkEntityResolver implements EntityResolver {
|
||||
private final EntityResolver lhs;
|
||||
private final EntityResolver rhs;
|
||||
|
||||
public ForkEntityResolver(EntityResolver lhs, EntityResolver rhs) {
|
||||
this.lhs = lhs;
|
||||
this.rhs = rhs;
|
||||
}
|
||||
|
||||
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
|
||||
InputSource is = lhs.resolveEntity(publicId, systemId);
|
||||
if(is!=null)
|
||||
return is;
|
||||
return rhs.resolveEntity(publicId,systemId);
|
||||
}
|
||||
}
|
||||
57
jdkSrc/jdk8/com/sun/tools/internal/xjc/util/Messages.java
Normal file
57
jdkSrc/jdk8/com/sun/tools/internal/xjc/util/Messages.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.tools.internal.xjc.util;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Formats error messages.
|
||||
*/
|
||||
class Messages
|
||||
{
|
||||
/** Loads a string resource and formats it with specified arguments. */
|
||||
static String format( String property, Object... args ) {
|
||||
String text = ResourceBundle.getBundle(Messages.class.getPackage().getName() +".MessageBundle").getString(property);
|
||||
return MessageFormat.format(text,args);
|
||||
}
|
||||
|
||||
|
||||
static final String ERR_CLASSNAME_COLLISION =
|
||||
"CodeModelClassFactory.ClassNameCollision";
|
||||
|
||||
static final String ERR_CLASSNAME_COLLISION_SOURCE =
|
||||
"CodeModelClassFactory.ClassNameCollision.Source";
|
||||
|
||||
static final String ERR_INVALID_CLASSNAME =
|
||||
"ERR_INVALID_CLASSNAME";
|
||||
|
||||
static final String ERR_CASE_SENSITIVITY_COLLISION = // 2 args
|
||||
"CodeModelClassFactory.CaseSensitivityCollision";
|
||||
|
||||
static final String ERR_CHAMELEON_SCHEMA_GONE_WILD = // no argts
|
||||
"ERR_CHAMELEON_SCHEMA_GONE_WILD";
|
||||
}
|
||||
165
jdkSrc/jdk8/com/sun/tools/internal/xjc/util/MimeTypeRange.java
Normal file
165
jdkSrc/jdk8/com/sun/tools/internal/xjc/util/MimeTypeRange.java
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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.tools.internal.xjc.util;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.activation.MimeType;
|
||||
import javax.activation.MimeTypeParseException;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class MimeTypeRange {
|
||||
public final String majorType;
|
||||
public final String subType;
|
||||
|
||||
public final Map<String,String> parameters = new HashMap<String, String>();
|
||||
|
||||
/**
|
||||
* Each media-range MAY be followed by one or more accept-params,
|
||||
* beginning with the "q" parameter for indicating a relative quality
|
||||
* factor. The first "q" parameter (if any) separates the media-range
|
||||
* parameter(s) from the accept-params. Quality factors allow the user
|
||||
* or user agent to indicate the relative degree of preference for that
|
||||
* media-range, using the qvalue scale from 0 to 1 (section 3.9). The
|
||||
* default value is q=1.
|
||||
*/
|
||||
public final float q;
|
||||
|
||||
// accept-extension is not implemented
|
||||
|
||||
public static List<MimeTypeRange> parseRanges(String s) throws ParseException {
|
||||
StringCutter cutter = new StringCutter(s,true);
|
||||
List<MimeTypeRange> r = new ArrayList<MimeTypeRange>();
|
||||
while(cutter.length()>0) {
|
||||
r.add(new MimeTypeRange(cutter));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public MimeTypeRange(String s) throws ParseException {
|
||||
this(new StringCutter(s,true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Used only to produce the static constants within this class.
|
||||
*/
|
||||
private static MimeTypeRange create(String s) {
|
||||
try {
|
||||
return new MimeTypeRange(s);
|
||||
} catch (ParseException e) {
|
||||
// we only use this method for known inputs
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cutter
|
||||
* A string like "text/html; charset=utf-8;
|
||||
*/
|
||||
private MimeTypeRange(StringCutter cutter) throws ParseException {
|
||||
majorType = cutter.until("/");
|
||||
cutter.next("/");
|
||||
subType = cutter.until("[;,]");
|
||||
|
||||
float q = 1.0f;
|
||||
|
||||
while(cutter.length()>0) {
|
||||
String sep = cutter.next("[;,]");
|
||||
if(sep.equals(","))
|
||||
break;
|
||||
|
||||
String key = cutter.until("=");
|
||||
cutter.next("=");
|
||||
String value;
|
||||
char ch = cutter.peek();
|
||||
if(ch=='"') {
|
||||
// quoted
|
||||
cutter.next("\"");
|
||||
value = cutter.until("\"");
|
||||
cutter.next("\"");
|
||||
} else {
|
||||
value = cutter.until("[;,]");
|
||||
}
|
||||
|
||||
if(key.equals("q")) {
|
||||
q = Float.parseFloat(value);
|
||||
} else {
|
||||
parameters.put(key,value);
|
||||
}
|
||||
}
|
||||
|
||||
this.q = q;
|
||||
}
|
||||
|
||||
public MimeType toMimeType() throws MimeTypeParseException {
|
||||
// due to the additional error check done in the MimeType class,
|
||||
// an error at this point is possible
|
||||
return new MimeType(toString());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(majorType+'/'+subType);
|
||||
if(q!=1)
|
||||
sb.append("; q=").append(q);
|
||||
|
||||
for( Map.Entry<String,String> p : parameters.entrySet() ) {
|
||||
// I'm too lazy to quote the value
|
||||
sb.append("; ").append(p.getKey()).append('=').append(p.getValue());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static final MimeTypeRange ALL = create("*/*");
|
||||
|
||||
/**
|
||||
* Creates a range by merging all the given types.
|
||||
*/
|
||||
public static MimeTypeRange merge( Collection<MimeTypeRange> types ) {
|
||||
if(types.size()==0) throw new IllegalArgumentException();
|
||||
if(types.size()==1) return types.iterator().next();
|
||||
|
||||
String majorType=null;
|
||||
for (MimeTypeRange mt : types) {
|
||||
if(majorType==null) majorType = mt.majorType;
|
||||
if(!majorType.equals(mt.majorType))
|
||||
return ALL;
|
||||
}
|
||||
|
||||
return create(majorType+"/*");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws ParseException {
|
||||
for( MimeTypeRange m : parseRanges(args[0]))
|
||||
System.out.println(m.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.tools.internal.xjc.util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
|
||||
import com.sun.xml.internal.xsom.XmlString;
|
||||
|
||||
import org.relaxng.datatype.ValidationContext;
|
||||
|
||||
/**
|
||||
* Take a {@link ValidationContext} and make it look like a {@link NamespaceContext}.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class NamespaceContextAdapter implements NamespaceContext {
|
||||
private XmlString xstr;
|
||||
|
||||
public NamespaceContextAdapter(XmlString xstr) {
|
||||
this.xstr = xstr;
|
||||
}
|
||||
|
||||
public String getNamespaceURI(String prefix) {
|
||||
return xstr.resolvePrefix(prefix);
|
||||
}
|
||||
|
||||
public String getPrefix(String namespaceURI) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Iterator getPrefixes(String namespaceURI) {
|
||||
return Collections.EMPTY_LIST.iterator();
|
||||
}
|
||||
}
|
||||
53
jdkSrc/jdk8/com/sun/tools/internal/xjc/util/NullStream.java
Normal file
53
jdkSrc/jdk8/com/sun/tools/internal/xjc/util/NullStream.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.tools.internal.xjc.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Just consumes the byte stream. Kind of like /dev/null.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class NullStream extends OutputStream {
|
||||
|
||||
public void write(int b) throws IOException {
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
}
|
||||
|
||||
public void flush() throws IOException {
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
}
|
||||
|
||||
public void write(byte[] b) throws IOException {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.tools.internal.xjc.util;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||
|
||||
/**
|
||||
* {@link XmlAdapter} used inside XJC is almost always unmarshal-only.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public abstract class ReadOnlyAdapter<OnTheWire,InMemory> extends XmlAdapter<OnTheWire,InMemory> {
|
||||
public final OnTheWire marshal(InMemory onTheWire) {
|
||||
// the unmarshaller uses this method
|
||||
// to get the current collection object from the property.
|
||||
// so we can't just throw UnsupportedOperationException here
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.tools.internal.xjc.util;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Utility class to parse a string
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class StringCutter {
|
||||
private final String original;
|
||||
private String s;
|
||||
private boolean ignoreWhitespace;
|
||||
|
||||
public StringCutter(String s, boolean ignoreWhitespace) {
|
||||
this.s = this.original = s;
|
||||
this.ignoreWhitespace = ignoreWhitespace;
|
||||
}
|
||||
|
||||
public void skip(String regexp) throws ParseException {
|
||||
next(regexp);
|
||||
}
|
||||
|
||||
public String next(String regexp) throws ParseException {
|
||||
trim();
|
||||
Pattern p = Pattern.compile(regexp);
|
||||
Matcher m = p.matcher(s);
|
||||
if(m.lookingAt()) {
|
||||
String r = m.group();
|
||||
s = s.substring(r.length());
|
||||
trim();
|
||||
return r;
|
||||
} else
|
||||
throw error();
|
||||
}
|
||||
|
||||
private ParseException error() {
|
||||
return new ParseException(original,original.length()-s.length());
|
||||
}
|
||||
|
||||
public String until(String regexp) throws ParseException {
|
||||
Pattern p = Pattern.compile(regexp);
|
||||
Matcher m = p.matcher(s);
|
||||
if(m.find()) {
|
||||
String r = s.substring(0,m.start());
|
||||
s = s.substring(m.start());
|
||||
if(ignoreWhitespace)
|
||||
r = r.trim();
|
||||
return r;
|
||||
} else {
|
||||
// return everything left
|
||||
String r = s;
|
||||
s = "";
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
public char peek() {
|
||||
return s.charAt(0);
|
||||
}
|
||||
|
||||
private void trim() {
|
||||
if(ignoreWhitespace)
|
||||
s = s.trim();
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return s.length();
|
||||
}
|
||||
}
|
||||
108
jdkSrc/jdk8/com/sun/tools/internal/xjc/util/SubtreeCutter.java
Normal file
108
jdkSrc/jdk8/com/sun/tools/internal/xjc/util/SubtreeCutter.java
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.tools.internal.xjc.util;
|
||||
|
||||
import org.xml.sax.helpers.XMLFilterImpl;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
import org.xml.sax.XMLFilter;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
/**
|
||||
* {@link XMLFilter} that can cut sub-trees.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public abstract class SubtreeCutter extends XMLFilterImpl {
|
||||
/**
|
||||
* When we are pruning a sub tree, this field holds the depth of
|
||||
* elements that are being cut. Used to resume event forwarding.
|
||||
*
|
||||
* As long as this value is 0, we will pass through data.
|
||||
*/
|
||||
private int cutDepth=0;
|
||||
|
||||
|
||||
/**
|
||||
* This object will receive SAX events while a sub tree is being
|
||||
* pruned.
|
||||
*/
|
||||
private static final ContentHandler stub = new DefaultHandler();
|
||||
|
||||
/**
|
||||
* This field remembers the user-specified ContentHandler.
|
||||
* So that we can restore it once the sub tree is completely pruned.
|
||||
*/
|
||||
private ContentHandler next;
|
||||
|
||||
|
||||
public void startDocument() throws SAXException {
|
||||
cutDepth=0;
|
||||
super.startDocument();
|
||||
}
|
||||
|
||||
public boolean isCutting() {
|
||||
return cutDepth>0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts cutting a sub-tree. Should be called from within the
|
||||
* {@link #startElement(String, String, String, Attributes)} implementation
|
||||
* before the execution is passed to {@link SubtreeCutter#startElement(String, String, String, Attributes)} .
|
||||
* The current element will be cut.
|
||||
*/
|
||||
public void startCutting() {
|
||||
super.setContentHandler(stub);
|
||||
cutDepth=1;
|
||||
}
|
||||
|
||||
public void setContentHandler(ContentHandler handler) {
|
||||
next = handler;
|
||||
// changes take effect immediately unless the sub-tree is being pruned
|
||||
if(getContentHandler()!=stub)
|
||||
super.setContentHandler(handler);
|
||||
}
|
||||
|
||||
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
|
||||
if(cutDepth>0)
|
||||
cutDepth++;
|
||||
super.startElement(uri, localName, qName, atts);
|
||||
}
|
||||
|
||||
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
|
||||
super.endElement(namespaceURI, localName, qName);
|
||||
|
||||
if( cutDepth!=0 ) {
|
||||
cutDepth--;
|
||||
if( cutDepth == 1 ) {
|
||||
// pruning completed. restore the user handler
|
||||
super.setContentHandler(next);
|
||||
cutDepth=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
76
jdkSrc/jdk8/com/sun/tools/internal/xjc/util/Util.java
Normal file
76
jdkSrc/jdk8/com/sun/tools/internal/xjc/util/Util.java
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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.tools.internal.xjc.util;
|
||||
|
||||
import org.xml.sax.Locator;
|
||||
|
||||
|
||||
/**
|
||||
* Other miscellaneous utility methods.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public final class Util {
|
||||
private Util() {} // no instanciation please
|
||||
|
||||
/**
|
||||
* An easier-to-use version of the System.getProperty method
|
||||
* that doesn't throw an exception even if a property cannot be
|
||||
* read.
|
||||
*/
|
||||
public static String getSystemProperty( String name ) {
|
||||
try {
|
||||
return System.getProperty(name);
|
||||
} catch( SecurityException e ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares if two {@link Locator}s point to the exact same position.
|
||||
*/
|
||||
public static boolean equals(Locator lhs, Locator rhs) {
|
||||
return lhs.getLineNumber()==rhs.getLineNumber()
|
||||
&& lhs.getColumnNumber()==rhs.getColumnNumber()
|
||||
&& equals(lhs.getSystemId(),rhs.getSystemId())
|
||||
&& equals(lhs.getPublicId(),rhs.getPublicId());
|
||||
}
|
||||
|
||||
private static boolean equals(String lhs, String rhs) {
|
||||
if(lhs==null && rhs==null) return true;
|
||||
if(lhs==null || rhs==null) return false;
|
||||
return lhs.equals(rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the other getSystemProperty method with
|
||||
* "[clazz].[name].
|
||||
*/
|
||||
public static String getSystemProperty( Class clazz, String name ) {
|
||||
return getSystemProperty( clazz.getName()+'.'+name );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user