Class SolrSchemaUtil


  • public class SolrSchemaUtil
    extends java.lang.Object
    A stateful utility bean for working with schema documents. This class is not thread safe.
    • Constructor Summary

      Constructors 
      Constructor Description
      SolrSchemaUtil()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> java.lang.Class<? extends T> findClass​(java.lang.String cname, java.lang.Class<T> expectedType, java.lang.String... subpackages)
      This method loads a class either with its FQN or a short-name (solr.class-simplename or class-simplename).
      protected java.lang.String[] getDefaultPackages()  
      org.apache.solr.schema.FieldType getFieldType​(org.w3c.dom.Document doc, java.lang.String fieldTypeName, java.lang.String luceneMatch, float schemaVersion, ClassSubPathResourceLoader loader)  
      protected java.lang.String getFieldTypeXPathExpressions()  
      org.w3c.dom.Document getSchemaDocument​(java.lang.String schemaFile, ClassSubPathResourceLoader classLoader)  
      <T> void load​(org.w3c.dom.NodeList nodes, java.lang.String errRef, java.util.List<T> list, java.lang.Class<T> clazz, java.lang.String luceneMatch, org.apache.lucene.util.ResourceLoader loader)
      Initializes and each plugin in the list.
      <T> T newInstance​(java.lang.String cName, java.lang.Class<T> expectedType, java.lang.String[] subPackages, java.lang.Class[] params, java.lang.Object[] args)
      Create a new instance as per the parameters.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SCHEMA_XML_ANALYZER_FILTER

        public static final java.lang.String SCHEMA_XML_ANALYZER_FILTER
        See Also:
        Constant Field Values
      • SCHEMA_XML_ANALYZER_TOKENIZER

        public static final java.lang.String SCHEMA_XML_ANALYZER_TOKENIZER
        See Also:
        Constant Field Values
      • SCHEMA_XML_ANALYZER_CHAR_FILTER

        public static final java.lang.String SCHEMA_XML_ANALYZER_CHAR_FILTER
        See Also:
        Constant Field Values
    • Constructor Detail

      • SolrSchemaUtil

        public SolrSchemaUtil()
    • Method Detail

      • getSchemaDocument

        public org.w3c.dom.Document getSchemaDocument​(java.lang.String schemaFile,
                                                      ClassSubPathResourceLoader classLoader)
                                               throws javax.xml.parsers.ParserConfigurationException,
                                                      org.xml.sax.SAXException,
                                                      java.io.IOException
        Throws:
        javax.xml.parsers.ParserConfigurationException
        org.xml.sax.SAXException
        java.io.IOException
      • getFieldType

        public org.apache.solr.schema.FieldType getFieldType​(org.w3c.dom.Document doc,
                                                             java.lang.String fieldTypeName,
                                                             java.lang.String luceneMatch,
                                                             float schemaVersion,
                                                             ClassSubPathResourceLoader loader)
                                                      throws javax.xml.xpath.XPathExpressionException,
                                                             java.lang.InstantiationException,
                                                             java.lang.IllegalAccessException
        Throws:
        javax.xml.xpath.XPathExpressionException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
      • load

        public <T> void load​(org.w3c.dom.NodeList nodes,
                             java.lang.String errRef,
                             java.util.List<T> list,
                             java.lang.Class<T> clazz,
                             java.lang.String luceneMatch,
                             org.apache.lucene.util.ResourceLoader loader)
        Initializes and each plugin in the list. Given a NodeList from XML in the form:
         
         <plugins>
            <plugin name="name1" class="solr.ClassName" >
              ...
            </plugin>
            <plugin name="name2" class="solr.ClassName" >
              ...
            </plugin>
         </plugins>
         

        This will attempt to initialize each plugin from the list. Plugins with factories that pull additional information from a SolrResourceLoader or with constructors requiring parameters may not work unless that logic is pulled into this class. As of this writing this has only been done for TokenFilterFactory, TokenizerFactory and CharFilterFactory. This is similar to SolrResourceLoader but contains class specific logic, skips all class registration and does not perform default checking.

        Type Parameters:
        T - the generic type of the plugins to load
        Parameters:
        nodes - the nodelist specifying the plugin.
        errRef - a string to include with error messages
        list - a list to which loaded plugin objects will be added
        clazz - a type for which the loaded plugins should have the same class or be a subclass of
        luceneMatch - the lucene match version to be supplied to plugins that care about it.
        loader - the resource loader with which to load additional resources (e.g. stopwords.txt)
      • newInstance

        public <T> T newInstance​(java.lang.String cName,
                                 java.lang.Class<T> expectedType,
                                 java.lang.String[] subPackages,
                                 java.lang.Class[] params,
                                 java.lang.Object[] args)
        Create a new instance as per the parameters. This serves as a replacement for SolrResourceLoader.newInstance(), but doesn't concern it self with SolrCoreAware, ResourceLoaderAware, or SolrInfoBean.
        Type Parameters:
        T - The type that will be loaded
        Parameters:
        cName - The name of the class to load
        expectedType - The type that should be loaded (must be passed due to type erasure)
        subPackages - The package names to check
        params - The types of the parameters for the constructor to be used
        args - The values for the parameters to the constructor to be used
        Returns:
        A freshly constructed instance.
      • findClass

        public <T> java.lang.Class<? extends T> findClass​(java.lang.String cname,
                                                          java.lang.Class<T> expectedType,
                                                          java.lang.String... subpackages)
        This method loads a class either with its FQN or a short-name (solr.class-simplename or class-simplename). It tries to load the class with the name that is given first and if it fails, it tries all the known solr packages. This method caches the FQN of a short-name in a static map in-order to make subsequent lookups for the same class faster. The caching is done only if the class is loaded by the webapp classloader and it is loaded using a short name.

        The classloader used is the current thread's class loader (instead of one from a SolrResourceLoader)

        Type Parameters:
        T - the generic type that the type returned should extend
        Parameters:
        cname - The name or the short name of the class.
        expectedType - The type which must be equal to or a super class of the returned type
        subpackages - the packages to be tried if the cname starts with solr.
        Returns:
        the loaded class. An exception is thrown if it fails
      • getFieldTypeXPathExpressions

        protected java.lang.String getFieldTypeXPathExpressions()
      • getDefaultPackages

        protected java.lang.String[] getDefaultPackages()