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 di...@apache.org on 2005/02/20 04:01:03 UTC
svn commit: r154468 [2/6] - in webservices/axis/trunk/java/modules/om/src:
java/org/apache/axis/om/ java/org/apache/axis/om/impl/llom/
java/org/apache/axis/om/impl/llom/builder/
java/org/apache/axis/om/impl/llom/exception/
java/org/apache/axis/om/impl/llom/factory/
java/org/apache/axis/om/impl/llom/serialize/
java/org/apache/axis/om/impl/llom/traverse/ test-resources/
test-resources/badsoap/ test-resources/soap/ test/org/apache/axis/om/
test/org/apache/axis/om/factory/ test/org/apache/axis/om/impl/builder/
test/org/apache/axis/om/impl/serializer/
test/org/apache/axis/om/impl/streamwrapper/
test/org/apache/axis/om/impl/traverse/
Modified: webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMElementImpl.java?view=diff&r1=154467&r2=154468
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMElementImpl.java (original)
+++ webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMElementImpl.java Sat Feb 19 19:00:47 2005
@@ -1,19 +1,18 @@
/*
* 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.axis.om.impl.llom;
import org.apache.axis.om.OMAttribute;
@@ -39,23 +38,50 @@
import java.util.HashMap;
import java.util.Iterator;
-public class OMElementImpl
- extends OMNamedNodeImpl
+/**
+ * Class OMElementImpl
+ */
+public class OMElementImpl extends OMNamedNodeImpl
implements OMElement, OMConstants {
+ /**
+ * Field firstChild
+ */
protected OMNode firstChild;
+
+ /**
+ * Field builder
+ */
protected OMXMLParserWrapper builder;
- // (prefix,uri) one element "can" have same nsURI with different prefixes
+ /**
+ * Field namespaces
+ */
private HashMap namespaces = null;
+ /**
+ * Field attributes
+ */
private HashMap attributes = null;
+
+ /**
+ * Field log
+ */
private Log log = LogFactory.getLog(getClass());
+ /**
+ * Field noPrefixNamespaceCounter
+ */
private int noPrefixNamespaceCounter = 0;
- public OMElementImpl(String localName,
- OMNamespace ns,
- OMElement parent,
+ /**
+ * Constructor OMElementImpl
+ *
+ * @param localName
+ * @param ns
+ * @param parent
+ * @param builder
+ */
+ public OMElementImpl(String localName, OMNamespace ns, OMElement parent,
OMXMLParserWrapper builder) {
super(localName, null, parent);
if (ns != null) {
@@ -66,8 +92,7 @@
}
/**
- * @param localName
- * @param ns
+ * @param parent
* @param parent
*/
protected OMElementImpl(OMElement parent) {
@@ -75,39 +100,53 @@
this.done = true;
}
+ /**
+ * Constructor OMElementImpl
+ *
+ * @param localName
+ * @param ns
+ */
public OMElementImpl(String localName, OMNamespace ns) {
super(localName, null, null);
this.done = true;
if (ns != null) {
setNamespace(handleNamespace(ns));
}
-
}
/**
* Here it is assumed that this QName passed, at least contains the localName for this element
*
* @param qname
+ * @param parent
+ * @throws OMException
*/
public OMElementImpl(QName qname, OMElement parent) throws OMException {
super(qname.getLocalPart(), null, parent);
this.done = true;
handleNamespace(qname, parent);
-
}
+ /**
+ * Method handleNamespace
+ *
+ * @param qname
+ * @param parent
+ */
private void handleNamespace(QName qname, OMElement parent) {
OMNamespace ns;
// first try to find a namespace from the scope
String namespaceURI = qname.getNamespaceURI();
if (!"".equals(namespaceURI)) {
- ns = findInScopeNamespace(qname.getNamespaceURI(), qname.getPrefix());
+ ns = findInScopeNamespace(qname.getNamespaceURI(),
+ qname.getPrefix());
} else {
if (parent != null) {
ns = parent.getNamespace();
} else {
- throw new OMException("Element can not be declared without a namespaceURI. Every Element should be namespace qualified");
+ throw new OMException(
+ "Element can not be declared without a namespaceURI. Every Element should be namespace qualified");
}
}
@@ -116,8 +155,7 @@
* 1. nsURI = null & parent != null, but ns = null
* 2. nsURI != null, (parent doesn't have an ns with given URI), but ns = null
*/
-
- if (ns == null && !"".equals(namespaceURI)) {
+ if ((ns == null) && !"".equals(namespaceURI)) {
String prefix = qname.getPrefix();
if (!"".equals(prefix)) {
ns = declareNamespace(namespaceURI, prefix);
@@ -126,14 +164,21 @@
}
}
if (ns == null) {
- throw new OMException("Element can not be declared without a namespaceURI. Every Element should be namespace qualified");
+ throw new OMException(
+ "Element can not be declared without a namespaceURI. Every Element should be namespace qualified");
}
this.setNamespace(ns);
}
+ /**
+ * Method handleNamespace
+ *
+ * @param ns
+ * @return
+ */
private OMNamespace handleNamespace(OMNamespace ns) {
- OMNamespace namespace =
- findInScopeNamespace(ns.getName(), ns.getPrefix());
+ OMNamespace namespace = findInScopeNamespace(ns.getName(),
+ ns.getPrefix());
if (namespace == null) {
namespace = declareNamespace(ns);
}
@@ -158,13 +203,20 @@
* @param elementQName
* @return
* @throws org.apache.axis.om.OMException
+ * @throws OMException
*/
- public Iterator getChildrenWithName(QName elementQName)
- throws OMException {
+ public Iterator getChildrenWithName(QName elementQName) throws OMException {
return new OMChildrenQNameIterator((OMNodeImpl) getFirstChild(),
elementQName);
}
+ /**
+ * Method getChildWithName
+ *
+ * @param elementQName
+ * @return
+ * @throws OMException
+ */
public OMNode getChildWithName(QName elementQName) throws OMException {
OMChildrenQNameIterator omChildrenQNameIterator =
new OMChildrenQNameIterator((OMNodeImpl) getFirstChild(),
@@ -176,9 +228,15 @@
return omNode;
}
+ /**
+ * Method addChild
+ *
+ * @param child
+ */
private void addChild(OMNodeImpl child) {
- if (firstChild == null && !done)
+ if ((firstChild == null) && !done) {
builder.next();
+ }
child.setPreviousSibling(null);
child.setNextSibling(firstChild);
if (firstChild != null) {
@@ -186,7 +244,6 @@
firstChildImpl.setPreviousSibling(child);
}
child.setParent(this);
- // child.setComplete(true);
firstChild = child;
}
@@ -195,22 +252,25 @@
*
* @return
* @throws org.apache.axis.om.OMException
+ * @throws OMException
*/
public OMNode getNextSibling() throws OMException {
- while (!done)
+ while (!done) {
builder.next();
+ }
return super.getNextSibling();
}
/**
* This returns a collection of this element.
* Children can be of types OMElement, OMText.
+ *
+ * @return
*/
public Iterator getChildren() {
return new OMChildrenIterator(getFirstChild());
}
- // --------------------- Namespace Methods ------------------------------------------------------------
/**
* THis will create a namespace in the current element scope
*
@@ -223,7 +283,11 @@
return declareNamespace(ns);
}
- //TODO correct this
+ /**
+ * Method setValue
+ *
+ * @param value
+ */
public void setValue(String value) {
OMText txt = OMFactory.newInstance().createText(value);
this.addChild(txt);
@@ -250,6 +314,7 @@
* @param prefix
* @return
* @throws org.apache.axis.om.OMException
+ * @throws OMException
*/
public OMNamespace findInScopeNamespace(String uri, String prefix)
throws OMException {
@@ -259,9 +324,11 @@
if (namespace != null) {
return namespace;
}
+
// go up to check with ancestors
- if (parent != null)
+ if (parent != null) {
return parent.findInScopeNamespace(uri, prefix);
+ }
return null;
}
@@ -293,6 +360,11 @@
}
}
+ /**
+ * Method getAllDeclaredNamespaces
+ *
+ * @return
+ */
public Iterator getAllDeclaredNamespaces() {
if (namespaces == null) {
return null;
@@ -300,14 +372,13 @@
return namespaces.values().iterator();
}
- // ---------------------------------------------------------------------------------------------------------------
-
/**
* This will help to search for an attribute with a given QName within this Element
*
* @param qname
* @return
* @throws org.apache.axis.om.OMException
+ * @throws OMException
*/
public OMAttribute getAttributeWithQName(QName qname) throws OMException {
if (attributes == null) {
@@ -333,6 +404,7 @@
* in the front or at the end of set of attributes
*
* @param attr
+ * @return
*/
public OMAttribute insertAttribute(OMAttribute attr) {
if (attributes == null) {
@@ -342,22 +414,33 @@
return attr;
}
+ /**
+ * Method removeAttribute
+ *
+ * @param attr
+ */
public void removeAttribute(OMAttribute attr) {
if (attributes != null) {
attributes.remove(attr.getQName());
}
}
- public OMAttribute insertAttribute(String attributeName,
- String value,
+ /**
+ * Method insertAttribute
+ *
+ * @param attributeName
+ * @param value
+ * @param ns
+ * @return
+ */
+ public OMAttribute insertAttribute(String attributeName, String value,
OMNamespace ns) {
OMNamespace namespace = null;
if (ns != null) {
namespace = findInScopeNamespace(ns.getName(), ns.getPrefix());
if (namespace == null) {
- throw new OMException("Given OMNamespace("
- + ns.getName()
- + ns.getPrefix()
+ throw new OMException(
+ "Given OMNamespace(" + ns.getName() + ns.getPrefix()
+ ") for "
+ "this attribute is not declared in the scope of this element. First declare the namespace"
+ " and then use it with the attribute");
@@ -366,10 +449,20 @@
return insertAttribute(new OMAttributeImpl(attributeName, ns, value));
}
+ /**
+ * Method setBuilder
+ *
+ * @param wrapper
+ */
public void setBuilder(OMXMLParserWrapper wrapper) {
this.builder = wrapper;
}
+ /**
+ * Method getBuilder
+ *
+ * @return
+ */
public OMXMLParserWrapper getBuilder() {
return builder;
}
@@ -381,12 +474,23 @@
builder.next();
}
+ /**
+ * Method getFirstChild
+ *
+ * @return
+ */
public OMNode getFirstChild() {
- while (firstChild == null && !done)
+ while ((firstChild == null) && !done) {
buildNext();
+ }
return firstChild;
}
+ /**
+ * Method setFirstChild
+ *
+ * @param firstChild
+ */
public void setFirstChild(OMNode firstChild) {
this.firstChild = firstChild;
}
@@ -395,14 +499,21 @@
* This will remove this information item and its children, from the model completely
*
* @throws org.apache.axis.om.OMException
+ * @throws OMException
*/
public void detach() throws OMException {
- if (done)
+ if (done) {
super.detach();
- else
+ } else {
builder.discard(this);
+ }
}
+ /**
+ * Method isComplete
+ *
+ * @return
+ */
public boolean isComplete() {
return done;
}
@@ -415,6 +526,7 @@
*
* @return
* @throws org.apache.axis.om.OMException
+ * @throws OMException
*/
public String getValue() throws OMException {
throw new UnsupportedOperationException();
@@ -425,39 +537,51 @@
*
* @return
* @throws org.apache.axis.om.OMException
+ * @throws OMException
*/
public short getType() throws OMException {
return OMNode.ELEMENT_NODE;
}
/**
- *
+ * @param cacheOff
+ * @return
*/
public XMLStreamReader getPullParser(boolean cacheOff) {
- if (builder == null && cacheOff)
- throw new UnsupportedOperationException("This element was not created in a manner to be switched");
+ if ((builder == null) && cacheOff) {
+ throw new UnsupportedOperationException(
+ "This element was not created in a manner to be switched");
+ }
return new OMStAXWrapper(builder, this, cacheOff);
}
+ /**
+ * Method serialize
+ *
+ * @param writer
+ * @param cache
+ * @throws XMLStreamException
+ */
public void serialize(XMLStreamWriter writer, boolean cache)
throws XMLStreamException {
boolean firstElement = false;
- short builderType = PULL_TYPE_BUILDER; //default is pull type
- if (builder != null)
+ short builderType = PULL_TYPE_BUILDER; // default is pull type
+ if (builder != null) {
builderType = this.builder.getBuilderType();
- if (builderType == PUSH_TYPE_BUILDER
- && builder.getRegisteredContentHandler() == null) {
- builder.registerExternalContentHandler(new StreamWriterToContentHandlerConverter(writer));
- //for now only SAX
}
+ if ((builderType == PUSH_TYPE_BUILDER)
+ && (builder.getRegisteredContentHandler() == null)) {
+ builder.registerExternalContentHandler(
+ new StreamWriterToContentHandlerConverter(writer));
- //Special case for the pull type building with cache off
- //The getPullParser method returns the current elements itself.
+ // for now only SAX
+ }
+
+ // Special case for the pull type building with cache off
+ // The getPullParser method returns the current elements itself.
if (!cache) {
- if (firstChild == null
- && nextSibling == null
- && !isComplete()
- && builderType == PULL_TYPE_BUILDER) {
+ if ((firstChild == null) && (nextSibling == null) && !isComplete()
+ && (builderType == PULL_TYPE_BUILDER)) {
StreamingOMSerializer streamingOMSerializer =
new StreamingOMSerializer();
streamingOMSerializer.serialize(this.getPullParser(!cache),
@@ -467,10 +591,12 @@
}
if (!cache) {
if (isComplete()) {
- //serialize own normally
+
+ // serialize own normally
serializeNormal(writer, cache);
if (nextSibling != null) {
- //serilize next sibling
+
+ // serilize next sibling
nextSibling.serialize(writer, cache);
} else {
if (parent == null) {
@@ -478,31 +604,34 @@
} else if (parent.isComplete()) {
return;
} else {
- //do the special serialization
- //Only the push serializer is left now
+
+ // do the special serialization
+ // Only the push serializer is left now
builder.setCache(cache);
builder.next();
}
-
}
} else if (firstChild != null) {
serializeStartpart(writer);
- log.info("Serializing the Element from " + localName + " the generated OM tree");
+ log.info("Serializing the Element from " + localName
+ + " the generated OM tree");
firstChild.serialize(writer, cache);
serializeEndpart(writer);
} else {
- //do the special serilization
- //Only the push serializer is left now
+
+ // do the special serilization
+ // Only the push serializer is left now
builder.setCache(cache);
serializeStartpart(writer);
builder.next();
serializeEndpart(writer);
}
-
} else {
- //serialize own normally
+
+ // serialize own normally
serializeNormal(writer, cache);
- //serialize the siblings if this is not the first element
+
+ // serialize the siblings if this is not the first element
if (!firstElement) {
OMNode nextSibling = this.getNextSibling();
if (nextSibling != null) {
@@ -510,9 +639,14 @@
}
}
}
-
}
+ /**
+ * Method serializeStartpart
+ *
+ * @param writer
+ * @throws XMLStreamException
+ */
private void serializeStartpart(XMLStreamWriter writer)
throws XMLStreamException {
String nameSpaceName = null;
@@ -528,8 +662,7 @@
this.getLocalName());
} else {
if (prefix != null) {
- writer.writeStartElement(prefix,
- this.getLocalName(),
+ writer.writeStartElement(prefix, this.getLocalName(),
nameSpaceName);
writer.writeNamespace(prefix, nameSpaceName);
writer.setPrefix(prefix, nameSpaceName);
@@ -540,17 +673,16 @@
writer.setDefaultNamespace(nameSpaceName);
}
}
-
} else {
- throw new OMException("Non namespace qualified elements are not allowed");
-
+ throw new OMException(
+ "Non namespace qualified elements are not allowed");
}
-
} else {
- throw new OMException("Non namespace qualified elements are not allowed");
+ throw new OMException(
+ "Non namespace qualified elements are not allowed");
}
- //add the elements attributes
+ // add the elements attributes
if (attributes != null) {
Iterator attributesList = attributes.values().iterator();
while (attributesList.hasNext()) {
@@ -558,7 +690,7 @@
}
}
- //add the namespaces
+ // add the namespaces
Iterator namespaces = this.getAllDeclaredNamespaces();
if (namespaces != null) {
while (namespaces.hasNext()) {
@@ -567,11 +699,24 @@
}
}
+ /**
+ * Method serializeEndpart
+ *
+ * @param writer
+ * @throws XMLStreamException
+ */
private void serializeEndpart(XMLStreamWriter writer)
throws XMLStreamException {
writer.writeEndElement();
}
+ /**
+ * Method serializeNormal
+ *
+ * @param writer
+ * @param cache
+ * @throws XMLStreamException
+ */
private void serializeNormal(XMLStreamWriter writer, boolean cache)
throws XMLStreamException {
serializeStartpart(writer);
@@ -580,35 +725,48 @@
firstChild.serialize(writer, cache);
}
serializeEndpart(writer);
-
}
+ /**
+ * Method serializeAttribute
+ *
+ * @param attr
+ * @param writer
+ * @throws XMLStreamException
+ */
protected void serializeAttribute(OMAttribute attr, XMLStreamWriter writer)
throws XMLStreamException {
- //first check whether the attribute is associated with a namespace
+
+ // first check whether the attribute is associated with a namespace
OMNamespace ns = attr.getNamespace();
String prefix = null;
String namespaceName = null;
if (ns != null) {
- //add the prefix if it's availble
+
+ // add the prefix if it's availble
prefix = ns.getPrefix();
namespaceName = ns.getName();
- if (prefix != null)
- writer.writeAttribute(prefix,
- namespaceName,
- attr.getLocalName(),
- attr.getValue());
- else
- writer.writeAttribute(namespaceName,
- attr.getLocalName(),
+ if (prefix != null) {
+ writer.writeAttribute(prefix, namespaceName,
+ attr.getLocalName(), attr.getValue());
+ } else {
+ writer.writeAttribute(namespaceName, attr.getLocalName(),
attr.getValue());
+ }
} else {
writer.writeAttribute(attr.getLocalName(), attr.getValue());
}
}
- protected void serializeNamespace(OMNamespace namespace,
- XMLStreamWriter writer)
+ /**
+ * Method serializeNamespace
+ *
+ * @param namespace
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeNamespace(
+ OMNamespace namespace, XMLStreamWriter writer)
throws XMLStreamException {
if (namespace != null) {
String uri = namespace.getName();
@@ -621,8 +779,13 @@
}
}
+ /**
+ * Method getNextNamespacePrefix
+ *
+ * @return
+ */
private String getNextNamespacePrefix() {
return "ns" + ++noPrefixNamespaceCounter;
}
-
}
+
Modified: webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNamedNodeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNamedNodeImpl.java?view=diff&r1=154467&r2=154468
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNamedNodeImpl.java (original)
+++ webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNamedNodeImpl.java Sat Feb 19 19:00:47 2005
@@ -1,19 +1,18 @@
/*
* 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.axis.om.impl.llom;
import org.apache.axis.om.OMElement;
@@ -22,38 +21,98 @@
import org.apache.axis.om.OMNamespace;
import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.XMLStreamException;
+/**
+ * Class OMNamedNodeImpl
+ */
public class OMNamedNodeImpl extends OMNodeImpl implements OMNamedNode {
+ /**
+ * Field ns
+ */
protected OMNamespace ns;
+
+ /**
+ * Field localName
+ */
protected String localName;
+ /**
+ * Constructor OMNamedNodeImpl
+ *
+ * @param parent
+ */
public OMNamedNodeImpl(OMElement parent) {
super(parent);
}
+ /**
+ * Method serialize
+ *
+ * @param writer
+ * @param cache
+ * @throws javax.xml.stream.XMLStreamException
+ *
+ */
+ public void serialize(XMLStreamWriter writer, boolean cache)
+ throws XMLStreamException {
+ //TODO: do we need to do something here?
+ }
+
+ /**
+ * Constructor OMNamedNodeImpl
+ *
+ * @param localName
+ * @param ns
+ * @param parent
+ */
public OMNamedNodeImpl(String localName, OMNamespace ns, OMElement parent) {
super(parent);
this.localName = localName;
this.ns = ns;
}
+ /**
+ * Method getLocalName
+ *
+ * @return
+ */
public String getLocalName() {
return localName;
}
+ /**
+ * Method setLocalName
+ *
+ * @param localName
+ */
public void setLocalName(String localName) {
this.localName = localName;
}
+ /**
+ * Method getNamespace
+ *
+ * @return
+ * @throws OMException
+ */
public OMNamespace getNamespace() throws OMException {
- if (ns == null && parent != null) {
+ if ((ns == null) && (parent != null)) {
ns = parent.getNamespace();
}
- if (ns == null)
- throw new OMException("all elements in a soap message must be namespace qualified");
+ if (ns == null) {
+ throw new OMException(
+ "all elements in a soap message must be namespace qualified");
+ }
return ns;
}
+ /**
+ * Method getNamespaceName
+ *
+ * @return
+ */
public String getNamespaceName() {
if (ns != null) {
return ns.getName();
@@ -68,6 +127,11 @@
this.ns = namespace;
}
+ /**
+ * Method getQName
+ *
+ * @return
+ */
public QName getQName() {
QName qName = new QName(ns.getName(), localName, ns.getPrefix());
return qName;
Modified: webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNamespaceImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNamespaceImpl.java?view=diff&r1=154467&r2=154468
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNamespaceImpl.java (original)
+++ webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNamespaceImpl.java Sat Feb 19 19:00:47 2005
@@ -1,27 +1,37 @@
/*
* 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.axis.om.impl.llom;
import org.apache.axis.om.OMNamespace;
+/**
+ * Class OMNamespaceImpl
+ */
public class OMNamespaceImpl implements OMNamespace {
+ /**
+ * Field prefix
+ */
private String prefix;
+
+ /**
+ * Field uri
+ */
private String uri;
- //private String value;
+
+ // private String value;
/**
* @param uri
@@ -32,18 +42,33 @@
this.prefix = prefix;
}
+ /**
+ * Method equals
+ *
+ * @param uri
+ * @param prefix
+ * @return
+ */
public boolean equals(String uri, String prefix) {
- return ((prefix == null && this.prefix == null) || (prefix != null && prefix.equals(this.prefix)))
- && uri.equals(uri);
+ return (((prefix == null) && (this.prefix == null)) || ((prefix != null) && prefix.equals(
+ this.prefix))) && uri.equals(uri);
}
+ /**
+ * Method getPrefix
+ *
+ * @return
+ */
public String getPrefix() {
return prefix;
}
+ /**
+ * Method getName
+ *
+ * @return
+ */
public String getName() {
return uri;
}
-
-
}
Modified: webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNavigator.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNavigator.java?view=diff&r1=154467&r2=154468
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNavigator.java (original)
+++ webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNavigator.java Sat Feb 19 19:00:47 2005
@@ -1,144 +1,191 @@
/*
-/*
+ *
* 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.axis.om.impl.llom;
+ package org.apache.axis.om.impl.llom;
-import org.apache.axis.om.OMElement;
-import org.apache.axis.om.OMNode;
+ import org.apache.axis.om.OMElement;
+ import org.apache.axis.om.OMNode;
-/**
- * Refer to the testClass to find out how to use
- * features like isNavigable, isComplete and step
- */
-public class OMNavigator {
- protected OMNode node;
- private boolean visited;
- private OMNode next;
-
- //root is the starting element. Once the navigator comes back to the
- //root, the traversal is terminated
- private OMNode root;
- private boolean backtracked;
-
- //flags that tell the status of the navigator
- private boolean end = false;
- private boolean start = true;
-
- public OMNavigator() {
- }
-
- public OMNavigator(OMNode node) {
- init(node);
- }
-
- public void init(OMNode node) {
- next = node;
- root = node;
- backtracked = false;
- }
-
- /**
- * get the next node
- *
- * @return OMnode in the sequence of preorder traversal. Note however that an element node is
- * treated slightly diffrently. 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) {
- OMElementImpl e = (OMElementImpl) next;
- if (e.firstChild != null)
- next = e.firstChild;
- else if (e.isComplete())
- backtracked = true;
- else
- next = null;
-
- } else {
- OMNode nextSibling = ((OMNodeImpl) next).nextSibling;
- OMNode parent = next.getParent();
- if (nextSibling != null)
- next = nextSibling;
- else if (parent != null && parent.isComplete()) {
- next = parent;
- backtracked = true;
- } else
- next = null;
- }
- }
-
- 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();
- }
- }
-
- /**
- * the navigable status
- *
- * @return
- */
- public boolean isNavigable() {
- if (end)
- return false;
- else
- return !(next == null);
- }
-
- /**
- * The completed status
- *
- * @return
- */
- public boolean isCompleted() {
- return end;
- }
-}
+ /**
+ * Refer to the testClass to find out how to use
+ * features like isNavigable, isComplete and step
+ */
+ public class OMNavigator {
+ /**
+ * 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 OMNavigator() {
+ }
+
+ /**
+ * Constructor OMNavigator
+ *
+ * @param node
+ */
+ public OMNavigator(OMNode node) {
+ init(node);
+ }
+
+ /**
+ * Method init
+ *
+ * @param node
+ */
+ public void init(OMNode node) {
+ next = node;
+ root = node;
+ backtracked = false;
+ }
+
+ /**
+ * get the next node
+ *
+ * @return OMnode in the sequence of preorder traversal. Note however that an element node is
+ * treated slightly diffrently. 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) {
+ OMElementImpl e = (OMElementImpl) next;
+ if (e.firstChild != null) {
+ next = e.firstChild;
+ } else if (e.isComplete()) {
+ backtracked = true;
+ } else {
+ next = null;
+ }
+ } else {
+ OMNode nextSibling = ((OMNodeImpl) next).nextSibling;
+ OMNode parent = next.getParent();
+ if (nextSibling != null) {
+ next = nextSibling;
+ } else if ((parent != null) && parent.isComplete()) {
+ next = parent;
+ backtracked = true;
+ } else {
+ next = null;
+ }
+ }
+ }
+
+ /**
+ * Method visited
+ *
+ * @return
+ */
+ 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();
+ }
+ }
+
+ /**
+ * the navigable status
+ *
+ * @return
+ */
+ public boolean isNavigable() {
+ if (end) {
+ return false;
+ } else {
+ return !(next == null);
+ }
+ }
+
+ /**
+ * The completed status
+ *
+ * @return
+ */
+ public boolean isCompleted() {
+ return end;
+ }
+ }
Modified: webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNodeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNodeImpl.java?view=diff&r1=154467&r2=154468
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNodeImpl.java (original)
+++ webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMNodeImpl.java Sat Feb 19 19:00:47 2005
@@ -1,19 +1,18 @@
/*
* 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.axis.om.impl.llom;
import org.apache.axis.om.OMElement;
@@ -23,14 +22,43 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
-public class OMNodeImpl implements OMNode {
+/**
+ * Class OMNodeImpl
+ */
+public abstract class OMNodeImpl implements OMNode {
+ /**
+ * Field parent
+ */
protected OMElementImpl parent;
+
+ /**
+ * Field nextSibling
+ */
protected OMNodeImpl nextSibling;
+
+ /**
+ * Field previousSibling
+ */
protected OMNodeImpl previousSibling;
+
+ /**
+ * Field value
+ */
protected String value;
+
+ /**
+ * Field done
+ */
protected boolean done = false;
+
+ /**
+ * Field nodeType
+ */
protected short nodeType;
+ /**
+ * Constructor OMNodeImpl
+ */
public OMNodeImpl() {
}
@@ -40,7 +68,7 @@
* @param parent
*/
public OMNodeImpl(OMElement parent) {
- if (parent != null && parent.getType() == OMNode.ELEMENT_NODE) {
+ if ((parent != null) && (parent.getType() == OMNode.ELEMENT_NODE)) {
this.parent = (OMElementImpl) parent;
}
}
@@ -51,14 +79,21 @@
*
* @return
* @throws org.apache.axis.om.OMException
+ * @throws OMException
*/
public OMElement getParent() throws OMException {
return parent;
}
+ /**
+ * Method setParent
+ *
+ * @param element
+ */
public void setParent(OMElement element) {
- if (element instanceof OMNodeImpl)
+ if (element instanceof OMNodeImpl) {
this.parent = (OMElementImpl) element;
+ }
}
/**
@@ -66,13 +101,20 @@
*
* @return
* @throws org.apache.axis.om.OMException
+ * @throws OMException
*/
public OMNode getNextSibling() throws OMException {
- if (nextSibling == null && parent != null && !parent.isComplete())
+ if ((nextSibling == null) && (parent != null) && !parent.isComplete()) {
parent.buildNext();
+ }
return nextSibling;
}
+ /**
+ * Method setNextSibling
+ *
+ * @param node
+ */
public void setNextSibling(OMNode node) {
this.nextSibling = (OMNodeImpl) node;
}
@@ -85,11 +127,17 @@
*
* @return
* @throws org.apache.axis.om.OMException
+ * @throws OMException
*/
public String getValue() throws OMException {
return value;
}
+ /**
+ * Method setValue
+ *
+ * @param value
+ */
public void setValue(String value) {
this.value = value;
}
@@ -105,6 +153,11 @@
return true;
}
+ /**
+ * Method setComplete
+ *
+ * @param state
+ */
public void setComplete(boolean state) {
this.done = state;
}
@@ -113,18 +166,22 @@
* This will remove this information item and its children, from the model completely
*
* @throws org.apache.axis.om.OMException
+ * @throws OMException
*/
public void detach() throws OMException {
- if (parent == null)
- throw new OMException("Elements that doesn't have a parent can not be detached");
+ if (parent == null) {
+ throw new OMException(
+ "Elements that doesn't have a parent can not be detached");
+ }
OMNodeImpl nextSibling = (OMNodeImpl) getNextSibling();
- if (previousSibling == null)
+ if (previousSibling == null) {
parent.setFirstChild(nextSibling);
- else
+ } else {
previousSibling.setNextSibling(nextSibling);
- if (nextSibling != null)
+ }
+ if (nextSibling != null) {
nextSibling.setPreviousSibling(previousSibling);
-
+ }
}
/**
@@ -132,22 +189,25 @@
*
* @param sibling
* @throws org.apache.axis.om.OMException
+ * @throws OMException
*/
public void insertSiblingAfter(OMNode sibling) throws OMException {
- if (parent == null)
+ if (parent == null) {
throw new OMException();
+ }
sibling.setParent(parent);
if (sibling instanceof OMNodeImpl) {
OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
- if (nextSibling == null)
+ if (nextSibling == null) {
getNextSibling();
+ }
siblingImpl.setPreviousSibling(this);
- if (nextSibling != null)
+ if (nextSibling != null) {
nextSibling.setPreviousSibling(sibling);
+ }
sibling.setNextSibling(nextSibling);
nextSibling = siblingImpl;
}
-
}
/**
@@ -155,19 +215,22 @@
*
* @param sibling
* @throws org.apache.axis.om.OMException
+ * @throws OMException
*/
public void insertSiblingBefore(OMNode sibling) throws OMException {
- if (parent == null)
+ if (parent == null) {
throw new OMException();
+ }
sibling.setParent(parent);
if (sibling instanceof OMNodeImpl) {
OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
siblingImpl.setPreviousSibling(previousSibling);
siblingImpl.setNextSibling(this);
- if (previousSibling == null)
+ if (previousSibling == null) {
parent.setFirstChild(siblingImpl);
- else
+ } else {
previousSibling.setNextSibling(siblingImpl);
+ }
previousSibling = siblingImpl;
}
}
@@ -177,24 +240,47 @@
*
* @return
* @throws org.apache.axis.om.OMException
+ * @throws OMException
*/
public short getType() throws OMException {
return nodeType;
}
+ /**
+ * Method setType
+ *
+ * @param nodeType
+ * @throws OMException
+ */
public void setType(short nodeType) throws OMException {
this.nodeType = nodeType;
}
+ /**
+ * Method getPreviousSibling
+ *
+ * @return
+ */
public OMNode getPreviousSibling() {
return previousSibling;
}
+ /**
+ * Method setPreviousSibling
+ *
+ * @param previousSibling
+ */
public void setPreviousSibling(OMNode previousSibling) {
this.previousSibling = (OMNodeImpl) previousSibling;
}
- public void serialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException {
- //Do nothing. Relevant children will put relevant things here
- }
+ /**
+ * Method serialize
+ *
+ * @param writer
+ * @param cache
+ * @throws XMLStreamException
+ */
+ public abstract void serialize(XMLStreamWriter writer, boolean cache)
+ throws XMLStreamException ;
}
Modified: webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMStAXWrapper.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMStAXWrapper.java?view=diff&r1=154467&r2=154468
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMStAXWrapper.java (original)
+++ webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMStAXWrapper.java Sat Feb 19 19:00:47 2005
@@ -1,19 +1,18 @@
/*
* 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.axis.om.impl.llom;
import org.apache.axis.om.OMAttribute;
@@ -41,49 +40,123 @@
* to get access to the StAX constants
*/
public class OMStAXWrapper implements XMLStreamReader, XMLStreamConstants {
+ /**
+ * Field log
+ */
private Log log = LogFactory.getLog(getClass());
+
+ /**
+ * Field navigator
+ */
private OMNavigator 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
+ // to false and the subsequent events will be taken from the builder
+ // or the parser directly
+
+ /**
+ * Field NAVIGABLE
+ */
private static final short NAVIGABLE = 0;
+
+ /**
+ * Field SWITCH_AT_NEXT
+ */
private static final short SWITCH_AT_NEXT = 1;
+
+ /**
+ * Field COMPLETED
+ */
private static final short COMPLETED = 2;
+
+ /**
+ * Field SWITCHED
+ */
private static final short SWITCHED = 3;
+ /**
+ * Field state
+ */
private short state;
- private int currentEvent = 0;
+ /**
+ * Field currentEvent
+ */
+ private int currentEvent = 0;
// 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
+ // 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
+ // 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
+ // needs this to refer to the last known node
+
+ /**
+ * Field lastNode
+ */
private OMNode lastNode = null;
+ /**
+ * Method setAllowSwitching
+ *
+ * @param b
+ */
public void setAllowSwitching(boolean b) {
this.switchingAllowed = b;
}
+ /**
+ * Method isAllowSwitching
+ *
+ * @return
+ */
public boolean isAllowSwitching() {
return switchingAllowed;
}
@@ -94,25 +167,39 @@
* Element Node to start parsing. The wrapper wil parse(proceed) until
* the end of the given element. hence care should be taken to pass the
* root element if the entire document is needed
+ *
+ * @param builder
+ * @param startNode
*/
OMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode) {
this(builder, startNode, false);
}
- OMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode, boolean cacheOff) {
- //create a navigator
+ /**
+ * Constructor OMStAXWrapper
+ *
+ * @param builder
+ * @param startNode
+ * @param cacheOff
+ */
+ OMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode,
+ boolean cacheOff) {
+
+ // create a navigator
this.navigator = new OMNavigator(startNode);
this.builder = builder;
this.rootNode = startNode;
- //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
+
+ // 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 = cacheOff;
}
/**
+ * @return
* @see javax.xml.stream.XMLStreamReader#getPrefix()
*/
public String getPrefix() {
@@ -120,15 +207,19 @@
if (parser != null) {
returnStr = parser.getPrefix();
} else {
- if (currentEvent == START_ELEMENT || currentEvent == END_ELEMENT) {
+ if ((currentEvent == START_ELEMENT)
+ || (currentEvent == END_ELEMENT)) {
OMNamespace ns = ((OMElement) lastNode).getNamespace();
- returnStr = ns == null ? null : ns.getPrefix();
+ returnStr = (ns == null)
+ ? null
+ : ns.getPrefix();
}
}
return returnStr;
}
/**
+ * @return
* @see javax.xml.stream.XMLStreamReader#getNamespaceURI()
*/
public String getNamespaceURI() {
@@ -136,26 +227,33 @@
if (parser != null) {
returnStr = parser.getNamespaceURI();
} else {
- if (currentEvent == START_ELEMENT || currentEvent == END_ELEMENT || currentEvent == NAMESPACE) {
+ if ((currentEvent == START_ELEMENT)
+ || (currentEvent == END_ELEMENT)
+ || (currentEvent == NAMESPACE)) {
OMNamespace ns = ((OMElement) lastNode).getNamespace();
- returnStr = ns == null ? null : ns.getName();
+ returnStr = (ns == null)
+ ? null
+ : ns.getName();
}
}
return returnStr;
}
/**
+ * @return
* @see javax.xml.stream.XMLStreamReader#hasName()
*/
public boolean hasName() {
if (parser != null) {
return parser.hasName();
} else {
- return (currentEvent == START_ELEMENT || currentEvent == END_ELEMENT);
+ return ((currentEvent == START_ELEMENT)
+ || (currentEvent == END_ELEMENT));
}
}
/**
+ * @return
* @see javax.xml.stream.XMLStreamReader#getLocalName()
*/
public String getLocalName() {
@@ -163,7 +261,9 @@
if (parser != null) {
returnStr = parser.getLocalName();
} else {
- if (currentEvent == START_ELEMENT || currentEvent == END_ELEMENT || currentEvent == ENTITY_REFERENCE) {
+ if ((currentEvent == START_ELEMENT)
+ || (currentEvent == END_ELEMENT)
+ || (currentEvent == ENTITY_REFERENCE)) {
returnStr = ((OMElement) lastNode).getLocalName();
}
}
@@ -171,6 +271,7 @@
}
/**
+ * @return
* @see javax.xml.stream.XMLStreamReader#getName()
*/
public QName getName() {
@@ -178,7 +279,8 @@
if (parser != null) {
returnName = parser.getName();
} else {
- if (currentEvent == START_ELEMENT || currentEvent == END_ELEMENT) {
+ if ((currentEvent == START_ELEMENT)
+ || (currentEvent == END_ELEMENT)) {
returnName = getQName((OMNamedNode) lastNode);
}
}
@@ -186,17 +288,17 @@
}
/**
+ * @return
* @see javax.xml.stream.XMLStreamReader#hasText()
*/
public boolean hasText() {
- return (currentEvent == CHARACTERS ||
- currentEvent == DTD ||
- currentEvent == ENTITY_REFERENCE ||
- currentEvent == COMMENT ||
- currentEvent == SPACE);
+ return ((currentEvent == CHARACTERS) || (currentEvent == DTD)
+ || (currentEvent == ENTITY_REFERENCE)
+ || (currentEvent == COMMENT) || (currentEvent == SPACE));
}
/**
+ * @return
* @see javax.xml.stream.XMLStreamReader#getTextLength()
*/
public int getTextLength() {
@@ -211,6 +313,7 @@
}
/**
+ * @return
* @see javax.xml.stream.XMLStreamReader#getTextStart()
*/
public int getTextStart() {
@@ -218,15 +321,22 @@
if (parser != null) {
returnLength = parser.getTextStart();
}
- //Note - this has no relevant method in the OM
+ // Note - this has no relevant method in the OM
return returnLength;
}
/**
+ * @param i
+ * @param chars
+ * @param i1
+ * @param i2
+ * @return
+ * @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 {
+ public int getTextCharacters(int i, char[] chars, int i1, int i2)
+ throws XMLStreamException {
int returnLength = 0;
if (hasText()) {
if (parser != null) {
@@ -236,12 +346,14 @@
throw new OMStreamingException(e);
}
}
- //Note - this has no relevant method in the OM
+
+ // Note - this has no relevant method in the OM
}
return returnLength;
}
/**
+ * @return
* @see javax.xml.stream.XMLStreamReader#getTextCharacters()
*/
public char[] getTextCharacters() {
@@ -259,6 +371,7 @@
}
/**
+ * @return
* @see javax.xml.stream.XMLStreamReader#getText()
*/
public String getText() {
@@ -269,21 +382,24 @@
if (hasText()) {
OMText textNode = (OMText) lastNode;
returnString = textNode.getValue();
-
}
}
return returnString;
}
/**
+ * @return
* @see javax.xml.stream.XMLStreamReader#getEventType()
*/
- //todo this should be improved
+
+ // todo this should be improved
public int getEventType() {
return currentEvent;
}
/**
+ * @param i
+ * @return
* @see javax.xml.stream.XMLStreamReader#getNamespaceURI
*/
public String getNamespaceURI(int i) {
@@ -291,15 +407,21 @@
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();
+ if (isStartElement() || isEndElement()
+ || (currentEvent == NAMESPACE)) {
+ OMNamespace ns = (OMNamespace) getItemFromIterator(
+ ((OMElement) lastNode).getAllDeclaredNamespaces(), i);
+ returnString = (ns == null)
+ ? null
+ : ns.getName();
}
}
return returnString;
}
/**
+ * @param i
+ * @return
* @see javax.xml.stream.XMLStreamReader#getNamespacePrefix
*/
public String getNamespacePrefix(int i) {
@@ -307,15 +429,20 @@
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();
+ if (isStartElement() || isEndElement()
+ || (currentEvent == NAMESPACE)) {
+ OMNamespace ns = (OMNamespace) getItemFromIterator(
+ ((OMElement) lastNode).getAllDeclaredNamespaces(), i);
+ returnString = (ns == null)
+ ? null
+ : ns.getPrefix();
}
}
return returnString;
}
/**
+ * @return
* @see javax.xml.stream.XMLStreamReader#getNamespaceCount()
*/
public int getNamespaceCount() {
@@ -323,14 +450,18 @@
if (parser != null) {
returnCount = parser.getNamespaceCount();
} else {
- if (isStartElement() || isEndElement() || currentEvent == NAMESPACE) {
- returnCount = getCount(((OMElement) lastNode).getAllDeclaredNamespaces());
+ if (isStartElement() || isEndElement()
+ || (currentEvent == NAMESPACE)) {
+ returnCount =
+ getCount(((OMElement) lastNode).getAllDeclaredNamespaces());
}
}
return returnCount;
}
/**
+ * @param i
+ * @return
* @see javax.xml.stream.XMLStreamReader#isAttributeSpecified
*/
public boolean isAttributeSpecified(int i) {
@@ -338,16 +469,20 @@
if (parser != null) {
returnValue = parser.isAttributeSpecified(i);
} else {
- if (isStartElement() || currentEvent == ATTRIBUTE) {
- //theres nothing to be returned here
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
+
+ // theres nothing to be returned here
} else {
- throw new IllegalStateException("attribute type accessed in illegal event!");
+ throw new IllegalStateException(
+ "attribute type accessed in illegal event!");
}
}
return returnValue;
}
/**
+ * @param i
+ * @return
* @see javax.xml.stream.XMLStreamReader#getAttributeValue
*/
public String getAttributeValue(int i) {
@@ -355,19 +490,22 @@
if (parser != null) {
returnString = parser.getAttributeValue(i);
} else {
- if (isStartElement() || currentEvent == ATTRIBUTE) {
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
OMAttribute attrib = getAttribute((OMElement) lastNode, i);
if (attrib != null) {
returnString = attrib.getValue();
}
} else {
- throw new IllegalStateException("attribute type accessed in illegal event!");
+ throw new IllegalStateException(
+ "attribute type accessed in illegal event!");
}
}
return returnString;
}
/**
+ * @param i
+ * @return
* @see javax.xml.stream.XMLStreamReader#getAttributeType
*/
public String getAttributeType(int i) {
@@ -375,16 +513,20 @@
if (parser != null) {
returnString = parser.getAttributeType(i);
} else {
- if (isStartElement() || currentEvent == ATTRIBUTE) {
- //todo implement this
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
+
+ // todo implement this
} else {
- throw new IllegalStateException("attribute type accessed in illegal event!");
+ throw new IllegalStateException(
+ "attribute type accessed in illegal event!");
}
}
return returnString;
}
/**
+ * @param i
+ * @return
* @see javax.xml.stream.XMLStreamReader#getAttributePrefix
*/
public String getAttributePrefix(int i) {
@@ -392,7 +534,7 @@
if (parser != null) {
returnString = parser.getAttributePrefix(i);
} else {
- if (isStartElement() || currentEvent == ATTRIBUTE) {
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
OMAttribute attrib = getAttribute((OMElement) lastNode, i);
if (attrib != null) {
OMNamespace nameSpace = attrib.getNamespace();
@@ -400,15 +542,17 @@
returnString = nameSpace.getPrefix();
}
}
-
} else {
- throw new IllegalStateException("attribute prefix accessed in illegal event!");
+ throw new IllegalStateException(
+ "attribute prefix accessed in illegal event!");
}
}
return returnString;
}
/**
+ * @param i
+ * @return
* @see javax.xml.stream.XMLStreamReader#getAttributeLocalName
*/
public String getAttributeLocalName(int i) {
@@ -416,20 +560,22 @@
if (parser != null) {
returnString = parser.getAttributeLocalName(i);
} else {
- if (isStartElement() || currentEvent == ATTRIBUTE) {
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
OMAttribute attrib = getAttribute((OMElement) lastNode, i);
- if (attrib != null)
+ if (attrib != null) {
returnString = attrib.getLocalName();
-
-
+ }
} else {
- throw new IllegalStateException("attribute localName accessed in illegal event!");
+ throw new IllegalStateException(
+ "attribute localName accessed in illegal event!");
}
}
return returnString;
}
/**
+ * @param i
+ * @return
* @see javax.xml.stream.XMLStreamReader#getAttributeNamespace
*/
public String getAttributeNamespace(int i) {
@@ -437,7 +583,7 @@
if (parser != null) {
returnString = parser.getAttributeNamespace(i);
} else {
- if (isStartElement() || currentEvent == ATTRIBUTE) {
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
OMAttribute attrib = getAttribute((OMElement) lastNode, i);
if (attrib != null) {
OMNamespace nameSpace = attrib.getNamespace();
@@ -445,15 +591,17 @@
returnString = nameSpace.getName();
}
}
-
} else {
- throw new IllegalStateException("attribute nameSpace accessed in illegal event!");
+ throw new IllegalStateException(
+ "attribute nameSpace accessed in illegal event!");
}
}
return returnString;
}
/**
+ * @param i
+ * @return
* @see javax.xml.stream.XMLStreamReader#getAttributeName
*/
public QName getAttributeName(int i) {
@@ -461,11 +609,11 @@
if (parser != null) {
returnQName = parser.getAttributeName(i);
} else {
- if (isStartElement() || currentEvent == ATTRIBUTE) {
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
returnQName = getAttribute((OMElement) lastNode, i).getQName();
-
} else {
- throw new IllegalStateException("attribute count accessed in illegal event!");
+ throw new IllegalStateException(
+ "attribute count accessed in illegal event!");
}
}
return returnQName;
@@ -480,24 +628,35 @@
if (parser != null) {
returnCount = parser.getAttributeCount();
} else {
- if (isStartElement() || currentEvent == ATTRIBUTE) {
+ if (isStartElement() || (currentEvent == ATTRIBUTE)) {
OMElement elt = (OMElement) lastNode;
returnCount = getCount(elt.getAttributes());
-
-
} else {
- throw new IllegalStateException("attribute count accessed in illegal event!");
+ throw new IllegalStateException(
+ "attribute count accessed in illegal event!");
}
}
return returnCount;
}
+ // todo
- //todo
+ /**
+ * Method getAttributeValue
+ *
+ * @param s
+ * @param s1
+ * @return
+ */
public String getAttributeValue(String s, String s1) {
throw new UnsupportedOperationException();
}
+ /**
+ * Method isWhiteSpace
+ *
+ * @return
+ */
public boolean isWhiteSpace() {
boolean b;
if (parser != null) {
@@ -508,6 +667,11 @@
return b;
}
+ /**
+ * Method isCharacters
+ *
+ * @return
+ */
public boolean isCharacters() {
boolean b;
if (parser != null) {
@@ -518,6 +682,11 @@
return b;
}
+ /**
+ * Method isEndElement
+ *
+ * @return
+ */
public boolean isEndElement() {
boolean b;
if (parser != null) {
@@ -539,6 +708,11 @@
throw new XMLStreamException();
}
+ /**
+ * Method isStartElement
+ *
+ * @return
+ */
public boolean isStartElement() {
boolean b;
if (parser != null) {
@@ -549,29 +723,45 @@
return b;
}
+ /**
+ * Method getNamespaceURI
+ *
+ * @param s
+ * @return
+ */
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
+ 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
+
+ // this doesnot mean anything with respect to the OM
if (parser != null) {
parser.close();
-
}
-
}
+ /**
+ * Method hasNext
+ *
+ * @return
+ * @throws XMLStreamException
+ */
public boolean hasNext() throws XMLStreamException {
return !(state == COMPLETED);
}
@@ -580,14 +770,17 @@
* Not implemented yet
*
* @return
- * @throws org.apache.axis.impl.llom.exception.OMStreamingException
+ * @throws org.apache.axis.om.impl.llom.exception.OMStreamingException
*
+ * @throws XMLStreamException
*/
public int nextTag() throws XMLStreamException {
throw new UnsupportedOperationException();
}
/**
+ * @return
+ * @throws XMLStreamException
* @see javax.xml.stream.XMLStreamReader#getElementText()
*/
public String getElementText() throws XMLStreamException {
@@ -600,26 +793,36 @@
}
} else {
if (currentNode.getType() == OMNode.ELEMENT_NODE) {
- //todo complete this
+
+ // todo complete this
return null;
}
}
return returnText;
}
+ /**
+ * Method next
+ *
+ * @return
+ * @throws XMLStreamException
+ */
public int next() throws XMLStreamException {
switch (state) {
case COMPLETED:
throw new OMStreamingException("Parser completed!");
case SWITCH_AT_NEXT:
state = SWITCHED;
- //load the parser
+
+ // load the parser
try {
parser = (XMLStreamReader) builder.getParser();
} catch (ClassCastException e) {
- throw new UnsupportedOperationException("incompatible parser found!");
+ throw new UnsupportedOperationException(
+ "incompatible parser found!");
}
- log.info("Switching to the Real Stax parser to generated the future events");
+ log.info(
+ "Switching to the Real Stax parser to generated the future events");
currentEvent = parser.getEventType();
updateCompleteStatus();
break;
@@ -632,12 +835,19 @@
currentEvent = parser.next();
updateCompleteStatus();
break;
- default:
+ default :
throw new OMStreamingException("unsuppported state!");
}
return currentEvent;
}
+ /**
+ * Method getProperty
+ *
+ * @param s
+ * @return
+ * @throws IllegalArgumentException
+ */
public Object getProperty(String s) throws IllegalArgumentException {
throw new UnsupportedOperationException();
}
@@ -648,6 +858,8 @@
* 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;
@@ -659,6 +871,9 @@
}
}
+ /**
+ * Method updateNextNode
+ */
private void updateNextNode() {
if (navigator.isNavigable()) {
nextNode = navigator.next();
@@ -672,78 +887,138 @@
nextNode = navigator.next();
}
} else {
- //reset caching (the default is ON so it was not needed in the
- //earlier case!
+
+ // 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)
+ if (rootNode == currentNode) {
+ if (isFirst) {
isFirst = false;
- else
+ } else {
state = COMPLETED;
+ }
+ }
} else {
- state = (currentEvent == END_DOCUMENT) ? COMPLETED : state;
+ state = (currentEvent == END_DOCUMENT)
+ ? COMPLETED
+ : state;
}
-
}
+ /**
+ * Method getNamespaceContext
+ *
+ * @return
+ */
public NamespaceContext getNamespaceContext() {
throw new UnsupportedOperationException();
}
+ /**
+ * Method getEncoding
+ *
+ * @return
+ */
public String getEncoding() {
throw new UnsupportedOperationException();
}
+ /**
+ * Method getLocation
+ *
+ * @return
+ */
public Location getLocation() {
throw new UnsupportedOperationException();
}
+ /**
+ * Method getVersion
+ *
+ * @return
+ */
public String getVersion() {
throw new UnsupportedOperationException();
}
+ /**
+ * Method isStandalone
+ *
+ * @return
+ */
public boolean isStandalone() {
throw new UnsupportedOperationException();
}
+ /**
+ * Method standaloneSet
+ *
+ * @return
+ */
public boolean standaloneSet() {
throw new UnsupportedOperationException();
}
+ /**
+ * Method getCharacterEncodingScheme
+ *
+ * @return
+ */
public String getCharacterEncodingScheme() {
throw new UnsupportedOperationException();
}
+ /**
+ * Method getPITarget
+ *
+ * @return
+ */
public String getPITarget() {
throw new UnsupportedOperationException();
}
+ /**
+ * Method getPIData
+ *
+ * @return
+ */
public String getPIData() {
throw new UnsupportedOperationException();
}
/*
+ *
+ * ################################################################
+ * Generator methods for the OMNodes returned by the navigator
+ * ################################################################
+ *
+ */
- ################################################################
- Generator methods for the OMNodes returned by the navigator
- ################################################################
-
- */
-
+ /**
+ * Method generateEvents
+ *
+ * @param node
+ * @return
+ */
private int generateEvents(OMNode node) {
int returnEvent = 0;
int nodeType = node.getType();
switch (nodeType) {
case OMNode.ELEMENT_NODE:
OMElement element = (OMElement) node;
- log.info("Generating events from element {" + element.getNamespaceName() + '}' + element.getLocalName() + " Generated OM tree");
+ log.info("Generating events from element {"
+ + element.getNamespaceName() + '}'
+ + element.getLocalName() + " Generated OM tree");
returnEvent = generateElementEvents(element);
break;
case OMNode.TEXT_NODE:
@@ -755,12 +1030,18 @@
case OMNode.CDATA_SECTION_NODE:
returnEvent = generateCdataEvents();
break;
- default:
- break; //just ignore any other nodes
+ default :
+ break; // just ignore any other nodes
}
return returnEvent;
}
+ /**
+ * Method generateElementEvents
+ *
+ * @param elt
+ * @return
+ */
private int generateElementEvents(OMElement elt) {
int returnValue = START_ELEMENT;
if (!elementStack.isEmpty() && elementStack.peek().equals(elt)) {
@@ -772,23 +1053,38 @@
return returnValue;
}
+ /**
+ * Method generateTextEvents
+ *
+ * @return
+ */
private int generateTextEvents() {
return CHARACTERS;
}
+ /**
+ * Method generateCommentEvents
+ *
+ * @return
+ */
private int generateCommentEvents() {
return COMMENT;
}
+ /**
+ * Method generateCdataEvents
+ *
+ * @return
+ */
private int generateCdataEvents() {
return CDATA;
}
/*
- ####################################################################
- Other helper methods
- ####################################################################
- */
+ * ####################################################################
+ * Other helper methods
+ * ####################################################################
+ */
/**
* helper method
@@ -847,10 +1143,11 @@
if (ns != null) {
String prefix = ns.getPrefix();
String uri = ns.getName();
- if (prefix == null || prefix.equals(""))
+ if ((prefix == null) || prefix.equals("")) {
returnName = new QName(uri, localPart);
- else
+ } else {
returnName = new QName(uri, localPart, prefix);
+ }
} else {
returnName = new QName(localPart);
}
@@ -865,7 +1162,8 @@
private OMAttribute getAttribute(OMElement elt, int index) {
OMAttribute returnAttrib = null;
if (elt != null) {
- returnAttrib = (OMAttribute) getItemFromIterator(elt.getAttributes(), index);
+ returnAttrib =
+ (OMAttribute) getItemFromIterator(elt.getAttributes(), index);
}
return returnAttrib;
}
Modified: webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMTextImpl.java?view=diff&r1=154467&r2=154468
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMTextImpl.java (original)
+++ webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMTextImpl.java Sat Feb 19 19:00:47 2005
@@ -1,19 +1,18 @@
/*
* 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.axis.om.impl.llom;
import org.apache.axis.om.OMConstants;
@@ -25,15 +24,32 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
+/**
+ * Class OMTextImpl
+ */
public class OMTextImpl extends OMNodeImpl implements OMText, OMConstants {
+ /**
+ * Field textType
+ */
protected short textType = TEXT_NODE;
+ /**
+ * Constructor OMTextImpl
+ *
+ * @param parent
+ * @param text
+ */
public OMTextImpl(OMElement parent, String text) {
super(parent);
setValue(text);
done = true;
}
+ /**
+ * Constructor OMTextImpl
+ *
+ * @param s
+ */
public OMTextImpl(String s) {
setValue(s);
}
@@ -45,20 +61,40 @@
* @param type
*/
public void setTextType(short type) {
- if (type == TEXT_NODE || type == COMMENT_NODE || type == CDATA_SECTION_NODE)
+ if ((type == TEXT_NODE) || (type == COMMENT_NODE)
+ || (type == CDATA_SECTION_NODE)) {
this.textType = type;
- else
- throw new UnsupportedOperationException("Attempt to set wrong type");
+ } else {
+ throw new UnsupportedOperationException(
+ "Attempt to set wrong type");
+ }
}
+ /**
+ * Method getTextType
+ *
+ * @return
+ */
public short getTextType() {
return textType;
}
+ /**
+ * Method getFirstChild
+ *
+ * @return
+ * @throws OMException
+ */
public OMNode getFirstChild() throws OMException {
throw new UnsupportedOperationException();
}
+ /**
+ * Method setFirstChild
+ *
+ * @param node
+ * @throws OMException
+ */
public void setFirstChild(OMNode node) throws OMException {
throw new UnsupportedOperationException();
}
@@ -66,6 +102,7 @@
/**
* @return
* @throws org.apache.axis.om.OMException
+ * @throws OMException
*/
public short getType() throws OMException {
return textType;
@@ -76,12 +113,13 @@
* @param cache
* @throws XMLStreamException
*/
- public void serialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException {
- if (textType == TEXT_NODE)
+ public void serialize(XMLStreamWriter writer, boolean cache)
+ throws XMLStreamException {
+ if (textType == TEXT_NODE) {
writer.writeCharacters(this.value);
- else if (textType == COMMENT_NODE)
+ } else if (textType == COMMENT_NODE) {
writer.writeComment(this.value);
- else if (textType == CDATA_SECTION_NODE) {
+ } else if (textType == CDATA_SECTION_NODE) {
writer.writeCData(this.value);
}
OMNode nextSibling = this.getNextSibling();
@@ -90,4 +128,3 @@
}
}
}
-