feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* 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.bind.unmarshaller;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.xml.bind.ValidationEventLocator;
|
||||
import javax.xml.bind.helpers.AbstractUnmarshallerImpl;
|
||||
import javax.xml.bind.helpers.ValidationEventLocatorImpl;
|
||||
|
||||
import com.sun.xml.internal.bind.v2.runtime.unmarshaller.LocatorEx;
|
||||
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.ProcessingInstruction;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
import org.xml.sax.helpers.NamespaceSupport;
|
||||
|
||||
/**
|
||||
* Visits a W3C DOM tree and generates SAX2 events from it.
|
||||
*
|
||||
* <p>
|
||||
* This class is just intended to be used by {@link AbstractUnmarshallerImpl}.
|
||||
* The javax.xml.bind.helpers package is generally a wrong place to put
|
||||
* classes like this.
|
||||
*
|
||||
* @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li></ul>
|
||||
* @since JAXB1.0
|
||||
*/
|
||||
public class DOMScanner implements LocatorEx,InfosetScanner/*<Node> --- but can't do this to protect 1.0 clients, or can I? */
|
||||
{
|
||||
|
||||
/** reference to the current node being scanned - used for determining
|
||||
* location info for validation events */
|
||||
private Node currentNode = null;
|
||||
|
||||
/** To save memory, only one instance of AttributesImpl will be used. */
|
||||
private final AttributesImpl atts = new AttributesImpl();
|
||||
|
||||
/** This handler will receive SAX2 events. */
|
||||
private ContentHandler receiver=null;
|
||||
|
||||
private Locator locator=this;
|
||||
|
||||
public DOMScanner() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Configures the locator object that the SAX {@link ContentHandler} will see.
|
||||
*/
|
||||
public void setLocator( Locator loc ) {
|
||||
this.locator = loc;
|
||||
}
|
||||
|
||||
public void scan(Object node) throws SAXException {
|
||||
if( node instanceof Document ) {
|
||||
scan( (Document)node );
|
||||
} else {
|
||||
scan( (Element)node );
|
||||
}
|
||||
}
|
||||
|
||||
public void scan( Document doc ) throws SAXException {
|
||||
scan( doc.getDocumentElement() );
|
||||
}
|
||||
|
||||
public void scan( Element e) throws SAXException {
|
||||
setCurrentLocation( e );
|
||||
|
||||
receiver.setDocumentLocator(locator);
|
||||
receiver.startDocument();
|
||||
|
||||
NamespaceSupport nss = new NamespaceSupport();
|
||||
buildNamespaceSupport( nss, e.getParentNode() );
|
||||
|
||||
for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) {
|
||||
String prefix = (String)en.nextElement();
|
||||
receiver.startPrefixMapping( prefix, nss.getURI(prefix) );
|
||||
}
|
||||
|
||||
visit(e);
|
||||
|
||||
for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) {
|
||||
String prefix = (String)en.nextElement();
|
||||
receiver.endPrefixMapping( prefix );
|
||||
}
|
||||
|
||||
|
||||
setCurrentLocation( e );
|
||||
receiver.endDocument();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a subtree starting from the element e and
|
||||
* reports SAX2 events to the specified handler.
|
||||
*
|
||||
* @deprecated in JAXB 2.0
|
||||
* Use {@link #scan(Element)}
|
||||
*/
|
||||
public void parse( Element e, ContentHandler handler ) throws SAXException {
|
||||
// it might be better to set receiver at the constructor.
|
||||
receiver = handler;
|
||||
|
||||
setCurrentLocation( e );
|
||||
receiver.startDocument();
|
||||
|
||||
receiver.setDocumentLocator(locator);
|
||||
visit(e);
|
||||
|
||||
setCurrentLocation( e );
|
||||
receiver.endDocument();
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to the parse method but it visits the ancestor nodes
|
||||
* and properly emulate the all in-scope namespace declarations.
|
||||
*
|
||||
* @deprecated in JAXB 2.0
|
||||
* Use {@link #scan(Element)}
|
||||
*/
|
||||
public void parseWithContext( Element e, ContentHandler handler ) throws SAXException {
|
||||
setContentHandler(handler);
|
||||
scan(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively visit ancestors and build up {@link NamespaceSupport} oject.
|
||||
*/
|
||||
private void buildNamespaceSupport(NamespaceSupport nss, Node node) {
|
||||
if(node==null || node.getNodeType()!=Node.ELEMENT_NODE)
|
||||
return;
|
||||
|
||||
buildNamespaceSupport( nss, node.getParentNode() );
|
||||
|
||||
nss.pushContext();
|
||||
NamedNodeMap atts = node.getAttributes();
|
||||
for( int i=0; i<atts.getLength(); i++ ) {
|
||||
Attr a = (Attr)atts.item(i);
|
||||
if( "xmlns".equals(a.getPrefix()) ) {
|
||||
nss.declarePrefix( a.getLocalName(), a.getValue() );
|
||||
continue;
|
||||
}
|
||||
if( "xmlns".equals(a.getName()) ) {
|
||||
nss.declarePrefix( "", a.getValue() );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits an element and its subtree.
|
||||
*/
|
||||
public void visit( Element e ) throws SAXException {
|
||||
setCurrentLocation( e );
|
||||
final NamedNodeMap attributes = e.getAttributes();
|
||||
|
||||
atts.clear();
|
||||
int len = attributes==null ? 0: attributes.getLength();
|
||||
|
||||
for( int i=len-1; i>=0; i-- ) {
|
||||
Attr a = (Attr)attributes.item(i);
|
||||
String name = a.getName();
|
||||
// start namespace binding
|
||||
if(name.startsWith("xmlns")) {
|
||||
if(name.length()==5) {
|
||||
receiver.startPrefixMapping( "", a.getValue() );
|
||||
} else {
|
||||
String localName = a.getLocalName();
|
||||
if(localName==null) {
|
||||
// DOM built without namespace support has this problem
|
||||
localName = name.substring(6);
|
||||
}
|
||||
receiver.startPrefixMapping( localName, a.getValue() );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
String uri = a.getNamespaceURI();
|
||||
if(uri==null) uri="";
|
||||
|
||||
String local = a.getLocalName();
|
||||
if(local==null) local = a.getName();
|
||||
// add other attributes to the attribute list
|
||||
// that we will pass to the ContentHandler
|
||||
atts.addAttribute(
|
||||
uri,
|
||||
local,
|
||||
a.getName(),
|
||||
"CDATA",
|
||||
a.getValue());
|
||||
}
|
||||
|
||||
String uri = e.getNamespaceURI();
|
||||
if(uri==null) uri="";
|
||||
String local = e.getLocalName();
|
||||
String qname = e.getTagName();
|
||||
if(local==null) local = qname;
|
||||
receiver.startElement( uri, local, qname, atts );
|
||||
|
||||
// visit its children
|
||||
NodeList children = e.getChildNodes();
|
||||
int clen = children.getLength();
|
||||
for( int i=0; i<clen; i++ )
|
||||
visit(children.item(i));
|
||||
|
||||
|
||||
|
||||
setCurrentLocation( e );
|
||||
receiver.endElement( uri, local, qname );
|
||||
|
||||
// call the endPrefixMapping method
|
||||
for( int i=len-1; i>=0; i-- ) {
|
||||
Attr a = (Attr)attributes.item(i);
|
||||
String name = a.getName();
|
||||
if(name.startsWith("xmlns")) {
|
||||
if(name.length()==5)
|
||||
receiver.endPrefixMapping("");
|
||||
else
|
||||
receiver.endPrefixMapping(a.getLocalName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void visit( Node n ) throws SAXException {
|
||||
setCurrentLocation( n );
|
||||
|
||||
// if a case statement gets too big, it should be made into a separate method.
|
||||
switch(n.getNodeType()) {
|
||||
case Node.CDATA_SECTION_NODE:
|
||||
case Node.TEXT_NODE:
|
||||
String value = n.getNodeValue();
|
||||
receiver.characters( value.toCharArray(), 0, value.length() );
|
||||
break;
|
||||
case Node.ELEMENT_NODE:
|
||||
visit( (Element)n );
|
||||
break;
|
||||
case Node.ENTITY_REFERENCE_NODE:
|
||||
receiver.skippedEntity(n.getNodeName());
|
||||
break;
|
||||
case Node.PROCESSING_INSTRUCTION_NODE:
|
||||
ProcessingInstruction pi = (ProcessingInstruction)n;
|
||||
receiver.processingInstruction(pi.getTarget(),pi.getData());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setCurrentLocation( Node currNode ) {
|
||||
currentNode = currNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* The same as {@link #getCurrentElement()} but
|
||||
* better typed.
|
||||
*/
|
||||
public Node getCurrentLocation() {
|
||||
return currentNode;
|
||||
}
|
||||
|
||||
public Object getCurrentElement() {
|
||||
return currentNode;
|
||||
}
|
||||
|
||||
public LocatorEx getLocator() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setContentHandler(ContentHandler handler) {
|
||||
this.receiver = handler;
|
||||
}
|
||||
|
||||
public ContentHandler getContentHandler() {
|
||||
return this.receiver;
|
||||
}
|
||||
|
||||
|
||||
// LocatorEx implementation
|
||||
public String getPublicId() { return null; }
|
||||
public String getSystemId() { return null; }
|
||||
public int getLineNumber() { return -1; }
|
||||
public int getColumnNumber() { return -1; }
|
||||
|
||||
public ValidationEventLocator getLocation() {
|
||||
return new ValidationEventLocatorImpl(getCurrentLocation());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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.bind.unmarshaller;
|
||||
|
||||
import javax.xml.bind.Binder;
|
||||
|
||||
import com.sun.xml.internal.bind.v2.runtime.unmarshaller.LocatorEx;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Visits a DOM-ish API and generates SAX events.
|
||||
*
|
||||
* <p>
|
||||
* This interface is not tied to any particular DOM API.
|
||||
* Used by the {@link Binder}.
|
||||
*
|
||||
* <p>
|
||||
* Since we are parsing a DOM-ish tree, I don't think this
|
||||
* scanner itself will ever find an error, so this class
|
||||
* doesn't have its own error reporting scheme.
|
||||
*
|
||||
* <p>
|
||||
* This interface <b>MAY NOT</b> be implemented by the generated
|
||||
* runtime nor the generated code. We may add new methods on
|
||||
* this interface later. This is to be implemented by the static runtime
|
||||
* only.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface InfosetScanner<XmlNode> {
|
||||
/**
|
||||
* Parses the given DOM-ish element/document and generates
|
||||
* SAX events.
|
||||
*
|
||||
* @throws ClassCastException
|
||||
* If the type of the node is not known to this implementation.
|
||||
*
|
||||
* @throws SAXException
|
||||
* If the {@link ContentHandler} throws a {@link SAXException}.
|
||||
* Do not throw an exception just because the scanner failed
|
||||
* (if that can happen we need to change the API.)
|
||||
*/
|
||||
void scan( XmlNode node ) throws SAXException;
|
||||
|
||||
/**
|
||||
* Sets the {@link ContentHandler}.
|
||||
*
|
||||
* This handler receives the SAX events.
|
||||
*/
|
||||
void setContentHandler( ContentHandler handler );
|
||||
ContentHandler getContentHandler();
|
||||
|
||||
/**
|
||||
* Gets the current element we are parsing.
|
||||
*
|
||||
* <p>
|
||||
* This method could
|
||||
* be called from the {@link ContentHandler#startElement(String, String, String, Attributes)}
|
||||
* or {@link ContentHandler#endElement(String, String, String)}.
|
||||
*
|
||||
* <p>
|
||||
* Otherwise the behavior of this method is undefined.
|
||||
*
|
||||
* @return
|
||||
* never return null.
|
||||
*/
|
||||
XmlNode getCurrentElement();
|
||||
|
||||
LocatorEx getLocator();
|
||||
}
|
||||
101
jdkSrc/jdk8/com/sun/xml/internal/bind/unmarshaller/Messages.java
Normal file
101
jdkSrc/jdk8/com/sun/xml/internal/bind/unmarshaller/Messages.java
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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.bind.unmarshaller;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Formats error messages.
|
||||
*
|
||||
* @since JAXB1.0
|
||||
*/
|
||||
public class Messages
|
||||
{
|
||||
public static String format( String property ) {
|
||||
return format( property, null );
|
||||
}
|
||||
|
||||
public static String format( String property, Object arg1 ) {
|
||||
return format( property, new Object[]{arg1} );
|
||||
}
|
||||
|
||||
public static String format( String property, Object arg1, Object arg2 ) {
|
||||
return format( property, new Object[]{arg1,arg2} );
|
||||
}
|
||||
|
||||
public static String format( String property, Object arg1, Object arg2, Object arg3 ) {
|
||||
return format( property, new Object[]{arg1,arg2,arg3} );
|
||||
}
|
||||
|
||||
// add more if necessary.
|
||||
|
||||
/** Loads a string resource and formats it with specified arguments. */
|
||||
public static String format( String property, Object[] args ) {
|
||||
String text = ResourceBundle.getBundle(Messages.class.getName()).getString(property);
|
||||
return MessageFormat.format(text,args);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// Message resources
|
||||
//
|
||||
//
|
||||
public static final String UNEXPECTED_ENTER_ELEMENT = // arg:2
|
||||
"ContentHandlerEx.UnexpectedEnterElement";
|
||||
|
||||
public static final String UNEXPECTED_LEAVE_ELEMENT = // arg:2
|
||||
"ContentHandlerEx.UnexpectedLeaveElement";
|
||||
|
||||
public static final String UNEXPECTED_ENTER_ATTRIBUTE =// arg:2
|
||||
"ContentHandlerEx.UnexpectedEnterAttribute";
|
||||
|
||||
public static final String UNEXPECTED_LEAVE_ATTRIBUTE =// arg:2
|
||||
"ContentHandlerEx.UnexpectedLeaveAttribute";
|
||||
|
||||
public static final String UNEXPECTED_TEXT =// arg:1
|
||||
"ContentHandlerEx.UnexpectedText";
|
||||
|
||||
public static final String UNEXPECTED_LEAVE_CHILD = // 0 args
|
||||
"ContentHandlerEx.UnexpectedLeaveChild";
|
||||
|
||||
public static final String UNEXPECTED_ROOT_ELEMENT = // 1 arg
|
||||
"SAXUnmarshallerHandlerImpl.UnexpectedRootElement";
|
||||
|
||||
// Usage not found. TODO Remove
|
||||
// public static final String UNEXPECTED_ROOT_ELEMENT2 = // 3 arg
|
||||
// "SAXUnmarshallerHandlerImpl.UnexpectedRootElement2";
|
||||
|
||||
public static final String UNDEFINED_PREFIX = // 1 arg
|
||||
"Util.UndefinedPrefix";
|
||||
|
||||
public static final String NULL_READER = // 0 args
|
||||
"Unmarshaller.NullReader";
|
||||
|
||||
public static final String ILLEGAL_READER_STATE = // 1 arg
|
||||
"Unmarshaller.IllegalReaderState";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.bind.unmarshaller;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Runs by UnmarshallingContext after all the parsing is done.
|
||||
*
|
||||
* Primarily used to resolve forward IDREFs, but it can run any action.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public interface Patcher {
|
||||
/**
|
||||
* Runs an post-action.
|
||||
*
|
||||
* @throws SAXException
|
||||
* if an error is found during the action, it should be reporeted to the context.
|
||||
* The context may then throw a {@link SAXException} to abort the processing,
|
||||
* and that's when you can throw a {@link SAXException}.
|
||||
*/
|
||||
void run() throws SAXException;
|
||||
}
|
||||
Reference in New Issue
Block a user