Esempio n. 1
0
        protected override void Initialize()
        {
            clazz =
                ReflectHelper.ClassForFullName(
                    TypeNameParser.Parse(meta.name, meta.rootMapping.@namespace, meta.rootMapping.assembly).ToString());
            classAttributes = meta.attributename == null
                                                ? new List <Attribute>(0)
                                                : new List <Attribute>(meta.attributename.Length);

            List <MemberInfo> lmembers = meta.property == null
                                                        ? new List <MemberInfo>(0)
                                                        : new List <MemberInfo>(meta.property.Length);

            if (meta.attributename != null)
            {
                log.Debug("Looking for class attributes");
                foreach (NhvmClassAttributename attributename in meta.attributename)
                {
                    log.Info("Attribute to look for = " + GetText(attributename));
                    Attribute classAttribute = RuleAttributeFactory.CreateAttributeFromClass(clazz, attributename);
                    classAttributes.Add(classAttribute);
                }
            }

            if (meta.property != null)
            {
                foreach (NhvmProperty property in meta.property)
                {
                    MemberInfo currentMember = TypeUtils.GetPropertyOrField(clazz, property.name);

                    if (currentMember == null)
                    {
                        throw new InvalidPropertyNameException(property.name, clazz);
                    }

                    log.Info("Looking for rules for property : " + property.name);
                    lmembers.Add(currentMember);

                    // creation of member attributes
                    foreach (object rule in property.Items)
                    {
                        Attribute thisAttribute = RuleAttributeFactory.CreateAttributeFromRule(rule, meta.rootMapping.assembly,
                                                                                               meta.rootMapping.@namespace);

                        if (thisAttribute != null)
                        {
                            log.Info(string.Format("Adding member {0} to dictionary with attribute {1}", currentMember.Name, thisAttribute));
                            if (!membersAttributesDictionary.ContainsKey(currentMember))
                            {
                                membersAttributesDictionary.Add(currentMember, new List <Attribute>());
                            }

                            membersAttributesDictionary[currentMember].Add(thisAttribute);
                        }
                    }
                }
            }
            members = lmembers.ToArray();
        }
Esempio n. 2
0
        private static Attribute ConvertToRule(XmlNhvmRuleConverterArgs rule)
        {
            NhvmRule ruleRule = (NhvmRule)rule.schemaRule;

            string attribute = ruleRule.attribute;
            AssemblyQualifiedTypeName fullClassName =
                TypeNameParser.Parse(attribute, rule.defaultNameSpace, rule.defaultAssembly);

            System.Type type = ReflectHelper.ClassForFullName(fullClassName.ToString());
#if NETFX
            log.Info("The type found for ruleRule = " + type.FullName);
#else
            Log.Info("The type found for ruleRule = {0}", type.FullName);
#endif
            Attribute thisattribute = (Attribute)Activator.CreateInstance(type);
#if NETFX
            log.Info("Attribute found = " + thisattribute);
#else
            Log.Info("Attribute found = {0}", thisattribute);
#endif

            var tr = thisattribute as ITagableRule;
            if (tr != null)
            {
                AssignTagsFromString(tr, ruleRule.tags);
            }

            if (ruleRule.param == null)
            {
                return(thisattribute);                                    //eager return
            }
            foreach (NhvmParam parameter in ruleRule.param)
            {
                PropertyInfo propInfo = type.GetProperty(parameter.name);
                if (propInfo != null)
                {
#if NETFX
                    log.Info("propInfo value = " + parameter.value);
#else
                    Log.Info("propInfo value = {0}", parameter.value);
#endif
                    object value = propInfo.PropertyType != typeof(string)
                                                                        ? Convert.ChangeType(parameter.value, propInfo.PropertyType)
                                                                        : parameter.value;
                    propInfo.SetValue(thisattribute, value, null);
                }
                else
                {
                    throw new InvalidPropertyNameException(
                              string.Format("The custom attribute '{0}' don't have the property '{1}'; Check for typo.", type.FullName, parameter.name), parameter.name,
                              type);
                }
            }

            return(thisattribute);
        }
Esempio n. 3
0
 public override object FromStringValue(string xml)
 {
     try
     {
         return(ReflectHelper.ClassForFullName(xml));
     }
     catch (Exception tle)
     {
         throw new HibernateException("could not parse xml:" + xml, tle);
     }
 }
Esempio n. 4
0
 private System.Type DetermineAssociatedEntityClass()
 {
     try
     {
         return(ReflectHelper.ClassForFullName(GetAssociatedEntityName()));
     }
     catch (Exception)
     {
         return(typeof(IDictionary));
     }
 }
Esempio n. 5
0
        private static ISharedEngineProvider BuildSharedEngine(IDictionary <string, string> properties)
        {
            string clazz;
            ISharedEngineProvider result = null;

            if (properties.TryGetValue(SharedEngineClass, out clazz))
            {
                result = (ISharedEngineProvider)Activator.CreateInstance(ReflectHelper.ClassForFullName(clazz));
            }
            return(result);
        }
Esempio n. 6
0
        private static object ParseStringRepresentation(object value)
        {
            var str = value as string;

            if (string.IsNullOrEmpty(str))
            {
                return(null);
            }

            try
            {
                return(ReflectHelper.ClassForFullName(str));
            }
            catch (Exception cnfe)
            {
                throw new HibernateException("Class not found: " + str, cnfe);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Gets the <see cref="System.Type"/> in the <see cref="DbDataReader"/> for the Property.
        /// </summary>
        /// <param name="rs">The <see cref="DbDataReader"/> that contains the value.</param>
        /// <param name="index">The index of the field to get the value from.</param>
        /// <returns>The <see cref="System.Type"/> from the database.</returns>
        /// <exception cref="TypeLoadException">
        /// Thrown when the value in the database can not be loaded as a <see cref="System.Type"/>
        /// </exception>
        public override object Get(DbDataReader rs, int index)
        {
            string str = (string)NHibernateUtil.String.Get(rs, index);

            if (string.IsNullOrEmpty(str))
            {
                return(null);
            }
            else
            {
                try
                {
                    return(ReflectHelper.ClassForFullName(str));
                }
                catch (Exception cnfe)
                {
                    throw new HibernateException("Class not found: " + str, cnfe);
                }
            }
        }
Esempio n. 8
0
 public static System.Type ResolveDotnetType(string className)
 {
     return(ReflectHelper.ClassForFullName(className));
 }
Esempio n. 9
0
        /// <summary>
        /// Return the names of all persistent (mapped) classes that extend or implement the
        /// given class or interface, accounting for implicit/explicit polymorphism settings
        /// and excluding mapped subclasses/joined-subclasses of other classes in the result.
        /// </summary>
        public string[] GetImplementors(string className)
        {
            System.Type clazz = null;

            // NH Different implementation for performance: a class without at least a namespace sure can't be found by reflection
            if (className.IndexOf('.') > 0)
            {
                IEntityPersister checkPersister;
                // NH Different implementation: we have better performance checking, first of all, if we know the class
                // and take the System.Type directly from the persister (className have high probability to be entityName)
                if (entityPersisters.TryGetValue(className, out checkPersister))
                {
                    if (!checkPersister.EntityMetamodel.HasPocoRepresentation)
                    {
                        // we found the persister but it is a dynamic entity without class
                        return(new[] { className });
                    }
                    // NH : take care with this because we are forcing the Poco EntityMode
                    clazz = checkPersister.GetMappedClass(EntityMode.Poco);
                }

                if (clazz == null)
                {
                    try
                    {
                        clazz = ReflectHelper.ClassForFullName(className);
                    }
                    catch (Exception)
                    {
                        clazz = null;
                    }
                }
            }

            if (clazz == null)
            {
                return(new[] { className });              //for a dynamic-class
            }

            List <string> results = new List <string>();

            foreach (IEntityPersister p in entityPersisters.Values)
            {
                IQueryable q = p as IQueryable;
                if (q != null)
                {
                    string testClassName = q.EntityName;
                    bool   isMappedClass = className.Equals(testClassName);
                    if (q.IsExplicitPolymorphism)
                    {
                        if (isMappedClass)
                        {
                            return(new string[] { testClassName });                          // NOTE EARLY EXIT
                        }
                    }
                    else
                    {
                        if (isMappedClass)
                        {
                            results.Add(testClassName);
                        }
                        else
                        {
                            System.Type mappedClass = q.GetMappedClass(EntityMode.Poco);
                            if (mappedClass != null && clazz.IsAssignableFrom(mappedClass))
                            {
                                bool assignableSuperclass;
                                if (q.IsInherited)
                                {
                                    System.Type mappedSuperclass = GetEntityPersister(q.MappedSuperclass).GetMappedClass(EntityMode.Poco);
                                    assignableSuperclass = clazz.IsAssignableFrom(mappedSuperclass);
                                }
                                else
                                {
                                    assignableSuperclass = false;
                                }
                                if (!assignableSuperclass)
                                {
                                    results.Add(testClassName);
                                }
                            }
                        }
                    }
                }
            }
            return(results.ToArray());
        }