Refactor PluginManager into PluginService and LegacyPluginServiceImpl. Add unit tests.

This commit is contained in:
Tim Donohue
2015-10-15 11:47:12 -05:00
parent 0466184350
commit 3df18c68b8
47 changed files with 507 additions and 426 deletions

View File

@@ -18,6 +18,7 @@ import org.dspace.core.*;
import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.factory.HandleServiceFactory;
import java.util.*; import java.util.*;
import org.dspace.core.factory.CoreServiceFactory;
/** /**
* MediaFilterManager is the class that invokes the media/format filters over the * MediaFilterManager is the class that invokes the media/format filters over the
@@ -178,7 +179,7 @@ public class MediaFilterCLITool {
for(int i=0; i< filterNames.length; i++) for(int i=0; i< filterNames.length; i++)
{ {
//get filter of this name & add to list of filters //get filter of this name & add to list of filters
FormatFilter filter = (FormatFilter) PluginManager.getNamedPlugin(FormatFilter.class, filterNames[i]); FormatFilter filter = (FormatFilter) CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(FormatFilter.class, filterNames[i]);
if(filter==null) if(filter==null)
{ {
System.err.println("\nERROR: Unknown MediaFilter specified (either from command-line or in dspace.cfg): '" + filterNames[i] + "'"); System.err.println("\nERROR: Unknown MediaFilter specified (either from command-line or in dspace.cfg): '" + filterNames[i] + "'");

View File

@@ -29,7 +29,8 @@ import org.dspace.content.packager.PackageParameters;
import org.dspace.content.packager.PackageIngester; import org.dspace.content.packager.PackageIngester;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.core.service.PluginService;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import org.dspace.eperson.factory.EPersonServiceFactory; import org.dspace.eperson.factory.EPersonServiceFactory;
import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.factory.HandleServiceFactory;
@@ -164,6 +165,7 @@ public class Packager
String[] parents = null; String[] parents = null;
String identifier = null; String identifier = null;
PackageParameters pkgParams = new PackageParameters(); PackageParameters pkgParams = new PackageParameters();
PluginService pluginService = CoreServiceFactory.getInstance().getPluginService();
//initialize a new packager -- we'll add all our current params as settings //initialize a new packager -- we'll add all our current params as settings
Packager myPackager = new Packager(); Packager myPackager = new Packager();
@@ -182,7 +184,7 @@ public class Packager
System.out.println("--------------------------------------------------------------"); System.out.println("--------------------------------------------------------------");
System.out.println("(These options may be specified using --option as described above)"); System.out.println("(These options may be specified using --option as described above)");
PackageIngester sip = (PackageIngester) PluginManager PackageIngester sip = (PackageIngester) pluginService
.getNamedPlugin(PackageIngester.class, line.getOptionValue('t')); .getNamedPlugin(PackageIngester.class, line.getOptionValue('t'));
if (sip != null) if (sip != null)
@@ -195,7 +197,7 @@ public class Packager
System.out.println("\nNo valid Submission plugin found for " + line.getOptionValue('t') + " type."); System.out.println("\nNo valid Submission plugin found for " + line.getOptionValue('t') + " type.");
} }
PackageDisseminator dip = (PackageDisseminator) PluginManager PackageDisseminator dip = (PackageDisseminator) pluginService
.getNamedPlugin(PackageDisseminator.class, line.getOptionValue('t')); .getNamedPlugin(PackageDisseminator.class, line.getOptionValue('t'));
if (dip != null) if (dip != null)
@@ -212,7 +214,7 @@ public class Packager
else //otherwise, display list of valid packager types else //otherwise, display list of valid packager types
{ {
System.out.println("\nAvailable Submission Package (SIP) types:"); System.out.println("\nAvailable Submission Package (SIP) types:");
String pn[] = PluginManager String pn[] = pluginService
.getAllPluginNames(PackageIngester.class); .getAllPluginNames(PackageIngester.class);
for (int i = 0; i < pn.length; ++i) for (int i = 0; i < pn.length; ++i)
{ {
@@ -220,7 +222,7 @@ public class Packager
} }
System.out System.out
.println("\nAvailable Dissemination Package (DIP) types:"); .println("\nAvailable Dissemination Package (DIP) types:");
pn = PluginManager.getAllPluginNames(PackageDisseminator.class); pn = pluginService.getAllPluginNames(PackageDisseminator.class);
for (int i = 0; i < pn.length; ++i) for (int i = 0; i < pn.length; ++i)
{ {
System.out.println(" " + pn[i]); System.out.println(" " + pn[i]);
@@ -329,7 +331,7 @@ public class Packager
//If we are in REPLACE mode //If we are in REPLACE mode
if(pkgParams.replaceModeEnabled()) if(pkgParams.replaceModeEnabled())
{ {
PackageIngester sip = (PackageIngester) PluginManager PackageIngester sip = (PackageIngester) pluginService
.getNamedPlugin(PackageIngester.class, myPackager.packageType); .getNamedPlugin(PackageIngester.class, myPackager.packageType);
if (sip == null) if (sip == null)
{ {
@@ -392,7 +394,7 @@ public class Packager
//else if normal SUBMIT mode (or basic RESTORE mode -- which is a special type of submission) //else if normal SUBMIT mode (or basic RESTORE mode -- which is a special type of submission)
else if (myPackager.submit || pkgParams.restoreModeEnabled()) else if (myPackager.submit || pkgParams.restoreModeEnabled())
{ {
PackageIngester sip = (PackageIngester) PluginManager PackageIngester sip = (PackageIngester) pluginService
.getNamedPlugin(PackageIngester.class, myPackager.packageType); .getNamedPlugin(PackageIngester.class, myPackager.packageType);
if (sip == null) if (sip == null)
{ {
@@ -444,7 +446,7 @@ public class Packager
else else
{ {
//retrieve specified package disseminator //retrieve specified package disseminator
PackageDisseminator dip = (PackageDisseminator) PluginManager PackageDisseminator dip = (PackageDisseminator) pluginService
.getNamedPlugin(PackageDisseminator.class, myPackager.packageType); .getNamedPlugin(PackageDisseminator.class, myPackager.packageType);
if (dip == null) if (dip == null)
{ {

View File

@@ -18,7 +18,7 @@ import java.util.List;
import org.dspace.authenticate.service.AuthenticationService; import org.dspace.authenticate.service.AuthenticationService;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group; import org.dspace.eperson.Group;
import org.dspace.eperson.service.EPersonService; import org.dspace.eperson.service.EPersonService;
@@ -68,7 +68,7 @@ public class AuthenticationServiceImpl implements AuthenticationService, Initial
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
methodStack = Arrays.asList((AuthenticationMethod[])PluginManager.getPluginSequence("authentication", AuthenticationMethod.class)); methodStack = Arrays.asList((AuthenticationMethod[])CoreServiceFactory.getInstance().getPluginService().getPluginSequence(AuthenticationMethod.class));
} }
@Override @Override

View File

@@ -8,9 +8,9 @@
package org.dspace.checker; package org.dspace.checker;
import org.dspace.content.Bitstream; import org.dspace.content.Bitstream;
import org.dspace.core.PluginManager;
import java.sql.SQLException; import java.sql.SQLException;
import org.dspace.core.factory.CoreServiceFactory;
/** /**
* Decorator that dispatches a specified number of bitstreams from a delegate * Decorator that dispatches a specified number of bitstreams from a delegate
@@ -30,11 +30,11 @@ public class LimitedCountDispatcher implements BitstreamDispatcher
private BitstreamDispatcher delegate = null; private BitstreamDispatcher delegate = null;
/** /**
* Default constructor uses PluginManager * Default constructor uses LegacyPluginServiceImpl
*/ */
public LimitedCountDispatcher() public LimitedCountDispatcher()
{ {
this((BitstreamDispatcher) PluginManager this((BitstreamDispatcher) CoreServiceFactory.getInstance().getPluginService()
.getSinglePlugin(BitstreamDispatcher.class)); .getSinglePlugin(BitstreamDispatcher.class));
} }

View File

@@ -10,16 +10,16 @@ package org.dspace.content.authority;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.Enumeration; import java.util.Iterator;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.content.Collection; import org.dspace.content.Collection;
import org.dspace.content.MetadataValue; import org.dspace.content.MetadataValue;
import org.dspace.content.authority.service.ChoiceAuthorityService; import org.dspace.content.authority.service.ChoiceAuthorityService;
import org.dspace.core.ConfigurationManager; import org.dspace.core.service.PluginService;
import org.dspace.core.PluginManager; import org.dspace.services.ConfigurationService;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired;
/** /**
* Broker for ChoiceAuthority plugins, and for other information configured * Broker for ChoiceAuthority plugins, and for other information configured
@@ -40,7 +40,7 @@ import org.springframework.beans.factory.InitializingBean;
* @author Larry Stone * @author Larry Stone
* @see ChoiceAuthority * @see ChoiceAuthority
*/ */
public final class ChoiceAuthorityServiceImpl implements ChoiceAuthorityService, InitializingBean public final class ChoiceAuthorityServiceImpl implements ChoiceAuthorityService
{ {
private Logger log = Logger.getLogger(ChoiceAuthorityServiceImpl.class); private Logger log = Logger.getLogger(ChoiceAuthorityServiceImpl.class);
@@ -53,22 +53,32 @@ public final class ChoiceAuthorityServiceImpl implements ChoiceAuthorityService,
// map of field key to closed value // map of field key to closed value
protected Map<String,Boolean> closed = new HashMap<String,Boolean>(); protected Map<String,Boolean> closed = new HashMap<String,Boolean>();
@Autowired(required = true)
protected ConfigurationService configurationService;
@Autowired(required = true)
protected PluginService pluginService;
private ChoiceAuthorityServiceImpl() { private ChoiceAuthorityServiceImpl() {
} }
@Override /**
public void afterPropertiesSet() throws Exception * Initialize the bean (after dependency injection has already taken place).
* Ensures the configurationService is injected, so that we can load
* choices from configuration.
* Called by "init-method" in Spring config.
*/
public void init() throws Exception
{ {
List<String> propKeys = configurationService.getPropertyKeys("choices");
Enumeration pn = ConfigurationManager.propertyNames(); Iterator<String> keyIterator = propKeys.iterator();
final String choicesPrefix = "choices."; final String choicesPrefix = "choices.";
final String choicesPlugin = "choices.plugin."; final String choicesPlugin = "choices.plugin.";
final String choicesPresentation = "choices.presentation."; final String choicesPresentation = "choices.presentation.";
final String choicesClosed = "choices.closed."; final String choicesClosed = "choices.closed.";
property: property:
while (pn.hasMoreElements()) while (keyIterator.hasNext())
{ {
String key = (String)pn.nextElement(); String key = keyIterator.next();
if (key.startsWith(choicesPrefix)) if (key.startsWith(choicesPrefix))
{ {
if (key.startsWith(choicesPlugin)) if (key.startsWith(choicesPlugin))
@@ -82,12 +92,11 @@ public final class ChoiceAuthorityServiceImpl implements ChoiceAuthorityService,
// XXX FIXME maybe add sanity check, call // XXX FIXME maybe add sanity check, call
// MetadataField.findByElement to make sure it's a real field. // MetadataField.findByElement to make sure it's a real field.
ChoiceAuthority ma = (ChoiceAuthority) ChoiceAuthority ma = (ChoiceAuthority)
PluginManager.getNamedPlugin(ChoiceAuthority.class, ConfigurationManager.getProperty(key)); pluginService.getNamedPlugin(ChoiceAuthority.class, configurationService.getProperty(key));
if (ma == null) if (ma == null)
{ {
log.warn("Skipping invalid configuration for "+key+" because named plugin not found: "+ConfigurationManager.getProperty(key)); log.warn("Skipping invalid configuration for "+key+" because named plugin not found: "+configurationService.getProperty(key));
continue property; continue property;
} }
controller.put(fkey, ma); controller.put(fkey, ma);
@@ -102,7 +111,7 @@ public final class ChoiceAuthorityServiceImpl implements ChoiceAuthorityService,
log.warn("Skipping invalid ChoiceAuthority configuration property: "+key+": does not have schema.element.qualifier"); log.warn("Skipping invalid ChoiceAuthority configuration property: "+key+": does not have schema.element.qualifier");
continue property; continue property;
} }
presentation.put(fkey, ConfigurationManager.getProperty(key)); presentation.put(fkey, configurationService.getProperty(key));
} }
else if (key.startsWith(choicesClosed)) else if (key.startsWith(choicesClosed))
{ {
@@ -112,7 +121,7 @@ public final class ChoiceAuthorityServiceImpl implements ChoiceAuthorityService,
log.warn("Skipping invalid ChoiceAuthority configuration property: "+key+": does not have schema.element.qualifier"); log.warn("Skipping invalid ChoiceAuthority configuration property: "+key+": does not have schema.element.qualifier");
continue property; continue property;
} }
closed.put(fkey, Boolean.valueOf(ConfigurationManager.getBooleanProperty(key))); closed.put(fkey, configurationService.getBooleanProperty(key));
} }
else else
{ {

View File

@@ -22,7 +22,7 @@ import org.dspace.content.packager.PackageParameters;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.jdom.Document; import org.jdom.Document;
import org.jdom.Element; import org.jdom.Element;
import org.jdom.JDOMException; import org.jdom.JDOMException;
@@ -101,7 +101,7 @@ public class METSDisseminationCrosswalk
} }
PackageDisseminator dip = (PackageDisseminator) PackageDisseminator dip = (PackageDisseminator)
PluginManager.getNamedPlugin(PackageDisseminator.class, METS_PACKAGER_PLUGIN); CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(PackageDisseminator.class, METS_PACKAGER_PLUGIN);
if (dip == null) if (dip == null)
{ {
throw new CrosswalkInternalException("Cannot find a disseminate plugin for package=" + METS_PACKAGER_PLUGIN); throw new CrosswalkInternalException("Cannot find a disseminate plugin for package=" + METS_PACKAGER_PLUGIN);

View File

@@ -23,7 +23,7 @@ import org.dspace.content.packager.RoleDisseminator;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.workflow.WorkflowException; import org.dspace.workflow.WorkflowException;
import org.jdom.Document; import org.jdom.Document;
import org.jdom.Element; import org.jdom.Element;
@@ -176,7 +176,7 @@ public class RoleCrosswalk
try try
{ {
PackageDisseminator dip = (PackageDisseminator) PackageDisseminator dip = (PackageDisseminator)
PluginManager.getNamedPlugin(PackageDisseminator.class, ROLE_PACKAGER_PLUGIN); CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(PackageDisseminator.class, ROLE_PACKAGER_PLUGIN);
if (dip == null) if (dip == null)
{ {
throw new CrosswalkInternalException("Cannot find a PackageDisseminator plugin named " + ROLE_PACKAGER_PLUGIN); throw new CrosswalkInternalException("Cannot find a PackageDisseminator plugin named " + ROLE_PACKAGER_PLUGIN);
@@ -286,7 +286,7 @@ public class RoleCrosswalk
//locate our "DSPACE-ROLES" PackageIngester plugin //locate our "DSPACE-ROLES" PackageIngester plugin
PackageIngester sip = (PackageIngester) PackageIngester sip = (PackageIngester)
PluginManager.getNamedPlugin(PackageIngester.class, ROLE_PACKAGER_PLUGIN); CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(PackageIngester.class, ROLE_PACKAGER_PLUGIN);
if (sip == null) if (sip == null)
{ {
throw new CrosswalkInternalException("Cannot find a PackageIngester plugin named " + ROLE_PACKAGER_PLUGIN); throw new CrosswalkInternalException("Cannot find a PackageIngester plugin named " + ROLE_PACKAGER_PLUGIN);

View File

@@ -28,7 +28,7 @@ import org.dspace.content.service.ItemService;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.factory.HandleServiceFactory;
import org.jdom.Document; import org.jdom.Document;
import org.jdom.Element; import org.jdom.Element;
@@ -525,7 +525,7 @@ public class XSLTDisseminationCrosswalk
} }
} }
DisseminationCrosswalk xwalk = (DisseminationCrosswalk)PluginManager.getNamedPlugin( DisseminationCrosswalk xwalk = (DisseminationCrosswalk) CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(
DisseminationCrosswalk.class, xwalkname); DisseminationCrosswalk.class, xwalkname);
if (xwalk == null) if (xwalk == null)
{ {

View File

@@ -30,7 +30,7 @@ import org.dspace.content.service.CommunityService;
import org.dspace.content.service.ItemService; import org.dspace.content.service.ItemService;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.jdom.Document; import org.jdom.Document;
import org.jdom.Element; import org.jdom.Element;
import org.jdom.input.SAXBuilder; import org.jdom.input.SAXBuilder;
@@ -287,7 +287,7 @@ public class XSLTIngestionCrosswalk
++i; ++i;
list = true; list = true;
} }
IngestionCrosswalk xwalk = (IngestionCrosswalk)PluginManager.getNamedPlugin( IngestionCrosswalk xwalk = (IngestionCrosswalk) CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(
IngestionCrosswalk.class, argv[i]); IngestionCrosswalk.class, argv[i]);
if (xwalk == null) if (xwalk == null)
{ {

View File

@@ -10,12 +10,12 @@ package org.dspace.content.license;
import java.util.Formattable; import java.util.Formattable;
import java.util.Formatter; import java.util.Formatter;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
/** /**
* Wrapper class to make formattable any argument used in the license template. * Wrapper class to make formattable any argument used in the license template.
* The formatter behavior is delegated to a specific class on "type" basis * The formatter behavior is delegated to a specific class on "type" basis
* using the PluginManager * using the PluginService
* *
* @see Formattable * @see Formattable
* @see LicenseArgumentFormatter * @see LicenseArgumentFormatter
@@ -38,7 +38,7 @@ public class FormattableArgument implements Formattable
public void formatTo(Formatter formatter, int flags, int width, public void formatTo(Formatter formatter, int flags, int width,
int precision) int precision)
{ {
LicenseArgumentFormatter laf = (LicenseArgumentFormatter) PluginManager LicenseArgumentFormatter laf = (LicenseArgumentFormatter) CoreServiceFactory.getInstance().getPluginService()
.getNamedPlugin(LicenseArgumentFormatter.class, type); .getNamedPlugin(LicenseArgumentFormatter.class, type);
if (laf != null) if (laf != null)
{ {

View File

@@ -73,8 +73,9 @@ import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.LogManager; import org.dspace.core.LogManager;
import org.dspace.core.PluginManager;
import org.dspace.core.Utils; import org.dspace.core.Utils;
import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.core.service.PluginService;
import org.dspace.license.factory.LicenseServiceFactory; import org.dspace.license.factory.LicenseServiceFactory;
import org.dspace.license.service.CreativeCommonsService; import org.dspace.license.service.CreativeCommonsService;
import org.jdom.Element; import org.jdom.Element;
@@ -583,14 +584,16 @@ public abstract class AbstractMETSDisseminator
xwalkName = typeSpec; xwalkName = typeSpec;
} }
PluginService pluginService = CoreServiceFactory.getInstance().getPluginService();
// First, check to see if the crosswalk we are using is a normal DisseminationCrosswalk // First, check to see if the crosswalk we are using is a normal DisseminationCrosswalk
boolean xwalkFound = PluginManager.hasNamedPlugin(DisseminationCrosswalk.class, xwalkName); boolean xwalkFound = pluginService.hasNamedPlugin(DisseminationCrosswalk.class, xwalkName);
if(xwalkFound) if(xwalkFound)
{ {
// Find the crosswalk we will be using to generate the metadata for this mdSec // Find the crosswalk we will be using to generate the metadata for this mdSec
DisseminationCrosswalk xwalk = (DisseminationCrosswalk) DisseminationCrosswalk xwalk = (DisseminationCrosswalk)
PluginManager.getNamedPlugin(DisseminationCrosswalk.class, xwalkName); pluginService.getNamedPlugin(DisseminationCrosswalk.class, xwalkName);
if (xwalk.canDisseminate(dso)) if (xwalk.canDisseminate(dso))
{ {
@@ -629,7 +632,7 @@ public abstract class AbstractMETSDisseminator
else else
{ {
StreamDisseminationCrosswalk sxwalk = (StreamDisseminationCrosswalk) StreamDisseminationCrosswalk sxwalk = (StreamDisseminationCrosswalk)
PluginManager.getNamedPlugin(StreamDisseminationCrosswalk.class, xwalkName); pluginService.getNamedPlugin(StreamDisseminationCrosswalk.class, xwalkName);
if (sxwalk != null) if (sxwalk != null)
{ {
if (sxwalk.canDisseminate(context, dso)) if (sxwalk.canDisseminate(context, dso))

View File

@@ -20,8 +20,9 @@ import org.dspace.content.crosswalk.CrosswalkException;
import org.dspace.content.crosswalk.MetadataValidationException; import org.dspace.content.crosswalk.MetadataValidationException;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.PluginManager;
import org.dspace.app.mediafilter.MediaFilter; import org.dspace.app.mediafilter.MediaFilter;
import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.core.service.PluginService;
import org.jdom.Element; import org.jdom.Element;
@@ -199,12 +200,14 @@ public class DSpaceMETSIngester
// only needed when importing a SIP without canonical DSpace derived file naming. // only needed when importing a SIP without canonical DSpace derived file naming.
private String makeDerivedFilename(String bundleName, String origName) private String makeDerivedFilename(String bundleName, String origName)
{ {
PluginService pluginService = CoreServiceFactory.getInstance().getPluginService();
// get the MediaFilter that would create this bundle: // get the MediaFilter that would create this bundle:
String mfNames[] = PluginManager.getAllPluginNames(MediaFilter.class); String mfNames[] = pluginService.getAllPluginNames(MediaFilter.class);
for (int i = 0; i < mfNames.length; ++i) for (int i = 0; i < mfNames.length; ++i)
{ {
MediaFilter mf = (MediaFilter)PluginManager.getNamedPlugin(MediaFilter.class, mfNames[i]); MediaFilter mf = (MediaFilter)pluginService.getNamedPlugin(MediaFilter.class, mfNames[i]);
if (bundleName.equals(mf.getBundleName())) if (bundleName.equals(mf.getBundleName()))
{ {
return mf.getFilteredName(origName); return mf.getFilteredName(origName);

View File

@@ -32,7 +32,7 @@ import org.dspace.content.crosswalk.StreamIngestionCrosswalk;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.jdom.Document; import org.jdom.Document;
import org.jdom.Content; import org.jdom.Content;
import org.jdom.Element; import org.jdom.Element;
@@ -989,7 +989,7 @@ public class METSManifest
xwalkName = type; xwalkName = type;
} }
} }
return PluginManager.getNamedPlugin(clazz, xwalkName); return CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(clazz, xwalkName);
} }
/** /**

View File

@@ -13,19 +13,23 @@ import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.core.service.PluginService;
import org.dspace.services.ConfigurationService; import org.dspace.services.ConfigurationService;
import org.dspace.utils.DSpace; import org.springframework.beans.factory.annotation.Autowired;
/** /**
* The Plugin Manager is a very simple component container. It creates and * The Legacy Plugin Service is a very simple component container (based on the
* organizes components (plugins), and helps select a plugin in the cases * legacy PluginManager class). It reads defined "plugins" (interfaces) from
* where there are many possible choices. It also gives some limited * config file(s) and makes them available to the API. (@TODO: Someday, this
* entire "plugin" framework needs to be replaced by Spring Beans.)
* <p>
* It creates and organizes components (plugins), and helps select a plugin in
* the cases where there are many possible choices. It also gives some limited
* control over the lifecycle of a plugin. It manages three different types * control over the lifecycle of a plugin. It manages three different types
* (usage patterns) of plugins: * (usage patterns) of plugins:
* <p> * <p>
@@ -53,12 +57,13 @@ import org.dspace.utils.DSpace;
* names in the configuration entry. * names in the configuration entry.
* *
* @author Larry Stone * @author Larry Stone
* @author Tim Donohue (turned old PluginManager into a PluginService)
* @see SelfNamedPlugin * @see SelfNamedPlugin
*/ */
public class PluginManager public class LegacyPluginServiceImpl implements PluginService
{ {
/** log4j category */ /** log4j category */
private static Logger log = Logger.getLogger(PluginManager.class); private static Logger log = Logger.getLogger(LegacyPluginServiceImpl.class);
/** /**
* Prefixes of names of properties to look for in DSpace Configuration * Prefixes of names of properties to look for in DSpace Configuration
@@ -78,51 +83,32 @@ public class PluginManager
private static final String SEP = "\034"; private static final String SEP = "\034";
/** Paths to search for third-party plugins. */ /** Paths to search for third-party plugins. */
private static final String[] classPath; private String[] classPath;
static {
String path = new DSpace().getConfigurationService().getProperty(CLASSPATH); /** Custom class loader to search for third-party plugins. */
private PathsClassLoader loader;
@Autowired(required = true)
protected ConfigurationService configurationService;
private LegacyPluginServiceImpl() {
}
/**
* Initialize the bean (after dependency injection has already taken place).
* Ensures the configurationService is injected, so that we can load
* plugin classpath info from config.
* Called by "init-method" in Spring config.
*/
void init()
{
String path = configurationService.getProperty(CLASSPATH);
if (null == path) if (null == path)
classPath = new String[0]; classPath = new String[0];
else else
classPath = path.split(":"); classPath = path.split(":");
}
/** Custom class loader to search for third-party plugins. */ loader = new PathsClassLoader(LegacyPluginServiceImpl.class.getClassLoader(), classPath);
private static final PathsClassLoader loader
= new PathsClassLoader(PluginManager.class.getClassLoader(), classPath);
// Map of plugin class to "reusable" metric (as Boolean, must be Object)
// Key is Class, value is Boolean (true by default).
private static Map<Class<Object>, Boolean> cacheMeCache = new HashMap<Class<Object>, Boolean>();
/**
* Whether or not to cache instances of this class. Ironically,
* the cacheability information is itself cached.
* <P>
* By default, all plugin class instances ARE cached. To disable instance
* caching for a specific plugin class, you must add a configuration similar
* to this in your dspace.cfg:
* <code>
* plugin.reusable.[full-class-name] = false
* </code>
* @return true if class instances should be cached in memory, false otherwise.
*/
private static boolean cacheMe(String module, Class implClass)
{
if (cacheMeCache.containsKey(implClass))
{
return (cacheMeCache.get(implClass)).booleanValue();
}
else
{
ConfigurationService config = new DSpace().getConfigurationService();
String key = REUSABLE_PREFIX+implClass.getName();
// NOTE: module name is ignored, as reusable plugins configs ALWAYS begin with REUSABLE_PREFIX
boolean reusable = config.getBooleanProperty(key, true);
cacheMeCache.put(implClass, Boolean.valueOf(reusable));
return reusable;
}
} }
/** /**
@@ -139,28 +125,8 @@ public class PluginManager
* @return instance of plugin * @return instance of plugin
* @throws PluginConfigurationError * @throws PluginConfigurationError
*/ */
public static Object getSinglePlugin(Class interfaceClass) @Override
throws PluginConfigurationError, PluginInstantiationException public Object getSinglePlugin(Class interfaceClass)
{
return getSinglePlugin(null, interfaceClass);
}
/**
* Returns an instance of the singleton (single) plugin implementing
* the given interface. There must be exactly one single plugin
* configured for this interface, otherwise the
* <code>PluginConfigurationError</code> is thrown.
* <p>
* Note that this is the only "get plugin" method which throws an
* exception. It is typically used at initialization time to set up
* a permanent part of the system so any failure is fatal.
*
* @param module name of config module, or <code>null</code> for standard location
* @param interfaceClass interface Class object
* @return instance of plugin
* @throws PluginConfigurationError
*/
public static Object getSinglePlugin(String module, Class interfaceClass)
throws PluginConfigurationError, PluginInstantiationException throws PluginConfigurationError, PluginInstantiationException
{ {
String iname = interfaceClass.getName(); String iname = interfaceClass.getName();
@@ -168,11 +134,11 @@ public class PluginManager
// NOTE: module name is ignored, as single plugins ALWAYS begin with SINGLE_PREFIX // NOTE: module name is ignored, as single plugins ALWAYS begin with SINGLE_PREFIX
String key = SINGLE_PREFIX+iname; String key = SINGLE_PREFIX+iname;
// configuration format is prefix.<interface> = <classname> // configuration format is prefix.<interface> = <classname>
String classname = new DSpace().getConfigurationService().getProperty(key); String classname = configurationService.getProperty(key);
if (classname != null) if (classname != null)
{ {
return getAnonymousPlugin(module, classname.trim()); return getAnonymousPlugin(classname.trim());
} }
else else
{ {
@@ -180,58 +146,40 @@ public class PluginManager
} }
} }
// cache of config data for Sequence Plugins; format its
// <interface-name> -> [ <classname>.. ] (value is Array)
private static Map<String, String[]> sequenceConfig = new HashMap<String, String[]>();
/** /**
* Returns instances of all plugins that implement the interface * Returns instances of all plugins that implement the interface,
* intface, in an Array. Returns an empty array if no there are no * in an Array. Returns an empty array if no there are no
* matching plugins. * matching plugins.
* <p> * <p>
* The order of the plugins in the array is the same as their class * The order of the plugins in the array is the same as their class
* names in the configuration's value field. * names in the configuration's value field.
* *
* @param intfc interface for which to find plugins. * @param interfaceClass interface for which to find plugins.
* @return an array of plugin instances; if none are * @return an array of plugin instances; if none are
* available an empty array is returned. * available an empty array is returned.
*/ */
public static Object[] getPluginSequence(Class intfc) @Override
public Object[] getPluginSequence(Class interfaceClass)
throws PluginInstantiationException throws PluginInstantiationException
{ {
return getPluginSequence(null, intfc); // cache of config data for Sequence Plugins; format its
} // <interface-name> -> [ <classname>.. ] (value is Array)
Map<String, String[]> sequenceConfig = new HashMap<String, String[]>();
/**
* Returns instances of all plugins that implement the interface
* intface, in an Array. Returns an empty array if no there are no
* matching plugins.
* <p>
* The order of the plugins in the array is the same as their class
* names in the configuration's value field.
*
* @param module name of config module, or <code>null</code> for standard
* @param intfc interface for which to find plugins.
* @return an array of plugin instances; if none are
* available an empty array is returned.
*/
public static Object[] getPluginSequence(String module, Class intfc)
throws PluginInstantiationException
{
// cache the configuration for this interface after grovelling it once: // cache the configuration for this interface after grovelling it once:
// format is prefix.<interface> = <classname> // format is prefix.<interface> = <classname>
String iname = intfc.getName(); String iname = interfaceClass.getName();
String[] classname = null; String[] classname = null;
if (!sequenceConfig.containsKey(iname)) if (!sequenceConfig.containsKey(iname))
{ {
// NOTE: module name is ignored, as sequence plugins ALWAYS begin with SEQUENCE_PREFIX // NOTE: module name is ignored, as sequence plugins ALWAYS begin with SEQUENCE_PREFIX
String key = SEQUENCE_PREFIX+iname; String key = SEQUENCE_PREFIX+iname;
classname = new DSpace().getConfigurationService().getArrayProperty(key); classname = configurationService.getArrayProperty(key);
if (classname == null || classname.length==0) if (classname == null || classname.length==0)
{ {
log.warn("No Configuration entry found for Sequence Plugin interface="+iname); log.warn("No Configuration entry found for Sequence Plugin interface="+iname);
return (Object[]) Array.newInstance(intfc, 0); return (Object[]) Array.newInstance(interfaceClass, 0);
} }
sequenceConfig.put(iname, classname); sequenceConfig.put(iname, classname);
} }
@@ -240,52 +188,31 @@ public class PluginManager
classname = sequenceConfig.get(iname); classname = sequenceConfig.get(iname);
} }
Object result[] = (Object[])Array.newInstance(intfc, classname.length); Object result[] = (Object[])Array.newInstance(interfaceClass, classname.length);
for (int i = 0; i < classname.length; ++i) for (int i = 0; i < classname.length; ++i)
{ {
log.debug("Adding Sequence plugin for interface= "+iname+", class="+classname[i]); log.debug("Adding Sequence plugin for interface= "+iname+", class="+classname[i]);
result[i] = getAnonymousPlugin(module, classname[i]); result[i] = getAnonymousPlugin(classname[i]);
} }
return result; return result;
} }
// Map of cached (reusable) single plugin instances - class -> instance.
private static Map<Serializable, Object> anonymousInstanceCache = new HashMap<Serializable, Object>();
// Get possibly-cached plugin instance for un-named plugin, // Get possibly-cached plugin instance for un-named plugin,
// this is shared by Single and Sequence plugins. // this is shared by Single and Sequence plugins.
private static Object getAnonymousPlugin(String module, String classname) private Object getAnonymousPlugin(String classname)
throws PluginInstantiationException throws PluginInstantiationException
{ {
try try
{ {
Class pluginClass = Class.forName(classname, true, loader); Class pluginClass = Class.forName(classname, true, loader);
if (cacheMe(module, pluginClass)) return pluginClass.newInstance();
{
Object cached = anonymousInstanceCache.get(pluginClass);
if (cached == null)
{
cached = pluginClass.newInstance();
anonymousInstanceCache.put(pluginClass, cached);
}
return cached;
}
else
{
return pluginClass.newInstance();
}
} }
catch (ClassNotFoundException e) catch (ClassNotFoundException e)
{ {
throw new PluginInstantiationException("Cannot load plugin class: " + throw new PluginInstantiationException("Cannot load plugin class: " +
e.toString(), e); e.toString(), e);
} }
catch (InstantiationException e) catch (InstantiationException|IllegalAccessException e)
{
throw new PluginInstantiationException(e);
}
catch (IllegalAccessException e)
{ {
throw new PluginInstantiationException(e); throw new PluginInstantiationException(e);
} }
@@ -293,13 +220,13 @@ public class PluginManager
// Map of named plugin classes, [intfc,name] -> class // Map of named plugin classes, [intfc,name] -> class
// Also contains intfc -> "marker" to mark when interface has been loaded. // Also contains intfc -> "marker" to mark when interface has been loaded.
private static Map<String, String> namedPluginClasses = new HashMap<String, String>(); private Map<String, String> namedPluginClasses = new HashMap<String, String>();
// Map of cached (reusable) named plugin instances, [class,name] -> instance // Map of cached (reusable) named plugin instances, [class,name] -> instance
private static Map<Serializable, Object> namedInstanceCache = new HashMap<Serializable, Object>(); private Map<Serializable, Object> namedInstanceCache = new HashMap<Serializable, Object>();
// load and cache configuration data for the given interface. // load and cache configuration data for the given interface.
private static void configureNamedPlugin(String module, String iname) private void configureNamedPlugin(String iname)
throws ClassNotFoundException throws ClassNotFoundException
{ {
int found = 0; int found = 0;
@@ -317,7 +244,7 @@ public class PluginManager
// <CLASS> = <name>\, <name> [ ... ] // <CLASS> = <name>\, <name> [ ... ]
// NOTE: module name is ignored, as named plugins ALWAYS begin with NAMED_PREFIX // NOTE: module name is ignored, as named plugins ALWAYS begin with NAMED_PREFIX
String key = NAMED_PREFIX+iname; String key = NAMED_PREFIX+iname;
String[] namedVals = new DSpace().getConfigurationService().getArrayProperty(key); String[] namedVals = configurationService.getArrayProperty(key);
if (namedVals != null && namedVals.length>0) if (namedVals != null && namedVals.length>0)
{ {
String prevClassName = null; String prevClassName = null;
@@ -356,7 +283,7 @@ public class PluginManager
// format is plugin.selfnamed.<INTF> = <CLASS> , <CLASS> .. // format is plugin.selfnamed.<INTF> = <CLASS> , <CLASS> ..
// NOTE: module name is ignored, as self-named plugins ALWAYS begin with SELFNAMED_PREFIX // NOTE: module name is ignored, as self-named plugins ALWAYS begin with SELFNAMED_PREFIX
key = SELFNAMED_PREFIX+iname; key = SELFNAMED_PREFIX+iname;
String[] selfNamedVals = new DSpace().getConfigurationService().getArrayProperty(key); String[] selfNamedVals = configurationService.getArrayProperty(key);
if (selfNamedVals != null && selfNamedVals.length>0) if (selfNamedVals != null && selfNamedVals.length>0)
{ {
for (String classname : selfNamedVals) for (String classname : selfNamedVals)
@@ -394,7 +321,7 @@ public class PluginManager
} }
// add info for a named plugin to cache, under all its names. // add info for a named plugin to cache, under all its names.
private static int installNamedConfigs(String iname, String classname, String names[]) private int installNamedConfigs(String iname, String classname, String names[])
throws ClassNotFoundException throws ClassNotFoundException
{ {
int found = 0; int found = 0;
@@ -418,38 +345,22 @@ public class PluginManager
/** /**
* Returns an instance of a plugin that implements the interface * Returns an instance of a plugin that implements the interface
* intface and is bound to a name matching name. If there is no * and is bound to a name matching name. If there is no
* matching plugin, it returns null. The names are matched by * matching plugin, it returns null. The names are matched by
* String.equals(). * String.equals().
* *
* @param intfc the interface class of the plugin * @param interfaceClass the interface class of the plugin
* @param name under which the plugin implementation is configured. * @param name under which the plugin implementation is configured.
* @return instance of plugin implementation, or null if there is no match or an error. * @return instance of plugin implementation, or null if there is no match or an error.
*/ */
public static Object getNamedPlugin(Class intfc, String name) @Override
throws PluginInstantiationException public Object getNamedPlugin(Class interfaceClass, String name)
{
return getNamedPlugin(null, intfc, name);
}
/**
* Returns an instance of a plugin that implements the interface
* intface and is bound to a name matching name. If there is no
* matching plugin, it returns null. The names are matched by
* String.equals().
*
* @param module config module, or <code>null</code> for standard location
* @param intfc the interface class of the plugin
* @param name under which the plugin implementation is configured.
* @return instance of plugin implementation, or null if there is no match or an error.
*/
public static Object getNamedPlugin(String module, Class intfc, String name)
throws PluginInstantiationException throws PluginInstantiationException
{ {
try try
{ {
String iname = intfc.getName(); String iname = interfaceClass.getName();
configureNamedPlugin(module, iname); configureNamedPlugin(iname);
String key = iname + SEP + name; String key = iname + SEP + name;
String cname = namedPluginClasses.get(key); String cname = namedPluginClasses.get(key);
if (cname == null) if (cname == null)
@@ -459,36 +370,15 @@ public class PluginManager
else else
{ {
Class pluginClass = Class.forName(cname, true, loader); Class pluginClass = Class.forName(cname, true, loader);
if (cacheMe(module, pluginClass)) log.debug("Creating instance of: " + cname +
" for interface=" + iname +
" pluginName=" + name );
Object result = pluginClass.newInstance();
if (result instanceof SelfNamedPlugin)
{ {
String nkey = pluginClass.getName() + SEP + name; ((SelfNamedPlugin) result).setPluginInstanceName(name);
Object cached = namedInstanceCache.get(nkey);
if (cached == null)
{
log.debug("Creating cached instance of: " + cname +
" for interface=" + iname +
" pluginName=" + name );
cached = pluginClass.newInstance();
if (cached instanceof SelfNamedPlugin)
{
((SelfNamedPlugin) cached).setPluginInstanceName(name);
}
namedInstanceCache.put(nkey, cached);
}
return cached;
}
else
{
log.debug("Creating UNcached instance of: " + cname +
" for interface=" + iname +
" pluginName=" + name );
Object result = pluginClass.newInstance();
if (result instanceof SelfNamedPlugin)
{
((SelfNamedPlugin) result).setPluginInstanceName(name);
}
return result;
} }
return result;
} }
} }
catch (ClassNotFoundException e) catch (ClassNotFoundException e)
@@ -496,11 +386,7 @@ public class PluginManager
throw new PluginInstantiationException("Cannot load plugin class: " + throw new PluginInstantiationException("Cannot load plugin class: " +
e.toString(), e); e.toString(), e);
} }
catch (InstantiationException e) catch (InstantiationException|IllegalAccessException e)
{
throw new PluginInstantiationException(e);
}
catch (IllegalAccessException e)
{ {
throw new PluginInstantiationException(e); throw new PluginInstantiationException(e);
} }
@@ -510,36 +396,21 @@ public class PluginManager
/** /**
* Returns whether a plugin exists which implements the specified interface * Returns whether a plugin exists which implements the specified interface
* and has a specified name. If a matching plugin is found to be configured, * and has a specified name. If a matching plugin is found to be configured,
* return true. If there is no matching plugin, return false. * return true. If there is no matching plugin, return false.
* *
* @param intfc the interface class of the plugin * @param interfaceClass the interface class of the plugin
* @param name under which the plugin implementation is configured. * @param name under which the plugin implementation is configured.
* @return true if plugin was found to be configured, false otherwise * @return true if plugin was found to be configured, false otherwise
*/ */
public static boolean hasNamedPlugin(Class intfc, String name) @Override
throws PluginInstantiationException public boolean hasNamedPlugin(Class interfaceClass, String name)
{
return hasNamedPlugin(null, intfc, name);
}
/**
* Returns whether a plugin exists which implements the specified interface
* and has a specified name. If a matching plugin is found to be configured,
* return true. If there is no matching plugin, return false.
*
* @param module the config module or <code>null</code> for regular location
* @param intfc the interface class of the plugin
* @param name under which the plugin implementation is configured.
* @return true if plugin was found to be configured, false otherwise
*/
public static boolean hasNamedPlugin(String module, Class intfc, String name)
throws PluginInstantiationException throws PluginInstantiationException
{ {
try try
{ {
String iname = intfc.getName(); String iname = interfaceClass.getName();
configureNamedPlugin(module, iname); configureNamedPlugin(iname);
String key = iname + SEP + name; String key = iname + SEP + name;
return namedPluginClasses.get(key) != null; return namedPluginClasses.get(key) != null;
} }
@@ -552,42 +423,24 @@ public class PluginManager
/** /**
* Returns all of the names under which a named plugin implementing * Returns all of the names under which a named plugin implementing
* the interface intface can be requested (with getNamedPlugin()). * the interface can be requested (with getNamedPlugin()).
* The array is empty if there are no matches. Use this to populate * The array is empty if there are no matches. Use this to populate
* a menu of plugins for interactive selection, or to document what * a menu of plugins for interactive selection, or to document what
* the possible choices are. * the possible choices are.
* <p> * <p>
* NOTE: The names are NOT returned in any deterministic order. * NOTE: The names are NOT returned in any deterministic order.
* *
* @param intfc plugin interface for which to return names. * @param interfaceClass plugin interface for which to return names.
* @return an array of strings with every name; if none are * @return an array of strings with every name; if none are
* available an empty array is returned. * available an empty array is returned.
*/ */
public static String[] getAllPluginNames(Class intfc) @Override
{ public String[] getAllPluginNames(Class interfaceClass)
return getAllPluginNames(null, intfc);
}
/**
* Returns all of the names under which a named plugin implementing
* the interface intface can be requested (with getNamedPlugin()).
* The array is empty if there are no matches. Use this to populate
* a menu of plugins for interactive selection, or to document what
* the possible choices are.
* <p>
* NOTE: The names are NOT returned in any deterministic order.
*
* @param module the module name
* @param intfc plugin interface for which to return names.
* @return an array of strings with every name; if none are
* available an empty array is returned.
*/
public static String[] getAllPluginNames(String module, Class intfc)
{ {
try try
{ {
String iname = intfc.getName(); String iname = interfaceClass.getName();
configureNamedPlugin(module, iname); configureNamedPlugin(iname);
String prefix = iname + SEP; String prefix = iname + SEP;
ArrayList<String> result = new ArrayList<String>(); ArrayList<String> result = new ArrayList<String>();
@@ -611,43 +464,13 @@ public class PluginManager
} }
} }
/**
* Tells the Plugin Manager to let go of any references to a
* reusable plugin, to prevent it from being given out again and to
* allow the object to be garbage-collected. Call this when a
* plugin instance must be taken out of circulation.
*
* @param plugin the object to release, must have been created by
* <code>getNamedPlugin</code> etc.
*/
public static void releasePlugin(Object plugin)
{
forgetInstance(plugin, namedInstanceCache);
forgetInstance(plugin, anonymousInstanceCache);
}
private static void forgetInstance(Object plugin, Map<Serializable, Object> cacheMap)
{
Collection values = cacheMap.values();
Iterator ci = values.iterator();
while (ci.hasNext())
{
// Identity comparison is valid for this usage
Object val = ci.next();
if (val == plugin)
{
values.remove(val);
}
}
}
/* ----------------------------------------------------------------- /* -----------------------------------------------------------------
* Code to check configuration is all below this line * Code to check configuration is all below this line
* ----------------------------------------------------------------- * -----------------------------------------------------------------
*/ */
// true if classname is valid and loadable. // true if classname is valid and loadable.
private static boolean checkClassname(String iname, String msg) private boolean checkClassname(String iname, String msg)
{ {
try try
{ {
@@ -664,7 +487,7 @@ public class PluginManager
} }
// true if classname is loadable AND is subclass of SelfNamedPlugin // true if classname is loadable AND is subclass of SelfNamedPlugin
private static boolean checkSelfNamed(String iname) private boolean checkSelfNamed(String iname)
{ {
try try
{ {
@@ -681,7 +504,7 @@ public class PluginManager
} }
// recursively climb superclass stack until we find SelfNamedPlugin // recursively climb superclass stack until we find SelfNamedPlugin
private static boolean checkSelfNamed(Class cls) private boolean checkSelfNamed(Class cls)
{ {
Class sup = cls.getSuperclass(); Class sup = cls.getSuperclass();
if (sup == null) if (sup == null)
@@ -700,11 +523,11 @@ public class PluginManager
// check named-plugin names by interface -- call the usual // check named-plugin names by interface -- call the usual
// configuration and let it find missing or duplicate names. // configuration and let it find missing or duplicate names.
private static void checkNames(String iname) private void checkNames(String iname)
{ {
try try
{ {
configureNamedPlugin(null, iname); configureNamedPlugin(iname);
} }
catch (ClassNotFoundException ce) catch (ClassNotFoundException ce)
{ {
@@ -714,7 +537,7 @@ public class PluginManager
/** /**
* Validate the entries in the DSpace Configuration relevant to * Validate the entries in the DSpace Configuration relevant to
* PluginManager. Look for inconsistencies, illegal syntax, etc. LegacyPluginServiceImpl. Look for inconsistencies, illegal syntax, etc.
* Announce violations with "log.error" so they appear in the log * Announce violations with "log.error" so they appear in the log
* or in the standard error stream if this is run interactively. * or in the standard error stream if this is run interactively.
* <ul> * <ul>
@@ -727,7 +550,7 @@ public class PluginManager
* <li>Named plugin entries lacking names. * <li>Named plugin entries lacking names.
* </ul> * </ul>
*/ */
public static void checkConfiguration() public void checkConfiguration()
throws IOException throws IOException
{ {
FileReader fr = null; FileReader fr = null;
@@ -745,9 +568,8 @@ public class PluginManager
Map<String, String> reusableKey = new HashMap<String, String>(); Map<String, String> reusableKey = new HashMap<String, String>();
HashMap<String, String> keyMap = new HashMap<String, String>(); HashMap<String, String> keyMap = new HashMap<String, String>();
ConfigurationService config = new DSpace().getConfigurationService();
// Find all property keys starting with "plugin." // Find all property keys starting with "plugin."
List<String> keys = config.getPropertyKeys("plugin."); List<String> keys = configurationService.getPropertyKeys("plugin.");
for(String key : keys) for(String key : keys)
{ {
@@ -803,7 +625,7 @@ public class PluginManager
while (ii.hasNext()) while (ii.hasNext())
{ {
String key = ii.next(); String key = ii.next();
String val = config.getProperty(SINGLE_PREFIX+key); String val = configurationService.getProperty(SINGLE_PREFIX+key);
if (val == null) if (val == null)
{ {
log.error("Single plugin config not found for: " + SINGLE_PREFIX + key); log.error("Single plugin config not found for: " + SINGLE_PREFIX + key);
@@ -823,7 +645,7 @@ public class PluginManager
while (ii.hasNext()) while (ii.hasNext())
{ {
String key = ii.next(); String key = ii.next();
String[] vals = config.getArrayProperty(SEQUENCE_PREFIX+key); String[] vals = configurationService.getArrayProperty(SEQUENCE_PREFIX+key);
if (vals == null || vals.length==0) if (vals == null || vals.length==0)
{ {
log.error("Sequence plugin config not found for: " + SEQUENCE_PREFIX + key); log.error("Sequence plugin config not found for: " + SEQUENCE_PREFIX + key);
@@ -846,7 +668,7 @@ public class PluginManager
while (ii.hasNext()) while (ii.hasNext())
{ {
String key = ii.next(); String key = ii.next();
String[] vals = config.getArrayProperty(SELFNAMED_PREFIX+key); String[] vals = configurationService.getArrayProperty(SELFNAMED_PREFIX+key);
if (vals == null || vals.length==0) if (vals == null || vals.length==0)
{ {
log.error("Selfnamed plugin config not found for: " + SELFNAMED_PREFIX + key); log.error("Selfnamed plugin config not found for: " + SELFNAMED_PREFIX + key);
@@ -871,7 +693,7 @@ public class PluginManager
while (ii.hasNext()) while (ii.hasNext())
{ {
String key = ii.next(); String key = ii.next();
String[] vals =config.getArrayProperty(NAMED_PREFIX+key); String[] vals = configurationService.getArrayProperty(NAMED_PREFIX+key);
if (vals == null || vals.length==0) if (vals == null || vals.length==0)
{ {
log.error("Named plugin config not found for: " + NAMED_PREFIX + key); log.error("Named plugin config not found for: " + NAMED_PREFIX + key);
@@ -910,7 +732,7 @@ public class PluginManager
* <code>checkConfiguration</code> and shows the results. * <code>checkConfiguration</code> and shows the results.
* There are no command-line options. * There are no command-line options.
*/ */
public static void main(String[] argv) throws Exception public void main(String[] argv) throws Exception
{ {
checkConfiguration(); checkConfiguration();
} }

View File

@@ -9,6 +9,7 @@ package org.dspace.core.factory;
import org.dspace.core.service.LicenseService; import org.dspace.core.service.LicenseService;
import org.dspace.core.service.NewsService; import org.dspace.core.service.NewsService;
import org.dspace.core.service.PluginService;
import org.dspace.utils.DSpace; import org.dspace.utils.DSpace;
/** /**
@@ -22,6 +23,8 @@ public abstract class CoreServiceFactory {
public abstract NewsService getNewsService(); public abstract NewsService getNewsService();
public abstract PluginService getPluginService();
public static CoreServiceFactory getInstance() public static CoreServiceFactory getInstance()
{ {
return new DSpace().getServiceManager().getServiceByName("coreServiceFactory", CoreServiceFactory.class); return new DSpace().getServiceManager().getServiceByName("coreServiceFactory", CoreServiceFactory.class);

View File

@@ -9,6 +9,7 @@ package org.dspace.core.factory;
import org.dspace.core.service.LicenseService; import org.dspace.core.service.LicenseService;
import org.dspace.core.service.NewsService; import org.dspace.core.service.NewsService;
import org.dspace.core.service.PluginService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
/** /**
@@ -24,6 +25,9 @@ public class CoreServiceFactoryImpl extends CoreServiceFactory {
@Autowired(required = true) @Autowired(required = true)
private NewsService newsService; private NewsService newsService;
@Autowired(required = true)
private PluginService pluginService;
@Override @Override
public LicenseService getLicenseService() { public LicenseService getLicenseService() {
return licenseService; return licenseService;
@@ -33,4 +37,9 @@ public class CoreServiceFactoryImpl extends CoreServiceFactory {
public NewsService getNewsService() { public NewsService getNewsService() {
return newsService; return newsService;
} }
@Override
public PluginService getPluginService() {
return pluginService;
}
} }

View File

@@ -0,0 +1,84 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.core.service;
/**
* A service to manage "plugins". At this point, it's based off of the structure
* of the legacy PluginManager, until a better plugin definition is created.
*
* @author Tim Donohue
*/
public interface PluginService
{
/**
* Returns all of the names under which a named plugin implementing
* the interface can be requested (with getNamedPlugin()).
* The array is empty if there are no matches. Use this to populate
* a menu of plugins for interactive selection, or to document what
* the possible choices are.
* <p>
* NOTE: The names are NOT returned in any deterministic order.
*
* @param interfaceClass plugin interface for which to return names.
* @return an array of strings with every name; if none are
* available an empty array is returned.
*/
public String[] getAllPluginNames(Class interfaceClass);
/**
* Returns an instance of a plugin that implements the interface
* and is bound to a name matching name. If there is no
* matching plugin, it returns null. The names are matched by
* String.equals().
*
* @param interfaceClass the interface class of the plugin
* @param name under which the plugin implementation is configured.
* @return instance of plugin implementation, or null if there is no match or an error.
*/
public Object getNamedPlugin(Class interfaceClass, String name);
/**
* Returns whether a plugin exists which implements the specified interface
* and has a specified name. If a matching plugin is found to be configured,
* return true. If there is no matching plugin, return false.
*
* @param interfaceClass the interface class of the plugin
* @param name under which the plugin implementation is configured.
* @return true if plugin was found to be configured, false otherwise
*/
public boolean hasNamedPlugin(Class interfaceClass, String name);
/**
* Returns instances of all plugins that implement the interface,
* in an Array. Returns an empty array if no there are no
* matching plugins.
* <p>
* The order of the plugins in the array is the same as their class
* names in the configuration's value field.
*
* @param interfaceClass interface for which to find plugins.
* @return an array of plugin instances; if none are
* available an empty array is returned.
*/
public Object[] getPluginSequence(Class interfaceClass);
/**
* Returns an instance of the singleton (single) plugin implementing
* the given interface. There must be exactly one single plugin
* configured for this interface, otherwise the
* <code>PluginConfigurationError</code> is thrown.
* <p>
* Note that this is the only "get plugin" method which throws an
* exception. It is typically used at initialization time to set up
* a permanent part of the system so any failure is fatal.
*
* @param interfaceClass interface Class object
* @return instance of plugin
*/
public Object getSinglePlugin(Class interfaceClass);
}

View File

@@ -19,7 +19,7 @@ import org.apache.commons.cli.PosixParser;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.curate.factory.CurateServiceFactory; import org.dspace.curate.factory.CurateServiceFactory;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import org.dspace.eperson.factory.EPersonServiceFactory; import org.dspace.eperson.factory.EPersonServiceFactory;
@@ -232,7 +232,7 @@ public class CurationCli
else else
{ {
// process the task queue // process the task queue
TaskQueue queue = (TaskQueue)PluginManager.getSinglePlugin("curate", TaskQueue.class); TaskQueue queue = (TaskQueue) CoreServiceFactory.getInstance().getPluginService().getSinglePlugin(TaskQueue.class);
if (queue == null) if (queue == null)
{ {
System.out.println("No implementation configured for queue"); System.out.println("No implementation configured for queue");

View File

@@ -20,7 +20,7 @@ import org.dspace.content.service.CommunityService;
import org.dspace.content.service.ItemService; import org.dspace.content.service.ItemService;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService; import org.dspace.handle.service.HandleService;
@@ -280,7 +280,7 @@ public class Curator
{ {
if (taskQ == null) if (taskQ == null)
{ {
taskQ = (TaskQueue)PluginManager.getSinglePlugin("curate", TaskQueue.class); taskQ = (TaskQueue) CoreServiceFactory.getInstance().getPluginService().getSinglePlugin(TaskQueue.class);
} }
if (taskQ != null) if (taskQ != null)
{ {

View File

@@ -24,19 +24,19 @@ import javax.script.ScriptException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
/** /**
* TaskResolver takes a logical name of a curation task and attempts to deliver * TaskResolver takes a logical name of a curation task and attempts to deliver
* a suitable implementation object. Supported implementation types include: * a suitable implementation object. Supported implementation types include:
* (1) Classpath-local Java classes configured and loaded via PluginManager. * (1) Classpath-local Java classes configured and loaded via PluginService.
* (2) Local script-based tasks, viz. coded in any scripting language whose * (2) Local script-based tasks, viz. coded in any scripting language whose
* runtimes are accessible via the JSR-223 scripting API. This really amounts * runtimes are accessible via the JSR-223 scripting API. This really amounts
* to the family of dynamic JVM languages: JRuby, Jython, Groovy, Javascript, etc * to the family of dynamic JVM languages: JRuby, Jython, Groovy, Javascript, etc
* Note that the requisite jars and other resources for these languages must be * Note that the requisite jars and other resources for these languages must be
* installed in the DSpace instance for them to be used here. * installed in the DSpace instance for them to be used here.
* Further work may involve remote URL-loadable code, etc. * Further work may involve remote URL-loadable code, etc.
* *
* Scripted tasks are managed in a directory configured with the * Scripted tasks are managed in a directory configured with the
* dspace/config/modules/curate.cfg property "script.dir". A catalog of * dspace/config/modules/curate.cfg property "script.dir". A catalog of
* scripted tasks named 'task.catalog" is kept in this directory. * scripted tasks named 'task.catalog" is kept in this directory.
@@ -195,7 +195,7 @@ public class TaskResolver
*/ */
public ResolvedTask resolveTask(String taskName) public ResolvedTask resolveTask(String taskName)
{ {
CurationTask ctask = (CurationTask)PluginManager.getNamedPlugin("curate", CurationTask.class, taskName); CurationTask ctask = (CurationTask)CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(CurationTask.class, taskName);
if (ctask != null) if (ctask != null)
{ {
return new ResolvedTask(taskName, ctask); return new ResolvedTask(taskName, ctask);

View File

@@ -42,8 +42,9 @@ import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.Email; import org.dspace.core.Email;
import org.dspace.core.I18nUtil; import org.dspace.core.I18nUtil;
import org.dspace.core.PluginManager;
import org.dspace.core.Utils; import org.dspace.core.Utils;
import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.core.service.PluginService;
import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService; import org.dspace.handle.service.HandleService;
import org.dspace.harvest.factory.HarvestServiceFactory; import org.dspace.harvest.factory.HarvestServiceFactory;
@@ -88,7 +89,7 @@ public class OAIHarvester {
protected HandleService handleService; protected HandleService handleService;
protected HarvestedItemService harvestedItemService; protected HarvestedItemService harvestedItemService;
protected WorkspaceItemService workspaceItemService; protected WorkspaceItemService workspaceItemService;
protected PluginService pluginService;
// The collection this harvester instance is dealing with // The collection this harvester instance is dealing with
Collection targetCollection; Collection targetCollection;
@@ -126,6 +127,7 @@ public class OAIHarvester {
installItemService = ContentServiceFactory.getInstance().getInstallItemService(); installItemService = ContentServiceFactory.getInstance().getInstallItemService();
workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService(); workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
pluginService = CoreServiceFactory.getInstance().getPluginService();
if (dso.getType() != Constants.COLLECTION) if (dso.getType() != Constants.COLLECTION)
{ {
@@ -451,14 +453,14 @@ public class OAIHarvester {
// If we are only harvesting descriptive metadata, the record should already contain all we need // If we are only harvesting descriptive metadata, the record should already contain all we need
List<Element> descMD = record.getChild("metadata", OAI_NS).getChildren(); List<Element> descMD = record.getChild("metadata", OAI_NS).getChildren();
IngestionCrosswalk MDxwalk = (IngestionCrosswalk)PluginManager.getNamedPlugin(IngestionCrosswalk.class, this.metadataKey); IngestionCrosswalk MDxwalk = (IngestionCrosswalk)pluginService.getNamedPlugin(IngestionCrosswalk.class, this.metadataKey);
// Otherwise, obtain the ORE ReM and initiate the ORE crosswalk // Otherwise, obtain the ORE ReM and initiate the ORE crosswalk
IngestionCrosswalk ORExwalk = null; IngestionCrosswalk ORExwalk = null;
Element oreREM = null; Element oreREM = null;
if (harvestRow.getHarvestType() > 1) { if (harvestRow.getHarvestType() > 1) {
oreREM = getMDrecord(harvestRow.getOaiSource(), itemOaiID, OREPrefix).get(0); oreREM = getMDrecord(harvestRow.getOaiSource(), itemOaiID, OREPrefix).get(0);
ORExwalk = (IngestionCrosswalk)PluginManager.getNamedPlugin(IngestionCrosswalk.class, this.ORESerialKey); ORExwalk = (IngestionCrosswalk)pluginService.getNamedPlugin(IngestionCrosswalk.class, this.ORESerialKey);
} }
// Ignore authorization // Ignore authorization

View File

@@ -12,7 +12,7 @@ import org.apache.log4j.Logger;
import org.dspace.content.DSpaceObject; import org.dspace.content.DSpaceObject;
import org.dspace.content.crosswalk.DisseminationCrosswalk; import org.dspace.content.crosswalk.DisseminationCrosswalk;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.jdom.Element; import org.jdom.Element;
import org.jdom.output.XMLOutputter; import org.jdom.output.XMLOutputter;
@@ -93,7 +93,7 @@ public class DataCiteXMLCreator
if (null != this.xwalk) if (null != this.xwalk)
return; return;
this.xwalk = (DisseminationCrosswalk) PluginManager.getNamedPlugin( this.xwalk = (DisseminationCrosswalk) CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(
DisseminationCrosswalk.class, this.CROSSWALK_NAME); DisseminationCrosswalk.class, this.CROSSWALK_NAME);
if (this.xwalk == null) if (this.xwalk == null)

View File

@@ -33,7 +33,7 @@ import org.dspace.content.crosswalk.DisseminationCrosswalk;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.DSpaceObjectService; import org.dspace.content.service.DSpaceObjectService;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService; import org.dspace.handle.service.HandleService;
import org.dspace.identifier.DOI; import org.dspace.identifier.DOI;
@@ -198,7 +198,7 @@ implements DOIConnector
if (null != this.xwalk) if (null != this.xwalk)
return; return;
this.xwalk = (DisseminationCrosswalk) PluginManager.getNamedPlugin( this.xwalk = (DisseminationCrosswalk) CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(
DisseminationCrosswalk.class, this.CROSSWALK_NAME); DisseminationCrosswalk.class, this.CROSSWALK_NAME);
if (this.xwalk == null) if (this.xwalk == null)

View File

@@ -7,7 +7,7 @@
*/ */
package org.dspace.sort; package org.dspace.sort;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
/** /**
* Class implementing static helpers for anywhere that interacts with the sort columns * Class implementing static helpers for anywhere that interacts with the sort columns
@@ -43,7 +43,7 @@ public class OrderFormat
public static final String AUTHORITY = "authority"; public static final String AUTHORITY = "authority";
// Array of all available order delegates - avoids excessive calls to plugin manager // Array of all available order delegates - avoids excessive calls to plugin manager
private static final String[] delegates = PluginManager.getAllPluginNames(OrderFormatDelegate.class); private static final String[] delegates = CoreServiceFactory.getInstance().getPluginService().getAllPluginNames(OrderFormatDelegate.class);
private static final OrderFormatDelegate authorDelegate = new OrderFormatAuthor(); private static final OrderFormatDelegate authorDelegate = new OrderFormatAuthor();
private static final OrderFormatDelegate titleDelegate = new OrderFormatTitle(); private static final OrderFormatDelegate titleDelegate = new OrderFormatTitle();
@@ -116,7 +116,7 @@ public class OrderFormat
{ {
if (delegates[idx].equals(name)) if (delegates[idx].equals(name))
{ {
return (OrderFormatDelegate)PluginManager.getNamedPlugin(OrderFormatDelegate.class, name); return (OrderFormatDelegate)CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(OrderFormatDelegate.class, name);
} }
} }
} }

View File

@@ -1,9 +1,28 @@
# Configure authority control for Unit Testing # Configure authority control for Unit Testing (in DSpaceControlledVocabularyTest)
# (This overrides default, commented out settings in dspace.cfg) # (This overrides default, commented out settings in dspace.cfg)
plugin.selfnamed.org.dspace.content.authority.ChoiceAuthority = \ plugin.selfnamed.org.dspace.content.authority.ChoiceAuthority = \
org.dspace.content.authority.DCInputAuthority, \ org.dspace.content.authority.DCInputAuthority, \
org.dspace.content.authority.DSpaceControlledVocabulary org.dspace.content.authority.DSpaceControlledVocabulary
# Configure some more Plugins for PluginTest class
# NOTE: Plugins are just *interfaces*. So, here we are defining some plugins
# based on java.util.List interface and giving them names.
# (These are used by PluginTest)
plugin.named.java.util.List = \
java.util.ArrayList = MyArrayList, \
java.util.LinkedList = MyLinkedList, \
java.util.AttributeList = MyAttributeList
# Define a single Map plugin (used by PluginTest)
plugin.single.java.util.Map = java.util.HashMap
# Define a sequence of Collection plugins (used by PluginTest)
plugin.sequence.java.util.Collection = \
java.util.ArrayList, \
java.util.LinkedList, \
java.util.Stack, \
java.util.TreeSet
# Enable a test authority control on dc.language.iso field # Enable a test authority control on dc.language.iso field
choices.plugin.dc.language.iso = common_iso_languages choices.plugin.dc.language.iso = common_iso_languages
choices.presentation.dc.language.iso = select choices.presentation.dc.language.iso = select

View File

@@ -11,7 +11,7 @@ import java.io.IOException;
import org.dspace.content.Collection; import org.dspace.content.Collection;
import org.dspace.AbstractUnitTest; import org.dspace.AbstractUnitTest;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import org.junit.*; import org.junit.*;
@@ -86,7 +86,7 @@ public class DSpaceControlledVocabularyTest extends AbstractUnitTest
// (under /src/test/data/dspaceFolder/) and it should be auto-loaded // (under /src/test/data/dspaceFolder/) and it should be auto-loaded
// by test configs in /src/test/data/dspace.cfg.more // by test configs in /src/test/data/dspace.cfg.more
DSpaceControlledVocabulary instance = (DSpaceControlledVocabulary) DSpaceControlledVocabulary instance = (DSpaceControlledVocabulary)
PluginManager.getNamedPlugin(Class.forName(PLUGIN_INTERFACE), "farm"); CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(Class.forName(PLUGIN_INTERFACE), "farm");
assertNotNull(instance); assertNotNull(instance);
Choices result = instance.getMatches(field, text, collection, start, Choices result = instance.getMatches(field, text, collection, start,
limit, locale); limit, locale);

View File

@@ -24,6 +24,8 @@ import org.dspace.content.crosswalk.CrosswalkException;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.*; import org.dspace.content.service.*;
import org.dspace.core.*; import org.dspace.core.*;
import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.core.service.PluginService;
import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.CoreMatchers.nullValue;
@@ -61,6 +63,7 @@ public class ITDSpaceAIP extends AbstractUnitTest
protected WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService(); protected WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
protected InstallItemService installItemService = ContentServiceFactory.getInstance().getInstallItemService(); protected InstallItemService installItemService = ContentServiceFactory.getInstance().getInstallItemService();
protected HandleService handleService = HandleServiceFactory.getInstance().getHandleService(); protected HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
protected PluginService pluginService = CoreServiceFactory.getInstance().getPluginService();
/** InfoMap multiple value separator (see saveObjectInfo() and assertObject* methods) **/ /** InfoMap multiple value separator (see saveObjectInfo() and assertObject* methods) **/
private static final String valueseparator = "::"; private static final String valueseparator = "::";
@@ -794,7 +797,7 @@ public class ITDSpaceAIP extends AbstractUnitTest
throws PackageException, CrosswalkException, AuthorizeException, SQLException, IOException throws PackageException, CrosswalkException, AuthorizeException, SQLException, IOException
{ {
// Get a reference to the configured "AIP" package disseminator // Get a reference to the configured "AIP" package disseminator
PackageDisseminator dip = (PackageDisseminator) PluginManager PackageDisseminator dip = (PackageDisseminator) pluginService
.getNamedPlugin(PackageDisseminator.class, "AIP"); .getNamedPlugin(PackageDisseminator.class, "AIP");
if (dip == null) if (dip == null)
{ {
@@ -832,7 +835,7 @@ public class ITDSpaceAIP extends AbstractUnitTest
private void restoreFromAIP(DSpaceObject parent, File aipFile, PackageParameters pkgParams, boolean recursive) private void restoreFromAIP(DSpaceObject parent, File aipFile, PackageParameters pkgParams, boolean recursive)
throws PackageException, CrosswalkException, AuthorizeException, SQLException, IOException, WorkflowException { throws PackageException, CrosswalkException, AuthorizeException, SQLException, IOException, WorkflowException {
// Get a reference to the configured "AIP" package ingestor // Get a reference to the configured "AIP" package ingestor
PackageIngester sip = (PackageIngester) PluginManager PackageIngester sip = (PackageIngester) pluginService
.getNamedPlugin(PackageIngester.class, "AIP"); .getNamedPlugin(PackageIngester.class, "AIP");
if(sip == null) if(sip == null)
{ {
@@ -869,7 +872,7 @@ public class ITDSpaceAIP extends AbstractUnitTest
private void replaceFromAIP(DSpaceObject dso, File aipFile, PackageParameters pkgParams, boolean recursive) private void replaceFromAIP(DSpaceObject dso, File aipFile, PackageParameters pkgParams, boolean recursive)
throws PackageException, CrosswalkException, AuthorizeException, SQLException, IOException, WorkflowException { throws PackageException, CrosswalkException, AuthorizeException, SQLException, IOException, WorkflowException {
// Get a reference to the configured "AIP" package ingestor // Get a reference to the configured "AIP" package ingestor
PackageIngester sip = (PackageIngester) PluginManager PackageIngester sip = (PackageIngester) pluginService
.getNamedPlugin(PackageIngester.class, "AIP"); .getNamedPlugin(PackageIngester.class, "AIP");
if (sip == null) if (sip == null)
{ {

View File

@@ -0,0 +1,123 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.core;
import org.dspace.AbstractUnitTest;
import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.core.service.PluginService;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* Tests for Plugin Service.
* <P>
* NOTE: Plugin definitions/configurations which are used for this test are
* defined in /data/dspaceFolder/dspace.cfg.more (and are added into the
* final test dspace.cfg file)
*
* @author Tim Donohue
*/
public class PluginServiceTest extends AbstractUnitTest
{
// Get our enabled pluginService
private PluginService pluginService = CoreServiceFactory.getInstance().getPluginService();
/**
* Test of getAllPluginNames() method
*/
@Test
public void testGetAllPluginNames()
{
// Get all plugins defined from List interface (see dspace.cfg.more)
String[] names = pluginService.getAllPluginNames(java.util.List.class);
// There should be exactly 3 List plugins
assertEquals("Plugin count", 3, names.length);
}
/**
* Test of getNamedPlugin() method
*/
@Test
public void testGetNamedPlugin()
{
// Get the plugin named "MyArrayList"
Object plugin = pluginService.getNamedPlugin(java.util.List.class, "MyArrayList");
assertNotNull("Plugin exists", plugin);
assertTrue("Plugin is List", plugin instanceof java.util.List);
assertTrue("Plugin is ArrayList", plugin instanceof java.util.ArrayList);
// Get a plugin that doesn't exist
plugin = pluginService.getNamedPlugin(java.util.List.class, "MyOtherList");
assertNull("Plugin 2 doesn't exist", plugin);
// Test for one plugin that is "selfnamed"
// The DCInputAuthority plugin enabled in dspace.cfg.more reads all <form-value-pairs> in input-forms.xml
// and defines a self named plugin for each. So, we SHOULD have a "common_types" plugin.
plugin = pluginService.getNamedPlugin(org.dspace.content.authority.ChoiceAuthority.class, "common_types");
assertNotNull("Plugin 3 exists", plugin);
assertTrue("Plugin 3 is ChoiceAuthority", plugin instanceof org.dspace.content.authority.ChoiceAuthority);
assertTrue("Plugin 3 is DCInputAuthority", plugin instanceof org.dspace.content.authority.DCInputAuthority);
// NOTE: Additional "selfnamed" plugins are tested in DSpaceControlledVocabularyTest
}
/**
* Test of hasNamedPlugin() method
*/
@Test
public void testHasNamedPlugin()
{
// Assert there is a plugin named "MyLinkedList"
assertTrue(pluginService.hasNamedPlugin(java.util.List.class, "MyLinkedList"));
// Assert there is NOT a plugin named "MyList"
assertFalse(pluginService.hasNamedPlugin(java.util.List.class, "MyList"));
// Assert existence of a self named plugin
assertTrue(pluginService.hasNamedPlugin(org.dspace.content.authority.ChoiceAuthority.class, "common_types"));
}
/**
* Test of getSinglePlugin() method
*/
@Test
public void testGetSinglePlugin()
{
// There should be a SINGLE Map plugin (unnamed)
Object plugin = pluginService.getSinglePlugin(java.util.Map.class);
assertNotNull("Plugin exists", plugin);
assertTrue("Plugin is Map", plugin instanceof java.util.Map);
assertTrue("Plugin is HashMap", plugin instanceof java.util.HashMap);
}
/**
* Test of getSinglePlugin() method
*/
@Test
public void testGetPluginSequence()
{
// There should be a sequence of Collection plugins
Object[] plugins = pluginService.getPluginSequence(java.util.Collection.class);
// There should be four of them
assertEquals("Plugin count", 4, plugins.length);
// They should be in an EXACT ORDER (as defined in dspace.cfg.more)
assertTrue("Plugin 0 is ArrayList", plugins[0] instanceof java.util.ArrayList);
assertTrue("Plugin 1 is LinkedList", plugins[1] instanceof java.util.LinkedList);
assertTrue("Plugin 2 is Stack", plugins[2] instanceof java.util.Stack);
assertTrue("Plugin 3 is TreeSet", plugins[3] instanceof java.util.TreeSet);
}
}

View File

@@ -52,8 +52,8 @@ import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.I18nUtil; import org.dspace.core.I18nUtil;
import org.dspace.core.PluginManager;
import org.dspace.core.Utils; import org.dspace.core.Utils;
import org.dspace.core.factory.CoreServiceFactory;
/** /**
* <P> * <P>
@@ -212,7 +212,7 @@ public class ItemTag extends TagSupport
private static final Logger log = Logger.getLogger(ItemTag.class); private static final Logger log = Logger.getLogger(ItemTag.class);
private final transient StyleSelection styleSelection private final transient StyleSelection styleSelection
= (StyleSelection) PluginManager.getSinglePlugin(StyleSelection.class); = (StyleSelection) CoreServiceFactory.getInstance().getPluginService().getSinglePlugin(StyleSelection.class);
/** Hashmap of linked metadata to browse, from dspace.cfg */ /** Hashmap of linked metadata to browse, from dspace.cfg */
private static final Map<String,String> linkedMetadata; private static final Map<String,String> linkedMetadata;

View File

@@ -21,7 +21,7 @@ import org.dspace.app.webui.search.SearchRequestProcessor;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginConfigurationError; import org.dspace.core.PluginConfigurationError;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
/** /**
* Servlet for constructing/processing an advanced search form * Servlet for constructing/processing an advanced search form
@@ -38,7 +38,7 @@ public class AdvancedSearchServlet extends DSpaceServlet
{ {
try try
{ {
internalLogic = (SearchRequestProcessor) PluginManager internalLogic = (SearchRequestProcessor) CoreServiceFactory.getInstance().getPluginService()
.getSinglePlugin(SearchRequestProcessor.class); .getSinglePlugin(SearchRequestProcessor.class);
} }
catch (PluginConfigurationError e) catch (PluginConfigurationError e)

View File

@@ -41,7 +41,8 @@ import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.LogManager; import org.dspace.core.LogManager;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.core.service.PluginService;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group; import org.dspace.eperson.Group;
import org.dspace.eperson.factory.EPersonServiceFactory; import org.dspace.eperson.factory.EPersonServiceFactory;
@@ -77,11 +78,6 @@ public class HandleServlet extends DSpaceServlet
/** log4j category */ /** log4j category */
private static final Logger log = Logger.getLogger(HandleServlet.class); private static final Logger log = Logger.getLogger(HandleServlet.class);
/** For obtaining &lt;meta&gt; elements to put in the &lt;head&gt; */
private final transient DisseminationCrosswalk xHTMLHeadCrosswalk
= (DisseminationCrosswalk) PluginManager
.getNamedPlugin(DisseminationCrosswalk.class, "XHTML_HEAD_ITEM");
// services API // services API
private final transient HandleService handleService private final transient HandleService handleService
= HandleServiceFactory.getInstance().getHandleService(); = HandleServiceFactory.getInstance().getHandleService();
@@ -97,6 +93,14 @@ public class HandleServlet extends DSpaceServlet
private final transient CollectionService collectionService private final transient CollectionService collectionService
= ContentServiceFactory.getInstance().getCollectionService(); = ContentServiceFactory.getInstance().getCollectionService();
private final transient PluginService pluginService
= CoreServiceFactory.getInstance().getPluginService();
/** For obtaining &lt;meta&gt; elements to put in the &lt;head&gt; */
private final transient DisseminationCrosswalk xHTMLHeadCrosswalk
= (DisseminationCrosswalk) pluginService
.getNamedPlugin(DisseminationCrosswalk.class, "XHTML_HEAD_ITEM");
@Override @Override
protected void doDSGet(Context context, HttpServletRequest request, protected void doDSGet(Context context, HttpServletRequest request,
@@ -486,7 +490,7 @@ public class HandleServlet extends DSpaceServlet
{ {
try try
{ {
ItemHomeProcessor[] chp = (ItemHomeProcessor[]) PluginManager.getPluginSequence(ItemHomeProcessor.class); ItemHomeProcessor[] chp = (ItemHomeProcessor[]) pluginService.getPluginSequence(ItemHomeProcessor.class);
for (int i = 0; i < chp.length; i++) for (int i = 0; i < chp.length; i++)
{ {
chp[i].process(context, request, response, item); chp[i].process(context, request, response, item);
@@ -576,7 +580,7 @@ public class HandleServlet extends DSpaceServlet
{ {
try try
{ {
CommunityHomeProcessor[] chp = (CommunityHomeProcessor[]) PluginManager.getPluginSequence(CommunityHomeProcessor.class); CommunityHomeProcessor[] chp = (CommunityHomeProcessor[]) pluginService.getPluginSequence(CommunityHomeProcessor.class);
for (int i = 0; i < chp.length; i++) for (int i = 0; i < chp.length; i++)
{ {
chp[i].process(context, request, response, community); chp[i].process(context, request, response, community);
@@ -723,7 +727,7 @@ public class HandleServlet extends DSpaceServlet
{ {
try try
{ {
CollectionHomeProcessor[] chp = (CollectionHomeProcessor[]) PluginManager.getPluginSequence(CollectionHomeProcessor.class); CollectionHomeProcessor[] chp = (CollectionHomeProcessor[]) pluginService.getPluginSequence(CollectionHomeProcessor.class);
for (int i = 0; i < chp.length; i++) for (int i = 0; i < chp.length; i++)
{ {
chp[i].process(context, request, response, collection); chp[i].process(context, request, response, collection);

View File

@@ -19,7 +19,7 @@ import org.dspace.app.webui.json.JSONRequest;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.LogManager; import org.dspace.core.LogManager;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
public class JSONServlet extends DSpaceServlet public class JSONServlet extends DSpaceServlet
{ {
@@ -50,7 +50,7 @@ public class JSONServlet extends DSpaceServlet
pluginName = pluginName.substring(1); pluginName = pluginName.substring(1);
pluginName = pluginName.split("/")[0]; pluginName = pluginName.split("/")[0];
} }
JSONRequest jsonReq = (JSONRequest) PluginManager.getNamedPlugin(JSONRequest.class, JSONRequest jsonReq = (JSONRequest) CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(JSONRequest.class,
pluginName); pluginName);
if (jsonReq == null) if (jsonReq == null)

View File

@@ -21,7 +21,7 @@ import org.dspace.app.webui.search.SearchRequestProcessor;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginConfigurationError; import org.dspace.core.PluginConfigurationError;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
/** /**
* Servlet for producing OpenSearch-compliant search results, and the OpenSearch * Servlet for producing OpenSearch-compliant search results, and the OpenSearch
@@ -49,7 +49,7 @@ public class OpenSearchServlet extends DSpaceServlet
try try
{ {
internalLogic = (SearchRequestProcessor) PluginManager internalLogic = (SearchRequestProcessor) CoreServiceFactory.getInstance().getPluginService()
.getSinglePlugin(SearchRequestProcessor.class); .getSinglePlugin(SearchRequestProcessor.class);
} }
catch (PluginConfigurationError e) catch (PluginConfigurationError e)

View File

@@ -21,7 +21,7 @@ import org.dspace.app.webui.search.SearchRequestProcessor;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginConfigurationError; import org.dspace.core.PluginConfigurationError;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
/** /**
* Servlet for handling a simple search. * Servlet for handling a simple search.
@@ -38,7 +38,7 @@ public class SimpleSearchServlet extends DSpaceServlet
{ {
try try
{ {
internalLogic = (SearchRequestProcessor) PluginManager internalLogic = (SearchRequestProcessor) CoreServiceFactory.getInstance().getPluginService()
.getSinglePlugin(SearchRequestProcessor.class); .getSinglePlugin(SearchRequestProcessor.class);
} }
catch (PluginConfigurationError e) catch (PluginConfigurationError e)

View File

@@ -37,7 +37,7 @@ import org.dspace.content.service.ItemService;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginConfigurationError; import org.dspace.core.PluginConfigurationError;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
/** /**
* Servlet for editing and deleting (expunging) items * Servlet for editing and deleting (expunging) items
@@ -61,7 +61,7 @@ public class ItemMapServlet extends DSpaceServlet
{ {
try try
{ {
internalLogic = (SearchRequestProcessor) PluginManager internalLogic = (SearchRequestProcessor) CoreServiceFactory.getInstance().getPluginService()
.getSinglePlugin(SearchRequestProcessor.class); .getSinglePlugin(SearchRequestProcessor.class);
} }
catch (PluginConfigurationError e) catch (PluginConfigurationError e)

View File

@@ -8,10 +8,11 @@
package org.dspace.sword; package org.dspace.sword;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager;
import org.dspace.content.DSpaceObject; import org.dspace.content.DSpaceObject;
import org.dspace.content.Collection; import org.dspace.content.Collection;
import org.dspace.content.Item; import org.dspace.content.Item;
import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.core.service.PluginService;
import org.purl.sword.base.Deposit; import org.purl.sword.base.Deposit;
import org.purl.sword.base.SWORDErrorException; import org.purl.sword.base.SWORDErrorException;
@@ -44,11 +45,12 @@ public class SWORDIngesterFactory
DSpaceObject dso) DSpaceObject dso)
throws DSpaceSWORDException, SWORDErrorException throws DSpaceSWORDException, SWORDErrorException
{ {
PluginService pluginService = CoreServiceFactory.getInstance().getPluginService();
if (dso instanceof Collection) if (dso instanceof Collection)
{ {
SWORDIngester ingester = (SWORDIngester) PluginManager SWORDIngester ingester = (SWORDIngester) pluginService
.getNamedPlugin("sword-server", SWORDIngester.class, .getNamedPlugin(SWORDIngester.class, deposit.getPackaging());
deposit.getPackaging());
if (ingester == null) if (ingester == null)
{ {
throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT, throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT,
@@ -58,9 +60,8 @@ public class SWORDIngesterFactory
} }
else if (dso instanceof Item) else if (dso instanceof Item)
{ {
SWORDIngester ingester = (SWORDIngester) PluginManager SWORDIngester ingester = (SWORDIngester) pluginService
.getNamedPlugin("sword-server", SWORDIngester.class, .getNamedPlugin(SWORDIngester.class, "SimpleFileIngester");
"SimpleFileIngester");
if (ingester == null) if (ingester == null)
{ {
throw new DSpaceSWORDException( throw new DSpaceSWORDException(

View File

@@ -21,7 +21,7 @@ import org.dspace.content.packager.PackageParameters;
import org.dspace.content.service.ItemService; import org.dspace.content.service.ItemService;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService; import org.dspace.handle.service.HandleService;
@@ -73,7 +73,7 @@ public class SWORDMETSIngester implements SWORDIngester
} }
swordService.message("Using package manifest format: " + cfg); swordService.message("Using package manifest format: " + cfg);
PackageIngester pi = (PackageIngester) PluginManager PackageIngester pi = (PackageIngester) CoreServiceFactory.getInstance().getPluginService()
.getNamedPlugin(PackageIngester.class, cfg); .getNamedPlugin(PackageIngester.class, cfg);
swordService.message( swordService.message(
"Loaded package ingester: " + pi.getClass().getName()); "Loaded package ingester: " + pi.getClass().getName());

View File

@@ -16,7 +16,7 @@ import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.BitstreamFormatService; import org.dspace.content.service.BitstreamFormatService;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.LegacyPluginServiceImpl;
import org.jaxen.function.FalseFunction; import org.jaxen.function.FalseFunction;
import org.swordapp.server.SwordConfiguration; import org.swordapp.server.SwordConfiguration;
import org.swordapp.server.SwordError; import org.swordapp.server.SwordError;

View File

@@ -7,13 +7,13 @@
*/ */
package org.dspace.sword2; package org.dspace.sword2;
import org.dspace.core.PluginManager;
import org.swordapp.server.SwordError; import org.swordapp.server.SwordError;
import org.swordapp.server.SwordServerException; import org.swordapp.server.SwordServerException;
import org.swordapp.server.UriRegistry; import org.swordapp.server.UriRegistry;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.dspace.core.factory.CoreServiceFactory;
public class SwordDisseminatorFactory public class SwordDisseminatorFactory
{ {
@@ -36,9 +36,8 @@ public class SwordDisseminatorFactory
"_"); // clean up the string for the plugin manager "_"); // clean up the string for the plugin manager
format = format.replace("=", format = format.replace("=",
"_"); // clean up the string for the plugin manager "_"); // clean up the string for the plugin manager
disseminator = (SwordContentDisseminator) PluginManager disseminator = (SwordContentDisseminator) CoreServiceFactory.getInstance().getPluginService()
.getNamedPlugin("swordv2-server", .getNamedPlugin(SwordContentDisseminator.class, format);
SwordContentDisseminator.class, format);
if (disseminator == null) if (disseminator == null)
{ {
continue; continue;
@@ -72,9 +71,8 @@ public class SwordDisseminatorFactory
"_"); // clean up the string for the plugin manager "_"); // clean up the string for the plugin manager
acceptPackaging = acceptPackaging.replace("=", acceptPackaging = acceptPackaging.replace("=",
"_"); // clean up the string for the plugin manager "_"); // clean up the string for the plugin manager
disseminator = (SwordContentDisseminator) PluginManager disseminator = (SwordContentDisseminator) CoreServiceFactory.getInstance().getPluginService()
.getNamedPlugin("swordv2-server", .getNamedPlugin(SwordContentDisseminator.class,
SwordContentDisseminator.class,
acceptPackaging); acceptPackaging);
if (disseminator != null) if (disseminator != null)
{ {
@@ -132,9 +130,8 @@ public class SwordDisseminatorFactory
"_"); // clean up the string for the plugin manager "_"); // clean up the string for the plugin manager
format = format.replace("=", format = format.replace("=",
"_"); // clean up the string for the plugin manager "_"); // clean up the string for the plugin manager
disseminator = (SwordStatementDisseminator) PluginManager disseminator = (SwordStatementDisseminator) CoreServiceFactory.getInstance().getPluginService()
.getNamedPlugin("swordv2-server", .getNamedPlugin(SwordStatementDisseminator.class, format);
SwordStatementDisseminator.class, format);
if (disseminator != null) if (disseminator != null)
{ {
break; break;
@@ -155,9 +152,8 @@ public class SwordDisseminatorFactory
public static SwordEntryDisseminator getEntryInstance() public static SwordEntryDisseminator getEntryInstance()
throws DSpaceSwordException, SwordError throws DSpaceSwordException, SwordError
{ {
SwordEntryDisseminator disseminator = (SwordEntryDisseminator) PluginManager SwordEntryDisseminator disseminator = (SwordEntryDisseminator) CoreServiceFactory.getInstance().getPluginService()
.getSinglePlugin("swordv2-server", .getSinglePlugin(SwordEntryDisseminator.class);
SwordEntryDisseminator.class);
if (disseminator == null) if (disseminator == null)
{ {
throw new SwordError(DSpaceUriRegistry.REPOSITORY_ERROR, throw new SwordError(DSpaceUriRegistry.REPOSITORY_ERROR,

View File

@@ -8,9 +8,9 @@
package org.dspace.sword2; package org.dspace.sword2;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager;
import org.dspace.content.DSpaceObject; import org.dspace.content.DSpaceObject;
import org.dspace.content.Collection; import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.core.service.PluginService;
import org.swordapp.server.Deposit; import org.swordapp.server.Deposit;
import org.swordapp.server.SwordError; import org.swordapp.server.SwordError;
import org.swordapp.server.UriRegistry; import org.swordapp.server.UriRegistry;
@@ -44,10 +44,11 @@ public class SwordIngesterFactory
{ {
SwordContentIngester ingester = null; SwordContentIngester ingester = null;
PluginService pluginService = CoreServiceFactory.getInstance().getPluginService();
// first look to see if there's an intester for the content type // first look to see if there's an intester for the content type
ingester = (SwordContentIngester) PluginManager ingester = (SwordContentIngester) pluginService
.getNamedPlugin("swordv2-server", SwordContentIngester.class, .getNamedPlugin(SwordContentIngester.class, deposit.getMimeType());
deposit.getMimeType());
if (ingester != null) if (ingester != null)
{ {
return ingester; return ingester;
@@ -55,9 +56,8 @@ public class SwordIngesterFactory
// if no ingester, then // if no ingester, then
// look to see if there's an ingester for the package format // look to see if there's an ingester for the package format
ingester = (SwordContentIngester) PluginManager ingester = (SwordContentIngester) pluginService
.getNamedPlugin("swordv2-server", SwordContentIngester.class, .getNamedPlugin(SwordContentIngester.class, deposit.getPackaging());
deposit.getPackaging());
if (ingester == null) if (ingester == null)
{ {
throw new SwordError(UriRegistry.ERROR_CONTENT, throw new SwordError(UriRegistry.ERROR_CONTENT,
@@ -70,8 +70,8 @@ public class SwordIngesterFactory
Deposit deposit, DSpaceObject dso) Deposit deposit, DSpaceObject dso)
throws DSpaceSwordException, SwordError throws DSpaceSwordException, SwordError
{ {
SwordEntryIngester ingester = (SwordEntryIngester) PluginManager SwordEntryIngester ingester = (SwordEntryIngester) CoreServiceFactory.getInstance().getPluginService()
.getSinglePlugin("swordv2-server", SwordEntryIngester.class); .getSinglePlugin(SwordEntryIngester.class);
if (ingester == null) if (ingester == null)
{ {
throw new SwordError(UriRegistry.ERROR_CONTENT, throw new SwordError(UriRegistry.ERROR_CONTENT,

View File

@@ -23,7 +23,7 @@ import org.dspace.content.service.CollectionService;
import org.dspace.content.service.WorkspaceItemService; import org.dspace.content.service.WorkspaceItemService;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService; import org.dspace.handle.service.HandleService;
@@ -104,7 +104,7 @@ public class SwordMETSContentIngester extends AbstractSwordContentIngester
} }
verboseDescription.append("Using package manifest format: " + cfg); verboseDescription.append("Using package manifest format: " + cfg);
PackageIngester pi = (PackageIngester) PluginManager PackageIngester pi = (PackageIngester) CoreServiceFactory.getInstance().getPluginService()
.getNamedPlugin(PackageIngester.class, cfg); .getNamedPlugin(PackageIngester.class, cfg);
verboseDescription.append("Loaded package ingester: " + verboseDescription.append("Loaded package ingester: " +
pi.getClass().getName()); pi.getClass().getName());
@@ -236,7 +236,7 @@ public class SwordMETSContentIngester extends AbstractSwordContentIngester
} }
verboseDescription.append("Using package manifest format: " + cfg); verboseDescription.append("Using package manifest format: " + cfg);
PackageIngester pi = (PackageIngester) PluginManager PackageIngester pi = (PackageIngester) CoreServiceFactory.getInstance().getPluginService()
.getNamedPlugin(PackageIngester.class, cfg); .getNamedPlugin(PackageIngester.class, cfg);
verboseDescription.append("Loaded package ingester: " + verboseDescription.append("Loaded package ingester: " +
pi.getClass().getName()); pi.getClass().getName());

View File

@@ -7,7 +7,7 @@
*/ */
package org.dspace.sword2; package org.dspace.sword2;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.swordapp.server.SwordError; import org.swordapp.server.SwordError;
public class WorkflowManagerFactory public class WorkflowManagerFactory
@@ -15,8 +15,8 @@ public class WorkflowManagerFactory
public static WorkflowManager getInstance() public static WorkflowManager getInstance()
throws DSpaceSwordException, SwordError throws DSpaceSwordException, SwordError
{ {
WorkflowManager manager = (WorkflowManager) PluginManager WorkflowManager manager = (WorkflowManager) CoreServiceFactory.getInstance().getPluginService()
.getSinglePlugin("swordv2-server", WorkflowManager.class); .getSinglePlugin(WorkflowManager.class);
if (manager == null) if (manager == null)
{ {
throw new SwordError(DSpaceUriRegistry.REPOSITORY_ERROR, throw new SwordError(DSpaceUriRegistry.REPOSITORY_ERROR,

View File

@@ -28,7 +28,7 @@ import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.CollectionService; import org.dspace.content.service.CollectionService;
import org.dspace.content.service.ItemService; import org.dspace.content.service.ItemService;
import org.dspace.core.PluginConfigurationError; import org.dspace.core.PluginConfigurationError;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@@ -179,7 +179,7 @@ public class SearchItemForm extends AbstractDSpaceTransformer {
// Which search provider do we use? // Which search provider do we use?
SearchRequestProcessor processor = null; SearchRequestProcessor processor = null;
try { try {
processor = (SearchRequestProcessor) PluginManager processor = (SearchRequestProcessor) CoreServiceFactory.getInstance().getPluginService()
.getSinglePlugin(SearchRequestProcessor.class); .getSinglePlugin(SearchRequestProcessor.class);
} catch (PluginConfigurationError e) { } catch (PluginConfigurationError e) {
log.warn("{} not properly configured. Please configure the {} plugin. {}", log.warn("{} not properly configured. Please configure the {} plugin. {}",

View File

@@ -25,7 +25,6 @@ import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.http.HttpEnvironment; import org.apache.cocoon.environment.http.HttpEnvironment;
import org.apache.cocoon.util.HashUtil; import org.apache.cocoon.util.HashUtil;
import org.apache.excalibur.source.SourceValidity; import org.apache.excalibur.source.SourceValidity;
import org.dspace.app.sfx.SFXFileReaderServiceImpl;
import org.dspace.app.sfx.factory.SfxServiceFactory; import org.dspace.app.sfx.factory.SfxServiceFactory;
import org.dspace.app.sfx.service.SFXFileReaderService; import org.dspace.app.sfx.service.SFXFileReaderService;
import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer; import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
@@ -48,13 +47,13 @@ import org.dspace.app.util.GoogleMetadata;
import org.dspace.content.crosswalk.CrosswalkException; import org.dspace.content.crosswalk.CrosswalkException;
import org.dspace.content.crosswalk.DisseminationCrosswalk; import org.dspace.content.crosswalk.DisseminationCrosswalk;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.core.PluginManager;
import org.jdom.Element; import org.jdom.Element;
import org.jdom.Text; import org.jdom.Text;
import org.jdom.output.XMLOutputter; import org.jdom.output.XMLOutputter;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.app.xmlui.wing.element.Metadata; import org.dspace.app.xmlui.wing.element.Metadata;
import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.utils.DSpace; import org.dspace.utils.DSpace;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -291,7 +290,7 @@ public class ItemViewer extends AbstractDSpaceTransformer implements CacheablePr
// Metadata for <head> element // Metadata for <head> element
if (xHTMLHeadCrosswalk == null) if (xHTMLHeadCrosswalk == null)
{ {
xHTMLHeadCrosswalk = (DisseminationCrosswalk) PluginManager.getNamedPlugin( xHTMLHeadCrosswalk = (DisseminationCrosswalk) CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(
DisseminationCrosswalk.class, "XHTML_HEAD_ITEM"); DisseminationCrosswalk.class, "XHTML_HEAD_ITEM");
} }

View File

@@ -23,8 +23,7 @@ import org.dspace.content.crosswalk.DisseminationCrosswalk;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.ItemService; import org.dspace.content.service.ItemService;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.handle.HandleServiceImpl;
import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService; import org.dspace.handle.service.HandleService;
import org.jdom.Element; import org.jdom.Element;
@@ -63,7 +62,7 @@ public class DSpaceOREGenerator extends AbstractGenerator
// Instantiate and execute the ORE plugin // Instantiate and execute the ORE plugin
SAXOutputter out = new SAXOutputter(contentHandler); SAXOutputter out = new SAXOutputter(contentHandler);
DisseminationCrosswalk xwalk = (DisseminationCrosswalk)PluginManager.getNamedPlugin(DisseminationCrosswalk.class,"ore"); DisseminationCrosswalk xwalk = (DisseminationCrosswalk)CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(DisseminationCrosswalk.class,"ore");
Element ore = xwalk.disseminateElement(context, item); Element ore = xwalk.disseminateElement(context, item);
out.output(ore); out.output(ore);

View File

@@ -25,7 +25,7 @@ import org.dspace.content.Item;
import org.dspace.content.crosswalk.CrosswalkException; import org.dspace.content.crosswalk.CrosswalkException;
import org.dspace.content.crosswalk.DisseminationCrosswalk; import org.dspace.content.crosswalk.DisseminationCrosswalk;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.factory.CoreServiceFactory;
import org.xml.sax.ContentHandler; import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler; import org.xml.sax.ext.LexicalHandler;
@@ -562,7 +562,7 @@ public abstract class AbstractAdapter
public final DisseminationCrosswalk getDisseminationCrosswalk(String crosswalkName) throws WingException public final DisseminationCrosswalk getDisseminationCrosswalk(String crosswalkName) throws WingException
{ {
// FIXME add some caching here // FIXME add some caching here
DisseminationCrosswalk crosswalk = (DisseminationCrosswalk) PluginManager.getNamedPlugin(DisseminationCrosswalk.class, crosswalkName); DisseminationCrosswalk crosswalk = (DisseminationCrosswalk) CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(DisseminationCrosswalk.class, crosswalkName);
if (crosswalk == null) if (crosswalk == null)
{ {

View File

@@ -13,8 +13,6 @@ import org.dspace.content.DSpaceObject;
import org.dspace.content.packager.PackageDisseminator; import org.dspace.content.packager.PackageDisseminator;
import org.dspace.content.packager.PackageParameters; import org.dspace.content.packager.PackageParameters;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager;
import org.dspace.handle.HandleServiceImpl;
import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService; import org.dspace.handle.service.HandleService;
import org.dspace.sword.client.exceptions.HttpException; import org.dspace.sword.client.exceptions.HttpException;
@@ -34,6 +32,7 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.UUID; import java.util.UUID;
import org.dspace.core.factory.CoreServiceFactory;
/** /**
* User: Robin Taylor * User: Robin Taylor
@@ -168,7 +167,7 @@ public class DSpaceSwordClient
{ {
// Note - in the future we may need to allow for more than zipped up packages. // Note - in the future we may need to allow for more than zipped up packages.
PackageDisseminator dip = (PackageDisseminator) PluginManager PackageDisseminator dip = (PackageDisseminator) CoreServiceFactory.getInstance().getPluginService()
.getNamedPlugin(PackageDisseminator.class, packageFormat); .getNamedPlugin(PackageDisseminator.class, packageFormat);
if (dip == null) if (dip == null)