Author: eranga Date: Sun Apr 3 05:04:58 2011 New Revision: 1088207 URL: http://svn.apache.org/viewvc?rev=1088207&view=rev Log: AXIS2-4988 (The CORBA module does not fully support the 'any' data type.)
Fixed. Now, the CORBA module supports 'any' data type as defined in CORBA-WSDL/SOAP Interworking (C2WSDL) 1.2.1 (http://www.omg.org/spec/C2WSDL/1.2.1) Added: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/SchemaToIDLMapping.java axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/AnyType.java axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/values/AnyValue.java Modified: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/CorbaConstants.java axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/CorbaDeployer.java axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/SchemaGenerator.java axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/parser/IDLVisitor.java axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/Operation.java axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/PrimitiveDataType.java axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaInOnlyMessageReceiver.java axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaInOutAsyncMessageReceiver.java axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaInvoker.java axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaMessageReceiver.java axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaUtil.java Modified: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/CorbaConstants.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/CorbaConstants.java?rev=1088207&r1=1088206&r2=1088207&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/CorbaConstants.java (original) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/CorbaConstants.java Sun Apr 3 05:04:58 2011 @@ -58,4 +58,8 @@ public interface CorbaConstants { String DEFAULT_SCHEMA_NAMESPACE_PREFIX = "xs"; String URI_2001_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema"; String FORM_DEFAULT_UNQUALIFIED = "unqualified"; + + String SCHEMA_TO_IDL_MAPPING_LITERAL = "SchemaToIDLMapping"; + String ANY_TYPE_NAME = "CORBA.Any"; + String TYPECODE_TYPE_NAME = "CORBA.TypeCode"; } Modified: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/CorbaDeployer.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/CorbaDeployer.java?rev=1088207&r1=1088206&r2=1088207&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/CorbaDeployer.java (original) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/CorbaDeployer.java Sun Apr 3 05:04:58 2011 @@ -466,6 +466,7 @@ public class CorbaDeployer extends Abstr axisService.addSchema(schemas); axisService.setSchemaTargetNamespace(schemaGenerator.getSchemaTargetNameSpace()); axisService.setTypeTable(schemaGenerator.getTypeTable()); + axisService.addParameter(SCHEMA_TO_IDL_MAPPING_LITERAL, schemaGenerator.getSchemaToIDLMapping()); if (Java2WSDLConstants.DEFAULT_TARGET_NAMESPACE.equals( axisService.getTargetNamespace())) { axisService.setTargetNamespace(schemaGenerator.getTargetNamespace()); @@ -548,23 +549,16 @@ public class CorbaDeployer extends Abstr AxisOperation operation; String opName = corbaOperation.getName(); DataType returnType = corbaOperation.getReturnType(); - if (returnType == null || CorbaUtil.getQualifiedName(returnType).equals(VOID)) { - if (corbaOperation.hasRaises()) { - operation = AxisOperationFactory.getAxisOperation(WSDLConstants.MEP_CONSTANT_IN_OUT); - AxisMessage outMessage = operation.getMessage( - WSDLConstants.MESSAGE_LABEL_OUT_VALUE); - outMessage.setElementQName(table.getQNamefortheType(opName + RESPONSE)); - outMessage.setName(opName + RESPONSE); - } else { - operation = AxisOperationFactory.getAxisOperation(WSDLConstants.MEP_CONSTANT_IN_ONLY); - } + + if (returnType == null && !corbaOperation.hasRaises() && !corbaOperation.hasOutParams()) { + operation = AxisOperationFactory.getAxisOperation(WSDLConstants.MEP_CONSTANT_IN_ONLY); } else { operation = AxisOperationFactory.getAxisOperation(WSDLConstants.MEP_CONSTANT_IN_OUT); - AxisMessage outMessage = operation.getMessage( - WSDLConstants.MESSAGE_LABEL_OUT_VALUE); + AxisMessage outMessage = operation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE); outMessage.setElementQName(table.getQNamefortheType(opName + RESPONSE)); outMessage.setName(opName + RESPONSE); } + if (corbaOperation.hasRaises()) { List extypes = corbaOperation.getRaises(); for (int j= 0 ; j < extypes.size() ; j++) { Modified: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/SchemaGenerator.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/SchemaGenerator.java?rev=1088207&r1=1088206&r2=1088207&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/SchemaGenerator.java (original) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/SchemaGenerator.java Sun Apr 3 05:04:58 2011 @@ -20,46 +20,18 @@ package org.apache.axis2.corba.deployer; import org.apache.axis2.corba.exceptions.SchemaGeneratorException; -import org.apache.axis2.corba.idl.types.AbstractCollectionType; -import org.apache.axis2.corba.idl.types.ArrayType; -import org.apache.axis2.corba.idl.types.CompositeDataType; -import org.apache.axis2.corba.idl.types.DataType; -import org.apache.axis2.corba.idl.types.EnumType; -import org.apache.axis2.corba.idl.types.ExceptionType; -import org.apache.axis2.corba.idl.types.IDL; -import org.apache.axis2.corba.idl.types.Interface; -import org.apache.axis2.corba.idl.types.Member; -import org.apache.axis2.corba.idl.types.Operation; -import org.apache.axis2.corba.idl.types.PrimitiveDataType; -import org.apache.axis2.corba.idl.types.Typedef; -import org.apache.axis2.corba.idl.types.UnionType; +import org.apache.axis2.corba.idl.types.*; import org.apache.axis2.corba.receivers.CorbaUtil; import org.apache.axis2.description.java2wsdl.DefaultNamespaceGenerator; import org.apache.axis2.description.java2wsdl.Java2WSDLConstants; import org.apache.axis2.description.java2wsdl.NamespaceGenerator; import org.apache.axis2.description.java2wsdl.TypeTable; -import org.apache.ws.commons.schema.XmlSchema; -import org.apache.ws.commons.schema.XmlSchemaChoice; -import org.apache.ws.commons.schema.XmlSchemaCollection; -import org.apache.ws.commons.schema.XmlSchemaComplexType; -import org.apache.ws.commons.schema.XmlSchemaElement; -import org.apache.ws.commons.schema.XmlSchemaEnumerationFacet; -import org.apache.ws.commons.schema.XmlSchemaForm; -import org.apache.ws.commons.schema.XmlSchemaImport; -import org.apache.ws.commons.schema.XmlSchemaObjectCollection; -import org.apache.ws.commons.schema.XmlSchemaSequence; -import org.apache.ws.commons.schema.XmlSchemaSimpleType; -import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction; +import org.apache.ws.commons.schema.*; import org.apache.ws.commons.schema.utils.NamespaceMap; import javax.xml.namespace.QName; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.net.URI; +import java.util.*; public class SchemaGenerator implements CorbaConstants { private static int prefixCount = 1; @@ -80,6 +52,7 @@ public class SchemaGenerator implements private NamespaceGenerator nsGen = null; private String targetNamespace = null; private ArrayList nonRpcMethods = new ArrayList(); + private SchemaToIDLMapping schemaToIDLMapping = new SchemaToIDLMapping(); public NamespaceGenerator getNsGen() throws SchemaGeneratorException { if ( nsGen == null ) { @@ -265,12 +238,16 @@ public class SchemaGenerator implements } } - /*} else { - //generate the schema type for extra classes - extraSchemaTypeName = typeTable.getSimpleSchemaTypeName(getQualifiedName(jclass)); - if (extraSchemaTypeName == null) { - generateSchema(jclass); - }*/ + + // if 'any' data type is used as a parameter or return type, we must generate schema types for all the composite types defined in the IDL file. + Map typeMap = idl.getCompositeDataTypes(); + if (typeTable.getComplexSchemaType(CorbaConstants.ANY_TYPE_NAME) != null && typeMap != null) { + Iterator valuesIter = typeMap.values().iterator(); + while (valuesIter.hasNext()) { + generateSchema((CompositeDataType) valuesIter.next()); + } + } + return schemaMap.values(); } @@ -405,6 +382,88 @@ public class SchemaGenerator implements return schemaTypeName; } + /** + * Generate schema construct for 'any' type + * + * @return Qname + * @throws SchemaGeneratorException if fails + */ + private QName generateSchemaForAnyType() throws SchemaGeneratorException { + // Create 'TypeCode' complex type + QName schemaTypeName = typeTable.getComplexSchemaType(CorbaConstants.TYPECODE_TYPE_NAME); + if (schemaTypeName == null) { + String targetNameSpace = resolveSchemaNamespace(""); + + XmlSchema xmlSchema = getXmlSchema(targetNameSpace); + String targetNamespacePrefix = (String) targetNamespacePrefixMap.get(targetNameSpace); + schemaTypeName = new QName(targetNameSpace, CorbaConstants.TYPECODE_TYPE_NAME, targetNamespacePrefix); + + XmlSchemaComplexType complexType = new XmlSchemaComplexType(xmlSchema); + XmlSchemaSequence sequence = new XmlSchemaSequence(); + XmlSchemaElement eltOuter = new XmlSchemaElement(); + eltOuter.setName(CorbaConstants.TYPECODE_TYPE_NAME); + eltOuter.setQName(schemaTypeName); + complexType.setParticle(sequence); + complexType.setName(CorbaConstants.TYPECODE_TYPE_NAME); + + xmlSchema.getItems().add(eltOuter); + xmlSchema.getElements().add(schemaTypeName, eltOuter); + eltOuter.setSchemaTypeName(complexType.getQName()); + + xmlSchema.getItems().add(complexType); + xmlSchema.getSchemaTypes().add(schemaTypeName, complexType); + + typeTable.addComplexSchema(CorbaConstants.TYPECODE_TYPE_NAME, eltOuter.getQName()); + + XmlSchemaElement typeElement = new XmlSchemaElement(); + typeElement.setName("definition"); + typeElement.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(URI.class.getName())); + sequence.getItems().add(typeElement); + + XmlSchemaElement valueElement = new XmlSchemaElement(); + valueElement.setName("typename"); + valueElement.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(String.class.getName())); + sequence.getItems().add(valueElement); + } + + // Create 'Any' complex type + schemaTypeName = typeTable.getComplexSchemaType(CorbaConstants.ANY_TYPE_NAME); + if (schemaTypeName == null) { + String targetNameSpace = resolveSchemaNamespace(""); + + XmlSchema xmlSchema = getXmlSchema(targetNameSpace); + String targetNamespacePrefix = (String) targetNamespacePrefixMap.get(targetNameSpace); + schemaTypeName = new QName(targetNameSpace, CorbaConstants.ANY_TYPE_NAME, targetNamespacePrefix); + + XmlSchemaComplexType complexType = new XmlSchemaComplexType(xmlSchema); + XmlSchemaSequence sequence = new XmlSchemaSequence(); + XmlSchemaElement eltOuter = new XmlSchemaElement(); + eltOuter.setName(CorbaConstants.ANY_TYPE_NAME); + eltOuter.setQName(schemaTypeName); + complexType.setParticle(sequence); + complexType.setName(CorbaConstants.ANY_TYPE_NAME); + + xmlSchema.getItems().add(eltOuter); + xmlSchema.getElements().add(schemaTypeName, eltOuter); + eltOuter.setSchemaTypeName(complexType.getQName()); + + xmlSchema.getItems().add(complexType); + xmlSchema.getSchemaTypes().add(schemaTypeName, complexType); + + typeTable.addComplexSchema(CorbaConstants.ANY_TYPE_NAME, eltOuter.getQName()); + + XmlSchemaElement typeElement = new XmlSchemaElement(); + typeElement.setName("type"); + typeElement.setSchemaTypeName(typeTable.getComplexSchemaType(CorbaConstants.TYPECODE_TYPE_NAME)); + sequence.getItems().add(typeElement); + + XmlSchemaElement valueElement = new XmlSchemaElement(); + valueElement.setName("value"); + valueElement.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(Object.class.getName())); + sequence.getItems().add(valueElement); + } + return schemaTypeName; + } // moved code common to Fields & properties out of above method private XmlSchemaElement generateSchemaforFieldsandProperties(XmlSchema xmlSchema, @@ -468,6 +527,8 @@ public class SchemaGenerator implements put(generatePrefix(), typeTable.getComplexSchemaType(propertyTypeName).getNamespaceURI()); } + } else if (type instanceof AnyType) { + elt1.setSchemaTypeName(generateSchemaForAnyType()); } else { throw new SchemaGeneratorException("Unsupported type:" + type); } @@ -517,17 +578,21 @@ public class SchemaGenerator implements schemaTypeName, partName, isArrayType); - String schemaNamespace; - schemaNamespace = resolveSchemaNamespace(getModuleName(type)); + String schemaNamespace = resolveSchemaNamespace(getModuleName(type)); addImport(getXmlSchema(schemaNamespace), schemaTypeName); - + } else if (schemaTypeName == null && type instanceof AnyType) { + schemaTypeName = generateSchemaForAnyType(); + addContentToMethodSchemaType(sequence, + schemaTypeName, + partName, + isArrayType); } else { addContentToMethodSchemaType(sequence, schemaTypeName, partName, isArrayType); } - + schemaToIDLMapping.addSchemaType(type, schemaTypeName); return schemaTypeName; } @@ -733,4 +798,8 @@ public class SchemaGenerator implements return ""; } } + + public SchemaToIDLMapping getSchemaToIDLMapping() { + return schemaToIDLMapping; + } } Added: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/SchemaToIDLMapping.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/SchemaToIDLMapping.java?rev=1088207&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/SchemaToIDLMapping.java (added) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/SchemaToIDLMapping.java Sun Apr 3 05:04:58 2011 @@ -0,0 +1,43 @@ +/* + * 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.axis2.corba.deployer; + +import org.apache.axis2.corba.idl.types.DataType; + +import javax.xml.namespace.QName; +import java.util.HashMap; +import java.util.Map; + +public class SchemaToIDLMapping { + + private Map types = new HashMap(); + + public void addSchemaType(DataType dataType, QName qName) { + types.put(getAString(qName), dataType); + } + + public DataType getDataType(QName qName) { + return (DataType) types.get(getAString(qName)); + } + + private String getAString(QName qName) { + return '{' + qName.getNamespaceURI() + '}' + qName.getLocalPart(); + } +} Modified: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/parser/IDLVisitor.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/parser/IDLVisitor.java?rev=1088207&r1=1088206&r2=1088207&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/parser/IDLVisitor.java (original) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/parser/IDLVisitor.java Sun Apr 3 05:04:58 2011 @@ -490,6 +490,10 @@ public class IDLVisitor /*implements AST dataType = PrimitiveDataType.getPrimitiveDataType(typeName); } + if (dataType == null && "any".equals(typeName)) { + dataType = new AnyType(); + } + if (dataType == null) { throw new InvalidIDLException("Invalid data type: " + typeName); } Added: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/AnyType.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/AnyType.java?rev=1088207&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/AnyType.java (added) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/AnyType.java Sun Apr 3 05:04:58 2011 @@ -0,0 +1,31 @@ +/* + * 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.axis2.corba.idl.types; + +import org.omg.CORBA.ORB; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; + +public class AnyType extends DataType { + @Override + protected TypeCode generateTypeCode() { + return ORB.init().get_primitive_tc(TCKind.tk_any); + } +} Modified: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/Operation.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/Operation.java?rev=1088207&r1=1088206&r2=1088207&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/Operation.java (original) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/Operation.java Sun Apr 3 05:04:58 2011 @@ -64,6 +64,17 @@ public class Operation { return raises != null && (raises.size() > 0); } + public boolean hasOutParams() { + for (int i = 0; i < params.size(); i++) { + Member member = (Member) params.get(0); + if (Member.MODE_OUT.equals(member.getMode()) + || Member.MODE_INOUT.equals(member.getMode())) { + return true; + } + } + return false; + } + public void setRaises(List raises) { this.raises = raises; } Modified: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/PrimitiveDataType.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/PrimitiveDataType.java?rev=1088207&r1=1088206&r2=1088207&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/PrimitiveDataType.java (original) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/PrimitiveDataType.java Sun Apr 3 05:04:58 2011 @@ -48,7 +48,6 @@ public class PrimitiveDataType extends D PRIMITIVE_TYPES.put("octet",orb.get_primitive_tc(TCKind.tk_octet)); PRIMITIVE_TYPES.put("string",orb.get_primitive_tc(TCKind.tk_string)); PRIMITIVE_TYPES.put("wstring",orb.get_primitive_tc(TCKind.tk_wstring)); - PRIMITIVE_TYPES.put("any",orb.get_primitive_tc(TCKind.tk_any)); PRIMITIVE_TYPES.put("longdouble",orb.get_primitive_tc(TCKind.tk_longdouble)); PRIMITIVE_TYPES.put("void",orb.get_primitive_tc(TCKind.tk_void)); //PRIMITIVE_TYPES.put("dateTime",orb.get_primitive_tc(TCKind.tk_dateTime)); Added: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/values/AnyValue.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/values/AnyValue.java?rev=1088207&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/values/AnyValue.java (added) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/values/AnyValue.java Sun Apr 3 05:04:58 2011 @@ -0,0 +1,44 @@ +/* + * 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.axis2.corba.idl.values; + +import org.apache.axis2.corba.idl.types.DataType; + +public class AnyValue { + + private DataType contentType; + private Object content; + + public DataType getContentType() { + return contentType; + } + + public void setContentType(DataType contentType) { + this.contentType = contentType; + } + + public Object getContent() { + return content; + } + + public void setContent(Object content) { + this.content = content; + } +} Modified: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaInOnlyMessageReceiver.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaInOnlyMessageReceiver.java?rev=1088207&r1=1088206&r2=1088207&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaInOnlyMessageReceiver.java (original) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaInOnlyMessageReceiver.java Sun Apr 3 05:04:58 2011 @@ -24,6 +24,7 @@ import org.apache.axiom.om.OMNamespace; import org.apache.axis2.AxisFault; import org.apache.axis2.context.MessageContext; import org.apache.axis2.corba.deployer.CorbaConstants; +import org.apache.axis2.corba.deployer.SchemaToIDLMapping; import org.apache.axis2.corba.exceptions.CorbaInvocationException; import org.apache.axis2.corba.idl.types.IDL; import org.apache.axis2.description.AxisMessage; @@ -106,7 +107,8 @@ public class CorbaInOnlyMessageReceiver "qualified element. But received a namespace qualified element"); } - Object[] objectArray = CorbaUtil.extractParameters(methodElement, invoker.getParameterMembers()); + SchemaToIDLMapping mapping = (SchemaToIDLMapping) service.getParameterValue(SCHEMA_TO_IDL_MAPPING_LITERAL); + Object[] objectArray = CorbaUtil.extractParameters(methodElement, invoker.getParameterMembers(), mapping); invoker.setParameters(objectArray); } invoker.invoke(); Modified: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaInOutAsyncMessageReceiver.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaInOutAsyncMessageReceiver.java?rev=1088207&r1=1088206&r2=1088207&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaInOutAsyncMessageReceiver.java (original) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaInOutAsyncMessageReceiver.java Sun Apr 3 05:04:58 2011 @@ -25,6 +25,7 @@ import org.apache.axiom.soap.SOAPFactory import org.apache.axis2.AxisFault; import org.apache.axis2.context.MessageContext; import org.apache.axis2.corba.deployer.CorbaConstants; +import org.apache.axis2.corba.deployer.SchemaToIDLMapping; import org.apache.axis2.corba.exceptions.CorbaInvocationException; import org.apache.axis2.corba.idl.types.IDL; import org.apache.axis2.corba.idl.types.Member; @@ -114,7 +115,8 @@ public class CorbaInOutAsyncMessageRecei "qualified element. But received a namespace qualified element"); } - Object[] objectArray = CorbaUtil.extractParameters(methodElement, invoker.getParameterMembers()); + SchemaToIDLMapping mapping = (SchemaToIDLMapping) service.getParameterValue(SCHEMA_TO_IDL_MAPPING_LITERAL); + Object[] objectArray = CorbaUtil.extractParameters(methodElement, invoker.getParameterMembers(), mapping); invoker.setParameters(objectArray); params = invoker.getParameterMembers(); outParamValues = invoker.getOutParameterValuess(); Modified: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaInvoker.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaInvoker.java?rev=1088207&r1=1088206&r2=1088207&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaInvoker.java (original) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaInvoker.java Sun Apr 3 05:04:58 2011 @@ -79,7 +79,7 @@ public class CorbaInvoker implements Inv if (mode.equals(Member.MODE_IN)) { arg = request.add_in_arg(); value = paramsIter.next(); - }else if (mode.equals(Member.MODE_INOUT)) { + } else if (mode.equals(Member.MODE_INOUT)) { arg = request.add_inout_arg(); value = paramsIter.next(); } else if (mode.equals(Member.MODE_OUT)) { Modified: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaMessageReceiver.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaMessageReceiver.java?rev=1088207&r1=1088206&r2=1088207&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaMessageReceiver.java (original) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaMessageReceiver.java Sun Apr 3 05:04:58 2011 @@ -25,6 +25,7 @@ import org.apache.axiom.soap.SOAPFactory import org.apache.axis2.AxisFault; import org.apache.axis2.context.MessageContext; import org.apache.axis2.corba.deployer.CorbaConstants; +import org.apache.axis2.corba.deployer.SchemaToIDLMapping; import org.apache.axis2.corba.exceptions.CorbaInvocationException; import org.apache.axis2.corba.idl.types.IDL; import org.apache.axis2.corba.idl.types.Member; @@ -111,7 +112,8 @@ public class CorbaMessageReceiver extend throw new AxisFault("namespace mismatch. Axis Oepration expects non-namespace " + "qualified element. But received a namespace qualified element"); } - Object[] objectArray = CorbaUtil.extractParameters(methodElement, invoker.getParameterMembers()); + SchemaToIDLMapping mapping = (SchemaToIDLMapping) service.getParameterValue(SCHEMA_TO_IDL_MAPPING_LITERAL); + Object[] objectArray = CorbaUtil.extractParameters(methodElement, invoker.getParameterMembers(), mapping); invoker.setParameters(objectArray); } resObject = invoker.invoke(); @@ -120,8 +122,8 @@ public class CorbaMessageReceiver extend } if (messageNameSpace == null) { - AxisMessage outaxisMessage = op.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE); - QName qname = outaxisMessage.getElementQName(); + AxisMessage outAxisMessage = op.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE); + QName qname = outAxisMessage.getElementQName(); if (qname != null) { messageNameSpace = qname.getNamespaceURI(); } Modified: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaUtil.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaUtil.java?rev=1088207&r1=1088206&r2=1088207&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaUtil.java (original) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/receivers/CorbaUtil.java Sun Apr 3 05:04:58 2011 @@ -26,38 +26,16 @@ import org.apache.axiom.soap.SOAPFactory import org.apache.axis2.AxisFault; import org.apache.axis2.context.MessageContext; import org.apache.axis2.corba.deployer.CorbaConstants; +import org.apache.axis2.corba.deployer.SchemaToIDLMapping; import org.apache.axis2.corba.exceptions.CorbaException; import org.apache.axis2.corba.exceptions.CorbaInvocationException; import org.apache.axis2.corba.idl.IDLProcessor; import org.apache.axis2.corba.idl.PreProcessorInputStream; -import org.apache.axis2.corba.idl.types.AbstractCollectionType; -import org.apache.axis2.corba.idl.types.ArrayType; -import org.apache.axis2.corba.idl.types.CompositeDataType; -import org.apache.axis2.corba.idl.types.DataType; -import org.apache.axis2.corba.idl.types.EnumType; -import org.apache.axis2.corba.idl.types.ExceptionType; -import org.apache.axis2.corba.idl.types.IDL; -import org.apache.axis2.corba.idl.types.Member; -import org.apache.axis2.corba.idl.types.PrimitiveDataType; -import org.apache.axis2.corba.idl.types.SequenceType; -import org.apache.axis2.corba.idl.types.Struct; -import org.apache.axis2.corba.idl.types.Typedef; -import org.apache.axis2.corba.idl.types.UnionMember; -import org.apache.axis2.corba.idl.types.UnionType; -import org.apache.axis2.corba.idl.types.ValueType; -import org.apache.axis2.corba.idl.values.AbstractCollectionValue; -import org.apache.axis2.corba.idl.values.AbstractValue; -import org.apache.axis2.corba.idl.values.AliasValue; -import org.apache.axis2.corba.idl.values.ArrayValue; -import org.apache.axis2.corba.idl.values.EnumValue; -import org.apache.axis2.corba.idl.values.ExceptionValue; -import org.apache.axis2.corba.idl.values.ObjectByValue; -import org.apache.axis2.corba.idl.values.SequenceValue; -import org.apache.axis2.corba.idl.values.StreamableValueFactory; -import org.apache.axis2.corba.idl.values.StructValue; -import org.apache.axis2.corba.idl.values.UnionValue; +import org.apache.axis2.corba.idl.types.*; +import org.apache.axis2.corba.idl.values.*; import org.apache.axis2.description.AxisService; import org.apache.axis2.description.Parameter; +import org.apache.axis2.description.java2wsdl.DefaultNamespaceGenerator; import org.apache.axis2.description.java2wsdl.TypeTable; import org.apache.axis2.namespace.Constants; import org.apache.commons.logging.Log; @@ -65,6 +43,7 @@ import org.apache.commons.logging.LogFac import org.omg.CORBA.Any; import org.omg.CORBA.TCKind; import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; import org.omg.CORBA_2_3.ORB; import org.omg.CosNaming.NamingContextExt; import org.omg.CosNaming.NamingContextExtHelper; @@ -73,19 +52,10 @@ import org.omg.CosNaming.NamingContextPa import org.omg.CosNaming.NamingContextPackage.NotFound; import javax.xml.namespace.QName; -import java.io.File; +import java.io.*; +import java.util.*; + //import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; //import java.util.zip.ZipEntry; //import java.util.zip.ZipInputStream; @@ -212,7 +182,7 @@ public class CorbaUtil implements CorbaC return invokerFactory.newInvoker(((String) interfaceName.getValue()).trim(), methodName, obj); } - public static Object[] extractParameters(OMElement methodElement, Member[] parameterMembers) throws CorbaInvocationException { + public static Object[] extractParameters(OMElement methodElement, Member[] parameterMembers, SchemaToIDLMapping mapping) throws CorbaInvocationException { if (parameterMembers==null) return new Object[0]; @@ -245,12 +215,16 @@ public class CorbaUtil implements CorbaC String paramName; for (int i = 0; i < parameterMembers.length; i++) { paramName = parameterMembers[i].getName(); - retObjs[i] = extractValue(parameterMembers[i].getDataType(), paramsMap.get(paramName)); + retObjs[i] = extractValue(parameterMembers[i].getDataType(), paramsMap.get(paramName), mapping); } return retObjs; } - private static Object extractValue(DataType dataType, Object param) throws CorbaInvocationException { + private static Object extractValue(DataType dataType, Object param, SchemaToIDLMapping mapping) throws CorbaInvocationException { + if (param == null) { + return null; + } + if (dataType instanceof Typedef) { Typedef typedef = (Typedef) dataType; AliasValue aliasValue = new AliasValue(typedef); @@ -266,7 +240,7 @@ public class CorbaUtil implements CorbaC if (paramElement == null || !ARRAY_ITEM.equals(paramElement.getLocalName())) return null; } - aliasValue.setValue(extractValue(aliasType, paramElement)); + aliasValue.setValue(extractValue(aliasType, paramElement, mapping)); return aliasValue; } else if (dataType instanceof PrimitiveDataType) { if (param!=null) @@ -282,7 +256,7 @@ public class CorbaUtil implements CorbaC Iterator paramsIter = paramElement.getChildElements(); List children = new ArrayList(); while (paramsIter.hasNext()) { - children.add(extractValue(collectionType.getDataType(), paramsIter.next())); + children.add(extractValue(collectionType.getDataType(), paramsIter.next(), mapping)); } AbstractCollectionValue collectionValue; @@ -320,13 +294,13 @@ public class CorbaUtil implements CorbaC } } if (member != null) { - unionValue.setMemberValue(extractValue(member.getDataType(), unElement)); + unionValue.setMemberValue(extractValue(member.getDataType(), unElement, mapping)); } return unionValue; } else if (dataType instanceof CompositeDataType) { CompositeDataType compositeType = (CompositeDataType) dataType; Member[] compositeMembers = compositeType.getMembers(); - Object[] compositeValues = extractParameters(((OMElement) param), compositeMembers); + Object[] compositeValues = extractParameters(((OMElement) param), compositeMembers, mapping); AbstractValue value; if (compositeType instanceof ValueType) @@ -338,6 +312,77 @@ public class CorbaUtil implements CorbaC value.setMemberValues(compositeValues); return value; + } else if (dataType instanceof AnyType) { + OMElement anyElement = (OMElement) param; + DefaultNamespaceGenerator namespaceGenerator = new DefaultNamespaceGenerator(); + String defaultNamespace = namespaceGenerator.schemaNamespaceFromPackageName("").toString(); + + OMElement typeElement = anyElement.getFirstChildWithName(new QName(defaultNamespace, "type")); + + if (typeElement != null) { + + OMElement definitionElement = typeElement.getFirstChildWithName(new QName(defaultNamespace, "definition")); + OMElement typenameElement = typeElement.getFirstChildWithName(new QName(defaultNamespace, "typename")); + OMElement anyValueElement = anyElement.getFirstChildWithName(new QName(defaultNamespace, "value")); + + if (typenameElement != null && anyValueElement != null) { + + String typeName = typenameElement.getText(); + String definition = definitionElement != null ? definitionElement.getText() : Constants.URI_DEFAULT_SCHEMA_XSD; + Object anyContent; + DataType anyValueType; + if (definition.equals(Constants.URI_DEFAULT_SCHEMA_XSD)) { + String anyValueString = anyValueElement.getText(); + if (typeName.equals("boolean")) { + anyValueType = PrimitiveDataType.getPrimitiveDataType("boolean"); + anyContent = Boolean.parseBoolean(anyValueString); + } else if (typeName.equals("double")) { + anyValueType = PrimitiveDataType.getPrimitiveDataType("double"); + anyContent = Double.parseDouble(anyValueString); + } else if (typeName.equals("float")) { + anyValueType = PrimitiveDataType.getPrimitiveDataType("float"); + anyContent = Float.parseFloat(anyValueString); + } else if (typeName.equals("unsignedByte")) { + anyValueType = PrimitiveDataType.getPrimitiveDataType("octet"); + anyContent = Byte.parseByte(anyValueString); + } else if (typeName.equals("int")) { + anyValueType = PrimitiveDataType.getPrimitiveDataType("long"); + anyContent = Integer.parseInt(anyValueString); + } else if (typeName.equals("long")) { + anyValueType = PrimitiveDataType.getPrimitiveDataType("longlong"); + anyContent = Long.parseLong(anyValueString); + } else if (typeName.equals("short")) { + anyValueType = PrimitiveDataType.getPrimitiveDataType("short"); + anyContent = Short.parseShort(anyValueString); + } else if (typeName.equals("string")) { + anyValueType = PrimitiveDataType.getPrimitiveDataType("string"); + anyContent = anyValueString; + } else if (typeName.equals("unsignedShort")) { + anyValueType = PrimitiveDataType.getPrimitiveDataType("ushort"); + anyContent = Short.parseShort(anyValueString); + } else if (typeName.equals("unsignedInt")) { + anyValueType = PrimitiveDataType.getPrimitiveDataType("ulong"); + anyContent = Integer.parseInt(anyValueString); + } else if (typeName.equals("unsignedLong")) { + anyValueType = PrimitiveDataType.getPrimitiveDataType("ulonglong"); + anyContent = Long.parseLong(anyValueString); + } else { + throw new CorbaInvocationException("Unsupported data type: " + typeName); + } + } else { + anyValueType = mapping.getDataType(new QName(definition, typeName)); + if (anyValueType != null) { + anyContent = CorbaUtil.extractValue(anyValueType, anyValueElement.getFirstElement(), mapping); + } else { + throw new CorbaInvocationException("Unsupported data schema: " + definition + " type:" + typeName); + } + } + AnyValue anyValue = new AnyValue(); + anyValue.setContent(anyContent); + anyValue.setContentType(anyValueType); + return anyValue; + } + } } return null; } @@ -395,7 +440,7 @@ public class CorbaUtil implements CorbaC } private static void processResponse(OMElement child, OMElement bodyContent, Object resObject, DataType dataType, - SOAPFactory fac, OMNamespace defaultNS, boolean qualified, AxisService service) { + SOAPFactory fac, OMNamespace defaultNS, boolean qualified, AxisService service) throws AxisFault { if (dataType instanceof PrimitiveDataType) { child.addChild(fac.createOMText(child, resObject.toString())); } else if (dataType instanceof Typedef) { @@ -454,6 +499,73 @@ public class CorbaUtil implements CorbaC } else if (dataType instanceof EnumType) { EnumValue enumValue = (EnumValue) resObject; child.addChild(fac.createOMText(child, enumValue.getValueAsString())); + } else if (dataType instanceof AnyType) { + Any any = (Any) resObject; + TypeCode typeCode = any.type(); + DataType contentDataType; + String dataTypeNameSpaceURI; + if (PrimitiveDataType.isPrimitive(typeCode)) { + contentDataType = new PrimitiveDataType(typeCode); + dataTypeNameSpaceURI = Constants.URI_DEFAULT_SCHEMA_XSD; + } else if (TCKind._tk_any == typeCode.kind().value()) { + dataTypeNameSpaceURI = Constants.URI_DEFAULT_SCHEMA_XSD; + contentDataType = new AnyType(); + } else { + try { + String id = typeCode.id(); + IDL idl = (IDL) service.getParameterValue(IDL_LITERAL); + Map complexTypes = idl.getCompositeDataTypes(); + String typeKey = id.substring(id.indexOf(":") + 1, id.lastIndexOf(":")).replaceAll("/", "::"); + contentDataType = (DataType) complexTypes.get(typeKey); + OMNamespace namespace = getNameSpaceForType(fac, service, (CompositeDataType) contentDataType); + dataTypeNameSpaceURI = namespace.getNamespaceURI(); + } catch (BadKind badKind) { + throw AxisFault.makeFault(badKind); + } + } + + if (contentDataType == null) { + throw new AxisFault("can't find the data type of the returned value."); + } + + Object value = CorbaUtil.extractValue(contentDataType, any); + + TypeTable typeTable = service.getTypeTable(); + QName anySchema = typeTable.getComplexSchemaType(CorbaConstants.ANY_TYPE_NAME); + if (anySchema == null) { + throw new AxisFault("CORBA.Any schema type is not defined."); + } + String defaultNSURI = anySchema.getNamespaceURI(); + String defaultNSPrefix = anySchema.getPrefix(); + + OMElement valueElement = fac.createOMElement(new QName(defaultNSURI, "value", defaultNSPrefix)); + processResponse(valueElement, child, value, contentDataType, fac, defaultNS, qualified, service); + child.addChild(valueElement); + + OMElement definitionElement = fac.createOMElement(new QName(defaultNSURI, "definition", defaultNSPrefix)); + definitionElement.addChild(fac.createOMText(dataTypeNameSpaceURI)); + + OMElement typeNameElement = fac.createOMElement(new QName(defaultNSURI, "typename", defaultNSPrefix)); + String typeName; + if (contentDataType instanceof PrimitiveDataType) { + typeName = ((PrimitiveDataType) contentDataType).getTypeName(); + if (String.class.getName().equals(typeName)) { + typeName = "string"; + } + } else if (contentDataType instanceof CompositeDataType) { + typeName = ((CompositeDataType) contentDataType).getName(); + } else if (contentDataType instanceof AnyType) { + typeName = CorbaConstants.ANY_TYPE_NAME; + } else { + throw new AxisFault("Invalid return type"); + } + + typeNameElement.addChild(fac.createOMText(typeName)); + + OMElement typeElement = fac.createOMElement(new QName(defaultNSURI, "type", defaultNSPrefix)); + typeElement.addChild(definitionElement); + typeElement.addChild(typeNameElement); + child.addChild(typeElement); } } @@ -476,6 +588,8 @@ public class CorbaUtil implements CorbaC } else if (type instanceof PrimitiveDataType) { PrimitiveDataType primitiveDataType = (PrimitiveDataType) type; return primitiveDataType.getTypeName(); + } else if (type instanceof AnyType) { + return CorbaConstants.ANY_TYPE_NAME; } return null; } @@ -496,9 +610,14 @@ public class CorbaUtil implements CorbaC case TCKind._tk_octet: arg.insert_octet(((Byte) value).byteValue()); break; case TCKind._tk_string: arg.insert_string((String) value); break; case TCKind._tk_wstring: arg.insert_wstring((String) value); break; - case TCKind._tk_any: arg.insert_any((Any) value); break; case TCKind._tk_value: arg.insert_Value((Serializable) value); break; case TCKind._tk_objref: arg.insert_Object((org.omg.CORBA.Object) value); break; + case TCKind._tk_any: + AnyValue anyValue = (AnyValue) value; + Any any = ORB.init().create_any(); + CorbaUtil.insertValue(any, anyValue.getContentType(), anyValue.getContent()); + arg.insert_any(any); + break; case TCKind._tk_struct: StructValue structValue = (StructValue) value; org.omg.CORBA_2_3.portable.OutputStream outputStream = (org.omg.CORBA_2_3.portable.OutputStream) arg.create_output_stream(); @@ -683,9 +802,13 @@ public class CorbaUtil implements CorbaC case TCKind._tk_octet: return new Byte("0"); case TCKind._tk_string: return ""; case TCKind._tk_wstring: return ""; - //case TCKind._tk_any: return new Any(); case TCKind._tk_value: return ""; //case TCKind._tk_objref: return new org.omg.CORBA.Object(); + case TCKind._tk_any: + AnyValue anyValue = new AnyValue(); + anyValue.setContentType(PrimitiveDataType.getPrimitiveDataType("string")); + anyValue.setContent(""); + return anyValue; case TCKind._tk_struct: Struct struct = (Struct) type; StructValue value = new StructValue(struct);