/// <summary> /// determines the operation name to use in a corba request for a method. /// </summary> internal static string GetPropertyRequestOperationName(PropertyInfo forProperty, bool forSetter) { string methodName; if (!forSetter) { methodName = GetRequestMethodNameFromAttr(forProperty.GetGetMethod()); } else { methodName = GetRequestMethodNameFromAttr(forProperty.GetSetMethod()); } if (methodName == null) { string mappedPropertyName = IdlNaming.MapClsNameToIdlName(forProperty.Name); if (!forSetter) { methodName = DetermineGetterTransmissionName(mappedPropertyName); } else { methodName = DetermineSetterTransmissionName(mappedPropertyName); } } return(methodName); }
public object MapToIdlStruct(Type clsType) { lock (structTCs) { StructTC result = structTCs[clsType] as StructTC; if (result != null) { return(result); } result = new StructTC(); RegisterCreatedTypeCodeForType(clsType, AttributeExtCollection.EmptyCollection, result); FieldInfo[] members = ReflectionHelper.GetAllDeclaredInstanceFieldsOrdered(clsType); StructMember[] structMembers = new StructMember[members.Length]; for (int i = 0; i < members.Length; i++) { omg.org.CORBA.TypeCode memberType = CreateOrGetTypeCodeForType(members[i].FieldType, ReflectionHelper.GetCustomAttriutesForField(members[i], true)); structMembers[i] = new StructMember(members[i].Name, memberType); } result.Initalize(Repository.GetRepositoryID(clsType), IdlNaming.ReverseIdlToClsNameMapping(clsType.Name), structMembers); structTCs[clsType] = result; return(result); } }
public object MapToIdlLocalInterface(Type clsType) { LocalIfTC result = new LocalIfTC(Repository.GetRepositoryID(clsType), IdlNaming.ReverseIdlToClsNameMapping(clsType.Name)); RegisterCreatedTypeCodeForType(clsType, AttributeExtCollection.EmptyCollection, result); return(result); }
public object MapToIdlConcreteInterface(System.Type dotNetType) { if (!dotNetType.Equals(ReflectionHelper.MarshalByRefObjectType)) { return(IdlNaming.MapFullTypeNameToIdlScoped(dotNetType)); } else { return("Object"); } }
public object MapToIdlEnum(Type clsType) { string[] names = Enum.GetNames(clsType); EnumTC result = new EnumTC(Repository.GetRepositoryID(clsType), IdlNaming.ReverseIdlToClsNameMapping(clsType.Name), names); RegisterCreatedTypeCodeForType(clsType, AttributeExtCollection.EmptyCollection, result); return(result); }
private object MapToIdlBoxedValueType(Type clsType, bool boxInAny) { // dotNetType is subclass of BoxedValueBase if (!clsType.IsSubclassOf(ReflectionHelper.BoxedValueBaseType)) { // mapper error: MapToIdlBoxedValue found incorrect type throw new INTERNAL(1929, CompletionStatus.Completed_MayBe); } Type boxedType; object[] attributesOnBoxed = new object[0]; try { boxedType = (Type)clsType.InvokeMember(BoxedValueBase.GET_BOXED_TYPE_METHOD_NAME, BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly, null, null, new object[0]); attributesOnBoxed = (object[])clsType.InvokeMember(BoxedValueBase.GET_BOXED_TYPE_ATTRIBUTES_METHOD_NAME, BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly, null, null, new object[0]); } catch (Exception) { // invalid type: clsType // static method missing or not callable: // BoxedValueBase.GET_BOXED_TYPE_METHOD_NAME throw new INTERNAL(1930, CompletionStatus.Completed_MayBe); } if (boxInAny) { omg.org.CORBA.TypeCode boxed = CreateOrGetTypeCodeForType(boxedType, AttributeExtCollection.ConvertToAttributeCollection(attributesOnBoxed)); ValueBoxTC result = new ValueBoxTC(Repository.GetRepositoryID(clsType), IdlNaming.ReverseIdlToClsNameMapping(clsType.Name), boxed); RegisterCreatedTypeCodeForType(clsType, AttributeExtCollection.EmptyCollection, result); return(result); } else { // don't use boxed form // therefore create a typecode for the type boxed inside // e.g. in case of a boxed sequence of int, there will be a idlsequence typecode with int as element type created. // e.g. in case, where a sequence of boxed valuetype is boxed, an idl sequence will be created containing a typecode // for the boxed type. omg.org.CORBA.TypeCodeImpl forBoxed = CreateOrGetTypeCodeForType(boxedType, AttributeExtCollection.ConvertToAttributeCollection(attributesOnBoxed)); return(forBoxed); } }
public object MapToIdlSequence(System.Type dotNetType, int bound, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) { if (m_useAnonymousSequences) { string refToElemType = (string)m_mapper.MapClsType(dotNetType.GetElementType(), elemTypeAttributes, this); return("sequence<" + refToElemType + ">"); } else { // use a typedef for non-anonymous sequence return(IdlNaming.GetFullyQualifiedIdlTypeDefAliasForSequenceType(dotNetType, bound, elemTypeAttributes)); } }
/// <summary> /// creates a CLS type name for a type represented by the IDL-id /// </summary> /// <param name="idlID"></param> /// <param name="assumeMappedFromIdl">should assume, that type represented by idlid is mapped from IDL to CLS</param> /// <returns> /// The typename for the idlID /// </returns> private static string CreateTypeNameForIDLId(string idlID, bool assumeMappedFromIdl) { int colonIndex = idlID.IndexOf(':', 4); if (colonIndex < 0) { // invalid repository id: idlID throw new INV_IDENT(9901, CompletionStatus.Completed_MayBe); } string typeName = idlID.Substring(4, colonIndex - 4); typeName = IdlNaming.MapIdlRepIdTypePartToClsName(typeName, assumeMappedFromIdl); return(typeName); }
/// <summary> /// determines the operation name to use in a corba request for a method. /// </summary> internal static string GetMethodRequestOperationName(MethodInfo method, bool isOverloaded) { string methodName = GetRequestMethodNameFromAttr(method); if (methodName == null) { // determine name for a native .NET method (not mapped from idl) // do a CLS to IDL mapping, because .NET server expect this for every client, also for a // native .NET client, which uses not CLS -> IDL -> CLS mapping methodName = IdlNaming.MapClsMethodNameToIdlName(method, isOverloaded); methodName = DetermineOperationTransmissionName(methodName); } return(methodName); }
public object MapToIdlConcreteInterface(Type clsType) { ObjRefTC result; if (!clsType.Equals(ReflectionHelper.MarshalByRefObjectType)) { result = new ObjRefTC(Repository.GetRepositoryID(clsType), IdlNaming.ReverseIdlToClsNameMapping(clsType.Name)); } else { result = new ObjRefTC(String.Empty, String.Empty); } RegisterCreatedTypeCodeForType(clsType, AttributeExtCollection.EmptyCollection, result); return(result); }
public object MapToIdlConcreateValueType(Type clsType) { omg.org.CORBA.TypeCode baseTypeCode; if (clsType.BaseType.Equals(ReflectionHelper.ObjectType) || clsType.BaseType.Equals(typeof(System.ComponentModel.MarshalByValueComponent))) { baseTypeCode = new NullTC(); } else { baseTypeCode = CreateOrGetTypeCodeForType(clsType.BaseType, AttributeExtCollection.EmptyCollection); } ValueTypeTC result = new ValueTypeTC(); RegisterCreatedTypeCodeForType(clsType, AttributeExtCollection.EmptyCollection, result); // create the TypeCodes for the members FieldInfo[] members = ReflectionHelper.GetAllDeclaredInstanceFieldsOrdered(clsType); ValueMember[] valueMembers = new ValueMember[members.Length]; for (int i = 0; i < members.Length; i++) { omg.org.CORBA.TypeCode memberType = CreateOrGetTypeCodeForType(members[i].FieldType, ReflectionHelper.GetCustomAttriutesForField(members[i], true)); short visibility; if (members[i].IsPrivate) { visibility = VISIBILITY_PRIVATE; } else { visibility = VISIBILITY_PUBLIC; } valueMembers[i] = new ValueMember(members[i].Name, memberType, visibility); } result.Initalize(Repository.GetRepositoryID(clsType), IdlNaming.ReverseIdlToClsNameMapping(clsType.Name), valueMembers, baseTypeCode, CONCRETE_VALUE_MOD); return(result); }
public object MapException(Type clsType) { // TODO: check this, generic user exception handling ... ExceptTC result = new ExceptTC(); RegisterCreatedTypeCodeForType(clsType, AttributeExtCollection.EmptyCollection, result); FieldInfo[] members = ReflectionHelper.GetAllDeclaredInstanceFieldsOrdered(clsType); StructMember[] exMembers = new StructMember[members.Length]; for (int i = 0; i < members.Length; i++) { omg.org.CORBA.TypeCode memberType = CreateOrGetTypeCodeForType(members[i].FieldType, ReflectionHelper.GetCustomAttriutesForField(members[i], true)); exMembers[i] = new StructMember(members[i].Name, memberType); } result.Initalize(Repository.GetRepositoryID(clsType), IdlNaming.ReverseIdlToClsNameMapping(clsType.Name), exMembers); return(result); }
/// <summary>creates the fully qualified type name for the box</summary> private string CreateBoxedArrayFullTypeName(Type arrayType) { Type arrayElemType = DetermineInnermostArrayElemType(arrayType); // unqualified name of the innermost element type of the array string arrayElemTypeName = IdlNaming.MapShortTypeNameToIdl(arrayElemType); // need the mapped name for identifier arrayElemTypeName = arrayElemTypeName.Replace(" ", "_"); string boxUnqual = "seq" + DetermineArrayRank(arrayType) + "_" + arrayElemTypeName; string namespaceBox = arrayElemType.Namespace; if ((namespaceBox != null) && (namespaceBox.Length > 0)) { namespaceBox = "org.omg.BoxedArray." + namespaceBox; } else { namespaceBox = "org.omg.BoxedArray"; } return(namespaceBox + "." + boxUnqual); }
public object MapToIdlAbstractValueType(Type clsType) { omg.org.CORBA.TypeCode baseTypeCode; if (clsType.BaseType.Equals(ReflectionHelper.ObjectType) || clsType.BaseType.Equals(typeof(System.ComponentModel.MarshalByValueComponent))) { baseTypeCode = new NullTC(); } else { baseTypeCode = CreateOrGetTypeCodeForType(clsType.BaseType, AttributeExtCollection.EmptyCollection); } ValueTypeTC result = new ValueTypeTC(); RegisterCreatedTypeCodeForType(clsType, AttributeExtCollection.EmptyCollection, result); result.Initalize(Repository.GetRepositoryID(clsType), IdlNaming.ReverseIdlToClsNameMapping(clsType.Name), new ValueMember[0], baseTypeCode, ABSTRACT_VALUE_MOD); return(result); }
/// <summary> /// returns the repository id to use for type. In the repIdForType the string identifying the /// type is returned. The result and the repIdForType can be different (e.g. SupportedInterface) /// </summary> private string GetRepositoryIDFromType(Type type, out string repIdForType) { string result; object[] attr = type.GetCustomAttributes(ReflectionHelper.RepositoryIDAttributeType, false); if (attr != null && attr.Length > 0) { RepositoryIDAttribute repIDAttr = (RepositoryIDAttribute)attr[0]; result = repIDAttr.Id; } else { result = IdlNaming.MapFullTypeNameToIdlRepId(type); } repIdForType = result; if (type.IsMarshalByRef) { attr = type.GetCustomAttributes(ReflectionHelper.SupportedInterfaceAttributeType, true); if (attr != null && attr.Length > 0) { SupportedInterfaceAttribute repIDFrom = (SupportedInterfaceAttribute)attr[0]; Type fromType = repIDFrom.FromType; if (fromType.Equals(type)) { throw new INTERNAL(1701, CompletionStatus.Completed_MayBe); } string repIdForInterface; result = GetRepositoryIDFromType(fromType, out repIdForInterface); // repository ID to use when serialising such a type } } if (IsValueTypeImplClass(type)) { string repIdForValType; result = GetRepositoryIDFromType(type.BaseType, out repIdForValType); // repository ID to use when serialising such a type } return(result); }
public object MapToIdlBoxedValueType(System.Type dotNetType, System.Type needsBoxingFrom) { // the dotNetType is a subclass of BoxedValueBase representing the boxed value type return(IdlNaming.MapFullTypeNameToIdlScoped(dotNetType)); }
/// <summary> /// returns the repository id, which will be assigned to a boxed value type generated at runtime /// for a .NET array type. /// </summary> internal string GetRepositoryIDForBoxedArrayType(Type arrayType) { string typeName = CreateBoxedArrayFullTypeName(arrayType); return(IdlNaming.MapFullTypeNameToIdlRepId(typeName)); }
/// <param name="elemNamespace">the namespace of the elementType</param> /// <returns> the unqualified elem-type name </returns> private static string ParseRMIArrayElemType(string rmiElemType, out string elemNamespace) { elemNamespace = string.Empty; // for primitve types, this is the correct namespace // first character in elemType determines what kind of type switch (rmiElemType[0]) { case 'I': return("long"); case 'Z': return("boolean"); case 'B': return("octet"); case 'C': return("wchar"); case 'D': return("double"); case 'F': return("float"); case 'J': return("long_long"); case 'S': return("short"); case 'L': if (rmiElemType.Length <= 1) { // invalid element type in RMI array repository id" throw new INV_IDENT(10004, CompletionStatus.Completed_MayBe); } string elemTypeName = rmiElemType.Substring(1, rmiElemType.Length - 1 - (rmiElemType[rmiElemType.Length - 1] == ';' ? 1 : 0)); string unqualName = string.Empty; int lastPIndex = elemTypeName.LastIndexOf('.'); if (lastPIndex < 0) { elemNamespace = string.Empty; unqualName = elemTypeName; } else { if (string.Compare(elemTypeName, 0, "java.lang", 0, lastPIndex) == 0 && string.Compare(elemTypeName, lastPIndex + 1, "String", 0, elemTypeName.Length - lastPIndex - 1) == 0) { // special case: map to CORBA.WStringValue elemNamespace = "CORBA"; unqualName = "WStringValue"; } else { elemNamespace = elemTypeName.Substring(0, lastPIndex); unqualName = elemTypeName.Substring(lastPIndex + 1); // map rmi name to cls name, handle e.g. clashes with cls keywords if (unqualName.StartsWith("_")) { unqualName = "J" + unqualName; // rmi mapping adds a J before a class name starting with _ } unqualName = IdlNaming.MapRmiNameToClsName(unqualName); elemNamespace = IdlNaming.MapRmiNameToClsName(elemNamespace); if (unqualName.StartsWith("_")) { // remove _ added by IDL to CLS mapping, because class name follows a seq<n>_, therefore _ not added // in IDL to CLS mapping unqualName = unqualName.Substring(1); } } } return(unqualName); default: // invalid element type identifier in RMI array repository id: firstChar throw new INV_IDENT(10003, CompletionStatus.Completed_MayBe); } }
/// <summary> /// create a CLS type name for a type represented by the RMI-id /// </summary> /// <param name="rmiID"></param> /// <returns></returns> private static string CreateTypeNameForRMIId(string rmiID) { string typeName; int colonIndex = rmiID.IndexOf(':', 4); if (colonIndex >= 0) { typeName = rmiID.Substring(4, colonIndex - 4); } else { typeName = rmiID.Substring(4); } // check for array type if (typeName.StartsWith("[")) { if (typeName.Length == 1) { // invalid rmi-repository-id: typeName throw new INV_IDENT(10002, CompletionStatus.Completed_MayBe); } string elemType = typeName.TrimStart('['); int arrayRank = typeName.Length - elemType.Length; // array rank = number of [ - characters // parse the elem-type, which is in RMI-ID format string elemNameSpace; string unqualElemType = ParseRMIArrayElemType(elemType, out elemNameSpace); if (elemNameSpace.Length > 0) { elemNameSpace = "." + elemNameSpace; } unqualElemType = ResolveRmiInnerTypeMapping(unqualElemType); // determine name of boxed value type typeName = "org.omg.boxedRMI" + elemNameSpace + ".seq" + arrayRank + "_" + unqualElemType; Debug.WriteLine("mapped rmi id to boxed value type name:" + typeName); } else { int lastPIndex = typeName.LastIndexOf("."); if (lastPIndex >= 0) { string elemNamespace = typeName.Substring(0, lastPIndex); string unqualName = typeName.Substring(lastPIndex + 1); if (unqualName.StartsWith("_")) { // rmi mapping adds a J before a class name starting with _ typeName = elemNamespace + ".J" + unqualName; } } else { if (typeName.StartsWith("_")) { // rmi mapping adds a J before a class name starting with _ typeName = "J" + typeName; } } typeName = ResolveRmiInnerTypeMapping(typeName); // do name mapping (e.g. resolve clashes with CLS keywords) typeName = IdlNaming.MapRmiNameToClsName(typeName); } return(typeName); }
public object MapToIdlLocalInterface(System.Type dotNetType) { return(IdlNaming.MapFullTypeNameToIdlScoped(dotNetType)); }
public object MapToIdlAbstractValueType(System.Type dotNetType) { return(IdlNaming.MapFullTypeNameToIdlScoped(dotNetType)); }
public object MapToIdlEnum(System.Type dotNetType) { return(IdlNaming.MapFullTypeNameToIdlScoped(dotNetType)); }
public object MapToIdlArray(System.Type dotNetType, int[] dimensions, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) { // use a typedef for arrays, because dimension is part of the name of the thing, the type is an array return(IdlNaming.GetFullyQualifiedIdlTypeDefAliasForArrayType(dotNetType, dimensions, elemTypeAttributes)); }
public object MapToIdlUnion(Type clsType) { UnionTC result = new UnionTC(); RegisterCreatedTypeCodeForType(clsType, AttributeExtCollection.EmptyCollection, result); // first get discriminator type FieldInfo discriminator = clsType.GetField(UnionGenerationHelper.DISCR_FIELD_NAME, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.NonPublic); omg.org.CORBA.TypeCode discrTypeCode = CreateOrGetTypeCodeForType(discriminator.FieldType, ReflectionHelper.GetCustomAttriutesForField(discriminator, true)); // get the methods used for typecode creation MethodInfo getCoveredDiscrMethod = clsType.GetMethod(UnionGenerationHelper.GET_COVERED_DISCR_VALUES, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); MethodInfo getDefaultFieldMethod = clsType.GetMethod(UnionGenerationHelper.GET_DEFAULT_FIELD, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); MethodInfo getFieldForDiscrVal = clsType.GetMethod(UnionGenerationHelper.GET_FIELD_FOR_DISCR_METHOD, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); // get all discriminator values used in switch-cases object[] coveredDiscrs = (object[])getCoveredDiscrMethod.Invoke(null, new object[0]); if (coveredDiscrs == null) { throw new INTERNAL(898, CompletionStatus.Completed_MayBe); } FieldInfo defaultField = (FieldInfo)getDefaultFieldMethod.Invoke(null, new object[0]); UnionSwitchCase[] cases = null; int defaultCaseNumber = -1; // no default case if (defaultField != null) { cases = new UnionSwitchCase[coveredDiscrs.Length + 1]; omg.org.CORBA.TypeCode elemType = CreateOrGetTypeCodeForType(defaultField.FieldType, ReflectionHelper.GetCustomAttriutesForField(defaultField, true)); // create a default value of type discriminiator type, because of possible discriminator types, this // is possible with Activator.CreateInstance ... object dummyValue = null; try { dummyValue = Activator.CreateInstance(discriminator.FieldType); } catch (Exception) { throw new MARSHAL(881, CompletionStatus.Completed_MayBe); } cases[coveredDiscrs.Length] = new UnionSwitchCase(dummyValue, defaultField.Name.Substring(2), elemType); defaultCaseNumber = coveredDiscrs.Length; } else { cases = new UnionSwitchCase[coveredDiscrs.Length]; } // add a UnionSwitchCase to typecode for every discriminator value used for (int i = 0; i < coveredDiscrs.Length; i++) { FieldInfo caseField = (FieldInfo)getFieldForDiscrVal.Invoke(null, new object[] { coveredDiscrs[i] }); if (caseField == null) { throw new INTERNAL(898, CompletionStatus.Completed_MayBe); } omg.org.CORBA.TypeCode elemType = CreateOrGetTypeCodeForType(caseField.FieldType, ReflectionHelper.GetCustomAttriutesForField(caseField, true)); // extract name of element field: strip m_ UnionSwitchCase switchCase = new UnionSwitchCase(coveredDiscrs[i], caseField.Name.Substring(2), elemType); cases[i] = switchCase; } result.Initalize(Repository.GetRepositoryID(clsType), IdlNaming.ReverseIdlToClsNameMapping(clsType.Name), discrTypeCode, defaultCaseNumber, cases); return(result); }