axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ow...@apache.org
Subject cvs commit: xml-axis-wsif/java/src/org/apache/wsif/util WSIFUtils.java
Date Fri, 26 Jul 2002 10:28:36 GMT
owenb       2002/07/26 03:28:35

  Modified:    java/src/org/apache/wsif/util WSIFUtils.java
  Log:
  - Updated code for java->xsd mappings to conform to latest JAX-RPC spec
  - Formatted code
  
  Revision  Changes    Path
  1.11      +129 -46   xml-axis-wsif/java/src/org/apache/wsif/util/WSIFUtils.java
  
  Index: WSIFUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/util/WSIFUtils.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- WSIFUtils.java	19 Jul 2002 15:46:30 -0000	1.10
  +++ WSIFUtils.java	26 Jul 2002 10:28:35 -0000	1.11
  @@ -115,6 +115,7 @@
    * @author Ant Elder <antelder@apache.org>
    * @author Jeremy Hughes <hughesj@apache.org>
    * @author Mark Whitlock <whitlock@apache.org>
  + * @author Piotr Przybylski
    */
   public class WSIFUtils {
       private static Class initContextClass;
  @@ -125,14 +126,19 @@
       private static final String PHYSICALREP = "physicalrep/";
       private static final String FORMATBINDING = "formatbinding/";
       private static final String XMLSEPARATORS =
  -        "\u002D\u002E\u003A\u005F\u00B7\u0387\u06DD\u06DE";
  -
  +        "\u002D\u002E\u003A\u00B7\u0387\u06DD\u06DE";
  +    private static final String XMLSEPARATORS_NODOT =
  +        "\u002D\u003A\u00B7\u0387\u06DD\u06DE";
  +    private static final String UNDERSCORE = "_";
  +    private static final String WWW = "www";
       private static final String lookupPrefix = "java:comp/env/";
       private static final String emptyString = "";
  +    
       private static Boolean providersInitialized = new Boolean(false);
       private static Boolean simpleTypesMapCreated = new Boolean(false);
       private static HashMap simpleTypesMap = new HashMap();
  -
  +	private static HashMap keywordMap = null;
  +    
       /**
        * This checks whether JNDI classes are available at runtime.
        * If the return value is true, then generated stubs should
  @@ -150,7 +156,7 @@
                           true,
                           Thread.currentThread().getContextClassLoader());
                   } catch (Throwable ignored) {
  -                	Trc.exception(ignored);
  +                    Trc.exception(ignored);
                   }
                   return null;
               }
  @@ -206,7 +212,7 @@
               Method m = initContextClass.getMethod("lookup", lookupSig);
               ws = (WSIFService) m.invoke(ic, lookupArgs);
           } catch (Exception e) {
  -        	Trc.exception(e);
  +            Trc.exception(e);
               throw new WSIFException(
                   "Exception while looking up JNDI factory: " + e.getMessage(),
                   e);
  @@ -504,7 +510,8 @@
           WSDLReader wsdlReader = factory.newWSDLReader();
           wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
           try {
  -            WSIFWSDLLocatorImpl lo = new WSIFWSDLLocatorImpl(documentBase, reader, cl);
  +            WSIFWSDLLocatorImpl lo =
  +                new WSIFWSDLLocatorImpl(documentBase, reader, cl);
               Definition def = wsdlReader.readWSDL(lo);
   
               if (oldPropValue != null) {
  @@ -726,7 +733,7 @@
           try {
               def = WSIFUtils.readWSDL(contextURL, location);
           } catch (WSDLException e) {
  -        	Trc.exception(e);
  +            Trc.exception(e);
               throw new WSIFException("Problem reading WSDL document.", e);
           }
           Trc.exitExpandWsdl(def);
  @@ -746,7 +753,7 @@
           try {
               def = WSIFUtils.readWSDL(contextURL, new StringReader(content));
           } catch (WSDLException e) {
  -        	Trc.exception(e);
  +            Trc.exception(e);
               throw new WSIFException("Problem reading WSDL document.", e);
           }
           Trc.exitExpandWsdl(def);
  @@ -767,33 +774,36 @@
               }
           }
       }
  -    
  +
       /**
        * Create a map of all schema simple types and there Java equivalents.
        */
       public static void createSimpleTypesMap() {
           synchronized (simpleTypesMapCreated) {
               if (!simpleTypesMapCreated.booleanValue()) {
  -                new Schema2Java(WSIFConstants.NS_URI_1999_SCHEMA_XSD).getRegistry(
  +                new Schema2Java(
  +                    WSIFConstants.NS_URI_1999_SCHEMA_XSD).getRegistry(
                       simpleTypesMap);
  -                new Schema2Java(WSIFConstants.NS_URI_2000_SCHEMA_XSD).getRegistry(
  +                new Schema2Java(
  +                    WSIFConstants.NS_URI_2000_SCHEMA_XSD).getRegistry(
                       simpleTypesMap);
  -                new Schema2Java(WSIFConstants.NS_URI_2001_SCHEMA_XSD).getRegistry(
  +                new Schema2Java(
  +                    WSIFConstants.NS_URI_2001_SCHEMA_XSD).getRegistry(
                       simpleTypesMap);
                   simpleTypesMapCreated = new Boolean(true);
               }
  -        }        
  +        }
       }
   
       /**
        * Get a map of all schema simple types and there Java equivalents.
        * @return The map of simple types
  -     */    
  +     */
       public static Map getSimpleTypesMap() {
  -    	if (!simpleTypesMapCreated.booleanValue()) {
  -    		createSimpleTypesMap();
  -    	}
  -    	return simpleTypesMap;
  +        if (!simpleTypesMapCreated.booleanValue()) {
  +            createSimpleTypesMap();
  +        }
  +        return simpleTypesMap;
       }
   
       // the following code copied from JCAUtils
  @@ -839,7 +849,7 @@
                       .loadClass(formatHandlerShortName + FORMAT_HANDLER)
                       .newInstance();
           } catch (ClassNotFoundException exn1) {
  -        	Trc.exception(exn1);
  +            Trc.exception(exn1);
               try {
                   ClassLoader cl = Thread.currentThread().getContextClassLoader();
                   formatHandler =
  @@ -848,14 +858,14 @@
                               formatHandlerShortName + ELEMENT_FORMAT_HANDLER)
                           .newInstance();
               } catch (ClassNotFoundException exn2) {
  -  	        	Trc.exception(exn2);
  +                Trc.exception(exn2);
                   try {
                       formatHandler =
                           (WSIFFormatHandler) Class
                               .forName(formatHandlerShortName + FORMAT_HANDLER)
                               .newInstance();
                   } catch (ClassNotFoundException exn3) {
  -		        	Trc.exception(exn3);
  +                    Trc.exception(exn3);
                       //try {
                       formatHandler =
                           (WSIFFormatHandler) Class
  @@ -896,12 +906,14 @@
   
                   // Turn segment into a valid package segment name
                   name = getPackageNameFromXMLName((String) segments.get(i));
  -
  +                if (name.startsWith(WWW))
  +                    name = name.substring(3);
                   // Reverse its components
                   StringTokenizer tokenizer = new StringTokenizer(name, ".");
                   List host = new ArrayList();
                   for (; tokenizer.hasMoreTokens();) {
  -                    host.add(0, tokenizer.nextToken());
  +                    String nextT = tokenizer.nextToken();
  +                    host.add(0, nextT);
                   }
                   StringBuffer buffer = new StringBuffer();
                   for (Iterator hi = host.iterator(); hi.hasNext();) {
  @@ -910,7 +922,9 @@
                       String nextSegment = (String) hi.next();
                       if (!Character
                           .isJavaIdentifierStart(nextSegment.toCharArray()[0]))
  -                        nextSegment = "_" + nextSegment;
  +                        nextSegment = UNDERSCORE + nextSegment;
  +                    if (isJavaKeyword(nextSegment))
  +                        nextSegment = UNDERSCORE + nextSegment;
                       buffer.append(nextSegment);
                   }
                   name = buffer.toString();
  @@ -918,8 +932,6 @@
   
                   // Turn segment into a valid java name
                   name = getJavaNameFromXMLName((String) segments.get(i));
  -                if (!Character.isJavaIdentifierStart(name.toCharArray()[0]))
  -                    name = "_" + name;
   
               }
   
  @@ -931,7 +943,7 @@
               packageNameBuffer.append(name);
           }
           Trc.exit(packageNameBuffer.toString());
  -        return packageNameBuffer.toString();
  +        return packageNameBuffer.toString().toLowerCase();
       }
   
       public static String getJavaNameFromXMLName(
  @@ -945,17 +957,16 @@
           }
           String result = buffer.toString();
           if (!Character.isJavaIdentifierStart(result.toCharArray()[0]))
  -            result = "_" + result;
  +            result = UNDERSCORE + result;
  +        if (isJavaKeyword(result))
  +            result = UNDERSCORE + result;
           Trc.exit(result);
           return result;
       }
   
       public static String getJavaNameFromXMLName(String xmlName) {
           Trc.entry(null, xmlName);
  -        String s =
  -            getJavaNameFromXMLName(
  -                xmlName,
  -                "\u002D\u002E\u003A\u005F\u00B7\u0387\u06DD\u06DE");
  +        String s = getJavaNameFromXMLName(xmlName, XMLSEPARATORS);
           Trc.exit(s);
           return s;
       }
  @@ -964,14 +975,11 @@
           Trc.entry(null, xmlName);
   
           // Tokenize, don't consider '.' as a delimiter here
  -        String name =
  -            getJavaNameFromXMLName(
  -                xmlName,
  -                "\u002D\u003A\u005F\u00B7\u0387\u06DD\u06DE");
  +        String name = getJavaNameFromXMLName(xmlName, XMLSEPARATORS_NODOT);
   
           // Tokenize using delimiter '.' and add the tokens separated by '.'
           // This is to ensure that we have no heading/trailing/dup '.' in the string
  -        StringTokenizer tokenizer = new StringTokenizer(name, ".");
  +        StringTokenizer tokenizer = new StringTokenizer(name, DOT);
           StringBuffer buffer = new StringBuffer();
           for (; tokenizer.hasMoreTokens();) {
               if (buffer.length() != 0)
  @@ -979,14 +987,16 @@
               // -->				
               String nextSegment = (String) tokenizer.nextToken();
               if (!Character.isJavaIdentifierStart(nextSegment.toCharArray()[0]))
  -                nextSegment = "_" + nextSegment;
  +                nextSegment = UNDERSCORE + nextSegment;
  +            if (isJavaKeyword(nextSegment))
  +                nextSegment = UNDERSCORE + nextSegment;
               buffer.append(nextSegment);
   
               //			buffer.append(tokenizer.nextToken());
               // <--				
           }
           Trc.exit(buffer.toString());
  -        return buffer.toString();
  +        return buffer.toString().toLowerCase();
       }
   
       private static List getNamespaceURISegments(String namespaceURI) {
  @@ -1006,7 +1016,7 @@
                   if (segments.get(0).equals(url.getProtocol()))
                       segments.remove(0);
               } catch (MalformedURLException exn) {
  -	        	Trc.exception(exn);
  +                Trc.exception(exn);
               }
           }
           Trc.exit(segments);
  @@ -1100,10 +1110,7 @@
   
       public static String getJavaClassNameFromXMLName(String xmlName) {
           Trc.entry(null, xmlName);
  -        String s =
  -            getJavaClassNameFromXMLName(
  -                xmlName,
  -                "\u002D\u002E\u003A\u005F\u00B7\u0387\u06DD\u06DE");
  +        String s = getJavaClassNameFromXMLName(xmlName, XMLSEPARATORS);
           Trc.exit(s);
           return s;
       }
  @@ -1125,8 +1132,84 @@
           }
           String result = buffer.toString();
           if (!Character.isJavaIdentifierStart(result.toCharArray()[0]))
  -            result = "_" + result;
  +            result = UNDERSCORE + result;
           Trc.exit(result);
  -        return result;
  +        if (isJavaKeyword(result))
  +            return UNDERSCORE + result;
  +        else
  +            return result;
  +    }
  +    
  +    private static boolean isJavaKeyword(String identifier) {
  +        if (keywordMap == null) {
  +            Object value = new Object();
  +            keywordMap = new HashMap();
  +            keywordMap.put("abstract", value);
  +            keywordMap.put("default", value);
  +            keywordMap.put("if", value);
  +            keywordMap.put("private", value);
  +            keywordMap.put("this", value);
  +            keywordMap.put("boolean", value);
  +            keywordMap.put("do", value);
  +            keywordMap.put("implements", value);
  +            keywordMap.put("protected", value);
  +            keywordMap.put("throw", value);
  +            keywordMap.put("break", value);
  +            keywordMap.put("double", value);
  +            keywordMap.put("import", value);
  +            keywordMap.put("public", value);
  +            keywordMap.put("throws", value);
  +            keywordMap.put("byte", value);
  +            keywordMap.put("else", value);
  +            keywordMap.put("instanceof", value);
  +            keywordMap.put("return", value);
  +            keywordMap.put("transient", value);
  +            keywordMap.put("case", value);
  +            keywordMap.put("extends", value);
  +            keywordMap.put("int", value);
  +            keywordMap.put("short", value);
  +            keywordMap.put("try", value);
  +            keywordMap.put("catch", value);
  +            keywordMap.put("final", value);
  +            keywordMap.put("interface", value);
  +            keywordMap.put("static", value);
  +            keywordMap.put("void", value);
  +            keywordMap.put("char", value);
  +            keywordMap.put("finally", value);
  +            keywordMap.put("long", value);
  +            keywordMap.put("strictfp", value);
  +            keywordMap.put("volatile", value);
  +            keywordMap.put("class", value);
  +            keywordMap.put("float", value);
  +            keywordMap.put("native", value);
  +            keywordMap.put("super", value);
  +            keywordMap.put("while", value);
  +            keywordMap.put("const", value);
  +            keywordMap.put("for", value);
  +            keywordMap.put("new", value);
  +            keywordMap.put("switch", value);
  +            keywordMap.put("continue", value);
  +            keywordMap.put("goto", value);
  +            keywordMap.put("package", value);
  +            keywordMap.put("synchronized", value);
  +            keywordMap.put("null", value);
  +            keywordMap.put("true", value);
  +            keywordMap.put("false", value);
  +            keywordMap.put("assert", value);
  +        }
  +        return keywordMap.containsKey(identifier);
  +
  +        //	abstract    default    if            private      this
  +        //	boolean     do         implements    protected    throw
  +        //	break       double     import        public       throws
  +        //	byte        else       instanceof    return       transient
  +        //	case        extends    int           short        try
  +        //	catch       final      interface     static       void
  +        //	char        finally    long          strictfp     volatile
  +        //	class       float      native        super        while
  +        //	const       for        new           switch
  +        //	continue    goto       package       synchronized
  +        //  null        true       false         assert
       }
  +
   }
  
  
  

Mime
View raw message