use of org.apache.axis2.corba.idl.types.Typedef 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;
}
use of org.apache.axis2.corba.idl.types.Typedef 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;
}
use of org.apache.axis2.corba.idl.types.Typedef in project axis-axis2-java-core by apache.
the class IDLVisitor method findDataType.
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 (isInsideATypeDef) {
return sequenceType;
}
Typedef typedef = new Typedef();
typedef.setDataType(sequenceType);
typedef.setModule(module);
typedef.setName(parentName + '_' + sequenceType.getName());
idl.addType(typedef);
return typedef;
}
DataType dataType;
String typeName;
if (typeNode.getType() == IDLTokenTypes.LITERAL_unsigned) {
AST nextNode = typeNode.getNextSibling();
if (nextNode == null) {
throw new InvalidIDLException("'unsigned' without a data type");
} else if (nextNode.getType() == IDLTokenTypes.LITERAL_short) {
typeNode.setNextSibling(nextNode.getNextSibling());
typeNode.setFirstChild(nextNode.getFirstChild());
typeName = "ushort";
} else if (nextNode.getType() == IDLTokenTypes.LITERAL_long) {
AST nextToLong = nextNode.getNextSibling();
if (nextToLong != null && nextToLong.getType() == IDLTokenTypes.LITERAL_long) {
typeNode.setNextSibling(nextToLong.getNextSibling());
typeNode.setFirstChild(nextToLong.getFirstChild());
typeName = "ulonglong";
} else {
typeNode.setNextSibling(nextNode.getNextSibling());
typeNode.setFirstChild(nextNode.getFirstChild());
typeName = "ulong";
}
} else {
throw new InvalidIDLException("either 'long' or 'short' is expected after the 'unsigned' keyword");
}
} else if (typeNode.getType() == IDLTokenTypes.LITERAL_long) {
AST nextToLong = typeNode.getNextSibling();
if (nextToLong != null && nextToLong.getType() == IDLTokenTypes.LITERAL_long) {
typeNode.setNextSibling(nextToLong.getNextSibling());
typeNode.setFirstChild(nextToLong.getFirstChild());
typeName = "longlong";
} else {
typeName = "long";
}
} else if (typeNode.getType() == IDLTokenTypes.LITERAL_struct) {
String innerModule = module + parentName + INNERTYPE_SUFFIX + CompositeDataType.MODULE_SEPERATOR;
Struct innerElem = visitStruct(typeNode);
innerElem.setModule(innerModule);
idl.addType(innerElem);
return innerElem;
} else if (typeNode.getType() == IDLTokenTypes.LITERAL_valuetype) {
String innerModule = module + parentName + INNERTYPE_SUFFIX + CompositeDataType.MODULE_SEPERATOR;
ValueType innerElem = visitValueType(typeNode);
innerElem.setModule(innerModule);
idl.addType(innerElem);
return innerElem;
} else if (typeNode.getType() == IDLTokenTypes.LITERAL_exception) {
String innerModule = module + parentName + INNERTYPE_SUFFIX + CompositeDataType.MODULE_SEPERATOR;
Struct innerElem = visitException(typeNode);
innerElem.setModule(innerModule);
idl.addType(innerElem);
return innerElem;
} else if (typeNode.getType() == IDLTokenTypes.LITERAL_enum) {
String innerModule = module + parentName + INNERTYPE_SUFFIX + CompositeDataType.MODULE_SEPERATOR;
EnumType innerElem = visitEnum(typeNode);
innerElem.setModule(innerModule);
idl.addType(innerElem);
return innerElem;
} else if (typeNode.getType() == IDLTokenTypes.LITERAL_union) {
String innerModule = module + parentName + INNERTYPE_SUFFIX + CompositeDataType.MODULE_SEPERATOR;
UnionType innerElem = visitUnion(typeNode);
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);
}
/* Map compositeDataTypes = idl.getCompositeDataTypes();
if (compositeDataTypes!=null) {
if (!module.equals("")) {
if (!typeName.startsWith(module)) {
dataType = (DataType) idl.getCompositeDataTypes().get(module + typeName);
}
}
if (dataType==null && moduleForInnerTypes!=null) {
if (!typeName.startsWith(module)) {
dataType = (DataType) idl.getCompositeDataTypes().get(moduleForInnerTypes + typeName);
}
}
if (dataType==null)
dataType = (DataType) idl.getCompositeDataTypes().get(typeName);
}
if (dataType == null)
dataType = PrimitiveDataType.getPrimitiveDataType(typeName);
if (dataType == null)
throw new InvalidIDLException("Invalid data type: " + typeName);
}
*/
dataType = getDataType(typeName);
return dataType;
}
use of org.apache.axis2.corba.idl.types.Typedef in project axis-axis2-java-core by apache.
the class SchemaGenerator method generateSchemaforFieldsandProperties.
// moved code common to Fields & properties out of above method
private XmlSchemaElement generateSchemaforFieldsandProperties(XmlSchema xmlSchema, DataType type, String name, boolean forceNotNillable) throws SchemaGeneratorException {
boolean isArryType = false;
long maxOccurs = 0;
long minOccurs = 0;
if (type instanceof AbstractCollectionType) {
AbstractCollectionType collectionType = (AbstractCollectionType) type;
type = collectionType.getDataType();
isArryType = true;
int elementCount = collectionType.getElementCount();
if (collectionType.isArray()) {
minOccurs = maxOccurs = elementCount;
} else if (collectionType.isSequence()) {
minOccurs = 0;
maxOccurs = (elementCount == 0) ? Long.MAX_VALUE : elementCount;
}
if (type instanceof AbstractCollectionType) {
AbstractCollectionType child = (AbstractCollectionType) type;
Typedef typedef = new Typedef();
typedef.setDataType(type);
typedef.setModule(child.getElementModule());
typedef.setName("_" + (child.getDepth() - 1) + "_" + child.getElementName());
type = typedef;
}
}
String propertyTypeName = CorbaUtil.getQualifiedName(type);
if (isArryType && "byte".equals(propertyTypeName)) {
propertyTypeName = "base64Binary";
}
XmlSchemaElement elt1 = new XmlSchemaElement(xmlSchema, false);
elt1.setName(name);
if (isArryType && (!propertyTypeName.equals("base64Binary"))) {
elt1.setMaxOccurs(maxOccurs);
elt1.setMinOccurs(minOccurs);
}
if (isNillable(type) && !forceNotNillable)
elt1.setNillable(true);
if (typeTable.isSimpleType(propertyTypeName)) {
elt1.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(propertyTypeName));
} else if (type instanceof CompositeDataType) {
generateSchema((CompositeDataType) type);
elt1.setSchemaTypeName(typeTable.getComplexSchemaType(propertyTypeName));
if (!((NamespaceMap) xmlSchema.getNamespaceContext()).values().contains(typeTable.getComplexSchemaType(propertyTypeName).getNamespaceURI())) {
XmlSchemaImport importElement = new XmlSchemaImport(xmlSchema);
importElement.setNamespace(typeTable.getComplexSchemaType(propertyTypeName).getNamespaceURI());
xmlSchema.getItems().add(importElement);
((NamespaceMap) xmlSchema.getNamespaceContext()).put(generatePrefix(), typeTable.getComplexSchemaType(propertyTypeName).getNamespaceURI());
}
} else if (type instanceof AnyType) {
elt1.setSchemaTypeName(generateSchemaForAnyType());
} else {
throw new SchemaGeneratorException("Unsupported type:" + type);
}
return elt1;
}
use of org.apache.axis2.corba.idl.types.Typedef in project axis-axis2-java-core by apache.
the class CorbaUtil method extractValue.
public static Object extractValue(DataType returnType, Any returned) {
Object returnValue = null;
TypeCode typeCode = returnType.getTypeCode();
switch(typeCode.kind().value()) {
case TCKind._tk_void:
returnValue = null;
break;
case TCKind._tk_long:
returnValue = new Integer(returned.extract_long());
break;
case TCKind._tk_ulong:
returnValue = new Integer(returned.extract_ulong());
break;
case TCKind._tk_longlong:
returnValue = new Long(returned.extract_longlong());
break;
case TCKind._tk_ulonglong:
returnValue = new Long(returned.extract_ulonglong());
break;
case TCKind._tk_short:
returnValue = new Short(returned.extract_short());
break;
case TCKind._tk_ushort:
returnValue = new Short(returned.extract_ushort());
break;
case TCKind._tk_float:
returnValue = new Float(returned.extract_float());
break;
case TCKind._tk_double:
returnValue = new Double(returned.extract_double());
break;
case TCKind._tk_char:
returnValue = new Character(returned.extract_char());
break;
case TCKind._tk_wchar:
returnValue = new Character(returned.extract_wchar());
break;
case TCKind._tk_boolean:
returnValue = Boolean.valueOf(returned.extract_boolean());
break;
case TCKind._tk_octet:
returnValue = new Byte(returned.extract_octet());
break;
case TCKind._tk_string:
returnValue = returned.extract_string();
break;
case TCKind._tk_wstring:
returnValue = returned.extract_wstring();
break;
case TCKind._tk_any:
returnValue = returned.extract_any();
break;
case TCKind._tk_value:
returnValue = returned.extract_Value();
break;
case TCKind._tk_objref:
returnValue = returned.extract_Object();
break;
// case TCKind._tk_longdouble :
case TCKind._tk_struct:
Struct struct = (Struct) returnType;
StructValue structValue = new StructValue(struct);
org.omg.CORBA_2_3.portable.InputStream inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream();
structValue.read(inputStream);
returnValue = structValue;
break;
case TCKind._tk_except:
ExceptionType exceptionType = (ExceptionType) returnType;
ExceptionValue exceptionValue = new ExceptionValue(exceptionType);
inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream();
exceptionValue.read(inputStream);
returnValue = exceptionValue;
break;
case TCKind._tk_enum:
EnumType enumType = (EnumType) returnType;
EnumValue enumValue = new EnumValue(enumType);
inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream();
enumValue.read(inputStream);
returnValue = enumValue;
break;
case TCKind._tk_union:
UnionType unionType = (UnionType) returnType;
inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream();
UnionValue unionValue = new UnionValue(unionType);
unionValue.read(inputStream);
returnValue = unionValue;
break;
case TCKind._tk_alias:
Typedef typedef = (Typedef) returnType;
inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream();
AliasValue aliasValue = new AliasValue(typedef);
aliasValue.read(inputStream);
returnValue = aliasValue;
break;
case TCKind._tk_sequence:
SequenceType sequenceType = (SequenceType) returnType;
inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream();
SequenceValue sequenceValue = new SequenceValue(sequenceType);
sequenceValue.read(inputStream);
returnValue = sequenceValue;
break;
case TCKind._tk_array:
ArrayType arrayType = (ArrayType) returnType;
inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream();
ArrayValue arrayValue = new ArrayValue(arrayType);
arrayValue.read(inputStream);
returnValue = arrayValue;
break;
default:
log.error("ERROR! Invalid dataType");
break;
}
return returnValue;
}
Aggregations