Exemple #1
0
        private LuceneAttrib GetLuceneAttrib(string attribName, TypeDef classType)
        {
            PropertyDef  pi         = null;
            FieldDef     fi         = null;
            LuceneAttrib tempAttrib = new LuceneAttrib();
            string       dt         = null;

            pi = classType.GetProperty(attribName);
            if (pi != null)
            {
                dt = pi.PropertyType.FullName;
            }
            if (pi == null)
            {
                fi = classType.GetField(attribName);
                if (fi != null)
                {
                    dt = fi.FieldType.FullName;
                }
            }
            if (pi != null || fi != null)
            {
                AttributeValidator validator = new AttributeValidator(defaults);
                tempAttrib.Name           = attribName;
                tempAttrib.ID             = attribName;
                tempAttrib.Type           = dt;
                tempAttrib.LuceneType     = LuceneType;
                tempAttrib.LuceneAnalyzer = Analyzer;
                tempAttrib.TermVector     = TermVector;
                tempAttrib.Pattern        = Pattern;
                tempAttrib.StopWords      = StopWords;


                if (!validator.ValidateTermVector(tempAttrib.TermVector))
                {
                    throw new Exception("Invalid Term Vector specified");
                }
                System.Type currentType = System.Type.GetType(dt);
                if (!ValidateDataType(currentType))
                {
                    //TODO: [Mehreen] :Insert Khubsurti here so it can collectively throw one exception
                    //_nonPrimitiveAttSpecified = true;
                    //_unsupportedtypes += currentType.FullName + "\n";
                    throw new Exception("NCache only supports premitive types. Type " + currentType.FullName + " is not supported");
                }
                else if (currentType == null)
                {
                    //_nonPrimitiveAttSpecified = true;
                    //_unsupportedtypes += "Unknown Type\n";
                    throw new Exception("NCache only supports premitive types. Type Unknown Type\n");
                }
                else if (!validator.ValidateLuceneType(tempAttrib.LuceneType, currentType))
                {
                    throw new Exception("Can not create Lucene Index of type " + tempAttrib.LuceneType + " on data type " + currentType.FullName);
                }
                else if (tempAttrib.LuceneType == LuceneUtil.SPATIAL)
                {
                    tempAttrib.SpaStrategy   = SpatialStrategy != null ? SpatialStrategy : LuceneUtil.SpatialStrategy.BBOX;
                    tempAttrib.SpaPrefixTree = SpatialPrefixTree != null ? SpatialPrefixTree : LuceneUtil.SpatialPrefixTre.GEOHASH;
                    if (!AttributeValidator.ValidateSpatialStrategy(tempAttrib.SpaStrategy, tempAttrib.Name, tempAttrib.SpaPrefixTree, SpatialContext.GEO))
                    {
                        throw new Exception("Spatial Startegy or Prefix Tree are not valid");
                    }
                }
                else if (tempAttrib.LuceneType == LuceneUtil.STRING)
                {
                    if (serverConfig.CacheSettings.LuceneSettings != null)
                    {
                        if (!validator.ValidateAnalyzer(tempAttrib.LuceneAnalyzer, GetDeployements(serverConfig.CacheSettings.LuceneSettings.Analyzers)))
                        {
                            throw new Exception("Analyzer " + tempAttrib.LuceneAnalyzer + " is not deployed");
                        }
                        if (!validator.ValidatePattern(tempAttrib.Pattern, GetDeployements(serverConfig.CacheSettings.LuceneSettings.Patterns)))
                        {
                            throw new Exception("Pattern " + tempAttrib.Pattern + " is not deployed");
                        }
                        if (!validator.ValidateStopWords(tempAttrib.StopWords, GetDeployements(serverConfig.CacheSettings.LuceneSettings.StopWordFiles)))
                        {
                            throw new Exception("Pattern " + tempAttrib.StopWords + " is not deployed");
                        }
                    }
                    else
                    {
                        if (!validator.ValidateAnalyzer(tempAttrib.LuceneAnalyzer, null))
                        {
                            throw new Exception("Analyzer " + tempAttrib.LuceneAnalyzer + " is not deployed");
                        }
                        if (!validator.ValidatePattern(tempAttrib.Pattern, null))
                        {
                            throw new Exception("Pattern " + tempAttrib.Pattern + " is not deployed");
                        }
                        if (!validator.ValidateStopWords(tempAttrib.StopWords, null))
                        {
                            throw new Exception("Pattern " + tempAttrib.StopWords + " is not deployed");
                        }
                    }
                }
            }
            else
            {
                string message = "Invalid class attribute(s) specified '" + attribName + "'.";
                throw new Exception(message);
            }
            return(tempAttrib);
        }
Exemple #2
0
 private void ValidateLuceneAttribute(LuceneAttrib attrib)
 {
     // TODO : [Mehreen] Insert Khubsurti for validating all here
 }