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 aj...@apache.org on 2006/05/29 13:33:25 UTC
svn commit: r410076 - in
/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl:
codegen/ codegen/extension/ i18n/ util/
Author: ajith
Date: Mon May 29 04:33:24 2006
New Revision: 410076
URL: http://svn.apache.org/viewvc?rev=410076&view=rev
Log:
1. Added a new feature - passing in an external mapping file which has the QName to value mappings. The argument is -em for the command line tool.
I. Added the necessary extension to process the mapping file - updated the configuration properties
II. updated the configuration and external parameters accordingly
2.Fixed some minor issues in internationalization
Added:
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/TypeMapperExtension.java
Modified:
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
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/codegen-config.properties
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/DefaultDatabindingExtension.java
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/i18n/resource.properties
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/CommandLineOptionConstants.java
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/WSDL2JavaOptionsValidator.java
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=410076&r1=410075&r2=410076&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 Mon May 29 04:33:24 2006
@@ -28,11 +28,22 @@
public class CodeGenConfiguration implements CommandLineOptionConstants {
+ /** Axis Service reference*/
private AxisService axisService;
-
+ /** Base URI */
private String baseURI;
-
+ /** path to the repository - used for evaluating policy */
private String repositoryPath;
+ /** Mapping file including the qname to type map */
+ private File typeMappingFile;
+
+ public File getTypeMappingFile() {
+ return typeMappingFile;
+ }
+
+ public void setTypeMappingFile(File typeMappingFile) {
+ this.typeMappingFile = typeMappingFile;
+ }
/**
* A map to keep the custom namespace and package name mappings
@@ -48,6 +59,8 @@
this.uri2PackageNameMap = uri2PackageNameMap;
}
+
+
/**
* Determines whether the parameters are wrappedor unwrapped
* false by default
@@ -143,7 +156,7 @@
//option to generate server side interface or not
private boolean serverSideInterface = false;
-
+
public boolean isServerSideInterface() {
return serverSideInterface;
}
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=410076&r1=410075&r2=410076&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 Mon May 29 04:33:24 2006
@@ -42,7 +42,8 @@
//check and create the directories
if (outputLocationFile.exists()) {
if (outputLocationFile.isFile()) {
- throw new RuntimeException(CodegenMessages.getMessage("options.notADirectoryException"));
+ throw new RuntimeException(
+ CodegenMessages.getMessage("options.notADirectoryException"));
}
} else {
outputLocationFile.mkdirs();
@@ -107,6 +108,21 @@
config.setGenerateAll(true);
}
+ //populate the external mapping
+ CommandLineOption externalMapping = loadOption(
+ WSDL2JavaConstants.EXTERNAL_MAPPING_OPTION,
+ WSDL2JavaConstants.EXTERNAL_MAPPING_OPTION_LONG,
+ optionMap);
+ if (externalMapping!=null){
+ try {
+ config.setTypeMappingFile(new File(externalMapping.getOptionValue()));
+ } catch (Exception e) {
+ throw new RuntimeException(
+ CodegenMessages.getMessage("options.nomappingFile"), e);
+ }
+ }
+
+ // load the namespace to package list
CommandLineOption ns2packageOption = loadOption(
WSDL2JavaConstants.NAME_SPACE_TO_PACKAGE_OPTION,
WSDL2JavaConstants.NAME_SPACE_TO_PACKAGE_OPTION_LONG,
@@ -137,7 +153,9 @@
p.load(new FileInputStream(value));
config.setUri2PackageNameMap(p);
} catch (IOException e) {
- throw new RuntimeException("Unable to load file :" + value, e);
+ throw new RuntimeException(
+ CodegenMessages.
+ getMessage("options.noFile", value), e);
}
}
}
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/codegen-config.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/codegen-config.properties?rev=410076&r1=410075&r2=410076&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/codegen-config.properties (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/codegen-config.properties Mon May 29 04:33:24 2006
@@ -5,7 +5,7 @@
# these are loaded in their lexical order
# Note the last extension - It includes a check to figure out whether proper databinding has taken place
# This extension should appear AFTER all the databinding extensions inorder to function properly
-codegen.extension=org.apache.axis2.wsdl.codegen.extension.JaxMeExtension,org.apache.axis2.wsdl.codegen.extension.XMLBeansExtension,org.apache.axis2.wsdl.codegen.extension.SimpleDBExtension,org.apache.axis2.wsdl.codegen.extension.JiBXExtension,org.apache.axis2.wsdl.codegen.extension.JAXBRIExtension,org.apache.axis2.wsdl.codegen.extension.DefaultDatabindingExtension
+codegen.extension=org.apache.axis2.wsdl.codegen.extension.JaxMeExtension,org.apache.axis2.wsdl.codegen.extension.XMLBeansExtension,org.apache.axis2.wsdl.codegen.extension.SimpleDBExtension,org.apache.axis2.wsdl.codegen.extension.JiBXExtension,org.apache.axis2.wsdl.codegen.extension.JAXBRIExtension,org.apache.axis2.wsdl.codegen.extension.TypeMapperExtension,org.apache.axis2.wsdl.codegen.extension.DefaultDatabindingExtension
#codegen.extension=org.apache.axis2.wsdl.codegen.extension.AxisBindingBuilder,org.apache.axis2.wsdl.codegen.extension.WSDLValidatorExtension,org.apache.axis2.wsdl.codegen.extension.PackageFinder,org.apache.axis2.wsdl.codegen.extension.SimpleDBExtension
# The third party schemas to be loaded. e.g. The Xmime extension
# Note - these will be loaded from the org.apache.axis2.wsdl.codegen.schema package.
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/DefaultDatabindingExtension.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/DefaultDatabindingExtension.java?rev=410076&r1=410075&r2=410076&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/DefaultDatabindingExtension.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/DefaultDatabindingExtension.java Mon May 29 04:33:24 2006
@@ -24,19 +24,20 @@
public void engage() throws CodeGenerationException {
- TypeMapper mappper = configuration.getTypeMapper();
+ TypeMapper mapper = configuration.getTypeMapper();
if (testFallThrough(configuration.getDatabindingType())) {
//if it's fall through for the default databinding extension and a mapper has
//not yet being set, then there's a problem.
//Hence check the mapper status here
- if (mappper == null) {
+ if (mapper == null) {
//this shouldn't happen
throw new CodeGenerationException("extension.noProperDatabinding");
}
return;
}
-
- configuration.setTypeMapper(new DefaultTypeMapper());
+ if (mapper ==null){
+ configuration.setTypeMapper(new DefaultTypeMapper());
+ }
}
}
Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/TypeMapperExtension.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/TypeMapperExtension.java?rev=410076&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/TypeMapperExtension.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/TypeMapperExtension.java Mon May 29 04:33:24 2006
@@ -0,0 +1,143 @@
+package org.apache.axis2.wsdl.codegen.extension;
+
+import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
+import org.apache.axis2.wsdl.codegen.CodeGenerationException;
+import org.apache.axis2.wsdl.databinding.TypeMapper;
+import org.apache.axis2.wsdl.databinding.DefaultTypeMapper;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.namespace.QName;
+/*
+ * 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.
+ */
+
+/**
+ * The purpose of this extension is to populate the type mapper from the
+ * type mapping file. The format of the type mapping file is as follows
+ * <mappings>
+ * <mapping>
+ * <qname namespace="ns" prefix="p1">localName</qname>
+ * <value>type</value>
+ * </mapping>
+ * </mappings>
+ */
+
+public class TypeMapperExtension implements CodeGenExtension {
+
+ private CodeGenConfiguration configuration;
+
+ private static final String MAPPING_ELEMENT_NAME = "mapping";
+ private static final String NAMESPACE_ATTRIBUTE_NAME = "namespace";
+ private static final String QNAME_ELEMENT_NAME = "qname";
+ private static final String VALUE_ELEMENT_NAME = "value";
+
+ /**
+ * Initialize the entension
+ * @param configuration
+ */
+ public void init(CodeGenConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ /**
+ *
+ * @throws CodeGenerationException
+ */
+ public void engage() throws CodeGenerationException {
+ if (configuration.getTypeMappingFile()!=null){
+ //a type mapping is present. try building the
+ //mapping from it
+
+ // if the configuration already has a mapping then take it
+ // the external mappings will override the currently available
+ // mappings
+ TypeMapper mapper = configuration.getTypeMapper();
+ // there is no mapper present - so just create a new one
+ if (mapper==null){
+ mapper = new DefaultTypeMapper();
+ }
+
+ //read the file as a DOM
+ Document mappingDocument = buildDocument();
+ NodeList mappingList = mappingDocument.getDocumentElement().
+ getElementsByTagName(MAPPING_ELEMENT_NAME);
+ int length = mappingList.getLength();
+ for (int i = 0; i < length; i++) {
+ Element mappingNode = (Element)mappingList.item(i);
+ //we know this is only one - if there are multiple then
+ //it is invalid
+ Element qNameChild =
+ (Element)mappingNode.
+ getElementsByTagName(QNAME_ELEMENT_NAME).item(0);
+ Element valueChild =
+ (Element)mappingNode.
+ getElementsByTagName(VALUE_ELEMENT_NAME).item(0);
+ //generate a Qname and add to the type mapping
+ mapper.addTypeMappingName(new QName(
+ qNameChild.getAttribute(NAMESPACE_ATTRIBUTE_NAME),
+ getTextFromElement(qNameChild)),
+ getTextFromElement(valueChild));
+
+ }
+
+ //set the type mapper to the configurtion
+ configuration.setTypeMapper(mapper);
+ }
+ }
+
+ /**
+ * Build a dom document from the mapping file
+ * @return
+ * @throws CodeGenerationException
+ */
+ private Document buildDocument() throws CodeGenerationException {
+ try {
+ DocumentBuilderFactory documentBuilderFactory
+ = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ DocumentBuilder documentBuilder =
+ documentBuilderFactory.newDocumentBuilder();
+ return documentBuilder.parse(configuration.getTypeMappingFile());
+ } catch (Exception e) {
+ throw new CodeGenerationException(e);
+ }
+ }
+
+ /**
+ * Gets the string content from an element. returns null if there are
+ * no test nodes found
+ * @param elt
+ * @return
+ */
+ private String getTextFromElement(Element elt){
+ NodeList children = elt.getChildNodes();
+ String returnString = null;
+ int length = children.getLength();
+ for (int i = 0; i < length; i++) {
+ Node node = children.item(i);
+ if (Node.TEXT_NODE == node.getNodeType()){
+ returnString = (returnString==null?"":returnString) + node.getNodeValue();
+ }
+
+ }
+
+ return returnString;
+ }
+}
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/i18n/resource.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/i18n/resource.properties?rev=410076&r1=410075&r2=410076&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/i18n/resource.properties (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/i18n/resource.properties Mon May 29 04:33:24 2006
@@ -54,6 +54,8 @@
################### Options ###################################
options.notADirectoryException=The specified output location is not a directory!
+options.nomappingFile=Unable to load mapping file!
+options.noFile=The specified output location is not a directory!
writer.noLangPropertiesExtension=No language specific properties!!!
writer.templateMissing=template for this writer is not found!
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/CommandLineOptionConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/CommandLineOptionConstants.java?rev=410076&r1=410075&r2=410076&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/CommandLineOptionConstants.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/CommandLineOptionConstants.java Mon May 29 04:33:24 2006
@@ -38,6 +38,7 @@
String REPOSITORY_PATH_OPTION = "r";
String NAME_SPACE_TO_PACKAGE_OPTION = "ns2p";
String SERVER_SIDE_INTERFACE_OPTION = "ssi";
+ String EXTERNAL_MAPPING_OPTION = "em";
//long option constants
String OUTPUT_LOCATION_OPTION_LONG = "output";
@@ -58,6 +59,7 @@
String REPOSITORY_PATH_OPTION_LONG = "repository-path";
String NAME_SPACE_TO_PACKAGE_OPTION_LONG = "namespace2package";
String SERVER_SIDE_INTERFACE_OPTION_LONG = "serverside-interface";
+ String EXTERNAL_MAPPING_OPTION_LONG = "external-mapping";
}
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/WSDL2JavaOptionsValidator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/WSDL2JavaOptionsValidator.java?rev=410076&r1=410075&r2=410076&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/WSDL2JavaOptionsValidator.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/util/WSDL2JavaOptionsValidator.java Mon May 29 04:33:24 2006
@@ -43,6 +43,7 @@
(WSDL2JavaConstants.REPOSITORY_PATH_OPTION).equalsIgnoreCase(optionType) ||
(WSDL2JavaConstants.NAME_SPACE_TO_PACKAGE_OPTION).equalsIgnoreCase(optionType) ||
(WSDL2JavaConstants.SERVER_SIDE_INTERFACE_OPTION).equalsIgnoreCase(optionType) ||
+ (WSDL2JavaConstants.EXTERNAL_MAPPING_OPTION).equalsIgnoreCase(optionType) ||
(WSDL2JavaConstants.OUTPUT_LOCATION_OPTION_LONG).equalsIgnoreCase(optionType) ||
(WSDL2JavaConstants.SERVER_SIDE_CODE_OPTION_LONG).equalsIgnoreCase(optionType) ||
@@ -59,6 +60,7 @@
(WSDL2JavaConstants.GENERATE_ALL_OPTION_LONG).equalsIgnoreCase(optionType) ||
(WSDL2JavaConstants.NAME_SPACE_TO_PACKAGE_OPTION_LONG).equalsIgnoreCase(optionType) ||
(WSDL2JavaConstants.SERVER_SIDE_INTERFACE_OPTION_LONG).equalsIgnoreCase(optionType) ||
+ (WSDL2JavaConstants.EXTERNAL_MAPPING_OPTION_LONG).equalsIgnoreCase(optionType) ||
(WSDL2JavaConstants.REPOSITORY_PATH_OPTION_LONG).equalsIgnoreCase(optionType)
);
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org