Search in sources :

Example 1 with DataType

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

the class CorbaInvoker method invoke.

public Object invoke() throws CorbaInvocationException {
    // Create request
    Request request = object._request(operation.getName());
    // Set parameters
    Any arg = null;
    List memArgs = new ArrayList();
    if (parameters != null) {
        List patamList = new LinkedList(Arrays.asList(parameters));
        Iterator paramsIter = patamList.iterator();
        for (int i = 0; i < parameterTypeList.size(); i++) {
            Member member = (Member) parameterTypeList.get(i);
            DataType type = member.getDataType();
            Object value = null;
            String mode = member.getMode();
            if (mode.equals(Member.MODE_IN)) {
                arg = request.add_in_arg();
                value = paramsIter.next();
            } else if (mode.equals(Member.MODE_INOUT)) {
                arg = request.add_inout_arg();
                value = paramsIter.next();
            } else if (mode.equals(Member.MODE_OUT)) {
                arg = request.add_out_arg();
                value = CorbaUtil.getEmptyValue(type);
            }
            memArgs.add(arg);
            CorbaUtil.insertValue(arg, type, value);
        }
    }
    // Set return type
    DataType returnType = operation.getReturnType();
    if (returnType != null) {
        TypeCode typeCode = returnType.getTypeCode();
        request.set_return_type(typeCode);
    }
    // Set exceptions
    List exceptions = operation.getRaises();
    if (exceptions != null && !exceptions.isEmpty()) {
        ExceptionList exceptionList = request.exceptions();
        for (int i = 0; i < exceptions.size(); i++) {
            ExceptionType exType = (ExceptionType) exceptions.get(i);
            exceptionList.add(exType.getTypeCode());
        }
    }
    // Invoke
    request.invoke();
    // Get exception
    Object returnValue = null;
    Exception exception = request.env().exception();
    if (exception == null) {
        // Extract the return value
        if (returnType != null) {
            Any returned = request.return_value();
            returnValue = CorbaUtil.extractValue(returnType, returned);
        }
        // Extract the values of inout and out parameters
        returnedParams = new ArrayList();
        for (int i = 0; i < parameterTypeList.size(); i++) {
            Member member = (Member) parameterTypeList.get(i);
            String mode = member.getMode();
            if (mode.equals(Member.MODE_INOUT) || mode.equals(Member.MODE_OUT)) {
                returnedParams.add(CorbaUtil.extractValue(member.getDataType(), (Any) memArgs.get(i)));
            }
        }
    } else {
        if (exception instanceof UnknownUserException) {
            UnknownUserException userException = (UnknownUserException) exception;
            TypeCode exTypeCode = userException.except.type();
            ExceptionType exceptionType = null;
            if (exceptions != null && !exceptions.isEmpty()) {
                for (int i = 0; i < exceptions.size(); i++) {
                    ExceptionType exType = (ExceptionType) exceptions.get(i);
                    if (exTypeCode.equal(exType.getTypeCode())) {
                        exceptionType = exType;
                        break;
                    }
                }
            }
            if (exceptionType == null) {
                throw new CorbaInvocationException(exception);
            } else {
                ExceptionValue exceptionValue = (ExceptionValue) CorbaUtil.extractValue(exceptionType, userException.except);
                if (exceptionValue != null)
                    throw exceptionValue.getException();
            }
        } else {
            throw new CorbaInvocationException(exception);
        }
    }
    return returnValue;
}
Also used : ExceptionType(org.apache.axis2.corba.idl.types.ExceptionType) TypeCode(org.omg.CORBA.TypeCode) Request(org.omg.CORBA.Request) ArrayList(java.util.ArrayList) UnknownUserException(org.omg.CORBA.UnknownUserException) ExceptionList(org.omg.CORBA.ExceptionList) Any(org.omg.CORBA.Any) LinkedList(java.util.LinkedList) CorbaInvocationException(org.apache.axis2.corba.exceptions.CorbaInvocationException) UnknownUserException(org.omg.CORBA.UnknownUserException) ExceptionValue(org.apache.axis2.corba.idl.values.ExceptionValue) Iterator(java.util.Iterator) DataType(org.apache.axis2.corba.idl.types.DataType) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ExceptionList(org.omg.CORBA.ExceptionList) CorbaInvocationException(org.apache.axis2.corba.exceptions.CorbaInvocationException) Member(org.apache.axis2.corba.idl.types.Member)

Example 2 with DataType

use of org.apache.axis2.corba.idl.types.DataType 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 3 with DataType

use of org.apache.axis2.corba.idl.types.DataType 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 4 with DataType

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

the class CorbaUtil method getIDL.

public static IDL getIDL(AxisService service, ORB orb, String dirName) throws CorbaException {
    Parameter idlFile = service.getParameter(IDL_FILE);
    if (idlFile == null) {
        throw new CorbaInvocationException("Please specify the IDL file");
    }
    String idlFileName = ((String) idlFile.getValue()).trim();
    String cacheKey = dirName + File.separator + idlFileName;
    IDL idl = (IDL) IDL_CACHE.get(cacheKey);
    if (idl == null) {
        try {
            /*File file = new File(dirName);
                InputStream stream;
                if (file.isDirectory()) {
                    stream = new FileInputStream(cacheKey);
                } else {
                    ZipInputStream zin = new ZipInputStream(new FileInputStream(file));

                    ZipEntry entry;
                    boolean found = false;
                    while ((entry = zin.getNextEntry()) != null) {
                        if (entry.getName().equalsIgnoreCase(idlFileName)) {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                        new CorbaInvocationException("cannot find " + idlFileName + " in " + file.getPath());

                    stream = zin;
                }*/
            InputStream stream = new PreProcessorInputStream(dirName, idlFileName);
            // TODO: Set pre-processor system and user input paths
            IDLProcessor idlProcessor = new IDLProcessor(stream);
            idl = idlProcessor.process();
            stream.close();
            IDL_CACHE.put(cacheKey, idl);
        } catch (IOException e) {
            throw new CorbaInvocationException("cannot process idl file", e);
        }
    }
    Map types = idl.getCompositeDataTypes();
    if (types != null) {
        Iterator iter = types.values().iterator();
        while (iter.hasNext()) {
            DataType type = (DataType) iter.next();
            if (type instanceof ValueType) {
                StreamableValueFactory.register(orb, (ValueType) type);
            }
        }
    }
    return idl;
}
Also used : PreProcessorInputStream(org.apache.axis2.corba.idl.PreProcessorInputStream) IDLProcessor(org.apache.axis2.corba.idl.IDLProcessor) Parameter(org.apache.axis2.description.Parameter) PreProcessorInputStream(org.apache.axis2.corba.idl.PreProcessorInputStream) CorbaInvocationException(org.apache.axis2.corba.exceptions.CorbaInvocationException)

Example 5 with DataType

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

the class ExpressionUtil method getValueObject.

private static Object getValueObject(String value, DataType type) throws InvalidIDLException {
    TCKind kind = type.getTypeCode().kind();
    Object valueObj;
    switch(kind.value()) {
        case TCKind._tk_long:
        case TCKind._tk_ulong:
            valueObj = new Integer(value);
            break;
        case TCKind._tk_longlong:
        case TCKind._tk_ulonglong:
            valueObj = new Long(value);
            break;
        case TCKind._tk_float:
            valueObj = new Float(value);
            break;
        case TCKind._tk_short:
        case TCKind._tk_ushort:
            valueObj = new Short(value);
            break;
        case TCKind._tk_char:
        case TCKind._tk_wchar:
            valueObj = new Character(value.charAt(0));
            break;
        case TCKind._tk_double:
            valueObj = new Double(value);
            break;
        case TCKind._tk_octet:
            valueObj = new Byte(value);
            break;
        case TCKind._tk_string:
        case TCKind._tk_wstring:
            valueObj = value;
            break;
        case TCKind._tk_alias:
            Typedef typedef = (Typedef) type;
            valueObj = getValueObject(value, typedef.getDataType());
            break;
        case TCKind._tk_fixed:
            valueObj = new BigDecimal(value);
            break;
        default:
            throw new InvalidIDLException("Unsupported IDL token ");
    }
    return valueObj;
}
Also used : InvalidIDLException(org.apache.axis2.corba.exceptions.InvalidIDLException) Typedef(org.apache.axis2.corba.idl.types.Typedef) TCKind(org.omg.CORBA.TCKind) BigDecimal(java.math.BigDecimal)

Aggregations

DataType (org.apache.axis2.corba.idl.types.DataType)11 InvalidIDLException (org.apache.axis2.corba.exceptions.InvalidIDLException)8 QName (javax.xml.namespace.QName)7 AbstractCollectionType (org.apache.axis2.corba.idl.types.AbstractCollectionType)6 AST (antlr.collections.AST)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 CompositeDataType (org.apache.axis2.corba.idl.types.CompositeDataType)5 BigDecimal (java.math.BigDecimal)4 ExceptionType (org.apache.axis2.corba.idl.types.ExceptionType)4 Member (org.apache.axis2.corba.idl.types.Member)4 TypeCode (org.omg.CORBA.TypeCode)4 CorbaInvocationException (org.apache.axis2.corba.exceptions.CorbaInvocationException)3 Typedef (org.apache.axis2.corba.idl.types.Typedef)3 UnionType (org.apache.axis2.corba.idl.types.UnionType)3 TypeTable (org.apache.axis2.description.java2wsdl.TypeTable)3 Iterator (java.util.Iterator)2 Map (java.util.Map)2 OMElement (org.apache.axiom.om.OMElement)2 SchemaGeneratorException (org.apache.axis2.corba.exceptions.SchemaGeneratorException)2