All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.fedora.server.utilities.rebuild.RebuildServer Maven / Gradle / Ivy

Go to download

The Fedora Client is a Java Library that allows API access to a Fedora Repository. The client is typically one part of a full Fedora installation.

The newest version!
/*
 * -----------------------------------------------------------------------------
 *
 * 

License and Copyright: The contents of this file are subject to the * Apache License, Version 2.0 (the "License"); you may not use * this file except in compliance with the License. You may obtain a copy of * the License at * http://www.fedora-commons.org/licenses.

* *

Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License.

* *

The entire file consists of original code.

*

Copyright © 2008 Fedora Commons, Inc.
*

Copyright © 2002-2007 The Rector and Visitors of the University of * Virginia and Cornell University
* All rights reserved.

* * ----------------------------------------------------------------------------- */ package fedora.server.utilities.rebuild; import java.io.File; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Element; import org.xml.sax.SAXException; import fedora.server.Server; import fedora.server.errors.ModuleInitializationException; import fedora.server.errors.ServerInitializationException; /** * @author diglib */ public class RebuildServer extends Server { /** * @param rootConfigElement * @param homeDir * @throws ServerInitializationException * @throws ModuleInitializationException */ public RebuildServer(Element rootConfigElement, File homeDir) throws ServerInitializationException, ModuleInitializationException { super(rootConfigElement, homeDir); } protected boolean overrideModuleRole(String moduleRole) { if (moduleRole.indexOf("Authorization") != -1 || moduleRole.indexOf("Access") != -1 || moduleRole.indexOf("OAIProvider") != -1 || moduleRole.indexOf("Management") != -1 || moduleRole.indexOf("ResourceIndex") != -1 ) { return(true); } return(false); } protected String overrideModuleClass(String moduleClass) { if (moduleClass.endsWith("DOManager")) { return("fedora.server.utilities.rebuild.RebuildDOManager"); } return(null); } /** * Provides an instance of the server specified in the configuration * file at homeDir/CONFIG_DIR/CONFIG_FILE, or DEFAULT_SERVER_CLASS * if unspecified. * * @param homeDir The base directory for the server. * @return The instance. * @throws ServerInitializationException If there was an error starting * the server. * @throws ModuleInitializationException If there was an error starting * a module. */ public final static Server getRebuildInstance(File homeDir) throws ServerInitializationException, ModuleInitializationException { configureLog4J("-rebuild.log"); // instantiate a new special purpose server for rebuilding // SQL databases given the class provided in the root element // in the config file and return it File configFile = null; try { DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder=factory.newDocumentBuilder(); configFile=new File(homeDir + File.separator + "server" + File.separator + CONFIG_DIR + File.separator + CONFIG_FILE); // suck it in Element rootElement=builder.parse(configFile).getDocumentElement(); // ensure root element name ok if (!rootElement.getLocalName().equals(CONFIG_ELEMENT_ROOT)) { throw new ServerInitializationException( MessageFormat.format(INIT_CONFIG_SEVERE_BADROOTELEMENT, new Object[] {configFile, CONFIG_ELEMENT_ROOT, rootElement.getLocalName()})); } // ensure namespace specified properly if (!rootElement.getNamespaceURI().equals(CONFIG_NAMESPACE)) { throw new ServerInitializationException(MessageFormat.format( INIT_CONFIG_SEVERE_BADNAMESPACE, new Object[] { configFile, CONFIG_NAMESPACE})); } // select .. String className="fedora.server.utilities.rebuild.RebuildServer"; try { Class serverClass=Class.forName(className); Class param1Class=Class.forName(SERVER_CONSTRUCTOR_PARAM1_CLASS); Class param2Class=Class.forName(SERVER_CONSTRUCTOR_PARAM2_CLASS); Constructor serverConstructor=serverClass.getConstructor( new Class[] {param1Class, param2Class}); Server inst=(Server) serverConstructor.newInstance( new Object[] {rootElement, homeDir} ); s_instances.put(homeDir, inst); return inst; } catch (ClassNotFoundException cnfe) { throw new ServerInitializationException( MessageFormat.format(INIT_SERVER_SEVERE_CLASSNOTFOUND, new Object[] {className})); } catch (IllegalAccessException iae) { // improbable throw new ServerInitializationException( MessageFormat.format(INIT_SERVER_SEVERE_ILLEGALACCESS, new Object[] {className})); } catch (IllegalArgumentException iae) { // improbable throw new ServerInitializationException( MessageFormat.format(INIT_SERVER_SEVERE_BADARGS, new Object[] {className})); } catch (InstantiationException ie) { throw new ServerInitializationException( MessageFormat.format( INIT_SERVER_SEVERE_MISSINGCONSTRUCTOR, new Object[] {className})); } catch (NoSuchMethodException nsme) { throw new ServerInitializationException( MessageFormat.format(INIT_SERVER_SEVERE_ISABSTRACT, new Object[] {className})); } catch (InvocationTargetException ite) { // throw the constructor's thrown exception, if any try { throw ite.getCause(); // as of java 1.4 } catch (ServerInitializationException sie) { throw sie; } catch (ModuleInitializationException mie) { throw mie; } catch (Throwable t) { // a runtime error..shouldn't happen, but if it does... StringBuffer s=new StringBuffer(); s.append(t.getClass().getName()); s.append(":[z] "); for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy