Author: eranga Date: Wed Apr 6 10:19:19 2011 New Revision: 1089383 URL: http://svn.apache.org/viewvc?rev=1089383&view=rev Log: AXIS2-4779 (Datatype fixed is not supported)
Fixed. Bow this CORBA module supports fixed data type as well Added: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/FixedType.java Modified: 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/ExpressionUtil.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/values/AbstractValue.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/SchemaGenerator.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/deployer/SchemaGenerator.java?rev=1089383&r1=1089382&r2=1089383&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 Wed Apr 6 10:19:19 2011 @@ -30,6 +30,7 @@ import org.apache.ws.commons.schema.*; import org.apache.ws.commons.schema.utils.NamespaceMap; import javax.xml.namespace.QName; +import java.math.BigDecimal; import java.net.URI; import java.util.*; @@ -343,29 +344,74 @@ public class SchemaGenerator implements typeTable.addComplexSchema(name, eltOuter.getQName()); } else { - XmlSchemaComplexType complexType = new XmlSchemaComplexType(xmlSchema); - XmlSchemaSequence sequence = new XmlSchemaSequence(); - XmlSchemaElement eltOuter = new XmlSchemaElement(); - eltOuter.setName(simpleName); - eltOuter.setQName(schemaTypeName); - complexType.setParticle(sequence); - complexType.setName(simpleName); - - xmlSchema.getItems().add(eltOuter); - xmlSchema.getElements().add(schemaTypeName, eltOuter); - eltOuter.setSchemaTypeName(complexType.getQName()); - - xmlSchema.getItems().add(complexType); - xmlSchema.getSchemaTypes().add(schemaTypeName, complexType); - - // adding this type to the table - typeTable.addComplexSchema(name, eltOuter.getQName()); if (dataType instanceof Typedef) { Typedef typedef = (Typedef) dataType; DataType aliasType = typedef.getDataType(); - sequence.getItems().add(generateSchemaforFieldsandProperties(xmlSchema, aliasType, "item", false)); + if (aliasType instanceof FixedType) { + XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType(xmlSchema); + XmlSchemaElement eltOuter = new XmlSchemaElement(); + eltOuter.setName(simpleName); + eltOuter.setQName(schemaTypeName); + simpleType.setName(simpleName); + + xmlSchema.getItems().add(eltOuter); + xmlSchema.getElements().add(schemaTypeName, eltOuter); + eltOuter.setSchemaTypeName(simpleType.getQName()); + + xmlSchema.getItems().add(simpleType); + xmlSchema.getSchemaTypes().add(schemaTypeName, simpleType); + + typeTable.addComplexSchema(name, eltOuter.getQName()); + XmlSchemaElement elt1 = new XmlSchemaElement(); + elt1.setName(name); + + XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction(); + restriction.setBaseTypeName(typeTable.getSimpleSchemaTypeName(BigDecimal.class.getName())); + + FixedType fixedType = (FixedType) aliasType; + XmlSchemaTotalDigitsFacet totalDigits = new XmlSchemaTotalDigitsFacet(fixedType.getDigits(), false); + restriction.getFacets().add(totalDigits); + XmlSchemaFractionDigitsFacet fractionDigits = new XmlSchemaFractionDigitsFacet(fixedType.getScale(), true); + restriction.getFacets().add(fractionDigits); + + simpleType.setContent(restriction); + } else { + XmlSchemaComplexType complexType = new XmlSchemaComplexType(xmlSchema); + XmlSchemaSequence sequence = new XmlSchemaSequence(); + XmlSchemaElement eltOuter = new XmlSchemaElement(); + eltOuter.setName(simpleName); + eltOuter.setQName(schemaTypeName); + complexType.setParticle(sequence); + complexType.setName(simpleName); + + xmlSchema.getItems().add(eltOuter); + xmlSchema.getElements().add(schemaTypeName, eltOuter); + eltOuter.setSchemaTypeName(complexType.getQName()); + + xmlSchema.getItems().add(complexType); + xmlSchema.getSchemaTypes().add(schemaTypeName, complexType); + + typeTable.addComplexSchema(name, eltOuter.getQName()); + sequence.getItems().add(generateSchemaforFieldsandProperties(xmlSchema, aliasType, "item", false)); + } } else { - //Set propertiesNames = new HashSet() ; + XmlSchemaComplexType complexType = new XmlSchemaComplexType(xmlSchema); + XmlSchemaSequence sequence = new XmlSchemaSequence(); + XmlSchemaElement eltOuter = new XmlSchemaElement(); + eltOuter.setName(simpleName); + eltOuter.setQName(schemaTypeName); + complexType.setParticle(sequence); + complexType.setName(simpleName); + + xmlSchema.getItems().add(eltOuter); + xmlSchema.getElements().add(schemaTypeName, eltOuter); + eltOuter.setSchemaTypeName(complexType.getQName()); + + xmlSchema.getItems().add(complexType); + xmlSchema.getSchemaTypes().add(schemaTypeName, complexType); + + typeTable.addComplexSchema(name, eltOuter.getQName()); + Member[] members = dataType.getMembers(); for (int i = 0; i < members.length; i++) { Member member = members[i]; @@ -378,6 +424,7 @@ public class SchemaGenerator implements } } } + schemaToIDLMapping.addSchemaType(dataType, schemaTypeName); } return schemaTypeName; } Modified: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/parser/ExpressionUtil.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/parser/ExpressionUtil.java?rev=1089383&r1=1089382&r2=1089383&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/parser/ExpressionUtil.java (original) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/parser/ExpressionUtil.java Wed Apr 6 10:19:19 2011 @@ -21,11 +21,13 @@ package org.apache.axis2.corba.idl.parse import antlr.collections.AST; import org.apache.axis2.corba.exceptions.InvalidIDLException; -import org.apache.axis2.corba.idl.types.*; -import org.omg.CORBA.TypeCode; +import org.apache.axis2.corba.idl.types.ConstType; +import org.apache.axis2.corba.idl.types.DataType; +import org.apache.axis2.corba.idl.types.Typedef; import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; -import java.util.Map; +import java.math.BigDecimal; public class ExpressionUtil { public static Object eval(AST expressionNode, DataType returnType, IDLVisitor visitor) throws InvalidIDLException { @@ -164,6 +166,9 @@ public class ExpressionUtil { case TCKind._tk_octet: valueObj = new Byte((byte) (((Byte) o1).byteValue() + ((Byte) o2).byteValue())); break; + case TCKind._tk_fixed: + valueObj = ((BigDecimal) o1).add((BigDecimal) o2); + break; default: throw new InvalidIDLException("Unsupported IDL token"); } @@ -195,6 +200,9 @@ public class ExpressionUtil { case TCKind._tk_octet: valueObj = new Byte((byte) (- ((Byte) o).byteValue())); break; + case TCKind._tk_fixed: + valueObj = ((BigDecimal) o).multiply(new BigDecimal(-1)); + break; default: throw new InvalidIDLException("Unsupported IDL token"); } @@ -226,6 +234,9 @@ public class ExpressionUtil { case TCKind._tk_octet: valueObj = new Byte((byte) (((Byte) o1).byteValue() - ((Byte) o2).byteValue())); break; + case TCKind._tk_fixed: + valueObj = ((BigDecimal) o1).subtract((BigDecimal) o2); + break; default: throw new InvalidIDLException("Unsupported IDL token"); } @@ -257,6 +268,9 @@ public class ExpressionUtil { case TCKind._tk_octet: valueObj = new Byte((byte) (((Byte) o1).byteValue() * ((Byte) o2).byteValue())); break; + case TCKind._tk_fixed: + valueObj = ((BigDecimal) o1).multiply((BigDecimal) o2); + break; default: throw new InvalidIDLException("Unsupported IDL token"); } @@ -288,6 +302,9 @@ public class ExpressionUtil { case TCKind._tk_octet: valueObj = new Byte((byte) (((Byte) o1).byteValue() / ((Byte) o2).byteValue())); break; + case TCKind._tk_fixed: + valueObj = ((BigDecimal) o1).divide((BigDecimal) o2); + break; default: throw new InvalidIDLException("Unsupported IDL token"); } @@ -487,6 +504,9 @@ public class ExpressionUtil { 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 "); } 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=1089383&r1=1089382&r2=1089383&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 Wed Apr 6 10:19:19 2011 @@ -25,6 +25,7 @@ import org.apache.axis2.corba.exceptions import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.math.BigDecimal; import java.util.Map; /** @@ -339,11 +340,11 @@ public class IDLVisitor /*implements AST return findDataType(typeNode, parentName, true, false); } - private DataType findDataType(AST typeNode, String parentName, boolean root, boolean noTypeDefForSeqs) throws InvalidIDLException { + private DataType findDataType(AST typeNode, String parentName, boolean root, boolean isInsideATypeDef) throws InvalidIDLException { // Check for sequences if (typeNode.getType()==IDLTokenTypes.LITERAL_sequence) { SequenceType sequenceType = visitAnonymousSequence(typeNode, parentName, root); - if (noTypeDefForSeqs) { + if (isInsideATypeDef) { return sequenceType; } Typedef typedef = new Typedef(); @@ -418,6 +419,29 @@ public class IDLVisitor /*implements AST innerElem.setModule(innerModule); idl.addType(innerElem); return innerElem; + } else if (typeNode.getType() == IDLTokenTypes.LITERAL_fixed) { + AST digitsNode = typeNode.getFirstChild(); + + short digits = 0; + short scale = 0; + if (digitsNode != null) { + AST scaleNode = digitsNode.getNextSibling(); + digits = Short.parseShort(digitsNode.getText()); + scale = Short.parseShort(scaleNode.getText()); + } + + FixedType fixedType = new FixedType(digits, scale); + if (isInsideATypeDef) { + return fixedType; + } + + Typedef typedef = new Typedef(); + typedef.setDataType(fixedType); + typedef.setModule(module); + String name = typeNode.getNextSibling().getText(); + typedef.setName(parentName + '_' + name); + idl.addType(typedef); + return typedef; } else { typeName = getTypeName(typeNode); } @@ -698,11 +722,27 @@ public class IDLVisitor /*implements AST ConstType constType = new ConstType(); constType.setModule(module); constType.setName(constName); - DataType type = findDataType(constTypeNode, constName); + DataType type = findDataType(constTypeNode, constName, true, true); constType.setDataType(type); AST constValueNode = constNameNode.getNextSibling(); + constType.setValue(ExpressionUtil.eval(constValueNode, type, this)); - //System.out.println(constType.getValue()); + + if (type instanceof FixedType) { + FixedType fixedType = (FixedType) type; + if (fixedType.getDigits() == 0 && fixedType.getScale() == 0) { + String value = constValueNode.getText().trim(); + short digits = (short) value.replace(".", "").length(); + int index = value.indexOf('.'); + short scale = (short) (index > -1 ? digits - index : 0); + fixedType.setDigits(digits); + fixedType.setScale(scale); + } + BigDecimal value = (BigDecimal) constType.getValue(); + value = value.setScale(fixedType.getDigits(), fixedType.getDigits()); + constType.setValue(value); + } + return constType; } Added: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/FixedType.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/FixedType.java?rev=1089383&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/FixedType.java (added) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/types/FixedType.java Wed Apr 6 10:19:19 2011 @@ -0,0 +1,54 @@ +/* + * 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.TypeCode; + +public class FixedType extends DataType { + + private short digits; + private short scale; + + public FixedType(short digits, short scale) { + this.digits = digits; + this.scale = scale; + } + + protected TypeCode generateTypeCode() { + return ORB.init().create_fixed_tc(digits, scale); + } + + public short getDigits() { + return digits; + } + + public void setDigits(short digits) { + this.digits = digits; + } + + public short getScale() { + return scale; + } + + public void setScale(short scale) { + this.scale = scale; + } +} Modified: axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/values/AbstractValue.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/values/AbstractValue.java?rev=1089383&r1=1089382&r2=1089383&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/values/AbstractValue.java (original) +++ axis/axis2/java/core/trunk/modules/corba/src/org/apache/axis2/corba/idl/values/AbstractValue.java Wed Apr 6 10:19:19 2011 @@ -19,16 +19,7 @@ package org.apache.axis2.corba.idl.values; -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.Member; -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.UnionType; +import org.apache.axis2.corba.idl.types.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.omg.CORBA.Any; @@ -38,6 +29,7 @@ import org.omg.CORBA_2_3.portable.InputS import org.omg.CORBA_2_3.portable.OutputStream; import java.io.Serializable; +import java.math.BigDecimal; public abstract class AbstractValue { protected Object[] memberValues; @@ -89,6 +81,7 @@ public abstract class AbstractValue { case TCKind._tk_alias: ((AliasValue) value).write(outputStream); break; case TCKind._tk_sequence: ((SequenceValue) value).write(outputStream); break; case TCKind._tk_array: ((ArrayValue) value).write(outputStream); break; + case TCKind._tk_fixed: outputStream.write_fixed((BigDecimal) value); break; default: log.error("ERROR! Invalid dataType"); break; @@ -115,7 +108,14 @@ public abstract class AbstractValue { case TCKind._tk_wstring: ret = inputStream.read_wstring(); break; case TCKind._tk_any: ret = inputStream.read_any(); break; case TCKind._tk_value: ret = inputStream.read_value(); break; - //case TCKind._tk_longdouble : + case TCKind._tk_fixed: + FixedType fixedType = (FixedType) dataType; + BigDecimal value = inputStream.read_fixed(); + if (value != null) { + value = value.movePointLeft(fixedType.getScale()); + } + ret = value; + break; case TCKind._tk_struct: StructValue structValue = new StructValue((Struct) dataType); structValue.read(inputStream); 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=1089383&r1=1089382&r2=1089383&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 Wed Apr 6 10:19:19 2011 @@ -53,6 +53,7 @@ import org.omg.CosNaming.NamingContextPa import javax.xml.namespace.QName; import java.io.*; +import java.math.BigDecimal; import java.util.*; //import java.io.FileInputStream; @@ -235,7 +236,7 @@ public class CorbaUtil implements CorbaC return null; DataType aliasType = typedef.getDataType(); - if (!(aliasType instanceof AbstractCollectionType)) { + if (!(aliasType instanceof AbstractCollectionType || aliasType instanceof FixedType)) { paramElement = paramElement.getFirstElement(); if (paramElement == null || !ARRAY_ITEM.equals(paramElement.getLocalName())) return null; @@ -383,6 +384,8 @@ public class CorbaUtil implements CorbaC return anyValue; } } + } else if (dataType instanceof FixedType) { + return new BigDecimal(((OMElement) param).getText()); } return null; } @@ -449,6 +452,8 @@ public class CorbaUtil implements CorbaC OMNamespace ns = getNameSpaceForType(fac, service, typedef); OMElement item = fac.createOMElement(ARRAY_ITEM, ns, child); processResponse(item, child, aliasValue.getValue(), typedef.getDataType(), fac, ns, qualified, service); + } else if (dataType instanceof FixedType) { + child.addChild(fac.createOMText(child, resObject.toString())); } else if (dataType instanceof AbstractCollectionType) { AbstractCollectionType collectionType = (AbstractCollectionType) dataType; AbstractCollectionValue collectionValue = (AbstractCollectionValue) resObject; @@ -643,7 +648,7 @@ public class CorbaUtil implements CorbaC AliasValue aliasValue = (AliasValue) value; outputStream = (org.omg.CORBA_2_3.portable.OutputStream) arg.create_output_stream(); arg.type(aliasValue.getTypeCode()); - aliasValue.write(outputStream); + aliasValue.write(outputStream);//TODO: returning fixed variables, inside structs, etc. arg.read_value(outputStream.create_input_stream (), aliasValue.getTypeCode()); break; case TCKind._tk_sequence: