public override void Validate(RootElement root)
        {
            // A property should specify either a type or an entity, but not both.
            // A concrete type should only be declared if a type is declared not if an entity is declared.

            if (!this.Type.Name.Equals(String.Empty) && !this.EntityType.Name.Equals(String.Empty))
            {
                root.AddValidationMessage(ParserValidationMessage.NewWarning(String.Format("Both a type ({0}) and an entity ({1}) were specified for property ({2})", this.Type.Name, this.entityType.Name, this.Name)));
            }

            TypeElement   typeElement = root.FindType(this.Type.Name);
            EntityElement entityType  = root.FindEntity(this.EntityType.Name);

            if (!this.Type.Name.Equals(String.Empty) && typeElement == null)
            {
                root.AddValidationMessage(ParserValidationMessage.NewError("Type " + Type.Name + " was not defined"));
            }
            else
            {
                this.Type = typeElement;
            }

            if (this.ConcreteType.Name.Equals(String.Empty))
            {
                this.concreteType = this.Type;
            }
            else
            {
                TypeElement concreteTypeElement = root.FindType(this.ConcreteType.Name);
                if (concreteTypeElement == null)
                {
                    root.AddValidationMessage(ParserValidationMessage.NewError("ConcreteType " + ConcreteType.Name + " was not defined"));
                }
                else
                {
                    this.ConcreteType = concreteTypeElement;
                }
            }

            if (!this.EntityType.Name.Equals(String.Empty) && entityType == null)
            {
                root.AddValidationMessage(ParserValidationMessage.NewError("Entity " + EntityType.Name + " was not defined"));
            }
            else
            {
                this.EntityType = entityType;
            }

            if (typeElement == null && entityType == null)
            {
                root.AddValidationMessage(ParserValidationMessage.NewError(String.Format("No type or entity was specified for property {0} on entity {1}.", this.Name, this.containingEntity.Name)));
            }
        }
Exemple #2
0
        public override void Validate(RootElement root)
        {
            // Look up the SQL entity in the database elements.
            //	    if (!this.SqlEntity.Name.Equals(String.Empty)) {
            //		SqlEntityElement sqlEntity = RootElement.Instance.FindSqlEntityByName(SqlEntity.Name);
            //		if (sqlEntity == null) {
            //		    this.AddValidationMessage(ParserValidationMessage.NewError("sqlentity (" + SqlEntity.Name + ") specified in entity " + Name + " could not be found as an defined sql entity"));
            //		} else {
            //		    this.sqlEntity = sqlEntity;
            //		}
            //	    }

            // Look up the base entity in the entity collection.
            if (!this.BaseEntity.Name.Equals(String.Empty))
            {
                EntityElement baseEntity = root.FindEntity(this.BaseEntity.Name);
                if (baseEntity == null)
                {
                    root.AddValidationMessage(ParserValidationMessage.NewError("baseentity (" + BaseEntity.Name + ") specified in entity " + Name + " could not be found as an defined entity (or is defined after this entity in the config file)"));
                }
                else
                {
                    this.baseEntity = baseEntity;
                }
            }

            foreach (PropertyElement property in this.Properties)
            {
                property.Validate(root);
            }
            foreach (DataMapElement dataMap in this.dataMaps)
            {
                dataMap.Validate(root);
            }
            foreach (FinderElement finder in this.Finders)
            {
                finder.Validate(root);
            }
        }