You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ve...@apache.org on 2009/06/30 23:14:25 UTC

svn commit: r789958 - in /webservices/axis2/trunk/java/modules: adb-codegen/src/org/apache/axis2/schema/ codegen/src/org/apache/axis2/wsdl/codegen/

Author: veithen
Date: Tue Jun 30 21:14:25 2009
New Revision: 789958

URL: http://svn.apache.org/viewvc?rev=789958&view=rev
Log:
Some more Java 5 stuff.

Modified:
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/ExtensionUtility.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodegenConfigLoader.java

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/ExtensionUtility.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/ExtensionUtility.java?rev=789958&r1=789957&r2=789958&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/ExtensionUtility.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/ExtensionUtility.java Tue Jun 30 21:14:25 2009
@@ -67,17 +67,16 @@
 
 
     public static void invoke(CodeGenConfiguration configuration) throws Exception {
-        List schemaList = new ArrayList();
+        List<XmlSchema> schemaList = new ArrayList<XmlSchema>();
         // add all the schemas to the list
-        List services = configuration.getAxisServices();
-        for (Iterator iter = services.iterator();iter.hasNext();){
-            schemaList.addAll(((AxisService)iter.next()).getSchema());
+        for (AxisService service : configuration.getAxisServices()) {
+            schemaList.addAll(service.getSchema());
         }
 
         //hashmap that keeps the targetnamespace and the xmlSchema object
         //this is a convenience to locate the relevant schema quickly
         //by looking at the target namespace
-        Map schemaMap = new HashMap();
+        Map<String,XmlSchema> schemaMap = new HashMap<String,XmlSchema>();
         populateSchemaMap(schemaMap, schemaList);
 
         if (schemaList == null || schemaList.isEmpty()) {
@@ -119,12 +118,8 @@
 
         if (options.isWriteOutput()) {
             //get the processed element map and transfer it to the type mapper
-            Map processedMap = schemaCompiler.getProcessedElementMap();
-            Iterator processedkeys = processedMap.keySet().iterator();
-            QName qNameKey;
-            while (processedkeys.hasNext()) {
-                qNameKey = (QName) processedkeys.next();
-                mapper.addTypeMappingName(qNameKey, processedMap.get(qNameKey).toString());
+            for (Map.Entry<QName,String> entry : schemaCompiler.getProcessedElementMap().entrySet()) {
+                mapper.addTypeMappingName(entry.getKey(), entry.getValue());
             }
 
         } else {
@@ -139,11 +134,8 @@
                 mapper.addTypeMappingObject(qNameKey, processedModelMap.get(qNameKey));
             }
 
-            Map processedMap = schemaCompiler.getProcessedElementMap();
-            processedkeys = processedMap.keySet().iterator();
-            while (processedkeys.hasNext()) {
-                qNameKey = (QName) processedkeys.next();
-                mapper.addTypeMappingName(qNameKey, processedMap.get(qNameKey).toString());
+            for (Map.Entry<QName,String> entry : schemaCompiler.getProcessedElementMap().entrySet()) {
+                mapper.addTypeMappingName(entry.getKey(), entry.getValue());
             }
 
             //get the ADB template from the schema compilers property bag and set the
@@ -157,13 +149,10 @@
         //process the unwrapped parameters
         if (!configuration.isParametersWrapped()) {
             //figure out the unwrapped operations
-            List axisServices = configuration.getAxisServices();
-            AxisService axisService;
-            for (Iterator servicesIter = axisServices.iterator(); servicesIter.hasNext();) {
-                axisService = (AxisService) servicesIter.next();
-                for (Iterator operations = axisService.getOperations();
+            for (AxisService axisService : configuration.getAxisServices()) {
+                for (Iterator<AxisOperation> operations = axisService.getOperations();
                      operations.hasNext();) {
-                    AxisOperation op = (AxisOperation) operations.next();
+                    AxisOperation op = operations.next();
                     if (WSDLUtil.isInputPresentForMEP(op.getMessageExchangePattern())) {
                         walkSchema(op.getMessage(
                                 WSDLConstants.MESSAGE_LABEL_IN_VALUE),
@@ -193,14 +182,11 @@
         //put the complext types for the top level elements having them
         // this is needed in unwrapping and to provide backwordCompatibility
         if (!configuration.isParametersWrapped() || configuration.isBackwordCompatibilityMode()) {
-            List axisServices = configuration.getAxisServices();
-            AxisService axisService;
-            for (Iterator servicesIter = axisServices.iterator(); servicesIter.hasNext();) {
-                axisService = (AxisService) servicesIter.next();
+            for (AxisService axisService : configuration.getAxisServices()) {
                 AxisOperation axisOperation;
                 AxisMessage axisMessage;
-                for (Iterator operators = axisService.getOperations(); operators.hasNext();) {
-                    axisOperation = (AxisOperation) operators.next();
+                for (Iterator<AxisOperation> operators = axisService.getOperations(); operators.hasNext();) {
+                    axisOperation = operators.next();
                     if (WSDLUtil.isInputPresentForMEP(axisOperation.getMessageExchangePattern())) {
                         axisMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
                         setComplexTypeName(axisMessage);
@@ -237,10 +223,7 @@
                     // now we need to get the schema of the extension type from the parent schema. For that let's first retrieve
                     // the parent schema
                     AxisService axisService = axisMessage.getAxisOperation().getAxisService();
-                    ArrayList schemasList = axisService.getSchema();
-                    XmlSchema schema = null;
-                    for (Iterator iter = schemasList.iterator(); iter.hasNext();) {
-                        schema = (XmlSchema) iter.next();
+                    for (XmlSchema schema : axisService.getSchema()) {
                         schemaType = getSchemaType(schema, schemaTypeQname);
                         if (schemaType != null) {
                             break;
@@ -273,9 +256,8 @@
      * @param schemaMap
      * @param schemaList
      */
-    private static void populateSchemaMap(Map schemaMap, List schemaList) {
-        for (int i = 0; i < schemaList.size(); i++) {
-            XmlSchema xmlSchema = (XmlSchema) schemaList.get(i);
+    private static void populateSchemaMap(Map<String,XmlSchema> schemaMap, List<XmlSchema> schemaList) {
+        for (XmlSchema xmlSchema : schemaList) {
             schemaMap.put(xmlSchema.getTargetNamespace(), xmlSchema);
         }
     }
@@ -286,7 +268,7 @@
      */
     private static void walkSchema(AxisMessage message,
                                    TypeMapper mapper,
-                                   Map schemaMap,
+                                   Map<String,XmlSchema> schemaMap,
                                    String opName,
                                    String qnameSuffix) {
 
@@ -302,11 +284,7 @@
                     // now we need to get the schema of the extension type from the parent schema. For that let's first retrieve
                     // the parent schema
                     AxisService axisService = message.getAxisOperation().getAxisService();
-                    ArrayList schemasList = axisService.getSchema();
-
-                    XmlSchema schema = null;
-                    for (Iterator iter = schemasList.iterator(); iter.hasNext();) {
-                        schema = (XmlSchema) iter.next();
+                    for (XmlSchema schema : axisService.getSchema()) {
                         schemaType = getSchemaType(schema, schemaTypeQname);
                         if (schemaType != null) {
                             break;
@@ -411,7 +389,7 @@
     private static void processComplexContentModel(XmlSchemaComplexType cmplxType,
                                                    TypeMapper mapper,
                                                    String opName,
-                                                   Map schemaMap,
+                                                   Map<String,XmlSchema> schemaMap,
                                                    String qnameSuffix) {
         XmlSchemaContentModel contentModel = cmplxType.getContentModel();
         if (contentModel instanceof XmlSchemaComplexContent) {
@@ -423,10 +401,8 @@
                 // process particles inside this extension, if any
                 processSchemaSequence(schemaExtension.getParticle(), mapper, opName, schemaMap, qnameSuffix);
 
-                XmlSchema xmlSchema = null;
                  XmlSchemaType extensionSchemaType = null;
-                for (Iterator iter = schemaMap.values().iterator();iter.hasNext();){
-                    xmlSchema = (XmlSchema) iter.next();
+                for (XmlSchema xmlSchema : schemaMap.values()) {
                     extensionSchemaType = getSchemaType(xmlSchema,schemaExtension.getBaseTypeName());
                     if (extensionSchemaType != null){
                         break;
@@ -441,7 +417,7 @@
     private static void processSchemaSequence(XmlSchemaParticle particle,
                                               TypeMapper mapper,
                                               String opName,
-                                              Map schemaMap,
+                                              Map<String,XmlSchema> schemaMap,
                                               String qnameSuffix) {
         if (particle instanceof XmlSchemaSequence) {
             XmlSchemaObjectCollection items = ((XmlSchemaSequence) particle).getItems();
@@ -545,9 +521,9 @@
      * @param schemaMap
      * @return null if the schema is not found
      */
-    private static XmlSchemaType findSchemaType(Map schemaMap, QName schemaTypeName) {
+    private static XmlSchemaType findSchemaType(Map<String,XmlSchema> schemaMap, QName schemaTypeName) {
         //find the schema
-        XmlSchema schema = (XmlSchema) schemaMap.get(schemaTypeName.getNamespaceURI());
+        XmlSchema schema = schemaMap.get(schemaTypeName.getNamespaceURI());
         if (schema != null) {
             return schema.getTypeByName(schemaTypeName);
         }
@@ -560,7 +536,7 @@
      * @param options
      */
     private static void populateUserparameters(CompilerOptions options, CodeGenConfiguration configuration) {
-        Map propertyMap = configuration.getProperties();
+        Map<Object,Object> propertyMap = configuration.getProperties();
         if (propertyMap.containsKey(SchemaConstants.SchemaCompilerArguments.WRAP_SCHEMA_CLASSES)) {
             if (Boolean.valueOf(
                     propertyMap.get(SchemaConstants.SchemaCompilerArguments.WRAP_SCHEMA_CLASSES).toString()).
@@ -640,7 +616,7 @@
         /// these options need to be taken from the command line
         options.setOutputLocation(outputDir);
         options.setNs2PackageMap(configuration.getUri2PackageNameMap() == null ?
-                new HashMap() :
+                new HashMap<String,String>() :
                 configuration.getUri2PackageNameMap());
 
         //default setting is to set the wrap status depending on whether it's

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java?rev=789958&r1=789957&r2=789958&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java Tue Jun 30 21:14:25 2009
@@ -20,10 +20,12 @@
 package org.apache.axis2.wsdl.codegen;
 
 import org.apache.axis2.description.AxisService;
+import org.apache.axis2.util.CommandLineOption;
 import org.apache.axis2.util.CommandLineOptionConstants;
 import org.apache.axis2.util.URLProcessor;
 import org.apache.axis2.wsdl.databinding.TypeMapper;
 import org.apache.axis2.wsdl.util.ConfigPropertyFileLoader;
+import org.apache.ws.commons.schema.XmlSchema;
 
 import javax.wsdl.Definition;
 import java.io.File;
@@ -36,7 +38,7 @@
 public class CodeGenConfiguration implements CommandLineOptionConstants {
 
     /** Axis Services reference */
-    private List axisServices;
+    private List<AxisService> axisServices;
 
     /** Axis service to use */
     private AxisService axisService;
@@ -68,14 +70,14 @@
     }
 
     /** A map to keep the custom namespace and package name mappings */
-    private Map uri2PackageNameMap;
+    private Map<String,String> uri2PackageNameMap;
 
 
-    public Map getUri2PackageNameMap() {
+    public Map<String,String> getUri2PackageNameMap() {
         return uri2PackageNameMap;
     }
 
-    public void setUri2PackageNameMap(Map uri2PackageNameMap) {
+    public void setUri2PackageNameMap(Map<String,String> uri2PackageNameMap) {
         if (this.uri2PackageNameMap == null) {
             this.uri2PackageNameMap = uri2PackageNameMap;
         } else {
@@ -159,11 +161,11 @@
         this.baseURI = baseURI;
     }
 
-    public Map getConfigurationProperties() {
+    public Map<Object,Object> getConfigurationProperties() {
         return configurationProperties;
     }
 
-    public void setConfigurationProperties(Map configurationProperties) {
+    public void setConfigurationProperties(Map<Object,Object> configurationProperties) {
         this.configurationProperties = configurationProperties;
     }
 
@@ -269,7 +271,7 @@
     * A hashmap of properties that may be populated on the way. extensions can populate it
     * This can be used to keep non specific information
     */
-    private Map configurationProperties = new HashMap();
+    private Map<Object,Object> configurationProperties = new HashMap<Object,Object>();
 
 
     public boolean isGenerateAll() {
@@ -342,7 +344,7 @@
      *
      * @return Returns Map of all properties.
      */
-    public Map getProperties() {
+    public Map<Object,Object> getProperties() {
         return configurationProperties;
     }
 
@@ -375,10 +377,10 @@
      *
      * @param optionMap
      */
-    public CodeGenConfiguration(Map optionMap) {
+    public CodeGenConfiguration(Map<String,CommandLineOption> optionMap) {
         CodegenConfigLoader.loadConfig(this, optionMap);
-        this.axisServices = new ArrayList();
-        this.outputXmlFileNamesList = new ArrayList();
+        this.axisServices = new ArrayList<AxisService>();
+        this.outputXmlFileNamesList = new ArrayList<String>();
     }
 
 
@@ -461,11 +463,11 @@
         return repositoryPath;
     }
 
-    public List getAxisServices() {
+    public List<AxisService> getAxisServices() {
         return axisServices;
     }
 
-    public void setAxisServices(List axisServices) {
+    public void setAxisServices(List<AxisService> axisServices) {
         this.axisServices = axisServices;
     }
 
@@ -478,7 +480,7 @@
         if (axisService != null) {
             return axisService;
         } else if ((axisServices != null) && (axisServices.size() > 0)) {
-            return (AxisService)axisServices.get(0);
+            return axisServices.get(0);
         } else {
             return null;
         }
@@ -516,16 +518,14 @@
     public String getTargetNamespace() {
         String targetNamespace = null;
         if ((this.axisServices != null) && (this.axisServices.size() > 0)) {
-            targetNamespace = ((AxisService)this.axisServices.get(0)).getTargetNamespace();
+            targetNamespace = this.axisServices.get(0).getTargetNamespace();
         }
         return targetNamespace;
     }
 
-    public List getSchemaListForAllServices() {
-        List schemas = new ArrayList();
-        AxisService axisService;
-        for (Iterator iter = this.axisServices.iterator(); iter.hasNext();) {
-            axisService = (AxisService)iter.next();
+    public List<XmlSchema> getSchemaListForAllServices() {
+        List<XmlSchema> schemas = new ArrayList<XmlSchema>();
+        for (AxisService axisService : axisServices) {
             schemas.addAll(axisService.getSchema());
         }
         return schemas;
@@ -563,13 +563,13 @@
     }
 
     // this is used to keep the generated xml file list to pretty print.
-    private List outputXmlFileNamesList;
+    private List<String> outputXmlFileNamesList;
 
-    public List getOutputXmlFileNamesList() {
+    public List<String> getOutputXmlFileNamesList() {
         return outputXmlFileNamesList;
     }
 
-    public void setOutputXmlFileNamesList(List outputXmlFileNamesList) {
+    public void setOutputXmlFileNamesList(List<String> outputXmlFileNamesList) {
         this.outputXmlFileNamesList = outputXmlFileNamesList;
     }
 

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodegenConfigLoader.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodegenConfigLoader.java?rev=789958&r1=789957&r2=789958&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodegenConfigLoader.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodegenConfigLoader.java Tue Jun 30 21:14:25 2009
@@ -28,13 +28,12 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Properties;
 
 class CodegenConfigLoader implements CommandLineOptionConstants {
 
-    public static void loadConfig(CodeGenConfiguration config, Map optionMap) {
+    public static void loadConfig(CodeGenConfiguration config, Map<String,CommandLineOption> optionMap) {
         String outputLocation = "."; //default output directory is the current working directory
         CommandLineOption commandLineOption = loadOption(WSDL2JavaConstants.OUTPUT_LOCATION_OPTION,
                                                          WSDL2JavaConstants.OUTPUT_LOCATION_OPTION_LONG,
@@ -185,7 +184,7 @@
                     String valuepairs[] = value.split(",");
                     if (valuepairs.length > 0) {
                         //put them in the hash map
-                        HashMap map = new HashMap(valuepairs.length);
+                        HashMap<String,String> map = new HashMap<String,String>(valuepairs.length);
                         for (int i = 0; i < valuepairs.length; i++) {
                             String values[] = valuepairs[i].split("=");
                             if (values.length == 2) {
@@ -199,7 +198,11 @@
                     try {
                         Properties p = new Properties();//$NON-SEC-3
                         p.load(new FileInputStream(value));//$NON-SEC-2//$NON-SEC-3
-                        config.setUri2PackageNameMap(p);
+                        Map<String,String> map = new HashMap<String,String>();
+                        for (Map.Entry<Object,Object> entry : p.entrySet()) {
+                            map.put((String)entry.getKey(), (String)entry.getValue());
+                        }
+                        config.setUri2PackageNameMap(map);
                     } catch (IOException e) {
                         throw new RuntimeException(
                                 CodegenMessages.
@@ -314,14 +317,12 @@
 
         // loop through the map and find parameters having the extra prefix.
         //put them in the property map
-        Iterator keyIterator = optionMap.keySet().iterator();
-        while (keyIterator.hasNext()) {
-            Object key = keyIterator.next();
-            CommandLineOption option = (CommandLineOption)optionMap.get(key);
-            if (key.toString().startsWith(WSDL2JavaConstants.EXTRA_OPTIONTYPE_PREFIX)) {
+        for (Map.Entry<String,CommandLineOption> entry : optionMap.entrySet()) {
+            String key = entry.getKey();
+            if (key.startsWith(WSDL2JavaConstants.EXTRA_OPTIONTYPE_PREFIX)) {
                 //add this to the property map
-                config.getProperties().put(key.toString().replaceFirst(
-                        WSDL2JavaConstants.EXTRA_OPTIONTYPE_PREFIX, ""), option.getOptionValue());
+                config.getProperties().put(key.replaceFirst(
+                        WSDL2JavaConstants.EXTRA_OPTIONTYPE_PREFIX, ""), entry.getValue().getOptionValue());
             }
         }
 
@@ -329,17 +330,17 @@
     }
 
     private static CommandLineOption loadOption(String shortOption, String longOption,
-                                                Map options) {
+                                                Map<String,CommandLineOption> options) {
         //short option gets precedence
         CommandLineOption option = null;
         if (longOption != null) {
-            option = (CommandLineOption)options.get(longOption);
+            option = options.get(longOption);
             if (option != null) {
                 return option;
             }
         }
         if (shortOption != null) {
-            option = (CommandLineOption)options.get(shortOption);
+            option = options.get(shortOption);
         }
 
         return option;