📄 indexmanager.java
字号:
package org.apache.lucene.server;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Lucene" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Lucene", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.RemoteSearchable;
import org.apache.lucene.server.exceptions.BuildIndexException;
import org.apache.lucene.server.exceptions.CreateIndexManagerException;
import org.apache.lucene.server.exceptions.IndexConfigurationErrorException;
import org.apache.lucene.server.exceptions.InvalidFileFactoryClassException;
import org.apache.lucene.server.exceptions.InvalidFileHandlerClassException;
import org.apache.lucene.server.exceptions.InvalidFileTypePatternException;
import org.apache.lucene.server.exceptions.InvalidLocationDescriptor;
import org.apache.lucene.server.exceptions.XFileException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* @author rcocula
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
class IndexManager {
private StringBuffer logBuffer = new StringBuffer();
protected String IndexName;
protected String IndexDescription;
protected String IndexDirectory;
protected Vector SourceVector = new Vector();
protected Analyzer AnalyzerClass;
protected IndexServer server;
private Logger logger = null;
/**
* @deprecated
* Creates a new instance of an IndexManager Object with
* type of class specified in ManagerClass tag.
*
*/
static public IndexManager createIndexManager(Element IndexManagerElement,IndexServer is)
throws CreateIndexManagerException
{
NodeList nl = IndexManagerElement.getElementsByTagName("ManagerClass");
Element eltclass = (Element)nl.item(0);
String ClassName = eltclass.getFirstChild().getNodeValue();
try
{
Class[] ConstructorParams = {
Class.forName("org.w3c.dom.Element"),
Class.forName("org.apache.lucene.server.IndexServer")
};
Constructor C = Class.forName(ClassName).getConstructor(ConstructorParams);
Object[] param = {IndexManagerElement,is};
IndexManager manager = (IndexManager)C.newInstance(param);
return manager;
}
catch (Exception e)
{
throw new CreateIndexManagerException(ClassName,e);
}
}
/**
*
* @param IndexManagerElement
*/
public IndexManager (org.w3c.dom.Element IndexManagerElement,IndexServer is) throws IndexConfigurationErrorException
{
server = is;
logger = is.getLogger();
try
{
NodeList nl = IndexManagerElement.getElementsByTagName("IndexName");
Element elt = (Element)nl.item(0);
IndexName = elt.getFirstChild().getNodeValue();
}
catch (NullPointerException e)
{
throw new IndexConfigurationErrorException("Error while retrieving IndexName");
}
logServer("Retrieving configuration for index "+IndexName);
try
{
NodeList nl = IndexManagerElement.getElementsByTagName("IndexDescription");
Element elt = (Element)nl.item(0);
IndexDescription = elt.getFirstChild().getNodeValue();
}
catch (NullPointerException e)
{
logServer("Error while retrieving IndexDescription");
}
try
{
NodeList nl = IndexManagerElement.getElementsByTagName("IndexDirectory");
Element elt = (Element)nl.item(0);
IndexDirectory = elt.getFirstChild().getNodeValue();
}
catch (NullPointerException e)
{
logServer("Error while retrieving IndexDirectory");
}
try
{
NodeList nl = IndexManagerElement.getElementsByTagName("AnalyzerClass");
Element elt = (Element)nl.item(0);
String ana = elt.getFirstChild().getNodeValue();
try
{
AnalyzerClass = (Analyzer)Class.forName(ana).newInstance();
}
catch (Exception e)
{
throw new IndexConfigurationErrorException("Invalid AnalyzerClass "+ana);
}
}
catch (NullPointerException e)
{
throw new IndexConfigurationErrorException("Error while retrieving AnalyzerClass");
}
// Elements Source
NodeList nl = IndexManagerElement.getElementsByTagName("Source");
for (int i=0;i<nl.getLength();i++)
{
try
{
SourceVector.add(new Source((Element)nl.item(i),server.getXFileFactory()));
}
catch (XFileException e)
{
logServer ("Source "+nl.item(i).getNodeValue()+" : initialisation error .");
e.printStackTrace();
}
catch (InvalidFileHandlerClassException e)
{
logServer("Invalid Class "+e.getInvalidClassName()+" ; Source declaration ignored.");
}
catch (InvalidFileFactoryClassException e)
{
logServer("Invalid Class "+e.getInvalidClassName()+" ; Source declaration ignored.");
}
catch (InvalidFileTypePatternException e)
{
logServer("Invalid regular expression "+e.getInvalidPattern()+" ; Source declaration ignored.");
}
catch (InvalidLocationDescriptor e)
{
logServer("Invalid location descriptor "+e.getInvalidDescriptor()+" ; Source declaration ignored.");
}
}
// Element Tasks
nl = IndexManagerElement.getElementsByTagName("Tasks");
Element elttask = (Element)nl.item(0);
if (elttask != null)
{
nl = elttask.getChildNodes();
for (int i=0;i<nl.getLength();i++)
{
Node N = nl.item(i);
if (N.getNodeType() == Node.ELEMENT_NODE)
{
createTask((Element)N);
}
}
}
// Element Log
nl = IndexManagerElement.getElementsByTagName("Log");
Element logelt = (Element)nl.item(0);
if (logelt!=null)
{
try
{
logger = new Logger(logelt.getFirstChild().getNodeValue());
if (logelt.getAttribute("level")!= null && logelt.getAttribute("level").compareTo("HIGH")==0)
{
logger.setLevel(Logger.LEVEL_HIGH);
}
}
catch (Exception e)
{
logServer("Logger could not be created for index "+IndexName);
}
}
}
/**
*
* @return
*/
private void createTask(Element E)
{
Calendar cal = new GregorianCalendar();
String tasktype = E.getNodeName();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -