You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ch...@apache.org on 2006/02/01 10:05:11 UTC
svn commit: r374025 [2/8] - in /webservices/axis2/trunk/java: etc/
modules/adb/src/org/apache/axis2/databinding/
modules/adb/src/org/apache/axis2/databinding/deserializers/
modules/adb/test/org/apache/axis2/databinding/
modules/codegen/src/org/apache/a...
Added: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMMessageFormatter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMMessageFormatter.java?rev=374025&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMMessageFormatter.java (added)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMMessageFormatter.java Wed Feb 1 00:58:23 2006
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2002,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.axis2.om.impl.dom;
+
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.PropertyResourceBundle;
+import java.util.ResourceBundle;
+
+/**
+ * Used to format DOM error messages, using the system locale.
+ */
+public class DOMMessageFormatter {
+ public static final String DOM_DOMAIN = "http://www.w3.org/dom/DOMTR";
+
+ public static final String XML_DOMAIN =
+ "http://www.w3.org/TR/1998/REC-xml-19980210";
+
+ public static final String SERIALIZER_DOMAIN =
+ "http://apache.org/xml/serializer";
+
+ private static ResourceBundle domResourceBundle = null;
+
+ private static ResourceBundle xmlResourceBundle = null;
+
+ private static ResourceBundle serResourceBundle = null;
+
+ private static Locale locale = null;
+
+ public static final String LEVEL3_NOT_SUPPORTED =
+ "DOM Level 3 operations are not supported";
+
+ public static final String NOT_REQUIRED_FOR_XMLSEC_OR_WSS4J =
+ "This method is not required by Apache XML-Security Impl or WSS4J";
+
+ DOMMessageFormatter() {
+ locale = Locale.getDefault();
+ }
+
+ /**
+ * Formats a message with the specified arguments using the given locale
+ * information.
+ *
+ * @param domain
+ * domain from which error string is to come.
+ * @param key
+ * The message key.
+ * @param arguments
+ * The message replacement text arguments. The order of the
+ * arguments must match that of the placeholders in the actual
+ * message.
+ *
+ * @return Returns the formatted message.
+ *
+ * @throws MissingResourceException
+ * Thrown if the message with the specified key cannot be found.
+ */
+ public static String formatMessage(String domain, String key,
+ Object[] arguments) throws MissingResourceException {
+ ResourceBundle resourceBundle = getResourceBundle(domain);
+ if (resourceBundle == null) {
+ init();
+ resourceBundle = getResourceBundle(domain);
+ if (resourceBundle == null)
+ throw new MissingResourceException("Unknown domain" + domain,
+ null, key);
+ }
+ // format message
+ String msg;
+ try {
+ msg = key + ": " + resourceBundle.getString(key);
+ if (arguments != null) {
+ try {
+ msg = java.text.MessageFormat.format(msg, arguments);
+ } catch (Exception e) {
+ msg = resourceBundle.getString("FormatFailed");
+ msg += " " + resourceBundle.getString(key);
+ }
+ }
+ } // error
+ catch (MissingResourceException e) {
+ msg = resourceBundle.getString("BadMessageKey");
+ throw new MissingResourceException(key, msg, key);
+ }
+
+ // no message
+ if (msg == null) {
+ msg = key;
+ if (arguments.length > 0) {
+ StringBuffer str = new StringBuffer(msg);
+ str.append('?');
+ for (int i = 0; i < arguments.length; i++) {
+ if (i > 0) {
+ str.append('&');
+ }
+ str.append(String.valueOf(arguments[i]));
+ }
+ }
+ }
+
+ return msg;
+ }
+
+ static ResourceBundle getResourceBundle(String domain) {
+ if (domain == DOM_DOMAIN || domain.equals(DOM_DOMAIN))
+ return domResourceBundle;
+ else if (domain == XML_DOMAIN || domain.equals(XML_DOMAIN))
+ return xmlResourceBundle;
+ else if (domain == SERIALIZER_DOMAIN
+ || domain.equals(SERIALIZER_DOMAIN))
+ return serResourceBundle;
+ return null;
+ }
+
+ /**
+ * Initializes Message Formatter.
+ */
+ public static void init() {
+ if (locale != null) {
+ domResourceBundle = PropertyResourceBundle.getBundle(
+ "org.apache.axis2.om.impl.dom.msg.DOMMessages", locale);
+ serResourceBundle = PropertyResourceBundle.getBundle(
+ "org.apache.axis2.om.impl.dom.msg.XMLSerializerMessages",
+ locale);
+ xmlResourceBundle = PropertyResourceBundle.getBundle(
+ "org.apache.axis2.om.impl.dom.msg.XMLMessages", locale);
+ } else {
+ domResourceBundle = PropertyResourceBundle
+ .getBundle("org.apache.axis2.om.impl.dom.msg.DOMMessages");
+ serResourceBundle = PropertyResourceBundle
+ .getBundle("org.apache.axis2.om.impl.dom.msg.XMLSerializerMessages");
+ xmlResourceBundle = PropertyResourceBundle
+ .getBundle("org.apache.axis2.om.impl.dom.msg.XMLMessages");
+ }
+ }
+
+ /**
+ * Sets Locale to be used by the formatter.
+ *
+ * @param dlocale
+ */
+ public static void setLocale(Locale dlocale) {
+ locale = dlocale;
+ }
+}
Added: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMNavigator.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMNavigator.java?rev=374025&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMNavigator.java (added)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMNavigator.java Wed Feb 1 00:58:23 2006
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.axis2.om.impl.dom;
+
+import org.apache.ws.commons.om.OMContainer;
+import org.apache.ws.commons.om.OMElement;
+import org.apache.ws.commons.om.OMNode;
+
+/**
+ * This is exactly the same as org.apache.ws.commons.om.impl.om.OMNavigator, only the
+ * llom specifics are changed to dom. Refer to the testClass to find out how to
+ * use features like isNavigable, isComplete and step.
+ */
+public class DOMNavigator {
+ /**
+ * Field node
+ */
+ protected OMNode node;
+
+ /**
+ * Field visited
+ */
+ private boolean visited;
+
+ /**
+ * Field next
+ */
+ private OMNode next;
+
+ // root is the starting element. Once the navigator comes back to the
+ // root, the traversal is terminated
+
+ /**
+ * Field root
+ */
+ private OMNode root;
+
+ /**
+ * Field backtracked
+ */
+ private boolean backtracked;
+
+ // flags that tell the status of the navigator
+
+ /**
+ * Field end
+ */
+ private boolean end = false;
+
+ /**
+ * Field start
+ */
+ private boolean start = true;
+
+ /**
+ * Constructor OMNavigator.
+ */
+ public DOMNavigator() {
+ }
+
+ /**
+ * Constructor OMNavigator.
+ *
+ * @param node
+ */
+ public DOMNavigator(OMNode node) {
+ init(node);
+ }
+
+ /**
+ * Method init.
+ *
+ * @param node
+ */
+ public void init(OMNode node) {
+ next = node;
+ root = node;
+ backtracked = false;
+ }
+
+ /**
+ * Gets the next node.
+ *
+ * @return Returns OMNode in the sequence of preorder traversal. Note
+ * however that an element node is treated slightly differently.
+ * Once the element is passed it returns the same element in the
+ * next encounter as well.
+ */
+ public OMNode next() {
+ if (next == null) {
+ return null;
+ }
+ node = next;
+ visited = backtracked;
+ backtracked = false;
+ updateNextNode();
+
+ // set the starting and ending flags
+ if (root.equals(node)) {
+ if (!start) {
+ end = true;
+ } else {
+ start = false;
+ }
+ }
+ return node;
+ }
+
+ /**
+ * Private method to encapsulate the searching logic
+ */
+ private void updateNextNode() {
+ if ((next instanceof OMElement) && !visited) {
+ ElementImpl e = (ElementImpl) next;
+ if (e.firstChild != null) {
+ next = e.firstChild;
+ } else if (e.isComplete()) {
+ backtracked = true;
+ } else {
+ next = null;
+ }
+ } else {
+ OMNode nextSibling = ((ChildNode) next).nextSibling;
+ OMContainer parent = next.getParent();
+ if (nextSibling != null) {
+ next = nextSibling;
+ } else if ((parent != null) && parent.isComplete()) {
+ next = (NodeImpl) parent;
+ backtracked = true;
+ } else {
+ next = null;
+ }
+ }
+ }
+
+ /**
+ * Method visited.
+ *
+ * @return Returns boolean.
+ */
+ public boolean visited() {
+ return visited;
+ }
+
+ /**
+ * This is a very special method. This allows the navigator to step once it
+ * has reached the existing OM. At this point the isNavigable method will
+ * return false but the isComplete method may return false which means that
+ * the navigating the given element is not complete but the navigator cannot
+ * proceed.
+ */
+ public void step() {
+ if (!end) {
+ next = node;
+ updateNextNode();
+ }
+ }
+
+ /**
+ * Returns the navigable status.
+ *
+ * @return Returns boolean.
+ */
+ public boolean isNavigable() {
+ if (end) {
+ return false;
+ } else {
+ return !(next == null);
+ }
+ }
+
+ /**
+ * Returns the completed status.
+ *
+ * @return Returns boolean.
+ */
+ public boolean isCompleted() {
+ return end;
+ }
+}
Added: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMStAXWrapper.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMStAXWrapper.java?rev=374025&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMStAXWrapper.java (added)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMStAXWrapper.java Wed Feb 1 00:58:23 2006
@@ -0,0 +1,1197 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.axis2.om.impl.dom;
+
+import org.apache.ws.commons.om.OMAttribute;
+import org.apache.ws.commons.om.OMComment;
+import org.apache.ws.commons.om.OMDocument;
+import org.apache.ws.commons.om.OMElement;
+import org.apache.ws.commons.om.OMNamespace;
+import org.apache.ws.commons.om.OMNode;
+import org.apache.ws.commons.om.OMText;
+import org.apache.ws.commons.om.OMXMLParserWrapper;
+import org.apache.ws.commons.om.impl.llom.exception.OMStreamingException;
+import org.apache.ws.commons.om.impl.llom.EmptyOMLocation;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Node;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import java.util.Iterator;
+import java.util.Stack;
+
+/**
+ * This is exactly the same as org.apache.ws.commons.om.impl.llom.OMStAXWrapper. BUT
+ * this uses the org.apache.axis2.om.impl.dom.DOMNavigator.
+ *
+ * Note - This class also implements the streaming constants interface to get
+ * access to the StAX constants.
+ */
+public class DOMStAXWrapper implements XMLStreamReader, XMLStreamConstants {
+ /**
+ * Field navigator
+ */
+ private DOMNavigator navigator;
+
+ /**
+ * Field builder
+ */
+ private OMXMLParserWrapper builder;
+
+ /**
+ * Field parser
+ */
+ private XMLStreamReader parser;
+
+ /**
+ * Field rootNode
+ */
+ private OMNode rootNode;
+
+ /**
+ * Field isFirst
+ */
+ private boolean isFirst = true;
+
+ // Navigable means the output should be taken from the navigator
+ // as soon as the navigator returns a null navigable will be reset
+ // to false and the subsequent events will be taken from the builder
+ // or the parser directly.
+
+ /**
+ * Field NAVIGABLE
+ */
+ private static final short NAVIGABLE = 0;
+
+ private static final short SWITCH_AT_NEXT = 1;
+
+ private static final short COMPLETED = 2;
+
+ private static final short SWITCHED = 3;
+
+ private static final short DOCUMENT_COMPLETE = 4;
+
+ /**
+ * Field state
+ */
+ private short state;
+
+ /**
+ * Field currentEvent Default set to START_DOCUMENT
+ */
+ private int currentEvent = START_DOCUMENT;
+
+ // SwitchingAllowed is set to false by default
+ // this means that unless the user explicitly states
+ // that he wants things not to be cached, everything will
+ // be cached
+
+ /**
+ * Field switchingAllowed
+ */
+ boolean switchingAllowed = false;
+
+ /**
+ * Field elementStack
+ */
+ private Stack elementStack = new Stack();
+
+ // keeps the next event. The parser actually keeps one step ahead to
+ // detect the end of navigation. (at the end of the stream the navigator
+ // returns a null
+
+ /**
+ * Field nextNode
+ */
+ private OMNode nextNode = null;
+
+ // holder for the current node. Needs this to generate events from the
+ // current node
+
+ /**
+ * Field currentNode
+ */
+ private OMNode currentNode = null;
+
+ // needs this to refer to the last known node
+
+ /**
+ * Field lastNode
+ */
+ private OMNode lastNode = null;
+
+ private boolean needToThrowEndDocument = false;
+
+ /**
+ * Method setAllowSwitching.
+ *
+ * @param b
+ */
+ public void setAllowSwitching(boolean b) {
+ this.switchingAllowed = b;
+ }
+
+ /**
+ * Method isAllowSwitching.
+ *
+ * @return Returns boolean.
+ */
+ public boolean isAllowSwitching() {
+ return switchingAllowed;
+ }
+
+ /**
+ * When constructing the OMStaxWrapper, the creator must produce the builder
+ * (an instance of the OMXMLparserWrapper of the input) and the Element Node
+ * to start parsing. The wrapper parses(proceed) until the end of the given
+ * element. Hence care must be taken to pass the root element if the entire
+ * document is needed.
+ *
+ * @param builder
+ * @param startNode
+ */
+ public DOMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode) {
+ this(builder, startNode, false);
+ }
+
+ /**
+ * Constructor OMStAXWrapper
+ *
+ * @param builder
+ * @param startNode
+ * @param cache
+ */
+ public DOMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode,
+ boolean cache) {
+
+ // create a navigator
+ this.navigator = new DOMNavigator(startNode);
+ this.builder = builder;
+ this.rootNode = startNode;
+ if (rootNode != null && rootNode.getParent() != null
+ && rootNode.getParent() instanceof OMDocument) {
+ needToThrowEndDocument = true;
+ }
+
+ // initaite the next and current nodes
+ // Note - navigator is written in such a way that it first
+ // returns the starting node at the first call to it
+ currentNode = navigator.next();
+ updateNextNode();
+ switchingAllowed = !cache;
+ }
+
+ /**
+ * @return Returns String.
+ * @see javax.xml.stream.XMLStreamReader#getPrefix()
+ */
+ public String getPrefix() {
+ String returnStr = null;
+ if (parser != null) {
+ returnStr = parser.getPrefix();
+ } else {
+ if ((currentEvent == START_ELEMENT)
+ || (currentEvent == END_ELEMENT)) {
+ OMNamespace ns = ((OMElement) lastNode).getNamespace();
+ returnStr = (ns == null) ? null : ns.getPrefix();
+ }
+ }
+ return returnStr;
+ }
+
+ /**
+ * @return Returns String.
+ * @see javax.xml.stream.XMLStreamReader#getNamespaceURI()
+ */
+ public String getNamespaceURI() {
+ String returnStr = null;
+ if (parser != null) {
+ returnStr = parser.getNamespaceURI();
+ } else {
+ if ((currentEvent == START_ELEMENT)
+ || (currentEvent == END_ELEMENT)
+ || (currentEvent == NAMESPACE)) {
+ OMNamespace ns = ((OMElement) lastNode).getNamespace();
+ returnStr = (ns == null) ? null : ns.getName();
+ }
+ }
+ return returnStr;
+ }
+
+ /**
+ * @return Returns String.
+ * @see javax.xml.stream.XMLStreamReader#hasName()
+ */
+ public boolean hasName() {
+ if (parser != null) {
+ return parser.hasName();
+ } else {
+ return ((currentEvent == START_ELEMENT) ||
+ (currentEvent == END_ELEMENT));
+ }
+ }
+
+ /**
+ * @return Returns String.
+ * @see javax.xml.stream.XMLStreamReader#getLocalName()
+ */
+ public String getLocalName() {
+ String returnStr = null;
+ if (parser != null) {
+ returnStr = parser.getLocalName();
+ } else {
+ if ((currentEvent == START_ELEMENT)
+ || (currentEvent == END_ELEMENT)
+ || (currentEvent == ENTITY_REFERENCE)) {
+ returnStr = ((OMElement) lastNode).getLocalName();
+ }
+ }
+ return returnStr;
+ }
+
+ /**
+ * @return Returns QName.
+ * @see javax.xml.stream.XMLStreamReader#getName()
+ */
+ public QName getName() {
+ QName returnName = null;
+ if (parser != null) {
+ returnName = parser.getName();
+ } else {
+ if ((currentEvent == START_ELEMENT)
+ || (currentEvent == END_ELEMENT)) {
+ returnName = getQName((OMElement) lastNode);
+ }
+ }
+ return returnName;
+ }
+
+ /**
+ * @return Returns boolean.
+ * @see javax.xml.stream.XMLStreamReader#hasText()
+ */
+ public boolean hasText() {
+ return ((currentEvent == CHARACTERS) || (currentEvent == DTD)
+ || (currentEvent == ENTITY_REFERENCE)
+ || (currentEvent == COMMENT) || (currentEvent == SPACE));
+ }
+
+ /**
+ * @return Returns int.
+ * @see javax.xml.stream.XMLStreamReader#getTextLength()
+ */
+ public int getTextLength() {
+ int returnLength = 0;
+ if (parser != null) {
+ returnLength = parser.getTextLength();
+ } else {
+ OMText textNode = (OMText) lastNode;
+ returnLength = textNode.getText().length();
+ }
+ return returnLength;
+ }
+
+ /**
+ * @return Returns int.
+ * @see javax.xml.stream.XMLStreamReader#getTextStart()
+ */
+ public int getTextStart() {
+ int returnLength = 0;
+ if (parser != null) {
+ returnLength = parser.getTextStart();
+ }
+
+ // Note - this has no relevant method in the OM
+ return returnLength;
+ }
+
+ /**
+ * @param i
+ * @param chars
+ * @param i1
+ * @param i2
+ * @return Returns int.
+ * @throws XMLStreamException
+ * @see javax.xml.stream.XMLStreamReader#getTextCharacters(int, char[], int,
+ * int)
+ */
+ public int getTextCharacters(int i, char[] chars, int i1, int i2)
+ throws XMLStreamException {
+ int returnLength = 0;
+ if (hasText()) {
+ if (parser != null) {
+ try {
+ returnLength = parser.getTextCharacters(i, chars, i1, i2);
+ } catch (XMLStreamException e) {
+ throw new OMStreamingException(e);
+ }
+ }
+
+ // Note - this has no relevant method in the OM
+ }
+ return returnLength;
+ }
+
+ /**
+ * @return Returns char[].
+ * @see javax.xml.stream.XMLStreamReader#getTextCharacters()
+ */
+ public char[] getTextCharacters() {
+ char[] returnArray = null;
+ if (parser != null) {
+ returnArray = parser.getTextCharacters();
+ } else {
+ if (hasText()) {
+ OMText textNode = (OMText) lastNode;
+ String str = textNode.getText();
+ returnArray = str.toCharArray();
+ }
+ }
+ return returnArray;
+ }
+
+ /**
+ * @return Returns String.
+ * @see javax.xml.stream.XMLStreamReader#getText()
+ */
+ public String getText() {
+ String returnString = null;
+ if (parser != null) {
+ returnString = parser.getText();
+ } else {
+ if (hasText()) {
+ if (lastNode instanceof OMText) {
+ returnString = ((OMText) lastNode).getText();
+ } else if (lastNode instanceof OMComment) {
+ returnString = ((OMComment) lastNode).getValue();
+ }
+ }
+ }
+ return returnString;
+ }
+
+ /**
+ * @return Returns int.
+ * @see javax.xml.stream.XMLStreamReader#getEventType()
+ */
+
+ // todo this should be improved
+ public int getEventType() {
+ return currentEvent;
+ }
+
+ /**
+ * @param i
+ * @return Returns String.
+ * @see javax.xml.stream.XMLStreamReader#getNamespaceURI
+ */
+ public String getNamespaceURI(int i) {
+ String returnString = null;
+ if (parser != null) {
+ returnString = parser.getNamespaceURI(i);
+ } else {
+ if (isStartElement() || isEndElement()
+ || (currentEvent == NAMESPACE)) {
+ OMNamespace ns = (OMNamespace) getItemFromIterator(
+ ((OMElement) lastNode).getAllDeclaredNamespaces(), i);
+ returnString = (ns == null) ? null : ns.getName();
+ }
+ }
+ return returnString;
+ }
+
+ /**
+ * @param i
+ * @return Returns String.
+ * @see javax.xml.stream.XMLStreamReader#getNamespacePrefix
+ */
+ public String getNamespacePrefix(int i) {
+ String returnString = null;
+ if (parser != null) {
+ returnString = parser.getNamespacePrefix(i);
+ } else {
+ if (isStartElement() || isEndElement()
+ || (currentEvent == NAMESPACE)) {
+ OMNamespace ns = (OMNamespace) getItemFromIterator(
+ ((OMElement) lastNode).getAllDeclaredNamespaces(), i);
+ returnString = (ns == null) ? null : ns.getPrefix();
+ }
+ }
+ return returnString;
+ }
+
+ /**
+ * @return Returns int.
+ * @see javax.xml.stream.XMLStreamReader#getNamespaceCount()
+ */
+ public int getNamespaceCount() {
+ int returnCount = 0;
+ if (parser != null) {
+ returnCount = parser.getNamespaceCount();
+ } else {
+ if (isStartElement() || isEndElement()
+ || (currentEvent == NAMESPACE)) {
+ returnCount = getCount(((OMElement) lastNode)
+ .getAllDeclaredNamespaces());
+ }
+ }
+ return returnCount;
+ }
+
+ /**
+ * @param i
+ * @return Returns boolean.
+ * @see javax.xml.stream.XMLStreamReader#isAttributeSpecified
+ */
+ public boolean isAttributeSpecified(int i) {
+ boolean returnValue = false;
+ if (parser != null) {
+ returnValue = parser.isAttributeSpecified(i);
+ } else {
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
+
+ // theres nothing to be returned here
+ } else {
+ throw new IllegalStateException(
+ "attribute type accessed in illegal event!");
+ }
+ }
+ return returnValue;
+ }
+
+ /**
+ * @param i
+ * @return Returns String.
+ * @see javax.xml.stream.XMLStreamReader#getAttributeValue
+ */
+ public String getAttributeValue(int i) {
+ String returnString = null;
+ if (parser != null) {
+ returnString = parser.getAttributeValue(i);
+ } else {
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
+ OMAttribute attrib = getAttribute((OMElement) lastNode, i);
+ if (attrib != null) {
+ returnString = attrib.getAttributeValue();
+ }
+ } else {
+ throw new IllegalStateException(
+ "attribute type accessed in illegal event!");
+ }
+ }
+ return returnString;
+ }
+
+ /**
+ * @param i
+ * @return Returns String.
+ * @see javax.xml.stream.XMLStreamReader#getAttributeType
+ */
+ public String getAttributeType(int i) {
+ String returnString = null;
+ if (parser != null) {
+ returnString = parser.getAttributeType(i);
+ } else {
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
+
+ // todo implement this
+ } else {
+ throw new IllegalStateException(
+ "attribute type accessed in illegal event!");
+ }
+ }
+ return returnString;
+ }
+
+ /**
+ * @param i
+ * @return Returns String.
+ * @see javax.xml.stream.XMLStreamReader#getAttributePrefix
+ */
+ public String getAttributePrefix(int i) {
+ String returnString = null;
+ if (parser != null) {
+ returnString = parser.getAttributePrefix(i);
+ } else {
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
+ OMAttribute attrib = getAttribute((OMElement) lastNode, i);
+ if (attrib != null) {
+ OMNamespace nameSpace = attrib.getNamespace();
+ if (nameSpace != null) {
+ returnString = nameSpace.getPrefix();
+ }
+ }
+ } else {
+ throw new IllegalStateException(
+ "attribute prefix accessed in illegal event!");
+ }
+ }
+ return returnString;
+ }
+
+ /**
+ * @param i
+ * @return Returns String.
+ * @see javax.xml.stream.XMLStreamReader#getAttributeLocalName
+ */
+ public String getAttributeLocalName(int i) {
+ String returnString = null;
+ if (parser != null) {
+ returnString = parser.getAttributeLocalName(i);
+ } else {
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
+ OMAttribute attrib = getAttribute((OMElement) lastNode, i);
+ if (attrib != null) {
+ if (attrib.getNamespace() != null) {
+ returnString = attrib.getLocalName();
+ } else {
+ returnString = ((Attr) attrib).getNodeName();
+ }
+ }
+ } else {
+ throw new IllegalStateException(
+ "attribute localName accessed in illegal event!");
+ }
+ }
+ return returnString;
+ }
+
+ /**
+ * @param i
+ * @return Returns String.
+ * @see javax.xml.stream.XMLStreamReader#getAttributeNamespace
+ */
+ public String getAttributeNamespace(int i) {
+ String returnString = null;
+ if (parser != null) {
+ returnString = parser.getAttributeNamespace(i);
+ } else {
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
+ OMAttribute attrib = getAttribute((OMElement) lastNode, i);
+ if (attrib != null) {
+ OMNamespace nameSpace = attrib.getNamespace();
+ if (nameSpace != null) {
+ returnString = nameSpace.getName();
+ }
+ }
+ } else {
+ throw new IllegalStateException(
+ "attribute nameSpace accessed in illegal event!");
+ }
+ }
+ return returnString;
+ }
+
+ /**
+ * @param i
+ * @return Returns QName.
+ * @see javax.xml.stream.XMLStreamReader#getAttributeName
+ */
+ public QName getAttributeName(int i) {
+ QName returnQName = null;
+ if (parser != null) {
+ returnQName = parser.getAttributeName(i);
+ } else {
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
+ returnQName = getAttribute((OMElement) lastNode, i).getQName();
+ } else {
+ throw new IllegalStateException(
+ "attribute count accessed in illegal event!");
+ }
+ }
+ return returnQName;
+ }
+
+ /**
+ * @return Returns int.
+ * @see javax.xml.stream.XMLStreamReader#getAttributeCount
+ */
+ public int getAttributeCount() {
+ int returnCount = 0;
+ if (parser != null) {
+ returnCount = parser.getAttributeCount();
+ } else {
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
+ OMElement elt = (OMElement) lastNode;
+ returnCount = getCount(elt.getAllAttributes());
+ } else {
+ throw new IllegalStateException(
+ "attribute count accessed in illegal event ("
+ + currentEvent + ")!");
+ }
+ }
+ return returnCount;
+ }
+
+ // todo
+
+ /**
+ * Method getAttributeValue.
+ *
+ * @param s
+ * @param s1
+ * @return Returns String.
+ */
+ public String getAttributeValue(String s, String s1) {
+ String returnString = null;
+ if (parser != null) {
+ returnString = parser.getAttributeValue(s, s1);
+ } else {
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
+ QName qname = new QName(s, s1);
+ OMAttribute attrib = ((OMElement) lastNode).getAttribute(qname);
+ if (attrib != null) {
+ returnString = attrib.getAttributeValue();
+ }
+ } else {
+ throw new IllegalStateException(
+ "attribute type accessed in illegal event!");
+ }
+ }
+ return returnString;
+ }
+
+ /**
+ * Method isWhiteSpace.
+ *
+ * @return Returns boolean.
+ */
+ public boolean isWhiteSpace() {
+ boolean b;
+ if (parser != null) {
+ b = parser.isWhiteSpace();
+ } else {
+ b = (currentEvent == SPACE);
+ }
+ return b;
+ }
+
+ /**
+ * Method isCharacters.
+ *
+ * @return Returns boolean.
+ */
+ public boolean isCharacters() {
+ boolean b;
+ if (parser != null) {
+ b = parser.isCharacters();
+ } else {
+ b = (currentEvent == CHARACTERS);
+ }
+ return b;
+ }
+
+ /**
+ * Method isEndElement.
+ *
+ * @return Returns boolean.
+ */
+ public boolean isEndElement() {
+ boolean b;
+ if (parser != null) {
+ b = parser.isEndElement();
+ } else {
+ b = (currentEvent == END_ELEMENT);
+ }
+ return b;
+ }
+
+ /**
+ * @param i
+ * @param s
+ * @param s1
+ * @throws XMLStreamException
+ * @see javax.xml.stream.XMLStreamReader#require(int, String, String)
+ */
+ public void require(int i, String s, String s1) throws XMLStreamException {
+ throw new XMLStreamException();
+ }
+
+ /**
+ * Method isStartElement.
+ *
+ * @return Returns boolean.
+ */
+ public boolean isStartElement() {
+ boolean b;
+ if (parser != null) {
+ b = parser.isStartElement();
+ } else {
+ b = (currentEvent == START_ELEMENT);
+ }
+ return b;
+ }
+
+ /**
+ * Method getNamespaceURI.
+ *
+ * @param s
+ * @return Returns String.
+ */
+ public String getNamespaceURI(String s) {
+ String returnString = null;
+ if (parser != null) {
+ returnString = parser.getNamespaceURI(s);
+ } else {
+ if (isStartElement() || isEndElement()
+ || (currentEvent == NAMESPACE)) {
+
+ // Nothing to do here! How to get the namespacace references
+ }
+ }
+ return returnString;
+ }
+
+ /**
+ * Method close.
+ *
+ * @throws XMLStreamException
+ */
+ public void close() throws XMLStreamException {
+
+ // this doesnot mean anything with respect to the OM
+ if (parser != null) {
+ parser.close();
+ }
+ }
+
+ /**
+ * Method hasNext.
+ *
+ * @return Returns boolean.
+ * @throws XMLStreamException
+ */
+ public boolean hasNext() throws XMLStreamException {
+ if (needToThrowEndDocument) {
+ return !(state == DOCUMENT_COMPLETE);
+ } else {
+ return (state != COMPLETED && currentEvent != END_DOCUMENT);
+ }
+ }
+
+ /**
+ * Not implemented yet
+ *
+ * @return Returns int.
+ * @throws org.apache.ws.commons.om.impl.llom.exception.OMStreamingException
+ *
+ * @throws XMLStreamException
+ */
+ public int nextTag() throws XMLStreamException {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @return Returns String.
+ * @throws XMLStreamException
+ * @see javax.xml.stream.XMLStreamReader#getElementText()
+ */
+ public String getElementText() throws XMLStreamException {
+ String returnText = "";
+ if (parser != null) {
+ try {
+ returnText = parser.getElementText();
+ } catch (XMLStreamException e) {
+ throw new OMStreamingException(e);
+ }
+ } else {
+ if (currentNode.getType() == OMNode.ELEMENT_NODE) {
+ returnText = ((OMElement) currentNode).getText();
+ } else if (currentNode.getType() == OMNode.TEXT_NODE) {
+ returnText = ((OMText) currentNode).getText();
+ }
+ }
+ return returnText;
+ }
+
+ /**
+ * Method next.
+ *
+ * @return Returns int.
+ * @throws XMLStreamException
+ */
+ public int next() throws XMLStreamException {
+ switch (state) {
+ case DOCUMENT_COMPLETE:
+ throw new XMLStreamException("End of the document reached");
+ case COMPLETED:
+ state = DOCUMENT_COMPLETE;
+ currentEvent = END_DOCUMENT;
+ break;
+ case SWITCH_AT_NEXT:
+ state = SWITCHED;
+
+ // load the parser
+ try {
+ parser = (XMLStreamReader) builder.getParser();
+ } catch (Exception e) {
+ throw new XMLStreamException("problem accessing the parser", e);
+ }
+
+ if ((currentEvent == START_DOCUMENT)
+ && (currentEvent == parser.getEventType())) {
+ currentEvent = parser.next();
+ } else {
+ currentEvent = parser.getEventType();
+ }
+ updateCompleteStatus();
+ break;
+ case NAVIGABLE:
+ currentEvent = generateEvents(currentNode);
+ updateCompleteStatus();
+ updateLastNode();
+ break;
+ case SWITCHED:
+ currentEvent = parser.next();
+ updateCompleteStatus();
+ break;
+ default:
+ throw new OMStreamingException("unsuppported state!");
+ }
+ return currentEvent;
+ }
+
+ /**
+ * Method getProperty.
+ *
+ * @param s
+ * @return Returns Object.
+ * @throws IllegalArgumentException
+ */
+ public Object getProperty(String s) throws IllegalArgumentException {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * This is a very important method. This keeps the navigator one step ahead
+ * and pushes the navigator one event ahead. If the nextNode is null then
+ * navigable is set to false; At the same time the parser and builder are
+ * set up for the upcoming event generation
+ *
+ * @throws XMLStreamException
+ */
+ private void updateLastNode() throws XMLStreamException {
+ lastNode = currentNode;
+ currentNode = nextNode;
+ try {
+ updateNextNode();
+ } catch (Exception e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ /**
+ * Method updateNextNode.
+ */
+ private void updateNextNode() {
+ if (navigator.isNavigable()) {
+ nextNode = navigator.next();
+ } else {
+ if (!switchingAllowed) {
+ if (navigator.isCompleted()) {
+ nextNode = null;
+
+ } else {
+ builder.next();
+ navigator.step();
+ nextNode = navigator.next();
+ }
+ } else {
+
+ // reset caching (the default is ON so it was not needed in the
+ // earlier case!
+ builder.setCache(false);
+ state = SWITCH_AT_NEXT;
+ }
+ }
+ }
+
+ /**
+ * Method updateCompleteStatus.
+ */
+ private void updateCompleteStatus() {
+ if (state == NAVIGABLE) {
+ if (rootNode == currentNode) {
+ if (isFirst) {
+ isFirst = false;
+ } else {
+ state = COMPLETED;
+ }
+ }
+ } else {
+ state = (currentEvent == END_DOCUMENT) ? DOCUMENT_COMPLETE : state;
+ }
+ }
+
+ /**
+ * Method getNamespaceContext.
+ *
+ * @return Returns NamespaceContext.
+ */
+ public NamespaceContext getNamespaceContext() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Method getEncoding.
+ *
+ * @return Returns String.
+ */
+ public String getEncoding() {
+ return null;
+ }
+
+ /**
+ * Method getLocation.
+ *
+ * @return Returns Location.
+ */
+ public Location getLocation() {
+ return new EmptyOMLocation();
+ }
+
+ /**
+ * Method getVersion.
+ *
+ * @return Returns String.
+ */
+ public String getVersion() {
+ return "1.0"; // todo put the constant
+ }
+
+ /**
+ * Method isStandalone.
+ *
+ * @return Returns boolean.
+ */
+ public boolean isStandalone() {
+ return true;
+ }
+
+ /**
+ * Method standaloneSet.
+ *
+ * @return Returns boolean.
+ */
+ public boolean standaloneSet() {
+ return false;
+ }
+
+ /**
+ * Method getCharacterEncodingScheme.
+ *
+ * @return Returns String.
+ */
+ public String getCharacterEncodingScheme() {
+ return "utf-8";
+ }
+
+ /**
+ * Method getPITarget.
+ *
+ * @return Returns String.
+ */
+ public String getPITarget() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Method getPIData.
+ *
+ * @return Returns String.
+ */
+ public String getPIData() {
+ throw new UnsupportedOperationException();
+ }
+
+ /*
+ *
+ * ################################################################
+ * Generator methods for the OMNodes returned by the navigator
+ * ################################################################
+ *
+ */
+
+ /**
+ * Method generateEvents
+ *
+ * @param node
+ * @return Returns int.
+ */
+ private int generateEvents(OMNode node) {
+ int returnEvent = 0;
+ int nodeType = node.getType();
+ switch (nodeType) {
+ case Node.ELEMENT_NODE:
+ OMElement element = (OMElement) node;
+ returnEvent = generateElementEvents(element);
+ break;
+ case Node.TEXT_NODE:
+ returnEvent = generateTextEvents();
+ break;
+ case Node.COMMENT_NODE:
+ returnEvent = generateCommentEvents();
+ break;
+ case Node.CDATA_SECTION_NODE:
+ returnEvent = generateCdataEvents();
+ break;
+ default:
+ break; // just ignore any other nodes
+ }
+ return returnEvent;
+ }
+
+ /**
+ * Method generateElementEvents.
+ *
+ * @param elt
+ * @return Returns int.
+ */
+ private int generateElementEvents(OMElement elt) {
+ int returnValue = START_ELEMENT;
+ if (!elementStack.isEmpty() && elementStack.peek().equals(elt)) {
+ returnValue = END_ELEMENT;
+ elementStack.pop();
+ } else {
+ elementStack.push(elt);
+ }
+ return returnValue;
+ }
+
+ /**
+ * Method generateTextEvents.
+ *
+ * @return Returns int.
+ */
+ private int generateTextEvents() {
+ return CHARACTERS;
+ }
+
+ /**
+ * Method generateCommentEvents.
+ *
+ * @return Returns int.
+ */
+ private int generateCommentEvents() {
+ return COMMENT;
+ }
+
+ /**
+ * Method generateCdataEvents.
+ *
+ * @return Returns int.
+ */
+ private int generateCdataEvents() {
+ return CDATA;
+ }
+
+ /*
+ * ####################################################################
+ * Other helper methods
+ * ####################################################################
+ */
+
+ /**
+ * helper method.
+ *
+ * @param it
+ * @return Returns int.
+ */
+ private int getCount(Iterator it) {
+ int count = 0;
+ if (it != null) {
+ while (it.hasNext()) {
+ it.next();
+ count++;
+ }
+ }
+ return count;
+ }
+
+ /**
+ * Helper method.
+ *
+ * @param it
+ * @param index
+ * @return Returns Object.
+ */
+ private Object getItemFromIterator(Iterator it, int index) {
+ int count = 0;
+ Object returnObject = null;
+ boolean found = false;
+ if (it != null) {
+ while (it.hasNext()) {
+ returnObject = it.next();
+ if (index == count++) {
+ found = true;
+ break;
+ }
+ }
+ }
+ if (found) {
+ return returnObject;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Helper method.
+ *
+ * @param element
+ * @return Returns QName.
+ */
+ private QName getQName(OMElement element) {
+ QName returnName;
+ OMNamespace ns = element.getNamespace();
+ String localPart = element.getLocalName();
+ if (ns != null) {
+ String prefix = ns.getPrefix();
+ String uri = ns.getName();
+ if ((prefix == null) || prefix.equals("")) {
+ returnName = new QName(uri, localPart);
+ } else {
+ returnName = new QName(uri, localPart, prefix);
+ }
+ } else {
+ returnName = new QName(localPart);
+ }
+ return returnName;
+ }
+
+ /**
+ * @param elt
+ * @param index
+ * @return Returns OMAttribute.
+ */
+ private OMAttribute getAttribute(OMElement elt, int index) {
+ OMAttribute returnAttrib = null;
+ if (elt != null) {
+ returnAttrib = (OMAttribute) getItemFromIterator(elt
+ .getAllAttributes(), index);
+ }
+ return returnAttrib;
+ }
+
+ public void setParser(XMLStreamReader parser) {
+ this.parser = parser;
+ }
+}
Added: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMUtil.java?rev=374025&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMUtil.java (added)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DOMUtil.java Wed Feb 1 00:58:23 2006
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.om.impl.dom;
+
+/**
+ * Utility class for the OM-DOM implementation
+ */
+class DOMUtil {
+
+ public static boolean isValidChras(String value) {
+ // TODO check for valid characters
+ // throw new UnsupportedOperationException("TODO");
+ return true;
+ }
+
+ public static boolean isValidNamespace(String namespaceURI,
+ String qualifiedname) {
+ // TODO check for valid namespace
+ /**
+ * if the qualifiedName has a prefix and the namespaceURI is null, if
+ * the qualifiedName has a prefix that is "xml" and the namespaceURI is
+ * different from " http://www.w3.org/XML/1998/namespace", or if the
+ * qualifiedName, or its prefix, is "xmlns" and the namespaceURI is
+ * different from " http://www.w3.org/2000/xmlns/".
+ */
+ // throw new UnsupportedOperationException("TODO");
+ // temporary fix
+ return true;
+ }
+
+ /**
+ * Get the local name from a qualified name
+ *
+ * @param qualifiedName
+ * @return
+ */
+ public static String getLocalName(String qualifiedName) {
+ if (qualifiedName.indexOf(":") > -1
+ && !qualifiedName.trim().endsWith(":")) {
+ return qualifiedName.split(":")[1];
+ } else {
+ return qualifiedName;
+ }
+ }
+
+ /**
+ * Get the prefix from a qualified name
+ *
+ * @param qualifiedName
+ * @return
+ */
+ public static String getPrefix(String qualifiedName) {
+ if (qualifiedName.indexOf(":") > -1) {
+ return qualifiedName.split(":")[0];
+ } else {
+ return null;
+ }
+ }
+}
Added: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DocumentFragmentimpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DocumentFragmentimpl.java?rev=374025&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DocumentFragmentimpl.java (added)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DocumentFragmentimpl.java Wed Feb 1 00:58:23 2006
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.om.impl.dom;
+
+import org.apache.ws.commons.om.OMException;
+import org.apache.ws.commons.om.impl.OMOutputImpl;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Node;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+public class DocumentFragmentimpl extends ParentNode implements
+ DocumentFragment {
+
+ /**
+ * @param ownerDocument
+ */
+ public DocumentFragmentimpl(DocumentImpl ownerDocument) {
+ super(ownerDocument);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.w3c.dom.Node#getNodeType()
+ */
+ public short getNodeType() {
+ return Node.DOCUMENT_FRAGMENT_NODE;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.w3c.dom.Node#getNodeName()
+ */
+ public String getNodeName() {
+ return "#document-fragment";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.ws.commons.om.OMNode#getType()
+ */
+ public int getType() throws OMException {
+ return Node.DOCUMENT_FRAGMENT_NODE;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.ws.commons.om.OMNode#setType(int)
+ */
+ public void setType(int nodeType) throws OMException {
+ // DO Nothing :-?
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.ws.commons.om.OMNode#serializeWithCache(org.apache.ws.commons.om.OMOutput)
+ */
+ public void serializeWithCache(OMOutputImpl omOutput)
+ throws XMLStreamException {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.ws.commons.om.OMNode#serialize(org.apache.ws.commons.om.OMOutput)
+ */
+ public void serialize(OMOutputImpl omOutput) throws XMLStreamException {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void serializeAndConsume(OMOutputImpl omOutput)
+ throws XMLStreamException {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void serializeAndConsume(XMLStreamWriter xmlWriter)
+ throws XMLStreamException {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DocumentImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DocumentImpl.java?rev=374025&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DocumentImpl.java (added)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/DocumentImpl.java Wed Feb 1 00:58:23 2006
@@ -0,0 +1,531 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.om.impl.dom;
+
+import org.apache.ws.commons.om.OMConstants;
+import org.apache.ws.commons.om.OMContainer;
+import org.apache.ws.commons.om.OMDocument;
+import org.apache.ws.commons.om.OMElement;
+import org.apache.ws.commons.om.OMException;
+import org.apache.ws.commons.om.OMNode;
+import org.apache.ws.commons.om.OMOutputFormat;
+import org.apache.ws.commons.om.OMXMLParserWrapper;
+import org.apache.ws.commons.om.impl.OMOutputImpl;
+import org.apache.axis2.util.XMLChar;
+import org.w3c.dom.Attr;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Comment;
+import org.w3c.dom.DOMConfiguration;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.OutputStream;
+import java.util.Hashtable;
+
+public class DocumentImpl extends ParentNode implements Document, OMDocument {
+
+ protected Hashtable identifiers;
+
+ private String xmlVersion;
+
+ private String charEncoding;
+
+ protected ElementImpl documentElement;
+
+ /**
+ * @param ownerDocument
+ */
+ public DocumentImpl(DocumentImpl ownerDocument) {
+ super(ownerDocument);
+ }
+
+ public DocumentImpl(OMXMLParserWrapper parserWrapper) {
+ this.builder = parserWrapper;
+ }
+
+ public DocumentImpl() {
+
+ }
+
+ // /
+ // /OMNode methods
+ // //
+ public void setType(int nodeType) throws OMException {
+ throw new UnsupportedOperationException(
+ "In OM Document object doesn't have a type");
+ }
+
+ public int getType() throws OMException {
+ throw new UnsupportedOperationException(
+ "In OM Document object doesn't have a type");
+ }
+
+ public void serialize(OMOutputImpl omOutput) throws XMLStreamException {
+ // TODO Auto-generated method stub
+ }
+
+ // /
+ // /Overrides ChildNode specific methods.
+ // /
+ public OMNode getNextOMSibling() throws OMException {
+ throw new UnsupportedOperationException("This is the document node");
+ }
+
+ public Node getNextSibling() {
+ throw new UnsupportedOperationException("This is the document node");
+ }
+
+ public OMContainer getParent() throws OMException {
+ throw new UnsupportedOperationException("This is the document node");
+ }
+
+ public OMNode getPreviousOMSibling() {
+ throw new UnsupportedOperationException("This is the document node");
+ }
+
+ public Node getPreviousSibling() {
+ throw new UnsupportedOperationException("This is the document node");
+ }
+
+ public void setNextOMSibling(OMNode node) {
+ throw new UnsupportedOperationException("This is the document node");
+ }
+
+ public void setParent(OMContainer element) {
+ throw new UnsupportedOperationException("This is the document node");
+ }
+
+ public void setPreviousOMSibling(OMNode node) {
+ throw new UnsupportedOperationException("This is the document node");
+ }
+
+ // /
+ // /org.w3c.dom.Node methods
+ // /
+ public String getNodeName() {
+ return "#document";
+ }
+
+ public short getNodeType() {
+ return Node.DOCUMENT_NODE;
+ }
+
+ // /org.w3c.dom.Document methods
+ // /
+
+ public Attr createAttribute(String name) throws DOMException {
+ if (!DOMUtil.isValidChras(name)) {
+ String msg = DOMMessageFormatter.formatMessage(
+ DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR",
+ null);
+ throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
+ }
+ return new AttrImpl(this, name);
+ }
+
+ public Attr createAttributeNS(String namespaceURI, String qualifiedName)
+ throws DOMException {
+ if (!namespaceURI.equals(OMConstants.XMLNS_NS_URI)) {
+ String localName = DOMUtil.getLocalName(qualifiedName);
+ String prefix = DOMUtil.getPrefix(qualifiedName);
+
+ this.checkQName(prefix, localName);
+
+ return new AttrImpl(this, localName, new NamespaceImpl(
+ namespaceURI, prefix));
+ } else {
+ // Do nothing since we handle the 'xmlns:' internally
+ return null;
+ }
+ }
+
+ public CDATASection createCDATASection(String arg0) throws DOMException {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public Comment createComment(String data) {
+ return new CommentImpl(this, data);
+ }
+
+ public DocumentFragment createDocumentFragment() {
+ return new DocumentFragmentimpl(this);
+ }
+
+ public Element createElement(String tagName) throws DOMException {
+ return new ElementImpl(this, tagName);
+ }
+
+ public Element createElementNS(String ns, String qualifiedName)
+ throws DOMException {
+
+ String localName = DOMUtil.getLocalName(qualifiedName);
+ String prefix = DOMUtil.getPrefix(qualifiedName);
+
+ if (ns != null && (prefix != null || "".equals(prefix))) {
+ this.checkQName(prefix, localName);
+ }
+
+ NamespaceImpl namespace = new NamespaceImpl(ns, prefix);
+ return new ElementImpl(this, localName, namespace);
+ }
+
+ public EntityReference createEntityReference(String arg0)
+ throws DOMException {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public ProcessingInstruction createProcessingInstruction(String arg0,
+ String arg1) throws DOMException {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public Text createTextNode(String value) {
+ return new TextImpl(this, value);
+ }
+
+ public DocumentType getDoctype() {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public Element getElementById(String arg0) {
+ // TODO getElementById
+ throw new UnsupportedOperationException("TODO: getElementById");
+ }
+
+ public NodeList getElementsByTagName(String arg0) {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public NodeList getElementsByTagNameNS(String arg0, String arg1) {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public DOMImplementation getImplementation() {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public Node importNode(Node importedNode, boolean deep) throws DOMException {
+
+ short type = importedNode.getNodeType();
+ Node newNode = null;
+ switch (type) {
+ case Node.ELEMENT_NODE: {
+ Element newElement;
+ if (importedNode.getLocalName() == null) {
+ newElement = this.createElement(importedNode.getNodeName());
+ } else {
+ newElement = createElementNS(importedNode.getNamespaceURI(),
+ importedNode.getNodeName());
+ }
+
+ // Copy element's attributes, if any.
+ NamedNodeMap sourceAttrs = importedNode.getAttributes();
+ if (sourceAttrs != null) {
+ int length = sourceAttrs.getLength();
+ for (int index = 0; index < length; index++) {
+ Attr attr = (Attr) sourceAttrs.item(index);
+ if (attr.getNamespaceURI() != null
+ && !attr.getNamespaceURI().equals(
+ OMConstants.XMLNS_NS_URI)) {
+ Attr newAttr = (Attr) importNode(attr, true);
+ newElement.setAttributeNodeNS(newAttr);
+ } else if (attr.getLocalName() == null) {
+ Attr newAttr = (Attr) importNode(attr, true);
+ newElement.setAttributeNode(newAttr);
+ }
+
+ }
+ }
+ newNode = newElement;
+ break;
+ }
+
+ case Node.ATTRIBUTE_NODE: {
+ if (importedNode.getLocalName() == null) {
+ newNode = createAttribute(importedNode.getNodeName());
+ } else {
+ newNode = createAttributeNS(importedNode.getNamespaceURI(),
+ importedNode.getNodeName());
+ }
+ ((Attr) newNode).setValue(importedNode.getNodeValue());
+ break;
+ }
+
+ case Node.TEXT_NODE: {
+ newNode = createTextNode(importedNode.getNodeValue());
+ break;
+ }
+
+ case Node.DOCUMENT_FRAGMENT_NODE: {
+ newNode = createDocumentFragment();
+ // No name, kids carry value
+ break;
+ }
+
+ case Node.CDATA_SECTION_NODE:
+ case Node.ENTITY_REFERENCE_NODE:
+ case Node.ENTITY_NODE:
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ case Node.COMMENT_NODE:
+ case Node.DOCUMENT_TYPE_NODE:
+ case Node.NOTATION_NODE:
+ throw new UnsupportedOperationException("TODO");
+
+ case Node.DOCUMENT_NODE: // Can't import document nodes
+ default: { // Unknown node type
+ String msg = DOMMessageFormatter.formatMessage(
+ DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null);
+ throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
+ }
+
+ }
+
+ // If deep, replicate and attach the kids.
+ if (deep) {
+ for (Node srckid = importedNode.getFirstChild(); srckid != null;
+ srckid = srckid.getNextSibling()) {
+ newNode.appendChild(importNode(srckid, true));
+ }
+ }
+
+ return newNode;
+
+ }
+
+ public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void serializeAndConsume(OMOutputImpl omOutput)
+ throws XMLStreamException {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void serializeAndConsume(XMLStreamWriter xmlWriter)
+ throws XMLStreamException {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ // /
+ // /OMDocument Methods
+ // /
+ public String getCharsetEncoding() {
+ return this.charEncoding;
+ }
+
+ public String getXMLVersion() {
+ return this.xmlVersion;
+ }
+
+ public String isStandalone() {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void serialize(OMOutputImpl omOutput, boolean includeXMLDeclaration)
+ throws XMLStreamException {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void serializeAndConsume(OMOutputImpl omOutput,
+ boolean includeXMLDeclaration) throws XMLStreamException {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void setCharsetEncoding(String charsetEncoding) {
+ this.charEncoding = charsetEncoding;
+ }
+
+ public void setOMDocumentElement(OMElement rootElement) {
+ this.firstChild = (ElementImpl) rootElement;
+ }
+
+ public void setStandalone(String isStandalone) {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void serializeAndConsume(OutputStream output, OMOutputFormat format)
+ throws XMLStreamException {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void serialize(OutputStream output, OMOutputFormat format)
+ throws XMLStreamException {
+ // TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void setXMLVersion(String version) {
+ this.xmlVersion = version;
+ }
+
+ /**
+ * Returns the document element.
+ *
+ * @see org.apache.ws.commons.om.OMDocument#getOMDocumentElement()
+ */
+ public OMElement getOMDocumentElement() {
+
+ //We'r sure that only an element can be the first child of a Document
+ if (this.documentElement == null && !this.done) {
+ this.build();
+ }
+ return this.documentElement;
+ }
+
+ /**
+ * Returns the document element.
+ *
+ * @see org.w3c.dom.Document#getDocumentElement()
+ */
+ public Element getDocumentElement() {
+
+ return (Element) this.getOMDocumentElement();
+ }
+
+ /**
+ * Borrowed from the Xerces impl. Checks if the given qualified name is
+ * legal with respect to the version of XML to which this document must
+ * conform.
+ *
+ * @param prefix
+ * prefix of qualified name
+ * @param local
+ * local part of qualified name
+ */
+ protected final void checkQName(String prefix, String local) {
+
+ // check that both prefix and local part match NCName
+ boolean validNCName = (prefix == null || XMLChar.isValidNCName(prefix))
+ && XMLChar.isValidNCName(local);
+
+ if (!validNCName) {
+ // REVISIT: add qname parameter to the message
+ String msg = DOMMessageFormatter.formatMessage(
+ DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR",
+ null);
+ throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
+ }
+
+ if (prefix == null || prefix.equals("")) {
+ String msg = DOMMessageFormatter.formatMessage(
+ DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null);
+ throw new DOMException(DOMException.NAMESPACE_ERR, msg);
+ }
+ }
+
+ /*
+ * DOM-Level 3 methods
+ */
+
+ public Node adoptNode(Node arg0) throws DOMException {
+ // TODO TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public String getDocumentURI() {
+ // TODO TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public DOMConfiguration getDomConfig() {
+ // TODO TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public String getInputEncoding() {
+ // TODO TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public boolean getStrictErrorChecking() {
+ // TODO TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public String getXmlEncoding() {
+ // TODO TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public boolean getXmlStandalone() {
+ // TODO TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public String getXmlVersion() {
+ // TODO TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void normalizeDocument() {
+ // TODO TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public Node renameNode(Node arg0, String arg1, String arg2)
+ throws DOMException {
+ // TODO TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void setDocumentURI(String arg0) {
+ // TODO TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void setStrictErrorChecking(boolean arg0) {
+ // TODO TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void setXmlStandalone(boolean arg0) throws DOMException {
+ // TODO TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ public void setXmlVersion(String arg0) throws DOMException {
+ // TODO TODO
+ throw new UnsupportedOperationException("TODO");
+ }
+
+}