axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: ws-axis/java/src/org/apache/axis/i18n resource.properties
Date Mon, 29 Nov 2004 20:54:55 GMT
dims        2004/11/29 12:54:55

  Modified:    java/src/org/apache/axis/types Duration.java
               java/src/org/apache/axis/i18n resource.properties
  Log:
  Trying to get rid of JDK1.4 dependency.
  
  Revision  Changes    Path
  1.11      +41 -5     ws-axis/java/src/org/apache/axis/types/Duration.java
  
  Index: Duration.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/types/Duration.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Duration.java	27 Nov 2004 21:08:12 -0000	1.10
  +++ Duration.java	29 Nov 2004 20:54:55 -0000	1.11
  @@ -17,8 +17,11 @@
   package org.apache.axis.types;
   
   import org.apache.axis.utils.Messages;
  +import org.apache.axis.utils.ClassUtils;
   
   import java.util.Calendar;
  +import java.lang.reflect.Method;
  +import java.lang.reflect.Constructor;
   
   /**
    * Implementation of the XML Schema type duration. Duration supports a minimum
  @@ -68,7 +71,7 @@
        * PnYnMnDTnHnMnS.
        *
        * @param duration String
  -     * @throws SchemaException if the string doesn't parse correctly.
  +     * @throws IllegalArgumentException if the string doesn't parse correctly.
        */
       public Duration(String duration) throws IllegalArgumentException {
           int position = 1;
  @@ -83,12 +86,12 @@
           // if does not have time
           if (duration.indexOf("T") == -1) {
               // no time information
  -            if (!duration.matches("-?P[0-9]*Y?[0-9]*M?[0-9]*D?")) {
  +            if (!matches(duration, "-?P[0-9]*Y?[0-9]*M?[0-9]*D?")) {
                   throw new IllegalArgumentException(
                           Messages.getMessage("badDuration"));
               }
           } else {
  -            if (!duration.matches(
  +            if (!matches(duration,
                       "-?P[0-9]*Y?[0-9]*M?[0-9]*D?T[0-9]*H?[0-9]*M?[0-9]*\\.?[0-9]*S?"))
{
                   throw new IllegalArgumentException(
                           Messages.getMessage("badDuration"));
  @@ -156,7 +159,7 @@
        */
       public void parseTime(String time) throws IllegalArgumentException {
           if (time.length() == 0 ||
  -            !time.matches("[0-9]*H?[0-9]*M?[0-9]*\\.?[0-9]*S?")) {
  +            !matches(time,"[0-9]*H?[0-9]*M?[0-9]*\\.?[0-9]*S?")) {
               throw new IllegalArgumentException(
                       Messages.getMessage("badTimeDuration"));
           }
  @@ -194,7 +197,7 @@
        * {@link #Duration(String) Duration(String)} constructor.
        */
       public void parseDate(String date) throws IllegalArgumentException {
  -        if (date.length() == 0 || !date.matches("[0-9]*Y?[0-9]*M?[0-9]*D?")) {
  +        if (date.length() == 0 || !matches(date, "[0-9]*Y?[0-9]*M?[0-9]*D?")) {
               throw new IllegalArgumentException(Messages.getMessage(
                       "badDateDuration"));
           }
  @@ -379,6 +382,39 @@
           return duration.toString();
       }
   
  +    /**
  +     * Matches the pattern specified in the string
  +     * 
  +     * @param string
  +     * @param regexp
  +     * @return boolean
  +     */ 
  +    private boolean matches(String string, String regexp) {
  +        try {
  +            Method method = String.class.getMethod("matches", new Class[]{String.class});
  +            Boolean b = (Boolean) method.invoke(string, new Object[]{regexp});
  +            return b.booleanValue();
  +        } catch (Throwable e) {
  +        }        
  +        try {
  +            Class clazz = ClassUtils.forName("org.apache.regexp.RE");
  +            Constructor constructor = clazz.getConstructor(new Class[]{String.class});
  +            Object obj = constructor.newInstance(new Object[]{regexp});
  +            Method method = clazz.getMethod("match", new Class[]{String.class});
  +            Boolean b = (Boolean) method.invoke(obj, new Object[]{regexp});
  +            return b.booleanValue();
  +        } catch (Throwable e){
  +        }
  +        try {
  +            Class clazz = ClassUtils.forName("org.apache.xerces.impl.xpath.regex.REUtil");
  +            Method method = clazz.getMethod("matches", new Class[]{String.class,String.class});
  +            Boolean b = (Boolean) method.invoke(string, new Object[]{regexp, string});
  +            return b.booleanValue();
  +        } catch (Throwable e){
  +        }
  +        throw new RuntimeException(Messages.getMessage("regexpFailure00"));
  +    }
  +    
       /**
        * The equals method compares the time represented by duration object, not
        * its string representation.
  
  
  
  1.101     +1 -0      ws-axis/java/src/org/apache/axis/i18n/resource.properties
  
  Index: resource.properties
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/i18n/resource.properties,v
  retrieving revision 1.100
  retrieving revision 1.101
  diff -u -r1.100 -r1.101
  --- resource.properties	27 Nov 2004 21:08:12 -0000	1.100
  +++ resource.properties	29 Nov 2004 20:54:55 -0000	1.101
  @@ -1256,3 +1256,4 @@
   Registrar.cantregister=Unable to initialize commons-modeler Registry.
   
   optionJaxrpc=Maps XML Schema types to Java types instead of the custom Axis types in org.apache.axis.types,
according to JAX-RPC 1.1.
  +regexpFailure00=Unable to run regexp
  \ No newline at end of file
  
  
  

Mime
View raw message