Commit f9604268 authored by Jay Jay Billings's avatar Jay Jay Billings
Browse files

Bug 480711 Fixed Reflectivity MatDB bug where the add button broke.



The recent changes caused, for some unknown reason, the
ReflectivityModel Item to no longer receive the IMaterialsDatabase
service. This addresses that problem by catching the service in the core
and reconfiguring the XMLMaterialsDatabase to register directly with an
activator.
Signed-off-by: default avatarJay Jay Billings <billingsjj@ornl.gov>
parent 647569a0
......@@ -25,7 +25,9 @@ Import-Package: com.google.gson;version="2.2.4",
org.eclipse.ice.io.serializable,
org.eclipse.ice.item,
org.eclipse.ice.item.messaging,
org.eclipse.ice.item.model,
org.eclipse.ice.item.persistence,
org.eclipse.ice.materials,
org.eclipse.osgi.service.datalocation;version="1.3.0",
org.osgi.framework,
org.osgi.service.component;version="1.1.0",
......
......@@ -4,4 +4,5 @@
<implementation class="org.eclipse.ice.core.internal.Core"/>
<reference bind="registerCompositeItem" cardinality="0..n" interface="org.eclipse.ice.item.ICompositeItemBuilder" name="ICompositeItemBuilder" policy="dynamic" unbind="unregisterItem"/>
<reference bind="setIOService" cardinality="1..1" interface="org.eclipse.ice.io.serializable.IIOService" name="IIOService" policy="static"/>
<reference cardinality="1..1" interface="org.eclipse.ice.materials.IMaterialsDatabase" name="IMaterialsDatabase" policy="static"/>
</scr:component>
......@@ -53,7 +53,9 @@ import org.eclipse.ice.item.ICompositeItemBuilder;
import org.eclipse.ice.item.ItemBuilder;
import org.eclipse.ice.item.SerializedItemBuilder;
import org.eclipse.ice.item.messaging.Message;
import org.eclipse.ice.item.model.AbstractModelBuilder;
import org.eclipse.ice.item.persistence.IPersistenceProvider;
import org.eclipse.ice.materials.IMaterialsDatabase;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
......@@ -120,6 +122,11 @@ public class Core extends Application implements ICore, BundleActivator {
*/
private ServiceReference<HttpService> httpServiceRef;
/**
* The ServiceReference used to track the Materials Database.
*/
private ServiceReference<IMaterialsDatabase> matDBServiceRef;
/**
* The OSGi HTTP Service used by the Core to publish itself.
*/
......@@ -234,6 +241,9 @@ public class Core extends Application implements ICore, BundleActivator {
// FIXME! Register composite items
// Get and set the Materials Database.
getMaterialsDatabase();
// Tell the ItemManager to suit up. It's time to rock and roll.
itemManager.loadItems(itemDBProject);
......@@ -250,7 +260,21 @@ public class Core extends Application implements ICore, BundleActivator {
}
return;
}
/**
* This operation configures the Materials database.
*/
private void getMaterialsDatabase() {
// Grab the service interface
matDBServiceRef = bundleContext
.getServiceReference(IMaterialsDatabase.class);
// Get the service
IMaterialsDatabase database = bundleContext.getService(matDBServiceRef);
// This should probably be delegated through the ItemManager.
AbstractModelBuilder.setMaterialsDatabase(database);
return;
}
/*
......@@ -269,6 +293,11 @@ public class Core extends Application implements ICore, BundleActivator {
bundleContext.ungetService(httpServiceRef);
}
// Unregister with the Materials Database service
if (matDBServiceRef != null) {
bundleContext.ungetService(matDBServiceRef);
}
// Unregister this service from the framework
registration.unregister();
}
......@@ -637,7 +666,7 @@ public class Core extends Application implements ICore, BundleActivator {
// Local Declaration
Dictionary<String, String> servletParams = new Hashtable<String, String>();
/// Get the service
// Get the service
httpService = bundleContext.getService(httpServiceRef);
// Set the parameters
......
......@@ -599,7 +599,7 @@ public class ItemManager implements ItemListener {
/**
* This operation loads a single Item into the ItemManager, like in
* loadItems(), and returns its Form.
*
*
* @param item
* the persisted Item that will be loaded
* @return the form for the Item or null if the Item couldn't be loaded
......@@ -622,7 +622,7 @@ public class ItemManager implements ItemListener {
/**
* This operation loads Items from a project.
*
*
* @param oldItems
* the persisted Items to load into the ItemManager after they
* have already been read in by an IPersistenceProvider
......@@ -1036,16 +1036,16 @@ public class ItemManager implements ItemListener {
/**
* This operation changes the name of the Item with id itemID.
*
*
* @param itemID
* The id of the item
* The id of the item
* @param name
* The new name of the Item.
* The new name of the Item.
*/
public void renameItem(int itemID, String name) {
itemList.get(itemID).setName(name);
}
/**
* This operation configures the IOService that should be used by Items
*
......
......@@ -37,7 +37,8 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="3.7.100",
org.eclipse.core.filesystem;bundle-version="1.3.200",
org.eclipse.ice.datastructures,
org.eclipse.e4.core.di;bundle-version="1.5.0"
Service-Component: OSGi-INF/*.xml
Service-Component: OSGi-INF/*.xml,
OSGi-INF/materialsDBComponent.xml
Meta-Persistence: META-INF/persistence.xml
JPA-PersistenceUnits: org.eclipse.ice.item
Bundle-ClassPath: .
......
......@@ -6,7 +6,9 @@ bin.includes = META-INF/,\
schema/,\
OSGi-INF/MOOSEIO.xml,\
OSGi-INF/jobLauncherRemote.xml,\
OSGi-INF/mooseModelRemote.xml
OSGi-INF/mooseModelRemote.xml,\
OSGi-INF/materialsDBComponent.xml,\
OSGi-INF/materialsDBComponent.xml
output.. = bin/
src.includes = pom.xml
source.. = src/
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension-point id="IMaterialsDatabase" name="Material Database" schema="schema/IMaterialsDatabase.exsd"/>
<extension-point id="itemBuilder" name="Item Builder" schema="schema/itemBuilder.exsd"/>
<extension-point id="compositeItemBuilder" name="Composite Item Builder" schema="schema/compositeItemBuilder.exsd"/>
<extension
......
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.ice.item" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.eclipse.ice.item" id="IMaterialsDatabase" name="Material Database"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<choice minOccurs="1" maxOccurs="unbounded">
<element ref="Implementation" minOccurs="1" maxOccurs="unbounded"/>
</choice>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="Implementation">
<complexType>
<attribute name="Class" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.ice.materials.IMaterialsDatabase"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>
......@@ -6,7 +6,7 @@
<meta.schema plugin="org.eclipse.ice.item" id="itemBuilder" name="Item Builder"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
This extension point shall provide ItemBuilders for the Eclipse ICE platform.
</documentation>
</annotation>
......@@ -52,7 +52,7 @@
<attribute name="class" type="string">
<annotation>
<documentation>
A class that implements the ItemBuilder interface (or extends one of its implementations) to provide a new builder to Eclipse ICE.
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.ice.item.ItemBuilder"/>
......
......@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation -
* Initial API and implementation and/or initial documentation -
* Jay Jay Billings
*******************************************************************************/
package org.eclipse.ice.item.model;
......@@ -20,9 +20,9 @@ import org.eclipse.ice.materials.IMaterialsDatabase;
/**
* This is a subclass of AbstractItemBuilder specifically focused on adding
* services for Models, which are Items that generate input files or data.
*
*
* @author Jay Jay Billings
*
*
*/
public class AbstractModelBuilder extends AbstractItemBuilder {
......@@ -30,22 +30,22 @@ public class AbstractModelBuilder extends AbstractItemBuilder {
* The materials database that is available to the Model Item and provided,
* usually, by the OSGi Declarative Services Framework.
*/
private IMaterialsDatabase materialsDatabase;
private static IMaterialsDatabase materialsDatabase;
/**
* This operation sets the service reference for the IMaterialsDatabase
* service.
*
*
* @param database
* the service
*/
public void setMaterialsDatabase(IMaterialsDatabase database) {
public static void setMaterialsDatabase(IMaterialsDatabase database) {
materialsDatabase = database;
}
/*
* (non-Javadoc)
*
*
* @see
* org.eclipse.ice.item.AbstractItemBuilder#setServices(org.eclipse.ice.
* item.Item)
......
......@@ -42,9 +42,9 @@ import ca.odell.glazedlists.gui.TableFormat;
* to perform various functions with order-independent tesst, this class only
* has one large operation that tests everything in a way that should be
* consistent with the intended use of the service.
*
*
* @author Jay Jay Billings
*
*
*/
public class XMLMaterialDatabaseTester {
......@@ -212,10 +212,10 @@ public class XMLMaterialDatabaseTester {
// Check the implementation of IElementSource provided by
// the database. Make sure the EventList is correct.
assertEquals(reloadedMaterials.size(), database.getElements()
.size());
assertEquals(reloadedMaterials.get(0), database.getElements()
.get(0));
assertEquals(reloadedMaterials.size(),
database.getElements().size());
assertEquals(reloadedMaterials.get(0),
database.getElements().get(0));
// The table format is checked in detail in its own test, so just
// make sure it isn't null and that it is the right type.
TableFormat format = database.getTableFormat();
......
......@@ -7,10 +7,10 @@
*
* Contributors:
* Jay Jay Billings (UT-Battelle, LLC.) - initial API and implementation and/or initial documentation
*
*
*******************************************************************************/
/**
*
*
*/
package org.eclipse.ice.materials.ui;
......@@ -21,11 +21,11 @@ import org.slf4j.LoggerFactory;
/**
* This is a simple class that catches the active Materials Database service and
* holds the reference for the Materials UI. It is a singleton.
*
*
* This class has no tests because it is a simple bean.
*
*
* @author Jay Jay Billings
*
*
*/
public class MaterialsDatabaseServiceHolder {
......@@ -42,7 +42,7 @@ public class MaterialsDatabaseServiceHolder {
/**
* This operation sets the reference to the service.
*
*
* @param database
* The database service
*/
......@@ -54,8 +54,8 @@ public class MaterialsDatabaseServiceHolder {
/**
* This operation retrieves the reference to the service.
*
* @return
*
* @return The database service
*/
public static IMaterialsDatabase get() {
return materialsDB;
......
......@@ -5,10 +5,9 @@ Bundle-SymbolicName: org.eclipse.ice.materials;singleton:=true
Bundle-Version: 2.1.7.20150825
Bundle-Vendor: Oak Ridge National Laboratory
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Service-Component: OSGI-INF/MaterialDatabase.xml
Import-Package: ca.odell.glazedlists,
ca.odell.glazedlists.gui,
org.eclipse.core.runtime;version="3.4.0",
org.eclipse.core.runtime;version="3.5.0",
org.eclipse.ice.datastructures.ICEObject,
org.eclipse.ice.datastructures.form,
org.osgi.framework;version="1.7.0",
......@@ -17,3 +16,5 @@ Import-Package: ca.odell.glazedlists,
org.osgi.util.tracker;version="1.5.1",
org.slf4j;version="1.7.2"
Export-Package: org.eclipse.ice.materials
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.eclipse.ice.materials.XMLMaterialsDatabase
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" immediate="false" name="org.eclipse.ice.materials">
<implementation class="org.eclipse.ice.materials.XMLMaterialsDatabase"/>
<service>
<provide interface="org.eclipse.ice.materials.IMaterialsDatabase"/>
</service>
</scr:component>
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
id="IMaterialsDatabase"
name="Materkals Database"
point="org.eclipse.ice.item.IMaterialsDatabase">
<Implementation
Class="org.eclipse.ice.materials.XMLMaterialsDatabase">
</Implementation>
</extension>
</plugin>
......@@ -30,9 +30,9 @@ import org.eclipse.ice.datastructures.ICEObject.ICEList;
import org.eclipse.ice.datastructures.form.Material;
import org.eclipse.ice.datastructures.form.MaterialStack;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -54,7 +54,8 @@ import ca.odell.glazedlists.gui.TableFormat;
* @author Jay Jay Billings
*
*/
public class XMLMaterialsDatabase implements IMaterialsDatabase {
public class XMLMaterialsDatabase
implements IMaterialsDatabase, BundleActivator {
/**
* Logger for handling event messages and other information.
......@@ -87,9 +88,10 @@ public class XMLMaterialsDatabase implements IMaterialsDatabase {
protected Hashtable<String, Material> materialsMap;
/**
* The service tracker to track the LoggingService.
* The service registration to publish and unpublish this class as an
* IMaterialsDatabase service.
*/
ServiceTracker logTracker;
private ServiceRegistration<IMaterialsDatabase> registration;
/**
* The constructor
......@@ -206,7 +208,7 @@ public class XMLMaterialsDatabase implements IMaterialsDatabase {
materialsMap.put(material.getName(), material);
}
} catch (JAXBException e) {
logger.error(getClass().getName() + " Exception!",e);
logger.error(getClass().getName() + " Exception!", e);
}
}
......@@ -226,7 +228,7 @@ public class XMLMaterialsDatabase implements IMaterialsDatabase {
jaxbMarshaller.marshal(materialsList, userDatabase);
} catch (JAXBException e) {
System.err.println("XMLMaterialDatabase: Error writing database!");
logger.error(getClass().getName() + " Exception!",e);
logger.error(getClass().getName() + " Exception!", e);
}
}
......@@ -253,23 +255,16 @@ public class XMLMaterialsDatabase implements IMaterialsDatabase {
// Create the JAXB context to manipulate the files
try {
jaxbContext = JAXBContext
.newInstance(ICEList.class, Material.class, MaterialStack.class);
jaxbContext = JAXBContext.newInstance(ICEList.class, Material.class,
MaterialStack.class);
} catch (JAXBException e) {
// Complain to the logger service
if (logger != null) {
logger.error("Unable to initialize JAXB!",
e);
} else {
logger.error(getClass().getName() + " Exception!",e);
}
logger.error("Unable to initialize JAXB!", e);
}
// Choose which database to load
if (userDatabase.exists()) {
if (logger != null) {
logger.info("Loading user-modified database.");
}
logger.info("Loading user-modified database.");
fileToLoad = userDatabase;
} else {
fileToLoad = defaultDatabase;
......@@ -277,10 +272,9 @@ public class XMLMaterialsDatabase implements IMaterialsDatabase {
// Load it up and throw some info in the log
loadDatabase(fileToLoad);
if (logger != null) {
logger.info("Started!");
}
logger.info("Started!");
return;
}
/**
......@@ -290,30 +284,34 @@ public class XMLMaterialsDatabase implements IMaterialsDatabase {
* @param context
* The component context
*/
public void start(ComponentContext context) {
@Override
public void start(BundleContext context) {
try {
// Get the file URLs from from the bundle
BundleContext bundleContext = context.getBundleContext();
Bundle bundle = bundleContext.getBundle();
URL userDBURL = bundle.getEntry("data/userMatDB.xml");
URL defaultDBURL = bundle.getEntry("data/defaultMatDB.xml");
// Set the file references by converting the bundle:// URLs to
// file:// URLs.
userDatabase = new File(FileLocator.toFileURL(userDBURL).getPath());
defaultDatabase = new File(FileLocator.toFileURL(defaultDBURL)
.getPath());
// Once the files are set, just call the other start operation
start();
if (context != null) {
Bundle bundle = context.getBundle();
URL userDBURL = bundle.getEntry("data/userMatDB.xml");
URL defaultDBURL = bundle.getEntry("data/defaultMatDB.xml");
// Set the file references by converting the bundle:// URLs to
// file:// URLs.
userDatabase = new File(
FileLocator.toFileURL(userDBURL).getPath());
defaultDatabase = new File(
FileLocator.toFileURL(defaultDBURL).getPath());
// Once the files are set, just call the other start operation
start();
// Register the service
registration = context.registerService(IMaterialsDatabase.class,
this, null);
}
} catch (IOException e) {
// Complain
if (logger != null) {
logger.error("Unable to start the XMLPersistence service!", e);
} else {
logger.error(getClass().getName() + " Exception!",e);
}
logger.error("Unable to start the XMLPersistence service!", e);
}
return;
}
/**
......@@ -324,10 +322,27 @@ public class XMLMaterialsDatabase implements IMaterialsDatabase {
// Write the database
writeDatabase();
if (logger != null) {
logger.info("Service stopped!");
}
logger.info("Service stopped!");