Esempio n. 1
0
		public override IMap DeepClone()
		{
			IPropertyMap propertyMap = new PropertyMap();
			DeepCopy(propertyMap);
			return propertyMap;
		}
Esempio n. 2
0
        public static IDomainMap LoadFromAttributes(Assembly asm, bool useCache,bool validate)
        {
            IDomainMap domainMap = new DomainMap();

            foreach (DomainMapAttribute domainMapAttribute in asm.GetCustomAttributes(typeof(DomainMapAttribute), false))
            {
                DomainMap.FromDomainMapAttribute(domainMapAttribute, asm, domainMap);
                break;
            }

            foreach (SourceMapAttribute sourceMapAttribute in asm.GetCustomAttributes(typeof(SourceMapAttribute), false))
            {
                ISourceMap sourceMap = new SourceMap();
                sourceMap.DomainMap = domainMap;

                SourceMap.FromSourceMapAttribute(sourceMapAttribute, sourceMap);
                break;
            }

            //Make this 2-pass so that mapped inheritance hierarchies can be found.

            foreach (Type type in asm.GetTypes())
            {
                foreach (ClassMapAttribute classMapAttribute in type.GetCustomAttributes(typeof(ClassMapAttribute), false))
                {
                    IClassMap classMap = new ClassMap();
                    classMap.DomainMap = domainMap;
                    classMap.Name = type.Name;
                    string waste = classMapAttribute.DocElement ; // The idiot compiler won't compile unless I use the stinkin' classMapAttribute somehow...
                    break;
                }
            }

            foreach (Type type in asm.GetTypes())
            {
                foreach (ClassMapAttribute classMapAttribute in type.GetCustomAttributes(typeof(ClassMapAttribute), false))
                {
                    IClassMap classMap = domainMap.MustGetClassMap(type);
                    ClassMap.FromClassMapAttribute(classMapAttribute, type, classMap);

                    foreach (PropertyInfo propInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                    {
                        foreach (PropertyMapAttribute propertyMapAttribute in propInfo.GetCustomAttributes(typeof(PropertyMapAttribute), false))
                        {
                            IPropertyMap propertyMap = new PropertyMap();
                            propertyMap.ClassMap = classMap;
                            PropertyMap.FromPropertyMapAttribute(propertyMapAttribute, propInfo, propertyMap);

                            break;
                        }
                    }

                    break;
                }
            }

            RecalculateModel(domainMap);

            domainMap.Dirty = false;

            if (validate)
                ((DomainMap)domainMap).Validate();

            return domainMap;
        }
		protected virtual void DeserializePropertyMap(IClassMap classMap, XmlNode xmlProp)
		{
			IPropertyMap propertyMap = new PropertyMap();
			string str;
			string[] arr;
			bool first;
			propertyMap.ClassMap = classMap;
			if (!(xmlProp.Attributes["name"] == null))
			{
				propertyMap.Name = xmlProp.Attributes["name"].Value;
			}
			if (!(xmlProp.Attributes["validate"] == null))
			{
				propertyMap.ValidateMethod = xmlProp.Attributes["validate"].Value;
			}
			if (!(xmlProp.Attributes["validation"] == null))
			{
				propertyMap.ValidationMode = (ValidationMode) Enum.Parse(typeof (ValidationMode), xmlProp.Attributes["validation"].Value);
			}
			if (!(xmlProp.Attributes["source-property"] == null))
			{
				propertyMap.SourceProperty = xmlProp.Attributes["source-property"].Value;
			}
			if (!(xmlProp.Attributes["source"] == null))
			{
				propertyMap.Source = xmlProp.Attributes["source"].Value;
			}
			if (!(xmlProp.Attributes["doc-source"] == null))
			{
				propertyMap.DocSource = xmlProp.Attributes["doc-source"].Value;
			}
			if (!(xmlProp.Attributes["nullable"] == null))
			{
				propertyMap.IsNullable = ParseBool(xmlProp.Attributes["nullable"].Value);
			}
			if (!(xmlProp.Attributes["source-assigned"] == null))
			{
				propertyMap.IsAssignedBySource = ParseBool(xmlProp.Attributes["source-assigned"].Value);
			}
			if (!(xmlProp.Attributes["max-length"] == null))
			{
				propertyMap.MaxLength = Int32.Parse(xmlProp.Attributes["max-length"].Value);
			}
			if (!(xmlProp.Attributes["min-length"] == null))
			{
				propertyMap.MinLength = Int32.Parse(xmlProp.Attributes["min-length"].Value);
			}
			if (!(xmlProp.Attributes["max-value"] == null))
			{
				propertyMap.MaxValue = xmlProp.Attributes["max-value"].Value;
			}
			if (!(xmlProp.Attributes["min-value"] == null))
			{
				propertyMap.MinValue = xmlProp.Attributes["min-value"].Value;
			}
			if (!(xmlProp.Attributes["table"] == null))
			{
				propertyMap.Table = xmlProp.Attributes["table"].Value;
			}
			if (!(xmlProp.Attributes["doc-attribute"] == null))
			{
				propertyMap.DocAttribute = xmlProp.Attributes["doc-attribute"].Value;
			}
			if (!(xmlProp.Attributes["doc-element"] == null))
			{
				propertyMap.DocElement = xmlProp.Attributes["doc-element"].Value;
			}
			if (!(xmlProp.Attributes["doc-mode"] == null))
			{
				propertyMap.DocPropertyMapMode = (DocPropertyMapMode) Enum.Parse(typeof (DocPropertyMapMode), xmlProp.Attributes["doc-mode"].Value);
			}
			if (!(xmlProp.Attributes["columns"] == null))
			{
				first = true;
				str = xmlProp.Attributes["columns"].Value;
				if (str.Length > 0)
				{
					arr = str.Split(',');
					foreach (string iStr in arr)
					{
						str = iStr.Trim();
						if (str.Length > 0)
						{
							if (first)
							{
								first = false;
								propertyMap.Column = str;
							}
							else
							{
								propertyMap.AdditionalColumns.Add(str);
							}
						}
					}
				}
			}
			if (!(xmlProp.Attributes["id-columns"] == null))
			{
				first = true;
				str = xmlProp.Attributes["id-columns"].Value;
				if (str.Length > 0)
				{
					arr = str.Split(',');
					foreach (string iStr in arr)
					{
						str = iStr.Trim();
						if (str.Length > 0)
						{
							if (first)
							{
								first = false;
								propertyMap.IdColumn = str;
							}
							else
							{
								propertyMap.AdditionalIdColumns.Add(str);
							}
						}
					}
				}
			}
			if (!(xmlProp.Attributes["type"] == null))
			{
				propertyMap.DataType = xmlProp.Attributes["type"].Value;
			}
			if (!(xmlProp.Attributes["field"] == null))
			{
				propertyMap.FieldName = xmlProp.Attributes["field"].Value;
			}
			if (!(xmlProp.Attributes["list"] == null))
			{
				propertyMap.IsCollection = ParseBool(xmlProp.Attributes["list"].Value);
			}
			if (!(xmlProp.Attributes["item-type"] == null))
			{
				propertyMap.ItemType = xmlProp.Attributes["item-type"].Value;
			}
			if (!(xmlProp.Attributes["order-by"] == null))
			{
				propertyMap.OrderBy = xmlProp.Attributes["order-by"].Value;
			}
			if (!(xmlProp.Attributes["modifier"] == null))
			{
				propertyMap.PropertyModifier = (PropertyModifier) Enum.Parse(typeof (PropertyModifier), xmlProp.Attributes["modifier"].Value);
			}
			if (!(xmlProp.Attributes["id"] == null))
			{
				propertyMap.IsIdentity = ParseBool(xmlProp.Attributes["id"].Value);
			}
			if (!(xmlProp.Attributes["id-index"] == null))
			{
				propertyMap.IdentityIndex = System.Convert.ToInt32(xmlProp.Attributes["id-index"].Value);
			}
			if (!(xmlProp.Attributes["key"] == null))
			{
				propertyMap.IsKey = ParseBool(xmlProp.Attributes["key"].Value);
			}
			if (!(xmlProp.Attributes["key-index"] == null))
			{
				propertyMap.KeyIndex = System.Convert.ToInt32(xmlProp.Attributes["key-index"].Value);
			}
			if (!(xmlProp.Attributes["id-generator"] == null))
			{
				propertyMap.IdentityGenerator = xmlProp.Attributes["id-generator"].Value;
			}
			if (!(xmlProp.Attributes["read-only"] == null))
			{
				propertyMap.IsReadOnly = ParseBool(xmlProp.Attributes["read-only"].Value);
			}
			if (!(xmlProp.Attributes["slave"] == null))
			{
				propertyMap.IsSlave = ParseBool(xmlProp.Attributes["slave"].Value);
			}
			if (!(xmlProp.Attributes["lazy"] == null))
			{
				propertyMap.LazyLoad = ParseBool(xmlProp.Attributes["lazy"].Value);
			}
			if (!(xmlProp.Attributes["manage-inverse"] == null))
			{
				propertyMap.NoInverseManagement = !(ParseBool(xmlProp.Attributes["manage-inverse"].Value));
			}
			if (!(xmlProp.Attributes["inherits-inverse"] == null))
			{
				propertyMap.InheritInverseMappings = ParseBool(xmlProp.Attributes["inherits-inverse"].Value);
			}
			if (!(xmlProp.Attributes["cascade-create"] == null))
			{
				propertyMap.CascadingCreate = ParseBool(xmlProp.Attributes["cascade-create"].Value);
			}
			if (!(xmlProp.Attributes["cascade-delete"] == null))
			{
				propertyMap.CascadingDelete = ParseBool(xmlProp.Attributes["cascade-delete"].Value);
			}
			if (!(xmlProp.Attributes["inverse"] == null))
			{
				propertyMap.Inverse = xmlProp.Attributes["inverse"].Value;
			}
			if (!(xmlProp.Attributes["access"] == null))
			{
				propertyMap.Accessibility = (AccessibilityType) Enum.Parse(typeof (AccessibilityType), xmlProp.Attributes["access"].Value);
			}
			if (!(xmlProp.Attributes["field"] == null))
			{
				propertyMap.FieldName = xmlProp.Attributes["field"].Value;
			}
			if (!(xmlProp.Attributes["field-access"] == null))
			{
				propertyMap.FieldAccessibility = (AccessibilityType) Enum.Parse(typeof (AccessibilityType), xmlProp.Attributes["field-access"].Value);
			}
			if (!(xmlProp.Attributes["default"] == null))
			{
				propertyMap.DefaultValue = xmlProp.Attributes["default"].Value;
			}
			if (!(xmlProp.Attributes["null-subst"] == null))
			{
				propertyMap.NullSubstitute = xmlProp.Attributes["null-subst"].Value;
			}
			if (!(xmlProp.Attributes["ref"] == null))
			{
				propertyMap.ReferenceType = (ReferenceType) Enum.Parse(typeof (ReferenceType), xmlProp.Attributes["ref"].Value);
			}
			if (!(xmlProp.Attributes["qualifier"] == null))
			{
				propertyMap.ReferenceQualifier = (ReferenceQualifier) Enum.Parse(typeof (ReferenceQualifier), xmlProp.Attributes["qualifier"].Value);
			}
			if (!(xmlProp.Attributes["optimistic-delete"] == null))
			{
				propertyMap.DeleteOptimisticConcurrencyBehavior = (OptimisticConcurrencyBehaviorType) Enum.Parse(typeof (OptimisticConcurrencyBehaviorType), xmlProp.Attributes["optimistic-delete"].Value);
			}
			if (!(xmlProp.Attributes["optimistic-update"] == null))
			{
				propertyMap.UpdateOptimisticConcurrencyBehavior = (OptimisticConcurrencyBehaviorType) Enum.Parse(typeof (OptimisticConcurrencyBehaviorType), xmlProp.Attributes["optimistic-update"].Value);
			}
			if (!(xmlProp.Attributes["on-create"] == null))
			{
				propertyMap.OnCreateBehavior = (PropertySpecialBehaviorType) Enum.Parse(typeof (PropertySpecialBehaviorType), xmlProp.Attributes["on-create"].Value);
			}
			if (!(xmlProp.Attributes["on-persist"] == null))
			{
				propertyMap.OnPersistBehavior = (PropertySpecialBehaviorType) Enum.Parse(typeof (PropertySpecialBehaviorType), xmlProp.Attributes["on-persist"].Value);
			}
			if (!(xmlProp.Attributes["merge"] == null))
			{
				propertyMap.MergeBehavior = (MergeBehaviorType) Enum.Parse(typeof (MergeBehaviorType), xmlProp.Attributes["merge"].Value);
			}
			if (!(xmlProp.Attributes["refresh"] == null))
			{
				propertyMap.RefreshBehavior = (RefreshBehaviorType) Enum.Parse(typeof (RefreshBehaviorType), xmlProp.Attributes["refresh"].Value);
			}
			if (!(xmlProp.Attributes["ttl"] == null))
			{
				propertyMap.TimeToLive = Int32.Parse(xmlProp.Attributes["ttl"].Value);
			}
			if (!(xmlProp.Attributes["ttl-behavior"] == null))
			{
				propertyMap.TimeToLiveBehavior = (TimeToLiveBehavior) Enum.Parse(typeof (TimeToLiveBehavior), xmlProp.Attributes["ttl-behavior"].Value);
			}
			if (!(xmlProp.Attributes["DOLFindByGroup"] == null))
			{
				propertyMap.DOLFindByGroup = int.Parse(xmlProp.Attributes["DOLFindByGroup"].Value);
			}
			if (!(xmlProp.Attributes["DOLFindByGroupIndex"] == null))
			{
				propertyMap.DOLFindByGroupIndex = int.Parse(xmlProp.Attributes["DOLFindByGroupIndex"].Value);
			}

			ArrayList metaData = propertyMap.MetaData;
			DeserializeMetaData(xmlProp, ref metaData);
		}
        public void CreateListProperty(string className, string propertyName, string propertyType)
        {
            ILoggingService loggingService = engine.GetService<ILoggingService>();
            if (loggingService != null)
                loggingService.LogInfo(this, String.Format("Creating list property {0}, item type {1} in class {2} in NPersist mapping file.",
                    propertyName, propertyType, className));

            IClassMap classMap = GetDomainMap().MustGetClassMap(className);

            //Add the property to the npersist xml file
            IPropertyMap propertyMap = new PropertyMap(propertyName);
            propertyMap.ClassMap = classMap;
            propertyMap.IsCollection = true;

            propertyMap.ItemType = propertyType;
        }