You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by di...@apache.org on 2006/04/04 11:33:39 UTC
svn commit: r391260 [3/7] - in /webservices/commons/trunk/modules/axiom:
src/org/apache/axiom/om/ src/org/apache/axiom/om/impl/
src/org/apache/axiom/om/impl/dom/ src/org/apache/axiom/om/impl/llom/
src/org/apache/axiom/om/impl/serialize/ src/org/apache/...
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMNodeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMNodeImpl.java?rev=391260&r1=391259&r2=391260&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMNodeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMNodeImpl.java Tue Apr 4 02:33:33 2006
@@ -1,411 +1,409 @@
-/*
- * 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.axiom.om.impl.llom;
-
-import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMOutputFormat;
-import org.apache.axiom.om.OMXMLParserWrapper;
-import org.apache.axiom.om.impl.OMContainerEx;
-import org.apache.axiom.om.impl.OMNodeEx;
-import org.apache.axiom.om.impl.OMOutputImpl;
-
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-import java.io.OutputStream;
-import java.io.Writer;
-
-/**
- * Class OMNodeImpl
- */
-public abstract class OMNodeImpl implements OMNode, OMNodeEx {
- /**
- * Field parent
- */
- protected OMContainerEx parent;
-
- /**
- * Field nextSibling
- */
- protected OMNodeImpl nextSibling;
-
- /**
- * Field previousSibling
- */
- protected OMNodeImpl previousSibling;
- /**
- * Field builder
- */
- protected OMXMLParserWrapper builder;
-
- /**
- * Field done
- */
- protected boolean done = false;
-
- /**
- * Field nodeType
- */
- protected int nodeType;
-
- protected OMFactory factory;
-
-// /**
-// * Constructor OMNodeImpl
-// */
-// public OMNodeImpl() {
-// }
-//
-// /**
-// * For a node to exist there must be a parent.
-// *
-// * @param parent
-// */
-// public OMNodeImpl(OMContainer parent) {
-// if ((parent != null)) {
-// this.parent = (OMContainerEx) parent;
-// parent.addChild(this);
-// }
-// }
-
- /**
- * Constructor OMNodeImpl
- * @param factory The <code>OMFactory</code> that created this
- */
- public OMNodeImpl(OMFactory factory) {
- this.factory = factory;
- }
-
- /**
- * For a node to exist there must be a parent.
- *
- * @param parent Parent <code>OMContainer</code> of this node
- * @param factory The <code>OMFactory</code> that created this
- */
- public OMNodeImpl(OMContainer parent, OMFactory factory) {
- if ((parent != null)) {
- this.parent = (OMContainerEx) parent;
- parent.addChild(this);
- }
- this.factory = factory;
- }
-
- /**
- * Returns the immediate parent of the node. Parent is always an Element.
- *
- * @return Returns OMContainer.
- * @throws OMException
- */
- public OMContainer getParent() {
- return parent;
- }
-
- /**
- * Method setParent.
- *
- * @param element
- */
- public void setParent(OMContainer element) {
-
- if ((this.parent) == element) {
- return;
- }
-
- //If we are asked to assign a new parent in place
- //of an existing one. We should detach this node
- //from the aegis of previous parent.
- if (this.parent != null) {
- this.detach();
- }
- this.parent = (OMContainerEx) element;
- }
-
- /**
- * Returns the next sibling. This can be an OMAttribute or
- * OMText or OMElement for others.
- *
- * @return Returns OMNode.
- * @throws org.apache.axiom.om.OMException
- *
- */
- public OMNode getNextOMSibling() throws OMException {
- if ((nextSibling == null) && (parent != null) && !parent.isComplete()) {
- parent.buildNext();
- }
- return nextSibling;
- }
-
- /**
- * Method setNextOMSibling.
- *
- * @param node
- */
- public void setNextOMSibling(OMNode node) {
- this.nextSibling = (OMNodeImpl) node;
- }
-
-
- /**
- * Indicates whether parser has parsed this information item completely or not.
- * If some information is not available in the item, one has to check this
- * attribute to make sure that, this item has been parsed completely or not.
- *
- * @return Returns boolean.
- */
- public boolean isComplete() {
- return done;
- }
-
- /**
- * Method setComplete.
- *
- * @param state
- */
- public void setComplete(boolean state) {
- this.done = state;
- }
-
- /**
- * Removes this information item and its children, from the model completely.
- *
- * @throws OMException
- */
- public OMNode detach() throws OMException {
- if (parent == null) {
- throw new OMException(
- "Elements that doesn't have a parent can not be detached");
- }
- OMNodeImpl nextSibling = (OMNodeImpl) getNextOMSibling();
- if (previousSibling == null) {
- parent.setFirstChild(nextSibling);
- } else {
- ((OMNodeEx) getPreviousOMSibling()).setNextOMSibling(nextSibling);
- }
- if (nextSibling != null) {
- nextSibling.setPreviousOMSibling(getPreviousOMSibling());
- }
-
- if ((parent instanceof OMElementImpl) && ((OMElementImpl) parent).lastChild == this) {
- ((OMElementImpl) parent).lastChild = getPreviousOMSibling();
- }
-
- this.parent = null;
- return this;
- }
-
- /**
- * Inserts a sibling just after the current information item.
- *
- * @param sibling
- * @throws OMException
- */
- public void insertSiblingAfter(OMNode sibling) throws OMException {
- if (parent == null) {
- throw new OMException();
- }
- ((OMNodeEx) sibling).setParent(parent);
- if (sibling instanceof OMNodeImpl) {
- OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
- if (nextSibling == null) {
- getNextOMSibling();
- }
- siblingImpl.setPreviousOMSibling(this);
- if (nextSibling != null) {
- nextSibling.setPreviousOMSibling(sibling);
- }
- ((OMNodeEx) sibling).setNextOMSibling(nextSibling);
- nextSibling = siblingImpl;
- }
- }
-
- /**
- * Inserts a sibling just before the current information item.
- *
- * @param sibling
- * @throws OMException
- */
- public void insertSiblingBefore(OMNode sibling) throws OMException {
- if (parent == null) {
- throw new OMException();
- }
- if (sibling instanceof OMNodeImpl) {
- OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
- siblingImpl.nextSibling = this;
- if (previousSibling == null) {
- parent.setFirstChild(siblingImpl);
- siblingImpl.previousSibling = null;
- } else {
- siblingImpl.setParent(parent);
- previousSibling.setNextOMSibling(siblingImpl);
- siblingImpl.setPreviousOMSibling(previousSibling);
- }
- previousSibling = siblingImpl;
-
- }
- }
-
- /**
- * Gets the type of node, as this is the super class of all the nodes.
- *
- * @return Returns the type of node as indicated by {@link #setType}
- * @see #setType
- */
- public int getType() {
- return nodeType;
- }
-
- /**
- * Method setType.
- *
- * @param nodeType
- * @throws OMException
- */
- public void setType(int nodeType) throws OMException {
- this.nodeType = nodeType;
- }
-
- /**
- * Gets the previous sibling.
- *
- * @return boolean
- */
- public OMNode getPreviousOMSibling() {
- return previousSibling;
- }
-
- /**
- * Method setPreviousOMSibling.
- *
- * @param previousSibling
- */
- public void setPreviousOMSibling(OMNode previousSibling) {
- this.previousSibling = (OMNodeImpl) previousSibling;
- }
-
-
- /**
- * Parses this node and builds the object structure in memory.
- * However a node, created programmatically, will have done set to true by
- * default and this will cause populateyourself not to work properly!
- *
- * @throws OMException
- */
- public void build() throws OMException {
- while (!done) {
- builder.next();
- }
- }
-
- /**
- * Serializes the node with caching.
- *
- * @param xmlWriter
- * @throws javax.xml.stream.XMLStreamException
- *
- * @see #serialize(org.apache.axiom.om.impl.OMOutputImpl)
- */
- public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
- OMOutputImpl omOutput = new OMOutputImpl(xmlWriter);
- serialize(omOutput);
- omOutput.flush();
- }
-
- /**
- * Serializes the node without caching.
- *
- * @param xmlWriter
- * @throws javax.xml.stream.XMLStreamException
- *
- * @see #serializeAndConsume(org.apache.axiom.om.impl.OMOutputImpl)
- */
- public void serializeAndConsume(XMLStreamWriter xmlWriter) throws XMLStreamException {
- OMOutputImpl omOutput = new OMOutputImpl(xmlWriter);
- serializeAndConsume(omOutput);
- omOutput.flush();
- }
-
- /**
- * Serializes the node with caching.
- *
- * @param omOutput
- * @throws XMLStreamException
- * @see #serialize(org.apache.axiom.om.impl.OMOutputImpl)
- */
- public void serialize(OMOutputImpl omOutput) throws XMLStreamException {
- throw new RuntimeException("Not implemented yet!");
- }
-
- /**
- * Serializes the node without caching.
- *
- * @param omOutput
- * @throws XMLStreamException
- * @see #serializeAndConsume(org.apache.axiom.om.impl.OMOutputImpl)
- */
- public void serializeAndConsume(OMOutputImpl omOutput) throws XMLStreamException {
- throw new RuntimeException("Not implemented yet!");
- }
-
- public void serialize(OutputStream output) throws XMLStreamException {
- serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(output));
- }
-
- public void serialize(Writer writer) throws XMLStreamException {
- serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
- }
-
- public void serializeAndConsume(OutputStream output) throws XMLStreamException {
- serializeAndConsume(XMLOutputFactory.newInstance().createXMLStreamWriter(output));
- }
-
- public void serializeAndConsume(Writer writer) throws XMLStreamException {
- serializeAndConsume(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
- }
-
- public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
- OMOutputImpl omOutput = new OMOutputImpl(output, format);
- serialize(omOutput);
- omOutput.flush();
- }
-
- public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
- OMOutputImpl omOutput = new OMOutputImpl(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
- omOutput.setOutputFormat(format);
- serialize(omOutput);
- omOutput.flush();
- }
-
- public void serializeAndConsume(OutputStream output, OMOutputFormat format) throws XMLStreamException {
- OMOutputImpl omOutput = new OMOutputImpl(output, format);
- serializeAndConsume(omOutput);
- omOutput.flush();
- }
-
- public void serializeAndConsume(Writer writer, OMOutputFormat format) throws XMLStreamException {
- OMOutputImpl omOutput = new OMOutputImpl(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
- omOutput.setOutputFormat(format);
- serializeAndConsume(omOutput);
- omOutput.flush();
- }
-
- public OMFactory getOMFactory() {
- return this.factory;
- }
-}
+/*
+ * 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.axiom.om.impl.llom;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.OMContainerEx;
+import org.apache.axiom.om.impl.OMNodeEx;
+import org.apache.axiom.om.impl.OMOutputImpl;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.OutputStream;
+import java.io.Writer;
+
+/**
+ * Class OMNodeImpl
+ */
+public abstract class OMNodeImpl implements OMNode, OMNodeEx {
+ /**
+ * Field parent
+ */
+ protected OMContainerEx parent;
+
+ /**
+ * Field nextSibling
+ */
+ protected OMNodeImpl nextSibling;
+
+ /**
+ * Field previousSibling
+ */
+ protected OMNodeImpl previousSibling;
+ /**
+ * Field builder
+ */
+ protected OMXMLParserWrapper builder;
+
+ /**
+ * Field done
+ */
+ protected boolean done = false;
+
+ /**
+ * Field nodeType
+ */
+ protected int nodeType;
+
+ protected OMFactory factory;
+
+// /**
+// * Constructor OMNodeImpl
+// */
+// public OMNodeImpl() {
+// }
+//
+// /**
+// * For a node to exist there must be a parent.
+// *
+// * @param parent
+// */
+// public OMNodeImpl(OMContainer parent) {
+// if ((parent != null)) {
+// this.parent = (OMContainerEx) parent;
+// parent.addChild(this);
+// }
+// }
+
+ /**
+ * Constructor OMNodeImpl
+ * @param factory The <code>OMFactory</code> that created this
+ */
+ public OMNodeImpl(OMFactory factory) {
+ this.factory = factory;
+ }
+
+ /**
+ * For a node to exist there must be a parent.
+ *
+ * @param parent Parent <code>OMContainer</code> of this node
+ * @param factory The <code>OMFactory</code> that created this
+ */
+ public OMNodeImpl(OMContainer parent, OMFactory factory) {
+ if ((parent != null)) {
+ this.parent = (OMContainerEx) parent;
+ parent.addChild(this);
+ }
+ this.factory = factory;
+ }
+
+ /**
+ * Returns the immediate parent of the node. Parent is always an Element.
+ *
+ * @return Returns OMContainer.
+ * @throws OMException
+ */
+ public OMContainer getParent() {
+ return parent;
+ }
+
+ /**
+ * Method setParent.
+ *
+ * @param element
+ */
+ public void setParent(OMContainer element) {
+
+ if ((this.parent) == element) {
+ return;
+ }
+
+ //If we are asked to assign a new parent in place
+ //of an existing one. We should detach this node
+ //from the aegis of previous parent.
+ if (this.parent != null) {
+ this.detach();
+ }
+ this.parent = (OMContainerEx) element;
+ }
+
+ /**
+ * Returns the next sibling. This can be an OMAttribute or
+ * OMText or OMElement for others.
+ *
+ * @return Returns OMNode.
+ * @throws org.apache.axiom.om.OMException
+ *
+ */
+ public OMNode getNextOMSibling() throws OMException {
+ if ((nextSibling == null) && (parent != null) && !parent.isComplete()) {
+ parent.buildNext();
+ }
+ return nextSibling;
+ }
+
+ /**
+ * Method setNextOMSibling.
+ *
+ * @param node
+ */
+ public void setNextOMSibling(OMNode node) {
+ this.nextSibling = (OMNodeImpl) node;
+ }
+
+
+ /**
+ * Indicates whether parser has parsed this information item completely or not.
+ * If some information is not available in the item, one has to check this
+ * attribute to make sure that, this item has been parsed completely or not.
+ *
+ * @return Returns boolean.
+ */
+ public boolean isComplete() {
+ return done;
+ }
+
+ /**
+ * Method setComplete.
+ *
+ * @param state
+ */
+ public void setComplete(boolean state) {
+ this.done = state;
+ }
+
+ /**
+ * Removes this information item and its children, from the model completely.
+ *
+ * @throws OMException
+ */
+ public OMNode detach() throws OMException {
+ if (parent == null) {
+ throw new OMException(
+ "Elements that doesn't have a parent can not be detached");
+ }
+ OMNodeImpl nextSibling = (OMNodeImpl) getNextOMSibling();
+ if (previousSibling == null) {
+ parent.setFirstChild(nextSibling);
+ } else {
+ ((OMNodeEx) getPreviousOMSibling()).setNextOMSibling(nextSibling);
+ }
+ if (nextSibling != null) {
+ nextSibling.setPreviousOMSibling(getPreviousOMSibling());
+ }
+
+ if ((parent instanceof OMElementImpl) && ((OMElementImpl) parent).lastChild == this) {
+ ((OMElementImpl) parent).lastChild = getPreviousOMSibling();
+ }
+
+ this.parent = null;
+ return this;
+ }
+
+ /**
+ * Inserts a sibling just after the current information item.
+ *
+ * @param sibling
+ * @throws OMException
+ */
+ public void insertSiblingAfter(OMNode sibling) throws OMException {
+ if (parent == null) {
+ throw new OMException();
+ }
+ ((OMNodeEx) sibling).setParent(parent);
+ if (sibling instanceof OMNodeImpl) {
+ OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
+ if (nextSibling == null) {
+ getNextOMSibling();
+ }
+ siblingImpl.setPreviousOMSibling(this);
+ if (nextSibling != null) {
+ nextSibling.setPreviousOMSibling(sibling);
+ }
+ ((OMNodeEx) sibling).setNextOMSibling(nextSibling);
+ nextSibling = siblingImpl;
+ }
+ }
+
+ /**
+ * Inserts a sibling just before the current information item.
+ *
+ * @param sibling
+ * @throws OMException
+ */
+ public void insertSiblingBefore(OMNode sibling) throws OMException {
+ if (parent == null) {
+ throw new OMException();
+ }
+ if (sibling instanceof OMNodeImpl) {
+ OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
+ siblingImpl.nextSibling = this;
+ if (previousSibling == null) {
+ parent.setFirstChild(siblingImpl);
+ siblingImpl.previousSibling = null;
+ } else {
+ siblingImpl.setParent(parent);
+ previousSibling.setNextOMSibling(siblingImpl);
+ siblingImpl.setPreviousOMSibling(previousSibling);
+ }
+ previousSibling = siblingImpl;
+
+ }
+ }
+
+ /**
+ * Gets the type of node, as this is the super class of all the nodes.
+ *
+ * @return Returns the type of node as indicated by {@link #setType}
+ * @see #setType
+ */
+ public int getType() {
+ return nodeType;
+ }
+
+ /**
+ * Method setType.
+ *
+ * @param nodeType
+ * @throws OMException
+ */
+ public void setType(int nodeType) throws OMException {
+ this.nodeType = nodeType;
+ }
+
+ /**
+ * Gets the previous sibling.
+ *
+ * @return boolean
+ */
+ public OMNode getPreviousOMSibling() {
+ return previousSibling;
+ }
+
+ /**
+ * Method setPreviousOMSibling.
+ *
+ * @param previousSibling
+ */
+ public void setPreviousOMSibling(OMNode previousSibling) {
+ this.previousSibling = (OMNodeImpl) previousSibling;
+ }
+
+
+ /**
+ * Parses this node and builds the object structure in memory.
+ * However a node, created programmatically, will have done set to true by
+ * default and this will cause populateyourself not to work properly!
+ *
+ * @throws OMException
+ */
+ public void build() throws OMException {
+ while (!done) {
+ builder.next();
+ }
+ }
+
+ /**
+ * Serializes the node with caching.
+ *
+ * @param xmlWriter
+ * @throws javax.xml.stream.XMLStreamException
+ */
+ public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+ OMOutputImpl omOutput = new OMOutputImpl(xmlWriter);
+ internalSerialize(omOutput);
+ omOutput.flush();
+ }
+
+ /**
+ * Serializes the node without caching.
+ *
+ * @param xmlWriter
+ * @throws javax.xml.stream.XMLStreamException
+ *
+ * @see #internalSerializeAndConsume(org.apache.axiom.om.impl.OMOutputImpl)
+ */
+ public void serializeAndConsume(XMLStreamWriter xmlWriter) throws XMLStreamException {
+ OMOutputImpl omOutput = new OMOutputImpl(xmlWriter);
+ internalSerializeAndConsume(omOutput);
+ omOutput.flush();
+ }
+
+ /**
+ * Serializes the node with caching.
+ *
+ * @param omOutput
+ * @throws XMLStreamException
+ * @see #internalSerialize(org.apache.axiom.om.impl.OMOutputImpl)
+ */
+ public void internalSerialize(OMOutputImpl omOutput) throws XMLStreamException {
+ throw new RuntimeException("Not implemented yet!");
+ }
+
+ /**
+ * Serializes the node without caching.
+ *
+ * @param omOutput
+ * @throws XMLStreamException
+ * @see #internalSerializeAndConsume(org.apache.axiom.om.impl.OMOutputImpl)
+ */
+ public void internalSerializeAndConsume(OMOutputImpl omOutput) throws XMLStreamException {
+ throw new RuntimeException("Not implemented yet!");
+ }
+
+ public void serialize(OutputStream output) throws XMLStreamException {
+ serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(output));
+ }
+
+ public void serialize(Writer writer) throws XMLStreamException {
+ serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
+ }
+
+ public void serializeAndConsume(OutputStream output) throws XMLStreamException {
+ serializeAndConsume(XMLOutputFactory.newInstance().createXMLStreamWriter(output));
+ }
+
+ public void serializeAndConsume(Writer writer) throws XMLStreamException {
+ serializeAndConsume(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
+ }
+
+ public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
+ OMOutputImpl omOutput = new OMOutputImpl(output, format);
+ internalSerialize(omOutput);
+ omOutput.flush();
+ }
+
+ public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
+ OMOutputImpl omOutput = new OMOutputImpl(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
+ omOutput.setOutputFormat(format);
+ internalSerialize(omOutput);
+ omOutput.flush();
+ }
+
+ public void serializeAndConsume(OutputStream output, OMOutputFormat format) throws XMLStreamException {
+ OMOutputImpl omOutput = new OMOutputImpl(output, format);
+ internalSerializeAndConsume(omOutput);
+ omOutput.flush();
+ }
+
+ public void serializeAndConsume(Writer writer, OMOutputFormat format) throws XMLStreamException {
+ OMOutputImpl omOutput = new OMOutputImpl(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
+ omOutput.setOutputFormat(format);
+ internalSerializeAndConsume(omOutput);
+ omOutput.flush();
+ }
+
+ public OMFactory getOMFactory() {
+ return this.factory;
+ }
+}
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java?rev=391260&r1=391259&r2=391260&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java Tue Apr 4 02:33:33 2006
@@ -1,129 +1,129 @@
-/*
- * 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.axiom.om.impl.llom;
-
-import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMProcessingInstruction;
-
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-public class OMProcessingInstructionImpl extends OMNodeImpl implements OMProcessingInstruction {
- protected String target;
- protected String value;
-
- /**
- * Constructor OMProcessingInstructionImpl.
- *
- * @param parentNode
- * @param target
- * @param value
- */
- public OMProcessingInstructionImpl(OMContainer parentNode, String target,
- String value, OMFactory factory) {
- super(parentNode, factory);
- this.target = (target == null) ? null : target.trim();
- this.value = (value == null) ? null : value.trim();
- nodeType = OMNode.PI_NODE;
- }
-
- /**
- * Constructor OMProcessingInstructionImpl.
- *
- * @param parentNode
- */
- public OMProcessingInstructionImpl(OMContainer parentNode,
- OMFactory factory) {
- this(parentNode, null, null, factory);
- }
-
- /**
- * Serializes the node with caching.
- *
- * @param omOutput
- * @throws XMLStreamException
- * @see #serialize(org.apache.axiom.om.impl.OMOutputImpl)
- */
- public void serialize(org.apache.axiom.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
- XMLStreamWriter writer = omOutput.getXmlStreamWriter();
- writer.writeProcessingInstruction(this.target+" ", this.value);
- }
-
- /**
- * Serializes the node without caching.
- *
- * @param omOutput
- * @throws XMLStreamException
- * @see #serializeAndConsume(org.apache.axiom.om.impl.OMOutputImpl)
- */
- public void serializeAndConsume(org.apache.axiom.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
- serialize(omOutput);
- }
-
- /**
- * Gets the value of this Processing Instruction.
- *
- * @return string
- */
- public String getValue() {
- return value;
- }
-
- /**
- * Sets the target of this Processing Instruction.
- *
- * @param target
- */
- public void setTarget(String target) {
- this.target = target;
- }
-
- /**
- * Gets the target of this Processing Instruction.
- *
- * @return Returns String.
- */
- public String getTarget() {
- return target;
- }
-
- /**
- * Sets the value of this Processing Instruction.
- *
- * @param text
- */
- public void setValue(String text) {
- this.value = text;
- }
-
- /**
- * Discards this node.
- *
- * @throws OMException
- */
- public void discard() throws OMException {
- if (done) {
- this.detach();
- } else {
- builder.discard((OMElement) this.parent);
- }
- }
-}
+/*
+ * 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.axiom.om.impl.llom;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMProcessingInstruction;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+public class OMProcessingInstructionImpl extends OMNodeImpl implements OMProcessingInstruction {
+ protected String target;
+ protected String value;
+
+ /**
+ * Constructor OMProcessingInstructionImpl.
+ *
+ * @param parentNode
+ * @param target
+ * @param value
+ */
+ public OMProcessingInstructionImpl(OMContainer parentNode, String target,
+ String value, OMFactory factory) {
+ super(parentNode, factory);
+ this.target = (target == null) ? null : target.trim();
+ this.value = (value == null) ? null : value.trim();
+ nodeType = OMNode.PI_NODE;
+ }
+
+ /**
+ * Constructor OMProcessingInstructionImpl.
+ *
+ * @param parentNode
+ */
+ public OMProcessingInstructionImpl(OMContainer parentNode,
+ OMFactory factory) {
+ this(parentNode, null, null, factory);
+ }
+
+ /**
+ * Serializes the node with caching.
+ *
+ * @param omOutput
+ * @throws XMLStreamException
+ * @see #internalSerialize(org.apache.axiom.om.impl.OMOutputImpl)
+ */
+ public void internalSerialize(org.apache.axiom.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
+ XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+ writer.writeProcessingInstruction(this.target+" ", this.value);
+ }
+
+ /**
+ * Serializes the node without caching.
+ *
+ * @param omOutput
+ * @throws XMLStreamException
+ * @see #internalSerializeAndConsume(org.apache.axiom.om.impl.OMOutputImpl)
+ */
+ public void internalSerializeAndConsume(org.apache.axiom.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
+ internalSerialize(omOutput);
+ }
+
+ /**
+ * Gets the value of this Processing Instruction.
+ *
+ * @return string
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Sets the target of this Processing Instruction.
+ *
+ * @param target
+ */
+ public void setTarget(String target) {
+ this.target = target;
+ }
+
+ /**
+ * Gets the target of this Processing Instruction.
+ *
+ * @return Returns String.
+ */
+ public String getTarget() {
+ return target;
+ }
+
+ /**
+ * Sets the value of this Processing Instruction.
+ *
+ * @param text
+ */
+ public void setValue(String text) {
+ this.value = text;
+ }
+
+ /**
+ * Discards this node.
+ *
+ * @throws OMException
+ */
+ public void discard() throws OMException {
+ if (done) {
+ this.detach();
+ } else {
+ builder.discard((OMElement) this.parent);
+ }
+ }
+}
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMTextImpl.java?rev=391260&r1=391259&r2=391260&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMTextImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMTextImpl.java Tue Apr 4 02:33:33 2006
@@ -1,519 +1,519 @@
-/*
- * 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.axiom.om.impl.llom;
-
-
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMConstants;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.OMText;
-import org.apache.axiom.om.OMXMLParserWrapper;
-import org.apache.axiom.om.impl.OMOutputImpl;
-import org.apache.axiom.om.impl.mtom.MTOMStAXSOAPModelBuilder;
-import org.apache.axiom.om.util.Base64;
-import org.apache.axiom.om.util.UUIDGenerator;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-import java.io.IOException;
-import java.io.InputStream;
-
-public class OMTextImpl extends OMNodeImpl implements OMText, OMConstants {
- protected String value = null;
-
- protected OMNamespace textNS;
-
- protected String mimeType;
-
- protected boolean optimize = false;
-
- protected boolean isBinary = false;
-
- /**
- * Field contentID for the mime part used when serializing Binary stuff as
- * MTOM optimized.
- */
- private String contentID = null;
-
- /**
- * Field dataHandler contains the DataHandler
- * Declaring as Object to remove the dependency on
- * Javax.activation.DataHandler
- */
- private Object dataHandlerObject = null;
-
- /**
- * Field nameSpace used when serializing Binary stuff as MTOM optimized.
- */
- protected OMNamespace xopNS = null;
-
- /**
- * Field localName used when serializing Binary stuff as MTOM optimized.
- */
- protected String localName = "Include";
-
- /**
- * Field attributes used when serializing Binary stuff as MTOM optimized.
- */
- protected OMAttribute attribute;
-
- /**
- * Constructor OMTextImpl.
- *
- * @param s
- */
- public OMTextImpl(String s, OMFactory factory) {
- this(s, TEXT_NODE, factory);
- }
-
- /**
- * @param s
- * @param nodeType - OMText can handle CHARACTERS, SPACES, CDATA and ENTITY REFERENCES.
- * Constants for this can be found in OMNode.
- */
- public OMTextImpl(String s, int nodeType, OMFactory factory) {
- super(factory);
- this.value = s;
- this.nodeType = nodeType;
- this.xopNS = new OMNamespaceImpl(
- "http://www.w3.org/2004/08/xop/include", "xop", factory);
- }
-
- /**
- * Constructor OMTextImpl.
- *
- * @param parent
- * @param text
- */
- public OMTextImpl(OMElement parent, String text, OMFactory factory) {
- this(parent, text, TEXT_NODE, factory);
- }
-
- public OMTextImpl(OMElement parent, String text, int nodeType,
- OMFactory factory) {
- super(parent, factory);
- this.value = text;
- done = true;
- this.nodeType = nodeType;
- this.xopNS = new OMNamespaceImpl(
- "http://www.w3.org/2004/08/xop/include", "xop", factory);
- }
-
-
- public OMTextImpl(OMElement parent, QName text, OMFactory factory) {
- this(parent, text, TEXT_NODE, factory);
- }
-
- public OMTextImpl(OMElement parent, QName text, int nodeType,
- OMFactory factory) {
- super(parent, factory);
- this.textNS = ((OMElementImpl) parent).handleNamespace(text);
- this.value = text.getLocalPart();
- done = true;
- this.nodeType = nodeType;
- this.xopNS = new OMNamespaceImpl(
- "http://www.w3.org/2004/08/xop/include", "xop", factory);
- }
-
- /**
- * @param s - base64 encoded String representation of Binary
- * @param mimeType of the Binary
- */
- public OMTextImpl(String s, String mimeType, boolean optimize,
- OMFactory factory) {
- this(null, s, mimeType, optimize, factory);
- }
-
- /**
- * @param parent
- * @param s -
- * base64 encoded String representation of Binary
- * @param mimeType of the Binary
- */
- public OMTextImpl(OMElement parent, String s, String mimeType,
- boolean optimize, OMFactory factory) {
- this(parent, s, factory);
- this.mimeType = mimeType;
- this.optimize = optimize;
- this.isBinary = true;
- done = true;
- this.nodeType = TEXT_NODE;
- }
-
- /**
- * @param dataHandler To send binary optimised content Created programatically.
- */
- public OMTextImpl(Object dataHandler, OMFactory factory) {
- this(dataHandler, true, factory);
- }
-
- /**
- * @param dataHandler
- * @param optimize To send binary content. Created progrmatically.
- */
- public OMTextImpl(Object dataHandler, boolean optimize, OMFactory factory) {
- super(factory);
- this.dataHandlerObject = dataHandler;
- this.isBinary = true;
- this.optimize = optimize;
- done = true;
- this.nodeType = TEXT_NODE;
- this.xopNS = new OMNamespaceImpl(
- "http://www.w3.org/2004/08/xop/include", "xop", factory);
- }
-
- /**
- * @param contentID
- * @param parent
- * @param builder Used when the builder is encountered with a XOP:Include tag
- * Stores a reference to the builder and the content-id. Supports
- * deferred parsing of MIME messages.
- */
- public OMTextImpl(String contentID, OMElement parent,
- OMXMLParserWrapper builder, OMFactory factory) {
- super(parent, factory);
- this.contentID = contentID;
- this.optimize = true;
- this.isBinary = true;
- this.builder = builder;
- this.nodeType = TEXT_NODE;
- this.xopNS = new OMNamespaceImpl(
- "http://www.w3.org/2004/08/xop/include", "xop", factory);
- }
-
- /**
- * @param omOutput
- * @throws XMLStreamException
- */
- public void serialize(OMOutputImpl omOutput) throws XMLStreamException {
- serializeLocal(omOutput);
-
- }
-
- /**
- * Writes the relevant output.
- *
- * @param omOutput
- * @throws XMLStreamException
- */
- private void writeOutput(XMLStreamWriter writer) throws XMLStreamException {
- int type = getType();
- if (type == TEXT_NODE || type == SPACE_NODE) {
- writer.writeCharacters(this.getText());
- } else if (type == CDATA_SECTION_NODE) {
- writer.writeCData(this.getText());
- } else if (type == ENTITY_REFERENCE_NODE) {
- writer.writeEntityRef(this.getText());
- }
- }
-
- /**
- * Returns the value.
- */
- public String getText() throws OMException {
- if (textNS != null) {
- return getTextString();
- }else if (this.value != null) {
- return this.value;
- } else {
- try {
- InputStream inStream;
- inStream = this.getInputStream();
- byte[] data;
- StringBuffer text = new StringBuffer();
- do {
- data = new byte[1024];
- int len;
- while ((len = inStream.read(data)) > 0) {
- byte[] temp = new byte[len];
- System.arraycopy(data, 0, temp, 0, len);
- text.append(Base64.encode(temp));
- }
-
- } while (inStream.available() > 0);
-
- return text.toString();
- } catch (Exception e) {
- throw new OMException(e);
- }
- }
- }
-
-
-/**
- * Returns the value.
- */
- public QName getTextAsQName() throws OMException {
- if (textNS != null) {
- String prefix = textNS.getPrefix();
- if (prefix == null || "".equals(prefix)) {
- return new QName(textNS.getName(), value);
- }else {
- return new QName(textNS.getName(), value, prefix);
- }
- }else if (this.value != null) {
- return new QName(value);
- } else {
- try {
- InputStream inStream;
- inStream = this.getInputStream();
- byte[] data;
- StringBuffer text = new StringBuffer();
- do {
- data = new byte[1024];
- int len;
- while ((len = inStream.read(data)) > 0) {
- byte[] temp = new byte[len];
- System.arraycopy(data, 0, temp, 0, len);
- text.append(Base64.encode(temp));
- }
-
- } while (inStream.available() > 0);
-
- return new QName(text.toString());
- } catch (Exception e) {
- throw new OMException(e);
- }
- }
- }
-
- public boolean isOptimized() {
- return optimize;
- }
-
- public void setOptimize(boolean value) {
- this.optimize = value;
- if (value) {
- isBinary = true;
- }
- }
-
-
- /**
- * Gets the datahandler.
- *
- * @return Returns javax.activation.DataHandler
- */
- public Object getDataHandler() {
- /*
- * this should return a DataHandler containing the binary data
- * reperesented by the Base64 strings stored in OMText
- */
-
- if(isBinary){
-
- }
-
- if ((value != null || textNS != null) & isBinary) {
- String text = textNS == null ? value : getTextString();
- return org.apache.axiom.attachments.DataHandlerUtils.getDataHandlerFromText(text, mimeType);
- } else {
-
- if (dataHandlerObject == null) {
- if (contentID == null) {
- throw new RuntimeException("ContentID is null");
- }
- dataHandlerObject = ((MTOMStAXSOAPModelBuilder) builder)
- .getDataHandler(contentID);
- }
- return dataHandlerObject;
- }
- }
-
- private String getTextString() {
- if(textNS != null){
- String prefix = textNS.getPrefix();
- if (prefix == null || "".equals(prefix)) {
- return value;
- }else {
- return prefix + ":" + value;
- }
- }
-
- return null;
- }
-
- public String getLocalName() {
- return localName;
- }
-
- public java.io.InputStream getInputStream() throws OMException {
- if (isBinary) {
- if (dataHandlerObject == null) {
- getDataHandler();
- }
- InputStream inStream;
- javax.activation.DataHandler dataHandler = (javax.activation.DataHandler) dataHandlerObject;
- try {
- inStream = dataHandler.getDataSource().getInputStream();
- } catch (IOException e) {
- throw new OMException(
- "Cannot get InputStream from DataHandler." + e);
- }
- return inStream;
- } else {
- throw new OMException("Unsupported Operation");
- }
- }
-
- public String getContentID() {
- if (contentID == null) {
- contentID = UUIDGenerator.getUUID()
- + "@apache.org";
- }
- return this.contentID;
- }
-
- public boolean isComplete() {
- return true;
- }
-
- public void serializeAndConsume(OMOutputImpl omOutput)
- throws XMLStreamException {
- serializeLocal(omOutput);
- }
-
- private void serializeLocal(OMOutputImpl omOutput) throws XMLStreamException {
- XMLStreamWriter xmlStreamWriter = omOutput.getXmlStreamWriter();
-
- if (!this.isBinary) {
- writeOutput(xmlStreamWriter);
- } else {
-
- if (omOutput.isOptimized()) {
- if (contentID == null) {
- contentID = omOutput.getNextContentId();
- }
- // send binary as MTOM optimised
- this.attribute = new OMAttributeImpl("href",
- new OMNamespaceImpl("", "", this.factory), "cid:" + getContentID(),
- this.factory);
- this.serializeStartpart(xmlStreamWriter);
- omOutput.writeOptimized(this);
- xmlStreamWriter.writeEndElement();
- } else {
- xmlStreamWriter.writeCharacters(this.getText());
- }
- }
- }
-
- /*
- * Methods to copy from OMSerialize utils
- */
- private void serializeStartpart(XMLStreamWriter writer)
- throws XMLStreamException {
- String nameSpaceName;
- String writer_prefix;
- String prefix;
- if (this.xopNS != null) {
- nameSpaceName = this.xopNS.getName();
- writer_prefix = writer.getPrefix(nameSpaceName);
- prefix = this.xopNS.getPrefix();
- if (nameSpaceName != null) {
- if (writer_prefix != null) {
- writer
- .writeStartElement(nameSpaceName, this
- .getLocalName());
- } else {
- if (prefix != null) {
- writer.writeStartElement(prefix, this.getLocalName(),
- nameSpaceName);
- //TODO FIX ME
- //writer.writeNamespace(prefix, nameSpaceName);
- writer.setPrefix(prefix, nameSpaceName);
- } else {
- writer.writeStartElement(nameSpaceName, this
- .getLocalName());
- writer.writeDefaultNamespace(nameSpaceName);
- writer.setDefaultNamespace(nameSpaceName);
- }
- }
- } else {
- writer.writeStartElement(this.getLocalName());
- }
- } else {
- writer.writeStartElement(this.getLocalName());
- }
- // add the elements attribute "href"
- serializeAttribute(this.attribute, writer);
- // add the namespace
- serializeNamespace(this.xopNS, writer);
- }
-
- /**
- * Method serializeAttribute.
- *
- * @param attr
- * @throws XMLStreamException
- */
- static void serializeAttribute(OMAttribute attr, XMLStreamWriter writer)
- throws XMLStreamException {
- // first check whether the attribute is associated with a namespace
- OMNamespace ns = attr.getNamespace();
- String prefix;
- String namespaceName;
- if (ns != null) {
- // add the prefix if it's availble
- prefix = ns.getPrefix();
- namespaceName = ns.getName();
- if (prefix != null) {
- writer.writeAttribute(prefix, namespaceName, attr
- .getLocalName(), attr.getAttributeValue());
- } else {
- writer.writeAttribute(namespaceName, attr.getLocalName(), attr
- .getAttributeValue());
- }
- } else {
- writer.writeAttribute(attr.getLocalName(), attr.getAttributeValue());
- }
- }
-
- /**
- * Method serializeNamespace.
- *
- * @param namespace
- * @param omOutput
- * @throws XMLStreamException
- */
- static void serializeNamespace(OMNamespace namespace, XMLStreamWriter writer)
- throws XMLStreamException {
- if (namespace != null) {
- String uri = namespace.getName();
- String ns_prefix = namespace.getPrefix();
- writer.writeNamespace(ns_prefix, namespace.getName());
- writer.setPrefix(ns_prefix, uri);
- }
- }
-
- /**
- * A slightly different implementation of the discard method.
- *
- * @throws OMException
- */
- public void discard() throws OMException {
- if (done) {
- this.detach();
- } else {
- builder.discard((OMElement) this.parent);
- }
- }
-
-}
+/*
+ * 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.axiom.om.impl.llom;
+
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMConstants;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.OMOutputImpl;
+import org.apache.axiom.om.impl.mtom.MTOMStAXSOAPModelBuilder;
+import org.apache.axiom.om.util.Base64;
+import org.apache.axiom.om.util.UUIDGenerator;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class OMTextImpl extends OMNodeImpl implements OMText, OMConstants {
+ protected String value = null;
+
+ protected OMNamespace textNS;
+
+ protected String mimeType;
+
+ protected boolean optimize = false;
+
+ protected boolean isBinary = false;
+
+ /**
+ * Field contentID for the mime part used when serializing Binary stuff as
+ * MTOM optimized.
+ */
+ private String contentID = null;
+
+ /**
+ * Field dataHandler contains the DataHandler
+ * Declaring as Object to remove the dependency on
+ * Javax.activation.DataHandler
+ */
+ private Object dataHandlerObject = null;
+
+ /**
+ * Field nameSpace used when serializing Binary stuff as MTOM optimized.
+ */
+ protected OMNamespace xopNS = null;
+
+ /**
+ * Field localName used when serializing Binary stuff as MTOM optimized.
+ */
+ protected String localName = "Include";
+
+ /**
+ * Field attributes used when serializing Binary stuff as MTOM optimized.
+ */
+ protected OMAttribute attribute;
+
+ /**
+ * Constructor OMTextImpl.
+ *
+ * @param s
+ */
+ public OMTextImpl(String s, OMFactory factory) {
+ this(s, TEXT_NODE, factory);
+ }
+
+ /**
+ * @param s
+ * @param nodeType - OMText can handle CHARACTERS, SPACES, CDATA and ENTITY REFERENCES.
+ * Constants for this can be found in OMNode.
+ */
+ public OMTextImpl(String s, int nodeType, OMFactory factory) {
+ super(factory);
+ this.value = s;
+ this.nodeType = nodeType;
+ this.xopNS = new OMNamespaceImpl(
+ "http://www.w3.org/2004/08/xop/include", "xop", factory);
+ }
+
+ /**
+ * Constructor OMTextImpl.
+ *
+ * @param parent
+ * @param text
+ */
+ public OMTextImpl(OMElement parent, String text, OMFactory factory) {
+ this(parent, text, TEXT_NODE, factory);
+ }
+
+ public OMTextImpl(OMElement parent, String text, int nodeType,
+ OMFactory factory) {
+ super(parent, factory);
+ this.value = text;
+ done = true;
+ this.nodeType = nodeType;
+ this.xopNS = new OMNamespaceImpl(
+ "http://www.w3.org/2004/08/xop/include", "xop", factory);
+ }
+
+
+ public OMTextImpl(OMElement parent, QName text, OMFactory factory) {
+ this(parent, text, TEXT_NODE, factory);
+ }
+
+ public OMTextImpl(OMElement parent, QName text, int nodeType,
+ OMFactory factory) {
+ super(parent, factory);
+ this.textNS = ((OMElementImpl) parent).handleNamespace(text);
+ this.value = text.getLocalPart();
+ done = true;
+ this.nodeType = nodeType;
+ this.xopNS = new OMNamespaceImpl(
+ "http://www.w3.org/2004/08/xop/include", "xop", factory);
+ }
+
+ /**
+ * @param s - base64 encoded String representation of Binary
+ * @param mimeType of the Binary
+ */
+ public OMTextImpl(String s, String mimeType, boolean optimize,
+ OMFactory factory) {
+ this(null, s, mimeType, optimize, factory);
+ }
+
+ /**
+ * @param parent
+ * @param s -
+ * base64 encoded String representation of Binary
+ * @param mimeType of the Binary
+ */
+ public OMTextImpl(OMElement parent, String s, String mimeType,
+ boolean optimize, OMFactory factory) {
+ this(parent, s, factory);
+ this.mimeType = mimeType;
+ this.optimize = optimize;
+ this.isBinary = true;
+ done = true;
+ this.nodeType = TEXT_NODE;
+ }
+
+ /**
+ * @param dataHandler To send binary optimised content Created programatically.
+ */
+ public OMTextImpl(Object dataHandler, OMFactory factory) {
+ this(dataHandler, true, factory);
+ }
+
+ /**
+ * @param dataHandler
+ * @param optimize To send binary content. Created progrmatically.
+ */
+ public OMTextImpl(Object dataHandler, boolean optimize, OMFactory factory) {
+ super(factory);
+ this.dataHandlerObject = dataHandler;
+ this.isBinary = true;
+ this.optimize = optimize;
+ done = true;
+ this.nodeType = TEXT_NODE;
+ this.xopNS = new OMNamespaceImpl(
+ "http://www.w3.org/2004/08/xop/include", "xop", factory);
+ }
+
+ /**
+ * @param contentID
+ * @param parent
+ * @param builder Used when the builder is encountered with a XOP:Include tag
+ * Stores a reference to the builder and the content-id. Supports
+ * deferred parsing of MIME messages.
+ */
+ public OMTextImpl(String contentID, OMElement parent,
+ OMXMLParserWrapper builder, OMFactory factory) {
+ super(parent, factory);
+ this.contentID = contentID;
+ this.optimize = true;
+ this.isBinary = true;
+ this.builder = builder;
+ this.nodeType = TEXT_NODE;
+ this.xopNS = new OMNamespaceImpl(
+ "http://www.w3.org/2004/08/xop/include", "xop", factory);
+ }
+
+ /**
+ * @param omOutput
+ * @throws XMLStreamException
+ */
+ public void internalSerialize(OMOutputImpl omOutput) throws XMLStreamException {
+ internalSerializeLocal(omOutput);
+
+ }
+
+ /**
+ * Writes the relevant output.
+ *
+ * @param writer
+ * @throws XMLStreamException
+ */
+ private void writeOutput(XMLStreamWriter writer) throws XMLStreamException {
+ int type = getType();
+ if (type == TEXT_NODE || type == SPACE_NODE) {
+ writer.writeCharacters(this.getText());
+ } else if (type == CDATA_SECTION_NODE) {
+ writer.writeCData(this.getText());
+ } else if (type == ENTITY_REFERENCE_NODE) {
+ writer.writeEntityRef(this.getText());
+ }
+ }
+
+ /**
+ * Returns the value.
+ */
+ public String getText() throws OMException {
+ if (textNS != null) {
+ return getTextString();
+ }else if (this.value != null) {
+ return this.value;
+ } else {
+ try {
+ InputStream inStream;
+ inStream = this.getInputStream();
+ byte[] data;
+ StringBuffer text = new StringBuffer();
+ do {
+ data = new byte[1024];
+ int len;
+ while ((len = inStream.read(data)) > 0) {
+ byte[] temp = new byte[len];
+ System.arraycopy(data, 0, temp, 0, len);
+ text.append(Base64.encode(temp));
+ }
+
+ } while (inStream.available() > 0);
+
+ return text.toString();
+ } catch (Exception e) {
+ throw new OMException(e);
+ }
+ }
+ }
+
+
+/**
+ * Returns the value.
+ */
+ public QName getTextAsQName() throws OMException {
+ if (textNS != null) {
+ String prefix = textNS.getPrefix();
+ if (prefix == null || "".equals(prefix)) {
+ return new QName(textNS.getName(), value);
+ }else {
+ return new QName(textNS.getName(), value, prefix);
+ }
+ }else if (this.value != null) {
+ return new QName(value);
+ } else {
+ try {
+ InputStream inStream;
+ inStream = this.getInputStream();
+ byte[] data;
+ StringBuffer text = new StringBuffer();
+ do {
+ data = new byte[1024];
+ int len;
+ while ((len = inStream.read(data)) > 0) {
+ byte[] temp = new byte[len];
+ System.arraycopy(data, 0, temp, 0, len);
+ text.append(Base64.encode(temp));
+ }
+
+ } while (inStream.available() > 0);
+
+ return new QName(text.toString());
+ } catch (Exception e) {
+ throw new OMException(e);
+ }
+ }
+ }
+
+ public boolean isOptimized() {
+ return optimize;
+ }
+
+ public void setOptimize(boolean value) {
+ this.optimize = value;
+ if (value) {
+ isBinary = true;
+ }
+ }
+
+
+ /**
+ * Gets the datahandler.
+ *
+ * @return Returns javax.activation.DataHandler
+ */
+ public Object getDataHandler() {
+ /*
+ * this should return a DataHandler containing the binary data
+ * reperesented by the Base64 strings stored in OMText
+ */
+
+ if(isBinary){
+
+ }
+
+ if ((value != null || textNS != null) & isBinary) {
+ String text = textNS == null ? value : getTextString();
+ return org.apache.axiom.attachments.DataHandlerUtils.getDataHandlerFromText(text, mimeType);
+ } else {
+
+ if (dataHandlerObject == null) {
+ if (contentID == null) {
+ throw new RuntimeException("ContentID is null");
+ }
+ dataHandlerObject = ((MTOMStAXSOAPModelBuilder) builder)
+ .getDataHandler(contentID);
+ }
+ return dataHandlerObject;
+ }
+ }
+
+ private String getTextString() {
+ if(textNS != null){
+ String prefix = textNS.getPrefix();
+ if (prefix == null || "".equals(prefix)) {
+ return value;
+ }else {
+ return prefix + ":" + value;
+ }
+ }
+
+ return null;
+ }
+
+ public String getLocalName() {
+ return localName;
+ }
+
+ public java.io.InputStream getInputStream() throws OMException {
+ if (isBinary) {
+ if (dataHandlerObject == null) {
+ getDataHandler();
+ }
+ InputStream inStream;
+ javax.activation.DataHandler dataHandler = (javax.activation.DataHandler) dataHandlerObject;
+ try {
+ inStream = dataHandler.getDataSource().getInputStream();
+ } catch (IOException e) {
+ throw new OMException(
+ "Cannot get InputStream from DataHandler." + e);
+ }
+ return inStream;
+ } else {
+ throw new OMException("Unsupported Operation");
+ }
+ }
+
+ public String getContentID() {
+ if (contentID == null) {
+ contentID = UUIDGenerator.getUUID()
+ + "@apache.org";
+ }
+ return this.contentID;
+ }
+
+ public boolean isComplete() {
+ return true;
+ }
+
+ public void internalSerializeAndConsume(OMOutputImpl omOutput)
+ throws XMLStreamException {
+ internalSerializeLocal(omOutput);
+ }
+
+ private void internalSerializeLocal(OMOutputImpl omOutput) throws XMLStreamException {
+ XMLStreamWriter xmlStreamWriter = omOutput.getXmlStreamWriter();
+
+ if (!this.isBinary) {
+ writeOutput(xmlStreamWriter);
+ } else {
+
+ if (omOutput.isOptimized()) {
+ if (contentID == null) {
+ contentID = omOutput.getNextContentId();
+ }
+ // send binary as MTOM optimised
+ this.attribute = new OMAttributeImpl("href",
+ new OMNamespaceImpl("", "", this.factory), "cid:" + getContentID(),
+ this.factory);
+ this.serializeStartpart(xmlStreamWriter);
+ omOutput.writeOptimized(this);
+ xmlStreamWriter.writeEndElement();
+ } else {
+ xmlStreamWriter.writeCharacters(this.getText());
+ }
+ }
+ }
+
+ /*
+ * Methods to copy from OMSerialize utils
+ */
+ private void serializeStartpart(XMLStreamWriter writer)
+ throws XMLStreamException {
+ String nameSpaceName;
+ String writer_prefix;
+ String prefix;
+ if (this.xopNS != null) {
+ nameSpaceName = this.xopNS.getName();
+ writer_prefix = writer.getPrefix(nameSpaceName);
+ prefix = this.xopNS.getPrefix();
+ if (nameSpaceName != null) {
+ if (writer_prefix != null) {
+ writer
+ .writeStartElement(nameSpaceName, this
+ .getLocalName());
+ } else {
+ if (prefix != null) {
+ writer.writeStartElement(prefix, this.getLocalName(),
+ nameSpaceName);
+ //TODO FIX ME
+ //writer.writeNamespace(prefix, nameSpaceName);
+ writer.setPrefix(prefix, nameSpaceName);
+ } else {
+ writer.writeStartElement(nameSpaceName, this
+ .getLocalName());
+ writer.writeDefaultNamespace(nameSpaceName);
+ writer.setDefaultNamespace(nameSpaceName);
+ }
+ }
+ } else {
+ writer.writeStartElement(this.getLocalName());
+ }
+ } else {
+ writer.writeStartElement(this.getLocalName());
+ }
+ // add the elements attribute "href"
+ serializeAttribute(this.attribute, writer);
+ // add the namespace
+ serializeNamespace(this.xopNS, writer);
+ }
+
+ /**
+ * Method serializeAttribute.
+ *
+ * @param attr
+ * @throws XMLStreamException
+ */
+ static void serializeAttribute(OMAttribute attr, XMLStreamWriter writer)
+ throws XMLStreamException {
+ // first check whether the attribute is associated with a namespace
+ OMNamespace ns = attr.getNamespace();
+ String prefix;
+ String namespaceName;
+ if (ns != null) {
+ // add the prefix if it's availble
+ prefix = ns.getPrefix();
+ namespaceName = ns.getName();
+ if (prefix != null) {
+ writer.writeAttribute(prefix, namespaceName, attr
+ .getLocalName(), attr.getAttributeValue());
+ } else {
+ writer.writeAttribute(namespaceName, attr.getLocalName(), attr
+ .getAttributeValue());
+ }
+ } else {
+ writer.writeAttribute(attr.getLocalName(), attr.getAttributeValue());
+ }
+ }
+
+ /**
+ * Method serializeNamespace.
+ *
+ * @param namespace
+ * @param writer
+ * @throws XMLStreamException
+ */
+ static void serializeNamespace(OMNamespace namespace, XMLStreamWriter writer)
+ throws XMLStreamException {
+ if (namespace != null) {
+ String uri = namespace.getName();
+ String ns_prefix = namespace.getPrefix();
+ writer.writeNamespace(ns_prefix, namespace.getName());
+ writer.setPrefix(ns_prefix, uri);
+ }
+ }
+
+ /**
+ * A slightly different implementation of the discard method.
+ *
+ * @throws OMException
+ */
+ public void discard() throws OMException {
+ if (done) {
+ this.detach();
+ } else {
+ builder.discard((OMElement) this.parent);
+ }
+ }
+
+}