You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2015/11/17 00:47:53 UTC
svn commit: r1714714 - in
/webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype:
TypeHelper.java xsd/AbstractWhitespaceCollapsingInvariantType.java
xsd/TemporalType.java xsd/Util.java xsd/XSQNameTypeImpl.java
Author: veithen
Date: Mon Nov 16 23:47:53 2015
New Revision: 1714714
URL: http://svn.apache.org/viewvc?rev=1714714&view=rev
Log:
Simplify the handling of XSD datatypes with whiteSpace=collapse.
Added:
webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/TypeHelper.java
- copied, changed from r1714491, webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/Util.java
Removed:
webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/AbstractWhitespaceCollapsingInvariantType.java
webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/Util.java
Modified:
webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/TemporalType.java
webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java
Copied: webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/TypeHelper.java (from r1714491, webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/Util.java)
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/TypeHelper.java?p2=webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/TypeHelper.java&p1=webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/Util.java&r1=1714491&r2=1714714&rev=1714714&view=diff
==============================================================================
--- webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/Util.java (original)
+++ webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/TypeHelper.java Mon Nov 16 23:47:53 2015
@@ -16,12 +16,73 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.axiom.datatype.xsd;
+package org.apache.axiom.datatype;
-final class Util {
- private Util() {}
+/**
+ * Contains utility methods for usage by {@link Type} implementations.
+ */
+public final class TypeHelper {
+ private TypeHelper() {}
- static boolean isWhitespace(char c) {
+ /**
+ * Determine if the given character is whitespace according to the XML specification.
+ *
+ * @param c
+ * the character to examine
+ * @return {@code true} if the character is whitespace, {@code false} otherwise
+ */
+ public static boolean isWhitespace(char c) {
return c == ' ' || c == '\r' || c == '\n' || c == '\t';
}
+
+ /**
+ * Determine the index of the first non whitespace character in the given literal. This method
+ * is intended for use in implementations of XSD datatypes for which the {@code whiteSpace}
+ * facet is {@code collapse}.
+ *
+ * @param literal
+ * the literal
+ * @return the index of the first non whitespace character
+ * @throws UnexpectedEndOfStringException
+ * if the literal is empty or contains only whitespace characters
+ */
+ public static int getStartIndex(String literal) throws UnexpectedEndOfStringException {
+ final int len = literal.length();
+ if (len == 0) {
+ throw new UnexpectedEndOfStringException(literal);
+ }
+ int start = 0;
+ while (TypeHelper.isWhitespace(literal.charAt(start))) {
+ if (++start == len) {
+ throw new UnexpectedEndOfStringException(literal);
+ }
+ }
+ return start;
+ }
+
+ /**
+ * Determine the index following the last non whitespace character in the given literal. This
+ * method is intended for use in conjunction with {@link #getStartIndex(String)}.
+ *
+ * @param literal
+ * the literal
+ * @return the index following the last non whitespace character
+ * @throws UnexpectedEndOfStringException
+ * if the literal is empty or contains only whitespace characters (Note that this
+ * means that the order in which {@link #getStartIndex(String)} and
+ * {@link #getEndIndex(String)} are called is not important)
+ */
+ public static int getEndIndex(String literal) throws UnexpectedEndOfStringException {
+ final int len = literal.length();
+ if (len == 0) {
+ throw new UnexpectedEndOfStringException(literal);
+ }
+ int end = len;
+ while (TypeHelper.isWhitespace(literal.charAt(end-1))) {
+ if (--end == 0) {
+ throw new UnexpectedEndOfStringException(literal);
+ }
+ }
+ return end;
+ }
}
Modified: webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/TemporalType.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/TemporalType.java?rev=1714714&r1=1714713&r2=1714714&view=diff
==============================================================================
--- webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/TemporalType.java (original)
+++ webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/TemporalType.java Mon Nov 16 23:47:53 2015
@@ -20,19 +20,21 @@ package org.apache.axiom.datatype.xsd;
import java.text.ParseException;
+import org.apache.axiom.datatype.AbstractInvariantType;
+import org.apache.axiom.datatype.TypeHelper;
import org.apache.axiom.datatype.UnexpectedCharacterException;
import org.apache.axiom.datatype.UnexpectedEndOfStringException;
-abstract class TemporalType<T> extends AbstractWhitespaceCollapsingInvariantType<T> {
+abstract class TemporalType<T> extends AbstractInvariantType<T> {
abstract boolean hasDatePart();
abstract boolean hasTimePart();
abstract T createInstance(boolean bc, String aeon, int year, int month, int day, int hour,
int minute, int second, int nanoSecond, String nanoSecondFraction,
SimpleTimeZone timeZone);
- @Override
- protected final T parse(String literal, int begin, int end) throws ParseException {
- int index = begin;
+ public final T parse(String literal) throws ParseException {
+ final int end = TypeHelper.getEndIndex(literal);
+ int index = TypeHelper.getStartIndex(literal);
boolean bc;
String aeon;
int year;
Modified: webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java?rev=1714714&r1=1714713&r2=1714714&view=diff
==============================================================================
--- webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java (original)
+++ webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java Mon Nov 16 23:47:53 2015
@@ -23,43 +23,24 @@ import java.text.ParseException;
import javax.xml.namespace.QName;
import org.apache.axiom.datatype.ContextAccessor;
+import org.apache.axiom.datatype.TypeHelper;
import org.apache.axiom.datatype.UnexpectedCharacterException;
-import org.apache.axiom.datatype.UnexpectedEndOfStringException;
final class XSQNameTypeImpl implements XSQNameType {
public <S,O> QName parse(String literal, ContextAccessor<S,O> contextAccessor, S contextObject, O options)
throws ParseException {
- int len = literal.length();
- int start = -1;
- int end = -1;
+ final int start = TypeHelper.getStartIndex(literal);
+ final int end = TypeHelper.getEndIndex(literal);
int colonIndex = -1;
- for (int index = 0; index<len; index++) {
- char c = literal.charAt(index);
- if (Util.isWhitespace(c)) {
- if (start != -1 && end == -1) {
- end = index;
- }
- } else {
- if (start == -1) {
- start = index;
- } else if (end != -1) {
+ for (int index = start; index<end; index++) {
+ // TODO: we should check that the literal is a valid NCName
+ if (literal.charAt(index) == ':') {
+ if (colonIndex != -1) {
throw new UnexpectedCharacterException(literal, index);
}
- // TODO: we should check that the literal is a valid NCName
- if (literal.charAt(index) == ':') {
- if (colonIndex != -1) {
- throw new UnexpectedCharacterException(literal, index);
- }
- colonIndex = index;
- }
+ colonIndex = index;
}
}
- if (start == -1) {
- throw new UnexpectedEndOfStringException(literal);
- }
- if (end == -1) {
- end = len;
- }
String prefix;
String localPart;
if (colonIndex == -1) {