Example #1
0
        protected void AddTypeInfoMapping(IMap <String, ITypeInfoItem> typeInfoMap, IValueObjectConfig config, String boMemberName, StringBuilder sb)
        {
            String        voMemberName = config.GetValueObjectMemberName(boMemberName);
            ITypeInfoItem voMember     = TypeInfoProvider.GetHierarchicMember(config.ValueType, voMemberName);

            if (voMember == null)
            {
                return;
            }
            typeInfoMap.Put(boMemberName, voMember);
            if (sb == null)
            {
                return;
            }
            sb.Length = 0;
            String        voSpecifiedName   = sb.Append(voMemberName).Append("Specified").ToString();
            ITypeInfoItem voSpecifiedMember = TypeInfoProvider.GetHierarchicMember(config.ValueType, voSpecifiedName);

            if (voSpecifiedMember == null)
            {
                return;
            }
            sb.Length = 0;
            String boSpecifiedName = sb.Append(boMemberName).Append("Specified").ToString();

            typeInfoMap.Put(boSpecifiedName, voSpecifiedMember);
        }
Example #2
0
        public virtual void AfterPropertiesSet()
        {
            ParamChecker.AssertNotNull(EntityType, "EntityType");
            ParamChecker.AssertNotNull(FilterMember, "FilterMember");

            // It is intentended to have no null check for ModelContainer, because the class can be used without it!

            typeInfoItem = TypeInfoProvider.GetHierarchicMember(EntityType, FilterMember);
        }
Example #3
0
 public Object Invoke(String fieldName, Type enhancedType)
 {
     ITypeInfoItem[] members = new ITypeInfoItem[fields.Length];
     for (int a = fields.Length; a-- > 0;)
     {
         FieldInfo[] field = ReflectUtil.GetDeclaredFieldInHierarchy(enhancedType, fields[a].Name);
         members[a] = new FieldInfoItemASM(field[0]);
     }
     return(members);
 }
Example #4
0
 public static void SetEntityType(Type entityType, ITypeInfoItem member, IProperties properties)
 {
     if (member is TypeInfoItem)
     {
         ((TypeInfoItem)member).ElementType = entityType;
     }
     else
     {
         throw new Exception("TypeInfoItem not supported: " + member);
     }
 }
Example #5
0
        public void PostInit(ITypeInfoItem[] members)
        {
            this.Members = members;

            for (int a = this.Members.Length; a-- > 0;)
            {
                ITypeInfoItem member = this.Members[a];
                nameToMemberDict.Add(member.Name, member);
                nameToXmlMemberDict.Add(member.XMLName, member);
            }
        }
Example #6
0
 public void Restore(Object target)
 {
     for (int b = allMembers.Length; b-- > 0;)
     {
         ITypeInfoItem member        = allMembers[b];
         Object        originalValue = values[b];
         if (!Equals(member.GetValue(target), originalValue))
         {
             member.SetValue(target, originalValue);
         }
     }
 }
Example #7
0
        public Object PackInListType(IEnumerable referencedVOs, Type listType)
        {
            Object listTypeInst = Activator.CreateInstance(listType);

            if (referencedVOs == null)
            {
                return(listType);
            }

            ITypeInfoItem accessor = GetListTypeAccessor(listType);

            if (accessor.CanWrite)
            {
                if (!accessor.RealType.IsAssignableFrom(referencedVOs.GetType()))
                {
                    ICollection <Object> targetCollection;
                    Type propertyType = accessor.RealType;
                    if (typeof(IList).IsAssignableFrom(propertyType))
                    {
                        targetCollection = new List <Object>();
                        foreach (Object item in referencedVOs)
                        {
                            targetCollection.Add(item);
                        }
                    }
                    // TODO type of Set
                    //else if (typeof(ISet).IsAssignableFrom(propertyType))
                    //{
                    //    targetCollection = new HashSet<Object>(referencedVOs);
                    //}
                    else
                    {
                        throw new ArgumentException("Collection type of '" + propertyType.Name + "' is not supported");
                    }
                    referencedVOs = targetCollection;
                }
                accessor.SetValue(listTypeInst, referencedVOs);
            }
            else
            {
                IList       internalList = (IList)accessor.GetValue(listTypeInst);
                IEnumerator enumerator   = referencedVOs.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    Object entry = enumerator.Current;
                    internalList.Add(entry);
                }
            }

            return(listTypeInst);
        }
Example #8
0
        public virtual ITypeInfoItem GetHierarchicMember(Type entityType, String hierarchicMemberName)
        {
            String[]        memberPath  = memberPathSplitPattern.Split(hierarchicMemberName);
            ITypeInfoItem[] members     = new ITypeInfoItem[memberPath.Length];
            Type            currentType = entityType;

            for (int a = 0, size = memberPath.Length; a < size; a++)
            {
                String        memberName = memberPath[a];
                ITypeInfo     typeInfo   = GetTypeInfo(currentType);
                ITypeInfoItem member     = typeInfo.GetMemberByName(memberName);
                if (member == null)
                {
                    String memberNameLower           = memberName.ToLower();
                    IList <ITypeInfoItem> allMembers = typeInfo.Members;
                    for (int b = allMembers.Count; b-- > 0;)
                    {
                        if (allMembers[b].Name.ToLower().Equals(memberNameLower))
                        {
                            member = allMembers[b];
                            break;
                        }
                    }
                    if (member == null)
                    {
                        return(null);
                    }
                }
                currentType = member.RealType;
                members[a]  = member;
            }
            if (members.Length == 1)
            {
                return(members[0]);
            }
            else if (members.Length > 1)
            {
                ITypeInfoItem[] memberForParentPath = new ITypeInfoItem[members.Length - 1];
                Array.Copy(members, 0, memberForParentPath, 0, memberForParentPath.Length);
                ITypeInfoItem lastMember = members[members.Length - 1];
                return(new EmbeddedTypeInfoItem(hierarchicMemberName, lastMember, memberForParentPath));
            }
            else
            {
                throw new ArgumentException("Must never happen");
            }
        }
Example #9
0
        public void SetValue(Object obj, Object value)
        {
            Object currentObj = obj;

            for (int a = 0, size = memberPath.Length; a < size; a++)
            {
                ITypeInfoItem memberPathItem = memberPath[a];
                Object        childObj       = memberPathItem.GetValue(currentObj, false);
                if (childObj == null)
                {
                    childObj = Activator.CreateInstance(memberPathItem.RealType);
                    memberPathItem.SetValue(currentObj, childObj);
                }
                currentObj = childObj;
            }
            childMember.SetValue(currentObj, value);
        }
Example #10
0
        public virtual Object ReadObject(Type returnType, Type objType, int id, IReader reader)
        {
            Object obj = Activator.CreateInstance(objType);

            if (id > 0)
            {
                reader.PutObjectWithId(obj, id);
            }
            reader.NextTag();
            ITypeInfoItem[] members = reader.GetMembersOfType(objType);

            int                  index               = 0;
            String               valueAttribute      = XmlDictionary.ValueAttribute;
            String               primitiveElement    = XmlDictionary.PrimitiveElement;
            ICommandBuilder      commandBuilder      = CommandBuilder;
            ICommandTypeRegistry commandTypeRegistry = reader.CommandTypeRegistry;
            IConversionHelper    conversionHelper    = ConversionHelper;

            while (reader.IsStartTag())
            {
                ITypeInfoItem member = members[index++];
                Object        memberValue;
                if (primitiveElement.Equals(reader.GetElementName()))
                {
                    String value = reader.GetAttributeValue(valueAttribute);
                    memberValue = conversionHelper.ConvertValueToType(member.RealType, value);
                    reader.MoveOverElementEnd();
                }
                else
                {
                    memberValue = reader.ReadObject(member.RealType);
                }
                if (memberValue is IObjectFuture)
                {
                    IObjectFuture  objectFuture = (IObjectFuture)memberValue;
                    IObjectCommand command      = commandBuilder.Build(commandTypeRegistry, objectFuture, obj, member);
                    reader.AddObjectCommand(command);
                }
                else
                {
                    member.SetValue(obj, memberValue);
                }
            }
            return(obj);
        }
Example #11
0
        public Object GetValue(Object obj, bool allowNullEquivalentValue)
        {
            Object currentObj = obj;

            for (int a = 0, size = memberPath.Length; a < size; a++)
            {
                ITypeInfoItem memberPathItem = memberPath[a];
                currentObj = memberPathItem.GetValue(currentObj, allowNullEquivalentValue);
                if (currentObj == null)
                {
                    if (allowNullEquivalentValue)
                    {
                        return(childMember.NullEquivalentValue);
                    }
                    return(null);
                }
            }
            return(childMember.GetValue(currentObj, allowNullEquivalentValue));
        }
Example #12
0
        public virtual void WriteObject(Object obj, Type type, IWriter writer)
        {
            writer.WriteStartElementEnd();
            ITypeInfoItem[] members = writer.GetMembersOfType(type);

            String valueAttribute   = XmlDictionary.ValueAttribute;
            String primitiveElement = XmlDictionary.PrimitiveElement;

            for (int a = 0, size = members.Length; a < size; a++)
            {
                ITypeInfoItem field = members[a];

                Object fieldValue = field.GetValue(obj, false);
                if (field.RealType.IsPrimitive)
                {
                    writer.WriteStartElement(primitiveElement);
                    String convertedValue = ConversionHelper.ConvertValueToType <String>(fieldValue);
                    writer.WriteAttribute(valueAttribute, convertedValue);
                    writer.WriteEndElement();
                    continue;
                }
                writer.WriteObject(fieldValue);
            }
        }
Example #13
0
 public static A GetAnnotation <A>(ITypeInfoItem member, bool inherit) where A : Attribute
 {
     return(member.GetAnnotation <A>());
 }
Example #14
0
        protected void InitializeValueObjectMapping()
        {
            Object writeLock = GetWriteLock();

            lock (writeLock)
            {
                this.businessObjectSaveOrder = null;

                HashMap <Type, IISet <Type> > boTypeToBeforeBoTypes = new HashMap <Type, IISet <Type> >();
                HashMap <Type, IISet <Type> > boTypeToAfterBoTypes  = new HashMap <Type, IISet <Type> >();

                foreach (Entry <Type, IValueObjectConfig> entry in ValueObjectMap.GetExtensions())
                {
                    IValueObjectConfig voConfig = entry.Value;
                    Type            entityType  = voConfig.EntityType;
                    Type            valueType   = voConfig.ValueType;
                    IEntityMetaData metaData    = GetMetaData(entityType);

                    if (metaData == null)
                    {
                        // Currently no bo metadata found. We can do nothing here
                        return;
                    }
                    IMap <String, ITypeInfoItem> boNameToVoMember = GetTypeInfoMapForVo(valueType);

                    foreach (RelationMember boMember in metaData.RelationMembers)
                    {
                        String        boMemberName = boMember.Name;
                        String        voMemberName = voConfig.GetValueObjectMemberName(boMemberName);
                        ITypeInfoItem voMember     = boNameToVoMember.Get(boMemberName);
                        if (voConfig.IsIgnoredMember(voMemberName) || voMember == null)
                        {
                            continue;
                        }
                        Type voMemberRealType = voMember.RealType;
                        if (voConfig.HoldsListType(voMember.Name))
                        {
                            IPropertyInfo[] properties = PropertyInfoProvider.GetProperties(voMemberRealType);
                            if (properties.Length != 1)
                            {
                                throw new ArgumentException("ListTypes must have exactly one property");
                            }
                            voMemberRealType = TypeInfoProvider.GetMember(voMemberRealType, properties[0]).RealType;
                        }
                        if (!ImmutableTypeSet.IsImmutableType(voMemberRealType))
                        {
                            // vo member is either a list or a single direct relation to another VO
                            // This implies that a potential service can handle both VO types as new objects at once
                            continue;
                        }
                        // vo member only holds a id reference which implies that the related VO has to be persisted first to
                        // contain an id which can be referred to. But we do NOT know the related VO here, but we know
                        // the related BO where ALL potential VOs will be derived from:
                        Type boMemberElementType = boMember.ElementType;

                        if (Object.Equals(entityType, boMemberElementType))
                        {
                            continue;
                        }

                        AddBoTypeAfter(entityType, boMemberElementType, boTypeToBeforeBoTypes, boTypeToAfterBoTypes);
                        AddBoTypeBefore(entityType, boMemberElementType, boTypeToBeforeBoTypes, boTypeToAfterBoTypes);
                    }
                }
                List <Type> businessObjectSaveOrder = new List <Type>();

                foreach (Type boType in boTypeToBeforeBoTypes.KeySet())
                {
                    // BeforeBoType are types which have to be saved BEFORE saving the boType
                    bool added = false;
                    for (int a = 0, size = businessObjectSaveOrder.Count; a < size; a++)
                    {
                        Type orderedBoType = businessObjectSaveOrder[a];

                        // OrderedBoType is the type currently inserted at the correct position in the save order - as far as the keyset
                        // has been traversed, yet

                        ISet <Type> typesBeforeOrderedType = boTypeToBeforeBoTypes.Get(orderedBoType);
                        // typesBeforeOrderedType are types which have to be

                        bool orderedHasToBeAfterCurrent = typesBeforeOrderedType != null && typesBeforeOrderedType.Contains(boType);

                        if (!orderedHasToBeAfterCurrent)
                        {
                            // our boType has nothing to do with the orderedBoType. So we let is be at it is
                            continue;
                        }
                        businessObjectSaveOrder.Insert(a, boType);
                        added = true;
                        break;
                    }
                    if (!added)
                    {
                        businessObjectSaveOrder.Add(boType);
                    }
                }
                foreach (Type boType in boTypeToAfterBoTypes.KeySet())
                {
                    if (boTypeToBeforeBoTypes.ContainsKey(boType))
                    {
                        // already handled in the previous loop
                        continue;
                    }
                    bool added = false;
                    for (int a = businessObjectSaveOrder.Count; a-- > 0;)
                    {
                        Type orderedBoType = businessObjectSaveOrder[a];

                        // OrderedBoType is the type currently inserted at the correct position in the save order - as far as the keyset
                        // has been traversed, yet

                        ISet <Type> typesBeforeOrderedType = boTypeToBeforeBoTypes.Get(orderedBoType);

                        bool orderedHasToBeAfterCurrent = typesBeforeOrderedType != null && typesBeforeOrderedType.Contains(boType);

                        if (!orderedHasToBeAfterCurrent)
                        {
                            // our boType has nothing to do with the orderedBoType. So we let it be as it is
                            continue;
                        }
                        businessObjectSaveOrder.Insert(a, boType);
                        added = true;
                        break;
                    }
                    if (!added)
                    {
                        businessObjectSaveOrder.Add(boType);
                    }
                }
                this.businessObjectSaveOrder = businessObjectSaveOrder.ToArray();
            }
        }
Example #15
0
 public EmbeddedTypeInfoItem(String name, ITypeInfoItem childMember, params ITypeInfoItem[] memberPath)
 {
     this.name        = name;
     this.childMember = childMember;
     this.memberPath  = memberPath;
 }
Example #16
0
        public Type ReadFromAttribute(String classIdAttribute, String classNameAttribute, String classNamespaceAttribute, String classMemberAttribute, IReader reader)
        {
            String classIdValue = reader.GetAttributeValue(classIdAttribute);
            int    classId      = 0;

            if (classIdValue != null && classIdValue.Length > 0)
            {
                classId = Int32.Parse(classIdValue);
            }
            Type typeObj = (Type)reader.GetObjectById(classId, false);

            if (typeObj != null)
            {
                return(typeObj);
            }
            String name            = reader.GetAttributeValue(classNameAttribute);
            String namespaceString = reader.GetAttributeValue(classNamespaceAttribute);

            int dimensionCount = 0;

            while (name.EndsWith("[]"))
            {
                dimensionCount++;
                name = name.Substring(0, name.Length - 2);
            }
            typeObj = XmlTypeRegistry.GetType(name, namespaceString);

            String classMemberValue = reader.GetAttributeValue(classMemberAttribute);

            if (classMemberValue != null)
            {
                ITypeInfo       typeInfo    = TypeInfoProvider.GetTypeInfo(typeObj);
                String[]        memberNames = classMemberValue.Split(' ');
                ITypeInfoItem[] members     = new ITypeInfoItem[memberNames.Length];

                for (int a = memberNames.Length; a-- > 0;)
                {
                    String        memberName = memberNames[a];
                    ITypeInfoItem member     = typeInfo.GetMemberByXmlName(memberName);
                    if (member == null)
                    {
                        throw new Exception("No member found with xml name '" + memberName + "' on entity '" + typeObj.FullName + "'");
                    }
                    members[a] = member;
                }
                reader.PutMembersOfType(typeObj, members);
            }
            String gtIdValue           = classIdAttribute.Equals("gti") ? null : reader.GetAttributeValue("gti");
            Type   genericArgumentType = null;

            if (gtIdValue != null && gtIdValue.Length > 0)
            {
                genericArgumentType = ReadFromAttribute("gti", "gn", "gns", "gm", reader);
                typeObj             = typeObj.MakeGenericType(genericArgumentType);
            }
            while (dimensionCount-- > 0)
            {
                typeObj = typeObj.MakeArrayType();
            }
            reader.PutObjectWithId(typeObj, classId);
            return(typeObj);
        }
Example #17
0
        public Object UnpackListType(Object item)
        {
            ITypeInfoItem accessor = GetListTypeAccessor(item.GetType());

            return(accessor.GetValue(item));
        }
Example #18
0
 public bool IsMergeRelevant(ITypeInfoItem primitiveMember)
 {
     throw new NotSupportedException();
 }
        protected virtual bool EqualsItems(Type leftRealType, Object leftId, T right, ITypeInfoItem idMember)
        {
            if (right == null)
            {
                return(false);
            }
            Type rightRealType = ProxyHelper.GetRealType(right.GetType());

            if (!leftRealType.Equals(rightRealType))
            {
                return(false);
            }
            Object rightId = idMember.GetValue(right);

            leftId = ConversionHelper.ConvertValueToType(idMember.RealType, leftId);

            return(Object.Equals(leftId, rightId));
        }
Example #20
0
        protected void BackupObjects(Object obj, IDictionary <Object, RevertChangesSavepoint.IBackup> originalToValueBackup)
        {
            if (obj == null)
            {
                return;
            }
            Type objType = ProxyHelper.GetRealType(obj.GetType());

            if (ImmutableTypeSet.IsImmutableType(objType) || originalToValueBackup.ContainsKey(obj))
            {
                return;
            }
            originalToValueBackup.Add(obj, null);
            if (obj is Array)
            {
                Array sourceArray = (Array)obj;
                RevertChangesSavepoint.ArrayBackup arrayBackup = new RevertChangesSavepoint.ArrayBackup((Array)sourceArray.Clone());
                originalToValueBackup[obj] = arrayBackup;
                Type elementType = sourceArray.GetType().GetElementType();
                if (!ImmutableTypeSet.IsImmutableType(elementType))
                {
                    for (int a = sourceArray.Length; a-- > 0;)
                    {
                        Object arrayItem = sourceArray.GetValue(a);
                        BackupObjects(arrayItem, originalToValueBackup);
                    }
                }
                return;
            }
            if (obj is IList)
            {
                IList    list  = (IList)obj;
                Object[] array = new Object[list.Count];
                list.CopyTo(array, 0);
                RevertChangesSavepoint.ListBackup listBackup = new RevertChangesSavepoint.ListBackup(array);
                originalToValueBackup[obj] = listBackup;
                for (int a = list.Count; a-- > 0;)
                {
                    Object item = list[a];
                    BackupObjects(item, originalToValueBackup);
                }
                return;
            }
            else if (obj is IEnumerable)
            {
                foreach (Object item in (IEnumerable)obj)
                {
                    BackupObjects(item, originalToValueBackup);
                }
                return;
            }
            ITypeInfo typeInfo = TypeInfoProvider.GetTypeInfo(objType);

            ITypeInfoItem[] members        = typeInfo.Members;
            Object[]        originalValues = new Object[members.Length];
            RevertChangesSavepoint.ObjectBackup objBackup = new RevertChangesSavepoint.ObjectBackup(members, originalValues);
            originalToValueBackup[obj] = objBackup;

            for (int b = members.Length; b-- > 0;)
            {
                ITypeInfoItem member        = members[b];
                Object        originalValue = member.GetValue(obj);
                originalValues[b] = originalValue;

                BackupObjects(originalValue, originalToValueBackup);
            }
        }
Example #21
0
        public void WriteAsAttribute(Type type, String classIdAttribute, String classNameAttribute, String classNamespaceAttribute, String classMemberAttribute, IWriter writer)
        {
            Type realType = ProxyHelper.GetRealType(type);
            int  typeId   = writer.GetIdOfObject(type);

            if (typeId > 0)
            {
                writer.WriteAttribute(classIdAttribute, typeId.ToString());
                return;
            }
            typeId = writer.AcquireIdForObject(realType);
            writer.WriteAttribute(classIdAttribute, typeId.ToString());

            StringBuilder sb = StringBuilder;

            try
            {
                while (type.IsArray)
                {
                    sb.Append("[]");
                    type = type.GetElementType();
                }
                String      xmlName, xmlNamespace;
                IXmlTypeKey xmlType;
                Type        genericArgumentType = null;
                if (type.IsGenericType && !typeof(Nullable <>).Equals(type.GetGenericTypeDefinition()))
                {
                    xmlType             = XmlTypeRegistry.GetXmlType(type.GetGenericTypeDefinition());
                    genericArgumentType = type.GetGenericArguments()[0];
                }
                else
                {
                    xmlType = XmlTypeRegistry.GetXmlType(type);
                }
                xmlName      = xmlType.Name;
                xmlNamespace = xmlType.Namespace;
                if (sb.Length > 0)
                {
                    sb.Insert(0, xmlName);
                    writer.WriteAttribute(classNameAttribute, sb.ToString());
                    sb.Length = 0;
                }
                else
                {
                    writer.WriteAttribute(classNameAttribute, xmlName);
                }
                writer.WriteAttribute(classNamespaceAttribute, xmlNamespace);
                if (genericArgumentType != null)
                {
                    WriteAsAttribute(genericArgumentType, "gti", "gn", "gns", "gm", writer);
                }
                if (!realType.IsArray && !realType.IsEnum && !realType.IsInterface && !typeof(Type).Equals(realType))
                {
                    ITypeInfo            typeInfo       = TypeInfoProvider.GetTypeInfo(type);
                    ITypeInfoItem[]      members        = typeInfo.Members;
                    List <ITypeInfoItem> membersToWrite = new List <ITypeInfoItem>(members.Length);
                    for (int a = 0, size = members.Length; a < size; a++)
                    {
                        ITypeInfoItem member = members[a];
                        if (member.IsXMLIgnore)
                        {
                            continue;
                        }
                        if (sb.Length > 0)
                        {
                            sb.Append(' ');
                        }
                        sb.Append(member.Name);
                        membersToWrite.Add(member);
                    }
                    if (sb.Length > 0)
                    {
                        writer.WriteAttribute(classMemberAttribute, sb.ToString());
                        sb.Length = 0;
                    }
                    writer.PutMembersOfType(type, ListUtil.ToArray(membersToWrite));
                }
            }
            finally
            {
                sb.Length = 0;
            }
        }