You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by em...@apache.org on 2006/09/06 09:40:24 UTC
svn commit: r440644 [1/2] - in /incubator/cxf/trunk/tools:
common/src/main/java/org/apache/cxf/tools/common/
common/src/main/java/org/apache/cxf/tools/common/model/
common/src/main/java/org/apache/cxf/tools/util/
wsdl2java/src/main/java/org/apache/cxf/...
Author: ema
Date: Wed Sep 6 00:40:23 2006
New Revision: 440644
URL: http://svn.apache.org/viewvc?view=rev&rev=440644
Log:
Refactor tools. Use JAXBBindingGenerator to generate types code
Added:
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/DataBindingGenerator.java (with props)
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindErrorListener.java (with props)
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindingGenerator.java (with props)
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindingMerger.java (with props)
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBErrorReceiver.java (with props)
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/Messages.properties (with props)
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/NamespaceContextImpl.java (with props)
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/TypesCodeWriter.java (with props)
Modified:
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ProcessorEnvironment.java
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaClass.java
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaInterface.java
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/BuiltInTypesJavaMappingUtil.java
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/ProcessorUtil.java
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/Messages.properties
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessor.java
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToProcessor.java
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/AbstractProcessor.java
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/FaultProcessor.java
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/Messages.properties
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/OperationProcessor.java
incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/ParameterProcessor.java
incubator/cxf/trunk/tools/wsdl2java/src/test/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessorTest.java
Added: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/DataBindingGenerator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/DataBindingGenerator.java?view=auto&rev=440644
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/DataBindingGenerator.java (added)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/DataBindingGenerator.java Wed Sep 6 00:40:23 2006
@@ -0,0 +1,33 @@
+/**
+ * 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.cxf.tools.common;
+import java.util.List;
+
+import javax.wsdl.Part;
+import javax.xml.namespace.QName;
+
+import com.sun.tools.xjc.api.Property;
+public interface DataBindingGenerator {
+ void initialize(ProcessorEnvironment penv);
+ void generate() throws ToolException;
+ String getType(QName qn, boolean fullName);
+ String getJavaType(QName qn, boolean fullName);
+ List<? extends Property> getBlock(Part part);
+}
Propchange: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/DataBindingGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ProcessorEnvironment.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ProcessorEnvironment.java?view=diff&rev=440644&r1=440643&r2=440644
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ProcessorEnvironment.java (original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ProcessorEnvironment.java Wed Sep 6 00:40:23 2006
@@ -21,6 +21,9 @@
import java.io.*;
import java.util.*;
+
+import javax.wsdl.extensions.schema.Schema;
+
import org.xml.sax.InputSource;
import org.apache.cxf.tools.common.model.JavaModel;
@@ -35,7 +38,9 @@
private Map<String, String> namespacePackageMap = new HashMap<String, String>();
private Map<String, String> excludeNamespacePackageMap = new HashMap<String, String>();
private final Map<String, InputSource> jaxbBindingFiles = new HashMap<String, InputSource>();
-
+ private List<String> excludePkgList = new java.util.ArrayList<String>();
+ private List<String> excludeFileList = new java.util.ArrayList<String>();
+
public ProcessorEnvironment() {
}
@@ -178,4 +183,20 @@
public boolean isExcludeNamespaceEnabled() {
return excludeNamespacePackageMap.size() > 0;
}
+
+ @SuppressWarnings("unchecked")
+ public List<Schema> getSchemaList() {
+ return (List<Schema>)this.get(ToolConstants.SCHEMA_LIST);
+ }
+
+ public List<String> getExcludePkgList() {
+ return this.excludePkgList;
+ }
+
+ public List<String> getExcludeFileList() {
+ return this.excludeFileList;
+ }
+
+
+
}
Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java?view=diff&rev=440644&r1=440643&r2=440644
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java (original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java Wed Sep 6 00:40:23 2006
@@ -130,7 +130,7 @@
public static final String HANDLER_CHAIN = "handler-chain";
public static final String HANDLER_CHAINS = "handler-chains";
- public static final String RAW_JAXB_MODEL = "rawjaxbmodel";
+ //public static final String RAW_JAXB_MODEL = "rawjaxbmodel";
// JMS adress
public static final String NS_JMS_ADDRESS = "http://cxf.apache.org/transports/jms";
@@ -156,5 +156,16 @@
public static final QName XML_FORMAT = new QName(NS_XML_FORMAT, "body");
public static final QName XML_BINDING_FORMAT = new QName(NS_XML_FORMAT, "binding");
+
+
+
+ public static final String SCHEMA_LIST = "schemaList";
+ public static final String PORTTYPE_MAP = "portTypeMap";
+ public static final String SCHEMA_TARGET_NAMESPACES = "schemaTargetNameSpaces";
+ public static final String WSDL_DEFINITION = "wsdlDefinition";
+ public static final String IMPORTED_DEFENITION = "importedDefinition";
+ public static final String IMPORTED_PORTTYPE = "importedPortType";
+ public static final String IMPORTED_SERVICE = "importedService";
+ public static final String BINDING_GENERATOR = "BindingGenerator";
}
Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaClass.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaClass.java?view=diff&rev=440644&r1=440643&r2=440644
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaClass.java (original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaClass.java Wed Sep 6 00:40:23 2006
@@ -39,4 +39,5 @@
public List<JavaField> getFields() {
return this.jfield;
}
+
}
Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaInterface.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaInterface.java?view=diff&rev=440644&r1=440643&r2=440644
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaInterface.java (original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaInterface.java Wed Sep 6 00:40:23 2006
@@ -45,7 +45,7 @@
private String webserviceName;
private Element handlerChains;
-
+
public JavaInterface() {
}
@@ -211,4 +211,6 @@
public void setBindingExt(JAXWSBinding pBindingExt) {
this.bindingExt = pBindingExt;
}
+
+
}
Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/BuiltInTypesJavaMappingUtil.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/BuiltInTypesJavaMappingUtil.java?view=diff&rev=440644&r1=440643&r2=440644
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/BuiltInTypesJavaMappingUtil.java (original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/BuiltInTypesJavaMappingUtil.java Wed Sep 6 00:40:23 2006
@@ -19,10 +19,10 @@
package org.apache.cxf.tools.util;
-import java.util.*;
-import javax.xml.namespace.QName;
-import com.sun.tools.xjc.api.S2JJAXBModel;
-import com.sun.tools.xjc.api.TypeAndAnnotation;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
public final class BuiltInTypesJavaMappingUtil {
private static final String XML_SCHEMA_NS = "http://www.w3.org/2000/10/XMLSchema";
@@ -37,6 +37,7 @@
nameSpaces.add(NS_XSD.toLowerCase());
nameSpaces.add(NS_XSI.toLowerCase());
}
+
private static Map<String, String> jTypeMapping = new HashMap<String, String>();
static {
jTypeMapping.put("string", "java.lang.String");
@@ -47,7 +48,7 @@
jTypeMapping.put("decimal", "java.math.BigDecimal");
jTypeMapping.put("float", "float");
jTypeMapping.put("double", "double");
- jTypeMapping.put("boolean", "java.lang.boolean");
+ jTypeMapping.put("boolean", "boolean");
jTypeMapping.put("byte", "byte");
jTypeMapping.put("qname", "javax.xml.namespace.QName");
jTypeMapping.put("dataTime", "javax.xml.datatype.XMLGregorianCalendar");
@@ -69,26 +70,6 @@
private BuiltInTypesJavaMappingUtil() {
}
- public static String getJType(QName xmlTypeName, S2JJAXBModel jaxbModel) {
- return getJType(xmlTypeName, jaxbModel, false);
- }
-
- public static String getJType(QName xmlTypeName, S2JJAXBModel jaxbModel, boolean boxify) {
- if (jaxbModel == null) {
- return getJType(xmlTypeName.getNamespaceURI(), xmlTypeName.getLocalPart());
- }
- TypeAndAnnotation typeAndAnnotation = jaxbModel.getJavaType(xmlTypeName);
- if (typeAndAnnotation == null) {
- return getJType(xmlTypeName.getNamespaceURI(), xmlTypeName.getLocalPart());
- }
- if (boxify) {
- return typeAndAnnotation.getTypeClass().boxify().fullName();
- } else {
- return typeAndAnnotation.getTypeClass().fullName();
-
- }
- }
-
public static String getJType(String nameSpace, String type) {
if (type == null || nameSpace == null || !nameSpaces.contains(nameSpace.toLowerCase())) {
return null;
Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/ProcessorUtil.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/ProcessorUtil.java?view=diff&rev=440644&r1=440643&r2=440644
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/ProcessorUtil.java (original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/ProcessorUtil.java Wed Sep 6 00:40:23 2006
@@ -23,12 +23,9 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
-import java.util.logging.Logger;
import javax.wsdl.Message;
import javax.wsdl.Operation;
@@ -41,18 +38,15 @@
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import com.sun.tools.xjc.api.Property;
-import com.sun.tools.xjc.api.S2JJAXBModel;
-import com.sun.tools.xjc.api.TypeAndAnnotation;
import com.sun.xml.bind.api.JAXBRIContext;
-import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.tools.common.DataBindingGenerator;
import org.apache.cxf.tools.common.ProcessorEnvironment;
import org.apache.cxf.tools.common.ToolConstants;
import org.apache.cxf.tools.common.ToolException;
public final class ProcessorUtil {
- private static final Logger LOG = LogUtils.getL7dLogger(ProcessorUtil.class);
+ //private static final Logger LOG = LogUtils.getL7dLogger(ProcessorUtil.class);
private ProcessorUtil() {
}
@@ -75,7 +69,16 @@
public static String resolvePartType(Part part) {
return mangleNameToClassName(getPartType(part));
}
-
+
+ public static String getType(Part part, ProcessorEnvironment env, boolean fullname) {
+ DataBindingGenerator dataBinder = (DataBindingGenerator)env.get(ToolConstants.BINDING_GENERATOR);
+ String type = dataBinder.getType(getElementName(part), fullname);
+ if (type == null) {
+ type = resolvePartType(part);
+ }
+ return type;
+ }
+
public static QName getElementName(Part part) {
if (part == null) {
return null;
@@ -104,29 +107,31 @@
public static String resolvePartType(Part part, ProcessorEnvironment env) {
if (env != null) {
- return resolvePartType(part, (S2JJAXBModel)env.get(ToolConstants.RAW_JAXB_MODEL));
+ return resolvePartType(part, env, false);
} else {
return resolvePartType(part);
}
}
- public static String resolvePartType(Part part, S2JJAXBModel jaxbModel) {
- return resolvePartType(part, jaxbModel, false);
- }
-
- public static String resolvePartType(Part part, S2JJAXBModel jaxbModel, boolean fullName) {
- if (jaxbModel == null) {
+ /* public static String resolvePartType(Part part, ProcessorEnvironment env) {
+ return resolvePartType(part, env, false);
+ }*/
+
+ public static String resolvePartType(Part part, ProcessorEnvironment env, boolean fullName) {
+ DataBindingGenerator binder = (DataBindingGenerator)env.get(ToolConstants.BINDING_GENERATOR);
+ if (binder == null) {
return resolvePartType(part);
}
- com.sun.tools.xjc.api.Mapping mapping = jaxbModel.get(getElementName(part));
- if (mapping == null) {
+ String name = binder.getType(getElementName(part), fullName);
+ if (name == null) {
return resolvePartType(part);
}
- if (fullName) {
+ return name;
+ /*if (fullName) {
return mapping.getType().getTypeClass().fullName();
} else {
return mapping.getType().getTypeClass().name();
- }
+ }*/
}
public static String resolvePartNamespace(Part part) {
@@ -179,38 +184,6 @@
return path.replace('\\', '/');
}
- //
- // the wrapper style will get the type info from the properties in the block
- //
- public static List<? extends Property> getBlock(Part part, ProcessorEnvironment env)
- throws ToolException {
- if (part == null) {
- return new ArrayList<Property>();
- }
-
- S2JJAXBModel jaxbModel = (S2JJAXBModel)env.get(ToolConstants.RAW_JAXB_MODEL);
-
- // QName element = getMappedElementName(part, env);
- QName element = getElementName(part);
-
- if (element != null && jaxbModel != null) {
- com.sun.tools.xjc.api.Mapping mapping = jaxbModel.get(element);
- if (mapping != null) {
- return mapping.getWrapperStyleDrilldown();
- } else {
- org.apache.cxf.common.i18n.Message msg =
- new org.apache.cxf.common.i18n.Message("ELEMENT_MISSING",
- LOG,
- new Object[]{element.toString(),
- part.getName()});
- throw new ToolException(msg);
- // return new ArrayList<Property>();
- }
- } else {
- return new ArrayList<Property>();
- }
- }
-
public static URL[] pathToURLs(String path) {
StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
URL[] urls = new URL[st.countTokens()];
@@ -248,35 +221,42 @@
//
// the non-wrapper style will get the type info from the part directly
//
- public static String getFullClzName(Part part, ProcessorEnvironment env, boolean boxify,
- ClassCollector collector) {
- S2JJAXBModel jaxbModel = (S2JJAXBModel)env.get(ToolConstants.RAW_JAXB_MODEL);
-
+ public static String getFullClzName(Part part, ProcessorEnvironment env,
+ ClassCollector collector, boolean boxify) {
+ DataBindingGenerator dataBindingGenerator = (DataBindingGenerator)env
+ .get(ToolConstants.BINDING_GENERATOR);
+ String jtype = null;
QName xmlTypeName = getElementName(part);
- String jtype = BuiltInTypesJavaMappingUtil.getJType(xmlTypeName, jaxbModel, boxify);
+ // if this flag is true , mapping to java Type first;
+ // if not found , findd the primitive type : int ,long
+ // if not found, find in the generated class
+
+ if (boxify) {
+ jtype = dataBindingGenerator.getJavaType(xmlTypeName, true);
+ } else {
+ jtype = dataBindingGenerator.getJavaType(xmlTypeName, true);
+ }
String namespace = xmlTypeName.getNamespaceURI();
- String type = resolvePartType(part, jaxbModel);
+ String type = resolvePartType(part, env, true);
String userPackage = env.mapPackageName(namespace);
if (jtype == null) {
- jtype = collector.getTypesFullClassName(parsePackageName(namespace, userPackage), type);
+ jtype = collector.getTypesFullClassName(parsePackageName(namespace, userPackage), type);
}
if (jtype == null) {
if (!type.equals(resolvePartType(part))) {
- jtype = resolvePartType(part, jaxbModel, true);
+ jtype = resolvePartType(part, env, true);
} else {
jtype = parsePackageName(namespace, userPackage) + "." + type;
- }
- }
-
+ }
+ }
+
+
return jtype;
}
- public static String getFullClzName(Part part, ProcessorEnvironment env, ClassCollector collector) {
- return getFullClzName(part, env, false, collector);
-
- }
+
public static String getFileOrURLName(String fileOrURL) {
try {
@@ -318,13 +298,7 @@
return name + "_handler";
}
- public static String boxify(QName xmlTypeName, S2JJAXBModel jaxbModel) {
- TypeAndAnnotation typeAndAnnotation = jaxbModel.getJavaType(xmlTypeName);
- if (typeAndAnnotation == null) {
- return null;
- }
- return typeAndAnnotation.getTypeClass().boxify().fullName();
- }
+
@SuppressWarnings("unchecked")
public static boolean isWrapperStyle(Operation operation, ProcessorEnvironment env) throws ToolException {
@@ -388,8 +362,9 @@
// RULE No.4 and No5:
// wrapper element should be pure complex type
//
- if (ProcessorUtil.getBlock(inputPart, env) == null
- || ProcessorUtil.getBlock(outputPart, env) == null) {
+ DataBindingGenerator databinder = (DataBindingGenerator)env.get(ToolConstants.BINDING_GENERATOR);
+ if (databinder.getBlock(inputPart) == null
+ || databinder.getBlock(outputPart) == null) {
return false;
}
Added: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindErrorListener.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindErrorListener.java?view=auto&rev=440644
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindErrorListener.java (added)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindErrorListener.java Wed Sep 6 00:40:23 2006
@@ -0,0 +1,60 @@
+/**
+ * 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.cxf.tools.wsdl2java.generator.jaxb;
+
+import com.sun.tools.xjc.api.ErrorListener;
+
+import org.apache.cxf.tools.common.ProcessorEnvironment;
+
+public class JAXBBindErrorListener implements ErrorListener {
+ private ProcessorEnvironment env;
+
+ public JAXBBindErrorListener(ProcessorEnvironment penv) {
+ env = penv;
+ }
+
+ public void error(org.xml.sax.SAXParseException exception) {
+ if (this.env.isVerbose()) {
+ exception.printStackTrace();
+ } else {
+ System.err.println("Parsing schema error: \n" + exception.toString());
+ }
+ }
+
+ public void fatalError(org.xml.sax.SAXParseException exception) {
+ if (this.env.isVerbose()) {
+ exception.printStackTrace();
+ } else {
+ System.err.println("Parsing schema fatal error: \n" + exception.toString());
+ }
+ }
+
+ public void info(org.xml.sax.SAXParseException exception) {
+ if (this.env.isVerbose()) {
+ System.err.println("Parsing schema info: " + exception.toString());
+ }
+ }
+
+ public void warning(org.xml.sax.SAXParseException exception) {
+ if (this.env.isVerbose()) {
+ System.err.println("Parsing schema warning " + exception.toString());
+ }
+ }
+}
Propchange: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindErrorListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindingGenerator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindingGenerator.java?view=auto&rev=440644
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindingGenerator.java (added)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindingGenerator.java Wed Sep 6 00:40:23 2006
@@ -0,0 +1,368 @@
+/**
+ * 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.cxf.tools.wsdl2java.generator.jaxb;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Part;
+import javax.wsdl.PortType;
+import javax.wsdl.extensions.schema.Schema;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Result;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.xml.sax.InputSource;
+
+import com.sun.codemodel.JCodeModel;
+import com.sun.tools.xjc.BadCommandLineException;
+import com.sun.tools.xjc.Language;
+import com.sun.tools.xjc.ModelLoader;
+import com.sun.tools.xjc.Options;
+import com.sun.tools.xjc.api.Property;
+import com.sun.tools.xjc.api.S2JJAXBModel;
+import com.sun.tools.xjc.api.TypeAndAnnotation;
+import com.sun.tools.xjc.api.XJC;
+import com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl;
+import com.sun.tools.xjc.model.Model;
+
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.tools.common.DataBindingGenerator;
+import org.apache.cxf.tools.common.ProcessorEnvironment;
+import org.apache.cxf.tools.common.ToolConstants;
+import org.apache.cxf.tools.common.ToolException;
+import org.apache.cxf.tools.util.ClassCollector;
+import org.apache.cxf.tools.util.JAXBUtils;
+import org.apache.cxf.tools.util.ProcessorUtil;
+import org.apache.cxf.tools.util.URIParserUtil;
+import org.apache.cxf.tools.wsdl2java.processor.internal.ClassNameAllocatorImpl;
+public class JAXBBindingGenerator implements DataBindingGenerator {
+ private static final Logger LOG = LogUtils.getL7dLogger(JAXBBindingGenerator.class);
+ protected S2JJAXBModel rawJaxbModel;
+ protected S2JJAXBModel rawJaxbModelGenCode;
+ private boolean nestedJaxbBinding;
+ private Model model;
+ private ProcessorEnvironment env;
+ private int fileIDX;
+
+ @SuppressWarnings("unchecked")
+ public void initialize(ProcessorEnvironment penv) {
+ env = penv;
+
+ SchemaCompilerImpl schemaCompiler = (SchemaCompilerImpl)XJC.createSchemaCompiler();
+ ClassCollector classCollector = (ClassCollector)env.get(ToolConstants.GENERATED_CLASS_COLLECTOR);
+
+ ClassNameAllocatorImpl allocator = new ClassNameAllocatorImpl(classCollector);
+
+ Map<QName, PortType> portTypeMap = (Map<QName, PortType>)env.get(ToolConstants.PORTTYPE_MAP);
+ Definition def = (Definition)env.get(ToolConstants.WSDL_DEFINITION);
+
+ allocator.setPortTypes(portTypeMap.values(), env.mapPackageName(def.getTargetNamespace()));
+
+ schemaCompiler.setClassNameAllocator(allocator);
+ JAXBBindErrorListener listener = new JAXBBindErrorListener(env);
+ schemaCompiler.setErrorListener(listener);
+
+ SchemaCompilerImpl schemaCompilerGenCode = schemaCompiler;
+ String excludePackageName = "";
+ if (env.isExcludeNamespaceEnabled()) {
+ schemaCompilerGenCode = (SchemaCompilerImpl)XJC.createSchemaCompiler();
+ schemaCompilerGenCode.setClassNameAllocator(allocator);
+ schemaCompilerGenCode.setErrorListener(listener);
+ }
+ List schemaSystemidList = new ArrayList();
+
+ Options opt = new OptionsEx();
+ List<Schema> schemaList = env.getSchemaList();
+ for (Schema schema : schemaList) {
+
+ Element schemaElement = schema.getElement();
+ String targetNamespace = schemaElement.getAttribute("targetNamespace");
+ if (StringUtils.isEmpty(targetNamespace)) {
+ continue;
+ }
+
+ if (env.hasExcludeNamespace(targetNamespace)) {
+ excludePackageName = env.getExcludePackageName(targetNamespace);
+ if (excludePackageName != null) {
+ env.getExcludePkgList().add(excludePackageName);
+ } else {
+ env.getExcludePkgList().add(URIParserUtil.getPackageName(targetNamespace));
+ }
+ }
+ customizeSchema(schemaElement, targetNamespace);
+ String systemid = schema.getDocumentBaseURI();
+ if (schemaSystemidList.contains(systemid)) {
+ systemid = schema.getDocumentBaseURI() + "#" + targetNamespace;
+ }
+ schemaSystemidList.add(systemid);
+ schemaCompiler.parseSchema(systemid, schemaElement);
+ schemaCompilerGenCode.parseSchema(systemid, schemaElement);
+ if (nestedJaxbBinding) {
+ processNestedBinding(schemaElement, systemid, opt);
+
+ }
+
+ }
+
+ Collection<InputSource> jaxbBindingFiles = env.getJaxbBindingFile().values();
+ for (InputSource bindingFile : jaxbBindingFiles) {
+ schemaCompiler.parseSchema(bindingFile);
+ if (env.isExcludeNamespaceEnabled()) {
+ schemaCompilerGenCode.parseSchema(bindingFile);
+ }
+ }
+ rawJaxbModel = schemaCompiler.bind();
+ if (env.isExcludeNamespaceEnabled()) {
+ rawJaxbModelGenCode = schemaCompilerGenCode.bind();
+ } else {
+ rawJaxbModelGenCode = rawJaxbModel;
+ }
+ if (nestedJaxbBinding) {
+ opt.classNameAllocator = allocator;
+ model = ModelLoader.load(opt, new JCodeModel(), new JAXBErrorReceiver(env));
+ model.generateCode(opt, new JAXBErrorReceiver(env));
+ }
+
+ }
+
+ private void processNestedBinding(Element schemaElement, String systemid, Options opt) {
+ String xsdFile = "schema" + (fileIDX++);
+ File file = null;
+ try {
+ file = File.createTempFile(xsdFile, ".xsd");
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Result result = new StreamResult(file);
+ DOMSource source = new DOMSource(schemaElement);
+
+ try {
+ TransformerFactory.newInstance().newTransformer().transform(source, result);
+ } catch (TransformerConfigurationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (TransformerException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (TransformerFactoryConfigurationError e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ InputSource insource = null;
+ try {
+ insource = new InputSource((InputStream)new FileInputStream(file));
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ insource.setSystemId(systemid);
+ opt.setSchemaLanguage(Language.XMLSCHEMA);
+ opt.addGrammar(file);
+ }
+
+ public void generate() throws ToolException {
+ if (env.optionSet(ToolConstants.CFG_GEN_CLIENT) || env.optionSet(ToolConstants.CFG_GEN_SERVER)) {
+ return;
+ }
+ if (rawJaxbModelGenCode == null) {
+ return;
+ }
+ try {
+ String dir = (String)env.get(ToolConstants.CFG_OUTPUTDIR);
+
+ TypesCodeWriter fileCodeWriter = new TypesCodeWriter(new File(dir), env.getExcludePkgList());
+
+ if (rawJaxbModelGenCode instanceof S2JJAXBModel && !nestedJaxbBinding) {
+ S2JJAXBModel schem2JavaJaxbModel = (S2JJAXBModel)rawJaxbModelGenCode;
+
+ JCodeModel jcodeModel = schem2JavaJaxbModel.generateCode(null, null);
+ jcodeModel.build(fileCodeWriter);
+ for (String str : fileCodeWriter.getExcludeFileList()) {
+ env.getExcludeFileList().add(str);
+ }
+ }
+
+ if (rawJaxbModelGenCode instanceof S2JJAXBModel && nestedJaxbBinding) {
+ model.codeModel.build(fileCodeWriter);
+ for (String str : fileCodeWriter.getExcludeFileList()) {
+ env.getExcludeFileList().add(str);
+ }
+ }
+
+ return;
+ } catch (IOException e) {
+ Message msg = new Message("FAIL_TO_GENERATE_TYPES", LOG);
+ throw new ToolException(msg);
+ }
+ }
+
+ public String getType(QName qn, boolean fullName) {
+ String type;
+ if (rawJaxbModel == null) {
+ return null;
+ }
+ com.sun.tools.xjc.api.Mapping mapping = rawJaxbModel.get(qn);
+ if (mapping == null) {
+ return null;
+ }
+ if (fullName) {
+ type = mapping.getType().getTypeClass().fullName();
+ if (type == null) {
+ type = mapping.getType().getTypeClass().boxify().fullName();
+ }
+ return type;
+
+ } else {
+ type = mapping.getType().getTypeClass().name();
+ if (type == null) {
+ type = mapping.getType().getTypeClass().boxify().name();
+ }
+ return type;
+ }
+
+ }
+
+ public String getJavaType(QName qn, boolean boxify) {
+ String jtypeClass;
+ if (rawJaxbModel == null) {
+ return null;
+ }
+ TypeAndAnnotation jtype = rawJaxbModel.getJavaType(qn);
+ if (jtype == null || jtype.getTypeClass() == null) {
+ return null;
+ } else {
+ if (boxify) {
+ jtypeClass = jtype.getTypeClass().boxify().fullName();
+ } else {
+ jtypeClass = jtype.getTypeClass().name();
+ }
+ }
+
+ return jtypeClass;
+
+
+ }
+
+ private void customizeSchema(Element schema, String targetNamespace) {
+ String userPackage = env.mapPackageName(targetNamespace);
+ if (env.hasExcludeNamespace(targetNamespace) && env.getExcludePackageName(targetNamespace) != null) {
+ // generate excluded namespace types classes with specified package
+ // name
+ userPackage = env.getExcludePackageName(targetNamespace);
+ }
+ if (!isSchemaParsed(targetNamespace) && !StringUtils.isEmpty(userPackage)) {
+ Node jaxbBindings = JAXBUtils.innerJaxbPackageBinding(schema, userPackage);
+ schema.appendChild(jaxbBindings);
+ }
+
+ int nodeListLen = schema.getElementsByTagNameNS(ToolConstants.SCHEMA_URI, "import").getLength();
+ for (int i = 0; i < nodeListLen; i++) {
+ removeImportElement(schema);
+ }
+ JAXBBindingMerger jaxbBindingMerger = new JAXBBindingMerger();
+ jaxbBindingMerger.mergeJaxwsBinding(schema, env);
+
+ if (jaxbBindingMerger.isMerged()) {
+ nestedJaxbBinding = true;
+ }
+ }
+
+ private void removeImportElement(Element element) {
+ NodeList nodeList = element.getElementsByTagNameNS(ToolConstants.SCHEMA_URI, "import");
+ if (nodeList.getLength() > 0) {
+ Node importNode = nodeList.item(0);
+ Node schemaNode = importNode.getParentNode();
+ schemaNode.removeChild(importNode);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private boolean isSchemaParsed(String targetNamespace) {
+ List schemaNamespaces = (List)env.get(ToolConstants.SCHEMA_TARGET_NAMESPACES);
+ if (!schemaNamespaces.contains(targetNamespace)) {
+ schemaNamespaces.add(targetNamespace);
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ public List<? extends Property> getBlock(Part part) {
+ if (part == null) {
+ return new ArrayList<Property>();
+ }
+
+ // QName element = getMappedElementName(part, env);
+ QName element = ProcessorUtil.getElementName(part);
+
+ if (element != null && rawJaxbModel != null) {
+ com.sun.tools.xjc.api.Mapping mapping = rawJaxbModel.get(element);
+ if (mapping != null) {
+ return mapping.getWrapperStyleDrilldown();
+ } else {
+ org.apache.cxf.common.i18n.Message msg =
+ new org.apache.cxf.common.i18n.Message("ELEMENT_MISSING",
+ LOG,
+ new Object[] {element.toString(),
+ part.getName()});
+ System.err.println(msg);
+ // return new ArrayList<Property>();
+ }
+ }
+ return new ArrayList<Property>();
+ }
+
+ private class OptionsEx extends Options {
+
+ protected Mode mode = Mode.CODE;
+
+ protected int parseArgument(String[] args, int i) throws BadCommandLineException {
+
+ return super.parseArgument(args, i);
+ }
+ }
+
+ private enum Mode {
+ CODE, BGM, SIGNATURE, FOREST, DRYRUN, ZIP,
+ }
+
+}
Propchange: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindingGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindingMerger.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindingMerger.java?view=auto&rev=440644
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindingMerger.java (added)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindingMerger.java Wed Sep 6 00:40:23 2006
@@ -0,0 +1,159 @@
+/**
+ * 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.cxf.tools.wsdl2java.generator.jaxb;
+
+import java.io.File;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.tools.common.ProcessorEnvironment;
+import org.apache.cxf.tools.common.ToolConstants;
+import org.apache.cxf.tools.common.ToolException;
+import org.apache.cxf.tools.util.ProcessorUtil;
+
+
+public class JAXBBindingMerger {
+ protected static final Logger LOG = LogUtils.getL7dLogger(JAXBBindingMerger.class);
+ private boolean merged;
+ public void mergeJaxwsBinding(Element schema, ProcessorEnvironment env) {
+ String[] bindingFiles;
+ try {
+ bindingFiles = (String[])env.get(ToolConstants.CFG_BINDING);
+ } catch (ClassCastException e) {
+ bindingFiles = new String[1];
+ bindingFiles[0] = (String)env.get(ToolConstants.CFG_BINDING);
+ }
+
+ if (bindingFiles == null) {
+ return;
+ }
+
+ for (int i = 0; i < bindingFiles.length; i++) {
+ File jaxwsFile = new File(bindingFiles[i]);
+ // get jaxBidnings nested in jaxws bindings
+ NodeList jaxbBindingList = getJaxbBindingsNodes(jaxwsFile);
+ String elementpath = ".";
+ if (jaxbBindingList != null && jaxbBindingList.getLength() > 0) {
+ for (int j = 0; j < jaxbBindingList.getLength(); j++) {
+ Node bindingNode = jaxbBindingList.item(j);
+ elementpath = ((Element)bindingNode).getAttribute("node");
+
+ NamespaceContext nsContext = (NamespaceContext)new NamespaceContextImpl(jaxwsFile);
+ NodeList bindNodesInSchemaElement = findBindingNode(schema, elementpath, nsContext);
+
+ if (bindNodesInSchemaElement != null && bindNodesInSchemaElement.getLength() > 0) {
+ for (int k = 0; k < bindNodesInSchemaElement.getLength(); k++) {
+ // set jaxb namespace and jaxb version attribute
+ String jaxbPrefix = schema.lookupPrefix("http://java.sun.com/xml/ns/jaxb");
+ if (jaxbPrefix == null) {
+ schema.setAttribute("xmlns:jaxb", "http://java.sun.com/xml/ns/jaxb");
+ schema.setAttribute("jaxb:version", "2.0");
+ }
+ // bindElement in schema
+ Element bindElement = (Element)bindNodesInSchemaElement.item(k);
+ NodeList jaxbBindings = bindingNode.getChildNodes();
+ if (jaxbBindings.getLength() != 0) {
+ Element annoElement =
+ bindElement.getOwnerDocument().createElementNS(ToolConstants.SCHEMA_URI,
+ "annotation");
+ Element appinfoEle =
+ bindElement.getOwnerDocument().createElementNS(ToolConstants.SCHEMA_URI,
+ "appinfo");
+ annoElement.appendChild(appinfoEle);
+ for (int l = 0; l < jaxbBindings.getLength(); l++) {
+ Node jaxbBindingNode = jaxbBindings.item(l);
+ Node node = ProcessorUtil.cloneNode(bindElement.getOwnerDocument(),
+ jaxbBindingNode, true);
+ appinfoEle.appendChild(node);
+ }
+ if (bindElement.getChildNodes().getLength() > 0) {
+ bindElement
+ .insertBefore(annoElement, bindElement.getChildNodes().item(0));
+ } else {
+ bindElement.appendChild(annoElement);
+ }
+ merged = true;
+ }
+
+ }
+ }
+ }
+ }
+
+ }
+
+
+ }
+
+ private NodeList findBindingNode(Element schemaElement, String bindingPath, NamespaceContext nsContext) {
+ XPathFactory xpathFactory = XPathFactory.newInstance();
+ javax.xml.xpath.XPath xpath = xpathFactory.newXPath();
+ xpath.setNamespaceContext(nsContext);
+ NodeList nodelist = null;
+ try {
+ nodelist = (NodeList)xpath.evaluate(bindingPath, schemaElement,
+ javax.xml.xpath.XPathConstants.NODESET);
+ } catch (XPathExpressionException e) {
+ e.printStackTrace();
+ }
+ return nodelist;
+ }
+
+ private NodeList getJaxbBindingsNodes(File jaxwsFile) {
+ DocumentBuilderFactory docBuilderFact = DocumentBuilderFactory.newInstance();
+ docBuilderFact.setNamespaceAware(true);
+ Document jaxwsDoc;
+ NodeList nodeList = null;
+
+ try {
+ jaxwsDoc = docBuilderFact.newDocumentBuilder().parse(jaxwsFile);
+ NodeList jaxwsBindingNodeList = jaxwsDoc.getElementsByTagNameNS(ToolConstants.NS_JAXWS_BINDINGS,
+ "bindings");
+
+ if (jaxwsBindingNodeList.getLength() == 0) {
+ return null;
+ }
+ nodeList = jaxwsDoc.getElementsByTagNameNS(ToolConstants.NS_JAXB_BINDINGS, "bindings");
+ } catch (Exception e) {
+ org.apache.cxf.common.i18n.Message msg =
+ new org.apache.cxf.common.i18n.Message("FAIL_TO_GET_JAXBINDINGNODE_FROM_JAXWSBINDING",
+ LOG);
+ LOG.log(Level.SEVERE, msg.toString());
+ throw new ToolException(msg, e);
+ }
+ return nodeList;
+ }
+
+ public boolean isMerged() {
+ return merged;
+ }
+
+}
Propchange: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBBindingMerger.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBErrorReceiver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBErrorReceiver.java?view=auto&rev=440644
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBErrorReceiver.java (added)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBErrorReceiver.java Wed Sep 6 00:40:23 2006
@@ -0,0 +1,66 @@
+/**
+ * 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.cxf.tools.wsdl2java.generator.jaxb;
+
+import com.sun.tools.xjc.ErrorReceiver;
+
+import org.apache.cxf.tools.common.ProcessorEnvironment;
+
+public class JAXBErrorReceiver extends ErrorReceiver {
+ private ProcessorEnvironment env;
+
+ public JAXBErrorReceiver(ProcessorEnvironment penv) {
+ env = penv;
+ }
+
+ public void warning(org.xml.sax.SAXParseException saxEx) throws com.sun.tools.xjc.AbortException {
+ if (env.isVerbose()) {
+ saxEx.printStackTrace();
+ } else {
+ System.err.println("Use jaxb customization binding file to generate types warring "
+ + saxEx.getMessage());
+ }
+
+ }
+
+ public void error(org.xml.sax.SAXParseException saxEx) throws com.sun.tools.xjc.AbortException {
+ if (env.isVerbose()) {
+ saxEx.printStackTrace();
+ } else {
+ System.err.println("Use jaxb customization binding file to generate types error "
+ + saxEx.getMessage());
+ }
+ }
+
+ public void info(org.xml.sax.SAXParseException saxEx) {
+ if (env.isVerbose()) {
+ saxEx.printStackTrace();
+ }
+ }
+
+ public void fatalError(org.xml.sax.SAXParseException saxEx) throws com.sun.tools.xjc.AbortException {
+ if (env.isVerbose()) {
+ saxEx.printStackTrace();
+ } else {
+ System.err.println("Use jaxb customization binding file to generate types fatal error "
+ + saxEx.getMessage());
+ }
+ }
+}
Propchange: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/JAXBErrorReceiver.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/Messages.properties?view=auto&rev=440644
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/Messages.properties (added)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/Messages.properties Wed Sep 6 00:40:23 2006
@@ -0,0 +1,4 @@
+FAIL_TO_GENERATE_TYPES = Fail to generate types
+
+
+
Propchange: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/Messages.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/Messages.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/NamespaceContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/NamespaceContextImpl.java?view=auto&rev=440644
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/NamespaceContextImpl.java (added)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/NamespaceContextImpl.java Wed Sep 6 00:40:23 2006
@@ -0,0 +1,66 @@
+/**
+ * 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.cxf.tools.wsdl2java.generator.jaxb;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.xml.sax.SAXException;
+
+public class NamespaceContextImpl implements NamespaceContext {
+ private Element element;
+
+ public NamespaceContextImpl(File file) {
+ Document document = null;
+ DocumentBuilderFactory docFact = DocumentBuilderFactory.newInstance();
+ docFact.setNamespaceAware(true);
+ try {
+ document = docFact.newDocumentBuilder().parse(file);
+ } catch (SAXException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ }
+ element = document.getDocumentElement();
+ }
+
+ public String getNamespaceURI(String prefix) {
+ return element.lookupNamespaceURI(prefix);
+
+ }
+
+ public String getPrefix(String namespaceURI) {
+ return element.lookupPrefix(namespaceURI);
+ }
+
+ public Iterator getPrefixes(String namespaceURI) {
+ return null;
+ }
+
+}
Propchange: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/NamespaceContextImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/TypesCodeWriter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/TypesCodeWriter.java?view=auto&rev=440644
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/TypesCodeWriter.java (added)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/TypesCodeWriter.java Wed Sep 6 00:40:23 2006
@@ -0,0 +1,73 @@
+/**
+ * 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.cxf.tools.wsdl2java.generator.jaxb;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.sun.codemodel.CodeWriter;
+import com.sun.codemodel.JPackage;
+
+public class TypesCodeWriter extends CodeWriter {
+
+ /** The target directory to put source code. */
+ private File target;
+
+ private List<String> excludeFileList = new ArrayList<String>();
+ private List<String> excludePkgList;
+
+ public TypesCodeWriter(File ftarget, List<String> excludePkgs) throws IOException {
+ target = ftarget;
+ excludePkgList = excludePkgs;
+ }
+
+ public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
+ return new FileOutputStream(getFile(pkg, fileName));
+ }
+
+ protected File getFile(JPackage pkg, String fileName) throws IOException {
+ String dirName = pkg.name().replace('.', File.separatorChar);
+ File dir = pkg.isUnnamed() ? target : new File(target, dirName);
+ if (!dir.exists()) {
+ dir.mkdirs();
+ }
+ File fn = new File(dir, fileName);
+ if (excludePkgList.contains(pkg.name())) {
+ excludeFileList.add(dirName + File.separator + fileName);
+ }
+ if (fn.exists() && !fn.delete()) {
+ throw new IOException(fn + ": Can't delete previous version");
+ }
+ return fn;
+ }
+
+ public void close() throws IOException {
+
+ }
+
+ public List<String> getExcludeFileList() {
+ return excludeFileList;
+ }
+
+}
Propchange: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/generator/jaxb/TypesCodeWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/Messages.properties?view=diff&rev=440644&r1=440643&r2=440644
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/Messages.properties (original)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/Messages.properties Wed Sep 6 00:40:23 2006
@@ -6,9 +6,8 @@
WRAPPER_STYLE_TWO_RETURN_TYPES = Wrapper style can not have two return types
CANNOT_FIND_WSDL = Can not find the wsdl from : {0}
BINDING_SPECIFY_ONE_PROTOCOL = Binding : {0} must specify one protocol
-FAIL_TO_CREATE_JAVA_MODEL = Can not create java model with wsdl model
-FAIL_TO_CREATE_JAXB_MODEL = File to create jaxb model
-FAIL_TO_GENERATE_TYPES = Fail to generate types
+FAIL_TO_CREATE_DATABINDING_MODEL = File to create databinding model
+
FAIL_TO_COMPILE_GENERATE_CODES = Fail to compile generated code
FAIL_TO_COPY_GENERATED_RESOURCE_FILE = Fail to copy generated resource file
FAIL_TO_WRITE_FILE = Fail to write file {0}
Modified: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessor.java?view=diff&rev=440644&r1=440643&r2=440644
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessor.java (original)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToJavaProcessor.java Wed Sep 6 00:40:23 2006
@@ -34,9 +34,6 @@
import javax.wsdl.PortType;
import javax.xml.namespace.QName;
-import com.sun.codemodel.JCodeModel;
-import com.sun.tools.xjc.api.S2JJAXBModel;
-
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.tools.common.PluginProfile;
import org.apache.cxf.tools.common.ToolConstants;
@@ -50,7 +47,6 @@
import org.apache.cxf.tools.wsdl2java.processor.internal.PortTypeProcessor;
import org.apache.cxf.tools.wsdl2java.processor.internal.SEIAnnotationProcessor;
import org.apache.cxf.tools.wsdl2java.processor.internal.ServiceProcessor;
-import org.apache.cxf.tools.wsdl2java.processor.internal.TypesCodeWriter;
public class WSDLToJavaProcessor extends WSDLToProcessor {
@@ -104,6 +100,7 @@
}
public void removeExcludeFiles() throws IOException {
+ excludeGenFiles = env.getExcludeFileList();
if (excludeGenFiles == null) {
return;
}
@@ -168,39 +165,20 @@
if (env.optionSet(ToolConstants.CFG_GEN_CLIENT) || env.optionSet(ToolConstants.CFG_GEN_SERVER)) {
return;
}
- if (rawJaxbModelGenCode == null) {
+ if (bindingGenerator == null) {
return;
}
- try {
- String dir = (String)env.get(ToolConstants.CFG_OUTPUTDIR);
-
- TypesCodeWriter fileCodeWriter = new TypesCodeWriter(new File(dir), excludePkgList);
-
- if (rawJaxbModelGenCode instanceof S2JJAXBModel && !nestedJaxbBinding) {
- S2JJAXBModel schem2JavaJaxbModel = (S2JJAXBModel)rawJaxbModelGenCode;
-
- JCodeModel jcodeModel = schem2JavaJaxbModel.generateCode(null, null);
- jcodeModel.build(fileCodeWriter);
- excludeGenFiles = fileCodeWriter.getExcludeFileList();
- }
-
- if (rawJaxbModelGenCode instanceof S2JJAXBModel && nestedJaxbBinding) {
- model.codeModel.build(fileCodeWriter);
- excludeGenFiles = fileCodeWriter.getExcludeFileList();
- }
-
- return;
- } catch (IOException e) {
- Message msg = new Message("FAIL_TO_GENERATE_TYPES", LOG);
- throw new ToolException(msg);
- }
+
+ bindingGenerator.generate();
+ //env.put(ToolConstants.BINDING_GENERATOR, bindingGenerator);
+
}
private JavaModel wsdlDefinitionToJavaModel(Definition definition) throws ToolException {
JavaModel javaModel = new JavaModel();
- getEnvironment().put(ToolConstants.RAW_JAXB_MODEL, getRawJaxbModel());
+ /* getEnvironment().put(ToolConstants.RAW_JAXB_MODEL, getRawJaxbModel());*/
javaModel.setJAXWSBinding(customizing(definition));
Modified: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToProcessor.java?view=diff&rev=440644&r1=440643&r2=440644
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToProcessor.java (original)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/WSDLToProcessor.java Wed Sep 6 00:40:23 2006
@@ -20,13 +20,10 @@
package org.apache.cxf.tools.wsdl2java.processor;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -49,31 +46,13 @@
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
-import javax.xml.transform.Result;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import org.xml.sax.InputSource;
-
-import com.sun.codemodel.JCodeModel;
-import com.sun.tools.xjc.BadCommandLineException;
-import com.sun.tools.xjc.ErrorReceiver;
-import com.sun.tools.xjc.Language;
-import com.sun.tools.xjc.ModelLoader;
-import com.sun.tools.xjc.Options;
+
import com.sun.tools.xjc.api.S2JJAXBModel;
-import com.sun.tools.xjc.api.XJC;
-import com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl;
import com.sun.tools.xjc.model.Model;
import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.helpers.WSDLHelper;
+import org.apache.cxf.tools.common.DataBindingGenerator;
import org.apache.cxf.tools.common.GeneratorPlugin;
import org.apache.cxf.tools.common.Processor;
import org.apache.cxf.tools.common.ProcessorEnvironment;
@@ -82,16 +61,12 @@
import org.apache.cxf.tools.common.extensions.jaxws.CustomizationParser;
import org.apache.cxf.tools.util.ClassCollector;
import org.apache.cxf.tools.util.FileWriterUtil;
-import org.apache.cxf.tools.util.JAXBUtils;
-import org.apache.cxf.tools.util.URIParserUtil;
import org.apache.cxf.tools.util.WSDLExtensionRegister;
import org.apache.cxf.tools.validator.internal.WSDL11Validator;
-import org.apache.cxf.tools.wsdl2java.processor.internal.ClassNameAllocatorImpl;
-import org.apache.cxf.tools.wsdl2java.processor.internal.JAXBBindingMerger;
-
+import org.apache.cxf.tools.wsdl2java.generator.jaxb.JAXBBindingGenerator;
import org.apache.velocity.app.Velocity;
-public class WSDLToProcessor implements Processor, com.sun.tools.xjc.api.ErrorListener {
+public class WSDLToProcessor implements Processor {
protected static final Logger LOG = LogUtils.getL7dLogger(WSDLToProcessor.class);
protected static final String WSDL_FILE_NAME_EXT = ".wsdl";
@@ -112,6 +87,7 @@
// For process nestedJaxbBinding
protected boolean nestedJaxbBinding;
protected Model model;
+ protected DataBindingGenerator bindingGenerator;
protected List<Schema> schemaList = new ArrayList<Schema>();
private List<Definition> importedDefinitions = new ArrayList<Definition>();
@@ -258,7 +234,7 @@
}
}
- private void initJAXBModel() {
+ private void initDataModel() {
schemaTargetNamespaces.clear();
extractSchema(wsdlDefinition);
for (Definition def : importedDefinitions) {
@@ -274,97 +250,25 @@
schemaTargetNamespaces.clear();
try {
- buildJaxbModel();
+ env.put(ToolConstants.WSDL_DEFINITION, wsdlDefinition);
+ env.put(ToolConstants.IMPORTED_DEFENITION, importedDefinitions);
+ env.put(ToolConstants.SCHEMA_LIST, schemaList);
+ env.put(ToolConstants.SCHEMA_TARGET_NAMESPACES, schemaTargetNamespaces);
+ env.put(ToolConstants.PORTTYPE_MAP, getPortTypes(wsdlDefinition));
+ bindingGenerator = (DataBindingGenerator)new JAXBBindingGenerator();
+ bindingGenerator.initialize(env);
+ env.put(ToolConstants.BINDING_GENERATOR, bindingGenerator);
+
} catch (Exception e) {
org.apache.cxf.common.i18n.Message msg =
- new org.apache.cxf.common.i18n.Message("FAIL_TO_CREATE_JAXB_MODEL",
+ new org.apache.cxf.common.i18n.Message("FAIL_TO_CREATE_DATABINDING_MODEL",
LOG);
LOG.log(Level.SEVERE, msg.toString());
throw new ToolException(msg, e);
}
}
- @SuppressWarnings("unchecked")
- private void buildJaxbModel() throws Exception {
- SchemaCompilerImpl schemaCompiler = (SchemaCompilerImpl)XJC.createSchemaCompiler();
-
- ClassNameAllocatorImpl allocator = new ClassNameAllocatorImpl(classColletor);
-
- allocator.setPortTypes(getPortTypes(wsdlDefinition).values(), env.mapPackageName(this.wsdlDefinition
- .getTargetNamespace()));
- schemaCompiler.setClassNameAllocator(allocator);
- schemaCompiler.setErrorListener(this);
-
- SchemaCompilerImpl schemaCompilerGenCode = schemaCompiler;
- String excludePackageName = "";
- if (env.isExcludeNamespaceEnabled()) {
- schemaCompilerGenCode = (SchemaCompilerImpl)XJC.createSchemaCompiler();
- schemaCompilerGenCode.setClassNameAllocator(allocator);
- schemaCompilerGenCode.setErrorListener(this);
- }
- List schemaSystemidList = new ArrayList();
- // this variable for jaxb binding nested in jaxws
- Options opt = new OptionsEx();
- int fileIDX = 0;
- for (Schema schema : schemaList) {
- String xsdFile = "schema" + (fileIDX++);
- Element schemaElement = schema.getElement();
- String targetNamespace = schemaElement.getAttribute("targetNamespace");
- if (StringUtils.isEmpty(targetNamespace)) {
- continue;
- }
-
- if (env.hasExcludeNamespace(targetNamespace)) {
- excludePackageName = env.getExcludePackageName(targetNamespace);
- if (excludePackageName != null) {
- excludePkgList.add(excludePackageName);
- } else {
- excludePkgList.add(URIParserUtil.getPackageName(targetNamespace));
- }
- }
- customizeSchema(schemaElement, targetNamespace);
- String systemid = schema.getDocumentBaseURI();
- if (schemaSystemidList.contains(systemid)) {
- systemid = schema.getDocumentBaseURI() + "#" + targetNamespace;
- }
- schemaSystemidList.add(systemid);
- schemaCompiler.parseSchema(systemid, schemaElement);
- schemaCompilerGenCode.parseSchema(systemid, schemaElement);
- if (nestedJaxbBinding) {
- File file = File.createTempFile(xsdFile, ".xsd");
- Result result = new StreamResult(file);
- DOMSource source = new DOMSource(schemaElement);
-
- TransformerFactory.newInstance().newTransformer().transform(source, result);
- InputSource insource = new InputSource((InputStream)new FileInputStream(file));
- insource.setSystemId(systemid);
- opt.setSchemaLanguage(Language.XMLSCHEMA);
- opt.addGrammar(file);
-
- }
-
- }
-
- Collection<InputSource> jaxbBindingFiles = env.getJaxbBindingFile().values();
- for (InputSource bindingFile : jaxbBindingFiles) {
- schemaCompiler.parseSchema(bindingFile);
- if (env.isExcludeNamespaceEnabled()) {
- schemaCompilerGenCode.parseSchema(bindingFile);
- }
- }
- rawJaxbModel = schemaCompiler.bind();
- if (env.isExcludeNamespaceEnabled()) {
- rawJaxbModelGenCode = schemaCompilerGenCode.bind();
- } else {
- rawJaxbModelGenCode = rawJaxbModel;
- }
- if (nestedJaxbBinding) {
- opt.classNameAllocator = allocator;
- model = ModelLoader.load(opt, new JCodeModel(), new JAXBErrorReceiver());
- model.generateCode(opt, new JAXBErrorReceiver());
- }
-
- }
+
@SuppressWarnings("unchecked")
protected Map<QName, PortType> getPortTypes(Definition definition) {
@@ -406,40 +310,8 @@
return true;
}
}
-
- private void customizeSchema(Element schema, String targetNamespace) {
- String userPackage = env.mapPackageName(targetNamespace);
- if (env.hasExcludeNamespace(targetNamespace) && env.getExcludePackageName(targetNamespace) != null) {
- // generate excluded namespace types classes with specified package
- // name
- userPackage = env.getExcludePackageName(targetNamespace);
- }
- if (!isSchemaParsed(targetNamespace) && !StringUtils.isEmpty(userPackage)) {
- Node jaxbBindings = JAXBUtils.innerJaxbPackageBinding(schema, userPackage);
- schema.appendChild(jaxbBindings);
- }
-
- int nodeListLen = schema.getElementsByTagNameNS(ToolConstants.SCHEMA_URI, "import").getLength();
- for (int i = 0; i < nodeListLen; i++) {
- removeImportElement(schema);
- }
- JAXBBindingMerger jaxbBindingMerger = new JAXBBindingMerger();
- jaxbBindingMerger.mergeJaxwsBinding(schema, env);
-
- if (jaxbBindingMerger.isMerged()) {
- nestedJaxbBinding = true;
- }
- }
-
- private void removeImportElement(Element element) {
- NodeList nodeList = element.getElementsByTagNameNS(ToolConstants.SCHEMA_URI, "import");
- if (nodeList.getLength() > 0) {
- Node importNode = nodeList.item(0);
- Node schemaNode = importNode.getParentNode();
- schemaNode.removeChild(importNode);
- }
- }
-
+
+
private boolean isSchemaImported(Schema schema) {
return schemaList.contains(schema);
}
@@ -483,13 +355,11 @@
initVelocity();
classColletor = new ClassCollector();
env.put(ToolConstants.GENERATED_CLASS_COLLECTOR, classColletor);
- initJAXBModel();
+ initDataModel();
}
- public S2JJAXBModel getRawJaxbModel() {
- return this.rawJaxbModel;
- }
+
public Definition getWSDLDefinition() {
return this.wsdlDefinition;
@@ -519,33 +389,7 @@
return this.env;
}
- public void error(org.xml.sax.SAXParseException exception) {
- if (this.env.isVerbose()) {
- exception.printStackTrace();
- } else {
- System.err.println("Parsing schema error: \n" + exception.toString());
- }
- }
-
- public void fatalError(org.xml.sax.SAXParseException exception) {
- if (this.env.isVerbose()) {
- exception.printStackTrace();
- } else {
- System.err.println("Parsing schema fatal error: \n" + exception.toString());
- }
- }
-
- public void info(org.xml.sax.SAXParseException exception) {
- if (this.env.isVerbose()) {
- System.err.println("Parsing schema info: " + exception.toString());
- }
- }
-
- public void warning(org.xml.sax.SAXParseException exception) {
- if (this.env.isVerbose()) {
- System.err.println("Parsing schema warning " + exception.toString());
- }
- }
+
public void checkSupported(Definition def) throws ToolException {
if (isSOAP12Binding(wsdlDefinition)) {
@@ -607,59 +451,6 @@
return false;
}
- static class OptionsEx extends Options {
-
- protected Mode mode = Mode.CODE;
-
- protected int parseArgument(String[] args, int i) throws BadCommandLineException {
-
- return super.parseArgument(args, i);
- }
- }
-
- private static enum Mode {
- CODE,
- BGM,
- SIGNATURE,
- FOREST,
- DRYRUN,
- ZIP,
- }
-
- class JAXBErrorReceiver extends ErrorReceiver {
- public void warning(org.xml.sax.SAXParseException saxEx) throws com.sun.tools.xjc.AbortException {
- if (env.isVerbose()) {
- saxEx.printStackTrace();
- } else {
- System.err.println("Use jaxb customization binding file to generate types warring "
- + saxEx.getMessage());
- }
-
- }
-
- public void error(org.xml.sax.SAXParseException saxEx) throws com.sun.tools.xjc.AbortException {
- if (env.isVerbose()) {
- saxEx.printStackTrace();
- } else {
- System.err.println("Use jaxb customization binding file to generate types error "
- + saxEx.getMessage());
- }
- }
-
- public void info(org.xml.sax.SAXParseException saxEx) {
- if (env.isVerbose()) {
- saxEx.printStackTrace();
- }
- }
-
- public void fatalError(org.xml.sax.SAXParseException saxEx) throws com.sun.tools.xjc.AbortException {
- if (env.isVerbose()) {
- saxEx.printStackTrace();
- } else {
- System.err.println("Use jaxb customization binding file to generate types fatal error "
- + saxEx.getMessage());
- }
- }
- }
+
}
Modified: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/AbstractProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/AbstractProcessor.java?view=diff&rev=440644&r1=440643&r2=440644
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/AbstractProcessor.java (original)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/AbstractProcessor.java Wed Sep 6 00:40:23 2006
@@ -22,19 +22,24 @@
import java.util.logging.Logger;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.tools.common.DataBindingGenerator;
import org.apache.cxf.tools.common.ProcessorEnvironment;
import org.apache.cxf.tools.common.ToolConstants;
import org.apache.cxf.tools.util.ClassCollector;
public abstract class AbstractProcessor {
- protected static final Logger LOG = LogUtils.getL7dLogger(AbstractProcessor .class);
+ protected static final Logger LOG = LogUtils.getL7dLogger(AbstractProcessor.class);
protected ProcessorEnvironment env;
protected ClassCollector collector;
+ protected DataBindingGenerator dataBinder;
+
public AbstractProcessor(ProcessorEnvironment penv) {
this.env = penv;
this.collector = (ClassCollector)env.get(ToolConstants.GENERATED_CLASS_COLLECTOR);
+ dataBinder = (DataBindingGenerator)env.get(ToolConstants.BINDING_GENERATOR);
+
}
}
Modified: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/FaultProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/FaultProcessor.java?view=diff&rev=440644&r1=440643&r2=440644
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/FaultProcessor.java (original)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/FaultProcessor.java Wed Sep 6 00:40:23 2006
@@ -26,11 +26,7 @@
import javax.wsdl.Message;
import javax.wsdl.Part;
-import com.sun.tools.xjc.api.S2JJAXBModel;
-
import org.apache.cxf.tools.common.ProcessorEnvironment;
-
-import org.apache.cxf.tools.common.ToolConstants;
import org.apache.cxf.tools.common.ToolException;
import org.apache.cxf.tools.common.model.JavaException;
import org.apache.cxf.tools.common.model.JavaExceptionClass;
@@ -95,7 +91,7 @@
expClass.setName(name);
expClass.setNamespace(namespace);
expClass.setPackageName(packageName);
- S2JJAXBModel jaxbModel = (S2JJAXBModel)env.get(ToolConstants.RAW_JAXB_MODEL);
+
for (Part part : faultValues) {
String fName;
String fNamespace;
@@ -117,7 +113,7 @@
}
- String fType = ProcessorUtil.resolvePartType(part, jaxbModel);
+ String fType = ProcessorUtil.getType(part, env, false);
String fPackageName = ProcessorUtil.parsePackageName(fNamespace, env
.mapPackageName(fNamespace));
@@ -127,10 +123,11 @@
fField.setQName(ProcessorUtil.getElementName(part));
if (!method.getInterface().getPackageName().equals(fPackageName)) {
- fField.setClassName(ProcessorUtil.getFullClzName(part, env, this.collector));
+ fField.setClassName(ProcessorUtil.getFullClzName(part,
+ env, this.collector, false));
}
if (!fType.equals(ProcessorUtil.resolvePartType(part))) {
- fField.setClassName(ProcessorUtil.resolvePartType(part, jaxbModel, true));
+ fField.setClassName(ProcessorUtil.getType(part, env, true));
}
expClass.addField(fField);
Modified: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/Messages.properties?view=diff&rev=440644&r1=440643&r2=440644
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/Messages.properties (original)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/Messages.properties Wed Sep 6 00:40:23 2006
@@ -15,5 +15,5 @@
GENERATE_TYPES_ERROR = Generate types error
FAIL_TO_GET_JAXBINDINGNODE_FROM_JAXWSBINDING = Fail to get jaxb binding information from jaxws binding file
NO_INPUT_MESSAGE=Problem outputting method for {0} as no input message was found
-INVALID_MEP = Invalid WSDL, wsdl:operation {0} is not request-response or one-way
+INVALID_MEP = Invalid WSDL,wsdl:operation: "{0}" is not request-response or one-way
Modified: incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/OperationProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/OperationProcessor.java?view=diff&rev=440644&r1=440643&r2=440644
==============================================================================
--- incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/OperationProcessor.java (original)
+++ incubator/cxf/trunk/tools/wsdl2java/src/main/java/org/apache/cxf/tools/wsdl2java/processor/internal/OperationProcessor.java Wed Sep 6 00:40:23 2006
@@ -156,6 +156,7 @@
if (method.getSoapStyle() == SOAPBinding.Style.RPC) {
name = method.getReturn().getName();
targetNamespace = method.getInterface().getNamespace();
+
}
if (method.getSoapStyle() == SOAPBinding.Style.DOCUMENT) {
if (method.getReturn().getQName() != null) {
@@ -262,8 +263,9 @@
// RULE No.4 and No5:
// wrapper element should be pure complex type
//
- if (ProcessorUtil.getBlock(inputPart, env) == null
- || ProcessorUtil.getBlock(outputPart, env) == null) {
+
+ if (dataBinder.getBlock(inputPart) == null
+ || dataBinder.getBlock(outputPart) == null) {
return false;
}
@@ -273,7 +275,8 @@
wrapperRequest.setType(ProcessorUtil.getPartType(inputPart));
wrapperRequest.setTargetNamespace(ProcessorUtil.resolvePartNamespace(inputPart));
- wrapperRequest.setClassName(ProcessorUtil.getFullClzName(inputPart, this.env, this.collector));
+ wrapperRequest.setClassName(ProcessorUtil.getFullClzName(inputPart,
+ this.env, this.collector, false));
}
if (outputPart != null) {
@@ -282,7 +285,8 @@
wrapperResponse.setType(ProcessorUtil.getPartType(outputPart));
wrapperResponse.setTargetNamespace(ProcessorUtil.resolvePartNamespace(outputPart));
- wrapperResponse.setClassName(ProcessorUtil.getFullClzName(outputPart, this.env, this.collector));
+ wrapperResponse.setClassName(ProcessorUtil.getFullClzName(outputPart,
+ this.env, this.collector, false));
}