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 gd...@apache.org on 2007/03/07 15:59:13 UTC
svn commit: r515594 [4/19] - in
/webservices/commons/trunk/modules/axiom/modules:
axiom-api/src/main/java/org/apache/axiom/attachments/
axiom-api/src/main/java/org/apache/axiom/attachments/utils/
axiom-api/src/main/java/org/apache/axiom/om/ axiom-api/s...
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenIterator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenIterator.java?view=diff&rev=515594&r1=515593&r2=515594
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenIterator.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenIterator.java Wed Mar 7 06:59:00 2007
@@ -22,28 +22,18 @@
import java.util.Iterator;
import java.util.NoSuchElementException;
-/**
- * Class OMChildrenIterator
- */
+/** Class OMChildrenIterator */
public class OMChildrenIterator implements Iterator {
- /**
- * Field currentChild
- */
+ /** Field currentChild */
protected OMNode currentChild;
- /**
- * Field lastChild
- */
+ /** Field lastChild */
protected OMNode lastChild;
- /**
- * Field nextCalled
- */
+ /** Field nextCalled */
protected boolean nextCalled = false;
- /**
- * Field removeCalled
- */
+ /** Field removeCalled */
protected boolean removeCalled = false;
protected boolean isExceptionThrownInAdvancingToNextElement = false;
@@ -58,18 +48,16 @@
}
/**
- * Removes the last element returned by the iterator (optional operation)
- * from the underlying collection. This method must be called only once per
- * call to <tt>next</tt>. The behavior of an iterator is unspecified if
- * the underlying collection is modified while the iteration is in
- * progress in any way other than by calling this method.
+ * Removes the last element returned by the iterator (optional operation) from the underlying
+ * collection. This method must be called only once per call to <tt>next</tt>. The behavior
+ * of an iterator is unspecified if the underlying collection is modified while the iteration is
+ * in progress in any way other than by calling this method.
*
- * @throws UnsupportedOperationException if the <tt>remove</tt>
- * operation is not supported by this Iterator.
- * @throws IllegalStateException if the <tt>next</tt> method has not
- * yet been called, or the <tt>remove</tt> method has already
- * been called after the last call to the <tt>next</tt>
- * method.
+ * @throws UnsupportedOperationException if the <tt>remove</tt> operation is not supported by
+ * this Iterator.
+ * @throws IllegalStateException if the <tt>next</tt> method has not yet been called, or
+ * the <tt>remove</tt> method has already been called
+ * after the last call to the <tt>next</tt> method.
*/
public void remove() {
if (!nextCalled) {
@@ -89,12 +77,11 @@
}
/**
- * Returns <tt>true</tt> if the iteration has more elements. (In other
- * words, returns <tt>true</tt> if <tt>next</tt> would return an element
- * rather than throwing an exception.)
+ * Returns <tt>true</tt> if the iteration has more elements. (In other words, returns
+ * <tt>true</tt> if <tt>next</tt> would return an element rather than throwing an exception.)
*
- * @return Returns <tt>true</tt> if the iterator has more elements. This will never throw an exception even there is an
- * exception thrown underneath.
+ * @return Returns <tt>true</tt> if the iterator has more elements. This will never throw an
+ * exception even there is an exception thrown underneath.
*/
public boolean hasNext() {
return (currentChild != null && !isExceptionThrownInAdvancingToNextElement);
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenQNameIterator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenQNameIterator.java?view=diff&rev=515594&r1=515593&r2=515594
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenQNameIterator.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenQNameIterator.java Wed Mar 7 06:59:00 2007
@@ -21,23 +21,15 @@
import javax.xml.namespace.QName;
-/**
- * Class OMChildrenQNameIterator
- */
+/** Class OMChildrenQNameIterator */
public class OMChildrenQNameIterator extends OMChildrenIterator {
- /**
- * Field givenQName
- */
+ /** Field givenQName */
private QName givenQName;
- /**
- * Field needToMoveForward
- */
+ /** Field needToMoveForward */
private boolean needToMoveForward = true;
- /**
- * Field isMatchingNodeFound
- */
+ /** Field isMatchingNodeFound */
private boolean isMatchingNodeFound = false;
/**
@@ -52,9 +44,8 @@
}
/**
- * Returns <tt>true</tt> if the iteration has more elements. (In other
- * words, returns <tt>true</tt> if <tt>next</tt> would return an element
- * rather than throwing an exception.)
+ * Returns <tt>true</tt> if the iteration has more elements. (In other words, returns
+ * <tt>true</tt> if <tt>next</tt> would return an element rather than throwing an exception.)
*
* @return Returns <tt>true</tt> if the iterator has more elements.
*/
@@ -65,8 +56,8 @@
// check the current node for the criteria
if ((currentChild instanceof OMElement)
&& (isQNamesMatch(
- ((OMElement) currentChild).getQName(),
- this.givenQName))) {
+ ((OMElement) currentChild).getQName(),
+ this.givenQName))) {
isMatchingNodeFound = true;
needToMoveForward = false;
} else {
@@ -103,10 +94,9 @@
}
/**
- * Cannot use the overridden equals method of QName, as one might want to get
- * some element just by giving the localname, even though a matching element
- * has a namespace uri as well.
- * This is not supported in the equals method of the QName.
+ * Cannot use the overridden equals method of QName, as one might want to get some element just
+ * by giving the localname, even though a matching element has a namespace uri as well. This is
+ * not supported in the equals method of the QName.
*
* @param elementQName
* @param qNameToBeMatched
@@ -123,21 +113,21 @@
String localPart = qNameToBeMatched.getLocalPart();
boolean localNameMatch =
(localPart == null)
- || (localPart.equals(""))
- ||
- ((elementQName != null)
- &&
- elementQName.getLocalPart().equalsIgnoreCase(
- localPart));
+ || (localPart.equals(""))
+ ||
+ ((elementQName != null)
+ &&
+ elementQName.getLocalPart().equalsIgnoreCase(
+ localPart));
String namespaceURI = qNameToBeMatched.getNamespaceURI();
boolean namespaceURIMatch =
(namespaceURI == null)
- || (namespaceURI.equals(""))
- ||
- ((elementQName != null)
- &&
- elementQName.getNamespaceURI().equalsIgnoreCase(
- namespaceURI));
+ || (namespaceURI.equals(""))
+ ||
+ ((elementQName != null)
+ &&
+ elementQName.getNamespaceURI().equalsIgnoreCase(
+ namespaceURI));
return localNameMatch && namespaceURIMatch;
}
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenWithSpecificAttributeIterator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenWithSpecificAttributeIterator.java?view=diff&rev=515594&r1=515593&r2=515594
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenWithSpecificAttributeIterator.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenWithSpecificAttributeIterator.java Wed Mar 7 06:59:00 2007
@@ -22,24 +22,16 @@
import javax.xml.namespace.QName;
-/**
- * Class OMChildrenWithSpecificAttributeIterator
- */
+/** Class OMChildrenWithSpecificAttributeIterator */
public class OMChildrenWithSpecificAttributeIterator
extends OMChildrenIterator {
- /**
- * Field attributeName
- */
+ /** Field attributeName */
private QName attributeName;
- /**
- * Field attributeValue
- */
+ /** Field attributeValue */
private String attributeValue;
- /**
- * Field detach
- */
+ /** Field detach */
private boolean detach;
/**
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java?view=diff&rev=515594&r1=515593&r2=515594
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java Wed Mar 7 06:59:00 2007
@@ -20,7 +20,6 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.impl.OMNodeEx;
import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
import javax.xml.namespace.NamespaceContext;
@@ -68,10 +67,10 @@
namespaceName = ns.getNamespaceURI();
if (prefix != null) {
writer.writeAttribute(prefix, namespaceName,
- attr.getLocalName(), attr.getAttributeValue());
+ attr.getLocalName(), attr.getAttributeValue());
} else {
writer.writeAttribute(namespaceName, attr.getLocalName(),
- attr.getAttributeValue());
+ attr.getAttributeValue());
}
} else {
String localName = attr.getLocalName();
@@ -107,16 +106,17 @@
// Case 2 :
// The passed in namespace is a default ns, but there is a non-default ns declared
// in the current scope.
- if (("".equals(prefix) && "".equals(prefixFromWriter) && !uri.equals(writer.getNamespaceContext().getNamespaceURI(""))) ||
- (prefix != null && "".equals(prefix) && (prefixFromWriter == null || !prefix.equals(prefixFromWriter))))
- {
+ if (("".equals(prefix) && "".equals(prefixFromWriter) &&
+ !uri.equals(writer.getNamespaceContext().getNamespaceURI(""))) ||
+ (prefix != null && "".equals(prefix) &&
+ (prefixFromWriter == null || !prefix.equals(prefixFromWriter)))) {
// this has not been declared earlier
writer.writeDefaultNamespace(uri);
writer.setDefaultNamespace(uri);
} else {
prefix = prefix == null ? getNextNSPrefix(writer) : prefix;
- if (prefix != null && !prefix.equals(prefixFromWriter) && !checkForPrefixInTheCurrentContext(writer, uri, prefix))
- {
+ if (prefix != null && !prefix.equals(prefixFromWriter) &&
+ !checkForPrefixInTheCurrentContext(writer, uri, prefix)) {
writer.writeNamespace(prefix, uri);
writer.setPrefix(prefix, uri);
}
@@ -125,8 +125,8 @@
// now the nsURI passed is "" or null. Meaning we gonna work with defaultNS.
// check whether there is a defaultNS already declared. If yes, is it the same as this ?
String currentDefaultNSURI = writer.getNamespaceContext().getNamespaceURI("");
- if( (currentDefaultNSURI != null && !currentDefaultNSURI.equals(uri)) ||
- uri != null && !uri.equals(currentDefaultNSURI)){
+ if ((currentDefaultNSURI != null && !currentDefaultNSURI.equals(uri)) ||
+ uri != null && !uri.equals(currentDefaultNSURI)) {
// this has not been declared earlier
writer.writeDefaultNamespace(uri);
writer.setDefaultNamespace(uri);
@@ -135,262 +135,262 @@
}
/**
- * Unfortunately there is disagreement in the user community about the semantics of
- * setPrefix on the XMLStreamWriter. An example will explain the difference:
- * writer.startElement("a")
- * writer.setPrefix("pre", "urn://sample")
- * writer.startElement("b")
- *
- * Some user communities (woodstox) believe that the setPrefix is associate with the scope
- * for "a" and thus remains in scope until the end of a. The basis for this believe is
+ * Unfortunately there is disagreement in the user community about the semantics of setPrefix on
+ * the XMLStreamWriter. An example will explain the difference: writer.startElement("a")
+ * writer.setPrefix("pre", "urn://sample") writer.startElement("b")
+ * <p/>
+ * Some user communities (woodstox) believe that the setPrefix is associate with the scope for
+ * "a" and thus remains in scope until the end of a. The basis for this believe is
* XMLStreamWriter javadoc (which some would argue is incomplete).
- *
- * Some user communities believe that the setPrefix is associated with the "b" element.
- * These communities reference an example in the specification and historical usage of SAX.
- *
+ * <p/>
+ * Some user communities believe that the setPrefix is associated with the "b" element. These
+ * communities reference an example in the specification and historical usage of SAX.
+ * <p/>
* This method will return true if the setPrefix is associated with the next writeStartElement.
- *
+ *
* @param writer
* @return true if setPrefix should be generated before startElement
*/
public static boolean isSetPrefixBeforeStartElement(XMLStreamWriter writer) {
- NamespaceContext nc = writer.getNamespaceContext();
- return(nc ==null || nc.getClass().getName().indexOf("wstx") == -1);
+ NamespaceContext nc = writer.getNamespaceContext();
+ return (nc == null || nc.getClass().getName().indexOf("wstx") == -1);
}
-
+
/**
- * Method serializeStartpart.
- * Serialize the start tag of an element.
+ * Method serializeStartpart. Serialize the start tag of an element.
*
* @param element
* @param writer
* @throws XMLStreamException
*/
- public static void serializeStartpart(OMElement element,
- XMLStreamWriter writer) throws XMLStreamException {
- serializeStartpart(element, element.getLocalName(), writer);
+ public static void serializeStartpart(OMElement element,
+ XMLStreamWriter writer) throws XMLStreamException {
+ serializeStartpart(element, element.getLocalName(), writer);
}
-
+
/**
- * Method serializeStartpart.
- * Serialize the start tag of an element.
+ * Method serializeStartpart. Serialize the start tag of an element.
*
* @param element
* @param localName (in some cases, the caller wants to force a different localName)
* @param writer
* @throws XMLStreamException
*/
- public static void serializeStartpart(OMElement element, String localName, XMLStreamWriter writer)
+ public static void serializeStartpart(OMElement element, String localName,
+ XMLStreamWriter writer)
throws XMLStreamException {
-
- // Note: To serialize the start tag, we must follow the order dictated by the JSR-173 (StAX) specification.
- // Please keep this code in sync with the code in StreamingOMSerializer.serializeElement
-
+
+ // Note: To serialize the start tag, we must follow the order dictated by the JSR-173 (StAX) specification.
+ // Please keep this code in sync with the code in StreamingOMSerializer.serializeElement
+
// The algorithm is:
// ... generate setPrefix/setDefaultNamespace for each namespace declaration if the prefix is unassociated.
- // ... generate setPrefix/setDefaultNamespace if the prefix of the element is unassociated
- // ... generate setPrefix/setDefaultNamespace for each unassociated prefix of the attributes.
- //
- // ... generate writeStartElement (See NOTE_A)
- //
- // ... generate writeNamespace/writerDefaultNamespace for the new namespace declarations determine during the "set" processing
- // ... generate writeAttribute for each attribute
-
- // NOTE_A: To confuse matters, some StAX vendors (including woodstox), believe that the setPrefix bindings
- // should occur after the writeStartElement. If this is the case, the writeStartElement is generated first.
-
- ArrayList writePrefixList = null;
- ArrayList writeNSList = null;
-
- // Get the namespace and prefix of the element
- OMNamespace eOMNamespace = element.getNamespace();
- String ePrefix = null;
- String eNamespace = null;
- if (eOMNamespace != null) {
- ePrefix = eOMNamespace.getPrefix();
- eNamespace = eOMNamespace.getNamespaceURI();
- }
- ePrefix = (ePrefix != null && ePrefix.length() == 0) ? null : ePrefix;
- eNamespace = (eNamespace != null && eNamespace.length() == 0) ? null : eNamespace;
-
- // Write the startElement if required
- boolean setPrefixFirst = isSetPrefixBeforeStartElement(writer);
+ // ... generate setPrefix/setDefaultNamespace if the prefix of the element is unassociated
+ // ... generate setPrefix/setDefaultNamespace for each unassociated prefix of the attributes.
+ //
+ // ... generate writeStartElement (See NOTE_A)
+ //
+ // ... generate writeNamespace/writerDefaultNamespace for the new namespace declarations determine during the "set" processing
+ // ... generate writeAttribute for each attribute
+
+ // NOTE_A: To confuse matters, some StAX vendors (including woodstox), believe that the setPrefix bindings
+ // should occur after the writeStartElement. If this is the case, the writeStartElement is generated first.
+
+ ArrayList writePrefixList = null;
+ ArrayList writeNSList = null;
+
+ // Get the namespace and prefix of the element
+ OMNamespace eOMNamespace = element.getNamespace();
+ String ePrefix = null;
+ String eNamespace = null;
+ if (eOMNamespace != null) {
+ ePrefix = eOMNamespace.getPrefix();
+ eNamespace = eOMNamespace.getNamespaceURI();
+ }
+ ePrefix = (ePrefix != null && ePrefix.length() == 0) ? null : ePrefix;
+ eNamespace = (eNamespace != null && eNamespace.length() == 0) ? null : eNamespace;
+
+ // Write the startElement if required
+ boolean setPrefixFirst = isSetPrefixBeforeStartElement(writer);
if (!setPrefixFirst) {
- if (eNamespace != null) {
- if (ePrefix == null) {
- writer.writeStartElement("", localName, eNamespace);
- } else {
- writer.writeStartElement(ePrefix, localName, eNamespace);
- }
- } else {
- writer.writeStartElement(localName);
- }
- }
-
- // Generate setPrefix for the namespace declarations
- Iterator it = element.getAllDeclaredNamespaces();
- while (it != null && it.hasNext()) {
- OMNamespace omNamespace = (OMNamespace) it.next();
- String prefix = null;
- String namespace = null;
- if (omNamespace != null) {
- prefix = omNamespace.getPrefix();
- namespace = omNamespace.getNamespaceURI();
- }
- prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
- namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
-
-
- String newPrefix = generateSetPrefix(prefix, namespace, writer, false);
- // If this is a new association, remember it so that it can written out later
- if (newPrefix != null) {
- if (writePrefixList == null) {
- writePrefixList= new ArrayList();
- writeNSList = new ArrayList();
- }
- if (!writePrefixList.contains(newPrefix)) {
- writePrefixList.add(newPrefix);
- writeNSList.add(namespace);
- }
- }
- }
-
- // Generate setPrefix for the element
- // Get the prefix and namespace of the element. "" and null are identical.
- String newPrefix = generateSetPrefix(ePrefix, eNamespace, writer, false);
- // If this is a new association, remember it so that it can written out later
- if (newPrefix != null) {
- if (writePrefixList == null) {
- writePrefixList= new ArrayList();
- writeNSList = new ArrayList();
- }
- if (!writePrefixList.contains(newPrefix)) {
- writePrefixList.add(newPrefix);
- writeNSList.add(eNamespace);
- }
- }
-
- // Now Generate setPrefix for each attribute
- Iterator attrs = element.getAllAttributes();
+ if (eNamespace != null) {
+ if (ePrefix == null) {
+ writer.writeStartElement("", localName, eNamespace);
+ } else {
+ writer.writeStartElement(ePrefix, localName, eNamespace);
+ }
+ } else {
+ writer.writeStartElement(localName);
+ }
+ }
+
+ // Generate setPrefix for the namespace declarations
+ Iterator it = element.getAllDeclaredNamespaces();
+ while (it != null && it.hasNext()) {
+ OMNamespace omNamespace = (OMNamespace) it.next();
+ String prefix = null;
+ String namespace = null;
+ if (omNamespace != null) {
+ prefix = omNamespace.getPrefix();
+ namespace = omNamespace.getNamespaceURI();
+ }
+ prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
+ namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
+
+
+ String newPrefix = generateSetPrefix(prefix, namespace, writer, false);
+ // If this is a new association, remember it so that it can written out later
+ if (newPrefix != null) {
+ if (writePrefixList == null) {
+ writePrefixList = new ArrayList();
+ writeNSList = new ArrayList();
+ }
+ if (!writePrefixList.contains(newPrefix)) {
+ writePrefixList.add(newPrefix);
+ writeNSList.add(namespace);
+ }
+ }
+ }
+
+ // Generate setPrefix for the element
+ // Get the prefix and namespace of the element. "" and null are identical.
+ String newPrefix = generateSetPrefix(ePrefix, eNamespace, writer, false);
+ // If this is a new association, remember it so that it can written out later
+ if (newPrefix != null) {
+ if (writePrefixList == null) {
+ writePrefixList = new ArrayList();
+ writeNSList = new ArrayList();
+ }
+ if (!writePrefixList.contains(newPrefix)) {
+ writePrefixList.add(newPrefix);
+ writeNSList.add(eNamespace);
+ }
+ }
+
+ // Now Generate setPrefix for each attribute
+ Iterator attrs = element.getAllAttributes();
while (attrs != null && attrs.hasNext()) {
- OMAttribute attr = (OMAttribute) attrs.next();
- OMNamespace omNamespace = attr.getNamespace();
- String prefix = null;
- String namespace = null;
- if (omNamespace != null) {
- prefix = omNamespace.getPrefix();
- namespace = omNamespace.getNamespaceURI();
- }
- prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
- namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
-
+ OMAttribute attr = (OMAttribute) attrs.next();
+ OMNamespace omNamespace = attr.getNamespace();
+ String prefix = null;
+ String namespace = null;
+ if (omNamespace != null) {
+ prefix = omNamespace.getPrefix();
+ namespace = omNamespace.getNamespaceURI();
+ }
+ prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
+ namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
+
// Default prefix referencing is not allowed on an attribute
if (prefix == null && namespace != null) {
- String writerPrefix = writer.getPrefix(namespace);
- writerPrefix = (writerPrefix != null && writerPrefix.length() == 0) ? null : writerPrefix;
- prefix = (writerPrefix != null) ?
- writerPrefix : getNextNSPrefix();
+ String writerPrefix = writer.getPrefix(namespace);
+ writerPrefix =
+ (writerPrefix != null && writerPrefix.length() == 0) ? null : writerPrefix;
+ prefix = (writerPrefix != null) ?
+ writerPrefix : getNextNSPrefix();
}
newPrefix = generateSetPrefix(prefix, namespace, writer, true);
// If the prefix is not associated with a namespace yet, remember it so that we can
- // write out a namespace declaration
- if (newPrefix != null) {
- if (writePrefixList == null) {
- writePrefixList= new ArrayList();
- writeNSList = new ArrayList();
- }
- if (!writePrefixList.contains(newPrefix)) {
- writePrefixList.add(newPrefix);
- writeNSList.add(namespace);
- }
- }
+ // write out a namespace declaration
+ if (newPrefix != null) {
+ if (writePrefixList == null) {
+ writePrefixList = new ArrayList();
+ writeNSList = new ArrayList();
+ }
+ if (!writePrefixList.contains(newPrefix)) {
+ writePrefixList.add(newPrefix);
+ writeNSList.add(namespace);
+ }
+ }
}
-
+
// Write the startElement if required
if (setPrefixFirst) {
- if (eNamespace != null) {
- if (ePrefix == null) {
- writer.writeStartElement("", localName, eNamespace);
- } else {
- writer.writeStartElement(ePrefix, localName, eNamespace);
- }
- } else {
- writer.writeStartElement(localName);
- }
+ if (eNamespace != null) {
+ if (ePrefix == null) {
+ writer.writeStartElement("", localName, eNamespace);
+ } else {
+ writer.writeStartElement(ePrefix, localName, eNamespace);
+ }
+ } else {
+ writer.writeStartElement(localName);
+ }
}
-
+
// Now write out the list of namespace declarations in this list that we constructed
- // while doing the "set" processing.
- if (writePrefixList != null) {
- for (int i=0; i<writePrefixList.size(); i++) {
- String prefix = (String) writePrefixList.get(i);
- String namespace = (String) writeNSList.get(i);
- if (prefix != null) {
- if(namespace==null){
+ // while doing the "set" processing.
+ if (writePrefixList != null) {
+ for (int i = 0; i < writePrefixList.size(); i++) {
+ String prefix = (String) writePrefixList.get(i);
+ String namespace = (String) writeNSList.get(i);
+ if (prefix != null) {
+ if (namespace == null) {
writer.writeNamespace(prefix, "");
- } else{
+ } else {
writer.writeNamespace(prefix, namespace);
}
- } else {
- writer.writeDefaultNamespace(namespace);
- }
- }
+ } else {
+ writer.writeDefaultNamespace(namespace);
+ }
+ }
}
-
+
// Now write the attributes
- attrs = element.getAllAttributes();
+ attrs = element.getAllAttributes();
while (attrs != null && attrs.hasNext()) {
- OMAttribute attr = (OMAttribute) attrs.next();
- OMNamespace omNamespace = attr.getNamespace();
- String prefix = null;
- String namespace = null;
- if (omNamespace != null) {
- prefix = omNamespace.getPrefix();
- namespace = omNamespace.getNamespaceURI();
- }
- prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
- namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
-
+ OMAttribute attr = (OMAttribute) attrs.next();
+ OMNamespace omNamespace = attr.getNamespace();
+ String prefix = null;
+ String namespace = null;
+ if (omNamespace != null) {
+ prefix = omNamespace.getPrefix();
+ namespace = omNamespace.getNamespaceURI();
+ }
+ prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
+ namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
+
if (prefix == null && namespace != null) {
- // Default namespaces are not allowed on an attribute reference.
+ // Default namespaces are not allowed on an attribute reference.
// Earlier in this code, a unique prefix was added for this case...now obtain and use it
- prefix = writer.getPrefix(namespace);
+ prefix = writer.getPrefix(namespace);
//XMLStreamWriter doesn't allow for getPrefix to know whether you're asking for the prefix
//for an attribute or an element. So if the namespace matches the default namespace getPrefix will return
- //the empty string, as if it were an element, in all cases (even for attributes, and even if
+ //the empty string, as if it were an element, in all cases (even for attributes, and even if
//there was a prefix specifically set up for this), which is not the desired behavior.
- //Since the interface is base java, we can't fix it where we need to (by adding an attr boolean to
+ //Since the interface is base java, we can't fix it where we need to (by adding an attr boolean to
//XMLStreamWriter.getPrefix), so we hack it in here...
- if ( prefix == null || "".equals( prefix ) ) {
- for (int i=0; i<writePrefixList.size(); i++) {
- if ( namespace.equals( (String)writeNSList.get( i ) ) ) {
- prefix = (String)writePrefixList.get( i );
+ if (prefix == null || "".equals(prefix)) {
+ for (int i = 0; i < writePrefixList.size(); i++) {
+ if (namespace.equals((String) writeNSList.get(i))) {
+ prefix = (String) writePrefixList.get(i);
}
}
}
} else if (namespace != null) {
- // Use the writer's prefix if it is different, but if the writers
+ // Use the writer's prefix if it is different, but if the writers
// prefix is empty then do not replace because attributes do not
// default to the default namespace like elements do.
String writerPrefix = writer.getPrefix(namespace);
if (!prefix.equals(writerPrefix) && !"".equals(writerPrefix)) {
- prefix = writerPrefix;
- }
+ prefix = writerPrefix;
+ }
}
if (namespace != null) {
- // Qualified attribute
- writer.writeAttribute(prefix, namespace,
- attr.getLocalName(),
- attr.getAttributeValue());
+ // Qualified attribute
+ writer.writeAttribute(prefix, namespace,
+ attr.getLocalName(),
+ attr.getAttributeValue());
} else {
- // Unqualified attribute
- writer.writeAttribute(attr.getLocalName(),
- attr.getAttributeValue());
+ // Unqualified attribute
+ writer.writeAttribute(attr.getLocalName(),
+ attr.getAttributeValue());
}
}
}
- private static boolean checkForPrefixInTheCurrentContext(XMLStreamWriter writer, String nameSpaceName, String prefix) throws XMLStreamException {
+ private static boolean checkForPrefixInTheCurrentContext(XMLStreamWriter writer,
+ String nameSpaceName, String prefix)
+ throws XMLStreamException {
Iterator prefixesIter = writer.getNamespaceContext().getPrefixes(nameSpaceName);
while (prefixesIter.hasNext()) {
String prefix_w = (String) prefixesIter.next();
@@ -424,6 +424,7 @@
/**
* Serialize attributes
+ *
* @param element
* @param writer
* @throws XMLStreamException
@@ -437,7 +438,7 @@
if (attributes != null && attributes.hasNext()) {
while (attributes.hasNext()) {
serializeAttribute((OMAttribute) attributes.next(),
- writer);
+ writer);
}
}
}
@@ -482,11 +483,12 @@
StreamingOMSerializer streamingOMSerializer = new StreamingOMSerializer();
if (cache) {
streamingOMSerializer.serialize(element.getXMLStreamReader(),
- writer);
+ writer);
} else {
- XMLStreamReader xmlStreamReaderWithoutCaching = element.getXMLStreamReaderWithoutCaching();
+ XMLStreamReader xmlStreamReaderWithoutCaching =
+ element.getXMLStreamReaderWithoutCaching();
streamingOMSerializer.serialize(xmlStreamReaderWithoutCaching,
- writer);
+ writer);
}
}
@@ -502,47 +504,50 @@
return prefix;
}
-
+
/**
* Generate setPrefix/setDefaultNamespace if the prefix is not associated
+ *
* @param prefix
* @param namespace
* @param writer
- * @param attr
+ * @param attr
* @return prefix name if a setPrefix/setDefaultNamespace is performed
*/
- public static String generateSetPrefix(String prefix, String namespace, XMLStreamWriter writer, boolean attr) throws XMLStreamException {
- // Generate setPrefix/setDefaultNamespace if the prefix is not associated.
- String newPrefix = null;
+ public static String generateSetPrefix(String prefix, String namespace, XMLStreamWriter writer,
+ boolean attr) throws XMLStreamException {
+ // Generate setPrefix/setDefaultNamespace if the prefix is not associated.
+ String newPrefix = null;
if (namespace != null) {
- // Qualified Namespace
-
- // Get the namespace associated with this writer
- String writerNS = writer.getNamespaceContext().getNamespaceURI((prefix==null) ? "" : prefix);
- writerNS = (writerNS != null && writerNS.length() == 0) ? null : writerNS;
-
- if (writerNS == null || !writerNS.equals(namespace)) {
- // Writer has not associated this namespace with a prefix
- if (prefix == null) {
- writer.setDefaultNamespace(namespace);
- newPrefix = "";
- } else {
- writer.setPrefix(prefix, namespace);
- newPrefix = prefix;
- }
- } else {
- // No Action needed..The writer already has associated this prefix to this namespace
- }
+ // Qualified Namespace
+
+ // Get the namespace associated with this writer
+ String writerNS =
+ writer.getNamespaceContext().getNamespaceURI((prefix == null) ? "" : prefix);
+ writerNS = (writerNS != null && writerNS.length() == 0) ? null : writerNS;
+
+ if (writerNS == null || !writerNS.equals(namespace)) {
+ // Writer has not associated this namespace with a prefix
+ if (prefix == null) {
+ writer.setDefaultNamespace(namespace);
+ newPrefix = "";
+ } else {
+ writer.setPrefix(prefix, namespace);
+ newPrefix = prefix;
+ }
+ } else {
+ // No Action needed..The writer already has associated this prefix to this namespace
+ }
} else {
- // Unqualified Namespace
-
- // Make sure the default namespace is either not used or disabled (set to "")
- String writerNS = writer.getNamespaceContext().getNamespaceURI("");
- if (writerNS != null && writerNS.length() > 0 && !attr) {
- // Disable the default namespace
- writer.setDefaultNamespace("");
- newPrefix = "";
- }
+ // Unqualified Namespace
+
+ // Make sure the default namespace is either not used or disabled (set to "")
+ String writerNS = writer.getNamespaceContext().getNamespaceURI("");
+ if (writerNS != null && writerNS.length() > 0 && !attr) {
+ // Disable the default namespace
+ writer.setDefaultNamespace("");
+ newPrefix = "";
+ }
}
return newPrefix;
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/AttributeHelper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/AttributeHelper.java?view=diff&rev=515594&r1=515593&r2=515594
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/AttributeHelper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/AttributeHelper.java Wed Mar 7 06:59:00 2007
@@ -19,24 +19,22 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
-/**
- * Helper class for attributes.
- */
+/** Helper class for attributes. */
public class AttributeHelper {
/**
- * In Axiom, a single tree should always contain objects created from the same type
- * of factory (eg: LinkedListImplFactory, DOMFactory, etc.,). This method will convert
- * omAttribute to the given omFactory.
- *
- * @see ElementHelper#importOMElement(OMElement, OMFactory) to convert instances of OMElement
- */
+ * In Axiom, a single tree should always contain objects created from the same type of factory
+ * (eg: LinkedListImplFactory, DOMFactory, etc.,). This method will convert omAttribute to the
+ * given omFactory.
+ *
+ * @see ElementHelper#importOMElement(OMElement, OMFactory) to convert instances of OMElement
+ */
public static void importOMAttribute(OMAttribute omAttribute, OMElement omElement) {
// first check whether the given OMAttribute has the same OMFactory
if (omAttribute.getOMFactory().getClass().isInstance(omElement.getOMFactory())) {
omElement.addAttribute(omAttribute);
- }
- else {
- omElement.addAttribute(omAttribute.getLocalName(), omAttribute.getAttributeValue(), omAttribute.getNamespace());
+ } else {
+ omElement.addAttribute(omAttribute.getLocalName(), omAttribute.getAttributeValue(),
+ omAttribute.getNamespace());
}
}
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/Base64.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/Base64.java?view=diff&rev=515594&r1=515593&r2=515594
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/Base64.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/Base64.java Wed Mar 7 06:59:00 2007
@@ -22,12 +22,12 @@
*/
public class Base64 {
- private static final char[] S_BASE64CHAR = {'A', 'B', 'C', 'D', 'E', 'F',
+ private static final char[] S_BASE64CHAR = { 'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5',
- '6', '7', '8', '9', '+', '/'};
+ '6', '7', '8', '9', '+', '/' };
private static final char S_BASE64PAD = '=';
@@ -122,29 +122,28 @@
}
/**
- * checks input string for invalid Base64 characters
+ * checks input string for invalid Base64 characters
+ *
* @param data
- * @return true, if String contains only valid Base64 characters.
- * false, otherwise
+ * @return true, if String contains only valid Base64 characters. false, otherwise
*/
public static boolean isValidBase64Encoding(String data) {
for (int i = 0; i < data.length(); i++) {
char ch = data.charAt(i);
-
+
if (ch == S_BASE64PAD || ch < S_DECODETABLE.length
&& S_DECODETABLE[ch] != Byte.MAX_VALUE) {
- //valid character.Do nothing
- }else if(ch == '\r' || ch == '\n'){
- //do nothing
- }
- else{
- return false;
+ //valid character.Do nothing
+ } else if (ch == '\r' || ch == '\n') {
+ //do nothing
+ } else {
+ return false;
}
}//iterate over all characters in the string
return true;
- }
-
-
+ }
+
+
/**
*
*/
@@ -189,16 +188,12 @@
}
}
- /**
- * Returns base64 representation of specified byte array.
- */
+ /** Returns base64 representation of specified byte array. */
public static String encode(byte[] data) {
return encode(data, 0, data.length);
}
- /**
- * Returns base64 representation of specified byte array.
- */
+ /** Returns base64 representation of specified byte array. */
public static String encode(byte[] data, int off, int len) {
if (len <= 0)
return "";
@@ -233,9 +228,7 @@
return new String(out, 0, windex);
}
- /**
- * Outputs base64 representation of the specified byte array to the specified String Buffer
- */
+ /** Outputs base64 representation of the specified byte array to the specified String Buffer */
public static void encode(byte[] data, int off, int len, StringBuffer buffer) {
if (len <= 0) {
return;
@@ -273,10 +266,7 @@
}
}
- /**
- * Outputs base64 representation of the specified byte array to a byte
- * stream.
- */
+ /** Outputs base64 representation of the specified byte array to a byte stream. */
public static void encode(byte[] data, int off, int len,
OutputStream ostream) throws IOException {
if (len <= 0)
@@ -313,10 +303,7 @@
}
}
- /**
- * Outputs base64 representation of the specified byte array to a character
- * stream.
- */
+ /** Outputs base64 representation of the specified byte array to a character stream. */
public static void encode(byte[] data, int off, int len, Writer writer)
throws IOException {
if (len <= 0)
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/DigestGenerator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/DigestGenerator.java?view=diff&rev=515594&r1=515593&r2=515594
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/DigestGenerator.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/DigestGenerator.java Wed Mar 7 06:59:00 2007
@@ -15,7 +15,13 @@
*/
package org.apache.axiom.om.util;
-import org.apache.axiom.om.*;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMProcessingInstruction;
+import org.apache.axiom.om.OMText;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
@@ -23,11 +29,16 @@
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.SortedMap;
+import java.util.TreeMap;
/**
- * Helper class to provide the functionality of the digest value generation.
- * This is an implementation of the DOMHASH algorithm on OM.
+ * Helper class to provide the functionality of the digest value generation. This is an
+ * implementation of the DOMHASH algorithm on OM.
*/
public class DigestGenerator {
@@ -48,10 +59,11 @@
Collection childNodes = getValidElements(document);
dos.writeInt(childNodes.size());
Iterator itr = childNodes.iterator();
- while(itr.hasNext()) {
+ while (itr.hasNext()) {
OMNode node = (OMNode) itr.next();
if (node.getType() == OMNode.PI_NODE)
- dos.write(getDigest((OMProcessingInstruction) node, digestAlgorithm)); else if (
+ dos.write(getDigest((OMProcessingInstruction) node, digestAlgorithm));
+ else if (
node.getType() == OMNode.ELEMENT_NODE)
dos.write(getDigest((OMElement) node, digestAlgorithm));
}
@@ -74,10 +86,14 @@
* @return Returns a byte array representing the calculated digest value
*/
public byte[] getDigest(OMNode node, String digestAlgorithm) {
- if (node.getType() == OMNode.ELEMENT_NODE) return getDigest((OMElement) node, digestAlgorithm); else if (
+ if (node.getType() == OMNode.ELEMENT_NODE)
+ return getDigest((OMElement) node, digestAlgorithm);
+ else if (
node.getType() == OMNode.TEXT_NODE)
- return getDigest((OMText) node, digestAlgorithm); else if (node.getType() == OMNode.PI_NODE)
- return getDigest((OMProcessingInstruction) node, digestAlgorithm); else return new byte[0];
+ return getDigest((OMText) node, digestAlgorithm);
+ else if (node.getType() == OMNode.PI_NODE)
+ return getDigest((OMProcessingInstruction) node, digestAlgorithm);
+ else return new byte[0];
}
/**
@@ -100,7 +116,7 @@
Collection attrs = getAttributesWithoutNS(element);
dos.writeInt(attrs.size());
Iterator itr = attrs.iterator();
- while(itr.hasNext())
+ while (itr.hasNext())
dos.write(getDigest((OMAttribute) itr.next(), digestAlgorithm));
OMNode node = element.getFirstOMChild();
// adjoining Texts are merged,
@@ -165,7 +181,8 @@
*/
public byte[] getDigest(OMAttribute attribute, String digestAlgorithm) throws OMException {
byte[] digest = new byte[0];
- if (!(attribute.getLocalName().equals("xmlns") || attribute.getLocalName().startsWith("xmlns:"))) try {
+ if (!(attribute.getLocalName().equals("xmlns") ||
+ attribute.getLocalName().startsWith("xmlns:"))) try {
MessageDigest md = MessageDigest.getInstance(digestAlgorithm);
md.update((byte) 0);
md.update((byte) 0);
@@ -191,7 +208,7 @@
* @param digestAlgorithm
* @return Returns a byte array representing the calculated digest value
*/
- public byte[] getDigest(OMText text, String digestAlgorithm) throws OMException {
+ public byte[] getDigest(OMText text, String digestAlgorithm) throws OMException {
byte[] digest = new byte[0];
try {
MessageDigest md = MessageDigest.getInstance(digestAlgorithm);
@@ -210,8 +227,8 @@
}
/**
- * This method is an overloaded method for getting the expanded name namespaceURI followed by the local name
- * for OMElement
+ * This method is an overloaded method for getting the expanded name namespaceURI followed by
+ * the local name for OMElement
*
* @param element
* @return Returns the expanded name of OMElement
@@ -221,8 +238,8 @@
}
/**
- * This method is an overloaded method for getting the expanded name namespaceURI followed by the local name
- * for OMAttribute
+ * This method is an overloaded method for getting the expanded name namespaceURI followed by
+ * the local name for OMAttribute
*
* @param attribute
* @return Returns the expanded name of the OMAttribute
@@ -242,15 +259,16 @@
Iterator itr = element.getAllAttributes();
while (itr.hasNext()) {
OMAttribute attribute = (OMAttribute) itr.next();
- if (!(attribute.getLocalName().equals("xmlns") || attribute.getLocalName().startsWith("xmlns:")))
+ if (!(attribute.getLocalName().equals("xmlns") ||
+ attribute.getLocalName().startsWith("xmlns:")))
map.put(getExpandedName(attribute), attribute);
}
return map.values();
}
/**
- * Gets the valid element collection of an OMDocument.
- * OMElement and OMProcessingInstruction only
+ * Gets the valid element collection of an OMDocument. OMElement and OMProcessingInstruction
+ * only
*
* @param document
* @return Returns a collection of OMProcessingInstructions and OMElements
@@ -258,9 +276,10 @@
public Collection getValidElements(OMDocument document) {
ArrayList list = new ArrayList();
Iterator itr = document.getChildren();
- while(itr.hasNext()) {
- OMNode node = (OMNode)itr.next();
- if(node.getType() == OMNode.ELEMENT_NODE || node.getType() == OMNode.PI_NODE) list.add(node);
+ while (itr.hasNext()) {
+ OMNode node = (OMNode) itr.next();
+ if (node.getType() == OMNode.ELEMENT_NODE || node.getType() == OMNode.PI_NODE)
+ list.add(node);
}
return list;
}
@@ -286,7 +305,8 @@
* @return Returns true if the OMNode XML contents are equal
*/
public boolean compareOMNode(OMNode node, OMNode comparingNode, String digestAlgorithm) {
- return Arrays.equals(getDigest(node, digestAlgorithm), getDigest(comparingNode, digestAlgorithm));
+ return Arrays.equals(getDigest(node, digestAlgorithm),
+ getDigest(comparingNode, digestAlgorithm));
}
/**
@@ -297,8 +317,10 @@
* @param digestAlgorithm
* @return Returns true if the OMDocument XML content are equal
*/
- public boolean compareOMDocument(OMDocument document, OMDocument comparingDocument, String digestAlgorithm) {
- return Arrays.equals(getDigest(document, digestAlgorithm), getDigest(comparingDocument, digestAlgorithm));
+ public boolean compareOMDocument(OMDocument document, OMDocument comparingDocument,
+ String digestAlgorithm) {
+ return Arrays.equals(getDigest(document, digestAlgorithm),
+ getDigest(comparingDocument, digestAlgorithm));
}
/**
@@ -309,22 +331,18 @@
* @param digestAlgorithm
* @return Returns true if the OMDocument XML content are equal
*/
- public boolean compareOMAttribute(OMAttribute attribute, OMAttribute comparingAttribute, String digestAlgorithm) {
- return Arrays.equals(getDigest(attribute, digestAlgorithm), getDigest(comparingAttribute, digestAlgorithm));
+ public boolean compareOMAttribute(OMAttribute attribute, OMAttribute comparingAttribute,
+ String digestAlgorithm) {
+ return Arrays.equals(getDigest(attribute, digestAlgorithm),
+ getDigest(comparingAttribute, digestAlgorithm));
}
- /**
- * String representing the MD5 digest algorithm
- */
+ /** String representing the MD5 digest algorithm */
public static final String md5DigestAlgorithm = "MD5";
- /**
- * String representing the SHA digest algorithm
- */
+ /** String representing the SHA digest algorithm */
public static final String shaDigestAlgorithm = "SHA";
- /**
- * String representing the SHA1 digest algorithm
- */
+ /** String representing the SHA1 digest algorithm */
public static final String sha1DigestAlgorithm = "SHA1";
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java?view=diff&rev=515594&r1=515593&r2=515594
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java Wed Mar 7 06:59:00 2007
@@ -15,7 +15,12 @@
*/
package org.apache.axiom.om.util;
-import org.apache.axiom.om.*;
+import org.apache.axiom.om.OMAttribute;
+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.OMNode;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import javax.xml.namespace.QName;
@@ -25,8 +30,8 @@
import java.util.Iterator;
/**
- * Helper class to provide extra utility stuff against elements.
- * The code is designed to work with any element implementation.
+ * Helper class to provide extra utility stuff against elements. The code is designed to work with
+ * any element implementation.
*/
public class ElementHelper {
@@ -43,7 +48,8 @@
}
/**
- * Turns a prefix:local qname string into a proper QName, evaluating it in the OMElement context.
+ * Turns a prefix:local qname string into a proper QName, evaluating it in the OMElement
+ * context.
*
* @param qname qname to resolve
* @param defaultToParentNameSpace flag that controls behaviour when there is no namespace.
@@ -76,8 +82,8 @@
}
/**
- * Turns a prefix:local qname string into a proper QName, evaluating it in the OMElement context.
- * Unprefixed qnames resolve to the local namespace.
+ * Turns a prefix:local qname string into a proper QName, evaluating it in the OMElement
+ * context. Unprefixed qnames resolve to the local namespace.
*
* @param qname prefixed qname string to resolve
* @return Returns null for any failure to extract a qname.
@@ -119,7 +125,8 @@
if (contentIDName.equalsIgnoreCase("href")
& contentID.substring(0, 3).equalsIgnoreCase("cid")) {
contentID = contentID.substring(4);
- String charEnc = charsetEncoding == null || "".equals(charsetEncoding) ? "UTF-8" : charsetEncoding;
+ String charEnc = charsetEncoding == null || "".equals(charsetEncoding) ? "UTF-8" :
+ charsetEncoding;
try {
contentID = URLDecoder.decode(contentID, charEnc);
} catch (UnsupportedEncodingException e) {
@@ -138,20 +145,23 @@
}
/**
- * Some times two OMElements needs to be added to the same object tree. But in Axiom, a single tree should always
- * contain object created from the same type of factory (eg: LinkedListImplFactory, DOMFactory, etc.,). If one OMElement
- * is created from a different factory than that of the factory which was used to create the object in the existing
- * tree, we need to convert the new OMElement to match to the factory of existing object tree.
- * This method will convert omElement to the given omFactory.
+ * Some times two OMElements needs to be added to the same object tree. But in Axiom, a single
+ * tree should always contain object created from the same type of factory (eg:
+ * LinkedListImplFactory, DOMFactory, etc.,). If one OMElement is created from a different
+ * factory than that of the factory which was used to create the object in the existing tree, we
+ * need to convert the new OMElement to match to the factory of existing object tree. This
+ * method will convert omElement to the given omFactory.
*
- * @see AttributeHelper#importOMAttribute(OMAttribute, OMElement) to convert instances of OMAttribute
+ * @see AttributeHelper#importOMAttribute(OMAttribute, OMElement) to convert instances of
+ * OMAttribute
*/
public static OMElement importOMElement(OMElement omElement, OMFactory omFactory) {
// first check whether the given OMElement has the same omFactory
if (omElement.getOMFactory().getClass().isInstance(omFactory)) {
return omElement;
- }else {
- OMElement documentElement = new StAXOMBuilder(omFactory, omElement.getXMLStreamReader()).getDocumentElement();
+ } else {
+ OMElement documentElement = new StAXOMBuilder(omFactory, omElement.getXMLStreamReader())
+ .getDocumentElement();
documentElement.build();
return documentElement;
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java?view=diff&rev=515594&r1=515593&r2=515594
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java Wed Mar 7 06:59:00 2007
@@ -1,5 +1,8 @@
package org.apache.axiom.om.util;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
@@ -12,91 +15,94 @@
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
public class StAXUtils {
private static interface ObjectCreator {
- Object newObject();
- }
+ Object newObject();
+ }
+
+ private static class Pool {
+ private final int MAX_POOL_SIZE = 100;
+ private final List objects = new ArrayList();
+ private final ObjectCreator objectCreator;
+
+ Pool(ObjectCreator[] creators) {
+ ObjectCreator oc = null;
+ for (int i = 0; i < creators.length; i++) {
+ try {
+ Object o = creators[i].newObject();
+ oc = creators[i];
+ break;
+ } catch (Throwable t) {
+ // Ignore me
+ }
+ }
+ if (oc == null) {
+ throw new IllegalStateException("No valid ObjectCreator found.");
+ }
+ objectCreator = oc;
+ }
+
+ synchronized Object getInstance() {
+ final int size = objects.size();
+ if (size > 0) {
+ return objects.remove(size - 1);
+ }
+ return objectCreator.newObject();
+ }
- private static class Pool {
- private final int MAX_POOL_SIZE = 100;
- private final List objects = new ArrayList();
- private final ObjectCreator objectCreator;
- Pool(ObjectCreator[] creators) {
- ObjectCreator oc = null;
- for (int i = 0; i < creators.length; i++) {
- try {
- Object o = creators[i].newObject();
- oc = creators[i];
- break;
- } catch (Throwable t) {
- // Ignore me
- }
- }
- if (oc == null) {
- throw new IllegalStateException("No valid ObjectCreator found.");
- }
- objectCreator = oc;
- }
- synchronized Object getInstance() {
- final int size = objects.size();
- if (size > 0) {
- return objects.remove(size-1);
- }
- return objectCreator.newObject();
- }
- synchronized void releaseInstance(Object object) {
- if (objects.size() < MAX_POOL_SIZE) {
- objects.add(object);
- }
- }
- synchronized void clear() {
- objects.clear();
- }
- }
-
- private static final Pool xmlInputFactoryPool = new Pool(new ObjectCreator[]{
- new ObjectCreator(){
- public Object newObject() {
- return XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", StAXUtils.class.getClassLoader());
- }
- },
- new ObjectCreator(){
- public Object newObject() {
- return XMLInputFactory.newInstance();
- }
- }
- });
-
- private static final Pool xmlOutputFactoryPool = new Pool(new ObjectCreator[]{
- new ObjectCreator(){
- public Object newObject() {
- return XMLOutputFactory.newInstance("javax.xml.stream.XMLOutputFactory", StAXUtils.class.getClassLoader());
- }
- },
- new ObjectCreator(){
- public Object newObject() {
- return XMLOutputFactory.newInstance();
- }
- }
- });
+ synchronized void releaseInstance(Object object) {
+ if (objects.size() < MAX_POOL_SIZE) {
+ objects.add(object);
+ }
+ }
-
- private static Log log = LogFactory.getLog(StAXUtils.class);
+ synchronized void clear() {
+ objects.clear();
+ }
+ }
+
+ private static final Pool xmlInputFactoryPool = new Pool(new ObjectCreator[] {
+ new ObjectCreator() {
+ public Object newObject() {
+ return XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory",
+ StAXUtils.class.getClassLoader());
+ }
+ },
+ new ObjectCreator() {
+ public Object newObject() {
+ return XMLInputFactory.newInstance();
+ }
+ }
+ });
+
+ private static final Pool xmlOutputFactoryPool = new Pool(new ObjectCreator[] {
+ new ObjectCreator() {
+ public Object newObject() {
+ return XMLOutputFactory.newInstance("javax.xml.stream.XMLOutputFactory",
+ StAXUtils.class.getClassLoader());
+ }
+ },
+ new ObjectCreator() {
+ public Object newObject() {
+ return XMLOutputFactory.newInstance();
+ }
+ }
+ });
+
+
+ private static Log log = LogFactory.getLog(StAXUtils.class);
private static boolean isDebugEnabled = log.isDebugEnabled();
-
- /**
+
+ /**
* Gets an XMLInputFactory instance from pool.
*
* @return an XMLInputFactory instance.
*/
- public static XMLInputFactory getXMLInputFactory() {
- return (XMLInputFactory) xmlInputFactoryPool.getInstance();
+ public static XMLInputFactory getXMLInputFactory() {
+ return (XMLInputFactory) xmlInputFactoryPool.getInstance();
}
/**
@@ -104,16 +110,16 @@
*
* @param factory An XMLInputFactory instance that is available for reuse
*/
- public static void releaseXMLInputFactory(XMLInputFactory factory) {
- xmlInputFactoryPool.releaseInstance(factory);
+ public static void releaseXMLInputFactory(XMLInputFactory factory) {
+ xmlInputFactoryPool.releaseInstance(factory);
}
public static XMLStreamReader createXMLStreamReader(InputStream in, String encoding)
throws XMLStreamException {
XMLInputFactory inputFactory = getXMLInputFactory();
try {
- XMLStreamReader reader = inputFactory.createXMLStreamReader(in, encoding);
- if(isDebugEnabled) {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(in, encoding);
+ if (isDebugEnabled) {
log.debug("XMLStreamReader is " + reader.getClass().getName());
}
return reader;
@@ -127,7 +133,7 @@
XMLInputFactory inputFactory = getXMLInputFactory();
try {
XMLStreamReader reader = inputFactory.createXMLStreamReader(in);
- if(isDebugEnabled) {
+ if (isDebugEnabled) {
log.debug("XMLStreamReader is " + reader.getClass().getName());
}
return reader;
@@ -141,7 +147,7 @@
XMLInputFactory inputFactory = getXMLInputFactory();
try {
XMLStreamReader reader = inputFactory.createXMLStreamReader(in);
- if(isDebugEnabled) {
+ if (isDebugEnabled) {
log.debug("XMLStreamReader is " + reader.getClass().getName());
}
return reader;
@@ -156,7 +162,7 @@
* @return an XMLOutputFactory instance.
*/
public static XMLOutputFactory getXMLOutputFactory() {
- return (XMLOutputFactory) xmlOutputFactoryPool.getInstance();
+ return (XMLOutputFactory) xmlOutputFactoryPool.getInstance();
}
/**
@@ -165,7 +171,7 @@
* @param factory An XMLOutputFactory instance that is available for reuse.
*/
public static void releaseXMLOutputFactory(XMLOutputFactory factory) {
- xmlOutputFactoryPool.releaseInstance(factory);
+ xmlOutputFactoryPool.releaseInstance(factory);
}
public static XMLStreamWriter createXMLStreamWriter(OutputStream out)
@@ -173,7 +179,7 @@
XMLOutputFactory outputFactory = getXMLOutputFactory();
try {
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(out);
- if(isDebugEnabled) {
+ if (isDebugEnabled) {
log.debug("XMLStreamWriter is " + writer.getClass().getName());
}
return writer;
@@ -187,7 +193,7 @@
XMLOutputFactory outputFactory = getXMLOutputFactory();
try {
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(out, encoding);
- if(isDebugEnabled) {
+ if (isDebugEnabled) {
log.debug("XMLStreamWriter is " + writer.getClass().getName());
}
return writer;
@@ -201,7 +207,7 @@
XMLOutputFactory outputFactory = getXMLOutputFactory();
try {
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(out);
- if(isDebugEnabled) {
+ if (isDebugEnabled) {
log.debug("XMLStreamWriter is " + writer.getClass().getName());
}
return writer;
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/UUIDGenerator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/UUIDGenerator.java?view=diff&rev=515594&r1=515593&r2=515594
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/UUIDGenerator.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/UUIDGenerator.java Wed Mar 7 06:59:00 2007
@@ -25,9 +25,7 @@
import java.util.Random;
public class UUIDGenerator {
- /**
- * This class will give UUIDs for axis2.
- */
+ /** This class will give UUIDs for axis2. */
private static String baseUUID = null;
private static long incrementingValue = 0;
@@ -36,8 +34,8 @@
private static Random myRand = null;
/**
- * MD5 a random string with localhost/date etc will return 128 bits
- * construct a string of 18 characters from those bits.
+ * MD5 a random string with localhost/date etc will return 128 bits construct a string of 18
+ * characters from those bits.
*
* @return string
*/
@@ -46,10 +44,10 @@
baseUUID = getInitialUUID();
baseUUID = "urn:uuid:" + baseUUID;
}
- if(++incrementingValue >= Long.MAX_VALUE){
+ if (++incrementingValue >= Long.MAX_VALUE) {
incrementingValue = 0;
}
- return baseUUID + (System.currentTimeMillis() + incrementingValue);
+ return baseUUID + (System.currentTimeMillis() + incrementingValue);
}
protected static String getInitialUUID() {
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/XPathEvaluator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/XPathEvaluator.java?view=diff&rev=515594&r1=515593&r2=515594
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/XPathEvaluator.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/XPathEvaluator.java Wed Mar 7 06:59:00 2007
@@ -7,11 +7,12 @@
public class XPathEvaluator {
- public List evaluateXpath(String xpathExpression, Object element, String nsURI) throws Exception{
+ public List evaluateXpath(String xpathExpression, Object element, String nsURI)
+ throws Exception {
AXIOMXPath xpath = new AXIOMXPath(xpathExpression);
- if (nsURI!=null){
+ if (nsURI != null) {
SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
- nsContext.addNamespace(null,nsURI);
+ nsContext.addNamespace(null, nsURI);
xpath.setNamespaceContext(nsContext);
}
return xpath.selectNodes(element);
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/AXIOMXPath.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/AXIOMXPath.java?view=diff&rev=515594&r1=515593&r2=515594
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/AXIOMXPath.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/AXIOMXPath.java Wed Mar 7 06:59:00 2007
@@ -2,7 +2,6 @@
import org.jaxen.BaseXPath;
import org.jaxen.JaxenException;
-import org.jaxen.SimpleNamespaceContext;
import java.util.HashMap;
import java.util.Map;
@@ -17,8 +16,7 @@
* Construct given an XPath expression string.
*
* @param xpathExpr the XPath expression.
- * @throws org.jaxen.JaxenException if there is a syntax error while
- * parsing the expression
+ * @throws org.jaxen.JaxenException if there is a syntax error while parsing the expression
*/
public AXIOMXPath(String xpathExpr) throws JaxenException {
super(xpathExpr, new DocumentNavigator());
@@ -26,11 +24,12 @@
/**
* This override captures any added namespaces, as the Jaxen BaseXPath class nor
- * NamespaceContext (or SimpleNamespaceContext) exposes thier internal map of the
- * prefixes to the namespaces. This method - although is not the ideal solution to
- * the issue, attempts to provide an override to changing the Jaxen code.
+ * NamespaceContext (or SimpleNamespaceContext) exposes thier internal map of the prefixes to
+ * the namespaces. This method - although is not the ideal solution to the issue, attempts to
+ * provide an override to changing the Jaxen code.
+ *
* @param prefix a namespace prefix
- * @param uri the URI to which the prefix matches
+ * @param uri the URI to which the prefix matches
* @throws JaxenException if the underlying implementation throws an exception
*/
public void addNamespace(String prefix, String uri) throws JaxenException {
@@ -46,6 +45,7 @@
/**
* Expose the prefix to namespace mapping for this expression
+ *
* @return a Map of namespace prefixes to the URIs
*/
public Map getNamespaces() {
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org