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 ru...@apache.org on 2008/08/27 03:06:55 UTC
svn commit: r689316 [2/3] - in
/webservices/commons/trunk/modules/axiom/modules/axiom-c14n: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/axiom/ src/main/java/org/apache/axiom/c14n/
src/main/java...
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/CanonicalizerBase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/CanonicalizerBase.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/CanonicalizerBase.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/CanonicalizerBase.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,534 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.impl;
+
+import org.apache.axiom.c14n.CanonicalizerSpi;
+import org.apache.axiom.c14n.exceptions.CanonicalizationException;
+import org.apache.axiom.c14n.helpers.AttrCompare;
+import org.apache.axiom.c14n.omwrapper.AttrImpl;
+import org.apache.axiom.c14n.omwrapper.interfaces.*;
+import org.apache.axiom.c14n.utils.Constants;
+import org.apache.axiom.c14n.utils.UnsyncByteArrayOutputStream;
+import org.apache.axiom.om.OMAbstractFactory;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.*;
+
+public abstract class CanonicalizerBase extends CanonicalizerSpi {
+ //Constants to be outputed, In char array form, so
+ //less garbage is generate when outputed.
+ private static final byte[] _END_PI = {'?', '>'};
+ private static final byte[] _BEGIN_PI = {'<', '?'};
+ private static final byte[] _END_COMM = {'-', '-', '>'};
+ private static final byte[] _BEGIN_COMM = {'<', '!', '-', '-'};
+ private static final byte[] __XA_ = {'&', '#', 'x', 'A', ';'};
+ private static final byte[] __X9_ = {'&', '#', 'x', '9', ';'};
+ private static final byte[] _QUOT_ = {'&', 'q', 'u', 'o', 't', ';'};
+ private static final byte[] __XD_ = {'&', '#', 'x', 'D', ';'};
+ private static final byte[] _GT_ = {'&', 'g', 't', ';'};
+ private static final byte[] _LT_ = {'&', 'l', 't', ';'};
+ private static final byte[] _END_TAG = {'<', '/'};
+ private static final byte[] _AMP_ = {'&', 'a', 'm', 'p', ';'};
+ final static AttrCompare COMPARE = new AttrCompare();
+ final static String XML = "xml";
+ final static String XMLNS = "xmlns";
+ final static byte[] equalsStr = {'=', '\"'};
+ static final int NODE_BEFORE_DOCUMENT_ELEMENT = -1;
+ static final int NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT = 0;
+ static final int NODE_AFTER_DOCUMENT_ELEMENT = 1;
+ //The null xmlns definiton.
+ protected static final Attr nullNode;
+
+ static {
+ try {
+// nullNode = (Attr) WrapperFactory.getNode(
+// OMAbstractFactory.getOMFactory().createOMNamespace("", ""));
+ nullNode = new AttrImpl(
+ OMAbstractFactory.getOMFactory().createOMNamespace("", ""), null, null);
+ } catch (Exception e) {
+ throw new RuntimeException("Unable to create nullNode"/*,*/ + e);
+ }
+ }
+
+ List nodeFilter;
+
+ boolean _includeComments;
+
+ /**
+ * The node to be skiped/excluded from the OM tree
+ * in subtree canonicalizations.
+ */
+ Node _excludeNode = null;
+ OutputStream _writer = new UnsyncByteArrayOutputStream();//null;
+
+ /**
+ * Constructor CanonicalizerBase
+ *
+ * @param includeComments
+ */
+ public CanonicalizerBase(boolean includeComments) {
+ this._includeComments = includeComments;
+ }
+
+ /**
+ * Method engineCanonicalizeSubTree
+ *
+ * @param rootNode
+ * @throws CanonicalizationException
+ * @inheritDoc
+ */
+ public byte[] engineCanonicalizeSubTree(Node rootNode)
+ throws CanonicalizationException {
+ return engineCanonicalizeSubTree(rootNode, (Node) null);
+ }
+
+ /**
+ * @param _writer The _writer to set.
+ */
+ public void setWriter(OutputStream _writer) {
+ this._writer = _writer;
+ }
+
+ /**
+ * Canonicalizes a Subtree node.
+ *
+ * @param rootNode the root of the subtree to canicalize
+ * @param excludeNode a node to be excluded from the canonicalize operation
+ * @return The canonicalize stream.
+ * @throws CanonicalizationException
+ */
+ byte[] engineCanonicalizeSubTree(Node rootNode, Node excludeNode)
+ throws CanonicalizationException {
+ this._excludeNode = excludeNode;
+ try {
+ NameSpaceSymbTable ns = new NameSpaceSymbTable();
+ int nodeLevel = NODE_BEFORE_DOCUMENT_ELEMENT;
+ if (rootNode instanceof Element) {
+ //Fills the nssymbtable with the definitions of the parent of the root subnode
+ getParentNameSpaces((Element) rootNode, ns);
+ nodeLevel = NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
+ }
+ this.canonicalizeSubTree(rootNode, ns, rootNode, nodeLevel);
+ this._writer.close();
+ if (this._writer instanceof ByteArrayOutputStream) {
+ byte []result = ((ByteArrayOutputStream) this._writer).toByteArray();
+ if (reset) {
+ ((ByteArrayOutputStream) this._writer).reset();
+ }
+ return result;
+ } else if (this._writer instanceof UnsyncByteArrayOutputStream) {
+ byte []result = ((UnsyncByteArrayOutputStream) this._writer).toByteArray();
+ if (reset) {
+ ((UnsyncByteArrayOutputStream) this._writer).reset();
+ }
+ return result;
+ }
+ return null;
+
+ } catch (UnsupportedEncodingException ex) {
+ throw new CanonicalizationException("empty", ex);
+ } catch (IOException ex) {
+ throw new CanonicalizationException("empty", ex);
+ }
+ }
+
+ /**
+ * Method canonicalizeSubTree, this function is a recursive one.
+ *
+ * @param currentNode
+ * @param ns
+ * @param endnode
+ * @throws CanonicalizationException
+ * @throws IOException
+ */
+ final void canonicalizeSubTree(Node currentNode, NameSpaceSymbTable ns, Node endnode,
+ int documentLevel)
+ throws CanonicalizationException, IOException {
+ Node sibling = null;
+ Node parentNode = null;
+ final OutputStream writer = this._writer;
+ final Node excludeNode = this._excludeNode;
+ final boolean includeComments = this._includeComments;
+ Map cache = new HashMap();
+ do {
+ switch (currentNode.getNodeType()) {
+
+ case Node.DOCUMENT_TYPE_NODE :
+ default :
+ break;
+
+ case Node.ENTITY_NODE :
+ case Node.NOTATION_NODE :
+ case Node.ATTRIBUTE_NODE :
+ // illegal node type during traversal
+ throw new CanonicalizationException("empty");
+
+ case Node.DOCUMENT_FRAGMENT_NODE :
+ case Node.DOCUMENT_NODE :
+ ns.outputNodePush();
+ sibling = currentNode.getFirstChild();
+ break;
+
+ case Node.COMMENT_NODE :
+ if (includeComments) {
+ outputCommentToWriter((Comment) currentNode, writer, documentLevel);
+ }
+ break;
+
+ case Node.PROCESSING_INSTRUCTION_NODE :
+ outputPItoWriter((ProcessingInstruction) currentNode, writer, documentLevel);
+ break;
+
+ case Node.TEXT_NODE :
+// Axiom gives everything as Text
+ outputTextToWriter(currentNode.getNodeValue(), writer);
+ break;
+ case Node.CDATA_SECTION_NODE :
+// break;
+
+ case Node.ELEMENT_NODE :
+ documentLevel = NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
+ if (currentNode == excludeNode) {
+ break;
+ }
+ Element currentElement = (Element) currentNode;
+ //Add a level to the nssymbtable. So latter can be pop-back.
+ ns.outputNodePush();
+ writer.write('<');
+ String name = currentElement.getTagName();
+ UtfHelper.writeByte(name, writer, cache);
+
+ Iterator attrs = this.handleAttributesSubtree(currentElement, ns);
+ if (attrs != null) {
+ //we output all Attrs which are available
+ while (attrs.hasNext()) {
+ Attr attr = (Attr) attrs.next();
+ outputAttrToWriter(attr.getNodeName(), attr.getNodeValue(), writer, cache);
+ }
+ }
+ writer.write('>');
+ sibling = currentNode.getFirstChild();
+ if (sibling == null) {
+ writer.write(_END_TAG);
+ UtfHelper.writeStringToUtf8(name, writer);
+ writer.write('>');
+ //We fineshed with this level, pop to the previous definitions.
+ ns.outputNodePop();
+ if (parentNode != null) {
+ sibling = currentNode.getNextSibling();
+ }
+ } else {
+ parentNode = currentElement;
+ }
+ break;
+ }
+ while (sibling == null && parentNode != null) {
+ writer.write(_END_TAG);
+ UtfHelper.writeByte(((Element) parentNode).getTagName(), writer, cache);
+ writer.write('>');
+ //We fineshed with this level, pop to the previous definitions.
+ ns.outputNodePop();
+ if (parentNode == endnode)
+ return;
+ sibling = parentNode.getNextSibling();
+ parentNode = parentNode.getParentNode();
+ if (!(parentNode instanceof Element)) {
+ documentLevel = NODE_AFTER_DOCUMENT_ELEMENT;
+ parentNode = null;
+ }
+ }
+ if (sibling == null)
+ return;
+ currentNode = sibling;
+ sibling = currentNode.getNextSibling();
+ } while (true);
+ }
+
+ void handleParent(Element e, NameSpaceSymbTable ns) {
+ if (!e.hasAttributes()) {
+ return;
+ }
+ NamedNodeMap attrs = e.getAttributes();
+ int attrsLength = attrs.getLength();
+ for (int i = 0; i < attrsLength; i++) {
+ Attr N = (Attr) attrs.item(i);
+ if (Constants.NamespaceSpecNS != N.getNamespaceURI()) {
+ //Not a namespace definition, ignore.
+ continue;
+ }
+
+ String NName = N.getLocalName();
+ String NValue = N.getNodeValue();
+ if (XML.equals(NName)
+ && Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) {
+ //xmlns:xml="http://www.w3.org/XML/1998/namespace"
+ continue;
+ }
+ ns.addMapping(NName, NValue, N);
+ }
+ }
+
+ /**
+ * Adds to ns the definitons from the parent elements of el
+ *
+ * @param el
+ * @param ns
+ */
+ final void getParentNameSpaces(Element el, NameSpaceSymbTable ns) {
+ List parents = new ArrayList(10);
+ Node n1 = el.getParentNode();
+ if (!(n1 instanceof Element)) {
+ return;
+ }
+ //Obtain all the parents of the elemnt
+ Element parent = (Element) n1;
+ while (parent != null) {
+ parents.add(parent);
+ Node n = parent.getParentNode();
+ if (!(n instanceof Element)) {
+ break;
+ }
+ parent = (Element) n;
+ }
+ //Visit them in reverse order.
+ ListIterator it = parents.listIterator(parents.size());
+ while (it.hasPrevious()) {
+ Element ele = (Element) it.previous();
+ handleParent(ele, ns);
+ }
+ Attr nsprefix;
+ if (((nsprefix = ns.getMappingWithoutRendered("xmlns")) != null)
+ && "".equals(nsprefix.getValue())) {
+ ns.addMappingAndRender("xmlns", "", nullNode);
+ }
+ }
+
+ abstract Iterator handleAttributesSubtree(Element E, NameSpaceSymbTable ns)
+ throws CanonicalizationException;
+
+ /**
+ * Outputs an Attribute to the internal Writer.
+ * <p/>
+ * The string value of the node is modified by replacing
+ * <UL>
+ * <LI>all ampersands (&) with <CODE>&amp;</CODE></LI>
+ * <LI>all open angle brackets (<) with <CODE>&lt;</CODE></LI>
+ * <LI>all quotation mark characters with <CODE>&quot;</CODE></LI>
+ * <LI>and the whitespace characters <CODE>#x9</CODE>, #xA, and #xD, with character
+ * references. The character references are written in uppercase
+ * hexadecimal with no leading zeroes (for example, <CODE>#xD</CODE> is represented
+ * by the character reference <CODE>&#xD;</CODE>)</LI>
+ * </UL>
+ *
+ * @param name
+ * @param value
+ * @param writer
+ * @throws IOException
+ */
+ static final void outputAttrToWriter(final String name, final String value, final OutputStream writer,
+ final Map cache) throws IOException {
+ writer.write(' ');
+ UtfHelper.writeByte(name, writer, cache);
+ writer.write(equalsStr);
+ byte []toWrite;
+ final int length = value.length();
+ int i = 0;
+ while (i < length) {
+ char c = value.charAt(i++);
+
+ switch (c) {
+
+ case '&' :
+ toWrite = _AMP_;
+ break;
+
+ case '<' :
+ toWrite = _LT_;
+ break;
+
+ case '"' :
+ toWrite = _QUOT_;
+ break;
+
+ case 0x09 : // '\t'
+ toWrite = __X9_;
+ break;
+
+ case 0x0A : // '\n'
+ toWrite = __XA_;
+ break;
+
+ case 0x0D : // '\r'
+ toWrite = __XD_;
+ break;
+
+ default :
+ if (c < 0x80) {
+ writer.write(c);
+ } else {
+ UtfHelper.writeCharToUtf8(c, writer);
+ }
+ ;
+ continue;
+ }
+ writer.write(toWrite);
+ }
+
+ writer.write('\"');
+ }
+
+ /**
+ * Outputs a PI to the internal Writer.
+ *
+ * @param currentPI
+ * @param writer where to write the things
+ * @throws IOException
+ */
+ static final void outputPItoWriter(ProcessingInstruction currentPI, OutputStream writer, int position) throws IOException {
+
+ if (position == NODE_AFTER_DOCUMENT_ELEMENT) {
+ writer.write('\n');
+ }
+ writer.write(_BEGIN_PI);
+
+ final String target = currentPI.getTarget();
+ int length = target.length();
+
+ for (int i = 0; i < length; i++) {
+ char c = target.charAt(i);
+ if (c == 0x0D) {
+ writer.write(__XD_);
+ } else {
+ if (c < 0x80) {
+ writer.write(c);
+ } else {
+ UtfHelper.writeCharToUtf8(c, writer);
+ }
+ ;
+ }
+ }
+
+ final String data = currentPI.getData();
+
+ length = data.length();
+
+ if (length > 0) {
+ writer.write(' ');
+
+ for (int i = 0; i < length; i++) {
+ char c = data.charAt(i);
+ if (c == 0x0D) {
+ writer.write(__XD_);
+ } else {
+ UtfHelper.writeCharToUtf8(c, writer);
+ }
+ }
+ }
+
+ writer.write(_END_PI);
+ if (position == NODE_BEFORE_DOCUMENT_ELEMENT) {
+ writer.write('\n');
+ }
+ }
+
+ /**
+ * Method outputCommentToWriter
+ *
+ * @param currentComment
+ * @param writer writer where to write the things
+ * @throws IOException
+ */
+ static final void outputCommentToWriter(Comment currentComment, OutputStream writer, int position) throws IOException {
+ if (position == NODE_AFTER_DOCUMENT_ELEMENT) {
+ writer.write('\n');
+ }
+ writer.write(_BEGIN_COMM);
+
+ final String data = currentComment.getData();
+ final int length = data.length();
+
+ for (int i = 0; i < length; i++) {
+ char c = data.charAt(i);
+ if (c == 0x0D) {
+ writer.write(__XD_);
+ } else {
+ if (c < 0x80) {
+ writer.write(c);
+ } else {
+ UtfHelper.writeCharToUtf8(c, writer);
+ }
+ ;
+ }
+ }
+
+ writer.write(_END_COMM);
+ if (position == NODE_BEFORE_DOCUMENT_ELEMENT) {
+ writer.write('\n');
+ }
+ }
+
+ /**
+ * Outputs a Text of CDATA section to the internal Writer.
+ *
+ * @param text
+ * @param writer writer where to write the things
+ * @throws IOException
+ */
+ static final void outputTextToWriter(final String text, final OutputStream writer) throws IOException {
+ final int length = text.length();
+ byte []toWrite;
+ for (int i = 0; i < length; i++) {
+ char c = text.charAt(i);
+
+ switch (c) {
+
+ case '&' :
+ toWrite = _AMP_;
+ break;
+
+ case '<' :
+ toWrite = _LT_;
+ break;
+
+ case '>' :
+ toWrite = _GT_;
+ break;
+
+ case 0xD :
+ toWrite = __XD_;
+ break;
+
+ default :
+ if (c < 0x80) {
+ writer.write(c);
+ } else {
+ UtfHelper.writeCharToUtf8(c, writer);
+ }
+ ;
+ continue;
+ }
+ writer.write(toWrite);
+ }
+ }
+
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/NameSpaceSymbTable.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/NameSpaceSymbTable.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/NameSpaceSymbTable.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/NameSpaceSymbTable.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,440 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.impl;
+
+import org.apache.axiom.c14n.omwrapper.interfaces.Attr;
+import org.apache.axiom.c14n.omwrapper.interfaces.Node;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * A stack based Symble Table.
+ * <br>For speed reasons all the symbols are introduced in the same map,
+ * and at the same time in a list so it can be removed when the frame is pop back.
+ *
+ * @author Raul Benito
+ *
+ * modified to work with Axiom wrapper by Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class NameSpaceSymbTable {
+
+ /**
+ * The map betwen prefix-> entry table.
+ */
+ SymbMap symb;
+ /**
+ * The level of nameSpaces (for Inclusive visibility).
+ */
+ int nameSpaces = 0;
+ /**
+ * The stacks for removing the definitions when doing pop.
+ */
+ List level;
+ boolean cloned = true;
+ static final String XMLNS = "xmlns";
+ final static SymbMap initialMap = new SymbMap();
+
+ static {
+ NameSpaceSymbEntry ne = new NameSpaceSymbEntry("", null, true, XMLNS);
+ ne.lastrendered = "";
+ initialMap.put(XMLNS, ne);
+ }
+
+ /**
+ * Default constractor
+ */
+ public NameSpaceSymbTable() {
+ level = new ArrayList(10);
+ //Insert the default binding for xmlns.
+ symb = (SymbMap) initialMap.clone();
+ }
+
+ /**
+ * Get all the unrendered nodes in the name space.
+ * For Inclusive rendering
+ *
+ * @param result the list where to fill the unrendered xmlns definitions.
+ */
+ public void getUnrenderedNodes(Collection result) {
+ //List result=new ArrayList();
+ Iterator it = symb.entrySet().iterator();
+ while (it.hasNext()) {
+ NameSpaceSymbEntry n = (NameSpaceSymbEntry) (it.next());
+ //put them rendered?
+ if ((!n.rendered) && (n.n != null)) {
+ n = (NameSpaceSymbEntry) n.clone();
+ needsClone();
+ symb.put(n.prefix, n);
+ n.lastrendered = n.uri;
+ n.rendered = true;
+
+ result.add(n.n);
+
+ }
+ }
+ }
+
+ /**
+ * Push a frame for visible namespace.
+ * For Inclusive rendering.
+ */
+ public void outputNodePush() {
+ nameSpaces++;
+ push();
+ }
+
+ /**
+ * Pop a frame for visible namespace.
+ */
+ public void outputNodePop() {
+ nameSpaces--;
+ pop();
+ }
+
+ /**
+ * Push a frame for a node.
+ * Inclusive or Exclusive.
+ */
+ public void push() {
+ //Put the number of namespace definitions in the stack.
+ level.add(null);
+ cloned = false;
+ }
+
+ /**
+ * Pop a frame.
+ * Inclusive or Exclusive.
+ */
+ public void pop() {
+ int size = level.size() - 1;
+ Object ob = level.remove(size);
+ if (ob != null) {
+ symb = (SymbMap) ob;
+ if (size == 0) {
+ cloned = false;
+ } else
+ cloned = (level.get(size - 1) != symb);
+ } else {
+ cloned = false;
+ }
+
+
+ }
+
+ final void needsClone() {
+ if (!cloned) {
+ level.set(level.size() - 1, symb);
+ symb = (SymbMap) symb.clone();
+ cloned = true;
+ }
+ }
+
+
+ /**
+ * Gets the attribute node that defines the binding for the prefix.
+ *
+ * @param prefix the prefix to obtain the attribute.
+ * @return null if there is no need to render the prefix. Otherwise the node of
+ * definition.
+ */
+ public Attr getMapping(String prefix) {
+ NameSpaceSymbEntry entry = symb.get(prefix);
+ if (entry == null) {
+ //There is no definition for the prefix(a bug?).
+ return null;
+ }
+ if (entry.rendered) {
+ //No need to render an entry already rendered.
+ return null;
+ }
+ // Mark this entry as render.
+ entry = (NameSpaceSymbEntry) entry.clone();
+ needsClone();
+ symb.put(prefix, entry);
+ entry.rendered = true;
+ entry.level = nameSpaces;
+ entry.lastrendered = entry.uri;
+ // Return the node for outputing.
+ return entry.n;
+ }
+
+ /**
+ * Gets a definition without mark it as render.
+ * For render in exclusive main.java.org.apache.axiom.c14n.impl the namespaces in the include prefixes.
+ *
+ * @param prefix The prefix whose definition is neaded.
+ * @return the attr to render, null if there is no need to render
+ */
+ public Attr getMappingWithoutRendered(String prefix) {
+ NameSpaceSymbEntry entry = symb.get(prefix);
+ if (entry == null) {
+ return null;
+ }
+ if (entry.rendered) {
+ return null;
+ }
+ return entry.n;
+ }
+
+ /**
+ * Adds the mapping for a prefix.
+ *
+ * @param prefix the prefix of definition
+ * @param uri the Uri of the definition
+ * @param n the attribute that have the definition
+ * @return true if there is already defined.
+ */
+ public boolean addMapping(String prefix, String uri, Attr n) {
+ NameSpaceSymbEntry ob = symb.get(prefix);
+ if ((ob != null) && uri.equals(ob.uri)) {
+ //If we have it previously defined. Don't keep working.
+ return false;
+ }
+ //Creates and entry in the table for this new definition.
+ NameSpaceSymbEntry ne = new NameSpaceSymbEntry(uri, n, false, prefix);
+ needsClone();
+ symb.put(prefix, ne);
+ if (ob != null) {
+ //We have a previous definition store it for the pop.
+ //Check if a previous definition(not the inmidiatly one) has been rendered.
+ ne.lastrendered = ob.lastrendered;
+ if ((ob.lastrendered != null) && (ob.lastrendered.equals(uri))) {
+ //Yes it is. Mark as rendered.
+ ne.rendered = true;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Adds a definition and mark it as render.
+ * For inclusive main.java.org.apache.axiom.c14n.impl.
+ *
+ * @param prefix the prefix of definition
+ * @param uri the Uri of the definition
+ * @param n the attribute that have the definition
+ * @return the attr to render, null if there is no need to render
+ */
+ public Node addMappingAndRender(String prefix, String uri, Attr n) {
+ NameSpaceSymbEntry ob = symb.get(prefix);
+
+ if ((ob != null) && uri.equals(ob.uri)) {
+ if (!ob.rendered) {
+ ob = (NameSpaceSymbEntry) ob.clone();
+ needsClone();
+ symb.put(prefix, ob);
+ ob.lastrendered = uri;
+ ob.rendered = true;
+ return ob.n;
+ }
+ return null;
+ }
+
+ NameSpaceSymbEntry ne = new NameSpaceSymbEntry(uri, n, true, prefix);
+ ne.lastrendered = uri;
+ needsClone();
+ symb.put(prefix, ne);
+ if (ob != null) {
+
+ if ((ob.lastrendered != null) && (ob.lastrendered.equals(uri))) {
+ ne.rendered = true;
+ return null;
+ }
+ }
+ return ne.n;
+ }
+
+ public int getLevel() {
+ // Auto-generated method stub
+ return level.size();
+ }
+
+ public void removeMapping(String prefix) {
+ NameSpaceSymbEntry ob = symb.get(prefix);
+
+ if (ob != null) {
+ needsClone();
+ symb.put(prefix, null);
+ }
+ }
+
+ public void removeMappingIfNotRender(String prefix) {
+ NameSpaceSymbEntry ob = symb.get(prefix);
+
+ if (ob != null && !ob.rendered) {
+ needsClone();
+ symb.put(prefix, null);
+ }
+ }
+
+ public boolean removeMappingIfRender(String prefix) {
+ NameSpaceSymbEntry ob = symb.get(prefix);
+
+ if (ob != null && ob.rendered) {
+ needsClone();
+ symb.put(prefix, null);
+ }
+ return false;
+ }
+}
+
+/**
+ * The internal structure of NameSpaceSymbTable.
+ */
+class NameSpaceSymbEntry implements Cloneable {
+ NameSpaceSymbEntry(String name, Attr n, boolean rendered, String prefix) {
+ this.uri = name;
+ this.rendered = rendered;
+ this.n = n;
+ this.prefix = prefix;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ return null;
+ }
+ }
+
+ /**
+ * The level where the definition was rendered(Only for inclusive)
+ */
+ int level = 0;
+ String prefix;
+ /**
+ * The URI that the prefix defines
+ */
+ String uri;
+ /**
+ * The last output in the URI for this prefix (This for speed reason).
+ */
+ String lastrendered = null;
+ /**
+ * This prefix-URI has been already render or not.
+ */
+ boolean rendered = false;
+ /**
+ * The attribute to include.
+ */
+ Attr n;
+};
+
+class SymbMap implements Cloneable {
+ int free = 23;
+ NameSpaceSymbEntry[] entries;
+ String[] keys;
+
+ SymbMap() {
+ entries = new NameSpaceSymbEntry[free];
+ keys = new String[free];
+ }
+
+ void put(String key, NameSpaceSymbEntry value) {
+ int index = index(key);
+ Object oldKey = keys[index];
+ keys[index] = key;
+ entries[index] = value;
+ if (oldKey == null || !oldKey.equals(key)) {
+ if (--free == 0) {
+ free = entries.length;
+ int newCapacity = free << 2;
+ rehash(newCapacity);
+ }
+ }
+ }
+
+ List entrySet() {
+ List a = new ArrayList();
+ for (int i = 0; i < entries.length; i++) {
+ if ((entries[i] != null) && !("".equals(entries[i].uri))) {
+ a.add(entries[i]);
+ }
+ }
+ return a;
+ }
+
+ protected int index(Object obj) {
+ Object[] set = keys;
+ int length = set.length;
+ //abs of index
+ int index = (obj.hashCode() & 0x7fffffff) % length;
+ Object cur = set[index];
+
+ if (cur == null || (cur.equals(obj))) {
+ return index;
+ }
+ length = length - 1;
+ do {
+ index = index == length ? 0 : ++index;
+ cur = set[index];
+ } while (cur != null && (!cur.equals(obj)));
+ return index;
+ }
+
+ /**
+ * rehashes the map to the new capacity.
+ *
+ * @param newCapacity an <code>int</code> value
+ */
+ protected void rehash(int newCapacity) {
+ int oldCapacity = keys.length;
+ String oldKeys[] = keys;
+ NameSpaceSymbEntry oldVals[] = entries;
+
+ keys = new String[newCapacity];
+ entries = new NameSpaceSymbEntry[newCapacity];
+
+ for (int i = oldCapacity; i-- > 0;) {
+ if (oldKeys[i] != null) {
+ String o = oldKeys[i];
+ int index = index(o);
+ keys[index] = o;
+ entries[index] = oldVals[i];
+ }
+ }
+ }
+
+ NameSpaceSymbEntry get(String key) {
+ return entries[index(key)];
+ }
+
+ protected Object clone() {
+ try {
+ SymbMap copy = (SymbMap) super.clone();
+ copy.entries = new NameSpaceSymbEntry[entries.length];
+ System.arraycopy(entries, 0, copy.entries, 0, entries.length);
+ copy.keys = new String[keys.length];
+ System.arraycopy(keys, 0, copy.keys, 0, keys.length);
+
+ return copy;
+ } catch (CloneNotSupportedException e) {
+ // Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/UtfHelper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/UtfHelper.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/UtfHelper.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/impl/UtfHelper.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.impl;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Map;
+
+public class UtfHelper {
+
+ final static void writeByte(final String str, final OutputStream out, Map cache) throws IOException {
+ byte []result = (byte[]) cache.get(str);
+ if (result == null) {
+ result = getStringInUtf8(str);
+ cache.put(str, result);
+ }
+
+ out.write(result);
+
+ }
+
+ final static void writeCharToUtf8(final char c, final OutputStream out) throws IOException {
+ if (c < 0x80) {
+ out.write(c);
+ return;
+ }
+ if ((c >= 0xD800 && c <= 0xDBFF) || (c >= 0xDC00 && c <= 0xDFFF)) {
+ //No Surrogates in sun java
+ out.write(0x3f);
+ return;
+ }
+ int bias;
+ int write;
+ char ch;
+ if (c > 0x07FF) {
+ ch = (char) (c >>> 12);
+ write = 0xE0;
+ if (ch > 0) {
+ write |= (ch & 0x0F);
+ }
+ out.write(write);
+ write = 0x80;
+ bias = 0x3F;
+ } else {
+ write = 0xC0;
+ bias = 0x1F;
+ }
+ ch = (char) (c >>> 6);
+ if (ch > 0) {
+ write |= (ch & bias);
+ }
+ out.write(write);
+ out.write(0x80 | ((c) & 0x3F));
+
+ }
+
+ final static void writeStringToUtf8(final String str, final OutputStream out) throws IOException {
+ final int length = str.length();
+ int i = 0;
+ char c;
+ while (i < length) {
+ c = str.charAt(i++);
+ if (c < 0x80) {
+ out.write(c);
+ continue;
+ }
+ if ((c >= 0xD800 && c <= 0xDBFF) || (c >= 0xDC00 && c <= 0xDFFF)) {
+ //No Surrogates in sun java
+ out.write(0x3f);
+ continue;
+ }
+ char ch;
+ int bias;
+ int write;
+ if (c > 0x07FF) {
+ ch = (char) (c >>> 12);
+ write = 0xE0;
+ if (ch > 0) {
+ write |= (ch & 0x0F);
+ }
+ out.write(write);
+ write = 0x80;
+ bias = 0x3F;
+ } else {
+ write = 0xC0;
+ bias = 0x1F;
+ }
+ ch = (char) (c >>> 6);
+ if (ch > 0) {
+ write |= (ch & bias);
+ }
+ out.write(write);
+ out.write(0x80 | ((c) & 0x3F));
+
+ }
+
+ }
+
+ public final static byte[] getStringInUtf8(final String str) {
+ final int length = str.length();
+ boolean expanded = false;
+ byte []result = new byte[length];
+ int i = 0;
+ int out = 0;
+ char c;
+ while (i < length) {
+ c = str.charAt(i++);
+ if (c < 0x80) {
+ result[out++] = (byte) c;
+ continue;
+ }
+ if ((c >= 0xD800 && c <= 0xDBFF) || (c >= 0xDC00 && c <= 0xDFFF)) {
+ //No Surrogates in sun java
+ result[out++] = 0x3f;
+
+ continue;
+ }
+ if (!expanded) {
+ byte newResult[] = new byte[3 * length];
+ System.arraycopy(result, 0, newResult, 0, out);
+ result = newResult;
+ expanded = true;
+ }
+ char ch;
+ int bias;
+ byte write;
+ if (c > 0x07FF) {
+ ch = (char) (c >>> 12);
+ write = (byte) 0xE0;
+ if (ch > 0) {
+ write |= (ch & 0x0F);
+ }
+ result[out++] = write;
+ write = (byte) 0x80;
+ bias = 0x3F;
+ } else {
+ write = (byte) 0xC0;
+ bias = 0x1F;
+ }
+ ch = (char) (c >>> 6);
+ if (ch > 0) {
+ write |= (ch & bias);
+ }
+ result[out++] = write;
+ result[out++] = (byte) (0x80 | ((c) & 0x3F));/**/
+
+ }
+ if (expanded) {
+ byte newResult[] = new byte[out];
+ System.arraycopy(result, 0, newResult, 0, out);
+ result = newResult;
+ }
+ return result;
+ }
+
+
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/AttrImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/AttrImpl.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/AttrImpl.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/AttrImpl.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper;
+
+import org.apache.axiom.c14n.omwrapper.factory.WrapperFactory;
+import org.apache.axiom.c14n.omwrapper.interfaces.Attr;
+import org.apache.axiom.c14n.omwrapper.interfaces.Element;
+import org.apache.axiom.c14n.omwrapper.interfaces.Node;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class AttrImpl extends NodeImpl implements Attr {
+ public static final String XMLNS = "xmlns";
+ public static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
+
+ private boolean isOMAttribute = false;
+ private OMElement parent = null;
+ private OMNamespace omns = null;
+ private OMAttribute omattr = null;
+
+ public AttrImpl(Object o, OMElement parent, WrapperFactory fac){
+ this.parent = parent;
+ this.fac = fac;
+ if (o instanceof OMAttribute) {
+ isOMAttribute = true;
+ omattr = (OMAttribute)o;
+ } else {
+ isOMAttribute = false;
+ omns = (OMNamespace)o;
+ }
+ }
+
+ public String getName() {
+ // for attributes getName() is the same as getNodeName()
+ return getNodeName();
+ }
+
+ public String getValue() {
+ // for attributes getValue() is the same as getNodeValue()
+ return getNodeValue();
+ }
+
+ public Element getOwnerElement() {
+ return (Element) fac.getNode(parent);
+ }
+
+ public short getNodeType() {
+ return Node.ATTRIBUTE_NODE;
+ }
+
+ public String getLocalName() {
+ return (isOMAttribute) ? omattr.getLocalName() : getOMNamespaceLocalName();
+ }
+
+ public String getNamespaceURI() {
+ return (isOMAttribute) ? getOMAttributeNsURI() : XMLNS_URI;
+ }
+
+ // overridden getNodeName() method
+ public String getNodeName() {
+ return (isOMAttribute) ? getOMAttributeName() : getOMNamespaceName();
+ }
+
+ // overridden getNodeValue() method
+ public String getNodeValue() {
+ return (isOMAttribute) ? omattr.getAttributeValue() : omns.getNamespaceURI();
+ }
+
+ public String getPrefix() {
+ return (isOMAttribute) ? getOMAttributePrefix() : getOMNamespacePrefix();
+ }
+
+ // a call to this method assumes that AttrImpl wraps an OMAttribute
+ private String getOMAttributeName(){
+ QName qn = omattr.getQName();
+ if (qn.getPrefix() == null || "".equals(qn.getPrefix())) {
+ return qn.getLocalPart();
+ }
+ return qn.getPrefix() + ":" + qn.getLocalPart();
+ }
+
+ // a call to this method assumes that AttrImpl wraps an OMNamespace
+ private String getOMNamespaceName() {
+ String prefix = omns.getPrefix();
+ if(prefix == null || "".equals(prefix)) {
+ return XMLNS;
+ }
+ return XMLNS + ":" + prefix;
+ }
+
+ // a call to this method assumes that AttrImpl wraps an OMNamespace
+ private String getOMNamespaceLocalName() {
+ String prefix = omns.getPrefix();
+ if(prefix == null || "".equals(prefix)) {
+ return XMLNS;
+ }
+ return prefix;
+ }
+
+ // a call to this method assumes that AttrImpl wraps an OMAttribute
+ private String getOMAttributeNsURI() {
+ String nsURI = omattr.getQName().getNamespaceURI();
+ if (nsURI == null || "".equals(nsURI)) {
+ return null;
+ }
+ return nsURI;
+ }
+
+ // a call to this method assumes that AttrImpl wraps an OMAttribute
+ private String getOMAttributePrefix() {
+ String prefix = omattr.getQName().getPrefix();
+ if (prefix == null || "".equals(prefix)){
+ return null;
+ }
+ return prefix;
+ }
+
+ // a call to this method assumes that AttrImpl wraps an OMNamespace
+ private String getOMNamespacePrefix() {
+ // OMNamespace prefix is what you get after xmlns:
+ // in DOM the prefix of an attribute is what you get before :
+ String prefix = omns.getPrefix();
+ if(prefix == null || "".equals(prefix)){
+ return null;
+ }
+ return XMLNS;
+ }
+
+ public Node getNextSibling() {
+ return null;
+ }
+
+ public Node getPreviousSibling() {
+ return null;
+ }
+
+ public Node getParentNode() {
+ return null;
+ }
+
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/CommentImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/CommentImpl.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/CommentImpl.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/CommentImpl.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper;
+
+import org.apache.axiom.c14n.omwrapper.factory.WrapperFactory;
+import org.apache.axiom.c14n.omwrapper.interfaces.Comment;
+import org.apache.axiom.c14n.omwrapper.interfaces.Node;
+import org.apache.axiom.om.OMComment;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class CommentImpl extends NodeImpl implements Comment {
+ private OMComment comment = null;
+
+ public CommentImpl(OMComment comment, WrapperFactory fac){
+ this.fac = fac;
+ this.comment = comment;
+ node = comment;
+ }
+
+ public short getNodeType() {
+ return Node.COMMENT_NODE;
+ }
+
+ public String getData() {
+ return comment.getValue();
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/DoctypeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/DoctypeImpl.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/DoctypeImpl.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/DoctypeImpl.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper;
+
+import org.apache.axiom.c14n.omwrapper.factory.WrapperFactory;
+import org.apache.axiom.c14n.omwrapper.interfaces.Doctype;
+import org.apache.axiom.c14n.omwrapper.interfaces.Node;
+import org.apache.axiom.om.OMDocType;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class DoctypeImpl extends NodeImpl implements Doctype {
+ private OMDocType dt = null;
+
+ public DoctypeImpl(OMDocType dt, WrapperFactory fac) {
+ this.fac = fac;
+ this.dt = dt;
+ node = dt;
+ }
+
+ public short getNodeType() {
+ return Node.DOCUMENT_TYPE_NODE;
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/DocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/DocumentImpl.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/DocumentImpl.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/DocumentImpl.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper;
+
+import org.apache.axiom.c14n.omwrapper.factory.WrapperFactory;
+import org.apache.axiom.c14n.omwrapper.interfaces.Document;
+import org.apache.axiom.c14n.omwrapper.interfaces.Element;
+import org.apache.axiom.c14n.omwrapper.interfaces.Node;
+import org.apache.axiom.c14n.omwrapper.interfaces.NodeList;
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMText;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class DocumentImpl extends NodeImpl implements Document {
+ private OMDocument doc = null;
+ private List list = null;
+ private NodeList nl = null;
+
+ public DocumentImpl(OMDocument doc, WrapperFactory fac){
+ this.fac = fac;
+ this.doc = doc;
+ }
+
+ public Element getDocumentElement() {
+ return (Element)fac.getNode(doc.getOMDocumentElement());
+ }
+
+ public short getNodeType() {
+ return Node.DOCUMENT_NODE;
+ }
+
+ public Node getFirstChild() {
+ // an XML Document node should not give Text nodes as children.
+ OMNode n = doc.getFirstOMChild();
+ do {
+ if (!(n instanceof OMText)){
+ return fac.getNode(n);
+ }
+ n = n.getNextOMSibling();
+ } while (true);
+
+ }
+
+ public NodeList getChildNodes() {
+ Iterator itr = null;
+ if (nl == null) { // ok then this is the first call to this method
+ list = new ArrayList();
+ nl = new NodeListImpl(list, fac);
+ itr = doc.getChildren();
+ Object o;
+ while(itr.hasNext()) {
+ o = itr.next();
+ // Axiom returns OMText nodes even for newline characters
+ // we don't want these to be returned from an XML Document node
+ if (o instanceof OMText) {
+ continue;
+ }
+ list.add(o);
+ }
+ }
+ return nl;
+ }
+
+ public Node getNextSibling() {
+ return null;
+ }
+
+ public Node getParentNode() {
+ return null;
+ }
+
+ public Node getPreviousSibling() {
+ return null;
+ }
+
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/ElementImpl.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/ElementImpl.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/ElementImpl.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper;
+
+import org.apache.axiom.c14n.omwrapper.factory.WrapperFactory;
+import org.apache.axiom.c14n.omwrapper.interfaces.Element;
+import org.apache.axiom.c14n.omwrapper.interfaces.NamedNodeMap;
+import org.apache.axiom.c14n.omwrapper.interfaces.Node;
+import org.apache.axiom.c14n.omwrapper.interfaces.NodeList;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class ElementImpl extends NodeImpl implements Element {
+ private OMElement e = null;
+ private NamedNodeMap nnm = null;
+ private List list = null;
+ private List nodes = null;
+ private NodeList nl = null;
+
+ public ElementImpl(OMElement e, WrapperFactory fac) {
+ this.fac = fac;
+ this.e = e;
+ node = e;
+ }
+
+
+ public String getTagName() {
+ // for Element type getTagName() is similar to its getNodeName();
+ return getNodeName();
+ }
+
+ public NamedNodeMap getAttributes() {
+ if (nnm == null) { // ok now nnm == null implies this is the first time call to this method
+ list = new ArrayList();
+ nnm = new NamedNodeMapImpl(list, e, fac);
+ Iterator itr = e.getAllAttributes();
+ while (itr.hasNext()) {
+ list.add(itr.next());
+ }
+ itr = e.getAllDeclaredNamespaces();
+ while (itr.hasNext()) {
+ list.add(itr.next());
+ }
+
+ Object parent = e.getParent();
+ if (parent instanceof OMElement) {
+ OMNamespace defaultNS = e.getDefaultNamespace();
+ OMNamespace defaultParentNS = ((OMElement) parent).getDefaultNamespace();
+ if (defaultNS != null && defaultParentNS != null &&
+ defaultNS.getNamespaceURI().equals(defaultParentNS.getNamespaceURI())) {
+ list.remove(defaultNS);
+ }
+ }
+ }
+ return nnm;
+ }
+
+ public short getNodeType() {
+ return Node.ELEMENT_NODE;
+ }
+
+ public boolean hasAttributes() {
+ // no worries only the first time call would be expensive
+ return getAttributes().getLength() != 0;
+ }
+
+ public String getNodeName() {
+ // overriden getNodeName()
+ QName qn = e.getQName();
+ if (qn.getPrefix() == null || "".equals(qn.getPrefix())) {
+ return qn.getLocalPart();
+ } else {
+ return qn.getPrefix() + ":" + qn.getLocalPart();
+ }
+ }
+
+// For Element getNodeValue is null so no need to override
+// public String getNodeValue() {
+// return super.getNodeValue();
+// }
+
+ public Node getFirstChild() {
+ return fac.getNode(e.getFirstOMChild());
+ }
+
+ public NodeList getChildNodes() {
+ Iterator itr = null;
+ if (nl == null) { // ok then this is the first call to this method
+ nodes = new ArrayList();
+ nl = new NodeListImpl(nodes, fac);
+ itr = e.getChildren();
+ while(itr.hasNext()) {
+ nodes.add(itr.next());
+ }
+ }
+ return nl;
+ }
+
+ public String getNamespaceURI() {
+ OMNamespace ns = e.getNamespace();
+ if (ns != null){
+ return ns.getNamespaceURI();
+ }
+ return null;
+ }
+
+ public String toString() {
+ return e.toString();
+ }
+
+ public String getPrefix() {
+ String prefix = e.getQName().getPrefix();
+ if (prefix == null || "".equals(prefix)){
+ return null;
+ }
+ return prefix;
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/NamedNodeMapImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/NamedNodeMapImpl.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/NamedNodeMapImpl.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/NamedNodeMapImpl.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper;
+
+import org.apache.axiom.c14n.omwrapper.factory.WrapperFactory;
+import org.apache.axiom.c14n.omwrapper.interfaces.NamedNodeMap;
+import org.apache.axiom.c14n.omwrapper.interfaces.Node;
+import org.apache.axiom.om.OMElement;
+
+import java.util.List;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class NamedNodeMapImpl implements NamedNodeMap {
+ private WrapperFactory fac = null;
+ private List list = null;
+ private OMElement parent = null;
+
+ public NamedNodeMapImpl(List list, OMElement parent, WrapperFactory fac){
+ this.fac = fac;
+ this.list = list;
+ this.parent = parent;
+ }
+ public int getLength() {
+ return list.size();
+ }
+
+ public Node item(int index) {
+ try {
+ // returns an appropriate AttrImpl, wrapping either an OMNamespace or OMAttribute
+ return fac.getAttribute(list.get(index), parent);
+ } catch (IndexOutOfBoundsException e) {
+ // returns null if index is invalid
+ return null;
+ }
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/NodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/NodeImpl.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/NodeImpl.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/NodeImpl.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper;
+
+import org.apache.axiom.c14n.omwrapper.factory.WrapperFactory;
+import org.apache.axiom.c14n.omwrapper.interfaces.Node;
+import org.apache.axiom.c14n.omwrapper.interfaces.NodeList;
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMText;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class NodeImpl implements Node {
+ protected WrapperFactory fac = null;
+ protected OMNode node = null;
+ protected Node next = null;
+ protected Node prev = null;
+ public String getNodeName() {
+ return null;
+ }
+
+ public short getNodeType() {
+ return 0;
+ }
+
+ public String getNodeValue() {
+ return null;
+ }
+
+ public String getNamespaceURI() {
+ return null;
+ }
+
+ public String getPrefix() {
+ return null;
+ }
+
+ public Node getFirstChild() {
+ return null;
+ }
+
+ public Node getNextSibling() {
+ if (next == null) {
+ if (node.getParent() instanceof OMDocument) {
+ OMNode n = node.getNextOMSibling();
+ do {
+ if (!(n instanceof OMText)) {
+ next = fac.getNode(n);
+ break;
+ }
+ n = n.getNextOMSibling();
+ } while (true);
+ } else {
+ next = fac.getNode(node.getNextOMSibling());
+ }
+ }
+ return next;
+ }
+
+ public Node getPreviousSibling() {
+ if (prev == null) {
+ if (node.getParent() instanceof OMDocument) {
+ OMNode n = node.getPreviousOMSibling();
+ do {
+ if (!(n instanceof OMText)) {
+ prev = fac.getNode(n);
+ break;
+ }
+ n = n.getPreviousOMSibling();
+ } while (true);
+ } else {
+ prev = fac.getNode(node.getPreviousOMSibling());
+ }
+ }
+ return prev;
+ }
+
+ public Node getParentNode() {
+ return fac.getNode(node.getParent());
+ }
+
+ public NodeList getChildNodes() {
+ return null;
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/NodeListImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/NodeListImpl.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/NodeListImpl.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/NodeListImpl.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper;
+
+import org.apache.axiom.c14n.omwrapper.factory.WrapperFactory;
+import org.apache.axiom.c14n.omwrapper.interfaces.Node;
+import org.apache.axiom.c14n.omwrapper.interfaces.NodeList;
+
+import java.util.List;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class NodeListImpl implements NodeList {
+ private WrapperFactory fac = null;
+ private List nodes = null;
+
+ public NodeListImpl(List nodes, WrapperFactory fac) {
+ this.fac = fac;
+ this.nodes = nodes;
+ }
+
+ public Node item(int index) {
+ try {
+ return fac.getNode(nodes.get(index));
+ } catch(IndexOutOfBoundsException e) {
+ return null;
+ }
+ }
+
+ public int getLength() {
+ return nodes.size();
+ }
+
+ // Object should represent an OMNode
+ protected int indexOf(Object o){
+ return nodes.indexOf(o);
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/ProcessingInstructionImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/ProcessingInstructionImpl.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/ProcessingInstructionImpl.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/ProcessingInstructionImpl.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper;
+
+import org.apache.axiom.c14n.omwrapper.factory.WrapperFactory;
+import org.apache.axiom.c14n.omwrapper.interfaces.Node;
+import org.apache.axiom.c14n.omwrapper.interfaces.ProcessingInstruction;
+import org.apache.axiom.om.OMProcessingInstruction;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class ProcessingInstructionImpl extends NodeImpl implements ProcessingInstruction {
+ private OMProcessingInstruction pi = null;
+
+ public ProcessingInstructionImpl(OMProcessingInstruction pi, WrapperFactory fac) {
+ this.fac = fac;
+ this.pi = pi;
+ node = pi;
+ }
+
+ public String getTarget() {
+ return pi.getTarget();
+ }
+
+ public String getData() {
+ return pi.getValue();
+ }
+
+ public short getNodeType() {
+ return Node.PROCESSING_INSTRUCTION_NODE;
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/TextImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/TextImpl.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/TextImpl.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/TextImpl.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper;
+
+import org.apache.axiom.c14n.omwrapper.factory.WrapperFactory;
+import org.apache.axiom.c14n.omwrapper.interfaces.Node;
+import org.apache.axiom.c14n.omwrapper.interfaces.Text;
+import org.apache.axiom.om.OMText;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class TextImpl extends NodeImpl implements Text {
+ private OMText txt = null;
+
+ public TextImpl(OMText txt, WrapperFactory fac) {
+ this.fac = fac;
+ this.txt = txt;
+ node = txt;
+ }
+
+ public char[] getText() {
+ return txt.getText().toCharArray();
+ }
+
+ public String getNodeValue() {
+ return txt.getText();
+ }
+
+ public short getNodeType() {
+ return Node.TEXT_NODE;
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/factory/WrapperFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/factory/WrapperFactory.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/factory/WrapperFactory.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/factory/WrapperFactory.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper.factory;
+
+import org.apache.axiom.c14n.omwrapper.*;
+import org.apache.axiom.c14n.omwrapper.interfaces.Attr;
+import org.apache.axiom.c14n.omwrapper.interfaces.Node;
+import org.apache.axiom.om.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * class WrapperFactory
+ *
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public class WrapperFactory {
+ private Map map = null;
+
+ public WrapperFactory(){
+ map = new HashMap();
+ }
+// public static Map map = new HashMap();
+ public Node getNode(Object o){
+ Node n = (Node)map.get(o);
+ if (n == null) {
+ if(o instanceof OMElement){
+ n = new ElementImpl((OMElement)o, this);
+ } else if (o instanceof OMDocument) {
+ n = new DocumentImpl((OMDocument)o, this);
+ } else if (o instanceof OMComment) {
+ n = new CommentImpl((OMComment)o, this);
+ } else if (o instanceof OMDocType) {
+ n = new DoctypeImpl((OMDocType)o, this);
+ } else if (o instanceof OMText){
+ n = new TextImpl((OMText)o, this);
+ } else if (o instanceof OMProcessingInstruction){
+ n = new ProcessingInstructionImpl((OMProcessingInstruction)o, this);
+ }
+ map.put(o, n);
+ }
+ return n;
+ }
+
+ public Attr getAttribute(Object o, OMElement parent){
+ Attr at = (Attr)map.get(o);
+ if (at == null){
+ if (o instanceof OMAttribute || o instanceof OMNamespace) {
+ at = new AttrImpl(o, parent, this);
+ }
+ map.put(o, at);
+ }
+ return at;
+ }
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Attr.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Attr.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Attr.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Attr.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper.interfaces;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public interface Attr extends Node{
+ public String getName();
+
+ public String getValue();
+
+ public Element getOwnerElement();
+
+ public String getLocalName();
+
+ public String getNamespaceURI();
+
+
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Comment.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Comment.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Comment.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Comment.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper.interfaces;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public interface Comment extends Node{
+ public String getData();
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Doctype.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Doctype.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Doctype.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Doctype.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper.interfaces;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public interface Doctype extends Node{
+// All I want is getNodeType() so nothing new here
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Document.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Document.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Document.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Document.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper.interfaces;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public interface Document extends Node{
+
+ public Element getDocumentElement();
+
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Element.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Element.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Element.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/Element.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper.interfaces;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public interface Element extends Node{
+ public boolean hasAttributes();
+
+ public String getTagName();
+
+ public NamedNodeMap getAttributes();
+}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/NamedNodeMap.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/NamedNodeMap.java?rev=689316&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/NamedNodeMap.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-c14n/src/main/java/org/apache/axiom/c14n/omwrapper/interfaces/NamedNodeMap.java Tue Aug 26 18:06:53 2008
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.c14n.omwrapper.interfaces;
+
+/**
+ * @author Saliya Ekanayake (esaliya@gmail.com)
+ */
+public interface NamedNodeMap {
+ public Node item(int index);
+
+ public int getLength();
+}