Author: jkaputin
Date: Wed Sep 28 08:17:44 2005
New Revision: 292208
URL: http://svn.apache.org/viewcvs?rev=292208&view=rev
Log:
Copied utility classes from wsdl4j and updated import
statements.
Modified:
incubator/woden/java/src/org/apache/woden/internal/util/StringUtils.java
incubator/woden/java/src/org/apache/woden/internal/util/dom/DOMUtils.java
Modified:
incubator/woden/java/src/org/apache/woden/internal/util/StringUtils.java
URL:
http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/util/StringUtils.java?rev=292208&r1=292207&r2=292208&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/util/StringUtils.java
(original)
+++ incubator/woden/java/src/org/apache/woden/internal/util/StringUtils.java
Wed Sep 28 08:17:44 2005
@@ -4,18 +4,119 @@
package org.apache.woden.internal.util;
import java.io.File;
-import java.io.InputStream;
import java.io.IOException;
-import java.net.URL;
+import java.io.InputStream;
import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
/**
* This class and code copied or borrowed from WSDL4J.
*
* @author [EMAIL PROTECTED]
*/
public class StringUtils {
-
- /**
+
+ public static final String lineSeparator =
+ System.getProperty("line.separator", "\n");
+ public static final String lineSeparatorStr = cleanString(lineSeparator);
+
+ // Ensure that escape sequences are passed through properly.
+ public static String cleanString(String str)
+ {
+ if (str == null)
+ return null;
+ else
+ {
+ char[] charArray = str.toCharArray();
+ StringBuffer sBuf = new StringBuffer();
+
+ for (int i = 0; i < charArray.length; i++)
+ switch (charArray[i])
+ {
+ case '\"' : sBuf.append("\\\"");
+ break;
+ case '\\' : sBuf.append("\\\\");
+ break;
+ case '\n' : sBuf.append("\\n");
+ break;
+ case '\r' : sBuf.append("\\r");
+ break;
+ default : sBuf.append(charArray[i]);
+ break;
+ }
+
+ return sBuf.toString();
+ }
+ }
+
+ /*
+ This method will return the correct name for a class object
representing
+ a primitive, a single instance of a class, as well as n-dimensional
arrays
+ of primitives or instances. This logic is needed to handle the string
returned
+ from Class.getName(). If the class object represents a single instance
(or
+ a primitive), Class.getName() returns the fully-qualified name of the
class
+ and no further work is needed. However, if the class object represents
an
+ array (of n dimensions), Class.getName() returns a Descriptor (the
Descriptor
+ grammar is defined in section 4.3 of the Java VM Spec). This method
will
+ parse the Descriptor if necessary.
+ */
+ public static String getClassName(Class targetClass)
+ {
+ String className = targetClass.getName();
+
+ return targetClass.isArray() ? parseDescriptor(className) : className;
+ }
+
+ /*
+ See the comment above for getClassName(targetClass)...
+ */
+ private static String parseDescriptor(String className)
+ {
+ char[] classNameChars = className.toCharArray();
+ int arrayDim = 0;
+ int i = 0;
+
+ while (classNameChars[i] == '[')
+ {
+ arrayDim++;
+ i++;
+ }
+
+ StringBuffer classNameBuf = new StringBuffer();
+
+ switch (classNameChars[i++])
+ {
+ case 'B' : classNameBuf.append("byte");
+ break;
+ case 'C' : classNameBuf.append("char");
+ break;
+ case 'D' : classNameBuf.append("double");
+ break;
+ case 'F' : classNameBuf.append("float");
+ break;
+ case 'I' : classNameBuf.append("int");
+ break;
+ case 'J' : classNameBuf.append("long");
+ break;
+ case 'S' : classNameBuf.append("short");
+ break;
+ case 'Z' : classNameBuf.append("boolean");
+ break;
+ case 'L' : classNameBuf.append(classNameChars,
+ i, classNameChars.length - i - 1);
+ break;
+ }
+
+ for (i = 0; i < arrayDim; i++)
+ classNameBuf.append("[]");
+
+ return classNameBuf.toString();
+ }
+
+ /*
* Return a URL created from a context URL and a relative URI.
* If a valid URL cannot be created the only other possibility
* this method will consider is that an absolute file path has
@@ -58,6 +159,7 @@
throw new IllegalArgumentException("URL cannot be null.");
}
+ //TODO consider exception handling used in wsdl4j
Object content = url.getContent();
if (content == null)
@@ -80,68 +182,38 @@
}
}
- /**
- * This method will return the correct name for a class object representing
- * a primitive, a single instance of a class, as well as n-dimensional
arrays
- * of primitives or instances. This logic is needed to handle the string
returned
- * from Class.getName(). If the class object represents a single instance
(or
- * a primitive), Class.getName() returns the fully-qualified name of the
class
- * and no further work is needed. However, if the class object represents
an
- * array (of n dimensions), Class.getName() returns a Descriptor (the
Descriptor
- * grammar is defined in section 4.3 of the Java VM Spec). This method will
- * parse the Descriptor if necessary.
- */
- public static String getClassName(Class targetClass)
+ public static List parseNMTokens(String nmTokens)
{
- String className = targetClass.getName();
-
- return targetClass.isArray() ? parseDescriptor(className) : className;
+ StringTokenizer strTok = new StringTokenizer(nmTokens, " ");
+ List tokens = new Vector();
+
+ while (strTok.hasMoreTokens())
+ {
+ tokens.add(strTok.nextToken());
+ }
+
+ return tokens;
}
- /*
- See the comment above for getClassName(targetClass)...
- */
- private static String parseDescriptor(String className)
+ public static String getNMTokens(List list)
{
- char[] classNameChars = className.toCharArray();
- int arrayDim = 0;
- int i = 0;
-
- while (classNameChars[i] == '[')
- {
- arrayDim++;
- i++;
- }
-
- StringBuffer classNameBuf = new StringBuffer();
-
- switch (classNameChars[i++])
+ if (list != null)
+ {
+ StringBuffer strBuf = new StringBuffer();
+ int size = list.size();
+
+ for (int i = 0; i < size; i++)
{
- case 'B' : classNameBuf.append("byte");
- break;
- case 'C' : classNameBuf.append("char");
- break;
- case 'D' : classNameBuf.append("double");
- break;
- case 'F' : classNameBuf.append("float");
- break;
- case 'I' : classNameBuf.append("int");
- break;
- case 'J' : classNameBuf.append("long");
- break;
- case 'S' : classNameBuf.append("short");
- break;
- case 'Z' : classNameBuf.append("boolean");
- break;
- case 'L' : classNameBuf.append(classNameChars,
- i, classNameChars.length - i - 1);
- break;
+ String token = (String)list.get(i);
+
+ strBuf.append((i > 0 ? " " : "") + token);
}
-
- for (i = 0; i < arrayDim; i++)
- classNameBuf.append("[]");
-
- return classNameBuf.toString();
- }
+ return strBuf.toString();
+ }
+ else
+ {
+ return null;
+ }
+ }
}
Modified:
incubator/woden/java/src/org/apache/woden/internal/util/dom/DOMUtils.java
URL:
http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/util/dom/DOMUtils.java?rev=292208&r1=292207&r2=292208&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/util/dom/DOMUtils.java
(original)
+++ incubator/woden/java/src/org/apache/woden/internal/util/dom/DOMUtils.java
Wed Sep 28 08:17:44 2005
@@ -2,13 +2,21 @@
* (c) Copyright IBM Corp 2001, 2005
*/
-package com.ibm.wsdl.util.xml;
+package org.apache.woden.internal.util.dom;
-import java.io.*;
-import java.util.*;
-import org.w3c.dom.*;
-import javax.wsdl.*;
-import javax.xml.namespace.*;
+import java.io.PrintWriter;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Vector;
+
+import javax.xml.namespace.QName;
+
+import org.apache.woden.WSDLException;
+import org.w3c.dom.Attr;
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
public class DOMUtils {
/**
@@ -272,7 +280,8 @@
return null;
}
-
+
+ /*
public static QName getQName(String prefixedValue,
Element contextEl,
Definition def)
@@ -307,7 +316,8 @@
throw wsdlExc;
}
}
-
+ */
+ /*
public static void registerUniquePrefix(String prefix,
String namespaceURI,
Definition def)
@@ -333,6 +343,7 @@
* because it does not track the remaining attributes to test for unexpected
* attributes.
*/
+ /*
public static QName getQualifiedAttributeValue(Element el,
String attrName,
String elDesc,
@@ -363,12 +374,14 @@
return null;
}
}
+ /*
/**
* This method should be used for elements that do not support extension
attributes
* because it tracks the remaining attributes so that eventually any
* unexpected attributes can be identified.
*/
+ /*
public static QName getQualifiedAttributeValue(Element el,
String attrName,
String elDesc,
@@ -402,6 +415,7 @@
return null;
}
}
+ */
public static void throwWSDLException(Element location) throws WSDLException
{
@@ -441,6 +455,7 @@
throw wsdlExc;
}
+ /*
public static void printAttribute(String name,
String value,
PrintWriter pw)
@@ -450,10 +465,12 @@
pw.print(' ' + name + "=\"" + cleanString(value) + '\"');
}
}
+ */
/**
* Prints attributes with qualified names.
*/
+ /*
public static void printQualifiedAttribute(QName name,
String value,
Definition def,
@@ -606,5 +623,7 @@
return strBuf.toString();
}
+ */
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]