Example #1
0
        public void MapToEntityFromMap(AuditConfiguration verCfg, object obj, IDictionary data,
                                       object primaryKey, IAuditReaderImplementor versionsReader, long revision)
        {
            if (data == null || obj == null)
            {
                return;
            }

            if (_propertyData.BeanName == null)
            {
                // If properties are not encapsulated in a component but placed directly in a class
                // (e.g. by applying <properties> tag).
                _delegate.MapToEntityFromMap(verCfg, obj, data, primaryKey, versionsReader, revision);
                return;
            }

            var setter = ReflectionTools.GetSetter(obj.GetType(), _propertyData);

            // If all properties are null and single, then the component has to be null also.
            var allNullAndSingle = true;

            foreach (var property in _delegate.Properties)
            {
                if (data[property.Key.Name] != null || !(property.Value is SinglePropertyMapper))
                {
                    allNullAndSingle = false;
                    break;
                }
            }

            if (allNullAndSingle)
            {
                // single property, but default value need not be null, so we'll set it to null anyway
                setter.Set(obj, null);
            }
            else
            {
                var componentType = Toolz.ResolveDotnetType(_componentClassName);
                var subObj        = ReflectionTools.CreateInstanceByDefaultConstructor(componentType);
                _delegate.MapToEntityFromMap(verCfg, subObj, data, primaryKey, versionsReader, revision);
                setter.Set(obj, subObj);
            }
        }
Example #2
0
        public void MapToEntityFromMap(AuditConfiguration verCfg, Object obj, IDictionary <String, Object> data,
                                       Object primaryKey, IAuditReaderImplementor versionsReader, long revision)
        {
            if (data == null || obj == null)
            {
                return;
            }

            //ORIG: Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData);
            PropertyInfo propInfo = obj.GetType().GetProperty(propertyData.Name);

            // If all properties are null and single, then the component has to be null also.
            bool allNullAndSingle = true;

            foreach (KeyValuePair <PropertyData, IPropertyMapper> property in _delegate.Properties)
            {
                if (data[property.Key.Name] != null || !(property.Value is SinglePropertyMapper))
                {
                    allNullAndSingle = false;
                    break;
                }
            }

            // And we don't have to set anything on the object - the default value is null
            if (!allNullAndSingle)
            {
                try {
                    //ORIG: Object subObj = ReflectHelper.getDefaultConstructor(
                    //        Thread.currentThread().getContextClassLoader().loadClass(componentClassName)).newInstance();
                    //setter.set(obj, subObj, null);
                    object subObj = Activator.CreateInstance(Toolz.ResolveDotnetType(componentClassName));
                    propInfo.SetValue(obj, subObj, null);

                    _delegate.MapToEntityFromMap(verCfg, subObj, data, primaryKey, versionsReader, revision);
                } catch (Exception e) {
                    throw new AuditException(e);
                }
            }
        }