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 de...@apache.org on 2006/07/12 06:13:27 UTC
svn commit: r421112 - in /webservices/axis2/trunk/java/modules:
adb/src/org/apache/axis2/databinding/utils/
codegen/src/org/apache/axis2/rpc/receivers/
common/src/org/apache/axis2/i18n/ core/src/org/apache/axis2/context/
core/src/org/apache/axis2/engin...
Author: deepal
Date: Tue Jul 11 21:13:26 2006
New Revision: 421112
URL: http://svn.apache.org/viewvc?rev=421112&view=rev
Log:
- all the service which are deployed in application scope , then the init method will be called when system start
- All the elements in the response is qualified (this fixed few JIRAs)
Modified:
webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/BeanUtil.java
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCUtil.java
webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/i18n/resource.properties
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AxisConfiguration.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/DependencyManager.java
webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/SchemaGenerator.java
Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/BeanUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/BeanUtil.java?rev=421112&r1=421111&r2=421112&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/BeanUtil.java (original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/BeanUtil.java Tue Jul 11 21:13:26 2006
@@ -55,14 +55,18 @@
JamServiceFactory factory = JamServiceFactory.getInstance();
JamServiceParams jam_service_parms = factory.createServiceParams();
jam_service_parms.addClassLoader(beanObject.getClass().getClassLoader());
+// beanObject.getClass().isArray()
+
jam_service_parms.includeClass(beanObject.getClass().getName());
JamService service = factory.createService(jam_service_parms);
JamClassIterator jClassIter = service.getClasses();
- JClass jClass = null;
- while (jClassIter.hasNext()) {
+ JClass jClass ;
+ if (jClassIter.hasNext()) {
jClass = (JClass) jClassIter.next();
-
+ } else {
+ throw new AxisFault("No service class found , exception from JAM");
}
+
// properties from JAM
JProperty properties [] = jClass.getDeclaredProperties();
Arrays.sort(properties);
@@ -89,7 +93,7 @@
if (SimpleTypeMapper.isSimpleType(ptype)) {
Object value = propDesc.getReadMethod().invoke(beanObject,
(Object[]) null);
- object.add(propDesc.getName());
+ object.add(new QName(beanName.getNamespaceURI(),propDesc.getName(),beanName.getPrefix()));
object.add(value == null ? null : value.toString());
} else if (ptype.isArray()) {
Object value [] = (Object[]) propDesc.getReadMethod().invoke(beanObject,
@@ -97,13 +101,13 @@
if (SimpleTypeMapper.isSimpleType(ptype.getComponentType())) {
for (int j = 0; j < value.length; j++) {
Object o = value[j];
- object.add(propDesc.getName());
+ object.add(new QName(beanName.getNamespaceURI(),propDesc.getName(),beanName.getPrefix()));
object.add(o == null ? null : o.toString());
}
} else {
for (int j = 0; j < value.length; j++) {
Object o = value[j];
- object.add(new QName(propDesc.getName()));
+ object.add(new QName(beanName.getNamespaceURI(),propDesc.getName(),beanName.getPrefix()));
object.add(o);
}
}
@@ -119,10 +123,10 @@
for (int j = 0; j < objList.size(); j++) {
Object o = objList.get(j);
if (SimpleTypeMapper.isSimpleType(o)) {
- object.add(propDesc.getName());
+ object.add(new QName(beanName.getNamespaceURI(),propDesc.getName(),beanName.getPrefix()));
object.add(o);
} else {
- object.add(new QName(propDesc.getName()));
+ object.add(new QName(beanName.getNamespaceURI(),propDesc.getName(),beanName.getPrefix()));
object.add(o);
}
}
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java?rev=421112&r1=421111&r2=421112&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java Tue Jul 11 21:13:26 2006
@@ -37,6 +37,7 @@
import org.apache.commons.logging.LogFactory;
import javax.xml.namespace.QName;
+import java.lang.reflect.Array;
import java.lang.reflect.Method;
public class RPCMessageReceiver extends AbstractInOutSyncMessageReceiver {
@@ -138,7 +139,20 @@
OMElement bodyChild = RPCUtil.getResponseElement(resName, (Object[]) resObject);
envelope.getBody().addChild(bodyChild);
} else {
- RPCUtil.processResponse(fac, resObject, bodyContent, ns, envelope, method);
+ if (resObject.getClass().isArray()) {
+ int length = Array.getLength(resObject);
+ Object objArray [] = new Object[length];
+ for (int i = 0; i < length; i++) {
+ objArray[i] = Array.get(resObject, i);
+ }
+ QName resName = new QName(service.getSchematargetNamespace(),
+ method.getName() + "Response",
+ service.getSchematargetNamespacePrefix());
+ OMElement bodyChild = RPCUtil.getResponseElementForArray(resName, objArray);
+ envelope.getBody().addChild(bodyChild);
+ } else {
+ RPCUtil.processResponse(fac, resObject, bodyContent, ns, envelope, method);
+ }
}
outMessage.setEnvelope(envelope);
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCUtil.java?rev=421112&r1=421111&r2=421112&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCUtil.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCUtil.java Tue Jul 11 21:13:26 2006
@@ -48,7 +48,7 @@
OMElement result = (OMElement) resObject;
bodyContent = fac.createOMElement(
method.getName() + "Response", ns);
- OMElement resWrapper = fac.createOMElement(RETURN_WRAPPER,ns.getName(),
+ OMElement resWrapper = fac.createOMElement(RETURN_WRAPPER, ns.getName(),
ns.getPrefix());
resWrapper.addChild(result);
bodyContent.addChild(resWrapper);
@@ -84,6 +84,11 @@
}
public static OMElement getResponseElement(QName resname, Object [] objs) {
+ return BeanUtil.getOMElement(resname, objs,
+ new QName(resname.getNamespaceURI(), RETURN_WRAPPER, resname.getPrefix()));
+ }
+
+ public static OMElement getResponseElementForArray(QName resname, Object [] objs) {
return BeanUtil.getOMElement(resname, objs,
new QName(resname.getNamespaceURI(), RETURN_WRAPPER, resname.getPrefix()));
}
Modified: webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/i18n/resource.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/i18n/resource.properties?rev=421112&r1=421111&r2=421112&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/i18n/resource.properties (original)
+++ webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/i18n/resource.properties Tue Jul 11 21:13:26 2006
@@ -209,6 +209,7 @@
checkingserviceforepr=Checking for Service using toEPR's address : {0}
checkingrelatesto=Checking RelatesTo : {0}
twoservicecannothavesamename=Two services can not have same name, a service with {0} already exists in the system
+cannotaddapplicationscopeservice=can not add service with application scope onece the systen start
invalidservicegroupname=invalid service group name : {0}
modulealredyengagedglobaly=Attempt to engage an already engaged module {0}
refertoinvalidmodule=Refer to invalid module , has not bean deployed yet !
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java?rev=421112&r1=421111&r2=421112&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java Tue Jul 11 21:13:26 2006
@@ -159,9 +159,7 @@
* service group context
*/
String maxScope = SessionUtils.calculateMaxScopeForServiceGroup(serviceGroupContext.getDescription());
- if (Constants.SCOPE_APPLICATION.equals(maxScope)) {
- addServiceGroupContextintoApplicatoionScopeTable(serviceGroupContext);
- } else if (Constants.SCOPE_SOAP_SESSION.equals(maxScope)) {
+ if (Constants.SCOPE_SOAP_SESSION.equals(maxScope)) {
registerServiceGroupContext(serviceGroupContext);
} else if (Constants.SCOPE_TRANSPORT_SESSION.equals(maxScope)) {
if (sessionContext != null) {
@@ -207,7 +205,7 @@
cleanupServiceGroupContexts();
}
- private synchronized void addServiceGroupContextintoApplicatoionScopeTable(
+ public synchronized void addServiceGroupContextintoApplicatoionScopeTable(
ServiceGroupContext serviceGroupContext) {
applicationSessionServiceGroupContextTable.put(
serviceGroupContext.getDescription().getServiceGroupName(), serviceGroupContext);
@@ -220,7 +218,6 @@
/**
* Gets a OperationContext given a Message ID.
*
- * @param msgctx
* @return Returns OperationContext <code>OperationContext<code>
*/
public OperationContext getOperationContext(String id) {
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java?rev=421112&r1=421111&r2=421112&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java Tue Jul 11 21:13:26 2006
@@ -23,13 +23,16 @@
import org.apache.axis2.deployment.URLBasedAxisConfigurator;
import org.apache.axis2.deployment.util.Utils;
import org.apache.axis2.description.AxisModule;
+import org.apache.axis2.description.AxisServiceGroup;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.engine.AxisConfigurator;
+import org.apache.axis2.engine.DependencyManager;
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.modules.Module;
import org.apache.axis2.transport.TransportSender;
+import org.apache.axis2.util.SessionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -64,7 +67,22 @@
axisConfigurator.engageGlobalModules();
axisConfigurator.loadServices();
addModuleService(axisConfig);
+ initApplicationScopeServices(configContext);
+ axisConfig.setStart(true);
return configContext;
+ }
+
+ private static void initApplicationScopeServices(ConfigurationContext configCtx) throws AxisFault {
+ Iterator serviceGroups = configCtx.getAxisConfiguration().getServiceGroups();
+ while (serviceGroups.hasNext()) {
+ AxisServiceGroup axisServiceGroup = (AxisServiceGroup) serviceGroups.next();
+ String maxScope = SessionUtils.calculateMaxScopeForServiceGroup(axisServiceGroup);
+ if (Constants.SCOPE_APPLICATION.equals(maxScope)) {
+ ServiceGroupContext serviceGroupContext = new ServiceGroupContext(configCtx, axisServiceGroup);
+ configCtx.addServiceGroupContextintoApplicatoionScopeTable(serviceGroupContext);
+ DependencyManager.initService(serviceGroupContext);
+ }
+ }
}
public static void addModuleService(AxisConfiguration axisConfig) throws AxisFault {
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AxisConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AxisConfiguration.java?rev=421112&r1=421111&r2=421112&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AxisConfiguration.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AxisConfiguration.java Tue Jul 11 21:13:26 2006
@@ -17,10 +17,12 @@
package org.apache.axis2.engine;
import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
import org.apache.axis2.deployment.util.PhasesInfo;
import org.apache.axis2.description.*;
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.phaseresolver.PhaseResolver;
+import org.apache.axis2.util.SessionUtils;
import org.apache.axis2.util.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -97,6 +99,9 @@
// to keep track of need to manage transport session or not
private boolean manageTransportSession;
+ //to keep tarck of system start or not
+ private boolean start;
+
/**
* Constructor AxisConfigurationImpl.
*/
@@ -118,13 +123,13 @@
}
public void addMessageReceiver(String mepURL,
- MessageReceiver messageReceiver) {
+ MessageReceiver messageReceiver) {
messageReceivers.put(mepURL, messageReceiver);
}
/**
* Method addModule.
- *
+ *
* @param module
* @throws AxisFault
*/
@@ -146,7 +151,7 @@
/**
* To remove a given module from the system
- *
+ *
* @param module
*/
public void removeModule(QName module) {
@@ -156,7 +161,7 @@
/**
* Adds module configuration, if there is moduleConfig tag in service.
- *
+ *
* @param moduleConfiguration
*/
public void addModuleConfig(ModuleConfiguration moduleConfiguration) {
@@ -170,7 +175,7 @@
/**
* Method addService.
- *
+ *
* @param service
* @throws AxisFault
*/
@@ -186,7 +191,7 @@
* This method will check whethere for a given service , can we ganerate
* valid wsdl or not. So if user derop a wsdl we print that out , else if
* all the operation uses RPC message recivers we will generate wsdl
- *
+ *
* @param axisService
*/
private void isWSDLEnable(AxisService axisService) {
@@ -205,7 +210,7 @@
if (!("org.apache.axis2.rpc.receivers.RPCMessageReceiver"
.equals(messageReceiverClass)
|| "org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"
- .equals(messageReceiverClass) || "org.apache.axis2.rpc.receivers.RPCInOutAsyncMessageReceiver"
+ .equals(messageReceiverClass) || "org.apache.axis2.rpc.receivers.RPCInOutAsyncMessageReceiver"
.equals(messageReceiverClass))) {
axisService.setWsdlfound(false);
return;
@@ -220,6 +225,10 @@
public synchronized void addServiceGroup(AxisServiceGroup axisServiceGroup)
throws AxisFault {
+ String maxScope = SessionUtils.calculateMaxScopeForServiceGroup(axisServiceGroup);
+ if (start && Constants.SCOPE_APPLICATION.equals(maxScope)) {
+ throw new AxisFault(Messages.getMessage("cannotaddapplicationscopeservice"));
+ }
Iterator services = axisServiceGroup.getServices();
axisServiceGroup.setParent(this);
AxisService description;
@@ -283,7 +292,7 @@
/**
* Method addTransportIn.
- *
+ *
* @param transport
* @throws AxisFault
*/
@@ -299,7 +308,7 @@
/**
* Method addTransportOut.
- *
+ *
* @param transport
* @throws AxisFault
*/
@@ -318,7 +327,7 @@
* or if the module name contains version number in it then it will engage
* the correct module. Both of the below two cases are valid 1.
* engageModule("addressing"); 2. engageModule("addressing-1.23");
- *
+ *
* @param moduleref
* @throws AxisFault
*/
@@ -334,7 +343,7 @@
/**
* Engages a module using give name and its version ID.
- *
+ *
* @param moduleName
* @param versionID
* @throws AxisFault
@@ -383,7 +392,7 @@
/**
* To dis-engage module from the system, this will remove all the handlers
* belongs to this module from all the handler chains
- *
+ *
* @param module
*/
public void disEngageModule(AxisModule module) {
@@ -439,7 +448,7 @@
/**
* Method removeService.
- *
+ *
* @param name
* @throws AxisFault
*/
@@ -453,7 +462,7 @@
/**
* Method getEngagedModules.
- *
+ *
* @return Collection
*/
public Collection getEngagedModules() {
@@ -495,7 +504,7 @@
* nane does not have version string in it then try to check whether default
* vresion of module available in the sytem for the give name , if so return
* that
- *
+ *
* @param name
* @return Returns ModuleDescription.
*/
@@ -551,7 +560,7 @@
/**
* Method getService.
- *
+ *
* @param name
* @return Returns AxisService.
*/
@@ -572,7 +581,7 @@
/**
* Service can start and stop , if once stop we can not acess that , so we
* need a way to get the service even if service is not active
- *
+ *
* @return AxisService
*/
public AxisService getServiceForActivation(String serviceName) {
@@ -694,7 +703,7 @@
* or by using axis2.xml . The default module version is important if user
* asks to engage a module without given version ID, in which case, we will
* engage the default version.
- *
+ *
* @param moduleName
* @param moduleVersion
*/
@@ -774,5 +783,17 @@
policySupportedModules.put(namespaces[i], modulesList);
}
}
+ }
+
+ public ArrayList getObserversList() {
+ return observersList;
+ }
+
+ public boolean isStart() {
+ return start;
+ }
+
+ public void setStart(boolean start) {
+ this.start = start;
}
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/DependencyManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/DependencyManager.java?rev=421112&r1=421111&r2=421112&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/DependencyManager.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/DependencyManager.java Tue Jul 11 21:13:26 2006
@@ -20,9 +20,16 @@
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.OperationContext;
import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.context.ServiceGroupContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisServiceGroup;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.i18n.Messages;
+import org.apache.axis2.receivers.AbstractMessageReceiver;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.Iterator;
/**
* If the service implementation has an init method with 1 or 2 message context as its parameters, then
@@ -66,7 +73,7 @@
ServiceContext serviceContext) throws AxisFault {
try {
Class classToLoad = obj.getClass();
- // We can not call classToLoad.getDeclaredMethed() , since there
+ // We can not call classToLoad.getDeclaredMethed() , since there
// can be insatnce where mutiple services extends using one class
// just for init and other reflection methods
Method[] methods = classToLoad.getMethods();
@@ -90,14 +97,47 @@
}
}
+ /**
+ * To init all the services in application scope
+ *
+ * @param serviceGroupContext
+ * @throws AxisFault
+ */
+ public static void initService(ServiceGroupContext serviceGroupContext) throws AxisFault {
+ AxisServiceGroup serviceGroup = serviceGroupContext.getDescription();
+ Iterator serviceItr = serviceGroup.getServices();
+ while (serviceItr.hasNext()) {
+ AxisService axisService = (AxisService) serviceItr.next();
+ ServiceContext serviceContext = serviceGroupContext.getServiceContext(axisService);
+ AxisService service = serviceContext.getAxisService();
+ ClassLoader classLoader = service.getClassLoader();
+ Parameter implInfoParam = service.getParameter(AbstractMessageReceiver.SERVICE_CLASS);
+ if (implInfoParam != null) {
+ try {
+ Class implClass = Class.forName(((String) implInfoParam.getValue()).trim(), true,
+ classLoader);
+ Object serviceImpl = implClass.newInstance();
+ serviceContext.setProperty(ServiceContext.SERVICE_OBJECT, serviceImpl);
+ initServiceClass(serviceImpl, serviceContext);
+ } catch (Exception e) {
+ new AxisFault(e);
+ }
+ } else {
+ throw new AxisFault(Messages.getMessage("paramIsNotSpecified", "SERVICE_OBJECT_SUPPLIER"));
+ }
+ }
+
+
+ }
+
public static void destroyServiceObject(ServiceContext serviceContext) throws AxisFault {
try {
Object obj = serviceContext.getProperty(ServiceContext.SERVICE_OBJECT);
if (obj != null) {
Class classToLoad = obj.getClass();
- // We can not call classToLoad.getDeclaredMethed() , since there
- // can be insatnce where mutiple services extends using one class
- // just for init and other reflection methods
+ // We can not call classToLoad.getDeclaredMethed() , since there
+ // can be insatnce where mutiple services extends using one class
+ // just for init and other reflection methods
Method[] methods = classToLoad.getMethods();
for (int i = 0; i < methods.length; i++) {
@@ -118,7 +158,7 @@
} catch (InvocationTargetException e) {
throw new AxisFault(e);
}
-
}
+
}
Modified: webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/SchemaGenerator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/SchemaGenerator.java?rev=421112&r1=421111&r2=421112&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/SchemaGenerator.java (original)
+++ webservices/axis2/trunk/java/modules/java2wsdl/src/org/apache/ws/java2wsdl/SchemaGenerator.java Tue Jul 11 21:13:26 2006
@@ -1,7 +1,5 @@
package org.apache.ws.java2wsdl;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.ws.commons.schema.*;
import org.apache.ws.java2wsdl.bytecode.MethodTable;
import org.apache.ws.java2wsdl.utils.TypeTable;
@@ -27,8 +25,7 @@
*
*/
-public class SchemaGenerator implements Java2WSDLConstants
-{
+public class SchemaGenerator implements Java2WSDLConstants {
public static final String NAME_SPACE_PREFIX = "stn_";
@@ -40,7 +37,6 @@
protected XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection();
- private static final Log log = LogFactory.getLog(SchemaGenerator.class);
private ClassLoader classLoader;
@@ -57,12 +53,10 @@
private String schemaTargetNameSpace;
private String schema_namespace_prefix;
-
+
private String attrFormDefault = null;
-
- private String elementFormDefault = null;
- private Class clazz;
+ private String elementFormDefault = null;
private ArrayList excludeMethods = new ArrayList();
@@ -72,7 +66,7 @@
this.classLoader = loader;
this.className = className;
- clazz = Class.forName(className, true, loader);
+ Class clazz = Class.forName(className, true, loader);
methodTable = new MethodTable(clazz);
if (schematargetNamespace != null
@@ -131,9 +125,8 @@
// since we do not support overload
HashMap uniqueMethods = new HashMap();
- XmlSchemaComplexType methodSchemaType = null;
+ XmlSchemaComplexType methodSchemaType;
XmlSchemaSequence sequence = null;
- QName methodPartSchemaTypeName = null;
for (int i = 0; i < methods.length; i++) {
JMethod jMethod = methods[i];
@@ -155,31 +148,28 @@
}
uniqueMethods.put(jMethod.getSimpleName(), jMethod);
//create the schema type for the method wrapper
-
+
uniqueMethods.put(jMethod.getSimpleName(), jMethod);
JParameter [] paras = jMethod.getParameters();
String parameterNames [] = null;
- if (paras.length > 0)
- {
+ if (paras.length > 0) {
parameterNames = methodTable.getParameterNames(methodName);
sequence = new XmlSchemaSequence();
-
+
methodSchemaType = createSchemaTypeForMethodPart(jMethod.getSimpleName());
methodSchemaType.setParticle(sequence);
}
-
- for (int j = 0; j < paras.length; j++)
- {
+
+ for (int j = 0; j < paras.length; j++) {
JParameter methodParameter = paras[j];
JClass paraType = methodParameter.getType();
- generateSchemaForType(sequence, paraType,
- ( parameterNames != null && parameterNames[j] != null )? parameterNames[j] : methodParameter.getSimpleName());
+ generateSchemaForType(sequence, paraType,
+ (parameterNames != null && parameterNames[j] != null) ? parameterNames[j] : methodParameter.getSimpleName());
}
// for its return type
JClass returnType = jMethod.getReturnType();
-
- if (!returnType.isVoidType())
- {
+
+ if (!returnType.isVoidType()) {
methodSchemaType = createSchemaTypeForMethodPart(jMethod.getSimpleName() + RESPONSE);
sequence = new XmlSchemaSequence();
methodSchemaType.setParticle(sequence);
@@ -210,11 +200,10 @@
/**
* @param javaType
*/
- private QName generateSchema(JClass javaType)
- {
+ private QName generateSchema(JClass javaType) {
String name = javaType.getQualifiedName();
QName schemaTypeName = typeTable.getComplexSchemaType(name);
- if ( schemaTypeName == null) {
+ if (schemaTypeName == null) {
String simpleName = javaType.getSimpleName();
String packageName = javaType.getContainingPackage().getQualifiedName();
@@ -259,7 +248,7 @@
sequence.getItems().add(elt1);
if (isArryType) {
elt1.setMaxOccurs(Long.MAX_VALUE);
- elt1.setMinOccurs(0);
+ elt1.setMinOccurs(1);
}
} else {
if (isArryType) {
@@ -273,7 +262,7 @@
sequence.getItems().add(elt1);
if (isArryType) {
elt1.setMaxOccurs(Long.MAX_VALUE);
- elt1.setMinOccurs(0);
+ elt1.setMinOccurs(1);
}
if (!xmlSchema.getPrefixToNamespaceMap().values().
@@ -290,101 +279,89 @@
return schemaTypeName;
}
- private QName generateSchemaForType(XmlSchemaSequence sequence, JClass type, String partName) throws Exception
- {
+ private QName generateSchemaForType(XmlSchemaSequence sequence, JClass type, String partName) throws Exception {
boolean isArrayType = type.isArrayType();
- if ( isArrayType )
- {
+ if (isArrayType) {
type = type.getArrayComponentType();
- }
-
+ }
+
String classTypeName = type.getQualifiedName();
-
+
QName schemaTypeName = typeTable.getSimpleSchemaTypeName(classTypeName);
- if ( schemaTypeName == null )
- {
+ if (schemaTypeName == null) {
schemaTypeName = generateSchema(type);
- addContentToMethodSchemaType(sequence,
- schemaTypeName,
- partName,
- type.isArrayType());
+ addContentToMethodSchemaType(sequence,
+ schemaTypeName,
+ partName,
+ isArrayType);
//addImport((XmlSchema)schemaMap.get(schemaTargetNameSpace), schemaTypeName);
String schemaNamespace = Java2WSDLUtils.schemaNamespaceFromPackageName(type.getContainingPackage().
- getQualifiedName()).toString();
- addImport(getXmlSchema(schemaNamespace),schemaTypeName);
-
- }
- else
- {
- addContentToMethodSchemaType(sequence,
- schemaTypeName,
- partName,
- type.isArrayType());
+ getQualifiedName()).toString();
+ addImport(getXmlSchema(schemaNamespace), schemaTypeName);
+
+ } else {
+ addContentToMethodSchemaType(sequence,
+ schemaTypeName,
+ partName,
+ isArrayType);
}
-
+
return schemaTypeName;
}
-
- private void addContentToMethodSchemaType(XmlSchemaSequence sequence,
- QName schemaTypeName,
- String paraName,
- boolean isArray )
- {
+
+ private void addContentToMethodSchemaType(XmlSchemaSequence sequence,
+ QName schemaTypeName,
+ String paraName,
+ boolean isArray) {
XmlSchemaElement elt1 = new XmlSchemaElement();
elt1.setName(paraName);
elt1.setSchemaTypeName(schemaTypeName);
sequence.getItems().add(elt1);
-
- if ( isArray )
- {
+
+ if (isArray) {
elt1.setMaxOccurs(Long.MAX_VALUE);
- elt1.setMinOccurs(0);
+ elt1.setMinOccurs(1);
}
}
-
- private XmlSchemaComplexType createSchemaTypeForMethodPart(String localPartName)
- {
+
+ private XmlSchemaComplexType createSchemaTypeForMethodPart(String localPartName) {
//XmlSchema xmlSchema = (XmlSchema)schemaMap.get(schemaTargetNameSpace);
XmlSchema xmlSchema = getXmlSchema(schemaTargetNameSpace);
QName elementName = new QName(this.schemaTargetNameSpace, localPartName, this.schema_namespace_prefix);
XmlSchemaComplexType complexType = new XmlSchemaComplexType(xmlSchema);
-
+
XmlSchemaElement globalElement = new XmlSchemaElement();
globalElement.setSchemaType(complexType);
globalElement.setName(formGlobalElementName(localPartName));
globalElement.setQName(elementName);
-
xmlSchema.getItems().add(globalElement);
xmlSchema.getElements().add(elementName, globalElement);
-
+
typeTable.addComplexSchema(localPartName, elementName);
-
+
return complexType;
}
-
-
- private String formGlobalElementName(String typeName)
- {
- String firstChar = typeName.substring(0,1);
+
+
+ private String formGlobalElementName(String typeName) {
+ String firstChar = typeName.substring(0, 1);
return typeName.replaceFirst(firstChar, firstChar.toLowerCase());
}
-
- private XmlSchema getXmlSchema(String targetNamespace)
- {
- XmlSchema xmlSchema;
-
- if ((xmlSchema = (XmlSchema) schemaMap.get(targetNamespace)) == null)
- {
+
+ private XmlSchema getXmlSchema(String targetNamespace) {
+ XmlSchema xmlSchema;
+
+ if ((xmlSchema = (XmlSchema) schemaMap.get(targetNamespace)) == null) {
String targetNamespacePrefix = generatePrefix();
-
+
xmlSchema = new XmlSchema(targetNamespace, xmlSchemaCollection);
xmlSchema.setAttributeFormDefault(getAttrFormDefaultSetting());
xmlSchema.setElementFormDefault(getElementFormDefaultSetting());
-
-
+
+
targetNamespacePrefixMap.put(targetNamespace, targetNamespacePrefix);
schemaMap.put(targetNamespace, xmlSchema);
-
+
Hashtable prefixmap = new Hashtable();
prefixmap.put(DEFAULT_SCHEMA_NAMESPACE_PREFIX, URI_2001_SCHEMA_XSD);
prefixmap.put(targetNamespacePrefix, targetNamespace);
@@ -413,24 +390,10 @@
public String getSchemaTargetNameSpace() {
return schemaTargetNameSpace;
}
-
- private void initializeSchemaMap(String targetNamespace, String targetNamespacePrefix)
- {
- XmlSchema xmlSchema = new XmlSchema(targetNamespace, xmlSchemaCollection);
- targetNamespacePrefixMap.put(targetNamespace, targetNamespacePrefix);
- schemaMap.put(targetNamespace, xmlSchema);
-
- Hashtable prefixmap = new Hashtable();
- prefixmap.put(DEFAULT_SCHEMA_NAMESPACE_PREFIX, URI_2001_SCHEMA_XSD);
- prefixmap.put(targetNamespacePrefix, targetNamespace);
- xmlSchema.setPrefixToNamespaceMap(prefixmap);
- }
-
- private void addImport(XmlSchema xmlSchema, QName schemaTypeName)
- {
+
+ private void addImport(XmlSchema xmlSchema, QName schemaTypeName) {
if (!xmlSchema.getPrefixToNamespaceMap().values().
- contains(schemaTypeName.getNamespaceURI()))
- {
+ contains(schemaTypeName.getNamespaceURI())) {
XmlSchemaImport importElement = new XmlSchemaImport();
importElement.setNamespace(schemaTypeName.getNamespaceURI());
xmlSchema.getItems().add(importElement);
@@ -454,27 +417,19 @@
public void setElementFormDefault(String elementFormDefault) {
this.elementFormDefault = elementFormDefault;
}
-
- private XmlSchemaForm getAttrFormDefaultSetting()
- {
- if ( FORM_DEFAULT_UNQUALIFIED.equals(getAttrFormDefault()) )
- {
+
+ private XmlSchemaForm getAttrFormDefaultSetting() {
+ if (FORM_DEFAULT_UNQUALIFIED.equals(getAttrFormDefault())) {
return new XmlSchemaForm(XmlSchemaForm.UNQUALIFIED);
- }
- else
- {
+ } else {
return new XmlSchemaForm(XmlSchemaForm.QUALIFIED);
}
}
-
- private XmlSchemaForm getElementFormDefaultSetting()
- {
- if ( FORM_DEFAULT_UNQUALIFIED.equals(getElementFormDefault()) )
- {
+
+ private XmlSchemaForm getElementFormDefaultSetting() {
+ if (FORM_DEFAULT_UNQUALIFIED.equals(getElementFormDefault())) {
return new XmlSchemaForm(XmlSchemaForm.UNQUALIFIED);
- }
- else
- {
+ } else {
return new XmlSchemaForm(XmlSchemaForm.QUALIFIED);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org