at.spardat.xma.plugins.PluginManagerServer Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* s IT Solutions AT Spardat GmbH - initial API and implementation
*******************************************************************************/
// @(#) $Id: PluginManagerServer.java 3240 2009-03-03 16:10:56Z gub $
package at.spardat.xma.plugins;
import at.spardat.xma.boot.comp.data.XMAApp;
import at.spardat.xma.boot.comp.data.XMAPluginImpl;
import at.spardat.xma.boot.server.ServerAppLoader;
/**
* Realizes the PluginManager at the server side of XMA.
*
* @author YSD, 11.06.2003 13:41:13
*/
public class PluginManagerServer extends PluginManager {
/* application description used for plugin lookups */
private XMAApp appDes;
/**
* the single instance
*/
private static PluginManagerServer theInstance_ = new PluginManagerServer();
/**
* Returns the single PluginManager instance at the server side of XMA.
*/
public static PluginManagerServer getInstance () {
return theInstance_;
}
/**
* Private constructor avoids that somebody constructs one.
*/
private PluginManagerServer () {
}
/**
* @see at.spardat.xma.plugins.PluginManager#resolvePlugin(java.lang.String, java.lang.ClassLoader)
*/
protected Object resolvePlugin (String interfaceName, ClassLoader cl) {
if( appDes == null ) {
appDes = ServerAppLoader.getXmaapp();
if( appDes == null ) {
throw new RuntimeException( "unable to load application description");
}
}
XMAPluginImpl impl = appDes.getPluginImpl( interfaceName );
if( impl == null ) {
throw new RuntimeException ("no implementation for plug-in-interface " + interfaceName);
}
String strImpl = impl.getImplServer_();
if( strImpl == null )
throw new RuntimeException ("no implementation for plug-in-interface " + interfaceName);
try {
// Object ret = Class.forName(strImpl).newInstance();
Object ret = cl.loadClass(strImpl).newInstance();
// TODO LOG
return ret;
} catch( Exception exc ) {
throw new RuntimeException("could not load implementation for "+interfaceName+": "+exc.toString());
}
}
/**
* Checks if a plugin is configured for the given interface and a server side implementation is defined.
* @param interfaceName the fully qualified name of a java interface, specifying
* the interface the plugin has to implement.
* @return true if a plugin is declared for the given interface in xma-app.xml, false otherwise.
* @author s2877
*/
public boolean isPluginDeclared(String interfaceName) {
if( appDes == null ) {
appDes = ServerAppLoader.getXmaapp();
if( appDes == null ) {
// throw new RuntimeException( "unable to load application description");
return false; // to be usable in unit tests
}
}
XMAPluginImpl impl = appDes.getPluginImpl( interfaceName );
if(impl != null ) {
return impl.getImplServer_()!=null;
} else {
return false;
}
}
}