Search in sources :

Example 1 with CompositeDataType

use of org.apache.axis2.corba.idl.types.CompositeDataType in project axis-axis2-java-core by apache.

the class CorbaUtil method extractValue.

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);
        OMElement paramElement;
        if (param instanceof OMElement)
            paramElement = (OMElement) param;
        else
            return null;
        DataType aliasType = typedef.getDataType();
        if (!(aliasType instanceof AbstractCollectionType || aliasType instanceof FixedType)) {
            paramElement = paramElement.getFirstElement();
            if (paramElement == null || !ARRAY_ITEM.equals(paramElement.getLocalName()))
                return null;
        }
        aliasValue.setValue(extractValue(aliasType, paramElement, mapping));
        return aliasValue;
    } else if (dataType instanceof PrimitiveDataType) {
        if (param != null)
            return parseValue(dataType, ((OMElement) param).getText());
    } else if (dataType instanceof AbstractCollectionType) {
        AbstractCollectionType collectionType = (AbstractCollectionType) dataType;
        OMElement paramElement;
        if (param instanceof OMElement)
            paramElement = (OMElement) param;
        else
            return null;
        Iterator paramsIter = paramElement.getChildElements();
        List children = new ArrayList();
        while (paramsIter.hasNext()) {
            children.add(extractValue(collectionType.getDataType(), paramsIter.next(), mapping));
        }
        AbstractCollectionValue collectionValue;
        if (collectionType.isArray()) {
            collectionValue = new ArrayValue((ArrayType) collectionType);
        } else if (collectionType.isSequence()) {
            collectionValue = new SequenceValue((SequenceType) collectionType);
        } else {
            return null;
        }
        collectionValue.setValues(children.toArray());
        return collectionValue;
    } else if (dataType instanceof EnumType) {
        EnumType enumType = (EnumType) dataType;
        String enumText = ((OMElement) param).getText();
        int index = enumType.getEnumMembers().indexOf(enumText);
        if (index >= 0) {
            EnumValue enumValue = new EnumValue(enumType);
            enumValue.setValue(index);
            return enumValue;
        }
    } else if (dataType instanceof UnionType) {
        UnionType unionType = (UnionType) dataType;
        OMElement unElement = ((OMElement) param).getFirstElement();
        String unionMemberName = unElement.getLocalName();
        UnionValue unionValue = new UnionValue(unionType);
        unionValue.setMemberName(unionMemberName);
        Member[] members = unionType.getMembers();
        UnionMember member = null;
        for (int i = 0; i < members.length; i++) {
            member = (UnionMember) members[i];
            if (member.getName().equals(unionMemberName)) {
                break;
            }
        }
        if (member != null) {
            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, mapping);
        AbstractValue value;
        if (compositeType instanceof ValueType)
            value = new ObjectByValue((ValueType) compositeType);
        else if (compositeType instanceof Struct)
            value = new StructValue((Struct) compositeType);
        else
            throw new CorbaInvocationException("Parameter type not supported");
        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;
            }
        }
    } else if (dataType instanceof FixedType) {
        return new BigDecimal(((OMElement) param).getText());
    }
    return null;
}
Also used : DefaultNamespaceGenerator(org.apache.axis2.description.java2wsdl.DefaultNamespaceGenerator) OMElement(org.apache.axiom.om.OMElement) QName(javax.xml.namespace.QName) BigDecimal(java.math.BigDecimal) CorbaInvocationException(org.apache.axis2.corba.exceptions.CorbaInvocationException)

Example 2 with CompositeDataType

use of org.apache.axis2.corba.idl.types.CompositeDataType in project axis-axis2-java-core by apache.

the class CorbaUtil method getNameSpaceForType.

private static OMNamespace getNameSpaceForType(SOAPFactory fac, AxisService service, CompositeDataType dataType) {
    TypeTable typeTable = service.getTypeTable();
    String fullname = (dataType.getModule() != null) ? dataType.getModule() + dataType.getName() : dataType.getName();
    fullname = fullname.replaceAll(CompositeDataType.MODULE_SEPERATOR, ".");
    QName qname = typeTable.getQNamefortheType(fullname);
    if (qname == null)
        return null;
    return fac.createOMNamespace(qname.getNamespaceURI(), qname.getPrefix());
}
Also used : QName(javax.xml.namespace.QName) TypeTable(org.apache.axis2.description.java2wsdl.TypeTable)

Example 3 with CompositeDataType

use of org.apache.axis2.corba.idl.types.CompositeDataType in project axis-axis2-java-core by apache.

the class SchemaGenerator method generateSchema.

/**
 * Generates schema for all the parameters in method. First generates schema for all different
 * parameter type and later refers to them.
 *
 * @return Returns XmlSchema.
 * @throws SchemaGeneratorException if failed
 */
public Collection generateSchema() throws SchemaGeneratorException {
    Map interfaces = idl.getInterfaces();
    if (interfaces == null)
        throw new SchemaGeneratorException("No interfaces defined");
    if (interfaceName == null)
        throw new SchemaGeneratorException("Interface name required");
    Interface intf = (Interface) interfaces.get(interfaceName);
    if (intf == null)
        throw new SchemaGeneratorException("Interface " + interfaceName + " does not exists");
    Operation[] operations = intf.getOperations();
    // since we do not support overload
    HashMap uniqueMethods = new HashMap();
    XmlSchemaComplexType methodSchemaType;
    XmlSchemaSequence sequence = null;
    List processedExs = new ArrayList();
    for (int i = 0; i < operations.length; i++) {
        Operation operation = operations[i];
        String operationName = operation.getName();
        if (excludeMethods.contains(operationName)) {
            continue;
        }
        if (uniqueMethods.get(operationName) != null) {
            throw new SchemaGeneratorException(" Sorry we don't support methods overloading !!!! ");
        }
        if (operation.hasRaises()) {
            List extypes = operation.getRaises();
            for (int j = 0; j < extypes.size(); j++) {
                ExceptionType extype = (ExceptionType) extypes.get(j);
                if (processedExs.contains(extype.getName()))
                    continue;
                processedExs.add(extype.getName());
                methodSchemaType = createSchemaTypeForMethodPart(extype.getName() + "Fault");
                sequence = new XmlSchemaSequence();
                generateSchemaForType(sequence, extype, extype.getName());
                methodSchemaType.setParticle(sequence);
            }
        }
        uniqueMethods.put(operationName, operation);
        // create the schema type for the method wrapper
        sequence = new XmlSchemaSequence();
        methodSchemaType = createSchemaTypeForMethodPart(operationName);
        methodSchemaType.setParticle(sequence);
        List paras = operation.getParams();
        List outparas = null;
        if (paras != null) {
            for (int j = 0; j < paras.size(); j++) {
                Member param = (Member) paras.get(j);
                String parameterName = param.getName();
                DataType paraType = param.getDataType();
                if (Member.MODE_INOUT.equals(param.getMode())) {
                    if (outparas == null)
                        outparas = new ArrayList();
                    outparas.add(param);
                } else if (Member.MODE_OUT.equals(param.getMode())) {
                    if (outparas == null)
                        outparas = new ArrayList();
                    outparas.add(param);
                    continue;
                }
                if (nonRpcMethods.contains(operationName)) {
                    generateSchemaForType(sequence, null, operationName);
                    break;
                } else {
                    generateSchemaForType(sequence, paraType, parameterName);
                }
            }
        }
        DataType returnType = operation.getReturnType();
        if ((returnType != null && !CorbaUtil.getQualifiedName(returnType).equals(VOID)) || outparas != null) {
            methodSchemaType = createSchemaTypeForMethodPart(operationName + RESPONSE);
            sequence = new XmlSchemaSequence();
            methodSchemaType.setParticle(sequence);
            if (returnType != null && !CorbaUtil.getQualifiedName(returnType).equals(VOID)) {
                String returnName = "return";
                if (nonRpcMethods.contains(operationName)) {
                    generateSchemaForType(sequence, null, returnName);
                } else {
                    generateSchemaForType(sequence, returnType, returnName);
                }
            }
            if (outparas != null) {
                for (int j = 0; j < outparas.size(); j++) {
                    Member param = (Member) outparas.get(j);
                    String parameterName = param.getName();
                    DataType paraType = param.getDataType();
                    if (nonRpcMethods.contains(operationName)) {
                        generateSchemaForType(sequence, null, operationName);
                        break;
                    } else {
                        generateSchemaForType(sequence, paraType, parameterName);
                    }
                }
            }
        }
    }
    // 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();
}
Also used : ExceptionType(org.apache.axis2.corba.idl.types.ExceptionType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SchemaGeneratorException(org.apache.axis2.corba.exceptions.SchemaGeneratorException) Operation(org.apache.axis2.corba.idl.types.Operation) Iterator(java.util.Iterator) PrimitiveDataType(org.apache.axis2.corba.idl.types.PrimitiveDataType) DataType(org.apache.axis2.corba.idl.types.DataType) CompositeDataType(org.apache.axis2.corba.idl.types.CompositeDataType) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) NamespaceMap(org.apache.ws.commons.schema.utils.NamespaceMap) Member(org.apache.axis2.corba.idl.types.Member) Interface(org.apache.axis2.corba.idl.types.Interface)

Example 4 with CompositeDataType

use of org.apache.axis2.corba.idl.types.CompositeDataType in project axis-axis2-java-core by apache.

the class SchemaGenerator method getModuleName.

private String getModuleName(DataType type) {
    if (type instanceof CompositeDataType) {
        CompositeDataType compositeType = (CompositeDataType) type;
        String module = compositeType.getModule();
        module = module.replaceAll("::", ".");
        if (module.endsWith(".")) {
            module = module.substring(0, module.length() - 1);
        }
        return module;
    } else {
        return "";
    }
}
Also used : CompositeDataType(org.apache.axis2.corba.idl.types.CompositeDataType)

Example 5 with CompositeDataType

use of org.apache.axis2.corba.idl.types.CompositeDataType in project axis-axis2-java-core by apache.

the class SchemaGenerator method generateSchemaForType.

private QName generateSchemaForType(XmlSchemaSequence sequence, DataType type, String partName) throws SchemaGeneratorException {
    boolean isArrayType = false;
    if (type != null) {
        isArrayType = (type instanceof ArrayType);
    }
    if (isArrayType) {
        ArrayType arrayType = (ArrayType) type;
        type = arrayType.getDataType();
    }
    String classTypeName;
    if (type == null) {
        classTypeName = "java.lang.Object";
    } else {
        classTypeName = CorbaUtil.getQualifiedName(type);
    }
    if (isArrayType && "byte".equals(classTypeName)) {
        classTypeName = "base64Binary";
        isArrayType = false;
    }
    if ("javax.activation.DataHandler".equals(classTypeName)) {
        classTypeName = "base64Binary";
    }
    QName schemaTypeName = typeTable.getSimpleSchemaTypeName(classTypeName);
    if (schemaTypeName == null && type instanceof CompositeDataType) {
        schemaTypeName = generateSchema((CompositeDataType) type);
        addContentToMethodSchemaType(sequence, schemaTypeName, partName, isArrayType);
        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;
}
Also used : ArrayType(org.apache.axis2.corba.idl.types.ArrayType) QName(javax.xml.namespace.QName) CompositeDataType(org.apache.axis2.corba.idl.types.CompositeDataType) AnyType(org.apache.axis2.corba.idl.types.AnyType)

Aggregations

QName (javax.xml.namespace.QName)5 CompositeDataType (org.apache.axis2.corba.idl.types.CompositeDataType)5 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 OMElement (org.apache.axiom.om.OMElement)2 SchemaGeneratorException (org.apache.axis2.corba.exceptions.SchemaGeneratorException)2 AnyType (org.apache.axis2.corba.idl.types.AnyType)2 DataType (org.apache.axis2.corba.idl.types.DataType)2 Member (org.apache.axis2.corba.idl.types.Member)2 PrimitiveDataType (org.apache.axis2.corba.idl.types.PrimitiveDataType)2 Typedef (org.apache.axis2.corba.idl.types.Typedef)2 TypeTable (org.apache.axis2.description.java2wsdl.TypeTable)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 OMNamespace (org.apache.axiom.om.OMNamespace)1 AxisFault (org.apache.axis2.AxisFault)1 CorbaInvocationException (org.apache.axis2.corba.exceptions.CorbaInvocationException)1 AbstractCollectionType (org.apache.axis2.corba.idl.types.AbstractCollectionType)1