Ejemplo n.º 1
0
        public static IFieldBridge ExtractType(ClassBridgeAttribute cb)
        {
            IFieldBridge bridge = null;

            if (cb != null)
            {
                System.Type impl = cb.Impl;

                if (impl != null)
                {
                    try
                    {
                        Object instance = Activator.CreateInstance(impl);
                        if (typeof(IFieldBridge).IsAssignableFrom(impl))
                            bridge = (IFieldBridge)instance;
                        if (cb.Parameters.Count > 0 && typeof(IParameterizedBridge).IsAssignableFrom(impl))
                        {
                            // Already converted the parameters by this stage
                            ((IParameterizedBridge) instance).SetParameterValues(cb.Parameters);
                        }
                    }
                    catch (Exception e)
                    {
                        //TODO add classname
                        throw new HibernateException("Unable to instantiate IFieldBridge for " + cb.Name, e);
                    }
                }
            }
            //TODO add classname
            if (bridge == null) throw new HibernateException("Unable to guess IFieldBridge ");

            return bridge;
        }
        private void BindClassAnnotation(string prefix, PropertiesMetadata propertiesMetadata, ClassBridgeAttribute ann)
        {
            // TODO: Name should be prefixed - NB is this still true?
            string fieldName = prefix + ann.Name;
            propertiesMetadata.classNames.Add(fieldName);
            propertiesMetadata.classStores.Add(GetStore(ann.Store));
            propertiesMetadata.classIndexes.Add(GetIndex(ann.Index));
            propertiesMetadata.classBridges.Add(BridgeFactory.ExtractType(ann));
            propertiesMetadata.classBoosts.Add(ann.Boost);

            Analyzer classAnalyzer = GetAnalyzer(ann.Analyzer) ?? propertiesMetadata.analyzer;
            if (classAnalyzer == null)
            {
                throw new NotSupportedException("Analyzer should not be undefined");
            }

            analyzer.AddScopedAnalyzer(fieldName, classAnalyzer);
        }