private static Object extractValue()

in modules/corba/src/org/apache/axis2/corba/receivers/CorbaUtil.java [224:391]


    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;
    }