Initial commit

OSGi monitoring framework and two demonstrator applications
This commit is contained in:
anibal-portero 2013-08-07 14:17:04 +02:00
parent 9fe8e60815
commit 758b21f6dc
63 changed files with 5230 additions and 4993 deletions

22
.gitattributes vendored Normal file
View File

@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

215
.gitignore vendored Normal file
View File

@ -0,0 +1,215 @@
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
*.pubxml
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
#############
## Windows detritus
#############
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac crap
.DS_Store
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -1,28 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>osgi.bundle.monitoring.dem1</name> <name>osgi.bundle.monitoring.dem1</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand> <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name> <name>org.eclipse.jdt.core.javabuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name> <name>org.eclipse.pde.ManifestBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name> <name>org.eclipse.pde.SchemaBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.pde.PluginNature</nature> <nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
</natures> </natures>
</projectDescription> </projectDescription>

View File

@ -1,7 +1,7 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7 org.eclipse.jdt.core.compiler.source=1.7

View File

@ -1,4 +1,4 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
pluginProject.equinox=false pluginProject.equinox=false
pluginProject.extensions=false pluginProject.extensions=false
resolve.requirebundle=false resolve.requirebundle=false

View File

@ -1,53 +1,53 @@
package osgi.bundle.monitoring.dem1; package osgi.bundle.monitoring.dem1;
import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import osgi.bundle.monitoring.dem1.controller.ButtonListener; import osgi.bundle.monitoring.dem1.controller.ButtonListener;
import osgi.bundle.monitoring.dem1.controller.CheckBoxMenuListener; import osgi.bundle.monitoring.dem1.controller.CheckBoxMenuListener;
import osgi.bundle.monitoring.dem1.controller.MenuItemListener; import osgi.bundle.monitoring.dem1.controller.MenuItemListener;
import osgi.bundle.monitoring.dem1.model.Model; import osgi.bundle.monitoring.dem1.model.Model;
import osgi.bundle.monitoring.dem1.view.View; import osgi.bundle.monitoring.dem1.view.View;
public class Activator implements BundleActivator public class Activator implements BundleActivator
{ {
private static BundleContext context; private static BundleContext context;
private View view; private View view;
private Model model; private Model model;
static BundleContext getContext() static BundleContext getContext()
{ {
return context; return context;
} }
public void start(BundleContext bundleContext) throws Exception public void start(BundleContext bundleContext) throws Exception
{ {
Activator.context = bundleContext; Activator.context = bundleContext;
view = new View(); view = new View();
view.initUi(); view.initUi();
model = new Model(bundleContext); model = new Model(bundleContext);
ButtonListener buttonListener = new ButtonListener(model, view); ButtonListener buttonListener = new ButtonListener(model, view);
CheckBoxMenuListener checkBoxMenuListener = new CheckBoxMenuListener(model); CheckBoxMenuListener checkBoxMenuListener = new CheckBoxMenuListener(model);
MenuItemListener menuItemListener = new MenuItemListener(model, view); MenuItemListener menuItemListener = new MenuItemListener(model, view);
model.addObserver(view); model.addObserver(view);
view.completeUi(buttonListener, checkBoxMenuListener, menuItemListener); view.completeUi(buttonListener, checkBoxMenuListener, menuItemListener);
} }
public void stop(BundleContext bundleContext) throws Exception public void stop(BundleContext bundleContext) throws Exception
{ {
Activator.context = null; Activator.context = null;
model.unregisterServices(); model.unregisterServices();
view.close(); view.close();
} }
} }

View File

@ -1,120 +1,120 @@
package osgi.bundle.monitoring.dem1.controller; package osgi.bundle.monitoring.dem1.controller;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import javax.swing.JButton; import javax.swing.JButton;
import osgi.bundle.monitoring.dem1.model.Model; import osgi.bundle.monitoring.dem1.model.Model;
import osgi.bundle.monitoring.dem1.view.View; import osgi.bundle.monitoring.dem1.view.View;
public class ButtonListener implements MouseListener public class ButtonListener implements MouseListener
{ {
private Model model; private Model model;
private View view; private View view;
public ButtonListener(Model model, View view) public ButtonListener(Model model, View view)
{ {
this.model = model; this.model = model;
this.view = view; this.view = view;
} }
@Override @Override
public void mouseClicked(MouseEvent me) public void mouseClicked(MouseEvent me)
{ {
String button = ((JButton)me.getSource()).getText(); String button = ((JButton)me.getSource()).getText();
if(button.compareTo("Install") == 0) if(button.compareTo("Install") == 0)
{ {
String fileName = view.installDialog(); String fileName = view.installDialog();
if(fileName != null) if(fileName != null)
{ {
model.installBundle(fileName); model.installBundle(fileName);
} }
} }
else if(button.compareTo("Uninstall") == 0) else if(button.compareTo("Uninstall") == 0)
{ {
long id = view.getSelectedBundleId(); long id = view.getSelectedBundleId();
if(id >= 0) if(id >= 0)
{ {
model.uninstallBundle(id); model.uninstallBundle(id);
} }
} }
else if(button.compareTo("Update") == 0) else if(button.compareTo("Update") == 0)
{ {
long id = view.getSelectedBundleId(); long id = view.getSelectedBundleId();
if(id >= 0) if(id >= 0)
{ {
model.updateBundle(id); model.updateBundle(id);
} }
} }
else if(button.compareTo("Start") == 0) else if(button.compareTo("Start") == 0)
{ {
long id = view.getSelectedBundleId(); long id = view.getSelectedBundleId();
if(id >= 0) if(id >= 0)
{ {
model.startBundle(id); model.startBundle(id);
} }
} }
else if(button.compareTo("Stop") == 0) else if(button.compareTo("Stop") == 0)
{ {
long id = view.getSelectedBundleId(); long id = view.getSelectedBundleId();
if(id >= 0) if(id >= 0)
{ {
model.stopBundle(id); model.stopBundle(id);
} }
} }
else if(button.compareTo("Monitor") == 0) else if(button.compareTo("Monitor") == 0)
{ {
long id = view.getSelectedBundleId(); long id = view.getSelectedBundleId();
if(id >= 0) if(id >= 0)
{ {
model.setIdOpened(id); model.setIdOpened(id);
view.checkMonitoring(id); view.checkMonitoring(id);
} }
} }
else if(button.compareTo("Unmonitor") == 0) else if(button.compareTo("Unmonitor") == 0)
{ {
long id = view.getSelectedBundleId(); long id = view.getSelectedBundleId();
if(id >= 0) if(id >= 0)
{ {
model.setIdClosed(id); model.setIdClosed(id);
view.uncheckMonitoring(id); view.uncheckMonitoring(id);
} }
} }
} }
@Override @Override
public void mouseEntered(MouseEvent me) public void mouseEntered(MouseEvent me)
{ {
} }
@Override @Override
public void mouseExited(MouseEvent me) public void mouseExited(MouseEvent me)
{ {
} }
@Override @Override
public void mousePressed(MouseEvent me) public void mousePressed(MouseEvent me)
{ {
} }
@Override @Override
public void mouseReleased(MouseEvent me) public void mouseReleased(MouseEvent me)
{ {
} }
} }

View File

@ -1,139 +1,139 @@
package osgi.bundle.monitoring.dem1.controller; package osgi.bundle.monitoring.dem1.controller;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import javax.swing.JCheckBoxMenuItem; import javax.swing.JCheckBoxMenuItem;
import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleEvent;
import osgi.bundle.monitoring.dem1.model.Model; import osgi.bundle.monitoring.dem1.model.Model;
import osgi.framework.monitoring.event.RepositoryEvent; import osgi.framework.monitoring.event.RepositoryEvent;
import osgi.framework.monitoring.event.ManifestEvent; import osgi.framework.monitoring.event.ManifestEvent;
public class CheckBoxMenuListener implements ActionListener public class CheckBoxMenuListener implements ActionListener
{ {
private Model model; private Model model;
public CheckBoxMenuListener(Model model) public CheckBoxMenuListener(Model model)
{ {
this.model = model; this.model = model;
} }
public void changeMonitorState(boolean state, int index) public void changeMonitorState(boolean state, int index)
{ {
if(state == true) if(state == true)
{ {
model.setMonitorOn(index); model.setMonitorOn(index);
} }
else else
{ {
model.setMonitorOff(index); model.setMonitorOff(index);
} }
} }
private void changeTypeFilter(boolean state, int index, int type) private void changeTypeFilter(boolean state, int index, int type)
{ {
if(state == true) if(state == true)
{ {
model.setTypeOpened(index, type); model.setTypeOpened(index, type);
} }
else else
{ {
model.setTypeClosed(index, type); model.setTypeClosed(index, type);
} }
} }
@Override @Override
public void actionPerformed(ActionEvent ae) public void actionPerformed(ActionEvent ae)
{ {
JCheckBoxMenuItem cb = (JCheckBoxMenuItem)ae.getSource(); JCheckBoxMenuItem cb = (JCheckBoxMenuItem)ae.getSource();
String checkBox = cb.getText(); String checkBox = cb.getText();
if(checkBox.compareTo("Bundle repository") == 0) if(checkBox.compareTo("Bundle repository") == 0)
{ {
changeMonitorState(cb.getState(), 0); changeMonitorState(cb.getState(), 0);
} }
else if(checkBox.compareTo("Bundle state") == 0) else if(checkBox.compareTo("Bundle state") == 0)
{ {
changeMonitorState(cb.getState(), 1); changeMonitorState(cb.getState(), 1);
} }
else if(checkBox.compareTo("Bundle manifest") == 0) else if(checkBox.compareTo("Bundle manifest") == 0)
{ {
changeMonitorState(cb.getState(), 2); changeMonitorState(cb.getState(), 2);
} }
else if(checkBox.compareTo("Data field") == 0) else if(checkBox.compareTo("Data field") == 0)
{ {
changeMonitorState(cb.getState(), 3); changeMonitorState(cb.getState(), 3);
} }
else if(checkBox.compareTo("Create") == 0) else if(checkBox.compareTo("Create") == 0)
{ {
changeTypeFilter(cb.getState(), 0, RepositoryEvent.ENTRY_CREATE); changeTypeFilter(cb.getState(), 0, RepositoryEvent.ENTRY_CREATE);
} }
else if(checkBox.compareTo("Modify") == 0) else if(checkBox.compareTo("Modify") == 0)
{ {
changeTypeFilter(cb.getState(), 0, RepositoryEvent.ENTRY_MODIFY); changeTypeFilter(cb.getState(), 0, RepositoryEvent.ENTRY_MODIFY);
} }
else if(checkBox.compareTo("Delete") == 0) else if(checkBox.compareTo("Delete") == 0)
{ {
changeTypeFilter(cb.getState(), 0, RepositoryEvent.ENTRY_DELETE); changeTypeFilter(cb.getState(), 0, RepositoryEvent.ENTRY_DELETE);
} }
else if(checkBox.compareTo("Installed") == 0) else if(checkBox.compareTo("Installed") == 0)
{ {
changeTypeFilter(cb.getState(), 1, BundleEvent.INSTALLED); changeTypeFilter(cb.getState(), 1, BundleEvent.INSTALLED);
} }
else if(checkBox.compareTo("Lazy Activation") == 0) else if(checkBox.compareTo("Lazy Activation") == 0)
{ {
changeTypeFilter(cb.getState(), 1, BundleEvent.LAZY_ACTIVATION); changeTypeFilter(cb.getState(), 1, BundleEvent.LAZY_ACTIVATION);
} }
else if(checkBox.compareTo("Resolved") == 0) else if(checkBox.compareTo("Resolved") == 0)
{ {
changeTypeFilter(cb.getState(), 1, BundleEvent.RESOLVED); changeTypeFilter(cb.getState(), 1, BundleEvent.RESOLVED);
} }
else if(checkBox.compareTo("Started") == 0) else if(checkBox.compareTo("Started") == 0)
{ {
changeTypeFilter(cb.getState(), 1, BundleEvent.STARTED); changeTypeFilter(cb.getState(), 1, BundleEvent.STARTED);
} }
else if(checkBox.compareTo("Starting") == 0) else if(checkBox.compareTo("Starting") == 0)
{ {
changeTypeFilter(cb.getState(), 1, BundleEvent.STARTING); changeTypeFilter(cb.getState(), 1, BundleEvent.STARTING);
} }
else if(checkBox.compareTo("Stopped") == 0) else if(checkBox.compareTo("Stopped") == 0)
{ {
changeTypeFilter(cb.getState(), 1, BundleEvent.STOPPED); changeTypeFilter(cb.getState(), 1, BundleEvent.STOPPED);
} }
else if(checkBox.compareTo("Stopping") == 0) else if(checkBox.compareTo("Stopping") == 0)
{ {
changeTypeFilter(cb.getState(), 1, BundleEvent.STOPPING); changeTypeFilter(cb.getState(), 1, BundleEvent.STOPPING);
} }
else if(checkBox.compareTo("Uninstalled") == 0) else if(checkBox.compareTo("Uninstalled") == 0)
{ {
changeTypeFilter(cb.getState(), 1, BundleEvent.UNINSTALLED); changeTypeFilter(cb.getState(), 1, BundleEvent.UNINSTALLED);
} }
else if(checkBox.compareTo("Unresolved") == 0) else if(checkBox.compareTo("Unresolved") == 0)
{ {
changeTypeFilter(cb.getState(), 1, BundleEvent.UNRESOLVED); changeTypeFilter(cb.getState(), 1, BundleEvent.UNRESOLVED);
} }
else if(checkBox.compareTo("Updated") == 0) else if(checkBox.compareTo("Updated") == 0)
{ {
changeTypeFilter(cb.getState(), 1, BundleEvent.UPDATED); changeTypeFilter(cb.getState(), 1, BundleEvent.UPDATED);
} }
else if(checkBox.compareTo("Created") == 0) else if(checkBox.compareTo("Created") == 0)
{ {
changeTypeFilter(cb.getState(), 2, ManifestEvent.CREATED); changeTypeFilter(cb.getState(), 2, ManifestEvent.CREATED);
} }
else if(checkBox.compareTo("Modified") == 0) else if(checkBox.compareTo("Modified") == 0)
{ {
changeTypeFilter(cb.getState(), 2, ManifestEvent.MODIFIED); changeTypeFilter(cb.getState(), 2, ManifestEvent.MODIFIED);
} }
else if(checkBox.compareTo("Deleted") == 0) else if(checkBox.compareTo("Deleted") == 0)
{ {
changeTypeFilter(cb.getState(), 2, ManifestEvent.DELETED); changeTypeFilter(cb.getState(), 2, ManifestEvent.DELETED);
} }
else else
{ {
//fields //fields
} }
} }
} }

View File

@ -1,36 +1,36 @@
package osgi.bundle.monitoring.dem1.controller; package osgi.bundle.monitoring.dem1.controller;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import osgi.bundle.monitoring.dem1.model.Model; import osgi.bundle.monitoring.dem1.model.Model;
import osgi.bundle.monitoring.dem1.view.View; import osgi.bundle.monitoring.dem1.view.View;
public class MenuItemListener implements ActionListener public class MenuItemListener implements ActionListener
{ {
private Model model; private Model model;
private View view; private View view;
public MenuItemListener(Model model, View view) public MenuItemListener(Model model, View view)
{ {
this.model = model; this.model = model;
this.view = view; this.view = view;
} }
@Override @Override
public void actionPerformed(ActionEvent ae) public void actionPerformed(ActionEvent ae)
{ {
JMenuItem mi = (JMenuItem)ae.getSource(); JMenuItem mi = (JMenuItem)ae.getSource();
String menuItem = mi.getText(); String menuItem = mi.getText();
if(menuItem.compareTo("Add field") == 0) if(menuItem.compareTo("Add field") == 0)
{ {
model.addField(view.addFieldDialog()); model.addField(view.addFieldDialog());
} }
} }
} }

View File

@ -1,75 +1,75 @@
package osgi.bundle.monitoring.dem1.model; package osgi.bundle.monitoring.dem1.model;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException; import org.osgi.framework.BundleException;
/** /**
* Provides methods to manage bundles in the OSGi BundleContext * Provides methods to manage bundles in the OSGi BundleContext
* @author Anibal * @author Anibal
*/ */
public class ContextManager public class ContextManager
{ {
private BundleContext bundleContext; private BundleContext bundleContext;
public ContextManager(BundleContext bundleContext) public ContextManager(BundleContext bundleContext)
{ {
this.bundleContext = bundleContext; this.bundleContext = bundleContext;
} }
public void installBundle(String file) public void installBundle(String file)
{ {
try try
{ {
bundleContext.installBundle("file:"+file); bundleContext.installBundle("file:"+file);
} catch (BundleException e) } catch (BundleException e)
{ {
} }
} }
public void uninstallBundle(long id) public void uninstallBundle(long id)
{ {
try try
{ {
bundleContext.getBundle(id).uninstall(); bundleContext.getBundle(id).uninstall();
} catch (BundleException e) } catch (BundleException e)
{ {
} }
} }
public void updateBundle(long id) public void updateBundle(long id)
{ {
try try
{ {
bundleContext.getBundle(id).update(); bundleContext.getBundle(id).update();
} catch (BundleException e) } catch (BundleException e)
{ {
} }
} }
public void startBundle(long id) public void startBundle(long id)
{ {
try try
{ {
bundleContext.getBundle(id).start(); bundleContext.getBundle(id).start();
} catch (BundleException e) } catch (BundleException e)
{ {
} }
} }
public void stopBundle(long id) public void stopBundle(long id)
{ {
try try
{ {
bundleContext.getBundle(id).stop(); bundleContext.getBundle(id).stop();
} catch (BundleException e) } catch (BundleException e)
{ {
} }
} }
} }

View File

@ -1,26 +1,26 @@
package osgi.bundle.monitoring.dem1.model; package osgi.bundle.monitoring.dem1.model;
public class FieldEvent public class FieldEvent
{ {
private String className; private String className;
private String fieldName; private String fieldName;
public FieldEvent(String className, String fieldName) public FieldEvent(String className, String fieldName)
{ {
this.className = className; this.className = className;
this.fieldName = fieldName; this.fieldName = fieldName;
} }
public String getClassName() public String getClassName()
{ {
return className; return className;
} }
public String getFieldName() public String getFieldName()
{ {
return fieldName; return fieldName;
} }
} }

View File

@ -1,95 +1,95 @@
package osgi.bundle.monitoring.dem1.model; package osgi.bundle.monitoring.dem1.model;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import osgi.bundle.monitoring.dem1.view.View; import osgi.bundle.monitoring.dem1.view.View;
/** /**
* Provides an API with the actions the user can perform * Provides an API with the actions the user can perform
* @author Anibal * @author Anibal
*/ */
public class Model public class Model
{ {
private Monitor monitor; private Monitor monitor;
private ContextManager contextManager; private ContextManager contextManager;
public Model(BundleContext bundleContext) public Model(BundleContext bundleContext)
{ {
monitor = new Monitor(bundleContext); monitor = new Monitor(bundleContext);
contextManager = new ContextManager(bundleContext); contextManager = new ContextManager(bundleContext);
} }
public void installBundle(String fileName) public void installBundle(String fileName)
{ {
contextManager.installBundle(fileName); contextManager.installBundle(fileName);
} }
public void uninstallBundle(long id) public void uninstallBundle(long id)
{ {
contextManager.uninstallBundle(id); contextManager.uninstallBundle(id);
} }
public void updateBundle(long id) public void updateBundle(long id)
{ {
contextManager.updateBundle(id); contextManager.updateBundle(id);
} }
public void startBundle(long id) public void startBundle(long id)
{ {
contextManager.startBundle(id); contextManager.startBundle(id);
} }
public void stopBundle(long id) public void stopBundle(long id)
{ {
contextManager.stopBundle(id); contextManager.stopBundle(id);
} }
public void setIdOpened(long id) public void setIdOpened(long id)
{ {
monitor.setIdOpened(id); monitor.setIdOpened(id);
} }
public void setIdClosed(long id) public void setIdClosed(long id)
{ {
monitor.setIdClosed(id); monitor.setIdClosed(id);
} }
public void setMonitorOn(int index) public void setMonitorOn(int index)
{ {
monitor.setMonitorOn(index); monitor.setMonitorOn(index);
} }
public void setMonitorOff(int index) public void setMonitorOff(int index)
{ {
monitor.setMonitorOff(index); monitor.setMonitorOff(index);
} }
public void setTypeOpened(int index, int type) public void setTypeOpened(int index, int type)
{ {
monitor.setTypeOpened(index, type); monitor.setTypeOpened(index, type);
} }
public void setTypeClosed(int index, int type) public void setTypeClosed(int index, int type)
{ {
monitor.setTypeClosed(index, type); monitor.setTypeClosed(index, type);
} }
public void addObserver(View view) public void addObserver(View view)
{ {
monitor.addObserver(view); monitor.addObserver(view);
} }
public void addField(String s) public void addField(String s)
{ {
monitor.addField(s); monitor.addField(s);
} }
public void unregisterServices() public void unregisterServices()
{ {
monitor.uniregisterServices(); monitor.uniregisterServices();
} }
} }

View File

@ -1,177 +1,177 @@
package osgi.bundle.monitoring.dem1.model; package osgi.bundle.monitoring.dem1.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import osgi.framework.monitoring.event.DataFieldMonitor; import osgi.framework.monitoring.event.DataFieldMonitor;
import osgi.framework.monitoring.event.ManifestMonitor; import osgi.framework.monitoring.event.ManifestMonitor;
import osgi.framework.monitoring.event.RepositoryMonitor; import osgi.framework.monitoring.event.RepositoryMonitor;
import osgi.framework.monitoring.event.StateMonitor; import osgi.framework.monitoring.event.StateMonitor;
import osgi.framework.monitoring.event.EventMonitor; import osgi.framework.monitoring.event.EventMonitor;
import osgi.framework.monitoring.event.filter.IdFilterSet; import osgi.framework.monitoring.event.filter.IdFilterSet;
import osgi.framework.monitoring.event.filter.TypeFilterSet; import osgi.framework.monitoring.event.filter.TypeFilterSet;
/** /**
* Manages the different types of monitors: repository monitor, state monitor, * Manages the different types of monitors: repository monitor, state monitor,
* manifest monitor and data field monitor * manifest monitor and data field monitor
* @author Anibal * @author Anibal
*/ */
public class Monitor extends Observable implements Observer public class Monitor extends Observable implements Observer
{ {
// Contains all monitor objects // Contains all monitor objects
private ArrayList<EventMonitor> bundleMonitors; private ArrayList<EventMonitor> bundleMonitors;
// Contains all type filer for the various monitors // Contains all type filer for the various monitors
private ArrayList<TypeFilterSet> typeFilters; private ArrayList<TypeFilterSet> typeFilters;
private IdFilterSet idFilter; private IdFilterSet idFilter;
/** /**
* Constructor. Initialize the different monitors * Constructor. Initialize the different monitors
* @param bundleContext * @param bundleContext
*/ */
public Monitor(BundleContext bundleContext) public Monitor(BundleContext bundleContext)
{ {
bundleMonitors = new ArrayList<EventMonitor>(); bundleMonitors = new ArrayList<EventMonitor>();
typeFilters = new ArrayList<TypeFilterSet>(); typeFilters = new ArrayList<TypeFilterSet>();
idFilter = new IdFilterSet(); idFilter = new IdFilterSet();
// Positions in array 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor // Positions in array 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor
bundleMonitors.add(new RepositoryMonitor(bundleContext)); bundleMonitors.add(new RepositoryMonitor(bundleContext));
bundleMonitors.add(new StateMonitor(bundleContext)); bundleMonitors.add(new StateMonitor(bundleContext));
bundleMonitors.add(new ManifestMonitor(bundleContext)); bundleMonitors.add(new ManifestMonitor(bundleContext));
bundleMonitors.add(new DataFieldMonitor(bundleContext)); bundleMonitors.add(new DataFieldMonitor(bundleContext));
// Set the type filter sets to each monitor object // Set the type filter sets to each monitor object
for(int i = 0; i < bundleMonitors.size() - 1; i++) for(int i = 0; i < bundleMonitors.size() - 1; i++)
{ {
typeFilters.add(new TypeFilterSet()); typeFilters.add(new TypeFilterSet());
bundleMonitors.get(i).setTypeFilterSet(typeFilters.get(i)); bundleMonitors.get(i).setTypeFilterSet(typeFilters.get(i));
bundleMonitors.get(i).setBundleFilterSet(idFilter); bundleMonitors.get(i).setBundleFilterSet(idFilter);
} }
// Registers necessary services for DataFieldMonitor // Registers necessary services for DataFieldMonitor
((DataFieldMonitor)bundleMonitors.get(3)).registerWeavingService(); ((DataFieldMonitor)bundleMonitors.get(3)).registerWeavingService();
// StateMonitor activated by default // StateMonitor activated by default
setMonitorOn(1); setMonitorOn(1);
} }
/** /**
* Activate monitor object * Activate monitor object
* @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor * @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor
*/ */
public void setMonitorOn(int index) public void setMonitorOn(int index)
{ {
bundleMonitors.get(index).addObserver(this); bundleMonitors.get(index).addObserver(this);
} }
/** /**
* Deactivate monitor object * Deactivate monitor object
* @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor * @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor
*/ */
public void setMonitorOff(int index) public void setMonitorOff(int index)
{ {
bundleMonitors.get(index).deleteObservers(); bundleMonitors.get(index).deleteObservers();
} }
/** /**
* Open or close type in one TypeFilterSet * Open or close type in one TypeFilterSet
* @param typeFilterSet * @param typeFilterSet
* @param type type of event * @param type type of event
* @param open true: opened, false: closed * @param open true: opened, false: closed
*/ */
private void setType(TypeFilterSet typeFilterSet, int type, Boolean open) private void setType(TypeFilterSet typeFilterSet, int type, Boolean open)
{ {
typeFilterSet.addEntry(type, open); typeFilterSet.addEntry(type, open);
} }
/** /**
* Open type in one TypeFilterSet * Open type in one TypeFilterSet
* @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor * @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor
* @param type type of event * @param type type of event
*/ */
public void setTypeOpened(int index, int type) public void setTypeOpened(int index, int type)
{ {
setType(typeFilters.get(index), type, true); setType(typeFilters.get(index), type, true);
} }
/** /**
* Close type in one TypeFilterSet * Close type in one TypeFilterSet
* @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor * @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor
* @param type type of event * @param type type of event
*/ */
public void setTypeClosed(int index, int type) public void setTypeClosed(int index, int type)
{ {
setType(typeFilters.get(index), type, false); setType(typeFilters.get(index), type, false);
} }
/** /**
* Open or close bundle in one IdFilterSet * Open or close bundle in one IdFilterSet
* @param idBundle * @param idBundle
* @param mode true: opened, false: closed * @param mode true: opened, false: closed
*/ */
private void setId(long idBundle, boolean mode) private void setId(long idBundle, boolean mode)
{ {
idFilter.addEntry(idBundle, mode); idFilter.addEntry(idBundle, mode);
} }
/** /**
* Open bundle in one IdFilterSet * Open bundle in one IdFilterSet
* @param idBundle * @param idBundle
*/ */
public void setIdOpened(long idBundle) public void setIdOpened(long idBundle)
{ {
setId(idBundle, true); setId(idBundle, true);
} }
/** /**
* Close bundle in one IdFilterSet * Close bundle in one IdFilterSet
* @param idBundle * @param idBundle
*/ */
public void setIdClosed(long idBundle) public void setIdClosed(long idBundle)
{ {
setId(idBundle, false); setId(idBundle, false);
} }
/** /**
* Add a new field and class to be instrumented * Add a new field and class to be instrumented
* @param s format: "field/class" * @param s format: "field/class"
*/ */
public void addField(String s) public void addField(String s)
{ {
String[] ss = s.split("/"); String[] ss = s.split("/");
if(ss.length == 2) if(ss.length == 2)
{ {
if(((DataFieldMonitor)bundleMonitors.get(3)).addDataField(ss[0], ss[1])) if(((DataFieldMonitor)bundleMonitors.get(3)).addDataField(ss[0], ss[1]))
{ {
setChanged(); setChanged();
notifyObservers(new FieldEvent(ss[0], ss[1])); notifyObservers(new FieldEvent(ss[0], ss[1]));
} }
} }
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see java.util.Observer#update(java.util.Observable, java.lang.Object) * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
*/ */
@Override @Override
public void update(Observable obs, Object obj) public void update(Observable obs, Object obj)
{ {
setChanged(); setChanged();
notifyObservers(obj); notifyObservers(obj);
} }
/** /**
* Unregisters necessary services for DataFieldMonitor * Unregisters necessary services for DataFieldMonitor
*/ */
public void uniregisterServices() public void uniregisterServices()
{ {
((DataFieldMonitor)bundleMonitors.get(3)).unregisterWeavingService(); ((DataFieldMonitor)bundleMonitors.get(3)).unregisterWeavingService();
} }
} }

View File

@ -1,136 +1,136 @@
package osgi.bundle.monitoring.dem1.view; package osgi.bundle.monitoring.dem1.view;
import java.awt.Dimension; import java.awt.Dimension;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleEvent;
public class BundleTable extends JScrollPane public class BundleTable extends JScrollPane
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
JTable bundleTable; JTable bundleTable;
BundleTableModel tableModel; BundleTableModel tableModel;
public BundleTable(int x, int y) public BundleTable(int x, int y)
{ {
tableModel = new BundleTableModel(); tableModel = new BundleTableModel();
bundleTable = new JTable(tableModel); bundleTable = new JTable(tableModel);
bundleTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); bundleTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
bundleTable.getColumnModel().getColumn(0).setPreferredWidth(75); bundleTable.getColumnModel().getColumn(0).setPreferredWidth(75);
bundleTable.getColumnModel().getColumn(1).setPreferredWidth(75); bundleTable.getColumnModel().getColumn(1).setPreferredWidth(75);
bundleTable.getColumnModel().getColumn(2).setPreferredWidth(150); bundleTable.getColumnModel().getColumn(2).setPreferredWidth(150);
bundleTable.getColumnModel().getColumn(3).setPreferredWidth(300); bundleTable.getColumnModel().getColumn(3).setPreferredWidth(300);
setViewportView(bundleTable); setViewportView(bundleTable);
setPreferredSize(new Dimension(x, y)); setPreferredSize(new Dimension(x, y));
} }
private String getBundleState(int state) private String getBundleState(int state)
{ {
switch(state) switch(state)
{ {
case Bundle.UNINSTALLED: case Bundle.UNINSTALLED:
return "Uninstalled"; return "Uninstalled";
case Bundle.INSTALLED: case Bundle.INSTALLED:
return "Installed"; return "Installed";
case Bundle.RESOLVED: case Bundle.RESOLVED:
return "Resolved"; return "Resolved";
case Bundle.STARTING: case Bundle.STARTING:
return "Starting"; return "Starting";
case Bundle.STOPPING: case Bundle.STOPPING:
return "Stopping"; return "Stopping";
case Bundle.ACTIVE: case Bundle.ACTIVE:
return "Active"; return "Active";
} }
return "Unknown"; return "Unknown";
} }
private void addBundle(Bundle bundle) private void addBundle(Bundle bundle)
{ {
tableModel.insertRow(true, tableModel.insertRow(true,
bundle.getBundleId(), bundle.getBundleId(),
getBundleState(bundle.getState()), getBundleState(bundle.getState()),
bundle.getSymbolicName()); bundle.getSymbolicName());
} }
private void modifyBundle(Bundle bundle) private void modifyBundle(Bundle bundle)
{ {
tableModel.modifyState(bundle.getBundleId(), tableModel.modifyState(bundle.getBundleId(),
getBundleState(bundle.getState())); getBundleState(bundle.getState()));
} }
private void removeBundle(long id) private void removeBundle(long id)
{ {
tableModel.deleteRow(id); tableModel.deleteRow(id);
} }
public void changeBundle(BundleEvent be) public void changeBundle(BundleEvent be)
{ {
switch(be.getType()) switch(be.getType())
{ {
case BundleEvent.INSTALLED: case BundleEvent.INSTALLED:
addBundle(be.getBundle()); addBundle(be.getBundle());
break; break;
case BundleEvent.LAZY_ACTIVATION: case BundleEvent.LAZY_ACTIVATION:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
case BundleEvent.RESOLVED: case BundleEvent.RESOLVED:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
case BundleEvent.STARTED: case BundleEvent.STARTED:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
case BundleEvent.STARTING: case BundleEvent.STARTING:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
case BundleEvent.STOPPED: case BundleEvent.STOPPED:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
case BundleEvent.STOPPING: case BundleEvent.STOPPING:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
case BundleEvent.UNINSTALLED: case BundleEvent.UNINSTALLED:
removeBundle(be.getBundle().getBundleId()); removeBundle(be.getBundle().getBundleId());
break; break;
case BundleEvent.UNRESOLVED: case BundleEvent.UNRESOLVED:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
case BundleEvent.UPDATED: case BundleEvent.UPDATED:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
} }
} }
public long getSelectedBundleId() public long getSelectedBundleId()
{ {
int index = bundleTable.getSelectedRow(); int index = bundleTable.getSelectedRow();
if(index >= 0) if(index >= 0)
{ {
return tableModel.idOfRow(index); return tableModel.idOfRow(index);
} }
return -1; return -1;
} }
public void checkMonitor(long id) public void checkMonitor(long id)
{ {
tableModel.modifyMonitoring(id, true); tableModel.modifyMonitoring(id, true);
} }
public void uncheckMonitor(long id) public void uncheckMonitor(long id)
{ {
tableModel.modifyMonitoring(id, false); tableModel.modifyMonitoring(id, false);
} }
} }

View File

@ -1,143 +1,143 @@
package osgi.bundle.monitoring.dem1.view; package osgi.bundle.monitoring.dem1.view;
import java.util.ArrayList; import java.util.ArrayList;
import javax.swing.table.AbstractTableModel; import javax.swing.table.AbstractTableModel;
public class BundleTableModel extends AbstractTableModel public class BundleTableModel extends AbstractTableModel
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String[] columnNames = private String[] columnNames =
{"Monitoring", {"Monitoring",
"Id", "Id",
"State", "State",
"Symbolic Name" "Symbolic Name"
}; };
private ArrayList<ArrayList<Object>> data; private ArrayList<ArrayList<Object>> data;
public BundleTableModel() public BundleTableModel()
{ {
data = new ArrayList<ArrayList<Object>>(); data = new ArrayList<ArrayList<Object>>();
} }
@Override @Override
public int getColumnCount() public int getColumnCount()
{ {
return columnNames.length; return columnNames.length;
} }
@Override @Override
public int getRowCount() public int getRowCount()
{ {
return data.size(); return data.size();
} }
public String getColumnName(int col) public String getColumnName(int col)
{ {
return columnNames[col]; return columnNames[col];
} }
@Override @Override
public Object getValueAt(int row, int col) public Object getValueAt(int row, int col)
{ {
return data.get(row).get(col); return data.get(row).get(col);
} }
public Class<?> getColumnClass(int col) public Class<?> getColumnClass(int col)
{ {
return getValueAt(0, col).getClass(); return getValueAt(0, col).getClass();
} }
public void setValueAt(Object value, int row, int col) public void setValueAt(Object value, int row, int col)
{ {
if(row == data.size()) if(row == data.size())
{ {
data.add(new ArrayList<Object>()); data.add(new ArrayList<Object>());
data.get(row).add(value); data.get(row).add(value);
data.get(row).add(null); data.get(row).add(null);
data.get(row).add(null); data.get(row).add(null);
data.get(row).add(null); data.get(row).add(null);
fireTableDataChanged(); fireTableDataChanged();
} }
else if(row < data.size()) else if(row < data.size())
{ {
data.get(row).set(col, value); data.get(row).set(col, value);
fireTableCellUpdated(row, col); fireTableCellUpdated(row, col);
} }
} }
public void insertRow(Boolean monitoring, long id, String state, String name) public void insertRow(Boolean monitoring, long id, String state, String name)
{ {
int row = data.size(); int row = data.size();
setValueAt(monitoring, row, 0); setValueAt(monitoring, row, 0);
setValueAt(id, row, 1); setValueAt(id, row, 1);
setValueAt(state, row, 2); setValueAt(state, row, 2);
setValueAt(name, row, 3); setValueAt(name, row, 3);
} }
private int rowOfId(long id) private int rowOfId(long id)
{ {
int first = 0; int first = 0;
int last = data.size() - 1; int last = data.size() - 1;
int middle; int middle;
while((first <= last)) while((first <= last))
{ {
middle = (int)(first + ((last - first)/2)); middle = (int)(first + ((last - first)/2));
if(id < (long)data.get(middle).get(1)) if(id < (long)data.get(middle).get(1))
{ {
last = middle - 1; last = middle - 1;
} }
else if(id > (long)data.get(middle).get(1)) else if(id > (long)data.get(middle).get(1))
{ {
first = middle + 1; first = middle + 1;
} }
else else
{ {
return middle; return middle;
} }
} }
return -1; return -1;
} }
public void modifyState(long id, String state) public void modifyState(long id, String state)
{ {
int row = rowOfId(id); int row = rowOfId(id);
if(row > -1) if(row > -1)
{ {
setValueAt(state, row, 2); setValueAt(state, row, 2);
} }
} }
public void modifyMonitoring(long id, Boolean monitoring) public void modifyMonitoring(long id, Boolean monitoring)
{ {
int row = rowOfId(id); int row = rowOfId(id);
if(row > -1) if(row > -1)
{ {
setValueAt(monitoring, row, 0); setValueAt(monitoring, row, 0);
} }
} }
public void deleteRow(long id) public void deleteRow(long id)
{ {
int row = rowOfId(id); int row = rowOfId(id);
data.remove(row); data.remove(row);
fireTableDataChanged(); fireTableDataChanged();
} }
public long idOfRow(int row) public long idOfRow(int row)
{ {
return (long)data.get(row).get(1); return (long)data.get(row).get(1);
} }
} }

View File

@ -1,100 +1,100 @@
package osgi.bundle.monitoring.dem1.view; package osgi.bundle.monitoring.dem1.view;
import java.awt.Container; import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.JLabel; import javax.swing.JLabel;
import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleEvent;
import osgi.framework.monitoring.event.DataFieldEvent; import osgi.framework.monitoring.event.DataFieldEvent;
import osgi.framework.monitoring.event.RepositoryEvent; import osgi.framework.monitoring.event.RepositoryEvent;
import osgi.framework.monitoring.event.ManifestEvent; import osgi.framework.monitoring.event.ManifestEvent;
public class LeftPane extends Container public class LeftPane extends Container
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private LogList logList; private LogList logList;
private BundleTable bundleTable; private BundleTable bundleTable;
public LeftPane() public LeftPane()
{ {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
addFillerToYPane(); addFillerToYPane();
addLabelToPane("Installed bundles"); addLabelToPane("Installed bundles");
addBundleListToPane(600, 150); addBundleListToPane(600, 150);
addFillerToYPane(); addFillerToYPane();
addLabelToPane("Monitoring log"); addLabelToPane("Monitoring log");
addLogListToPane(600, 200); addLogListToPane(600, 200);
addFillerToYPane(); addFillerToYPane();
} }
private void addFillerToYPane() private void addFillerToYPane()
{ {
add(Box.createRigidArea(new Dimension(0, 25))); add(Box.createRigidArea(new Dimension(0, 25)));
} }
private void addLabelToPane(String text) private void addLabelToPane(String text)
{ {
JLabel label = new JLabel(text); JLabel label = new JLabel(text);
add(label); add(label);
} }
private void addLogListToPane(int x, int y) private void addLogListToPane(int x, int y)
{ {
logList = new LogList(x, y); logList = new LogList(x, y);
add(logList); add(logList);
} }
private void addBundleListToPane(int x, int y) private void addBundleListToPane(int x, int y)
{ {
bundleTable = new BundleTable(x, y); bundleTable = new BundleTable(x, y);
add(bundleTable); add(bundleTable);
} }
public void checkEvent(Object event) public void checkEvent(Object event)
{ {
String className = event.getClass().getName(); String className = event.getClass().getName();
if(className.compareTo(RepositoryEvent.class.getName()) == 0) if(className.compareTo(RepositoryEvent.class.getName()) == 0)
{ {
logList.logFileEvent((RepositoryEvent)event); logList.logFileEvent((RepositoryEvent)event);
} }
else if(className.compareTo(BundleEvent.class.getName()) == 0) else if(className.compareTo(BundleEvent.class.getName()) == 0)
{ {
bundleTable.changeBundle((BundleEvent)event); bundleTable.changeBundle((BundleEvent)event);
logList.logBundleEvent((BundleEvent)event); logList.logBundleEvent((BundleEvent)event);
} }
else if(className.compareTo(ManifestEvent.class.getName()) == 0) else if(className.compareTo(ManifestEvent.class.getName()) == 0)
{ {
logList.logManifestEvent((ManifestEvent)event); logList.logManifestEvent((ManifestEvent)event);
} }
else if(className.compareTo(DataFieldEvent.class.getName()) == 0) else if(className.compareTo(DataFieldEvent.class.getName()) == 0)
{ {
logList.logDataFieldEvent((DataFieldEvent)event); logList.logDataFieldEvent((DataFieldEvent)event);
} }
} }
public long getSelectedBundleId() public long getSelectedBundleId()
{ {
return bundleTable.getSelectedBundleId(); return bundleTable.getSelectedBundleId();
} }
public void checkMonitor(long id) public void checkMonitor(long id)
{ {
bundleTable.checkMonitor(id); bundleTable.checkMonitor(id);
} }
public void uncheckMonitor(long id) public void uncheckMonitor(long id)
{ {
bundleTable.uncheckMonitor(id); bundleTable.uncheckMonitor(id);
} }
} }

View File

@ -1,157 +1,157 @@
package osgi.bundle.monitoring.dem1.view; package osgi.bundle.monitoring.dem1.view;
import java.awt.Dimension; import java.awt.Dimension;
import javax.swing.DefaultListModel; import javax.swing.DefaultListModel;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleEvent;
import osgi.framework.monitoring.event.DataFieldEvent; import osgi.framework.monitoring.event.DataFieldEvent;
import osgi.framework.monitoring.event.RepositoryEvent; import osgi.framework.monitoring.event.RepositoryEvent;
import osgi.framework.monitoring.event.ManifestEvent; import osgi.framework.monitoring.event.ManifestEvent;
public class LogList extends JScrollPane public class LogList extends JScrollPane
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private JList<String> listLog; private JList<String> listLog;
private DefaultListModel<String> listModelLog; private DefaultListModel<String> listModelLog;
public LogList(int x, int y) public LogList(int x, int y)
{ {
listLog = new JList<String>(); listLog = new JList<String>();
listModelLog = new DefaultListModel<String>(); listModelLog = new DefaultListModel<String>();
listLog.setModel(listModelLog); listLog.setModel(listModelLog);
setViewportView(listLog); setViewportView(listLog);
setPreferredSize(new Dimension(x, y)); setPreferredSize(new Dimension(x, y));
listLog.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listLog.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
} }
public void insertList(String message) public void insertList(String message)
{ {
listModelLog.addElement(message); listModelLog.addElement(message);
} }
public void insertListLog(String message) public void insertListLog(String message)
{ {
try try
{ {
Thread.sleep(10); Thread.sleep(10);
} }
catch (InterruptedException e) catch (InterruptedException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
insertList(message); insertList(message);
} }
public String getFileEvent(int type) public String getFileEvent(int type)
{ {
switch(type) switch(type)
{ {
case RepositoryEvent.ENTRY_CREATE: case RepositoryEvent.ENTRY_CREATE:
return "Created"; return "Created";
case RepositoryEvent.ENTRY_MODIFY: case RepositoryEvent.ENTRY_MODIFY:
return "Modified"; return "Modified";
case RepositoryEvent.ENTRY_DELETE: case RepositoryEvent.ENTRY_DELETE:
return "Deleted"; return "Deleted";
} }
return "Unknown"; return "Unknown";
} }
private String getBundleEvent(int type) private String getBundleEvent(int type)
{ {
switch(type) switch(type)
{ {
case BundleEvent.INSTALLED: case BundleEvent.INSTALLED:
return "Installed"; return "Installed";
case BundleEvent.LAZY_ACTIVATION: case BundleEvent.LAZY_ACTIVATION:
return "Lazily activated"; return "Lazily activated";
case BundleEvent.RESOLVED: case BundleEvent.RESOLVED:
return "Resolved"; return "Resolved";
case BundleEvent.STARTED: case BundleEvent.STARTED:
return "Started"; return "Started";
case BundleEvent.STARTING: case BundleEvent.STARTING:
return "Activated"; return "Activated";
case BundleEvent.STOPPED: case BundleEvent.STOPPED:
return "Stopped"; return "Stopped";
case BundleEvent.STOPPING: case BundleEvent.STOPPING:
return "Deactivated"; return "Deactivated";
case BundleEvent.UNINSTALLED: case BundleEvent.UNINSTALLED:
return "Uninstalled"; return "Uninstalled";
case BundleEvent.UNRESOLVED: case BundleEvent.UNRESOLVED:
return "Unresolved"; return "Unresolved";
case BundleEvent.UPDATED: case BundleEvent.UPDATED:
return "Updated"; return "Updated";
} }
return "Unknown"; return "Unknown";
} }
private String getManifestEvent(int type) private String getManifestEvent(int type)
{ {
switch(type) switch(type)
{ {
case ManifestEvent.CREATED: case ManifestEvent.CREATED:
return "Created"; return "Created";
case ManifestEvent.MODIFIED: case ManifestEvent.MODIFIED:
return "Modified"; return "Modified";
case ManifestEvent.DELETED: case ManifestEvent.DELETED:
return "Deleted"; return "Deleted";
} }
return "Unknown"; return "Unknown";
} }
public void logFileEvent(RepositoryEvent fe) public void logFileEvent(RepositoryEvent fe)
{ {
String message = "Bundle repository: bundle "+ String message = "Bundle repository: bundle "+
fe.getBundle().getBundleId()+ fe.getBundle().getBundleId()+
" file "+ " file "+
getFileEvent(fe.getType()); getFileEvent(fe.getType());
insertListLog(message); insertListLog(message);
} }
public void logBundleEvent(BundleEvent be) public void logBundleEvent(BundleEvent be)
{ {
String message = "Bundle state: bundle "+ String message = "Bundle state: bundle "+
be.getBundle().getBundleId()+ be.getBundle().getBundleId()+
" "+ " "+
getBundleEvent(be.getType()); getBundleEvent(be.getType());
insertListLog(message); insertListLog(message);
} }
public void logManifestEvent(ManifestEvent me) public void logManifestEvent(ManifestEvent me)
{ {
String message = "Bundle manifest: bundle "+ String message = "Bundle manifest: bundle "+
me.getBundle().getBundleId()+ me.getBundle().getBundleId()+
" manifest modified: "+ " manifest modified: "+
me.getHeader()+ me.getHeader()+
" "+ " "+
getManifestEvent(me.getType()); getManifestEvent(me.getType());
insertListLog(message); insertListLog(message);
} }
public void logDataFieldEvent(DataFieldEvent dfe) public void logDataFieldEvent(DataFieldEvent dfe)
{ {
String message = "Data field: "+ String message = "Data field: "+
dfe.getFieldName()+ dfe.getFieldName()+
" in "+ " in "+
dfe.getClassName()+ dfe.getClassName()+
" has changed to "+ " has changed to "+
dfe.getField(); dfe.getField();
insertListLog(message); insertListLog(message);
} }
} }

View File

@ -1,147 +1,147 @@
package osgi.bundle.monitoring.dem1.view; package osgi.bundle.monitoring.dem1.view;
import java.util.ArrayList; import java.util.ArrayList;
import javax.swing.JCheckBoxMenuItem; import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu; import javax.swing.JMenu;
import javax.swing.JMenuBar; import javax.swing.JMenuBar;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import osgi.bundle.monitoring.dem1.controller.CheckBoxMenuListener; import osgi.bundle.monitoring.dem1.controller.CheckBoxMenuListener;
import osgi.bundle.monitoring.dem1.controller.MenuItemListener; import osgi.bundle.monitoring.dem1.controller.MenuItemListener;
public class Menu extends JMenuBar public class Menu extends JMenuBar
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private ArrayList<JCheckBoxMenuItem> checkBoxesMonitor; private ArrayList<JCheckBoxMenuItem> checkBoxesMonitor;
private ArrayList<JCheckBoxMenuItem> checkBoxesRepFilter; private ArrayList<JCheckBoxMenuItem> checkBoxesRepFilter;
private ArrayList<JCheckBoxMenuItem> checkBoxesStatFilter; private ArrayList<JCheckBoxMenuItem> checkBoxesStatFilter;
private ArrayList<JCheckBoxMenuItem> checkBoxesManFilter; private ArrayList<JCheckBoxMenuItem> checkBoxesManFilter;
private JMenuItem addInstItem; private JMenuItem addInstItem;
private JMenu instrumentationMenu; private JMenu instrumentationMenu;
public Menu() public Menu()
{ {
checkBoxesMonitor = new ArrayList<JCheckBoxMenuItem>(); checkBoxesMonitor = new ArrayList<JCheckBoxMenuItem>();
checkBoxesRepFilter = new ArrayList<JCheckBoxMenuItem>(); checkBoxesRepFilter = new ArrayList<JCheckBoxMenuItem>();
checkBoxesStatFilter = new ArrayList<JCheckBoxMenuItem>(); checkBoxesStatFilter = new ArrayList<JCheckBoxMenuItem>();
checkBoxesManFilter = new ArrayList<JCheckBoxMenuItem>(); checkBoxesManFilter = new ArrayList<JCheckBoxMenuItem>();
JMenu monitorMenu, filterMenu, repSubMenu, statSubMenu, manSubMenu; JMenu monitorMenu, filterMenu, repSubMenu, statSubMenu, manSubMenu;
monitorMenu = new JMenu("Monitors"); monitorMenu = new JMenu("Monitors");
checkBoxesMonitor.add(new JCheckBoxMenuItem("Bundle repository")); checkBoxesMonitor.add(new JCheckBoxMenuItem("Bundle repository"));
checkBoxesMonitor.add(new JCheckBoxMenuItem("Bundle state")); checkBoxesMonitor.add(new JCheckBoxMenuItem("Bundle state"));
checkBoxesMonitor.add(new JCheckBoxMenuItem("Bundle manifest")); checkBoxesMonitor.add(new JCheckBoxMenuItem("Bundle manifest"));
checkBoxesMonitor.add(new JCheckBoxMenuItem("Data field")); checkBoxesMonitor.add(new JCheckBoxMenuItem("Data field"));
for(JCheckBoxMenuItem checkBox: checkBoxesMonitor) for(JCheckBoxMenuItem checkBox: checkBoxesMonitor)
{ {
monitorMenu.add(checkBox); monitorMenu.add(checkBox);
} }
checkBoxesMonitor.get(1).setState(true); checkBoxesMonitor.get(1).setState(true);
filterMenu = new JMenu("Filters"); filterMenu = new JMenu("Filters");
repSubMenu = new JMenu("Bundle repository"); repSubMenu = new JMenu("Bundle repository");
statSubMenu = new JMenu("Bundle state"); statSubMenu = new JMenu("Bundle state");
manSubMenu = new JMenu("Bundle manifest"); manSubMenu = new JMenu("Bundle manifest");
checkBoxesRepFilter.add(new JCheckBoxMenuItem("Create")); checkBoxesRepFilter.add(new JCheckBoxMenuItem("Create"));
checkBoxesRepFilter.add(new JCheckBoxMenuItem("Modify")); checkBoxesRepFilter.add(new JCheckBoxMenuItem("Modify"));
checkBoxesRepFilter.add(new JCheckBoxMenuItem("Delete")); checkBoxesRepFilter.add(new JCheckBoxMenuItem("Delete"));
for(JCheckBoxMenuItem checkBox: checkBoxesRepFilter) for(JCheckBoxMenuItem checkBox: checkBoxesRepFilter)
{ {
repSubMenu.add(checkBox); repSubMenu.add(checkBox);
checkBox.setState(true); checkBox.setState(true);
} }
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Installed")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Installed"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Lazy Activation")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Lazy Activation"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Resolved")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Resolved"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Started")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Started"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Starting")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Starting"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Stopped")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Stopped"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Stopping")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Stopping"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Uninstalled")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Uninstalled"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Unresolved")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Unresolved"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Updated")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Updated"));
for(JCheckBoxMenuItem checkBox: checkBoxesStatFilter) for(JCheckBoxMenuItem checkBox: checkBoxesStatFilter)
{ {
statSubMenu.add(checkBox); statSubMenu.add(checkBox);
checkBox.setState(true); checkBox.setState(true);
} }
checkBoxesManFilter.add(new JCheckBoxMenuItem("Created")); checkBoxesManFilter.add(new JCheckBoxMenuItem("Created"));
checkBoxesManFilter.add(new JCheckBoxMenuItem("Modified")); checkBoxesManFilter.add(new JCheckBoxMenuItem("Modified"));
checkBoxesManFilter.add(new JCheckBoxMenuItem("Deleted")); checkBoxesManFilter.add(new JCheckBoxMenuItem("Deleted"));
for(JCheckBoxMenuItem checkBox: checkBoxesManFilter) for(JCheckBoxMenuItem checkBox: checkBoxesManFilter)
{ {
manSubMenu.add(checkBox); manSubMenu.add(checkBox);
checkBox.setState(true); checkBox.setState(true);
} }
filterMenu.add(repSubMenu); filterMenu.add(repSubMenu);
filterMenu.add(statSubMenu); filterMenu.add(statSubMenu);
filterMenu.add(manSubMenu); filterMenu.add(manSubMenu);
instrumentationMenu = new JMenu("Instrumentation"); instrumentationMenu = new JMenu("Instrumentation");
addInstItem = new JMenuItem("Add field"); addInstItem = new JMenuItem("Add field");
instrumentationMenu.add(addInstItem); instrumentationMenu.add(addInstItem);
instrumentationMenu.addSeparator(); instrumentationMenu.addSeparator();
add(monitorMenu); add(monitorMenu);
add(filterMenu); add(filterMenu);
add(instrumentationMenu); add(instrumentationMenu);
} }
public void completeMenu(CheckBoxMenuListener checkBoxMenuListener, MenuItemListener menuItemListener) public void completeMenu(CheckBoxMenuListener checkBoxMenuListener, MenuItemListener menuItemListener)
{ {
for(JCheckBoxMenuItem checkBox: checkBoxesMonitor) for(JCheckBoxMenuItem checkBox: checkBoxesMonitor)
{ {
checkBox.addActionListener(checkBoxMenuListener); checkBox.addActionListener(checkBoxMenuListener);
} }
for(JCheckBoxMenuItem checkBox: checkBoxesRepFilter) for(JCheckBoxMenuItem checkBox: checkBoxesRepFilter)
{ {
checkBox.addActionListener(checkBoxMenuListener); checkBox.addActionListener(checkBoxMenuListener);
} }
for(JCheckBoxMenuItem checkBox: checkBoxesStatFilter) for(JCheckBoxMenuItem checkBox: checkBoxesStatFilter)
{ {
checkBox.addActionListener(checkBoxMenuListener); checkBox.addActionListener(checkBoxMenuListener);
} }
for(JCheckBoxMenuItem checkBox: checkBoxesManFilter) for(JCheckBoxMenuItem checkBox: checkBoxesManFilter)
{ {
checkBox.addActionListener(checkBoxMenuListener); checkBox.addActionListener(checkBoxMenuListener);
} }
addInstItem.addActionListener(menuItemListener); addInstItem.addActionListener(menuItemListener);
} }
public void addField(String className, String fieldName, CheckBoxMenuListener checkBoxMenuListener) public void addField(String className, String fieldName, CheckBoxMenuListener checkBoxMenuListener)
{ {
JCheckBoxMenuItem checkBoxMenuItem = new JCheckBoxMenuItem(className+" "+fieldName); JCheckBoxMenuItem checkBoxMenuItem = new JCheckBoxMenuItem(className+" "+fieldName);
instrumentationMenu.add(checkBoxMenuItem); instrumentationMenu.add(checkBoxMenuItem);
checkBoxMenuItem.addActionListener(checkBoxMenuListener); checkBoxMenuItem.addActionListener(checkBoxMenuListener);
} }
} }

View File

@ -1,63 +1,63 @@
package osgi.bundle.monitoring.dem1.view; package osgi.bundle.monitoring.dem1.view;
import java.awt.Container; import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.GridLayout; import java.awt.GridLayout;
import java.util.ArrayList; import java.util.ArrayList;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.JButton; import javax.swing.JButton;
import osgi.bundle.monitoring.dem1.controller.ButtonListener; import osgi.bundle.monitoring.dem1.controller.ButtonListener;
public class RightPane extends Container public class RightPane extends Container
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private ArrayList<JButton> buttons; private ArrayList<JButton> buttons;
public RightPane() public RightPane()
{ {
setLayout(new GridLayout(15, 1)); setLayout(new GridLayout(15, 1));
buttons = new ArrayList<JButton>(); buttons = new ArrayList<JButton>();
addFillerToYPane(); addFillerToYPane();
addButtonToPane("Install"); addButtonToPane("Install");
addFillerToYPane(); addFillerToYPane();
addButtonToPane("Uninstall"); addButtonToPane("Uninstall");
addFillerToYPane(); addFillerToYPane();
addButtonToPane("Update"); addButtonToPane("Update");
addFillerToYPane(); addFillerToYPane();
addButtonToPane("Start"); addButtonToPane("Start");
addFillerToYPane(); addFillerToYPane();
addButtonToPane("Stop"); addButtonToPane("Stop");
addFillerToYPane(); addFillerToYPane();
addButtonToPane("Monitor"); addButtonToPane("Monitor");
addFillerToYPane(); addFillerToYPane();
addButtonToPane("Unmonitor"); addButtonToPane("Unmonitor");
addFillerToYPane(); addFillerToYPane();
} }
private void addFillerToYPane() private void addFillerToYPane()
{ {
add(Box.createRigidArea(new Dimension(0, 25))); add(Box.createRigidArea(new Dimension(0, 25)));
} }
private void addButtonToPane(String text) private void addButtonToPane(String text)
{ {
JButton button = new JButton(text); JButton button = new JButton(text);
buttons.add(button); buttons.add(button);
add(button); add(button);
} }
public void completeRightPane(ButtonListener buttonListener) public void completeRightPane(ButtonListener buttonListener)
{ {
for(JButton button: buttons) for(JButton button: buttons)
{ {
button.addMouseListener(buttonListener); button.addMouseListener(buttonListener);
} }
} }
} }

View File

@ -1,133 +1,133 @@
package osgi.bundle.monitoring.dem1.view; package osgi.bundle.monitoring.dem1.view;
import java.awt.Container; import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import osgi.bundle.monitoring.dem1.controller.ButtonListener; import osgi.bundle.monitoring.dem1.controller.ButtonListener;
import osgi.bundle.monitoring.dem1.controller.CheckBoxMenuListener; import osgi.bundle.monitoring.dem1.controller.CheckBoxMenuListener;
import osgi.bundle.monitoring.dem1.controller.MenuItemListener; import osgi.bundle.monitoring.dem1.controller.MenuItemListener;
import osgi.bundle.monitoring.dem1.model.FieldEvent; import osgi.bundle.monitoring.dem1.model.FieldEvent;
public class View implements Observer public class View implements Observer
{ {
private JFrame mainFrame; private JFrame mainFrame;
private LeftPane leftPane; private LeftPane leftPane;
private RightPane rightPane; private RightPane rightPane;
private Menu menu; private Menu menu;
private CheckBoxMenuListener checkBoxMenuListener; private CheckBoxMenuListener checkBoxMenuListener;
public View() public View()
{ {
rightPane = new RightPane(); rightPane = new RightPane();
leftPane = new LeftPane(); leftPane = new LeftPane();
menu = new Menu(); menu = new Menu();
} }
private static void addFillerToXPane(Container pane) private static void addFillerToXPane(Container pane)
{ {
pane.add(Box.createRigidArea(new Dimension(25, 0))); pane.add(Box.createRigidArea(new Dimension(25, 0)));
} }
private void addComponentsToPane(Container pane) private void addComponentsToPane(Container pane)
{ {
pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS)); pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
addFillerToXPane(pane); addFillerToXPane(pane);
pane.add(leftPane); pane.add(leftPane);
addFillerToXPane(pane); addFillerToXPane(pane);
pane.add(rightPane); pane.add(rightPane);
addFillerToXPane(pane); addFillerToXPane(pane);
} }
public void initUi() public void initUi()
{ {
mainFrame = new JFrame("Monitoring System: demonstrator 1"); mainFrame = new JFrame("Monitoring System: demonstrator 1");
mainFrame.setJMenuBar(menu); mainFrame.setJMenuBar(menu);
addComponentsToPane(mainFrame.getContentPane()); addComponentsToPane(mainFrame.getContentPane());
mainFrame.pack(); mainFrame.pack();
mainFrame.setResizable(false); mainFrame.setResizable(false);
mainFrame.setVisible(true); mainFrame.setVisible(true);
} }
public String installDialog() public String installDialog()
{ {
JFileChooser fc = new JFileChooser(); JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(mainFrame); int returnVal = fc.showOpenDialog(mainFrame);
if(returnVal == JFileChooser.APPROVE_OPTION) if(returnVal == JFileChooser.APPROVE_OPTION)
{ {
return fc.getSelectedFile().getName(); return fc.getSelectedFile().getName();
} }
return null; return null;
} }
public String addFieldDialog() public String addFieldDialog()
{ {
return JOptionPane.showInputDialog(mainFrame, "Please, introduce the fully qualified name of class and field (e.g. for String class and foo field \"java.lang.String/foo\"):", "New Field", JOptionPane.PLAIN_MESSAGE); return JOptionPane.showInputDialog(mainFrame, "Please, introduce the fully qualified name of class and field (e.g. for String class and foo field \"java.lang.String/foo\"):", "New Field", JOptionPane.PLAIN_MESSAGE);
} }
public void completeUi(ButtonListener buttonListener, CheckBoxMenuListener checkBoxMenuListener, MenuItemListener menuItemListener) public void completeUi(ButtonListener buttonListener, CheckBoxMenuListener checkBoxMenuListener, MenuItemListener menuItemListener)
{ {
this.checkBoxMenuListener = checkBoxMenuListener; this.checkBoxMenuListener = checkBoxMenuListener;
rightPane.completeRightPane(buttonListener); rightPane.completeRightPane(buttonListener);
menu.completeMenu(checkBoxMenuListener, menuItemListener); menu.completeMenu(checkBoxMenuListener, menuItemListener);
} }
public long getSelectedBundleId() public long getSelectedBundleId()
{ {
return leftPane.getSelectedBundleId(); return leftPane.getSelectedBundleId();
} }
public void checkMonitoring(long id) public void checkMonitoring(long id)
{ {
leftPane.checkMonitor(id); leftPane.checkMonitor(id);
} }
public void uncheckMonitoring(long id) public void uncheckMonitoring(long id)
{ {
leftPane.uncheckMonitor(id); leftPane.uncheckMonitor(id);
} }
public void close() public void close()
{ {
mainFrame.setVisible(false); mainFrame.setVisible(false);
mainFrame.dispose(); mainFrame.dispose();
} }
@Override @Override
public void update(Observable obs, Object obj) public void update(Observable obs, Object obj)
{ {
String className = obj.getClass().getName(); String className = obj.getClass().getName();
if(className.compareTo(FieldEvent.class.getName()) == 0) if(className.compareTo(FieldEvent.class.getName()) == 0)
{ {
FieldEvent fe = (FieldEvent)obj; FieldEvent fe = (FieldEvent)obj;
menu.addField(fe.getClassName(), fe.getFieldName(), checkBoxMenuListener); menu.addField(fe.getClassName(), fe.getFieldName(), checkBoxMenuListener);
} }
else else
{ {
leftPane.checkEvent(obj); leftPane.checkEvent(obj);
} }
} }
} }

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -1,28 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>osgi.bundle.monitoring.dem2</name> <name>osgi.bundle.monitoring.dem2</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand> <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name> <name>org.eclipse.jdt.core.javabuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name> <name>org.eclipse.pde.ManifestBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name> <name>org.eclipse.pde.SchemaBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.pde.PluginNature</nature> <nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
</natures> </natures>
</projectDescription> </projectDescription>

View File

@ -1,7 +1,7 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7 org.eclipse.jdt.core.compiler.source=1.7

View File

@ -1,4 +1,4 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
pluginProject.equinox=false pluginProject.equinox=false
pluginProject.extensions=false pluginProject.extensions=false
resolve.requirebundle=false resolve.requirebundle=false

View File

@ -1,55 +1,55 @@
package osgi.bundle.monitoring.dem2; package osgi.bundle.monitoring.dem2;
import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import osgi.bundle.monitoring.dem2.controller.ButtonListener; import osgi.bundle.monitoring.dem2.controller.ButtonListener;
import osgi.bundle.monitoring.dem2.controller.CheckBoxMenuListener; import osgi.bundle.monitoring.dem2.controller.CheckBoxMenuListener;
import osgi.bundle.monitoring.dem2.model.Model; import osgi.bundle.monitoring.dem2.model.Model;
import osgi.bundle.monitoring.dem2.view.View; import osgi.bundle.monitoring.dem2.view.View;
public class Activator implements BundleActivator public class Activator implements BundleActivator
{ {
private static BundleContext context; private static BundleContext context;
private View view; private View view;
static BundleContext getContext() static BundleContext getContext()
{ {
return context; return context;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/ */
public void start(BundleContext bundleContext) throws Exception public void start(BundleContext bundleContext) throws Exception
{ {
Activator.context = bundleContext; Activator.context = bundleContext;
view = new View(); view = new View();
view.initUi(); view.initUi();
Model model = new Model(bundleContext); Model model = new Model(bundleContext);
ButtonListener buttonListener = new ButtonListener(model, view); ButtonListener buttonListener = new ButtonListener(model, view);
CheckBoxMenuListener checkBoxMenuListener = new CheckBoxMenuListener(model); CheckBoxMenuListener checkBoxMenuListener = new CheckBoxMenuListener(model);
model.addObserver(view); model.addObserver(view);
view.completeUi(buttonListener, checkBoxMenuListener); view.completeUi(buttonListener, checkBoxMenuListener);
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/ */
public void stop(BundleContext bundleContext) throws Exception public void stop(BundleContext bundleContext) throws Exception
{ {
Activator.context = null; Activator.context = null;
view.close(); view.close();
} }
} }

View File

@ -1,120 +1,120 @@
package osgi.bundle.monitoring.dem2.controller; package osgi.bundle.monitoring.dem2.controller;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import javax.swing.JButton; import javax.swing.JButton;
import osgi.bundle.monitoring.dem2.model.Model; import osgi.bundle.monitoring.dem2.model.Model;
import osgi.bundle.monitoring.dem2.view.View; import osgi.bundle.monitoring.dem2.view.View;
public class ButtonListener implements MouseListener public class ButtonListener implements MouseListener
{ {
private Model model; private Model model;
private View view; private View view;
public ButtonListener(Model model, View view) public ButtonListener(Model model, View view)
{ {
this.model = model; this.model = model;
this.view = view; this.view = view;
} }
@Override @Override
public void mouseClicked(MouseEvent me) public void mouseClicked(MouseEvent me)
{ {
String button = ((JButton)me.getSource()).getText(); String button = ((JButton)me.getSource()).getText();
if(button.compareTo("Install") == 0) if(button.compareTo("Install") == 0)
{ {
String fileName = view.installDialog(); String fileName = view.installDialog();
if(fileName != null) if(fileName != null)
{ {
model.installBundle(fileName); model.installBundle(fileName);
} }
} }
else if(button.compareTo("Uninstall") == 0) else if(button.compareTo("Uninstall") == 0)
{ {
long id = view.getSelectedBundleId(); long id = view.getSelectedBundleId();
if(id >= 0) if(id >= 0)
{ {
model.uninstallBundle(id); model.uninstallBundle(id);
} }
} }
else if(button.compareTo("Update") == 0) else if(button.compareTo("Update") == 0)
{ {
long id = view.getSelectedBundleId(); long id = view.getSelectedBundleId();
if(id >= 0) if(id >= 0)
{ {
model.updateBundle(id); model.updateBundle(id);
} }
} }
else if(button.compareTo("Start") == 0) else if(button.compareTo("Start") == 0)
{ {
long id = view.getSelectedBundleId(); long id = view.getSelectedBundleId();
if(id >= 0) if(id >= 0)
{ {
model.startBundle(id); model.startBundle(id);
} }
} }
else if(button.compareTo("Stop") == 0) else if(button.compareTo("Stop") == 0)
{ {
long id = view.getSelectedBundleId(); long id = view.getSelectedBundleId();
if(id >= 0) if(id >= 0)
{ {
model.stopBundle(id); model.stopBundle(id);
} }
} }
else if(button.compareTo("Monitor") == 0) else if(button.compareTo("Monitor") == 0)
{ {
long id = view.getSelectedBundleId(); long id = view.getSelectedBundleId();
if(id >= 0) if(id >= 0)
{ {
model.setIdOpened(id); model.setIdOpened(id);
view.checkMonitoring(id); view.checkMonitoring(id);
} }
} }
else if(button.compareTo("Unmonitor") == 0) else if(button.compareTo("Unmonitor") == 0)
{ {
long id = view.getSelectedBundleId(); long id = view.getSelectedBundleId();
if(id >= 0) if(id >= 0)
{ {
model.setIdClosed(id); model.setIdClosed(id);
view.uncheckMonitoring(id); view.uncheckMonitoring(id);
} }
} }
} }
@Override @Override
public void mouseEntered(MouseEvent me) public void mouseEntered(MouseEvent me)
{ {
} }
@Override @Override
public void mouseExited(MouseEvent me) public void mouseExited(MouseEvent me)
{ {
} }
@Override @Override
public void mousePressed(MouseEvent me) public void mousePressed(MouseEvent me)
{ {
} }
@Override @Override
public void mouseReleased(MouseEvent me) public void mouseReleased(MouseEvent me)
{ {
} }
} }

View File

@ -1,118 +1,118 @@
package osgi.bundle.monitoring.dem2.controller; package osgi.bundle.monitoring.dem2.controller;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import javax.swing.JCheckBoxMenuItem; import javax.swing.JCheckBoxMenuItem;
import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleEvent;
import osgi.bundle.monitoring.dem2.model.Model; import osgi.bundle.monitoring.dem2.model.Model;
import osgi.framework.monitoring.event.ServiceEventMod; import osgi.framework.monitoring.event.ServiceEventMod;
public class CheckBoxMenuListener implements ActionListener public class CheckBoxMenuListener implements ActionListener
{ {
private Model model; private Model model;
public CheckBoxMenuListener(Model model) public CheckBoxMenuListener(Model model)
{ {
this.model = model; this.model = model;
} }
public void changeMonitorState(boolean state, int index) public void changeMonitorState(boolean state, int index)
{ {
if(state == true) if(state == true)
{ {
model.setMonitorOn(index); model.setMonitorOn(index);
} }
else else
{ {
model.setMonitorOff(index); model.setMonitorOff(index);
} }
} }
private void changeTypeFilter(boolean state, int index, int type) private void changeTypeFilter(boolean state, int index, int type)
{ {
if(state == true) if(state == true)
{ {
model.setTypeOpened(index, type); model.setTypeOpened(index, type);
} }
else else
{ {
model.setTypeClosed(index, type); model.setTypeClosed(index, type);
} }
} }
@Override @Override
public void actionPerformed(ActionEvent ae) public void actionPerformed(ActionEvent ae)
{ {
JCheckBoxMenuItem cb = (JCheckBoxMenuItem)ae.getSource(); JCheckBoxMenuItem cb = (JCheckBoxMenuItem)ae.getSource();
String checkBox = cb.getText(); String checkBox = cb.getText();
if(checkBox.compareTo("Bundle state") == 0) if(checkBox.compareTo("Bundle state") == 0)
{ {
changeMonitorState(cb.getState(), 0); changeMonitorState(cb.getState(), 0);
} }
else if(checkBox.compareTo("Services") == 0) else if(checkBox.compareTo("Services") == 0)
{ {
changeMonitorState(cb.getState(), 1); changeMonitorState(cb.getState(), 1);
} }
else if(checkBox.compareTo("Installed") == 0) else if(checkBox.compareTo("Installed") == 0)
{ {
changeTypeFilter(cb.getState(), 0, BundleEvent.INSTALLED); changeTypeFilter(cb.getState(), 0, BundleEvent.INSTALLED);
} }
else if(checkBox.compareTo("Lazy Activation") == 0) else if(checkBox.compareTo("Lazy Activation") == 0)
{ {
changeTypeFilter(cb.getState(), 0, BundleEvent.LAZY_ACTIVATION); changeTypeFilter(cb.getState(), 0, BundleEvent.LAZY_ACTIVATION);
} }
else if(checkBox.compareTo("Resolved") == 0) else if(checkBox.compareTo("Resolved") == 0)
{ {
changeTypeFilter(cb.getState(), 0, BundleEvent.RESOLVED); changeTypeFilter(cb.getState(), 0, BundleEvent.RESOLVED);
} }
else if(checkBox.compareTo("Started") == 0) else if(checkBox.compareTo("Started") == 0)
{ {
changeTypeFilter(cb.getState(), 0, BundleEvent.STARTED); changeTypeFilter(cb.getState(), 0, BundleEvent.STARTED);
} }
else if(checkBox.compareTo("Starting") == 0) else if(checkBox.compareTo("Starting") == 0)
{ {
changeTypeFilter(cb.getState(), 0, BundleEvent.STARTING); changeTypeFilter(cb.getState(), 0, BundleEvent.STARTING);
} }
else if(checkBox.compareTo("Stopped") == 0) else if(checkBox.compareTo("Stopped") == 0)
{ {
changeTypeFilter(cb.getState(), 0, BundleEvent.STOPPED); changeTypeFilter(cb.getState(), 0, BundleEvent.STOPPED);
} }
else if(checkBox.compareTo("Stopping") == 0) else if(checkBox.compareTo("Stopping") == 0)
{ {
changeTypeFilter(cb.getState(), 0, BundleEvent.STOPPING); changeTypeFilter(cb.getState(), 0, BundleEvent.STOPPING);
} }
else if(checkBox.compareTo("Uninstalled") == 0) else if(checkBox.compareTo("Uninstalled") == 0)
{ {
changeTypeFilter(cb.getState(), 0, BundleEvent.UNINSTALLED); changeTypeFilter(cb.getState(), 0, BundleEvent.UNINSTALLED);
} }
else if(checkBox.compareTo("Unresolved") == 0) else if(checkBox.compareTo("Unresolved") == 0)
{ {
changeTypeFilter(cb.getState(), 0, BundleEvent.UNRESOLVED); changeTypeFilter(cb.getState(), 0, BundleEvent.UNRESOLVED);
} }
else if(checkBox.compareTo("Updated") == 0) else if(checkBox.compareTo("Updated") == 0)
{ {
changeTypeFilter(cb.getState(), 0, BundleEvent.UPDATED); changeTypeFilter(cb.getState(), 0, BundleEvent.UPDATED);
} }
else if(checkBox.compareTo("Modified") == 0) else if(checkBox.compareTo("Modified") == 0)
{ {
changeTypeFilter(cb.getState(), 1, ServiceEventMod.MODIFIED); changeTypeFilter(cb.getState(), 1, ServiceEventMod.MODIFIED);
} }
else if(checkBox.compareTo("Modified Endmatch") == 0) else if(checkBox.compareTo("Modified Endmatch") == 0)
{ {
changeTypeFilter(cb.getState(), 1, ServiceEventMod.MODIFIED_ENDMATCH); changeTypeFilter(cb.getState(), 1, ServiceEventMod.MODIFIED_ENDMATCH);
} }
else if(checkBox.compareTo("Registered") == 0) else if(checkBox.compareTo("Registered") == 0)
{ {
changeTypeFilter(cb.getState(), 1, ServiceEventMod.REGISTERED); changeTypeFilter(cb.getState(), 1, ServiceEventMod.REGISTERED);
} }
else if(checkBox.compareTo("Unregistered") == 0) else if(checkBox.compareTo("Unregistered") == 0)
{ {
changeTypeFilter(cb.getState(), 1, ServiceEventMod.UNREGISTERED); changeTypeFilter(cb.getState(), 1, ServiceEventMod.UNREGISTERED);
} }
} }
} }

View File

@ -1,75 +1,75 @@
package osgi.bundle.monitoring.dem2.model; package osgi.bundle.monitoring.dem2.model;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException; import org.osgi.framework.BundleException;
/** /**
* Provides methods to manage bundles in the OSGi BundleContext * Provides methods to manage bundles in the OSGi BundleContext
* @author Anibal * @author Anibal
*/ */
public class ContextManager public class ContextManager
{ {
private BundleContext bundleContext; private BundleContext bundleContext;
public ContextManager(BundleContext bundleContext) public ContextManager(BundleContext bundleContext)
{ {
this.bundleContext = bundleContext; this.bundleContext = bundleContext;
} }
public void installBundle(String file) public void installBundle(String file)
{ {
try try
{ {
bundleContext.installBundle("file:"+file); bundleContext.installBundle("file:"+file);
} catch (BundleException e) } catch (BundleException e)
{ {
} }
} }
public void uninstallBundle(long id) public void uninstallBundle(long id)
{ {
try try
{ {
bundleContext.getBundle(id).uninstall(); bundleContext.getBundle(id).uninstall();
} catch (BundleException e) } catch (BundleException e)
{ {
} }
} }
public void updateBundle(long id) public void updateBundle(long id)
{ {
try try
{ {
bundleContext.getBundle(id).update(); bundleContext.getBundle(id).update();
} catch (BundleException e) } catch (BundleException e)
{ {
} }
} }
public void startBundle(long id) public void startBundle(long id)
{ {
try try
{ {
bundleContext.getBundle(id).start(); bundleContext.getBundle(id).start();
} catch (BundleException e) } catch (BundleException e)
{ {
} }
} }
public void stopBundle(long id) public void stopBundle(long id)
{ {
try try
{ {
bundleContext.getBundle(id).stop(); bundleContext.getBundle(id).stop();
} catch (BundleException e) } catch (BundleException e)
{ {
} }
} }
} }

View File

@ -1,84 +1,84 @@
package osgi.bundle.monitoring.dem2.model; package osgi.bundle.monitoring.dem2.model;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import osgi.bundle.monitoring.dem2.view.View; import osgi.bundle.monitoring.dem2.view.View;
/** /**
* Provides an API with the actions the user can perform * Provides an API with the actions the user can perform
* @author Anibal * @author Anibal
*/ */
public class Model public class Model
{ {
private Monitor monitor; private Monitor monitor;
private ContextManager contextManager; private ContextManager contextManager;
public Model(BundleContext bundleContext) public Model(BundleContext bundleContext)
{ {
monitor = new Monitor(bundleContext); monitor = new Monitor(bundleContext);
contextManager = new ContextManager(bundleContext); contextManager = new ContextManager(bundleContext);
} }
public void installBundle(String fileName) public void installBundle(String fileName)
{ {
contextManager.installBundle(fileName); contextManager.installBundle(fileName);
} }
public void uninstallBundle(long id) public void uninstallBundle(long id)
{ {
contextManager.uninstallBundle(id); contextManager.uninstallBundle(id);
} }
public void updateBundle(long id) public void updateBundle(long id)
{ {
contextManager.updateBundle(id); contextManager.updateBundle(id);
} }
public void startBundle(long id) public void startBundle(long id)
{ {
contextManager.startBundle(id); contextManager.startBundle(id);
} }
public void stopBundle(long id) public void stopBundle(long id)
{ {
contextManager.stopBundle(id); contextManager.stopBundle(id);
} }
public void setIdOpened(long id) public void setIdOpened(long id)
{ {
monitor.setIdOpened(id); monitor.setIdOpened(id);
} }
public void setIdClosed(long id) public void setIdClosed(long id)
{ {
monitor.setIdClosed(id); monitor.setIdClosed(id);
} }
public void setMonitorOn(int index) public void setMonitorOn(int index)
{ {
monitor.setMonitorOn(index); monitor.setMonitorOn(index);
} }
public void setMonitorOff(int index) public void setMonitorOff(int index)
{ {
monitor.setMonitorOff(index); monitor.setMonitorOff(index);
} }
public void setTypeOpened(int index, int type) public void setTypeOpened(int index, int type)
{ {
monitor.setTypeOpened(index, type); monitor.setTypeOpened(index, type);
} }
public void setTypeClosed(int index, int type) public void setTypeClosed(int index, int type)
{ {
monitor.setTypeClosed(index, type); monitor.setTypeClosed(index, type);
} }
public void addObserver(View view) public void addObserver(View view)
{ {
monitor.addObserver(view); monitor.addObserver(view);
} }
} }

View File

@ -1,143 +1,143 @@
package osgi.bundle.monitoring.dem2.model; package osgi.bundle.monitoring.dem2.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import osgi.framework.monitoring.event.EventMonitor; import osgi.framework.monitoring.event.EventMonitor;
import osgi.framework.monitoring.event.ServiceRegistryMonitor; import osgi.framework.monitoring.event.ServiceRegistryMonitor;
import osgi.framework.monitoring.event.StateMonitor; import osgi.framework.monitoring.event.StateMonitor;
import osgi.framework.monitoring.event.filter.IdFilterSet; import osgi.framework.monitoring.event.filter.IdFilterSet;
import osgi.framework.monitoring.event.filter.TypeFilterSet; import osgi.framework.monitoring.event.filter.TypeFilterSet;
/** /**
* Manages the different types of monitors: state monitor and service monitor * Manages the different types of monitors: state monitor and service monitor
* @author Anibal * @author Anibal
*/ */
public class Monitor extends Observable implements Observer public class Monitor extends Observable implements Observer
{ {
// Contains all monitor objects // Contains all monitor objects
private ArrayList<EventMonitor> bundleMonitors; private ArrayList<EventMonitor> bundleMonitors;
// Contains all type filer for the various monitors // Contains all type filer for the various monitors
private ArrayList<TypeFilterSet> typeFilters; private ArrayList<TypeFilterSet> typeFilters;
private IdFilterSet idFilter; private IdFilterSet idFilter;
/** /**
* Constructor. Initialize the different monitors * Constructor. Initialize the different monitors
* @param bundleContext * @param bundleContext
*/ */
public Monitor(BundleContext bundleContext) public Monitor(BundleContext bundleContext)
{ {
bundleMonitors = new ArrayList<EventMonitor>(); bundleMonitors = new ArrayList<EventMonitor>();
typeFilters = new ArrayList<TypeFilterSet>(); typeFilters = new ArrayList<TypeFilterSet>();
idFilter = new IdFilterSet(); idFilter = new IdFilterSet();
// Positions in array 0: StateMonitor, 1: ServiceRegistryMonitor // Positions in array 0: StateMonitor, 1: ServiceRegistryMonitor
bundleMonitors.add(new StateMonitor(bundleContext)); bundleMonitors.add(new StateMonitor(bundleContext));
bundleMonitors.add(new ServiceRegistryMonitor(bundleContext)); bundleMonitors.add(new ServiceRegistryMonitor(bundleContext));
// Set the type filter sets to each monitor object // Set the type filter sets to each monitor object
for(int i = 0; i < bundleMonitors.size() - 1; i++) for(int i = 0; i < bundleMonitors.size() - 1; i++)
{ {
typeFilters.add(new TypeFilterSet()); typeFilters.add(new TypeFilterSet());
bundleMonitors.get(i).setTypeFilterSet(typeFilters.get(i)); bundleMonitors.get(i).setTypeFilterSet(typeFilters.get(i));
bundleMonitors.get(i).setBundleFilterSet(idFilter); bundleMonitors.get(i).setBundleFilterSet(idFilter);
} }
// StateMonitor activated by default // StateMonitor activated by default
setMonitorOn(0); setMonitorOn(0);
} }
/** /**
* Activate monitor object * Activate monitor object
* @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor * @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor
*/ */
public void setMonitorOn(int index) public void setMonitorOn(int index)
{ {
bundleMonitors.get(index).addObserver(this); bundleMonitors.get(index).addObserver(this);
} }
/** /**
* Deactivate monitor object * Deactivate monitor object
* @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor * @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor
*/ */
public void setMonitorOff(int index) public void setMonitorOff(int index)
{ {
bundleMonitors.get(index).deleteObservers(); bundleMonitors.get(index).deleteObservers();
} }
/** /**
* Open or close type in one TypeFilterSet * Open or close type in one TypeFilterSet
* @param typeFilterSet * @param typeFilterSet
* @param type type of event * @param type type of event
* @param open true: opened, false: closed * @param open true: opened, false: closed
*/ */
private void setType(TypeFilterSet typeFilterSet, int type, Boolean open) private void setType(TypeFilterSet typeFilterSet, int type, Boolean open)
{ {
typeFilterSet.addEntry(type, open); typeFilterSet.addEntry(type, open);
} }
/** /**
* Open type in one TypeFilterSet * Open type in one TypeFilterSet
* @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor * @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor
* @param type type of event * @param type type of event
*/ */
public void setTypeOpened(int index, int type) public void setTypeOpened(int index, int type)
{ {
setType(typeFilters.get(index), type, true); setType(typeFilters.get(index), type, true);
} }
/** /**
* Close type in one TypeFilterSet * Close type in one TypeFilterSet
* @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor * @param index 0: RepositoryMonitor, 1: StateMonitor, 2: ManifestMonitor, 3: DataFieldMonitor
* @param type type of event * @param type type of event
*/ */
public void setTypeClosed(int index, int type) public void setTypeClosed(int index, int type)
{ {
setType(typeFilters.get(index), type, false); setType(typeFilters.get(index), type, false);
} }
/** /**
* Open or close bundle in one IdFilterSet * Open or close bundle in one IdFilterSet
* @param idBundle * @param idBundle
* @param mode true: opened, false: closed * @param mode true: opened, false: closed
*/ */
private void setId(long idBundle, boolean mode) private void setId(long idBundle, boolean mode)
{ {
idFilter.addEntry(idBundle, mode); idFilter.addEntry(idBundle, mode);
} }
/** /**
* Open bundle in one IdFilterSet * Open bundle in one IdFilterSet
* @param idBundle * @param idBundle
*/ */
public void setIdOpened(long idBundle) public void setIdOpened(long idBundle)
{ {
setId(idBundle, true); setId(idBundle, true);
} }
/** /**
* Close bundle in one IdFilterSet * Close bundle in one IdFilterSet
* @param idBundle * @param idBundle
*/ */
public void setIdClosed(long idBundle) public void setIdClosed(long idBundle)
{ {
setId(idBundle, false); setId(idBundle, false);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see java.util.Observer#update(java.util.Observable, java.lang.Object) * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
*/ */
@Override @Override
public void update(Observable obs, Object obj) public void update(Observable obs, Object obj)
{ {
setChanged(); setChanged();
notifyObservers(obj); notifyObservers(obj);
} }
} }

View File

@ -1,137 +1,137 @@
package osgi.bundle.monitoring.dem2.view; package osgi.bundle.monitoring.dem2.view;
import java.awt.Dimension; import java.awt.Dimension;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleEvent;
public class BundleTable extends JScrollPane public class BundleTable extends JScrollPane
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
JTable bundleTable; JTable bundleTable;
BundleTableModel tableModel; BundleTableModel tableModel;
public BundleTable(int x, int y) public BundleTable(int x, int y)
{ {
tableModel = new BundleTableModel(); tableModel = new BundleTableModel();
bundleTable = new JTable(tableModel); bundleTable = new JTable(tableModel);
bundleTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); bundleTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
bundleTable.getColumnModel().getColumn(0).setPreferredWidth(75); bundleTable.getColumnModel().getColumn(0).setPreferredWidth(75);
bundleTable.getColumnModel().getColumn(1).setPreferredWidth(75); bundleTable.getColumnModel().getColumn(1).setPreferredWidth(75);
bundleTable.getColumnModel().getColumn(2).setPreferredWidth(150); bundleTable.getColumnModel().getColumn(2).setPreferredWidth(150);
bundleTable.getColumnModel().getColumn(3).setPreferredWidth(300); bundleTable.getColumnModel().getColumn(3).setPreferredWidth(300);
setViewportView(bundleTable); setViewportView(bundleTable);
setPreferredSize(new Dimension(x, y)); setPreferredSize(new Dimension(x, y));
} }
private String getBundleState(int state) private String getBundleState(int state)
{ {
switch(state) switch(state)
{ {
case Bundle.UNINSTALLED: case Bundle.UNINSTALLED:
return "Uninstalled"; return "Uninstalled";
case Bundle.INSTALLED: case Bundle.INSTALLED:
return "Installed"; return "Installed";
case Bundle.RESOLVED: case Bundle.RESOLVED:
return "Resolved"; return "Resolved";
case Bundle.STARTING: case Bundle.STARTING:
return "Starting"; return "Starting";
case Bundle.STOPPING: case Bundle.STOPPING:
return "Stopping"; return "Stopping";
case Bundle.ACTIVE: case Bundle.ACTIVE:
return "Active"; return "Active";
} }
return "Unknown"; return "Unknown";
} }
private void addBundle(Bundle bundle) private void addBundle(Bundle bundle)
{ {
tableModel.insertRow(true, tableModel.insertRow(true,
bundle.getBundleId(), bundle.getBundleId(),
getBundleState(bundle.getState()), getBundleState(bundle.getState()),
bundle.getSymbolicName()); bundle.getSymbolicName());
} }
private void modifyBundle(Bundle bundle) private void modifyBundle(Bundle bundle)
{ {
tableModel.modifyState(bundle.getBundleId(), tableModel.modifyState(bundle.getBundleId(),
getBundleState(bundle.getState())); getBundleState(bundle.getState()));
} }
private void removeBundle(long id) private void removeBundle(long id)
{ {
tableModel.deleteRow(id); tableModel.deleteRow(id);
} }
public void changeBundle(BundleEvent be) public void changeBundle(BundleEvent be)
{ {
switch(be.getType()) switch(be.getType())
{ {
case BundleEvent.INSTALLED: case BundleEvent.INSTALLED:
addBundle(be.getBundle()); addBundle(be.getBundle());
break; break;
case BundleEvent.LAZY_ACTIVATION: case BundleEvent.LAZY_ACTIVATION:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
case BundleEvent.RESOLVED: case BundleEvent.RESOLVED:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
case BundleEvent.STARTED: case BundleEvent.STARTED:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
case BundleEvent.STARTING: case BundleEvent.STARTING:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
case BundleEvent.STOPPED: case BundleEvent.STOPPED:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
case BundleEvent.STOPPING: case BundleEvent.STOPPING:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
case BundleEvent.UNINSTALLED: case BundleEvent.UNINSTALLED:
removeBundle(be.getBundle().getBundleId()); removeBundle(be.getBundle().getBundleId());
break; break;
case BundleEvent.UNRESOLVED: case BundleEvent.UNRESOLVED:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
case BundleEvent.UPDATED: case BundleEvent.UPDATED:
modifyBundle(be.getBundle()); modifyBundle(be.getBundle());
break; break;
} }
} }
public long getSelectedBundleId() public long getSelectedBundleId()
{ {
int index = bundleTable.getSelectedRow(); int index = bundleTable.getSelectedRow();
if(index >= 0) if(index >= 0)
{ {
return tableModel.idOfRow(index); return tableModel.idOfRow(index);
} }
return -1; return -1;
} }
public void checkMonitor(long id) public void checkMonitor(long id)
{ {
tableModel.modifyMonitoring(id, true); tableModel.modifyMonitoring(id, true);
} }
public void uncheckMonitor(long id) public void uncheckMonitor(long id)
{ {
tableModel.modifyMonitoring(id, false); tableModel.modifyMonitoring(id, false);
} }
} }

View File

@ -1,143 +1,143 @@
package osgi.bundle.monitoring.dem2.view; package osgi.bundle.monitoring.dem2.view;
import java.util.ArrayList; import java.util.ArrayList;
import javax.swing.table.AbstractTableModel; import javax.swing.table.AbstractTableModel;
public class BundleTableModel extends AbstractTableModel public class BundleTableModel extends AbstractTableModel
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String[] columnNames = private String[] columnNames =
{"Monitoring", {"Monitoring",
"Id", "Id",
"State", "State",
"Symbolic Name" "Symbolic Name"
}; };
private ArrayList<ArrayList<Object>> data; private ArrayList<ArrayList<Object>> data;
public BundleTableModel() public BundleTableModel()
{ {
data = new ArrayList<ArrayList<Object>>(); data = new ArrayList<ArrayList<Object>>();
} }
@Override @Override
public int getColumnCount() public int getColumnCount()
{ {
return columnNames.length; return columnNames.length;
} }
@Override @Override
public int getRowCount() public int getRowCount()
{ {
return data.size(); return data.size();
} }
public String getColumnName(int col) public String getColumnName(int col)
{ {
return columnNames[col]; return columnNames[col];
} }
@Override @Override
public Object getValueAt(int row, int col) public Object getValueAt(int row, int col)
{ {
return data.get(row).get(col); return data.get(row).get(col);
} }
public Class<?> getColumnClass(int col) public Class<?> getColumnClass(int col)
{ {
return getValueAt(0, col).getClass(); return getValueAt(0, col).getClass();
} }
public void setValueAt(Object value, int row, int col) public void setValueAt(Object value, int row, int col)
{ {
if(row == data.size()) if(row == data.size())
{ {
data.add(new ArrayList<Object>()); data.add(new ArrayList<Object>());
data.get(row).add(value); data.get(row).add(value);
data.get(row).add(null); data.get(row).add(null);
data.get(row).add(null); data.get(row).add(null);
data.get(row).add(null); data.get(row).add(null);
fireTableDataChanged(); fireTableDataChanged();
} }
else if(row < data.size()) else if(row < data.size())
{ {
data.get(row).set(col, value); data.get(row).set(col, value);
fireTableCellUpdated(row, col); fireTableCellUpdated(row, col);
} }
} }
public void insertRow(Boolean monitoring, long id, String state, String name) public void insertRow(Boolean monitoring, long id, String state, String name)
{ {
int row = data.size(); int row = data.size();
setValueAt(monitoring, row, 0); setValueAt(monitoring, row, 0);
setValueAt(id, row, 1); setValueAt(id, row, 1);
setValueAt(state, row, 2); setValueAt(state, row, 2);
setValueAt(name, row, 3); setValueAt(name, row, 3);
} }
private int rowOfId(long id) private int rowOfId(long id)
{ {
int first = 0; int first = 0;
int last = data.size() - 1; int last = data.size() - 1;
int middle; int middle;
while((first <= last)) while((first <= last))
{ {
middle = (int)(first + ((last - first)/2)); middle = (int)(first + ((last - first)/2));
if(id < (long)data.get(middle).get(1)) if(id < (long)data.get(middle).get(1))
{ {
last = middle - 1; last = middle - 1;
} }
else if(id > (long)data.get(middle).get(1)) else if(id > (long)data.get(middle).get(1))
{ {
first = middle + 1; first = middle + 1;
} }
else else
{ {
return middle; return middle;
} }
} }
return -1; return -1;
} }
public void modifyState(long id, String state) public void modifyState(long id, String state)
{ {
int row = rowOfId(id); int row = rowOfId(id);
if(row > -1) if(row > -1)
{ {
setValueAt(state, row, 2); setValueAt(state, row, 2);
} }
} }
public void modifyMonitoring(long id, Boolean monitoring) public void modifyMonitoring(long id, Boolean monitoring)
{ {
int row = rowOfId(id); int row = rowOfId(id);
if(row > -1) if(row > -1)
{ {
setValueAt(monitoring, row, 0); setValueAt(monitoring, row, 0);
} }
} }
public void deleteRow(long id) public void deleteRow(long id)
{ {
int row = rowOfId(id); int row = rowOfId(id);
data.remove(row); data.remove(row);
fireTableDataChanged(); fireTableDataChanged();
} }
public long idOfRow(int row) public long idOfRow(int row)
{ {
return (long)data.get(row).get(1); return (long)data.get(row).get(1);
} }
} }

View File

@ -1,104 +1,104 @@
package osgi.bundle.monitoring.dem2.view; package osgi.bundle.monitoring.dem2.view;
import java.awt.Container; import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.JLabel; import javax.swing.JLabel;
import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleEvent;
import osgi.framework.monitoring.event.ServiceEventMod; import osgi.framework.monitoring.event.ServiceEventMod;
public class LeftPane extends Container public class LeftPane extends Container
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private LogList logList; private LogList logList;
private BundleTable bundleTable; private BundleTable bundleTable;
private ServiceTable serviceTable; private ServiceTable serviceTable;
public LeftPane() public LeftPane()
{ {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
addFillerToYPane(); addFillerToYPane();
addLabelToPane("Installed bundles"); addLabelToPane("Installed bundles");
addBundleListToPane(600, 150); addBundleListToPane(600, 150);
addFillerToYPane(); addFillerToYPane();
addLabelToPane("Services advailable"); addLabelToPane("Services advailable");
addServiceListToPane(600, 150); addServiceListToPane(600, 150);
addFillerToYPane(); addFillerToYPane();
addLabelToPane("Monitoring log"); addLabelToPane("Monitoring log");
addLogListToPane(600, 200); addLogListToPane(600, 200);
addFillerToYPane(); addFillerToYPane();
} }
private void addFillerToYPane() private void addFillerToYPane()
{ {
add(Box.createRigidArea(new Dimension(0, 25))); add(Box.createRigidArea(new Dimension(0, 25)));
} }
private void addLabelToPane(String text) private void addLabelToPane(String text)
{ {
JLabel label = new JLabel(text); JLabel label = new JLabel(text);
add(label); add(label);
} }
private void addLogListToPane(int x, int y) private void addLogListToPane(int x, int y)
{ {
logList = new LogList(x, y); logList = new LogList(x, y);
add(logList); add(logList);
} }
private void addServiceListToPane(int x, int y) private void addServiceListToPane(int x, int y)
{ {
serviceTable = new ServiceTable(x, y); serviceTable = new ServiceTable(x, y);
add(serviceTable); add(serviceTable);
} }
private void addBundleListToPane(int x, int y) private void addBundleListToPane(int x, int y)
{ {
bundleTable = new BundleTable(x, y); bundleTable = new BundleTable(x, y);
add(bundleTable); add(bundleTable);
} }
public void checkEvent(Object event) public void checkEvent(Object event)
{ {
String className = event.getClass().getName(); String className = event.getClass().getName();
if(className.compareTo(BundleEvent.class.getName()) == 0) if(className.compareTo(BundleEvent.class.getName()) == 0)
{ {
bundleTable.changeBundle((BundleEvent)event); bundleTable.changeBundle((BundleEvent)event);
logList.logBundleEvent((BundleEvent)event); logList.logBundleEvent((BundleEvent)event);
} }
else if(className.compareTo(ServiceEventMod.class.getName()) == 0) else if(className.compareTo(ServiceEventMod.class.getName()) == 0)
{ {
serviceTable.changeService((ServiceEventMod)event); serviceTable.changeService((ServiceEventMod)event);
logList.logServiceEvent((ServiceEventMod)event); logList.logServiceEvent((ServiceEventMod)event);
} }
} }
public long getSelectedBundleId() public long getSelectedBundleId()
{ {
return bundleTable.getSelectedBundleId(); return bundleTable.getSelectedBundleId();
} }
public void checkMonitor(long id) public void checkMonitor(long id)
{ {
bundleTable.checkMonitor(id); bundleTable.checkMonitor(id);
} }
public void uncheckMonitor(long id) public void uncheckMonitor(long id)
{ {
bundleTable.uncheckMonitor(id); bundleTable.uncheckMonitor(id);
} }
} }

View File

@ -1,134 +1,134 @@
package osgi.bundle.monitoring.dem2.view; package osgi.bundle.monitoring.dem2.view;
import java.awt.Dimension; import java.awt.Dimension;
import javax.swing.DefaultListModel; import javax.swing.DefaultListModel;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleEvent;
import org.osgi.framework.ServiceEvent; import org.osgi.framework.ServiceEvent;
import osgi.framework.monitoring.event.ServiceEventMod; import osgi.framework.monitoring.event.ServiceEventMod;
public class LogList extends JScrollPane public class LogList extends JScrollPane
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private JList<String> listLog; private JList<String> listLog;
private DefaultListModel<String> listModelLog; private DefaultListModel<String> listModelLog;
public LogList(int x, int y) public LogList(int x, int y)
{ {
listLog = new JList<String>(); listLog = new JList<String>();
listModelLog = new DefaultListModel<String>(); listModelLog = new DefaultListModel<String>();
listLog.setModel(listModelLog); listLog.setModel(listModelLog);
setViewportView(listLog); setViewportView(listLog);
setPreferredSize(new Dimension(x, y)); setPreferredSize(new Dimension(x, y));
listLog.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listLog.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
} }
public void insertList(String message) public void insertList(String message)
{ {
listModelLog.addElement(message); listModelLog.addElement(message);
} }
public void insertListLog(String message) public void insertListLog(String message)
{ {
try try
{ {
Thread.sleep(10); Thread.sleep(10);
} }
catch (InterruptedException e) catch (InterruptedException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
insertList(message); insertList(message);
} }
private String getBundleEvent(int type) private String getBundleEvent(int type)
{ {
switch(type) switch(type)
{ {
case BundleEvent.INSTALLED: case BundleEvent.INSTALLED:
return "Installed"; return "Installed";
case BundleEvent.LAZY_ACTIVATION: case BundleEvent.LAZY_ACTIVATION:
return "Lazily activated"; return "Lazily activated";
case BundleEvent.RESOLVED: case BundleEvent.RESOLVED:
return "Resolved"; return "Resolved";
case BundleEvent.STARTED: case BundleEvent.STARTED:
return "Started"; return "Started";
case BundleEvent.STARTING: case BundleEvent.STARTING:
return "Activated"; return "Activated";
case BundleEvent.STOPPED: case BundleEvent.STOPPED:
return "Stopped"; return "Stopped";
case BundleEvent.STOPPING: case BundleEvent.STOPPING:
return "Deactivated"; return "Deactivated";
case BundleEvent.UNINSTALLED: case BundleEvent.UNINSTALLED:
return "Uninstalled"; return "Uninstalled";
case BundleEvent.UNRESOLVED: case BundleEvent.UNRESOLVED:
return "Unresolved"; return "Unresolved";
case BundleEvent.UPDATED: case BundleEvent.UPDATED:
return "Updated"; return "Updated";
} }
return "Unknown"; return "Unknown";
} }
private String getServiceEvent(int type) private String getServiceEvent(int type)
{ {
switch(type) switch(type)
{ {
case ServiceEvent.MODIFIED: case ServiceEvent.MODIFIED:
return "modified"; return "modified";
case ServiceEvent.MODIFIED_ENDMATCH: case ServiceEvent.MODIFIED_ENDMATCH:
return "modified endmatch"; return "modified endmatch";
case ServiceEvent.REGISTERED: case ServiceEvent.REGISTERED:
return "registered"; return "registered";
case ServiceEvent.UNREGISTERING: case ServiceEvent.UNREGISTERING:
return "unregistered"; return "unregistered";
} }
return "Unknown"; return "Unknown";
} }
public void logBundleEvent(BundleEvent be) public void logBundleEvent(BundleEvent be)
{ {
String message = "Bundle state: bundle "+ String message = "Bundle state: bundle "+
be.getBundle().getBundleId()+ be.getBundle().getBundleId()+
" "+ " "+
getBundleEvent(be.getType()); getBundleEvent(be.getType());
insertListLog(message); insertListLog(message);
} }
public void logServiceEvent(ServiceEventMod se) public void logServiceEvent(ServiceEventMod se)
{ {
String message = "Service registry: bundle "+ String message = "Service registry: bundle "+
se.getServiceReference().getBundle().getBundleId()+ se.getServiceReference().getBundle().getBundleId()+
" has "+ " has "+
getServiceEvent(se.getType())+ getServiceEvent(se.getType())+
" a service "+ " a service "+
se.getService().getClass().getName(); se.getService().getClass().getName();
//Only working with this //Only working with this
/*try /*try
{ {
Thread.sleep(10); Thread.sleep(10);
} }
catch (InterruptedException e) catch (InterruptedException e)
{ {
e.printStackTrace(); e.printStackTrace();
}*/ }*/
insertListLog(message); insertListLog(message);
} }
} }

View File

@ -1,102 +1,102 @@
package osgi.bundle.monitoring.dem2.view; package osgi.bundle.monitoring.dem2.view;
import java.util.ArrayList; import java.util.ArrayList;
import javax.swing.JCheckBoxMenuItem; import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu; import javax.swing.JMenu;
import javax.swing.JMenuBar; import javax.swing.JMenuBar;
import osgi.bundle.monitoring.dem2.controller.CheckBoxMenuListener; import osgi.bundle.monitoring.dem2.controller.CheckBoxMenuListener;
public class Menu extends JMenuBar public class Menu extends JMenuBar
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private ArrayList<JCheckBoxMenuItem> checkBoxesMonitor; private ArrayList<JCheckBoxMenuItem> checkBoxesMonitor;
private ArrayList<JCheckBoxMenuItem> checkBoxesStatFilter; private ArrayList<JCheckBoxMenuItem> checkBoxesStatFilter;
private ArrayList<JCheckBoxMenuItem> checkBoxesServFilter; private ArrayList<JCheckBoxMenuItem> checkBoxesServFilter;
public Menu() public Menu()
{ {
checkBoxesMonitor = new ArrayList<JCheckBoxMenuItem>(); checkBoxesMonitor = new ArrayList<JCheckBoxMenuItem>();
checkBoxesStatFilter = new ArrayList<JCheckBoxMenuItem>(); checkBoxesStatFilter = new ArrayList<JCheckBoxMenuItem>();
checkBoxesServFilter = new ArrayList<JCheckBoxMenuItem>(); checkBoxesServFilter = new ArrayList<JCheckBoxMenuItem>();
JMenu monitorMenu, filterMenu, statSubMenu, servSubMenu; JMenu monitorMenu, filterMenu, statSubMenu, servSubMenu;
monitorMenu = new JMenu("Monitors"); monitorMenu = new JMenu("Monitors");
checkBoxesMonitor.add(new JCheckBoxMenuItem("Bundle state")); checkBoxesMonitor.add(new JCheckBoxMenuItem("Bundle state"));
checkBoxesMonitor.add(new JCheckBoxMenuItem("Services")); checkBoxesMonitor.add(new JCheckBoxMenuItem("Services"));
for(JCheckBoxMenuItem checkBox: checkBoxesMonitor) for(JCheckBoxMenuItem checkBox: checkBoxesMonitor)
{ {
monitorMenu.add(checkBox); monitorMenu.add(checkBox);
} }
checkBoxesMonitor.get(0).setState(true); checkBoxesMonitor.get(0).setState(true);
filterMenu = new JMenu("Filters"); filterMenu = new JMenu("Filters");
statSubMenu = new JMenu("Bundle state"); statSubMenu = new JMenu("Bundle state");
servSubMenu = new JMenu("Services"); servSubMenu = new JMenu("Services");
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Installed")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Installed"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Lazy Activation")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Lazy Activation"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Resolved")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Resolved"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Started")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Started"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Starting")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Starting"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Stopped")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Stopped"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Stopping")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Stopping"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Uninstalled")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Uninstalled"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Unresolved")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Unresolved"));
checkBoxesStatFilter.add(new JCheckBoxMenuItem("Updated")); checkBoxesStatFilter.add(new JCheckBoxMenuItem("Updated"));
for(JCheckBoxMenuItem checkBox: checkBoxesStatFilter) for(JCheckBoxMenuItem checkBox: checkBoxesStatFilter)
{ {
statSubMenu.add(checkBox); statSubMenu.add(checkBox);
checkBox.setState(true); checkBox.setState(true);
} }
checkBoxesServFilter.add(new JCheckBoxMenuItem("Modified")); checkBoxesServFilter.add(new JCheckBoxMenuItem("Modified"));
checkBoxesServFilter.add(new JCheckBoxMenuItem("Modified Endmatch")); checkBoxesServFilter.add(new JCheckBoxMenuItem("Modified Endmatch"));
checkBoxesServFilter.add(new JCheckBoxMenuItem("Registered")); checkBoxesServFilter.add(new JCheckBoxMenuItem("Registered"));
checkBoxesServFilter.add(new JCheckBoxMenuItem("Unregistered")); checkBoxesServFilter.add(new JCheckBoxMenuItem("Unregistered"));
for(JCheckBoxMenuItem checkBox: checkBoxesServFilter) for(JCheckBoxMenuItem checkBox: checkBoxesServFilter)
{ {
servSubMenu.add(checkBox); servSubMenu.add(checkBox);
checkBox.setState(true); checkBox.setState(true);
} }
filterMenu.add(statSubMenu); filterMenu.add(statSubMenu);
filterMenu.add(servSubMenu); filterMenu.add(servSubMenu);
add(monitorMenu); add(monitorMenu);
add(filterMenu); add(filterMenu);
} }
public void completeMenu(CheckBoxMenuListener checkBoxMenuListener) public void completeMenu(CheckBoxMenuListener checkBoxMenuListener)
{ {
for(JCheckBoxMenuItem checkBox: checkBoxesMonitor) for(JCheckBoxMenuItem checkBox: checkBoxesMonitor)
{ {
checkBox.addActionListener(checkBoxMenuListener); checkBox.addActionListener(checkBoxMenuListener);
} }
for(JCheckBoxMenuItem checkBox: checkBoxesStatFilter) for(JCheckBoxMenuItem checkBox: checkBoxesStatFilter)
{ {
checkBox.addActionListener(checkBoxMenuListener); checkBox.addActionListener(checkBoxMenuListener);
} }
for(JCheckBoxMenuItem checkBox: checkBoxesServFilter) for(JCheckBoxMenuItem checkBox: checkBoxesServFilter)
{ {
checkBox.addActionListener(checkBoxMenuListener); checkBox.addActionListener(checkBoxMenuListener);
} }
} }
} }

View File

@ -1,64 +1,64 @@
package osgi.bundle.monitoring.dem2.view; package osgi.bundle.monitoring.dem2.view;
import java.awt.Container; import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.GridLayout; import java.awt.GridLayout;
import java.util.ArrayList; import java.util.ArrayList;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.JButton; import javax.swing.JButton;
import osgi.bundle.monitoring.dem2.controller.ButtonListener; import osgi.bundle.monitoring.dem2.controller.ButtonListener;
public class RightPane extends Container public class RightPane extends Container
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private ArrayList<JButton> buttons; private ArrayList<JButton> buttons;
public RightPane() public RightPane()
{ {
setLayout(new GridLayout(15, 1)); setLayout(new GridLayout(15, 1));
buttons = new ArrayList<JButton>(); buttons = new ArrayList<JButton>();
addFillerToYPane(); addFillerToYPane();
addButtonToPane("Install"); addButtonToPane("Install");
addFillerToYPane(); addFillerToYPane();
addButtonToPane("Uninstall"); addButtonToPane("Uninstall");
addFillerToYPane(); addFillerToYPane();
addButtonToPane("Update"); addButtonToPane("Update");
addFillerToYPane(); addFillerToYPane();
addButtonToPane("Start"); addButtonToPane("Start");
addFillerToYPane(); addFillerToYPane();
addButtonToPane("Stop"); addButtonToPane("Stop");
addFillerToYPane(); addFillerToYPane();
addButtonToPane("Monitor"); addButtonToPane("Monitor");
addFillerToYPane(); addFillerToYPane();
addButtonToPane("Unmonitor"); addButtonToPane("Unmonitor");
addFillerToYPane(); addFillerToYPane();
} }
private void addFillerToYPane() private void addFillerToYPane()
{ {
add(Box.createRigidArea(new Dimension(0, 25))); add(Box.createRigidArea(new Dimension(0, 25)));
} }
private void addButtonToPane(String text) private void addButtonToPane(String text)
{ {
JButton button = new JButton(text); JButton button = new JButton(text);
buttons.add(button); buttons.add(button);
add(button); add(button);
} }
public void completeRightPane(ButtonListener buttonListener) public void completeRightPane(ButtonListener buttonListener)
{ {
for(JButton button: buttons) for(JButton button: buttons)
{ {
button.addMouseListener(buttonListener); button.addMouseListener(buttonListener);
} }
} }
} }

View File

@ -1,80 +1,80 @@
package osgi.bundle.monitoring.dem2.view; package osgi.bundle.monitoring.dem2.view;
import java.awt.Dimension; import java.awt.Dimension;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import org.osgi.framework.ServiceEvent; import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceReference;
import osgi.framework.monitoring.event.ServiceEventMod; import osgi.framework.monitoring.event.ServiceEventMod;
public class ServiceTable extends JScrollPane public class ServiceTable extends JScrollPane
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
JTable serviceTable; JTable serviceTable;
private ServiceTableModel tableModel; private ServiceTableModel tableModel;
public ServiceTable(int x, int y) public ServiceTable(int x, int y)
{ {
tableModel = new ServiceTableModel(); tableModel = new ServiceTableModel();
serviceTable = new JTable(tableModel); serviceTable = new JTable(tableModel);
serviceTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); serviceTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
serviceTable.getColumnModel().getColumn(0).setPreferredWidth(225); serviceTable.getColumnModel().getColumn(0).setPreferredWidth(225);
serviceTable.getColumnModel().getColumn(1).setPreferredWidth(75); serviceTable.getColumnModel().getColumn(1).setPreferredWidth(75);
serviceTable.getColumnModel().getColumn(2).setPreferredWidth(200); serviceTable.getColumnModel().getColumn(2).setPreferredWidth(200);
serviceTable.getColumnModel().getColumn(3).setPreferredWidth(100); serviceTable.getColumnModel().getColumn(3).setPreferredWidth(100);
setViewportView(serviceTable); setViewportView(serviceTable);
setPreferredSize(new Dimension(x, y)); setPreferredSize(new Dimension(x, y));
} }
private void addService(ServiceReference<?> reference, String serviceName) private void addService(ServiceReference<?> reference, String serviceName)
{ {
tableModel.insertRow(reference, tableModel.insertRow(reference,
serviceName, serviceName,
reference.getBundle().getBundleId(), reference.getBundle().getBundleId(),
reference.getBundle().getSymbolicName(), reference.getBundle().getSymbolicName(),
reference.getBundle().getVersion().toString()); reference.getBundle().getVersion().toString());
} }
private void modifyService(ServiceReference<?> reference, String serviceName) private void modifyService(ServiceReference<?> reference, String serviceName)
{ {
tableModel.modifyState(reference, tableModel.modifyState(reference,
serviceName, serviceName,
reference.getBundle().getBundleId(), reference.getBundle().getBundleId(),
reference.getBundle().getSymbolicName(), reference.getBundle().getSymbolicName(),
reference.getBundle().getVersion().toString()); reference.getBundle().getVersion().toString());
} }
private void removeService(ServiceReference<?> reference) private void removeService(ServiceReference<?> reference)
{ {
tableModel.deleteRow(reference); tableModel.deleteRow(reference);
} }
public void changeService(ServiceEventMod se) public void changeService(ServiceEventMod se)
{ {
switch(se.getType()) switch(se.getType())
{ {
case ServiceEvent.MODIFIED: case ServiceEvent.MODIFIED:
modifyService(se.getServiceReference(), se.getService().getClass().getName()); modifyService(se.getServiceReference(), se.getService().getClass().getName());
break; break;
case ServiceEvent.MODIFIED_ENDMATCH: case ServiceEvent.MODIFIED_ENDMATCH:
modifyService(se.getServiceReference(), se.getService().getClass().getName()); modifyService(se.getServiceReference(), se.getService().getClass().getName());
break; break;
case ServiceEvent.REGISTERED: case ServiceEvent.REGISTERED:
addService(se.getServiceReference(), se.getService().getClass().getName()); addService(se.getServiceReference(), se.getService().getClass().getName());
break; break;
case ServiceEvent.UNREGISTERING: case ServiceEvent.UNREGISTERING:
removeService(se.getServiceReference()); removeService(se.getServiceReference());
break; break;
} }
} }
} }

View File

@ -1,130 +1,130 @@
package osgi.bundle.monitoring.dem2.view; package osgi.bundle.monitoring.dem2.view;
import java.util.ArrayList; import java.util.ArrayList;
import javax.swing.table.AbstractTableModel; import javax.swing.table.AbstractTableModel;
import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceReference;
public class ServiceTableModel extends AbstractTableModel public class ServiceTableModel extends AbstractTableModel
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String[] columnNames = private String[] columnNames =
{"Service Name", {"Service Name",
"Bundle Id", "Bundle Id",
"Bundle Symbolic Name", "Bundle Symbolic Name",
"Bundle Version" "Bundle Version"
}; };
private ArrayList<ArrayList<Object>> data; private ArrayList<ArrayList<Object>> data;
private ArrayList<ServiceReference<?>> indexServiceList; private ArrayList<ServiceReference<?>> indexServiceList;
public ServiceTableModel() public ServiceTableModel()
{ {
data = new ArrayList<ArrayList<Object>>(); data = new ArrayList<ArrayList<Object>>();
indexServiceList = new ArrayList<ServiceReference<?>>(); indexServiceList = new ArrayList<ServiceReference<?>>();
} }
@Override @Override
public int getColumnCount() public int getColumnCount()
{ {
return columnNames.length; return columnNames.length;
} }
@Override @Override
public int getRowCount() public int getRowCount()
{ {
return data.size(); return data.size();
} }
public String getColumnName(int col) public String getColumnName(int col)
{ {
return columnNames[col]; return columnNames[col];
} }
@Override @Override
public Object getValueAt(int row, int col) public Object getValueAt(int row, int col)
{ {
return data.get(row).get(col); return data.get(row).get(col);
} }
public Class<?> getColumnClass(int col) public Class<?> getColumnClass(int col)
{ {
return getValueAt(0, col).getClass(); return getValueAt(0, col).getClass();
} }
public void setValueAt(Object value, int row, int col) public void setValueAt(Object value, int row, int col)
{ {
if(row == data.size()) if(row == data.size())
{ {
data.add(new ArrayList<Object>()); data.add(new ArrayList<Object>());
data.get(row).add(value); data.get(row).add(value);
data.get(row).add(null); data.get(row).add(null);
data.get(row).add(null); data.get(row).add(null);
data.get(row).add(null); data.get(row).add(null);
fireTableDataChanged(); fireTableDataChanged();
} }
else if(row < data.size()) else if(row < data.size())
{ {
data.get(row).set(col, value); data.get(row).set(col, value);
fireTableCellUpdated(row, col); fireTableCellUpdated(row, col);
} }
} }
public void insertRow(ServiceReference<?> reference, String serviceName, public void insertRow(ServiceReference<?> reference, String serviceName,
long bundleId, String symbolicName, String string) long bundleId, String symbolicName, String string)
{ {
int row = data.size(); int row = data.size();
setValueAt(serviceName, row, 0); setValueAt(serviceName, row, 0);
setValueAt(bundleId, row, 1); setValueAt(bundleId, row, 1);
setValueAt(symbolicName, row, 2); setValueAt(symbolicName, row, 2);
setValueAt(string, row, 3); setValueAt(string, row, 3);
indexServiceList.add(reference); indexServiceList.add(reference);
} }
public void modifyState(ServiceReference<?> reference, String serviceName, public void modifyState(ServiceReference<?> reference, String serviceName,
long bundleId, String symbolicName, String string) long bundleId, String symbolicName, String string)
{ {
int row = indexOfServiceList(reference); int row = indexOfServiceList(reference);
if(row > -1) if(row > -1)
{ {
setValueAt(serviceName, row, 0); setValueAt(serviceName, row, 0);
setValueAt(bundleId, row, 1); setValueAt(bundleId, row, 1);
setValueAt(symbolicName, row, 2); setValueAt(symbolicName, row, 2);
setValueAt(string, row, 3); setValueAt(string, row, 3);
} }
} }
public void deleteRow(ServiceReference<?> reference) public void deleteRow(ServiceReference<?> reference)
{ {
int row = indexOfServiceList(reference); int row = indexOfServiceList(reference);
data.remove(row); data.remove(row);
fireTableDataChanged(); fireTableDataChanged();
indexServiceList.remove(row); indexServiceList.remove(row);
} }
private int indexOfServiceList(ServiceReference<?> unregistered) private int indexOfServiceList(ServiceReference<?> unregistered)
{ {
int index = -1; int index = -1;
for(ServiceReference<?> item: indexServiceList) for(ServiceReference<?> item: indexServiceList)
{ {
if(unregistered.equals(item) == true) if(unregistered.equals(item) == true)
{ {
index = indexServiceList.indexOf(item); index = indexServiceList.indexOf(item);
} }
} }
return index; return index;
} }
} }

View File

@ -1,111 +1,111 @@
package osgi.bundle.monitoring.dem2.view; package osgi.bundle.monitoring.dem2.view;
import java.awt.Container; import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JFrame; import javax.swing.JFrame;
import osgi.bundle.monitoring.dem2.controller.ButtonListener; import osgi.bundle.monitoring.dem2.controller.ButtonListener;
import osgi.bundle.monitoring.dem2.controller.CheckBoxMenuListener; import osgi.bundle.monitoring.dem2.controller.CheckBoxMenuListener;
public class View implements Observer public class View implements Observer
{ {
private JFrame mainFrame; private JFrame mainFrame;
private LeftPane leftPane; private LeftPane leftPane;
private RightPane rightPane; private RightPane rightPane;
private Menu menu; private Menu menu;
public View() public View()
{ {
rightPane = new RightPane(); rightPane = new RightPane();
leftPane = new LeftPane(); leftPane = new LeftPane();
menu = new Menu(); menu = new Menu();
} }
private static void addFillerToXPane(Container pane) private static void addFillerToXPane(Container pane)
{ {
pane.add(Box.createRigidArea(new Dimension(25, 0))); pane.add(Box.createRigidArea(new Dimension(25, 0)));
} }
private void addComponentsToPane(Container pane) private void addComponentsToPane(Container pane)
{ {
pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS)); pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
addFillerToXPane(pane); addFillerToXPane(pane);
pane.add(leftPane); pane.add(leftPane);
addFillerToXPane(pane); addFillerToXPane(pane);
pane.add(rightPane); pane.add(rightPane);
addFillerToXPane(pane); addFillerToXPane(pane);
} }
public void initUi() public void initUi()
{ {
mainFrame = new JFrame("Monitoring System: demonstrator 2"); mainFrame = new JFrame("Monitoring System: demonstrator 2");
mainFrame.setJMenuBar(menu); mainFrame.setJMenuBar(menu);
addComponentsToPane(mainFrame.getContentPane()); addComponentsToPane(mainFrame.getContentPane());
mainFrame.pack(); mainFrame.pack();
mainFrame.setResizable(false); mainFrame.setResizable(false);
mainFrame.setVisible(true); mainFrame.setVisible(true);
} }
public String installDialog() public String installDialog()
{ {
JFileChooser fc = new JFileChooser(); JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(mainFrame); int returnVal = fc.showOpenDialog(mainFrame);
if(returnVal == JFileChooser.APPROVE_OPTION) if(returnVal == JFileChooser.APPROVE_OPTION)
{ {
return fc.getSelectedFile().getName(); return fc.getSelectedFile().getName();
} }
return null; return null;
} }
public void completeUi(ButtonListener buttonListener, CheckBoxMenuListener checkBoxMenuListener) public void completeUi(ButtonListener buttonListener, CheckBoxMenuListener checkBoxMenuListener)
{ {
rightPane.completeRightPane(buttonListener); rightPane.completeRightPane(buttonListener);
menu.completeMenu(checkBoxMenuListener); menu.completeMenu(checkBoxMenuListener);
} }
public long getSelectedBundleId() public long getSelectedBundleId()
{ {
return leftPane.getSelectedBundleId(); return leftPane.getSelectedBundleId();
} }
public void checkMonitoring(long id) public void checkMonitoring(long id)
{ {
leftPane.checkMonitor(id); leftPane.checkMonitor(id);
} }
public void uncheckMonitoring(long id) public void uncheckMonitoring(long id)
{ {
leftPane.uncheckMonitor(id); leftPane.uncheckMonitor(id);
} }
public void close() public void close()
{ {
mainFrame.setVisible(false); mainFrame.setVisible(false);
mainFrame.dispose(); mainFrame.dispose();
} }
@Override @Override
public void update(Observable obs, Object obj) public void update(Observable obs, Object obj)
{ {
leftPane.checkEvent(obj); leftPane.checkEvent(obj);
} }
} }

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -1,28 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>osgi.framework.monitoring</name> <name>osgi.framework.monitoring</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand> <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name> <name>org.eclipse.jdt.core.javabuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name> <name>org.eclipse.pde.ManifestBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name> <name>org.eclipse.pde.SchemaBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.pde.PluginNature</nature> <nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
</natures> </natures>
</projectDescription> </projectDescription>

View File

@ -1,7 +1,7 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7 org.eclipse.jdt.core.compiler.source=1.7

View File

@ -1,4 +1,4 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
pluginProject.equinox=false pluginProject.equinox=false
pluginProject.extensions=false pluginProject.extensions=false
resolve.requirebundle=false resolve.requirebundle=false

View File

@ -1,68 +1,68 @@
package osgi.framework.monitoring.event; package osgi.framework.monitoring.event;
import java.util.EventObject; import java.util.EventObject;
/** /**
* Contains the relevant data of a DataFieldMonitor event * Contains the relevant data of a DataFieldMonitor event
* @author Anibal * @author Anibal
*/ */
public class DataFieldEvent extends EventObject public class DataFieldEvent extends EventObject
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// New field value // New field value
private Object field; private Object field;
// Monitored field's class name // Monitored field's class name
private String className; private String className;
// Monitored field's name // Monitored field's name
private String fieldName; private String fieldName;
/** /**
* Constructor * Constructor
* @param obs observable that raised the event * @param obs observable that raised the event
* @param field monitored field object * @param field monitored field object
* @param className monitored field's class name * @param className monitored field's class name
* @param fieldName monitored field name * @param fieldName monitored field name
*/ */
public DataFieldEvent(Object obs, public DataFieldEvent(Object obs,
Object field, Object field,
String className, String className,
String fieldName) String fieldName)
{ {
super(obs); super(obs);
this.field = field; this.field = field;
this.className = className; this.className = className;
this.fieldName = fieldName; this.fieldName = fieldName;
} }
/** /**
* @return new value of field * @return new value of field
*/ */
public Object getField() public Object getField()
{ {
return field; return field;
} }
/** /**
* @return monitored field's class name * @return monitored field's class name
*/ */
public String getClassName() public String getClassName()
{ {
return className; return className;
} }
/** /**
* @return monitored field name * @return monitored field name
*/ */
public String getFieldName() public String getFieldName()
{ {
return fieldName; return fieldName;
} }
} }

View File

@ -1,124 +1,124 @@
package osgi.framework.monitoring.event; package osgi.framework.monitoring.event;
import java.util.ArrayList; import java.util.ArrayList;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration; import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.hooks.weaving.WeavingHook; import org.osgi.framework.hooks.weaving.WeavingHook;
import osgi.framework.monitoring.event.impl.ClassWeaver; import osgi.framework.monitoring.event.impl.ClassWeaver;
import osgi.framework.monitoring.event.impl.MonitoredField; import osgi.framework.monitoring.event.impl.MonitoredField;
/** /**
* Will monitor different class attributes within a bundle and will raise an * Will monitor different class attributes within a bundle and will raise an
* event if any previously specified primitive data field is modified * event if any previously specified primitive data field is modified
* @author Anibal * @author Anibal
*/ */
public class DataFieldMonitor extends EventMonitor public class DataFieldMonitor extends EventMonitor
{ {
// Contains OSGi ServiceRegistration for DataFieldMonitor necessary // Contains OSGi ServiceRegistration for DataFieldMonitor necessary
// services // services
private ArrayList<ServiceRegistration<?>> serviceRegistration; private ArrayList<ServiceRegistration<?>> serviceRegistration;
// Contains information about monitored field and its classes // Contains information about monitored field and its classes
private ArrayList<MonitoredField> fields; private ArrayList<MonitoredField> fields;
/** /**
* Constructor * Constructor
* @param bundleContext - OSGi BundleContext object * @param bundleContext - OSGi BundleContext object
*/ */
public DataFieldMonitor(BundleContext bundleContext) public DataFieldMonitor(BundleContext bundleContext)
{ {
super(bundleContext); super(bundleContext);
serviceRegistration = new ArrayList<ServiceRegistration<?>>(); serviceRegistration = new ArrayList<ServiceRegistration<?>>();
fields = new ArrayList<MonitoredField>(); fields = new ArrayList<MonitoredField>();
} }
/** /**
* It will specify a new class and field to be monitored * It will specify a new class and field to be monitored
* @param className * @param className
* @param fieldName * @param fieldName
* @return true if the specified data field exists * @return true if the specified data field exists
*/ */
public boolean addDataField(String className, String fieldName) public boolean addDataField(String className, String fieldName)
{ {
if(getIndex(className, fieldName) == -1) if(getIndex(className, fieldName) == -1)
{ {
fields.add(new MonitoredField(className, fieldName)); fields.add(new MonitoredField(className, fieldName));
return true; return true;
} }
return false; return false;
} }
/** /**
* @param className * @param className
* @param fieldName * @param fieldName
* @return position of field in the array * @return position of field in the array
*/ */
private int getIndex(String className, String fieldName) private int getIndex(String className, String fieldName)
{ {
for(int i = 0; i < fields.size(); i++) for(int i = 0; i < fields.size(); i++)
{ {
if(className.compareTo(fields.get(i).getClassName()) == 0) if(className.compareTo(fields.get(i).getClassName()) == 0)
{ {
if(fieldName.compareTo(fields.get(i).getFieldName()) == 0) if(fieldName.compareTo(fields.get(i).getFieldName()) == 0)
{ {
return i; return i;
} }
} }
} }
return -1; return -1;
} }
/** /**
* Registers the necessary services for data field monitor to work. * Registers the necessary services for data field monitor to work.
* Initialize monitoring process * Initialize monitoring process
*/ */
public void registerWeavingService() public void registerWeavingService()
{ {
// DataFieldUpdate will provide an interface that can be used to raise // DataFieldUpdate will provide an interface that can be used to raise
// a DataFieldMonitor event // a DataFieldMonitor event
serviceRegistration.add(super.getBundleContext().registerService( serviceRegistration.add(super.getBundleContext().registerService(
DataFieldUpdate.class.getName(), DataFieldUpdate.class.getName(),
new DataFieldUpdate(this), null)); new DataFieldUpdate(this), null));
// WeavingHook will allow class modifications to insert invocations to // WeavingHook will allow class modifications to insert invocations to
// DataFieldUpdate methods // DataFieldUpdate methods
serviceRegistration.add(super.getBundleContext().registerService( serviceRegistration.add(super.getBundleContext().registerService(
WeavingHook.class.getName(), WeavingHook.class.getName(),
new ClassWeaver(fields), new ClassWeaver(fields),
null)); null));
} }
/** /**
* Unregister the necessary services for data field monitor to work * Unregister the necessary services for data field monitor to work
*/ */
public void unregisterWeavingService() public void unregisterWeavingService()
{ {
for(ServiceRegistration<?> sr: serviceRegistration) for(ServiceRegistration<?> sr: serviceRegistration)
{ {
if(sr != null) if(sr != null)
{ {
sr.unregister(); sr.unregister();
} }
} }
serviceRegistration.clear(); serviceRegistration.clear();
} }
/** /**
* Used to create and raise an event * Used to create and raise an event
* @param field * @param field
* @param className * @param className
* @param fieldName * @param fieldName
*/ */
public void update(Object field, String className, String fieldName) public void update(Object field, String className, String fieldName)
{ {
super.notify(new DataFieldEvent(this, field, className, fieldName)); super.notify(new DataFieldEvent(this, field, className, fieldName));
} }
} }

View File

@ -1,65 +1,65 @@
package osgi.framework.monitoring.event; package osgi.framework.monitoring.event;
/** /**
* This class is registered as a service by DataFieldMonitor, inserted in a * This class is registered as a service by DataFieldMonitor, inserted in a
* weave class by ClassWeaver and invoked by that class when a field value * weave class by ClassWeaver and invoked by that class when a field value
* is modified. It contains the different update functions for the different * is modified. It contains the different update functions for the different
* primitive data types * primitive data types
* @author Anibal * @author Anibal
*/ */
public class DataFieldUpdate public class DataFieldUpdate
{ {
private DataFieldMonitor dfm; private DataFieldMonitor dfm;
public DataFieldUpdate(DataFieldMonitor dfm) public DataFieldUpdate(DataFieldMonitor dfm)
{ {
this.dfm = dfm; this.dfm = dfm;
} }
public void update(Object field, String className, String fieldName) public void update(Object field, String className, String fieldName)
{ {
dfm.update(field, className, fieldName); dfm.update(field, className, fieldName);
} }
public void update(byte field, String className, String fieldName) public void update(byte field, String className, String fieldName)
{ {
dfm.update((Byte)field, className, fieldName); dfm.update((Byte)field, className, fieldName);
} }
public void update(short field, String className, String fieldName) public void update(short field, String className, String fieldName)
{ {
dfm.update((Short)field, className, fieldName); dfm.update((Short)field, className, fieldName);
} }
public void update(int field, String className, String fieldName) public void update(int field, String className, String fieldName)
{ {
dfm.update((Integer)field, className, fieldName); dfm.update((Integer)field, className, fieldName);
} }
public void update(long field, String className, String fieldName) public void update(long field, String className, String fieldName)
{ {
dfm.update((Long)field, className, fieldName); dfm.update((Long)field, className, fieldName);
} }
public void update(float field, String className, String fieldName) public void update(float field, String className, String fieldName)
{ {
dfm.update((Float)field, className, fieldName); dfm.update((Float)field, className, fieldName);
} }
public void update(double field, String className, String fieldName) public void update(double field, String className, String fieldName)
{ {
dfm.update((Double)field, className, fieldName); dfm.update((Double)field, className, fieldName);
} }
public void update(boolean field, String className, String fieldName) public void update(boolean field, String className, String fieldName)
{ {
dfm.update((Boolean)field, className, fieldName); dfm.update((Boolean)field, className, fieldName);
} }
public void update(char field, String className, String fieldName) public void update(char field, String className, String fieldName)
{ {
dfm.update((Character)field, className, fieldName); dfm.update((Character)field, className, fieldName);
} }
} }

View File

@ -1,136 +1,136 @@
package osgi.framework.monitoring.event; package osgi.framework.monitoring.event;
import java.util.EventObject; import java.util.EventObject;
import java.util.Observable; import java.util.Observable;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import osgi.framework.monitoring.event.filter.BundleFilterSet; import osgi.framework.monitoring.event.filter.BundleFilterSet;
import osgi.framework.monitoring.event.filter.IdFilterSet; import osgi.framework.monitoring.event.filter.IdFilterSet;
import osgi.framework.monitoring.event.filter.NameFilterSet; import osgi.framework.monitoring.event.filter.NameFilterSet;
import osgi.framework.monitoring.event.filter.TypeFilterSet; import osgi.framework.monitoring.event.filter.TypeFilterSet;
/** /**
* Abstract class that can be extended to create event based monitor classes. * Abstract class that can be extended to create event based monitor classes.
* It supports type filter set and bundle filter set * It supports type filter set and bundle filter set
* @author Anibal * @author Anibal
*/ */
public abstract class EventMonitor extends Observable public abstract class EventMonitor extends Observable
{ {
//OSGi BundleContext //OSGi BundleContext
BundleContext bundleContext = null; BundleContext bundleContext = null;
TypeFilterSet typeFilterSet = null; TypeFilterSet typeFilterSet = null;
BundleFilterSet bundleFilterSet = null; BundleFilterSet bundleFilterSet = null;
/** /**
* Constructor * Constructor
* @param bundleContext OSGi bundle context * @param bundleContext OSGi bundle context
*/ */
public EventMonitor(BundleContext bundleContext) public EventMonitor(BundleContext bundleContext)
{ {
this.bundleContext = bundleContext; this.bundleContext = bundleContext;
} }
/** /**
* Set a new TypeFilterSet that will control the event flow depending on * Set a new TypeFilterSet that will control the event flow depending on
* the event type * the event type
* @param fs * @param fs
*/ */
public void setTypeFilterSet(TypeFilterSet fs) public void setTypeFilterSet(TypeFilterSet fs)
{ {
typeFilterSet = fs; typeFilterSet = fs;
} }
/** /**
* Get TypeFilterSet * Get TypeFilterSet
* @return null if not previously set * @return null if not previously set
*/ */
public TypeFilterSet getFilterSet() public TypeFilterSet getFilterSet()
{ {
return typeFilterSet; return typeFilterSet;
} }
/** /**
* Set a new BundleFilterSet that will control the event flow depending on * Set a new BundleFilterSet that will control the event flow depending on
* the bundle that raises the event * the bundle that raises the event
* @param fs * @param fs
*/ */
public void setBundleFilterSet(BundleFilterSet fs) public void setBundleFilterSet(BundleFilterSet fs)
{ {
bundleFilterSet = fs; bundleFilterSet = fs;
} }
/** /**
* Get BundleFilterSet * Get BundleFilterSet
* @return null if not previously set * @return null if not previously set
*/ */
public BundleFilterSet getBundleFilterSet() public BundleFilterSet getBundleFilterSet()
{ {
return bundleFilterSet; return bundleFilterSet;
} }
/** /**
* @return OSGi BundleContext * @return OSGi BundleContext
*/ */
public BundleContext getBundleContext() public BundleContext getBundleContext()
{ {
return bundleContext; return bundleContext;
} }
/** /**
* Notify the observers, invoked by the child monitor class itself * Notify the observers, invoked by the child monitor class itself
* @param eo the event generated * @param eo the event generated
*/ */
public void notify(EventObject eo) public void notify(EventObject eo)
{ {
setChanged(); setChanged();
notifyObservers(eo); notifyObservers(eo);
} }
/** /**
* Notify the observers after checking filters, invoked by the monitors * Notify the observers after checking filters, invoked by the monitors
* that support them * that support them
* @param eo * @param eo
* @param type type code of event * @param type type code of event
* @param bundle bundle that raised the event * @param bundle bundle that raised the event
*/ */
public void checkUpdate(EventObject eo, int type, Bundle bundle) public void checkUpdate(EventObject eo, int type, Bundle bundle)
{ {
Boolean notify = true; Boolean notify = true;
// Check if the event meets the TypeFilterSet specifications // Check if the event meets the TypeFilterSet specifications
if(typeFilterSet != null) if(typeFilterSet != null)
{ {
notify = ((TypeFilterSet)typeFilterSet).isOpen(type); notify = ((TypeFilterSet)typeFilterSet).isOpen(type);
} }
// Check if the bundle meets the BundleFilterSet specifications // Check if the bundle meets the BundleFilterSet specifications
if((notify != false) && (bundleFilterSet != null)) if((notify != false) && (bundleFilterSet != null))
{ {
String filterClassName = bundleFilterSet.getClass().getName(); String filterClassName = bundleFilterSet.getClass().getName();
// Check by name // Check by name
if(filterClassName.compareTo(NameFilterSet.class.getName()) == 0) if(filterClassName.compareTo(NameFilterSet.class.getName()) == 0)
{ {
notify = ((NameFilterSet)bundleFilterSet).isOpen(bundle.getSymbolicName()); notify = ((NameFilterSet)bundleFilterSet).isOpen(bundle.getSymbolicName());
} }
// Check by id // Check by id
else if(filterClassName.compareTo(IdFilterSet.class.getName()) == 0) else if(filterClassName.compareTo(IdFilterSet.class.getName()) == 0)
{ {
notify = ((IdFilterSet)bundleFilterSet).isOpen(bundle.getBundleId()); notify = ((IdFilterSet)bundleFilterSet).isOpen(bundle.getBundleId());
} }
} }
if(notify) if(notify)
{ {
notify(eo); notify(eo);
} }
} }
} }

View File

@ -1,74 +1,74 @@
package osgi.framework.monitoring.event; package osgi.framework.monitoring.event;
import java.util.EventObject; import java.util.EventObject;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
/** /**
* Contains the relevant data of a ManifestMonitor event * Contains the relevant data of a ManifestMonitor event
* @author Anibal * @author Anibal
*/ */
public class ManifestEvent extends EventObject public class ManifestEvent extends EventObject
{ {
// CONSTANTS // CONSTANTS
public static final int CREATED = 1; public static final int CREATED = 1;
public static final int MODIFIED = 2; public static final int MODIFIED = 2;
public static final int DELETED = 3; public static final int DELETED = 3;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// Bundle that raised the event // Bundle that raised the event
private Bundle bundle; private Bundle bundle;
// Header that was created, modified or deleted // Header that was created, modified or deleted
private String header; private String header;
// Type of event 1: CREATED, 2: MODIFIED or 3: DELETED // Type of event 1: CREATED, 2: MODIFIED or 3: DELETED
private int type; private int type;
/** /**
* Constructor * Constructor
* @param source observable that raised the event * @param source observable that raised the event
* @param bundle bundle that raised the event * @param bundle bundle that raised the event
* @param header header that was created, modified or deleted * @param header header that was created, modified or deleted
* @param type 1: CREATED, 2: MODIFIED or 3: DELETED * @param type 1: CREATED, 2: MODIFIED or 3: DELETED
*/ */
public ManifestEvent(Object source, public ManifestEvent(Object source,
Bundle bundle, Bundle bundle,
String header, String header,
int type) int type)
{ {
super(source); super(source);
this.bundle = bundle; this.bundle = bundle;
this.header = header; this.header = header;
this.type = type; this.type = type;
} }
/** /**
* @return bundle that raised the event * @return bundle that raised the event
*/ */
public Bundle getBundle() public Bundle getBundle()
{ {
return bundle; return bundle;
} }
/** /**
* @return header that was created, modified or deleted * @return header that was created, modified or deleted
*/ */
public String getHeader() public String getHeader()
{ {
return header; return header;
} }
/** /**
* @return 1: CREATED, 2: MODIFIED or 3: DELETED * @return 1: CREATED, 2: MODIFIED or 3: DELETED
*/ */
public int getType() public int getType()
{ {
return type; return type;
} }
} }

View File

@ -1,242 +1,242 @@
package osgi.framework.monitoring.event; package osgi.framework.monitoring.event;
import java.util.Dictionary; import java.util.Dictionary;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Map; import java.util.Map;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleEvent;
import osgi.framework.monitoring.event.filter.TypeFilterSet; import osgi.framework.monitoring.event.filter.TypeFilterSet;
/** /**
* Will monitor the installed bundles manifest and will raise an event if any * Will monitor the installed bundles manifest and will raise an event if any
* entry of the manifest of any updated bundle is created, modified or deleted * entry of the manifest of any updated bundle is created, modified or deleted
* @author Anibal * @author Anibal
*/ */
public class ManifestMonitor extends EventMonitor implements Observer public class ManifestMonitor extends EventMonitor implements Observer
{ {
// Stores a map with bundle id and its correspondent manifest copies // Stores a map with bundle id and its correspondent manifest copies
Map<Long, Dictionary<String, String>> manifestMap; Map<Long, Dictionary<String, String>> manifestMap;
/** /**
* Constructor. Initialize monitoring process * Constructor. Initialize monitoring process
* @param bundleContext OSGi BundleContext * @param bundleContext OSGi BundleContext
*/ */
public ManifestMonitor(BundleContext bundleContext) public ManifestMonitor(BundleContext bundleContext)
{ {
super(bundleContext); super(bundleContext);
initManifestMap(); initManifestMap();
initObserver(); initObserver();
} }
/** /**
* This method adds the current bundles and manifest copies to the map * This method adds the current bundles and manifest copies to the map
*/ */
private void initManifestMap() private void initManifestMap()
{ {
manifestMap = new HashMap<Long, Dictionary<String, String>>(); manifestMap = new HashMap<Long, Dictionary<String, String>>();
Bundle[] bundles = super.getBundleContext().getBundles(); Bundle[] bundles = super.getBundleContext().getBundles();
for(int i = 0; i < bundles.length; i++) for(int i = 0; i < bundles.length; i++)
{ {
addManifestToMap(bundles[i]); addManifestToMap(bundles[i]);
} }
} }
/** /**
* This method adds a new bundle and its manifest copy to the map * This method adds a new bundle and its manifest copy to the map
* @param bundle * @param bundle
*/ */
private void addManifestToMap(Bundle bundle) private void addManifestToMap(Bundle bundle)
{ {
manifestMap.put(bundle.getBundleId(), manifestMap.put(bundle.getBundleId(),
cloneDictionary(bundle.getHeaders())); cloneDictionary(bundle.getHeaders()));
} }
/** /**
* This method get a manifest and make a copy of it * This method get a manifest and make a copy of it
* @param headers manifest * @param headers manifest
* @return copy of the manifest * @return copy of the manifest
*/ */
private Dictionary<String, String> cloneDictionary( private Dictionary<String, String> cloneDictionary(
Dictionary<String, String> headers) Dictionary<String, String> headers)
{ {
Enumeration<String> keys = headers.keys(); Enumeration<String> keys = headers.keys();
Dictionary<String, String> copy = new Hashtable<String, String>(); Dictionary<String, String> copy = new Hashtable<String, String>();
String header; String header;
while(keys.hasMoreElements()) while(keys.hasMoreElements())
{ {
header = keys.nextElement(); header = keys.nextElement();
copy.put(header, headers.get(header)); copy.put(header, headers.get(header));
} }
return copy; return copy;
} }
/** /**
* This method removes a bundle and manifest copy from the map * This method removes a bundle and manifest copy from the map
* @param bundle * @param bundle
*/ */
private void removeManifestFromMap(Bundle bundle) private void removeManifestFromMap(Bundle bundle)
{ {
manifestMap.remove(bundle.getBundleId()); manifestMap.remove(bundle.getBundleId());
} }
/** /**
* This method initialize the bundle state monitor * This method initialize the bundle state monitor
*/ */
private void initObserver() private void initObserver()
{ {
StateMonitor bsm = new StateMonitor(super.getBundleContext()); StateMonitor bsm = new StateMonitor(super.getBundleContext());
bsm.addObserver(this); bsm.addObserver(this);
} }
/** /**
* Initialize the TypeFilterSet values with ManifestMonitor ones * Initialize the TypeFilterSet values with ManifestMonitor ones
* @param tf * @param tf
*/ */
public void typeFilterSetDefaultConfiguration(TypeFilterSet tf) public void typeFilterSetDefaultConfiguration(TypeFilterSet tf)
{ {
if(tf.size() > 0) if(tf.size() > 0)
{ {
tf.clear(); tf.clear();
} }
tf.addEntry(ManifestEvent.CREATED, false); tf.addEntry(ManifestEvent.CREATED, false);
tf.addEntry(ManifestEvent.MODIFIED, false); tf.addEntry(ManifestEvent.MODIFIED, false);
tf.addEntry(ManifestEvent.DELETED, false); tf.addEntry(ManifestEvent.DELETED, false);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see java.util.Observer#update(java.util.Observable, java.lang.Object) * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
*/ */
@Override @Override
public void update(Observable obs, Object obj) public void update(Observable obs, Object obj)
{ {
int type = ((BundleEvent)obj).getType(); int type = ((BundleEvent)obj).getType();
Bundle bundle = ((BundleEvent)obj).getBundle(); Bundle bundle = ((BundleEvent)obj).getBundle();
// ManifestMonitor uses StateMonitor, and will make different changes // ManifestMonitor uses StateMonitor, and will make different changes
// in its map if there is a change in the state of any bundle. This is // in its map if there is a change in the state of any bundle. This is
// made to keep updated information about installed bundles and its // made to keep updated information about installed bundles and its
// manifest files // manifest files
switch(type) switch(type)
{ {
case BundleEvent.INSTALLED: case BundleEvent.INSTALLED:
addManifestToMap(bundle); addManifestToMap(bundle);
break; break;
case BundleEvent.UPDATED: case BundleEvent.UPDATED:
checkManifestChanges(bundle); checkManifestChanges(bundle);
break; break;
case BundleEvent.UNINSTALLED: case BundleEvent.UNINSTALLED:
removeManifestFromMap(bundle); removeManifestFromMap(bundle);
break; break;
} }
} }
/** /**
* This method raises a ManifestMonitor event * This method raises a ManifestMonitor event
* @param bundle bundle taht raised the event * @param bundle bundle taht raised the event
* @param header header that was created, modified or deleted * @param header header that was created, modified or deleted
* @param type 1: CREATED, 2: MODIFIED or 3: DELETED * @param type 1: CREATED, 2: MODIFIED or 3: DELETED
*/ */
private void raiseEvent(Bundle bundle, String header, int type) private void raiseEvent(Bundle bundle, String header, int type)
{ {
ManifestEvent me = new ManifestEvent(this, bundle, header, type); ManifestEvent me = new ManifestEvent(this, bundle, header, type);
super.checkUpdate(me, type, bundle); super.checkUpdate(me, type, bundle);
} }
/** /**
* This method compares a current bundle manifest with its old version to * This method compares a current bundle manifest with its old version to
* seek for created and modified headers * seek for created and modified headers
* @param bundle * @param bundle
* @param oldManifest * @param oldManifest
* @return * @return
*/ */
private int compareHeaders(Bundle bundle, private int compareHeaders(Bundle bundle,
Dictionary<String, String> oldManifest) Dictionary<String, String> oldManifest)
{ {
int created = 0; int created = 0;
Dictionary<String, String> newManifest = bundle.getHeaders(); Dictionary<String, String> newManifest = bundle.getHeaders();
String header; String header;
Enumeration<String> keys = newManifest.keys(); Enumeration<String> keys = newManifest.keys();
while(keys.hasMoreElements()) while(keys.hasMoreElements())
{ {
header = keys.nextElement(); header = keys.nextElement();
if(oldManifest.get(header) != null) if(oldManifest.get(header) != null)
{ {
if(newManifest.get(header).compareTo(oldManifest.get(header)) != 0) if(newManifest.get(header).compareTo(oldManifest.get(header)) != 0)
{ {
raiseEvent(bundle, header, ManifestEvent.MODIFIED); raiseEvent(bundle, header, ManifestEvent.MODIFIED);
} }
} }
else else
{ {
raiseEvent(bundle, header, ManifestEvent.CREATED); raiseEvent(bundle, header, ManifestEvent.CREATED);
created++; created++;
} }
} }
return newManifest.size() - created; return newManifest.size() - created;
} }
/** /**
* This method compares a current bundle manifest with its old version to * This method compares a current bundle manifest with its old version to
* seek for deleted headers * seek for deleted headers
* @param bundle * @param bundle
* @param oldManifest * @param oldManifest
*/ */
private void checkDeleted(Bundle bundle, private void checkDeleted(Bundle bundle,
Dictionary<String, String> oldManifest) Dictionary<String, String> oldManifest)
{ {
Dictionary<String, String> newManifest = bundle.getHeaders(); Dictionary<String, String> newManifest = bundle.getHeaders();
String header; String header;
Enumeration<String> keys = oldManifest.keys(); Enumeration<String> keys = oldManifest.keys();
while(keys.hasMoreElements()) while(keys.hasMoreElements())
{ {
header = keys.nextElement(); header = keys.nextElement();
if(newManifest.get(header) == null) if(newManifest.get(header) == null)
{ {
raiseEvent(bundle, header, ManifestEvent.DELETED); raiseEvent(bundle, header, ManifestEvent.DELETED);
} }
} }
} }
/** /**
* This method checks updates and changes a manifest to its new version * This method checks updates and changes a manifest to its new version
* if it is necessary * if it is necessary
* @param bundle * @param bundle
*/ */
private void checkManifestChanges(Bundle bundle) private void checkManifestChanges(Bundle bundle)
{ {
long id = bundle.getBundleId(); long id = bundle.getBundleId();
// Old manifest // Old manifest
Dictionary<String, String> oldManifest = manifestMap.get(id); Dictionary<String, String> oldManifest = manifestMap.get(id);
// Check created and modified headers // Check created and modified headers
int size = compareHeaders(bundle, oldManifest); int size = compareHeaders(bundle, oldManifest);
if(size < oldManifest.size()) if(size < oldManifest.size())
{ {
// Check deleted headers // Check deleted headers
checkDeleted(bundle, oldManifest); checkDeleted(bundle, oldManifest);
} }
// Replace manifest // Replace manifest
manifestMap.put(id, bundle.getHeaders()); manifestMap.put(id, bundle.getHeaders());
} }
} }

View File

@ -1,80 +1,80 @@
package osgi.framework.monitoring.event; package osgi.framework.monitoring.event;
import java.util.EventObject; import java.util.EventObject;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
/** /**
* Contains the relevant data of a RepositoryMonitor event * Contains the relevant data of a RepositoryMonitor event
* @author Anibal * @author Anibal
*/ */
public class RepositoryEvent extends EventObject public class RepositoryEvent extends EventObject
{ {
//CONSTANTS //CONSTANTS
public static final int ENTRY_ERROR = 0; public static final int ENTRY_ERROR = 0;
public static final int ENTRY_CREATE = 1; public static final int ENTRY_CREATE = 1;
public static final int ENTRY_MODIFY = 2; public static final int ENTRY_MODIFY = 2;
public static final int ENTRY_DELETE = 3; public static final int ENTRY_DELETE = 3;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// Bundle that raised the event // Bundle that raised the event
private Bundle bundle; private Bundle bundle;
// Type of event ENTRY_ERROR, ENTRY_CREATE, ENTRY_MODIFY or ENTRY_DELETE // Type of event ENTRY_ERROR, ENTRY_CREATE, ENTRY_MODIFY or ENTRY_DELETE
private String name; private String name;
/** /**
* Constructor * Constructor
* @param obj observable that raised the event * @param obj observable that raised the event
* @param bundle bundle that raised the event * @param bundle bundle that raised the event
* @param name 0: ENTRY_ERROR, 1: ENTRY_CREATE, 2: ENTRY_MODIFY or * @param name 0: ENTRY_ERROR, 1: ENTRY_CREATE, 2: ENTRY_MODIFY or
* 3: ENTRY_DELETE * 3: ENTRY_DELETE
*/ */
public RepositoryEvent(Object obj, Bundle bundle, String name) public RepositoryEvent(Object obj, Bundle bundle, String name)
{ {
super(obj); super(obj);
this.bundle = bundle; this.bundle = bundle;
this.name = name; this.name = name;
} }
/** /**
* @return bundle that raised the event * @return bundle that raised the event
*/ */
public Bundle getBundle() public Bundle getBundle()
{ {
return bundle; return bundle;
} }
/** /**
* @return ENTRY_ERROR, ENTRY_CREATE, ENTRY_MODIFY or ENTRY_DELETE * @return ENTRY_ERROR, ENTRY_CREATE, ENTRY_MODIFY or ENTRY_DELETE
*/ */
public String getName() public String getName()
{ {
return name; return name;
} }
/** /**
* @return type 0: ENTRY_ERROR, 1: ENTRY_CREATE, 2: ENTRY_MODIFY or * @return type 0: ENTRY_ERROR, 1: ENTRY_CREATE, 2: ENTRY_MODIFY or
* 3: ENTRY_DELETE * 3: ENTRY_DELETE
*/ */
public int getType() public int getType()
{ {
switch(name) switch(name)
{ {
case "ENTRY_CREATE": case "ENTRY_CREATE":
return ENTRY_CREATE; return ENTRY_CREATE;
case "ENTRY_MODIFY": case "ENTRY_MODIFY":
return ENTRY_MODIFY; return ENTRY_MODIFY;
case "ENTRY_DELETE": case "ENTRY_DELETE":
return ENTRY_DELETE; return ENTRY_DELETE;
} }
return ENTRY_ERROR; return ENTRY_ERROR;
} }
} }

View File

@ -1,85 +1,85 @@
package osgi.framework.monitoring.event; package osgi.framework.monitoring.event;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.WatchEvent; import java.nio.file.WatchEvent;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import osgi.framework.monitoring.event.filter.TypeFilterSet; import osgi.framework.monitoring.event.filter.TypeFilterSet;
import osgi.framework.monitoring.event.impl.DirectoryMonitor; import osgi.framework.monitoring.event.impl.DirectoryMonitor;
/** /**
* Will monitor the bundle repository, and will raise an event if any JAR file * Will monitor the bundle repository, and will raise an event if any JAR file
* of any installed bundle is added, modified (updated) or deleted * of any installed bundle is added, modified (updated) or deleted
* @author Anibal * @author Anibal
*/ */
public class RepositoryMonitor extends EventMonitor implements Observer public class RepositoryMonitor extends EventMonitor implements Observer
{ {
/** /**
* Constructor, initialize monitoring process * Constructor, initialize monitoring process
* @param bundleContext OSGi BundleContext * @param bundleContext OSGi BundleContext
*/ */
public RepositoryMonitor(BundleContext bundleContext) public RepositoryMonitor(BundleContext bundleContext)
{ {
super(bundleContext); super(bundleContext);
initObserver(); initObserver();
} }
/** /**
* Initialize the observation of the current directory in a different * Initialize the observation of the current directory in a different
* thread * thread
*/ */
private void initObserver() private void initObserver()
{ {
//run directory monitor //run directory monitor
DirectoryMonitor dm = new DirectoryMonitor(); DirectoryMonitor dm = new DirectoryMonitor();
Thread myThread = new Thread(dm); Thread myThread = new Thread(dm);
myThread.start(); myThread.start();
dm.addObserver(this); dm.addObserver(this);
} }
/** /**
* Initialize the TypeFilterSet values with RepositoryMonitor ones * Initialize the TypeFilterSet values with RepositoryMonitor ones
* @param tf * @param tf
*/ */
public void typeFilterSetDefaultConfiguration(TypeFilterSet tf) public void typeFilterSetDefaultConfiguration(TypeFilterSet tf)
{ {
if(tf.size() > 0) if(tf.size() > 0)
{ {
tf.clear(); tf.clear();
} }
tf.addEntry(RepositoryEvent.ENTRY_ERROR, false); tf.addEntry(RepositoryEvent.ENTRY_ERROR, false);
tf.addEntry(RepositoryEvent.ENTRY_CREATE, false); tf.addEntry(RepositoryEvent.ENTRY_CREATE, false);
tf.addEntry(RepositoryEvent.ENTRY_MODIFY, false); tf.addEntry(RepositoryEvent.ENTRY_MODIFY, false);
tf.addEntry(RepositoryEvent.ENTRY_DELETE, false); tf.addEntry(RepositoryEvent.ENTRY_DELETE, false);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see java.util.Observer#update(java.util.Observable, java.lang.Object) * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
*/ */
@Override @Override
public void update(Observable obs, Object obj) public void update(Observable obs, Object obj)
{ {
Path fileName = ((Path)((WatchEvent<?>)obj).context()); Path fileName = ((Path)((WatchEvent<?>)obj).context());
Bundle bundle = getBundleContext().getBundle("file:" + fileName); Bundle bundle = getBundleContext().getBundle("file:" + fileName);
// If the changed file corresponds with a bundle JAR file it will raise // If the changed file corresponds with a bundle JAR file it will raise
// an event // an event
if(bundle != null) if(bundle != null)
{ {
RepositoryEvent fe = new RepositoryEvent(this, RepositoryEvent fe = new RepositoryEvent(this,
bundle, bundle,
((WatchEvent<?>)obj).kind().name()); ((WatchEvent<?>)obj).kind().name());
super.checkUpdate(fe, fe.getType(), fe.getBundle()); super.checkUpdate(fe, fe.getType(), fe.getBundle());
} }
} }
} }

View File

@ -1,81 +1,81 @@
package osgi.framework.monitoring.event; package osgi.framework.monitoring.event;
import java.util.EventObject; import java.util.EventObject;
import org.osgi.framework.ServiceEvent; import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceReference;
/** /**
* Contains the relevant data of a ServiceRegistryMod event. OSGi * Contains the relevant data of a ServiceRegistryMod event. OSGi
* ServiceEvent modified to store the Service object * ServiceEvent modified to store the Service object
* @author Anibal * @author Anibal
*/ */
public class ServiceEventMod extends EventObject public class ServiceEventMod extends EventObject
{ {
// CONSTANTS // CONSTANTS
public static final int MODIFIED = ServiceEvent.MODIFIED; public static final int MODIFIED = ServiceEvent.MODIFIED;
public static final int MODIFIED_ENDMATCH = ServiceEvent.MODIFIED_ENDMATCH; public static final int MODIFIED_ENDMATCH = ServiceEvent.MODIFIED_ENDMATCH;
public static final int REGISTERED = ServiceEvent.REGISTERED; public static final int REGISTERED = ServiceEvent.REGISTERED;
public static final int UNREGISTERED = ServiceEvent.UNREGISTERING; public static final int UNREGISTERED = ServiceEvent.UNREGISTERING;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// Type of event 2: MODIFIED, 8:MODIFIED_ENDMATCH, 1: REGISTERED, // Type of event 2: MODIFIED, 8:MODIFIED_ENDMATCH, 1: REGISTERED,
// 4: UNREGISTERED // 4: UNREGISTERED
private int type; private int type;
// Service reference that raised the event // Service reference that raised the event
private ServiceReference<?> reference; private ServiceReference<?> reference;
// Service object that raised the event // Service object that raised the event
private Object service; private Object service;
/** /**
* Constructor * Constructor
* @param source observable that raised the event * @param source observable that raised the event
* @param type 2: MODIFIED, 8:MODIFIED_ENDMATCH, 1: REGISTERED, * @param type 2: MODIFIED, 8:MODIFIED_ENDMATCH, 1: REGISTERED,
* 4: UNREGISTERED * 4: UNREGISTERED
* @param reference service reference that raised the event * @param reference service reference that raised the event
* @param service service object that raised the event * @param service service object that raised the event
*/ */
public ServiceEventMod(Object source, public ServiceEventMod(Object source,
int type, int type,
ServiceReference<?> reference, ServiceReference<?> reference,
Object service) Object service)
{ {
super(source); super(source);
this.type = type; this.type = type;
this.reference = reference; this.reference = reference;
this.service = service; this.service = service;
} }
/** /**
* @return type 2: MODIFIED, 8:MODIFIED_ENDMATCH, 1: REGISTERED, * @return type 2: MODIFIED, 8:MODIFIED_ENDMATCH, 1: REGISTERED,
* 4: UNREGISTERED * 4: UNREGISTERED
*/ */
public int getType() public int getType()
{ {
return type; return type;
} }
/** /**
* @return service reference that raised the event * @return service reference that raised the event
*/ */
public ServiceReference<?> getServiceReference() public ServiceReference<?> getServiceReference()
{ {
return reference; return reference;
} }
/** /**
* @return service object that raised the event * @return service object that raised the event
*/ */
public Object getService() public Object getService()
{ {
return service; return service;
} }
} }

View File

@ -1,66 +1,66 @@
package osgi.framework.monitoring.event; package osgi.framework.monitoring.event;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceEvent; import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener; import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceReference;
import osgi.framework.monitoring.event.filter.TypeFilterSet; import osgi.framework.monitoring.event.filter.TypeFilterSet;
/** /**
* Will will monitor the OSGi service registry and will raise an event if any * Will will monitor the OSGi service registry and will raise an event if any
* service is registered, modified or unregistered * service is registered, modified or unregistered
* @author Anibal * @author Anibal
*/ */
public class ServiceRegistryMonitor public class ServiceRegistryMonitor
extends EventMonitor extends EventMonitor
implements ServiceListener implements ServiceListener
{ {
/** /**
* Constructor. Initialize the monitoring process * Constructor. Initialize the monitoring process
* @param bundleContext OSGi bundle context * @param bundleContext OSGi bundle context
*/ */
public ServiceRegistryMonitor(BundleContext bundleContext) public ServiceRegistryMonitor(BundleContext bundleContext)
{ {
super(bundleContext); super(bundleContext);
bundleContext.addServiceListener(this); bundleContext.addServiceListener(this);
} }
/** /**
* Initialize the TypeFilterSet values with ServiceRegistryMonitor * Initialize the TypeFilterSet values with ServiceRegistryMonitor
* @param tf * @param tf
*/ */
public void typeFilterSetDefaultConfiguration(TypeFilterSet tf) public void typeFilterSetDefaultConfiguration(TypeFilterSet tf)
{ {
if(tf.size() > 0) if(tf.size() > 0)
{ {
tf.clear(); tf.clear();
} }
tf.addEntry(ServiceEvent.MODIFIED, false); tf.addEntry(ServiceEvent.MODIFIED, false);
tf.addEntry(ServiceEvent.MODIFIED_ENDMATCH, false); tf.addEntry(ServiceEvent.MODIFIED_ENDMATCH, false);
tf.addEntry(ServiceEvent.REGISTERED, false); tf.addEntry(ServiceEvent.REGISTERED, false);
tf.addEntry(ServiceEvent.UNREGISTERING, false); tf.addEntry(ServiceEvent.UNREGISTERING, false);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.osgi.framework.ServiceListener#serviceChanged * @see org.osgi.framework.ServiceListener#serviceChanged
* (org.osgi.framework.ServiceEvent) * (org.osgi.framework.ServiceEvent)
*/ */
public void serviceChanged(ServiceEvent se) public void serviceChanged(ServiceEvent se)
{ {
ServiceReference<?> reference = se.getServiceReference(); ServiceReference<?> reference = se.getServiceReference();
ServiceEventMod sem = new ServiceEventMod(this, ServiceEventMod sem = new ServiceEventMod(this,
se.getType(), se.getType(),
reference, reference,
getBundleContext().getService(reference)); getBundleContext().getService(reference));
super.checkUpdate(sem, super.checkUpdate(sem,
se.getType(), se.getType(),
se.getServiceReference().getBundle()); se.getServiceReference().getBundle());
} }
} }

View File

@ -1,59 +1,59 @@
package osgi.framework.monitoring.event; package osgi.framework.monitoring.event;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener; import org.osgi.framework.BundleListener;
import osgi.framework.monitoring.event.filter.TypeFilterSet; import osgi.framework.monitoring.event.filter.TypeFilterSet;
/** /**
* Will raise an event if there is any change in the state of any bundle * Will raise an event if there is any change in the state of any bundle
* @author Anibal * @author Anibal
*/ */
public class StateMonitor extends EventMonitor implements BundleListener public class StateMonitor extends EventMonitor implements BundleListener
{ {
/** /**
* Constructor. Initialize the monitoring process * Constructor. Initialize the monitoring process
* @param bundleContext OSGi BundleContext * @param bundleContext OSGi BundleContext
*/ */
public StateMonitor(BundleContext bundleContext) public StateMonitor(BundleContext bundleContext)
{ {
super(bundleContext); super(bundleContext);
bundleContext.addBundleListener(this); bundleContext.addBundleListener(this);
} }
/** /**
* Initialize the TypeFilterSet values with ServiceRegistryMonitor * Initialize the TypeFilterSet values with ServiceRegistryMonitor
* @param tf * @param tf
*/ */
public void typeFilterSetDefaultConfiguration(TypeFilterSet tf) public void typeFilterSetDefaultConfiguration(TypeFilterSet tf)
{ {
if(tf.size() > 0) if(tf.size() > 0)
{ {
tf.clear(); tf.clear();
} }
tf.addEntry(BundleEvent.INSTALLED, false); tf.addEntry(BundleEvent.INSTALLED, false);
tf.addEntry(BundleEvent.LAZY_ACTIVATION, false); tf.addEntry(BundleEvent.LAZY_ACTIVATION, false);
tf.addEntry(BundleEvent.RESOLVED, false); tf.addEntry(BundleEvent.RESOLVED, false);
tf.addEntry(BundleEvent.STARTED, false); tf.addEntry(BundleEvent.STARTED, false);
tf.addEntry(BundleEvent.STARTING, false); tf.addEntry(BundleEvent.STARTING, false);
tf.addEntry(BundleEvent.STOPPED, false); tf.addEntry(BundleEvent.STOPPED, false);
tf.addEntry(BundleEvent.STOPPING, false); tf.addEntry(BundleEvent.STOPPING, false);
tf.addEntry(BundleEvent.UNINSTALLED, false); tf.addEntry(BundleEvent.UNINSTALLED, false);
tf.addEntry(BundleEvent.UNRESOLVED, false); tf.addEntry(BundleEvent.UNRESOLVED, false);
tf.addEntry(BundleEvent.UPDATED, false); tf.addEntry(BundleEvent.UPDATED, false);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.osgi.framework.BundleListener#bundleChanged * @see org.osgi.framework.BundleListener#bundleChanged
* (org.osgi.framework.BundleEvent) * (org.osgi.framework.BundleEvent)
*/ */
public void bundleChanged(BundleEvent be) public void bundleChanged(BundleEvent be)
{ {
super.checkUpdate(be, be.getType(), be.getBundle()); super.checkUpdate(be, be.getType(), be.getBundle());
} }
} }

View File

@ -1,13 +1,13 @@
package osgi.framework.monitoring.event.filter; package osgi.framework.monitoring.event.filter;
import osgi.framework.monitoring.event.filter.BundleFilterSet; import osgi.framework.monitoring.event.filter.BundleFilterSet;
/** /**
* Classes that inherit form this one filter events depending on the bundle * Classes that inherit form this one filter events depending on the bundle
* that generated it * that generated it
* @author Anibal * @author Anibal
*/ */
public abstract class BundleFilterSet public abstract class BundleFilterSet
{ {
} }

View File

@ -1,54 +1,54 @@
package osgi.framework.monitoring.event.filter; package osgi.framework.monitoring.event.filter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* This class filter events depending on the id bundle that raised it * This class filter events depending on the id bundle that raised it
* @author Anibal * @author Anibal
*/ */
public class IdFilterSet extends BundleFilterSet public class IdFilterSet extends BundleFilterSet
{ {
// Stores id and the correspondent value // Stores id and the correspondent value
Map<Long, Boolean> filter; Map<Long, Boolean> filter;
/** /**
* Constructor * Constructor
*/ */
public IdFilterSet() public IdFilterSet()
{ {
filter = new HashMap<Long, Boolean>(); filter = new HashMap<Long, Boolean>();
} }
/** /**
* It will add or modify the mode (opened or closed) associated with an id * It will add or modify the mode (opened or closed) associated with an id
* bundle. An opened value will allow all events related to that id, while * bundle. An opened value will allow all events related to that id, while
* a closed one will block them * a closed one will block them
* @param idBundle * @param idBundle
* @param mode True: opened, False: closed * @param mode True: opened, False: closed
*/ */
public void addEntry(long idBundle, Boolean mode) public void addEntry(long idBundle, Boolean mode)
{ {
// Adds or modifies // Adds or modifies
filter.put(idBundle, mode); filter.put(idBundle, mode);
} }
/** /**
* Return the value associated with idBundle * Return the value associated with idBundle
* @param idBundle * @param idBundle
* @return mode True: opened, False: closed, null if doesn't exist * @return mode True: opened, False: closed, null if doesn't exist
*/ */
public boolean isOpen(long idBundle) public boolean isOpen(long idBundle)
{ {
Boolean open = filter.get(idBundle); Boolean open = filter.get(idBundle);
if(open == null) if(open == null)
{ {
return true; return true;
} }
return open; return open;
} }
} }

View File

@ -1,54 +1,54 @@
package osgi.framework.monitoring.event.filter; package osgi.framework.monitoring.event.filter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* This class filter events depending on the name of the bundle that raised it * This class filter events depending on the name of the bundle that raised it
* @author Anibal * @author Anibal
*/ */
public class NameFilterSet extends BundleFilterSet public class NameFilterSet extends BundleFilterSet
{ {
// Stores name and correspondent value // Stores name and correspondent value
private Map<String, Boolean> filter; private Map<String, Boolean> filter;
/** /**
* Constructor * Constructor
*/ */
public NameFilterSet() public NameFilterSet()
{ {
filter = new HashMap<String, Boolean>(); filter = new HashMap<String, Boolean>();
} }
/** /**
* It will add or modify the mode (opened or closed) associated with name * It will add or modify the mode (opened or closed) associated with name
* of a bundle. An opened value will allow all events related to that name, * of a bundle. An opened value will allow all events related to that name,
* while a closed one will block them * while a closed one will block them
* @param nameBundle * @param nameBundle
* @param mode True: opened, False: closed * @param mode True: opened, False: closed
*/ */
public void addEntry(String nameBundle, Boolean mode) public void addEntry(String nameBundle, Boolean mode)
{ {
// Adds or modifies // Adds or modifies
filter.put(nameBundle, mode); filter.put(nameBundle, mode);
} }
/** /**
* Return the value associated with nameBundle * Return the value associated with nameBundle
* @param nameBundle * @param nameBundle
* @return mode True: opened, False: closed, null if it doesn't exist * @return mode True: opened, False: closed, null if it doesn't exist
*/ */
public boolean isOpen(String nameBundle) public boolean isOpen(String nameBundle)
{ {
Boolean open = filter.get(nameBundle); Boolean open = filter.get(nameBundle);
if(open == null) if(open == null)
{ {
return true; return true;
} }
return open; return open;
} }
} }

View File

@ -1,102 +1,102 @@
package osgi.framework.monitoring.event.filter; package osgi.framework.monitoring.event.filter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
/** /**
* This class can block or allow events depending on their type * This class can block or allow events depending on their type
* @author Anibal * @author Anibal
*/ */
public class TypeFilterSet public class TypeFilterSet
{ {
// Stores type and corespondent value // Stores type and corespondent value
Map<Integer, Boolean> filter; Map<Integer, Boolean> filter;
/** /**
* Constructor * Constructor
*/ */
public TypeFilterSet() public TypeFilterSet()
{ {
filter = new HashMap<Integer, Boolean>(); filter = new HashMap<Integer, Boolean>();
} }
/** /**
* This method will add or modify the mode (opened or closed) associated * This method will add or modify the mode (opened or closed) associated
* with a type of event. An opened value will allow all events of that * with a type of event. An opened value will allow all events of that
* kind, while a closed one will block them * kind, while a closed one will block them
* @param type * @param type
* @param mode True: opened, False: closed * @param mode True: opened, False: closed
*/ */
public void addEntry(int type, boolean mode) public void addEntry(int type, boolean mode)
{ {
//adds or modifies //adds or modifies
filter.put(type, mode); filter.put(type, mode);
} }
/** /**
* Reset all filter with a specified value * Reset all filter with a specified value
* @param mode value * @param mode value
*/ */
public void resetTypeFilter(boolean mode) public void resetTypeFilter(boolean mode)
{ {
Iterator<Map.Entry<Integer, Boolean>> entries = Iterator<Map.Entry<Integer, Boolean>> entries =
filter.entrySet().iterator(); filter.entrySet().iterator();
Map.Entry<Integer, Boolean> entry; Map.Entry<Integer, Boolean> entry;
while (entries.hasNext()) while (entries.hasNext())
{ {
entry = entries.next(); entry = entries.next();
entry.setValue(mode); entry.setValue(mode);
} }
} }
/** /**
* Reset filter with opened value * Reset filter with opened value
*/ */
public void openTypeFilter() public void openTypeFilter()
{ {
resetTypeFilter(true); resetTypeFilter(true);
} }
/** /**
* Reset filter with closed value * Reset filter with closed value
*/ */
public void closeTypeFilter() public void closeTypeFilter()
{ {
resetTypeFilter(false); resetTypeFilter(false);
} }
/** /**
* Return the value associated with type * Return the value associated with type
* @param type * @param type
* @return mode True: opened, False: closed * @return mode True: opened, False: closed
*/ */
public boolean isOpen(int type) public boolean isOpen(int type)
{ {
Boolean open = filter.get(type); Boolean open = filter.get(type);
if(open == null) if(open == null)
{ {
return true; return true;
} }
return open; return open;
} }
/** /**
* @return size of filter * @return size of filter
*/ */
public int size() public int size()
{ {
return filter.size(); return filter.size();
} }
/** /**
* Remove all entries from filter * Remove all entries from filter
*/ */
public void clear() public void clear()
{ {
filter.clear(); filter.clear();
} }
} }

View File

@ -1,50 +1,50 @@
package osgi.framework.monitoring.event.impl; package osgi.framework.monitoring.event.impl;
import java.util.ArrayList; import java.util.ArrayList;
import javassist.CannotCompileException; import javassist.CannotCompileException;
import javassist.expr.ExprEditor; import javassist.expr.ExprEditor;
import javassist.expr.FieldAccess; import javassist.expr.FieldAccess;
/** /**
* This class edits other classes to call DataFieldUpdate methods where all * This class edits other classes to call DataFieldUpdate methods where all
* modifications of a data field is made * modifications of a data field is made
* @author Anibal * @author Anibal
*/ */
public class ClassEditor extends ExprEditor public class ClassEditor extends ExprEditor
{ {
// Contains all data field names that are going to be edited // Contains all data field names that are going to be edited
private ArrayList<String> fieldsClass; private ArrayList<String> fieldsClass;
// Name of the class that is going to be edited // Name of the class that is going to be edited
private String className; private String className;
/** /**
* @param className name of the class to be edited * @param className name of the class to be edited
* @param fieldsClass all data field names to be edited * @param fieldsClass all data field names to be edited
*/ */
public ClassEditor(String className, ArrayList<String> fieldsClass) public ClassEditor(String className, ArrayList<String> fieldsClass)
{ {
this.className = className; this.className = className;
this.fieldsClass = fieldsClass; this.fieldsClass = fieldsClass;
} }
public void edit(FieldAccess f) throws CannotCompileException public void edit(FieldAccess f) throws CannotCompileException
{ {
// If a modification of a field on the list is made // If a modification of a field on the list is made
if(f.isWriter() && (fieldsClass.contains(f.getFieldName()))) if(f.isWriter() && (fieldsClass.contains(f.getFieldName())))
{ {
// Add after the modification line a call to DataFieldUpdate method // Add after the modification line a call to DataFieldUpdate method
// if that service is previously gotten. The parameters for such // if that service is previously gotten. The parameters for such
// method are the modified field, class name and modified field // method are the modified field, class name and modified field
// name // name
f.replace("$_ = $proceed($$);if(dfu != null) dfu.update("+ f.replace("$_ = $proceed($$);if(dfu != null) dfu.update("+
f.getFieldName()+ f.getFieldName()+
", \""+className+"\", \""+ ", \""+className+"\", \""+
f.getFieldName()+"\");"); f.getFieldName()+"\");");
} }
} }
} }

View File

@ -1,182 +1,182 @@
package osgi.framework.monitoring.event.impl; package osgi.framework.monitoring.event.impl;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javassist.ByteArrayClassPath; import javassist.ByteArrayClassPath;
import javassist.CannotCompileException; import javassist.CannotCompileException;
import javassist.ClassClassPath; import javassist.ClassClassPath;
import javassist.ClassPool; import javassist.ClassPool;
import javassist.CtClass; import javassist.CtClass;
import javassist.CtField; import javassist.CtField;
import javassist.CtMethod; import javassist.CtMethod;
import javassist.NotFoundException; import javassist.NotFoundException;
import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceReference;
import org.osgi.framework.hooks.weaving.*; import org.osgi.framework.hooks.weaving.*;
import osgi.framework.monitoring.event.DataFieldUpdate; import osgi.framework.monitoring.event.DataFieldUpdate;
/** /**
* This class implements the OSGi WeavingHook. WeavingHook must be registered * This class implements the OSGi WeavingHook. WeavingHook must be registered
* as a service to be able to work. It is used to get all classes that are * as a service to be able to work. It is used to get all classes that are
* loaded in the JVM. Then, it modifies previously specified classes to add * loaded in the JVM. Then, it modifies previously specified classes to add
* instrumentation in them. This instrumentation will consist in get the * instrumentation in them. This instrumentation will consist in get the
* DataFieldUpdate service and call the update method if there is any change in * DataFieldUpdate service and call the update method if there is any change in
* previously specified fields * previously specified fields
* @author Anibal * @author Anibal
*/ */
public class ClassWeaver implements WeavingHook public class ClassWeaver implements WeavingHook
{ {
// Contains all fields and correspondent classes that are going to be // Contains all fields and correspondent classes that are going to be
// instrumented // instrumented
private ArrayList<MonitoredField> fields; private ArrayList<MonitoredField> fields;
/** /**
* Constructor * Constructor
* @param fields all data field names and correspondent class names that * @param fields all data field names and correspondent class names that
* are going to be instrumented * are going to be instrumented
*/ */
public ClassWeaver(ArrayList<MonitoredField> fields) public ClassWeaver(ArrayList<MonitoredField> fields)
{ {
this.fields = fields; this.fields = fields;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.osgi.framework.hooks.weaving.WeavingHook#weave * @see org.osgi.framework.hooks.weaving.WeavingHook#weave
* (org.osgi.framework.hooks.weaving.WovenClass) * (org.osgi.framework.hooks.weaving.WovenClass)
*/ */
@Override @Override
public void weave(WovenClass wc) public void weave(WovenClass wc)
{ {
// Get all fields that must be instrumented from this class // Get all fields that must be instrumented from this class
ArrayList<String> fieldsClass = getFieldName(wc.getClassName()); ArrayList<String> fieldsClass = getFieldName(wc.getClassName());
// If not null, means that this is the class and field or fields we are // If not null, means that this is the class and field or fields we are
// looking for // looking for
if(fieldsClass != null) if(fieldsClass != null)
{ {
// Add necessary imports to the bundle // Add necessary imports to the bundle
List<String> imports = wc.getDynamicImports(); List<String> imports = wc.getDynamicImports();
imports.add("osgi.framework.monitoring.event;version=\"1.0.0\""); imports.add("osgi.framework.monitoring.event;version=\"1.0.0\"");
imports.add("javassist.runtime"); imports.add("javassist.runtime");
// Initialize Javassist container of classes // Initialize Javassist container of classes
ClassPool cp = ClassPool.getDefault(); ClassPool cp = ClassPool.getDefault();
cp.appendSystemPath(); cp.appendSystemPath();
// Insert instrumented class // Insert instrumented class
cp.insertClassPath(new ByteArrayClassPath(wc.getClassName(), cp.insertClassPath(new ByteArrayClassPath(wc.getClassName(),
wc.getBytes())); wc.getBytes()));
// Insert OSGi ServiceReference to be able to get services from // Insert OSGi ServiceReference to be able to get services from
// this class // this class
cp.insertClassPath(new ClassClassPath(ServiceReference.class)); cp.insertClassPath(new ClassClassPath(ServiceReference.class));
// Insert DataFieldUpdate, the service that we are going to use to // Insert DataFieldUpdate, the service that we are going to use to
// alert the monitoring framework // alert the monitoring framework
cp.insertClassPath(new ClassClassPath(DataFieldUpdate.class)); cp.insertClassPath(new ClassClassPath(DataFieldUpdate.class));
try try
{ {
// Get the CtClass objects from the pool // Get the CtClass objects from the pool
CtClass cc = cp.get(wc.getClassName()); CtClass cc = cp.get(wc.getClassName());
CtClass srcc = cp.get(ServiceReference.class.getName()); CtClass srcc = cp.get(ServiceReference.class.getName());
CtClass dfmcc = cp.get(DataFieldUpdate.class.getName()); CtClass dfmcc = cp.get(DataFieldUpdate.class.getName());
// New fields for ServiceReference and DataFieldUpdate // New fields for ServiceReference and DataFieldUpdate
CtField srf = new CtField(srcc, "sr", cc); CtField srf = new CtField(srcc, "sr", cc);
CtField dfmf = new CtField(dfmcc, "dfu", cc); CtField dfmf = new CtField(dfmcc, "dfu", cc);
// Add these fields to the instrumented class // Add these fields to the instrumented class
cc.addField(srf); cc.addField(srf);
cc.addField(dfmf); cc.addField(dfmf);
// Get all methods from instrumented class // Get all methods from instrumented class
CtMethod[] behaviors = cc.getDeclaredMethods(); CtMethod[] behaviors = cc.getDeclaredMethods();
// This class will instrument every modification within the // This class will instrument every modification within the
// list of fields // list of fields
ClassEditor classEditor = new ClassEditor(wc.getClassName(), ClassEditor classEditor = new ClassEditor(wc.getClassName(),
fieldsClass); fieldsClass);
// for all methods // for all methods
for(int i = 0; i < behaviors.length; i++) for(int i = 0; i < behaviors.length; i++)
{ {
// Insert in the beginning line to get DataFieldUpdate // Insert in the beginning line to get DataFieldUpdate
// service // service
behaviors[i].insertBefore("sr = org.osgi.framework." + behaviors[i].insertBefore("sr = org.osgi.framework." +
"FrameworkUtil.getBundle(this.getClass())." + "FrameworkUtil.getBundle(this.getClass())." +
"getBundleContext().getServiceReference(osgi." + "getBundleContext().getServiceReference(osgi." +
"framework.monitoring.event.DataFieldUpdate." + "framework.monitoring.event.DataFieldUpdate." +
"class.getName()); if(sr != null) {dfu = ("+ "class.getName()); if(sr != null) {dfu = ("+
DataFieldUpdate.class.getName()+ DataFieldUpdate.class.getName()+
")(org.osgi.framework.FrameworkUtil.getBundle" + ")(org.osgi.framework.FrameworkUtil.getBundle" +
"(this.getClass()).getBundleContext()." + "(this.getClass()).getBundleContext()." +
"getService(sr));}"); "getService(sr));}");
// instrument all fields to call update method within // instrument all fields to call update method within
// DataFieldUpdate service // DataFieldUpdate service
behaviors[i].instrument(classEditor); behaviors[i].instrument(classEditor);
// Insert in the end line to unget DataFieldUpdate service // Insert in the end line to unget DataFieldUpdate service
behaviors[i].insertAfter("if(sr != null) org.osgi." + behaviors[i].insertAfter("if(sr != null) org.osgi." +
"framework.FrameworkUtil.getBundle(this." + "framework.FrameworkUtil.getBundle(this." +
"getClass()).getBundleContext().ungetService(sr);" "getClass()).getBundleContext().ungetService(sr);"
); );
} }
// Transform instrumented class into array of bytes // Transform instrumented class into array of bytes
byte[] b = cc.toBytecode(); byte[] b = cc.toBytecode();
// Detach all used classes from pool // Detach all used classes from pool
cc.detach(); cc.detach();
srcc.detach(); srcc.detach();
dfmcc.detach(); dfmcc.detach();
// Modify instrumented class // Modify instrumented class
wc.setBytes(b); wc.setBytes(b);
} }
catch (NotFoundException e) catch (NotFoundException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
catch (CannotCompileException e) catch (CannotCompileException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
/** /**
* Get fields to be instrumented from a class * Get fields to be instrumented from a class
* @param className * @param className
* @return null if there is there is no correspondence between fields * @return null if there is there is no correspondence between fields
* stored and class name * stored and class name
*/ */
private ArrayList<String> getFieldName(String className) private ArrayList<String> getFieldName(String className)
{ {
ArrayList<String> fieldsClass = new ArrayList<String>(); ArrayList<String> fieldsClass = new ArrayList<String>();
// For all fields to be instrumented // For all fields to be instrumented
for(int i = 0; i < fields.size(); i++) for(int i = 0; i < fields.size(); i++)
{ {
if(className.compareTo(fields.get(i).getClassName()) == 0) if(className.compareTo(fields.get(i).getClassName()) == 0)
{ {
fieldsClass.add(fields.get(i).getFieldName()); fieldsClass.add(fields.get(i).getFieldName());
} }
} }
if(fieldsClass.size() > 0) if(fieldsClass.size() > 0)
{ {
return fieldsClass; return fieldsClass;
} }
else else
{ {
return null; return null;
} }
} }
} }

View File

@ -1,82 +1,82 @@
package osgi.framework.monitoring.event.impl; package osgi.framework.monitoring.event.impl;
import java.io.IOException; import java.io.IOException;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardWatchEventKinds; import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchEvent; import java.nio.file.WatchEvent;
import java.nio.file.WatchKey; import java.nio.file.WatchKey;
import java.nio.file.WatchService; import java.nio.file.WatchService;
import java.util.Observable; import java.util.Observable;
/** /**
* This class performs observation of all changes within a directory * This class performs observation of all changes within a directory
* @author Anibal * @author Anibal
*/ */
public class DirectoryMonitor extends Observable implements Runnable public class DirectoryMonitor extends Observable implements Runnable
{ {
/* (non-Javadoc) /* (non-Javadoc)
* @see java.lang.Runnable#run() * @see java.lang.Runnable#run()
*/ */
@Override @Override
public void run() public void run()
{ {
try try
{ {
monitorDirectory(); monitorDirectory();
} catch (IOException e) } catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} catch (InterruptedException e) } catch (InterruptedException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
} }
/** /**
* This method continuously performs observation of directory changes * This method continuously performs observation of directory changes
* @throws IOException * @throws IOException
* @throws InterruptedException * @throws InterruptedException
*/ */
public void monitorDirectory() throws IOException, InterruptedException public void monitorDirectory() throws IOException, InterruptedException
{ {
// Get running directory // Get running directory
Path tmpPath = Paths.get(System.getProperty("user.dir")); Path tmpPath = Paths.get(System.getProperty("user.dir"));
WatchService watchService = FileSystems.getDefault().newWatchService(); WatchService watchService = FileSystems.getDefault().newWatchService();
// Register service for create, modify and delete operations // Register service for create, modify and delete operations
tmpPath.register( tmpPath.register(
watchService, watchService,
StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_MODIFY,
StandardWatchEventKinds.ENTRY_DELETE); StandardWatchEventKinds.ENTRY_DELETE);
/* /*
* Keep polling for events on the watched directory, * Keep polling for events on the watched directory,
*/ */
while(true) while(true)
{ {
WatchKey key = watchService.take(); WatchKey key = watchService.take();
// Poll all the events queued for the key // Poll all the events queued for the key
for ( WatchEvent<?> event: key.pollEvents()) for ( WatchEvent<?> event: key.pollEvents())
{ {
setChanged(); setChanged();
notifyObservers(event); notifyObservers(event);
} }
// Reset is invoked to put the key back to ready state // Reset is invoked to put the key back to ready state
boolean valid = key.reset(); boolean valid = key.reset();
// If the key is invalid, just exit. // If the key is invalid, just exit.
if ( !valid) if ( !valid)
{ {
break; break;
} }
} }
} }
} }

View File

@ -1,43 +1,43 @@
package osgi.framework.monitoring.event.impl; package osgi.framework.monitoring.event.impl;
/** /**
* This class stores instrumented field data * This class stores instrumented field data
* @author Anibal * @author Anibal
*/ */
public class MonitoredField public class MonitoredField
{ {
// Name of the field's class // Name of the field's class
private String className; private String className;
// Instrumented field name // Instrumented field name
private String fieldName; private String fieldName;
/** /**
* @param className name of the field's class * @param className name of the field's class
* @param fieldName name of the instrumented field * @param fieldName name of the instrumented field
*/ */
public MonitoredField(String className, String fieldName) public MonitoredField(String className, String fieldName)
{ {
this.className = className; this.className = className;
this.fieldName = fieldName; this.fieldName = fieldName;
} }
/** /**
* @return name of the field's class * @return name of the field's class
*/ */
public String getClassName() public String getClassName()
{ {
return className; return className;
} }
/** /**
* @return instrumented field name * @return instrumented field name
*/ */
public String getFieldName() public String getFieldName()
{ {
return fieldName; return fieldName;
} }
} }