Author: dims Date: Sun Jun 3 21:16:31 2007 New Revision: 544041 URL: http://svn.apache.org/viewvc?view=rev&rev=544041 Log: consolidate duplicate code into SchemaGenerator basically maintain subset of all the methods in the service class
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/java2wsdl/SchemaGenerator.java Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java?view=diff&rev=544041&r1=544040&r2=544041 ============================================================================== --- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java (original) +++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/Utils.java Sun Jun 3 21:16:31 2007 @@ -338,19 +338,6 @@ for (int i = 0; i < method.length; i++) { JMethod jmethod = method[i]; - JAnnotation methodAnnon = jmethod.getAnnotation(AnnotationConstants.WEB_METHOD); - if (methodAnnon != null) { - if (methodAnnon.getValue(AnnotationConstants.EXCLUDE).asBoolean()) { - continue; - } - } - if (!jmethod.isPublic()) { - // no need to expose , private and protected methods - continue; - } - if (excludeOperations != null && excludeOperations.contains(jmethod.getSimpleName())) { - continue; - } String opName = jmethod.getSimpleName(); AxisOperation operation = axisService.getOperation(new QName(opName)); // if the operation there in services.xml then try to set it schema element name Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java?view=diff&rev=544041&r1=544040&r2=544041 ============================================================================== --- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java (original) +++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java Sun Jun 3 21:16:31 2007 @@ -1629,23 +1629,8 @@ PhasesInfo pinfo = axisConfiguration.getPhasesInfo(); - List excludes = schemaGenerator.getExcludeMethods(); for (int i = 0; i < method.length; i++) { JMethod jmethod = method[i]; - JAnnotation methodAnnon = jmethod.getAnnotation(AnnotationConstants.WEB_METHOD); - if (methodAnnon != null) { - if (methodAnnon.getValue(AnnotationConstants.EXCLUDE).asBoolean()) { - continue; - } - } - if (!jmethod.isPublic()) { - // no need to expose , private and protected methods - continue; - } else { - if (excludes.contains(jmethod.getSimpleName())) { - continue; - } - } AxisOperation operation = Utils.getAxisOperationforJmethod(jmethod, table); String mep = operation.getMessageExchangePattern(); MessageReceiver mr; @@ -1779,18 +1764,6 @@ for (int i = 0; i < method.length; i++) { JMethod jmethod = method[i]; - JAnnotation methodAnnon = jmethod.getAnnotation(AnnotationConstants.WEB_METHOD); - if (methodAnnon != null) { - if (methodAnnon.getValue(AnnotationConstants.EXCLUDE).asBoolean()) { - continue; - } - } - if (!jmethod.isPublic()) { - // no need to expose , private and protected methods - continue; - } else if (excludeOpeartion.contains(jmethod.getSimpleName())) { - continue; - } AxisOperation operation = Utils.getAxisOperationforJmethod(jmethod, table); // loading message receivers Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/java2wsdl/SchemaGenerator.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/java2wsdl/SchemaGenerator.java?view=diff&rev=544041&r1=544040&r2=544041 ============================================================================== --- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/java2wsdl/SchemaGenerator.java (original) +++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/java2wsdl/SchemaGenerator.java Sun Jun 3 21:16:31 2007 @@ -39,6 +39,7 @@ import java.util.Map; import java.util.Set; import java.util.List; +import java.lang.reflect.Array; /* * Copyright 2004,2005 The Apache Software Foundation. @@ -190,118 +191,128 @@ targetNamespace = tns; } } - methods = jclass.getDeclaredMethods(); - //short the elements in the array - Arrays.sort(methods); - - // since we do not support overload - HashMap uniqueMethods = new HashMap(); - XmlSchemaComplexType methodSchemaType; - XmlSchemaSequence sequence = null; - - for (int i = 0; i < methods.length; i++) { - JMethod jMethod = methods[i]; - JAnnotation methodAnnon = jMethod.getAnnotation(AnnotationConstants.WEB_METHOD); - if (methodAnnon != null) { - if (methodAnnon.getValue(AnnotationConstants.EXCLUDE).asBoolean()) { - continue; - } - } - String methodName = getSimpleName(jMethod); - // no need to think abt this method , since that is system - // config method - if (excludeMethods.contains(getSimpleName(jMethod))) { - continue; - } + methods = processMethods(jclass.getDeclaredMethods()); - if (uniqueMethods.get(getSimpleName(jMethod)) != null) { - log.warn("We don't support methods overloading. Ignoring [" + jMethod.getQualifiedName() + "]"); - continue; - } + } else { + //generate the schema type for extra classes + extraSchemaTypeName = typeTable.getSimpleSchemaTypeName(getQualifiedName(jclass)); + if (extraSchemaTypeName == null) { + generateSchema(jclass); + } + } + } + return schemaMap.values(); + } - if (!jMethod.isPublic()) { - // no need to generate Schema for non public methods - continue; - } - if (jMethod.getExceptionTypes().length > 0) { - JClass[] extypes = jMethod.getExceptionTypes() ; - for (int j= 0 ; j < extypes.length ; j++) { - JClass extype = extypes[j] ; - methodSchemaType = createSchemaTypeForMethodPart(extype.getSimpleName()+ "Fault"); - sequence = new XmlSchemaSequence(); - generateSchemaForType(sequence, extype, extype.getSimpleName()); - methodSchemaType.setParticle(sequence); - } - } - uniqueMethods.put(getSimpleName(jMethod), jMethod); - //create the schema type for the method wrapper + private JMethod[] processMethods(JMethod[] declaredMethods) throws Exception { + ArrayList list = new ArrayList(); + //short the elements in the array + Arrays.sort(declaredMethods); + + // since we do not support overload + HashMap uniqueMethods = new HashMap(); + XmlSchemaComplexType methodSchemaType; + XmlSchemaSequence sequence = null; + + for (int i = 0; i < declaredMethods.length; i++) { + JMethod jMethod = declaredMethods[i]; + JAnnotation methodAnnon = jMethod.getAnnotation(AnnotationConstants.WEB_METHOD); + if (methodAnnon != null) { + if (methodAnnon.getValue(AnnotationConstants.EXCLUDE).asBoolean()) { + continue; + } + } + String methodName = getSimpleName(jMethod); + // no need to think abt this method , since that is system + // config method + if (excludeMethods.contains(getSimpleName(jMethod))) { + continue; + } - uniqueMethods.put(getSimpleName(jMethod), jMethod); - JParameter[] paras = jMethod.getParameters(); - String parameterNames[] = null; - if (paras.length > 0) { - parameterNames = methodTable.getParameterNames(methodName); - sequence = new XmlSchemaSequence(); + if (uniqueMethods.get(getSimpleName(jMethod)) != null) { + log.warn("We don't support methods overloading. Ignoring [" + jMethod.getQualifiedName() + "]"); + continue; + } - methodSchemaType = createSchemaTypeForMethodPart(getSimpleName(jMethod)); - methodSchemaType.setParticle(sequence); - } + if (!jMethod.isPublic()) { + // no need to generate Schema for non public methods + continue; + } - for (int j = 0; j < paras.length; j++) { - JParameter methodParameter = paras[j]; - String parameterName = null; - JAnnotation paramterAnnon = - methodParameter.getAnnotation(AnnotationConstants.WEB_PARAM); - if (paramterAnnon != null) { - parameterName = - paramterAnnon.getValue(AnnotationConstants.NAME).asString(); - } - if (parameterName == null || "".equals(parameterName)) { - parameterName = (parameterNames != null && parameterNames[j] != null) ? - parameterNames[j] : getSimpleName(methodParameter); - } - JClass paraType = methodParameter.getType(); - if (nonRpcMethods.contains(getSimpleName(jMethod))) { - generateSchemaForType(sequence, null, getSimpleName(jMethod)); - break; - } else { - generateSchemaForType(sequence, paraType, parameterName); - } - } - // for its return type - JClass returnType = jMethod.getReturnType(); + // Maintain a list of methods we actually work with + list.add(jMethod); + + if (jMethod.getExceptionTypes().length > 0) { + JClass[] extypes = jMethod.getExceptionTypes() ; + for (int j= 0 ; j < extypes.length ; j++) { + JClass extype = extypes[j] ; + methodSchemaType = createSchemaTypeForMethodPart(extype.getSimpleName()+ "Fault"); + sequence = new XmlSchemaSequence(); + generateSchemaForType(sequence, extype, extype.getSimpleName()); + methodSchemaType.setParticle(sequence); + } + } + uniqueMethods.put(getSimpleName(jMethod), jMethod); + //create the schema type for the method wrapper - if (!returnType.isVoidType()) { - methodSchemaType = - createSchemaTypeForMethodPart(getSimpleName(jMethod) + RESPONSE); - sequence = new XmlSchemaSequence(); - methodSchemaType.setParticle(sequence); - JAnnotation returnAnnon = - jMethod.getAnnotation(AnnotationConstants.WEB_RESULT); - String returnName = "return"; - if (returnAnnon != null) { - returnName = returnAnnon.getValue(AnnotationConstants.NAME).asString(); - if (returnName != null && !"".equals(returnName)) { - returnName = "return"; - } - } - if (nonRpcMethods.contains(getSimpleName(jMethod))) { - generateSchemaForType(sequence, null, returnName); - } else { - generateSchemaForType(sequence, returnType, returnName); - } + uniqueMethods.put(getSimpleName(jMethod), jMethod); + JParameter[] paras = jMethod.getParameters(); + String parameterNames[] = null; + if (paras.length > 0) { + parameterNames = methodTable.getParameterNames(methodName); + sequence = new XmlSchemaSequence(); + methodSchemaType = createSchemaTypeForMethodPart(getSimpleName(jMethod)); + methodSchemaType.setParticle(sequence); + } + + for (int j = 0; j < paras.length; j++) { + JParameter methodParameter = paras[j]; + String parameterName = null; + JAnnotation paramterAnnon = + methodParameter.getAnnotation(AnnotationConstants.WEB_PARAM); + if (paramterAnnon != null) { + parameterName = + paramterAnnon.getValue(AnnotationConstants.NAME).asString(); + } + if (parameterName == null || "".equals(parameterName)) { + parameterName = (parameterNames != null && parameterNames[j] != null) ? + parameterNames[j] : getSimpleName(methodParameter); + } + JClass paraType = methodParameter.getType(); + if (nonRpcMethods.contains(getSimpleName(jMethod))) { + generateSchemaForType(sequence, null, getSimpleName(jMethod)); + break; + } else { + generateSchemaForType(sequence, paraType, parameterName); + } + } + // for its return type + JClass returnType = jMethod.getReturnType(); + + if (!returnType.isVoidType()) { + methodSchemaType = + createSchemaTypeForMethodPart(getSimpleName(jMethod) + RESPONSE); + sequence = new XmlSchemaSequence(); + methodSchemaType.setParticle(sequence); + JAnnotation returnAnnon = + jMethod.getAnnotation(AnnotationConstants.WEB_RESULT); + String returnName = "return"; + if (returnAnnon != null) { + returnName = returnAnnon.getValue(AnnotationConstants.NAME).asString(); + if (returnName != null && !"".equals(returnName)) { + returnName = "return"; } } - } else { - //generate the schema type for extra classes - extraSchemaTypeName = typeTable.getSimpleSchemaTypeName(getQualifiedName(jclass)); - if (extraSchemaTypeName == null) { - generateSchema(jclass); + if (nonRpcMethods.contains(getSimpleName(jMethod))) { + generateSchemaForType(sequence, null, returnName); + } else { + generateSchemaForType(sequence, returnType, returnName); } + } } - return schemaMap.values(); + return (JMethod[]) list.toArray(new JMethod[list.size()]); } /** --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]