de.deepamehta.core.impl
Class PluginImpl

Show UML class diagram
java.lang.Object
  extended by de.deepamehta.core.impl.PluginImpl
All Implemented Interfaces:
Plugin, EventHandler

public class PluginImpl
extends Object
implements Plugin, EventHandler


Field Summary
private  BundleContext bundleContext
           
private  List<ServiceTracker> coreServiceTrackers
           
private  WebResources directoryResource
           
private  EmbeddedService dms
           
private  EventAdmin eventService
           
private  Logger logger
           
private static String PLUGIN_ACTIVATED
           
private static String PLUGIN_CONFIG_FILE
           
private static String PLUGIN_DEFAULT_PACKAGE
           
private  Bundle pluginBundle
           
private  String pluginClass
           
private  PluginContext pluginContext
           
private  List<String> pluginDependencies
           
private  PluginInfo pluginInfo
           
private  String pluginName
           
private  String pluginPackage
           
private  Properties pluginProperties
           
private  Map<String,Object> pluginServices
           
private  List<ServiceTracker> pluginServiceTrackers
           
private  Topic pluginTopic
           
private  String pluginUri
           
private  ServiceRegistration registration
           
private  RestResource restResource
           
private  WebPublishingService webPublishingService
           
private  WebResources webResources
           
 
Constructor Summary
PluginImpl(PluginContext pluginContext)
           
 
Method Summary
private  void addService(Object service, String serviceInterface)
           
private  void checkRequirementsForActivation()
          Checks if this plugin's requirements are met, and if so, activates this plugin.
private  void closeCoreServiceTrackers()
           
private  void closePluginServiceTrackers()
           
private  void closeServiceTrackers(List<ServiceTracker> serviceTrackers)
           
private  String[] consumedServiceInterfaces()
           
private  void createCoreServiceTrackers()
           
private  void createPluginServiceTrackers()
           
private  Topic createPluginTopic()
          Creates a Plugin topic in the DB.
private  boolean createPluginTopicIfNotExists()
           
private  ServiceTracker createServiceTracker(Class serviceInterface)
           
private  ServiceTracker createServiceTracker(String serviceInterface)
           
private  boolean dependenciesAvailable()
           
private  String entryPathToClassName(String entryPath)
           
private  Topic fetchPluginTopic()
           
private  void fireEventLocally(CoreEvent event, Object... params)
          Fires an event locally, that is it is delivered only to this plugin itself.
(package private)  String getConfigProperty(String key)
          Returns a plugin configuration property (as read from file "plugin.properties") or null if no such property exists.
(package private)  String getConfigProperty(String key, String defaultValue)
           
private  List<CoreEvent> getEvents()
          Returns the events this plugin is listening to.
(package private)  PluginInfo getInfo()
           
(package private)  String getMigrationClassName(int migrationNr)
          Returns the migration class name for the given migration number.
private  Enumeration<String> getPluginPaths(String relativePath)
           
(package private)  Topic getPluginTopic()
           
private  List<Class<?>> getProviderClasses()
           
 InputStream getResourceAsStream(String name)
          Uses the plugin bundle's class loader to find a resource.
private  List<Object> getRootResources()
           
(package private)  String getUri()
           
private  String getWebResourcesNamespace()
           
 void handleEvent(Event event)
           
private  boolean hasDependency(String pluginUri)
           
(package private)  void initializePlugin()
           
(package private)  void installPluginInDB()
          Installs the plugin in the database.
private  void introduceAssociationTypesToPlugin()
           
private  void introduceTopicTypesToPlugin()
           
private  boolean isGenericPlugin()
           
private  boolean isListener(CoreEvent event)
          Returns true if this plugin is a listener for the specified event.
private  boolean isListenerInterface(Class interfaze)
          Returns true if the specified interface is a listener interface.
private  boolean isPluginActivated(String pluginUri)
           
(package private)  Class loadClass(String className)
          Uses the plugin bundle's class loader to load a class by name.
private  void openCoreServiceTrackers()
           
private  void openPluginServiceTrackers()
           
private  void openServiceTrackers(List<ServiceTracker> serviceTrackers)
           
private  List<String> pluginDependencies()
           
private  boolean pluginServicesAvailable()
           
(package private)  void postPluginActivatedEvent()
           
private  String providedServiceInterface()
           
 void publishDirectory(String directoryPath, String uriNamespace, SecurityHandler securityHandler)
           
private  Properties readConfigFile()
           
private  void registerEventListener()
           
(package private)  void registerListeners()
           
(package private)  void registerPluginService()
          Registers this plugin's OSGi service at the OSGi framework.
private  void registerRestResources()
          Registers this plugin's REST resources at the Web Publishing service.
private  void registerWebResources()
          Registers this plugin's web resources at the Web Publishing service.
private  void removeService(Object service, String serviceInterface)
           
private  List<String> scanPackage(String relativePath)
           
private  void setCoreService(EmbeddedService dms)
           
(package private)  void setMigrationNr(int migrationNr)
           
 void start()
           
 void stop()
           
 String toString()
           
private  void unregisterDirectoryResource()
           
(package private)  void unregisterListeners()
           
private  void unregisterRestResources()
           
private  void unregisterWebResources()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PLUGIN_DEFAULT_PACKAGE

private static final String PLUGIN_DEFAULT_PACKAGE
See Also:
Constant Field Values

PLUGIN_CONFIG_FILE

private static final String PLUGIN_CONFIG_FILE
See Also:
Constant Field Values

PLUGIN_ACTIVATED

private static final String PLUGIN_ACTIVATED
See Also:
Constant Field Values

pluginContext

private PluginContext pluginContext

bundleContext

private BundleContext bundleContext

pluginBundle

private Bundle pluginBundle

pluginUri

private String pluginUri

pluginName

private String pluginName

pluginClass

private String pluginClass

pluginProperties

private Properties pluginProperties

pluginPackage

private String pluginPackage

pluginInfo

private PluginInfo pluginInfo

pluginDependencies

private List<String> pluginDependencies

pluginTopic

private Topic pluginTopic

dms

private EmbeddedService dms

webPublishingService

private WebPublishingService webPublishingService

eventService

private EventAdmin eventService

pluginServices

private Map<String,Object> pluginServices

registration

private ServiceRegistration registration

webResources

private WebResources webResources

directoryResource

private WebResources directoryResource

restResource

private RestResource restResource

coreServiceTrackers

private List<ServiceTracker> coreServiceTrackers

pluginServiceTrackers

private List<ServiceTracker> pluginServiceTrackers

logger

private Logger logger
Constructor Detail

PluginImpl

public PluginImpl(PluginContext pluginContext)
Method Detail

start

public void start()

stop

public void stop()

publishDirectory

public void publishDirectory(String directoryPath,
                             String uriNamespace,
                             SecurityHandler securityHandler)

getResourceAsStream

public InputStream getResourceAsStream(String name)
                                throws IOException
Uses the plugin bundle's class loader to find a resource.

Specified by:
getResourceAsStream in interface Plugin
Returns:
A InputStream object or null if no resource with this name is found.
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object

getUri

String getUri()

getInfo

PluginInfo getInfo()

getPluginTopic

Topic getPluginTopic()

getConfigProperty

String getConfigProperty(String key)
Returns a plugin configuration property (as read from file "plugin.properties") or null if no such property exists.


getConfigProperty

String getConfigProperty(String key,
                         String defaultValue)

getMigrationClassName

String getMigrationClassName(int migrationNr)
Returns the migration class name for the given migration number.

Returns:
the fully qualified migration class name, or null if the migration package is unknown. This is the case if the plugin bundle contains no Plugin subclass and the "pluginPackage" config property is not set.

setMigrationNr

void setMigrationNr(int migrationNr)

loadClass

Class loadClass(String className)
Uses the plugin bundle's class loader to load a class by name.

Returns:
the class, or null if the class is not found.

readConfigFile

private Properties readConfigFile()

createCoreServiceTrackers

private void createCoreServiceTrackers()

createPluginServiceTrackers

private void createPluginServiceTrackers()

consumedServiceInterfaces

private String[] consumedServiceInterfaces()

pluginServicesAvailable

private boolean pluginServicesAvailable()

isGenericPlugin

private boolean isGenericPlugin()

createServiceTracker

private ServiceTracker createServiceTracker(Class serviceInterface)

createServiceTracker

private ServiceTracker createServiceTracker(String serviceInterface)

openCoreServiceTrackers

private void openCoreServiceTrackers()

closeCoreServiceTrackers

private void closeCoreServiceTrackers()

openPluginServiceTrackers

private void openPluginServiceTrackers()

closePluginServiceTrackers

private void closePluginServiceTrackers()

openServiceTrackers

private void openServiceTrackers(List<ServiceTracker> serviceTrackers)

closeServiceTrackers

private void closeServiceTrackers(List<ServiceTracker> serviceTrackers)

addService

private void addService(Object service,
                        String serviceInterface)

removeService

private void removeService(Object service,
                           String serviceInterface)

setCoreService

private void setCoreService(EmbeddedService dms)

checkRequirementsForActivation

private void checkRequirementsForActivation()
Checks if this plugin's requirements are met, and if so, activates this plugin. The requirements: - the 3 core services are available (DeepaMehtaService, WebPublishingService, EventAdmin). - the plugin services (according to the "consumedServiceInterfaces" config property) are available. - the plugin dependencies (according to the "importModels" config property) are active. Note: The Web Publishing service is not strictly required for activation, but we must ensure ALL_PLUGINS_ACTIVE is not fired before the Web Publishing service becomes available.


installPluginInDB

void installPluginInDB()
Installs the plugin in the database. This comprises: 1) create "Plugin" topic 2) run migrations 3) post installation (triggers the plugin's postInstall() hook) 4) type introduction (fires the CoreEvent.INTRODUCE_TOPIC_TYPE and CoreEvent.INTRODUCE_ASSOCIATION_TYPE events)


createPluginTopicIfNotExists

private boolean createPluginTopicIfNotExists()

createPluginTopic

private Topic createPluginTopic()
Creates a Plugin topic in the DB.

A Plugin topic represents an installed plugin and is used to track its version.


fetchPluginTopic

private Topic fetchPluginTopic()

introduceTopicTypesToPlugin

private void introduceTopicTypesToPlugin()

introduceAssociationTypesToPlugin

private void introduceAssociationTypesToPlugin()

initializePlugin

void initializePlugin()

registerListeners

void registerListeners()

unregisterListeners

void unregisterListeners()

getEvents

private List<CoreEvent> getEvents()
Returns the events this plugin is listening to.


fireEventLocally

private void fireEventLocally(CoreEvent event,
                              Object... params)
Fires an event locally, that is it is delivered only to this plugin itself. If this plugin is not a listener for that event nothing is performed.

Called internally to fire the INTRODUCE_TOPIC_TYPE event.


isListenerInterface

private boolean isListenerInterface(Class interfaze)
Returns true if the specified interface is a listener interface. A listener interface is a sub-interface of Listener.


isListener

private boolean isListener(CoreEvent event)
Returns true if this plugin is a listener for the specified event.


registerPluginService

void registerPluginService()
Registers this plugin's OSGi service at the OSGi framework. If the plugin doesn't provide an OSGi service nothing is performed.


providedServiceInterface

private String providedServiceInterface()

registerWebResources

private void registerWebResources()
Registers this plugin's web resources at the Web Publishing service. If the plugin doesn't provide web resources nothing is performed.


unregisterWebResources

private void unregisterWebResources()

getWebResourcesNamespace

private String getWebResourcesNamespace()

unregisterDirectoryResource

private void unregisterDirectoryResource()

registerRestResources

private void registerRestResources()
Registers this plugin's REST resources at the Web Publishing service. If the plugin doesn't provide REST resources nothing is performed.


unregisterRestResources

private void unregisterRestResources()

getRootResources

private List<Object> getRootResources()

getProviderClasses

private List<Class<?>> getProviderClasses()
                                   throws IOException
Throws:
IOException

pluginDependencies

private List<String> pluginDependencies()

hasDependency

private boolean hasDependency(String pluginUri)

dependenciesAvailable

private boolean dependenciesAvailable()

isPluginActivated

private boolean isPluginActivated(String pluginUri)

registerEventListener

private void registerEventListener()

postPluginActivatedEvent

void postPluginActivatedEvent()

handleEvent

public void handleEvent(Event event)
Specified by:
handleEvent in interface EventHandler

scanPackage

private List<String> scanPackage(String relativePath)

getPluginPaths

private Enumeration<String> getPluginPaths(String relativePath)

entryPathToClassName

private String entryPathToClassName(String entryPath)


Copyright © 2013. All Rights Reserved.