Commit 1cd1a453 authored by Alex McCaskey's avatar Alex McCaskey
Browse files

Committing new architecture for extending the way the


XMLPersistenceProvider persists our data structures. 

1. Added IJAXBClassProvider and ICEJAXBClassProvider implementation.
This interface exposes a getClasses() : Class[*] method that can be used
by the XMLPersistenceProvider to expose all relevant Classes when
creating the JAXBContext. 
2. Added registerClassProvider() method to XMLPersistenceProvider and
exposed it to the OSGi DS so that IJAXBClassProviders can be added and
used during XML persistence. 
3. Updated the Form JAXB annotations to not directly reference Component
realizations. 
4. Implemented tests for this new functionality and updated all tests
affected by this.
Signed-off-by: default avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent edac02fd
......@@ -25,6 +25,11 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
......
......@@ -4,6 +4,7 @@ Bundle-Name: ICEDataStructures
Bundle-SymbolicName: org.eclipse.ice.datastructures
Bundle-Version: 2.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Service-Component: OSGI-INF/*.xml
Meta-Persistence: META-INF/persistence.xml
Export-Package: org.eclipse.ice.datastructures.ICEObject,
org.eclipse.ice.datastructures.componentVisitor,
......@@ -13,6 +14,7 @@ Export-Package: org.eclipse.ice.datastructures.ICEObject,
org.eclipse.ice.datastructures.form.iterator,
org.eclipse.ice.datastructures.form.mesh,
org.eclipse.ice.datastructures.form.painfullySimpleForm,
org.eclipse.ice.datastructures.jaxbclassprovider,
org.eclipse.ice.datastructures.resource
Import-Package: ca.odell.glazedlists,
ca.odell.glazedlists.event,
......@@ -29,3 +31,4 @@ Import-Package: ca.odell.glazedlists,
Bundle-ActivationPolicy: lazy
JPA-PersistenceUnits: org.eclipse.ice.datastructures
Require-Bundle: ca.odell.glazedlists;bundle-version="1.9.0";visibility:=reexport
Service-Component: OSGI-INF/jaxbclassprovider.xml
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="ICE JAXB Class Provider">
<implementation class="org.eclipse.ice.datastructures.jaxbclassprovider.ICEJAXBClassProvider"/>
<service>
<provide interface="org.eclipse.ice.datastructures.jaxbclassprovider.IJAXBClassProvider"/>
</service>
</scr:component>
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
.,\
OSGI-INF/jaxbclassprovider.xml
src.includes = META-INF/,\
src/
source.. = src/
......@@ -17,8 +17,7 @@ import java.util.ArrayList;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementRefs;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.ice.datastructures.ICEObject.Component;
......@@ -26,11 +25,7 @@ import org.eclipse.ice.datastructures.ICEObject.Composite;
import org.eclipse.ice.datastructures.ICEObject.IUpdateableListener;
import org.eclipse.ice.datastructures.ICEObject.Identifiable;
import org.eclipse.ice.datastructures.ICEObject.ICEObject;
import org.eclipse.ice.datastructures.ICEObject.ListComponent;
import org.eclipse.ice.datastructures.componentVisitor.IComponentVisitor;
import org.eclipse.ice.datastructures.form.emf.EMFComponent;
import org.eclipse.ice.datastructures.form.geometry.GeometryComponent;
import org.eclipse.ice.datastructures.form.mesh.MeshComponent;
/**
* <!-- begin-UML-doc -->
......@@ -79,19 +74,8 @@ public class Form extends ICEObject implements Composite {
* @generated
* "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
*/
@XmlAnyElement()
@XmlElementRefs(value = {
@XmlElementRef(name = "ResourceComponent", type = ResourceComponent.class),
@XmlElementRef(name = "TableComponent", type = TableComponent.class),
@XmlElementRef(name = "MatrixComponent", type = MatrixComponent.class),
@XmlElementRef(name = "GeometryComponent", type = GeometryComponent.class),
@XmlElementRef(name = "MasterDetailsComponent", type = MasterDetailsComponent.class),
@XmlElementRef(name = "TimeDataComponent", type = TimeDataComponent.class),
@XmlElementRef(name = "DataComponent", type = DataComponent.class),
@XmlElementRef(name = "TreeComposite", type = TreeComposite.class),
@XmlElementRef(name = "MeshComponent", type = MeshComponent.class),
@XmlElementRef(name = "ListComponent", type = ListComponent.class),
@XmlElementRef(name = "EMFComponent", type = EMFComponent.class)})
@XmlElementWrapper
@XmlAnyElement(lax=true)
private ArrayList<Component> componentList;
/**
......@@ -119,7 +103,6 @@ public class Form extends ICEObject implements Composite {
* @generated
* "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
*/
protected boolean canProcess = true;
/**
......
/*******************************************************************************
* Copyright (c) 2013, 2014 UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation - Jay Jay Billings,
* Jordan H. Deyton, Dasha Gorin, Alexander J. McCaskey, Taylor Patterson,
* Claire Saunders, Matthew Wang, Anna Wojtowicz
*******************************************************************************/
package org.eclipse.ice.datastructures.jaxbclassprovider;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.ice.datastructures.ICEObject.ListComponent;
import org.eclipse.ice.datastructures.form.DataComponent;
import org.eclipse.ice.datastructures.form.MatrixComponent;
import org.eclipse.ice.datastructures.form.ResourceComponent;
import org.eclipse.ice.datastructures.form.TableComponent;
import org.eclipse.ice.datastructures.form.TimeDataComponent;
import org.eclipse.ice.datastructures.form.TreeComposite;
import org.eclipse.ice.datastructures.form.emf.EMFComponent;
import org.eclipse.ice.datastructures.form.geometry.GeometryComponent;
import org.eclipse.ice.datastructures.form.mesh.MeshComponent;
/**
* The ICEJAXBClassProvider is a realization of the IJAXBClassProvider that
* provides a list of classes that the XMLPersistenceProvider's JAXBContext must be
* aware of when marshalling/unmarshalling ICE data structures.
*
* @author Alex McCaskey
*
*/
public class ICEJAXBClassProvider implements IJAXBClassProvider {
/**
* (non-Javadoc)
* @see org.eclipse.ice.persistence.xml.IJAXBClassProvider#getClasses()
*/
@Override
public List<Class> getClasses() {
// Create the return list of classes.
List<Class> classList = new ArrayList<Class>();
// Add the classes needed for XML persistence
classList.add(ResourceComponent.class);
classList.add(TableComponent.class);
classList.add(MatrixComponent.class);
classList.add(GeometryComponent.class);
classList.add(TimeDataComponent.class);
classList.add(DataComponent.class);
classList.add(TreeComposite.class);
classList.add(MeshComponent.class);
classList.add(ListComponent.class);
classList.add(EMFComponent.class);
return classList;
}
/**
* (non-Javadoc)
* @see org.eclipse.ice.persistence.xml.IJAXBClassProvider#getProviderName()
*/
@Override
public String getProviderName() {
return "ICE JAXB Class Provider";
}
}
/*******************************************************************************
* Copyright (c) 2013, 2014 UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation - Jay Jay Billings,
* Jordan H. Deyton, Dasha Gorin, Alexander J. McCaskey, Taylor Patterson,
* Claire Saunders, Matthew Wang, Anna Wojtowicz
*******************************************************************************/
package org.eclipse.ice.datastructures.jaxbclassprovider;
import java.util.List;
/**
* The IJAXBClassProvider interface provides the methods necessary to inform
* clients creating a JAXBContext object of the relevant classes that must be
* known for succesfull marshalling/unmarshalling of XML data.
*
* Realizations of this interface must provide a valid name String that
* describes the realization and a valid set of Java Class objects representing
* the JAXB-annotated structures the JAXBContext must know about.
*
*
* @author Alex McCaskey
*
*/
public interface IJAXBClassProvider {
/**
* Return the list of Classes that will be required in the creation of a
* JAXBContext.
*
* @return classList The list of Classes used in creating a JAXBContext
* object.
*/
public List<Class> getClasses();
/**
* Return the name of this IJAXBClassProvider.
*
* @return providerName The name of this IJAXBClassProvider
*/
public String getProviderName();
}
......@@ -7,4 +7,5 @@
<provide interface="org.eclipse.ice.io.serializable.IReader"/>
</service>
<reference bind="addBuilder" cardinality="1..n" interface="org.eclipse.ice.item.ItemBuilder" name="ItemBuilder" policy="dynamic"/>
<reference bind="registerClassProvider" cardinality="1..n" interface="org.eclipse.ice.datastructures.jaxbclassprovider.IJAXBClassProvider" name="IJAXBClassProvider" policy="dynamic"/>
</scr:component>
......@@ -18,6 +18,7 @@ import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
......@@ -45,6 +46,7 @@ import org.eclipse.ice.core.iCore.IPersistenceProvider;
import org.eclipse.ice.datastructures.form.Entry;
import org.eclipse.ice.datastructures.form.Form;
import org.eclipse.ice.datastructures.form.Material;
import org.eclipse.ice.datastructures.jaxbclassprovider.IJAXBClassProvider;
/**
* This class implements the IPersistenceProvider interface using the native XML
......@@ -147,6 +149,12 @@ public class XMLPersistenceProvider implements IPersistenceProvider, Runnable,
*/
private Hashtable<Integer, String> itemIdMap = new Hashtable<Integer, String>();
/**
* The list of IJAXBClassProviders to be used in the construction of the
* JAXBContext.
*/
private List<IJAXBClassProvider> classProviders;
/**
* The JAXBContext that is used to create (un)marshalling tools for the XML
* files.
......@@ -157,6 +165,7 @@ public class XMLPersistenceProvider implements IPersistenceProvider, Runnable,
* Empty default constructor. No work to do.
*/
public XMLPersistenceProvider() {
classProviders = new ArrayList<IJAXBClassProvider>();
}
/**
......@@ -167,9 +176,29 @@ public class XMLPersistenceProvider implements IPersistenceProvider, Runnable,
* The project space that should be used instead of the default.
*/
public XMLPersistenceProvider(IProject projectSpace) {
classProviders = new ArrayList<IJAXBClassProvider>();
project = projectSpace;
}
/**
* This operation registers an IJAXBClassProvider with the persistence
* provider.
*
* @param provider
* The IJAXBClassProvider to be used in creation of the
* JAXBContext.
*/
public void registerClassProvider(IJAXBClassProvider provider) {
if (provider != null) {
System.out
.println("[XMLPersistenceProvider] Adding Class Provider "
+ provider.getProviderName());
classProviders.add(provider);
}
return;
}
/**
* This operation loads the Item id map with the contents of the project
* space.
......@@ -274,6 +303,13 @@ public class XMLPersistenceProvider implements IPersistenceProvider, Runnable,
// component so it will not get added to the class list when the Form is
// read from all of the Items above.
classList.add(Material.class);
// Now add all Classes provided by the registered
// IJAXBClassProviders.
for (IJAXBClassProvider provider : classProviders) {
classList.addAll(provider.getClasses());
}
// Create new JAXB class context and unmarshaller
context = JAXBContext.newInstance(classList.toArray(classArray));
}
......
......@@ -18,6 +18,7 @@ import org.eclipse.ice.datastructures.form.Entry;
import org.eclipse.ice.datastructures.form.Form;
import org.eclipse.ice.datastructures.form.FormStatus;
import org.eclipse.ice.datastructures.form.emf.ICEXMLProcessor;
import org.eclipse.ice.datastructures.jaxbclassprovider.ICEJAXBClassProvider;
import org.eclipse.ice.item.Item;
import org.eclipse.ice.item.ItemType;
......@@ -250,6 +251,7 @@ public class PROTEUSModel extends Item {
// Try to get the Form from it
ArrayList<Class> classList = new ArrayList<Class>();
classList.add(Form.class);
classList.addAll(new ICEJAXBClassProvider().getClasses());
ICEJAXBHandler handler = new ICEJAXBHandler();
try {
form = (Form) handler.read(classList, specFile.getContents());
......
......@@ -20,6 +20,7 @@ Import-Package: ca.odell.glazedlists,
org.eclipse.ice.datastructures.form.iterator,
org.eclipse.ice.datastructures.form.mesh,
org.eclipse.ice.datastructures.form.painfullySimpleForm,
org.eclipse.ice.datastructures.jaxbclassprovider,
org.eclipse.ice.datastructures.resource,
org.osgi.framework;version="1.6.0",
org.osgi.util.tracker;version="1.5.0"
......
......@@ -32,6 +32,7 @@ import org.eclipse.ice.datastructures.form.ResourceComponent;
import org.eclipse.ice.datastructures.form.ResourceComponent;
import org.eclipse.ice.datastructures.form.DataComponent;
import org.eclipse.ice.datastructures.form.mesh.Edge;
import org.eclipse.ice.datastructures.jaxbclassprovider.ICEJAXBClassProvider;
import org.eclipse.ice.datastructures.resource.ICEResource;
/**
......@@ -577,7 +578,10 @@ public class FormTester {
ICEJAXBHandler xmlHandler = new ICEJAXBHandler();
ArrayList<Class> classList = new ArrayList<Class>();
classList.add(Form.class);
// Inform the JAXBContext of all relevant classes.
classList.addAll(new ICEJAXBClassProvider().getClasses());
DataComponent dataComponent = new DataComponent();
DataComponent dataComponent2 = new DataComponent();
Entry entry1 = new Entry();
......
/*******************************************************************************
* Copyright (c) 2013, 2014 UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation - Jay Jay Billings,
* Jordan H. Deyton, Dasha Gorin, Alexander J. McCaskey, Taylor Patterson,
* Claire Saunders, Matthew Wang, Anna Wojtowicz
*******************************************************************************/
package org.eclipse.ice.datastructures.test;
import static org.junit.Assert.*;
import java.util.List;
import org.eclipse.ice.datastructures.ICEObject.ListComponent;
import org.eclipse.ice.datastructures.form.DataComponent;
import org.eclipse.ice.datastructures.form.MatrixComponent;
import org.eclipse.ice.datastructures.form.ResourceComponent;
import org.eclipse.ice.datastructures.form.TableComponent;
import org.eclipse.ice.datastructures.form.TimeDataComponent;
import org.eclipse.ice.datastructures.form.TreeComposite;
import org.eclipse.ice.datastructures.form.emf.EMFComponent;
import org.eclipse.ice.datastructures.form.geometry.GeometryComponent;
import org.eclipse.ice.datastructures.form.mesh.MeshComponent;
import org.eclipse.ice.datastructures.jaxbclassprovider.ICEJAXBClassProvider;
import org.eclipse.ice.datastructures.jaxbclassprovider.IJAXBClassProvider;
import org.junit.Test;
/**
* This class tests the ICEJAXBClassProvider. Specifically,
* it checks that the correct classes are created and returned by
* its IJAXBClassProvider.getClasses() method.
*
* @author Alex McCaskey
*
*/
public class ICEJAXBClassProviderTester {
/**
* Reference to the IJAXBClassProvider we are testing
*/
private IJAXBClassProvider provider;
/**
* This method checks that we can get a valid set of
* Classes from the ICEJAXBClassProvider.
*/
@Test
public void checkClassList() {
// Create the class provider
provider = new ICEJAXBClassProvider();
// Check the name
assertTrue("ICE JAXB Class Provider".equals(provider.getProviderName()));
// Get the list of classes, make sure its
// not null, and make sure we have 10 of them
List<Class> classList = provider.getClasses();
assertNotNull(classList);
assertEquals(10, classList.size());
// Check that all the correct ones are there.
assertTrue(classList.contains(ResourceComponent.class));
assertTrue(classList.contains(TableComponent.class));
assertTrue(classList.contains(MatrixComponent.class));
assertTrue(classList.contains(GeometryComponent.class));
assertTrue(classList.contains(TimeDataComponent.class));
assertTrue(classList.contains(DataComponent.class));
assertTrue(classList.contains(TreeComposite.class));
assertTrue(classList.contains(MeshComponent.class));
assertTrue(classList.contains(ListComponent.class));
assertTrue(classList.contains(EMFComponent.class));
}
}
......@@ -42,6 +42,7 @@ import org.eclipse.ice.datastructures.form.DataComponent;
import org.eclipse.ice.datastructures.form.Entry;
import org.eclipse.ice.datastructures.form.Form;
import org.eclipse.ice.datastructures.form.FormStatus;
import org.eclipse.ice.datastructures.jaxbclassprovider.ICEJAXBClassProvider;
import org.eclipse.ice.datastructures.resource.ICEResource;
import org.eclipse.ice.datastructures.resource.VizResource;
import org.eclipse.ice.io.serializable.IOService;
......@@ -739,7 +740,8 @@ public class ItemTester implements ItemListener {
ICEJAXBHandler xmlHandler = new ICEJAXBHandler();
ArrayList<Class> classList = new ArrayList<Class>();
classList.add(Item.class);
classList.addAll(new ICEJAXBClassProvider().getClasses());
// Setup the project
try {
// Get the project handle
......@@ -774,6 +776,7 @@ public class ItemTester implements ItemListener {
IOService ioService = new IOService();
XMLPersistenceProvider xmlpp = new XMLPersistenceProvider(project);
xmlpp.addBuilder(new TestItemBuilder());
xmlpp.registerClassProvider(new ICEJAXBClassProvider());
xmlpp.start();
ioService.addWriter(xmlpp);
item.setIOService(ioService);
......
......@@ -43,6 +43,7 @@ import org.eclipse.ice.datastructures.form.MatrixComponent;
import org.eclipse.ice.datastructures.form.geometry.IShape;
import org.eclipse.ice.datastructures.form.mesh.MeshComponent;
import org.eclipse.ice.datastructures.form.Entry;
import org.eclipse.ice.datastructures.jaxbclassprovider.ICEJAXBClassProvider;
import org.eclipse.ice.item.Item;
import org.eclipse.ice.item.jobLauncher.JobLauncherForm;
......@@ -526,7 +527,8 @@ public class JobLauncherFormTester implements IComponentVisitor {
ICEJAXBHandler xmlHandler = new ICEJAXBHandler();
ArrayList<Class> classList = new ArrayList<Class>();
classList.add(JobLauncherForm.class);
classList.addAll(new ICEJAXBClassProvider().getClasses());
// Setup a JobLauncherForm
jobForm.setName("I AM NEW!");
jobForm.setDescription("Oh Somewhat NEW?!");
......
......@@ -37,6 +37,7 @@ import org.eclipse.ice.datastructures.form.Entry;
import org.eclipse.ice.datastructures.form.Form;
import org.eclipse.ice.datastructures.form.FormStatus;
import org.eclipse.ice.datastructures.form.TableComponent;
import org.eclipse.ice.datastructures.jaxbclassprovider.ICEJAXBClassProvider;
import org.eclipse.ice.item.Item;
import org.eclipse.ice.item.action.LoginInfoForm;
import org.eclipse.ice.item.jobLauncher.JobLauncher;
......@@ -736,7 +737,8 @@ public class JobLauncherTester {
ICEJAXBHandler xmlHandler = new ICEJAXBHandler();
ArrayList<Class> classList = new ArrayList<Class>();
classList.add(JobLauncher.class);
classList.addAll(new ICEJAXBClassProvider().getClasses());
// Set up item
JobLauncher persistedItem = new JobLauncher();
persistedItem.setDescription("JobLauncher item description");
......
......@@ -39,6 +39,7 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.ice.caebat.kvPair.CAEBATKVPairBuilder;
import org.eclipse.ice.datastructures.form.Form;
import org.eclipse.ice.datastructures.jaxbclassprovider.ICEJAXBClassProvider;
import org.eclipse.ice.item.Item;
import org.eclipse.ice.item.nuclear.MOOSEModelBuilder;
import org.eclipse.ice.persistence.xml.XMLPersistenceProvider;
......@@ -141,6 +142,11 @@ public class XMLPersistenceProviderTester {
// Items.
xmlpp.addBuilder(new MOOSEModelBuilder());
xmlpp.addBuilder(new CAEBATKVPairBuilder());
// Add a Class Provider so that we can persist the forms.
xmlpp.registerClassProvider(new ICEJAXBClassProvider());
try {
// Start the service
xmlpp.start();
......
......@@ -22,6 +22,7 @@ import org.eclipse.ice.datastructures.form.AllowedValueType;
import org.eclipse.ice.datastructures.form.DataComponent;
import org.eclipse.ice.datastructures.form.Entry;
import org.eclipse.ice.datastructures.form.Form;
import org.eclipse.ice.datastructures.jaxbclassprovider.ICEJAXBClassProvider;
import org.eclipse.ice.datastructures.form.FormStatus;
import org.eclipse.ice.io.serializable.IOService;
import org.eclipse.ice.item.Item;
......@@ -372,7 +373,8 @@ public class PROTEUSModelTester {
ICEJAXBHandler xmlHandler = new ICEJAXBHandler();
ArrayList<Class> classList = new ArrayList<Class>();
classList.add(PROTEUSModel.class);
classList.addAll(new ICEJAXBClassProvider().getClasses());
// Create 6 DataComponents and append them to the form
for (int i = 1; i <= 6; i++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment