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  Map<Class<? extends PluginService>,InjectableService> consumedPluginServices
           
private  StaticResources 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  PluginContext pluginContext
           
private  List<String> pluginDependencies
           
private  PluginInfo pluginInfo
           
private  String pluginPackage
           
private  Properties pluginProperties
           
private  Topic pluginTopic
           
private  String pluginUri
           
private  String providedServiceInterface
           
private  ServiceRegistration registration
           
private  RestResources restResources
           
private  List<ServiceTracker> serviceTrackers
           
private  StaticResources staticResources
           
private  WebPublishingService webPublishingService
           
 
Constructor Summary
PluginImpl(PluginContext pluginContext)
           
 
Method Summary
(package private)  void activate()
          Activates this plugin and then posts the PLUGIN_ACTIVATED OSGi event.
private  void addService(Object service, Class serviceInterface)
           
private  void checkRequirementsForActivation()
          Checks if this plugin's requirements are met, and if so, activates this plugin.
private  void closeServiceTrackers()
           
private  void createCoreServiceTrackers()
           
private  List<InjectableService> createInjectableServices()
           
private  void createPluginServiceTrackers()
           
private  Topic createPluginTopic()
          Creates a Plugin topic in the DB.
private  boolean createPluginTopicIfNotExists()
           
private  ServiceTracker createServiceTracker(Class serviceInterface)
           
(package private)  void deactivate()
           
private  void deliverEvent(DeepaMehtaEvent event, Object... params)
          Checks weather this plugin is a listener for the given event, and if so, delivers the event to this plugin.
private  boolean dependenciesAvailable()
           
private  String entryPathToClassName(String entryPath)
           
private  Topic fetchPluginTopic()
           
private  URL getBundleEntry(String path)
           
(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)
           
(package private)  PluginContext getContext()
           
private  List<DeepaMehtaEvent> getEvents()
          Returns the events this plugin is listening to.
(package private)  PluginInfo getInfo()
           
(package private) static List<Field> getInjectableFields(Class<?> clazz)
           
(package private)  String getMigrationClassName(int migrationNr)
          Returns the migration class name for the given migration number.
private  Enumeration<String> getPluginPaths(String relativePath)
           
(package private)  PluginService getPluginService(Class<? extends PluginService> serviceInterface)
           
(package private)  Topic getPluginTopic()
           
(package private)  String getProvidedServiceInterface()
           
private  List<Class<?>> getProviderClasses()
           
private  List<Object> getRootResources()
           
 InputStream getStaticResource(String name)
          Accesses a static resource of the plugin.
private  String getStaticResourcesNamespace()
           
 String getUri()
           
 void handleEvent(Event event)
           
private  boolean hasDependency(String pluginUri)
           
 boolean hasStaticResource(String name)
          Checks if this plugin bundle contains a static resource with the given name.
private  void initializePlugin()
           
private  void installPluginInDB()
          Installs the plugin in the database.
private  void introduceAssociationTypesToPlugin()
           
private  void introduceTopicTypesToPlugin()
           
private  boolean isListenerInterface(Class interfaze)
          Returns true if the specified interface is an event 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 openServiceTrackers()
           
private  List<String> pluginDependencies()
           
private  String pluginName()
           
private  boolean pluginServicesAvailable()
           
private  void postPluginActivatedEvent()
           
private  String providedServiceInterface()
           
 void publishDirectory(String directoryPath, String uriNamespace, SecurityHandler securityHandler)
           
private  void publishRestResources()
          Publishes this plugin's REST resources (via Web Publishing service).
private  void publishStaticResources()
          Publishes this plugin's static resources (via Web Publishing service).
private  Properties readConfigFile()
           
private  void registerListeners()
           
private  void registerPluginActivatedEventListener()
           
private  void registerPluginService()
          Registers this plugin's OSGi service at the OSGi framework.
private  void removeService(Object service, Class 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 unpublishDirectoryResource()
           
private  void unpublishRestResources()
           
private  void unpublishStaticResources()
           
private  void unregisterListeners()
           
 
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

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

consumedPluginServices

private Map<Class<? extends PluginService>,InjectableService> consumedPluginServices

serviceTrackers

private List<ServiceTracker> serviceTrackers

providedServiceInterface

private String providedServiceInterface

registration

private ServiceRegistration registration

staticResources

private StaticResources staticResources

directoryResource

private StaticResources directoryResource

restResources

private RestResources restResources

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)

getUri

public String getUri()

getStaticResource

public InputStream getStaticResource(String name)
Description copied from interface: Plugin
Accesses a static resource of the plugin. A static resource is some data (images, audio, text, etc) that is contained in the plugin bundle (that is the jar file).

Specified by:
getStaticResource in interface Plugin
Parameters:
name - The resource name: a "/"-separated path name, relative to the plugin bundle's root directory. It may or may not begin with "/" (it makes no difference).
Returns:
An InputStream to read the static resource content.

hasStaticResource

public boolean hasStaticResource(String name)
Description copied from interface: Plugin
Checks if this plugin bundle contains a static resource with the given name.

Specified by:
hasStaticResource in interface Plugin
Parameters:
name - The resource name: a "/"-separated path name, relative to the plugin bundle's root directory. It may or may not begin with "/" (it makes no difference).

toString

public String toString()
Overrides:
toString in class Object

getInfo

PluginInfo getInfo()

getContext

PluginContext getContext()

getPluginTopic

Topic getPluginTopic()

getProvidedServiceInterface

String getProvidedServiceInterface()

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()

createInjectableServices

private List<InjectableService> createInjectableServices()

pluginServicesAvailable

private boolean pluginServicesAvailable()

getInjectableFields

static List<Field> getInjectableFields(Class<?> clazz)

getPluginService

PluginService getPluginService(Class<? extends PluginService> serviceInterface)

createServiceTracker

private ServiceTracker createServiceTracker(Class serviceInterface)

openServiceTrackers

private void openServiceTrackers()

closeServiceTrackers

private void closeServiceTrackers()

addService

private void addService(Object service,
                        Class serviceInterface)

removeService

private void removeService(Object service,
                           Class 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 "ConsumesService" annotation ### FIXDOC) 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.


activate

void activate()
Activates this plugin and then posts the PLUGIN_ACTIVATED OSGi event. Activation comprises: - install the plugin in the database (includes migrations, post-install hook, type introduction) - initialize the plugin - register the plugin's event listeners - register the plugin's OSGi service


deactivate

void deactivate()

installPluginInDB

private void installPluginInDB()
Installs the plugin in the database. This comprises: 1) create "Plugin" topic 2) run migrations 3) 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

private void initializePlugin()

registerListeners

private void registerListeners()

unregisterListeners

private void unregisterListeners()

getEvents

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


deliverEvent

private void deliverEvent(DeepaMehtaEvent event,
                          Object... params)
Checks weather this plugin is a listener for the given event, and if so, delivers the event to this plugin. Otherwise nothing is performed.

Called internally to deliver the INTRODUCE_TOPIC_TYPE and INTRODUCE_ASSOCIATION_TYPE events.


isListenerInterface

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


registerPluginService

private 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()

publishStaticResources

private void publishStaticResources()
Publishes this plugin's static resources (via Web Publishing service). If the plugin doesn't provide static resources nothing is performed.


unpublishStaticResources

private void unpublishStaticResources()

getStaticResourcesNamespace

private String getStaticResourcesNamespace()

getBundleEntry

private URL getBundleEntry(String path)

unpublishDirectoryResource

private void unpublishDirectoryResource()

publishRestResources

private void publishRestResources()
Publishes this plugin's REST resources (via Web Publishing service). If the plugin doesn't provide REST resources nothing is performed.


unpublishRestResources

private void unpublishRestResources()

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)

registerPluginActivatedEventListener

private void registerPluginActivatedEventListener()

postPluginActivatedEvent

private void postPluginActivatedEvent()

handleEvent

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

pluginName

private String pluginName()

scanPackage

private List<String> scanPackage(String relativePath)

getPluginPaths

private Enumeration<String> getPluginPaths(String relativePath)

entryPathToClassName

private String entryPathToClassName(String entryPath)


Copyright © 2015. All Rights Reserved.