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 di...@apache.org on 2006/10/24 22:25:04 UTC
svn commit: r467466 - in
/webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl:
Java2WSDLTask.java Mapper.java MappingSet.java NamespaceMapping.java
Author: dims
Date: Tue Oct 24 13:25:04 2006
New Revision: 467466
URL: http://svn.apache.org/viewvc?view=rev&rev=467466
Log:
Fix for AXIS2-1411 - Java2WSDL Task - missing options available in command line
Added:
webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Mapper.java
webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/MappingSet.java
webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/NamespaceMapping.java
Modified:
webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLTask.java
Modified: webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLTask.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLTask.java?view=diff&rev=467466&r1=467465&r2=467466
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLTask.java (original)
+++ webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLTask.java Tue Oct 24 13:25:04 2006
@@ -1,221 +1,384 @@
-package org.apache.ws.java2wsdl;
-
-import org.apache.tools.ant.AntClassLoader;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.types.Path;
-import org.apache.tools.ant.types.Reference;
-import org.apache.ws.java2wsdl.utils.Java2WSDLCommandLineOption;
-
-import java.util.HashMap;
-import java.util.Map;
-/*
-* Copyright 2004,2005 The Apache Software Foundation.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-*/
-
-public class Java2WSDLTask extends Task implements Java2WSDLConstants {
-
- private String className = null;
- private String outputLocation = null;
- private String targetNamespace = null;
- private String targetNamespacePrefix = null;
- private String schemaTargetNamespace = null;
- private String schemaTargetNamespacePrefix = null;
- private String serviceName = null;
- private String outputFileName = null;
- private Path classpath = null;
-
- /**
- *
- */
- public Java2WSDLTask() {
- super();
- }
-
- /**
- * Fills the option map. This map is passed onto
- * the code generation API to generate the code.
- */
- private Map fillOptionMap() {
- Map optionMap = new HashMap();
-
- // Check that critical options exist
- if (className == null) {
- throw new BuildException(
- "You must specify a classname");
- }
-
- ////////////////////////////////////////////////////////////////
-
- // Classname
- addToOptionMap(optionMap,
- Java2WSDLConstants.CLASSNAME_OPTION,
- className);
-
- // Output location
- addToOptionMap(optionMap,
- Java2WSDLConstants.OUTPUT_LOCATION_OPTION,
- outputLocation);
-
- // Target namespace
- addToOptionMap(optionMap,
- Java2WSDLConstants.TARGET_NAMESPACE_OPTION,
- targetNamespace);
-
- // Target namespace prefix
- addToOptionMap(optionMap,
- Java2WSDLConstants.TARGET_NAMESPACE_PREFIX_OPTION,
- targetNamespacePrefix);
-
- // Schema target namespace
- addToOptionMap(optionMap,
- Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_OPTION,
- schemaTargetNamespace);
-
- // Schema target namespace prefix
- addToOptionMap(optionMap,
- Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_PREFIX_OPTION,
- schemaTargetNamespacePrefix);
-
- // Service name
- addToOptionMap(optionMap,
- Java2WSDLConstants.SERVICE_NAME_OPTION,
- serviceName);
-
- // Output file name
- addToOptionMap(optionMap,
- Java2WSDLConstants.OUTPUT_FILENAME_OPTION,
- outputFileName);
-
- return optionMap;
- }
-
- /**
- * Utility method to convert a string into a single item string[]
- *
- * @param value
- * @return Returns String[].
- */
- private String[] getStringArray(String value) {
- String[] values = new String[1];
- values[0] = value;
- return values;
- }
-
- /**
- * Function to put arguments in the option map.
- * This functions skips adding of options that have a null value.
- *
- * @param map The option map into which the option is to be added
- * @param option The option name
- * @param value The value of the option
- */
- private void addToOptionMap(Map map, String option, String value) {
- if (value != null) {
- map.put(option,
- new Java2WSDLCommandLineOption(option, getStringArray(value)));
- }
- }
-
- public void execute() throws BuildException {
- try {
-
- Map commandLineOptions = this.fillOptionMap();
-
- AntClassLoader cl = new AntClassLoader(getClass().getClassLoader(),
- getProject(),
- classpath == null ? createClasspath() : classpath,
- false);
-
- commandLineOptions.put(Java2WSDLConstants.CLASSPATH_OPTION, new Java2WSDLCommandLineOption(Java2WSDLConstants.CLASSPATH_OPTION, classpath.list()));
-
- Thread.currentThread().setContextClassLoader(cl);
-
- if (outputLocation != null) cl.addPathElement(outputLocation);
-
- new Java2WSDLCodegenEngine(commandLineOptions).generate();
-
- } catch (Throwable e) {
- throw new BuildException(e);
- }
-
- }
-
- public void setClassName(String className) {
- this.className = className;
- }
-
- public void setOutputLocation(String outputLocation) {
- this.outputLocation = outputLocation;
- }
-
- public void setTargetNamespace(String targetNamespace) {
- this.targetNamespace = targetNamespace;
- }
-
- public void setTargetNamespacePrefix(String targetNamespacePrefix) {
- this.targetNamespacePrefix = targetNamespacePrefix;
- }
-
- public void setSchemaTargetNamespace(String schemaTargetNamespace) {
- this.schemaTargetNamespace = schemaTargetNamespace;
- }
-
- public void setSchemaTargetNamespacePrefix(String schemaTargetNamespacePrefix) {
- this.schemaTargetNamespacePrefix = schemaTargetNamespacePrefix;
- }
-
- public void setServiceName(String serviceName) {
- this.serviceName = serviceName;
- }
-
- public void setOutputFileName(String outputFileName) {
- this.outputFileName = outputFileName;
- }
-
- /**
- * Set the optional classpath
- *
- * @param classpath the classpath to use when loading class
- */
- public void setClasspath(Path classpath) {
- createClasspath().append(classpath);
- }
-
- /**
- * Set the optional classpath
- *
- * @return a path instance to be configured by the Ant core.
- */
- public Path createClasspath() {
- if (classpath == null) {
- classpath = new Path(getProject());
- classpath = classpath.concatSystemClasspath();
- }
- return classpath.createPath();
- }
-
- /**
- * Set the reference to an optional classpath
- *
- * @param r the id of the Ant path instance to act as the classpath
- */
- public void setClasspathRef(Reference r) {
- createClasspath().setRefid(r);
- }
-
-}
-
+package org.apache.ws.java2wsdl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.tools.ant.AntClassLoader;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+import org.apache.ws.java2wsdl.utils.Java2WSDLCommandLineOption;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+public class Java2WSDLTask extends Task implements Java2WSDLConstants {
+ public static final String OPEN_BRACKET = "[";
+ public static final String CLOSE_BRACKET = "]";
+ public static final String COMMA = ",";
+
+ private String className = null;
+ private String outputLocation = null;
+ private String targetNamespace = null;
+ private String targetNamespacePrefix = null;
+ private String schemaTargetNamespace = null;
+ private String schemaTargetNamespacePrefix = null;
+ private String serviceName = null;
+ private String outputFileName = null;
+ private Path classpath = null;
+ private String style = Java2WSDLConstants.DOCUMENT;
+ private String use = Java2WSDLConstants.LITERAL;
+ private String locationUri = Java2WSDLConstants.DEFAULT_LOCATION_URL;
+ private String attrFormDefault = null;
+ private String elementFormDefault = null;
+
+ //names of java types not used in the service defn. directly, but for which schema must be generated
+ private String[] extraClasses;
+
+ //namespace generator classname
+ private String nsGenClassName = null;
+
+ //package to namespace map
+ private HashMap namespaceMap = new HashMap();
+
+ //names of java types not used in the service defn. directly, but for which schema must be generated
+ private ArrayList pkg2nsMappings = new ArrayList();
+
+ private MappingSet mappings = new MappingSet();
+
+ public String getLocationUri() {
+ return locationUri;
+ }
+
+ public void setLocationUri(String locationUri) {
+ this.locationUri = locationUri;
+ }
+
+ public String getStyle() {
+ return style;
+ }
+
+ public void setStyle(String style) {
+ this.style = style;
+ }
+
+ public String getUse() {
+ return use;
+ }
+
+ public void setUse(String use) {
+ this.use = use;
+ }
+
+ /**
+ *
+ */
+ public Java2WSDLTask() {
+ super();
+ }
+
+ /**
+ * Fills the option map. This map is passed onto
+ * the code generation API to generate the code.
+ */
+ private Map fillOptionMap() {
+ Map optionMap = new HashMap();
+
+ // Check that critical options exist
+ if (className == null) {
+ throw new BuildException(
+ "You must specify a classname");
+ }
+
+ ////////////////////////////////////////////////////////////////
+
+ // Classname
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.CLASSNAME_OPTION,
+ className);
+
+ // Output location
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.OUTPUT_LOCATION_OPTION,
+ outputLocation);
+
+ // Target namespace
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.TARGET_NAMESPACE_OPTION,
+ targetNamespace);
+
+ // Target namespace prefix
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.TARGET_NAMESPACE_PREFIX_OPTION,
+ targetNamespacePrefix);
+
+ // Schema target namespace
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_OPTION,
+ schemaTargetNamespace);
+
+ // Schema target namespace prefix
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_PREFIX_OPTION,
+ schemaTargetNamespacePrefix);
+
+ // Service name
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.SERVICE_NAME_OPTION,
+ serviceName);
+
+ // Output file name
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.OUTPUT_FILENAME_OPTION,
+ outputFileName);
+
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.STYLE_OPTION,
+ getStyle());
+
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.USE_OPTION,
+ getUse());
+
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.LOCATION_OPTION,
+ getLocationUri());
+
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.ATTR_FORM_DEFAULT_OPTION,
+ getAttrFormDefault());
+
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.ELEMENT_FORM_DEFAULT_OPTION,
+ getElementFormDefault());
+
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.EXTRA_CLASSES_DEFAULT_OPTION,
+ getExtraClasses());
+
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.NAMESPACE_GENERATOR_OPTION,
+ getNsGenClassName());
+
+ loadPkg2NsMap();
+ addToOptionMap(optionMap,
+ Java2WSDLConstants.JAVA_PKG_2_NSMAP_OPTION,
+ getPkg2nsMappings());
+
+ return optionMap;
+ }
+
+ /**
+ * Utility method to convert a string into a single item string[]
+ *
+ * @param value
+ * @return Returns String[].
+ */
+ private String[] getStringArray(String value) {
+ String[] values = new String[1];
+ values[0] = value;
+ return values;
+ }
+
+ /**
+ * Function to put arguments in the option map.
+ * This functions skips adding of options that have a null value.
+ *
+ * @param map The option map into which the option is to be added
+ * @param option The option name
+ * @param value The value of the option
+ */
+ private void addToOptionMap(Map map, String option, String value) {
+ if (value != null) {
+ map.put(option,
+ new Java2WSDLCommandLineOption(option, getStringArray(value)));
+ }
+ }
+
+ private void addToOptionMap(Map map, String option, String[] values) {
+ if (values != null && values.length > 0 ) {
+ map.put(option,
+ new Java2WSDLCommandLineOption(option, values));
+ }
+ }
+
+ private void addToOptionMap(Map map, String option, ArrayList values) {
+ if (values != null && !values.isEmpty() ) {
+ map.put(option,
+ new Java2WSDLCommandLineOption(option, values));
+ }
+ }
+
+ public void execute() throws BuildException {
+ try {
+
+ Map commandLineOptions = this.fillOptionMap();
+
+ AntClassLoader cl = new AntClassLoader(getClass().getClassLoader(),
+ getProject(),
+ classpath == null ? createClasspath() : classpath,
+ false);
+
+ commandLineOptions.put(Java2WSDLConstants.CLASSPATH_OPTION, new Java2WSDLCommandLineOption(Java2WSDLConstants.CLASSPATH_OPTION, classpath.list()));
+
+ Thread.currentThread().setContextClassLoader(cl);
+
+ if (outputLocation != null) cl.addPathElement(outputLocation);
+
+ new Java2WSDLCodegenEngine(commandLineOptions).generate();
+
+ } catch (Throwable e) {
+ throw new BuildException(e);
+ }
+
+ }
+
+ public void setClassName(String className) {
+ this.className = className;
+ }
+
+ public void setOutputLocation(String outputLocation) {
+ this.outputLocation = outputLocation;
+ }
+
+ public void setTargetNamespace(String targetNamespace) {
+ this.targetNamespace = targetNamespace;
+ }
+
+ public void setTargetNamespacePrefix(String targetNamespacePrefix) {
+ this.targetNamespacePrefix = targetNamespacePrefix;
+ }
+
+ public void setSchemaTargetNamespace(String schemaTargetNamespace) {
+ this.schemaTargetNamespace = schemaTargetNamespace;
+ }
+
+ public void setSchemaTargetNamespacePrefix(String schemaTargetNamespacePrefix) {
+ this.schemaTargetNamespacePrefix = schemaTargetNamespacePrefix;
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public void setOutputFileName(String outputFileName) {
+ this.outputFileName = outputFileName;
+ }
+
+ /**
+ * Set the optional classpath
+ *
+ * @param classpath the classpath to use when loading class
+ */
+ public void setClasspath(Path classpath) {
+ createClasspath().append(classpath);
+ }
+
+ /**
+ * Set the optional classpath
+ *
+ * @return a path instance to be configured by the Ant core.
+ */
+ public Path createClasspath() {
+ if (classpath == null) {
+ classpath = new Path(getProject());
+ classpath = classpath.concatSystemClasspath();
+ }
+ return classpath.createPath();
+ }
+
+ /**
+ * Set the reference to an optional classpath
+ *
+ * @param r the id of the Ant path instance to act as the classpath
+ */
+ public void setClasspathRef(Reference r) {
+ createClasspath().setRefid(r);
+ }
+
+ public String getAttrFormDefault() {
+ return attrFormDefault;
+ }
+
+ public void setAttrFormDefault(String attrFormDefault) {
+ this.attrFormDefault = attrFormDefault;
+ }
+
+ public String getElementFormDefault() {
+ return elementFormDefault;
+ }
+
+ public void setElementFormDefault(String elementFormDefault) {
+ this.elementFormDefault = elementFormDefault;
+ }
+
+ public String[] getExtraClasses() {
+ return extraClasses;
+ }
+
+ public void setExtraClasses(String[] extraClasses) {
+ this.extraClasses = extraClasses;
+ }
+
+ public String getNsGenClassName() {
+ return nsGenClassName;
+ }
+
+ public void setNsGenClassName(String nsGenClassName) {
+ this.nsGenClassName = nsGenClassName;
+ }
+
+ public void loadPkg2NsMap() {
+ mappings.execute(namespaceMap, true);
+ Iterator packageNames = namespaceMap.keySet().iterator();
+ String packageName = null;
+ while ( packageNames.hasNext() ) {
+ packageName = (String)packageNames.next();
+ pkg2nsMappings.add(OPEN_BRACKET +
+ packageName +
+ COMMA +
+ namespaceMap.get(packageName) +
+ CLOSE_BRACKET);
+ }
+ }
+
+ public ArrayList getPkg2nsMappings() {
+ return pkg2nsMappings;
+ }
+
+ public void setPkg2nsMappings(ArrayList pkg2nsMappings) {
+ this.pkg2nsMappings = pkg2nsMappings;
+ }
+
+ /**
+ * add a mapping of namespaces to packages
+ */
+ public void addMapping(NamespaceMapping mapping) {
+ mappings.addMapping(mapping);
+ }
+
+ /**
+ * add a mapping of namespaces to packages
+ */
+ public void addMappingSet(MappingSet mappingset) {
+ mappings.addMappingSet(mappingset);
+ }
+
+}
+
Added: webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Mapper.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Mapper.java?view=auto&rev=467466
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Mapper.java (added)
+++ webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Mapper.java Tue Oct 24 13:25:04 2006
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ws.java2wsdl;
+
+import java.util.HashMap;
+
+import org.apache.tools.ant.BuildException;
+
+/**
+ * interface that namespace mappers are expected to implement
+ */
+
+public interface Mapper {
+ /**
+ * execute the mapping
+ * @param map map to map to
+ * @param packageIsKey if the package is to be the key for the map
+ * @throws BuildException in case of emergency
+ */
+ void execute(HashMap map, boolean packageIsKey) throws BuildException;
+}
\ No newline at end of file
Added: webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/MappingSet.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/MappingSet.java?view=auto&rev=467466
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/MappingSet.java (added)
+++ webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/MappingSet.java Tue Oct 24 13:25:04 2006
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ws.java2wsdl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ *a mappingset is a set of mappings
+ */
+public class MappingSet implements Mapper {
+
+ List mappings = new LinkedList();
+
+ /**
+ * add a new mapping
+ * @param mapping
+ */
+ public void addMapping(NamespaceMapping mapping) {
+ mappings.add(mapping);
+ }
+
+ /**
+ * add a mappingset inside this one
+ * @param mappingset
+ */
+ public void addMappingSet(MappingSet mappingset) {
+ mappings.add(mappingset);
+ }
+
+ /**
+ * execute by mapping everything iteratively and recursively
+ * @param map map to map into
+ * @param packageIsKey if the package is to be the key for the map
+ */
+ public void execute(HashMap map, boolean packageIsKey) {
+ Iterator it=mappings.iterator();
+ while (it.hasNext()) {
+ Mapper mapper = (Mapper) it.next();
+ mapper.execute(map, packageIsKey);
+ }
+ }
+}
Added: webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/NamespaceMapping.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/NamespaceMapping.java?view=auto&rev=467466
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/NamespaceMapping.java (added)
+++ webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/NamespaceMapping.java Tue Oct 24 13:25:04 2006
@@ -0,0 +1,255 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ws.java2wsdl;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamConstants;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashMap;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.tools.ant.BuildException;
+
+/**
+ * Used for nested package definitions.
+ * The file format used for storing mappings is a list of package=namespace
+ */
+public class NamespaceMapping implements Mapper {
+ public static final QName PKG2NS_MAPPINGS = new QName("http://ws.apache.org/axis2", "pkg2ns_mapping");
+ public static final QName MAPPING = new QName("http://ws.apache.org/axis2", "mapping");
+ public static final String NAMESPACE = "namespace";
+ public static final String PACKAGE = "package";
+
+ private String namespace = null;
+ private String packageName = null;
+ private File mappingFile;
+ private InputStream mapInputStream = null;
+ private XMLStreamReader mapXmlReader = null;
+
+ /**
+ * pass in the namespace to map to
+ */
+ public NamespaceMapping() {
+ }
+
+ /**
+ * the namespace in the WSDL. Required.
+ * @param value new uri of the mapping
+ */
+ public void setNamespace(String value) {
+ namespace = value;
+ }
+
+ /**
+ * the Java package to bind to. Required.
+ * @param value java package name
+ */
+ public void setPackage(String value) {
+ packageName = value;
+ }
+
+ /**
+ * name of a property file that contains mappings in
+ * package=namespace format
+ * @param file file to load
+ */
+ public void setFile(File file) {
+ mappingFile = file;
+ }
+
+ /**
+ * map a namespace to a package
+ * @param map map to assign to
+ * @param packName package name
+ * @param nspace namespace
+ * @param packageIsKey if the package is to be the key for the map
+ */
+ protected void map(HashMap map,
+ String packName,
+ String nspace,
+ boolean packageIsKey) {
+ if(packageIsKey) {
+ map.put(packName,nspace);
+ } else {
+ map.put(nspace, packName);
+ }
+ }
+
+ /**
+ * validate the option set
+ */
+ private void validate() {
+ if (mappingFile != null || mapInputStream != null || mapXmlReader != null ) {
+ if (namespace != null || packageName != null) {
+ throw new BuildException(
+ "Namespace or Package cannot be used with a File attribute");
+ }
+ } else {
+ if (namespace == null) {
+ throw new BuildException("namespace must be defined");
+ }
+ if (packageName == null) {
+ throw new BuildException("package must be defined");
+ }
+ }
+ }
+
+ /**
+ * Load a mapping xml reader and save it to the map
+ * @param map target map file
+ * @param packageIsKey if the package is to be the key for the map
+ * @throws BuildException if an IOException needed swallowing
+ */
+ protected void mapXmlReader(HashMap map, boolean packageIsKey) throws BuildException {
+ try {
+ loadMappingFromXMLReader(map, packageIsKey);
+ } catch ( Exception e ) {
+ throw new BuildException(e);
+ }
+ }
+
+
+ /**
+ * Load a mapping input stream and save it to the map
+ * @param map target map file
+ * @param packageIsKey if the package is to be the key for the map
+ * @throws BuildException if an IOException needed swallowing
+ */
+ protected void mapXmlStream(HashMap map, boolean packageIsKey) throws BuildException {
+ try {
+ mapXmlReader = StAXUtils.createXMLStreamReader(mapInputStream);
+ mapXmlReader(map, packageIsKey);
+ //ensure this clean up so that the next invocation does not have any stale state
+ mapXmlReader = null;
+ } catch ( Exception e ) {
+ throw new BuildException(e);
+ }
+ }
+
+ /**
+ * Load a mapping file and save it to the map
+ * @param map target map file
+ * @param packageIsKey if the package is to be the key for the map
+ * @throws BuildException if an IOException needed swallowing
+ */
+ protected void mapFile(HashMap map, boolean packageIsKey) throws BuildException {
+ try {
+ mapInputStream = new FileInputStream(mappingFile);
+ mapXmlStream(map, packageIsKey);
+ //need to do this since the file was opened here
+ mapInputStream.close();
+ //ensure this clean up so that the next invocation does not have any stale state
+ mapInputStream = null;
+ } catch ( Exception e ) {
+ throw new BuildException(e);
+ }
+ }
+
+ /**
+ * load from an xml reader containing mapping info
+ * @return a properties file with zero or more mappings
+ * @throws BuildException if the load failed
+ */
+ private void loadMappingFromXMLReader(HashMap map, boolean packageIsKey) throws BuildException {
+ try {
+ QName parentElement = null;
+ //if the reader is in the fragment that deals with package to namespace mappings
+ while (mapXmlReader.hasNext()) {
+ // mapXmlReader.next();mapXmlReader.next();
+ // if ( mapXmlReader.getName().equals(PKG2NS_MAPPINGS) ) {
+ switch (mapXmlReader.next()) {
+ case XMLStreamConstants.START_ELEMENT :
+ QName qname = mapXmlReader.getName();
+ if (MAPPING.equals(qname) && parentElement.equals(PKG2NS_MAPPINGS)) {
+ map(map,
+ mapXmlReader.getAttributeValue(null, PACKAGE),
+ mapXmlReader.getAttributeValue(null, NAMESPACE),
+ packageIsKey);
+ } else {
+ parentElement = qname;
+ }
+
+ mapXmlReader.next();
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (mapXmlReader.getName().equals(PKG2NS_MAPPINGS)) {
+ //ensure this clean up
+ return;
+ }
+ break;
+ // }
+ }
+ }
+ } catch ( Exception e ) {
+ System.out.println("Exception while loading package to namespace mappings... " + e);
+ }
+ }
+
+ /**
+ * execute the mapping
+ * @param map map to map to
+ * @param packageIsKey if the package is to be the key for the map
+ * @throws BuildException in case of emergency
+ */
+ public void execute(HashMap map, boolean packageIsKey) throws BuildException {
+ validate();
+ if (mappingFile != null ) {
+ mapFile(map,packageIsKey);
+ //ensure this clean up so that the next invocation does not have any stale state
+ mappingFile = null;
+ } else if ( mapInputStream != null ) {
+ mapXmlStream(map, packageIsKey);
+ } else if ( mapXmlReader != null ) {
+ mapXmlReader(map, packageIsKey);
+ } else {
+ map(map, packageName, namespace, packageIsKey);
+ }
+ }
+
+ public InputStream getMapInputStream() {
+ return mapInputStream;
+ }
+
+ public void setMapInputStream(InputStream mapInputStream) {
+ this.mapInputStream = mapInputStream;
+ }
+
+ public File getMappingFile() {
+ return mappingFile;
+ }
+
+ public void setMappingFile(File mappingFile) {
+ this.mappingFile = mappingFile;
+ }
+
+ public XMLStreamReader getXmlReader() {
+ return mapXmlReader;
+ }
+
+ public void setXmlReader(XMLStreamReader xmlReader) {
+ this.mapXmlReader = xmlReader;
+ }
+
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org