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

Finished first implementation of ComponentBuilder and its test.



Need to update the test to examine component member values.
Signed-off-by: default avatarJay Jay Billings <billingsjj@ornl.gov>
parent 01bedd76
......@@ -11,7 +11,6 @@
*****************************************************************************/
package org.eclipse.ice.data;
import org.apache.jena.ontology.Individual;
import org.apache.jena.ontology.ObjectProperty;
import org.apache.jena.ontology.OntClass;
import org.apache.jena.ontology.OntModel;
......@@ -19,7 +18,17 @@ import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
/**
* This is a builder class for constructing Components
* This is a builder class for constructing Components. It uses a standard
* builder API to dynamically build and construct a new Component based on the
* way the functions are called.
*
* All components should be constructed by using the with* star operations to
* configure data members before the build function (build()) is called.
*
* The builder will configure default values for the field variables of the
* components that it constructs. These are reasonable defaults such as
* "NO_NAME" and "NO_DESCRIPTION" for classes that have neither a name nor a
* description, for example.
*
* @author Jay Jay Billings
*
......@@ -31,6 +40,52 @@ public class ComponentBuilder {
*/
private OntModel ontModel;
/**
* The name of the component that should be built.
*/
private String name = "NO_NAME";
/**
* The identifier of the component that should be built.
*/
private long id = 0;
/**
* The unique context in which the Component exists
*/
private String context = "DEFAULT";
/**
* A description of the component.
*/
private String description = "NO_DESCRIPTION";
/**
* And OWL class, managed by the RDF framework, for the root component class in
* the ontology.
*/
private OntClass compClass;
/**
* An OWL property for the name
*/
private ObjectProperty nameProp;
/**
* An OWL property for the description
*/
private ObjectProperty descProp;
/**
* An OWL property for the context
*/
private ObjectProperty contextProp;
/**
* An OWL property for the id
*/
private ObjectProperty idProp;
/**
* Constructor
*
......@@ -38,23 +93,81 @@ public class ComponentBuilder {
*/
public ComponentBuilder(final OntModel ICEOntModel) {
ontModel = ICEOntModel;
// Grab all the properties for fast references
compClass = ontModel.getOntClass(ICEConstants.COMPONENT);
nameProp = ontModel.getObjectProperty(ICEConstants.NAME);
descProp = ontModel.getObjectProperty(ICEConstants.DESCRIPTION);
contextProp = ontModel.getObjectProperty(ICEConstants.CONTEXT);
idProp = ontModel.getObjectProperty(ICEConstants.ID);
}
/**
* This operation executes the construction process for the Component.
* This operation sets the name of the component. It should be called before the
* build operation.
*
* @return the fully initialized component based on the build parameters
* @param compName the name of the component
* @return the updated component builder
*/
public Resource build(Model dataModel) {
OntClass compClass = ontModel.getOntClass(ICEConstants.NAMESPACE + "Component");
Individual compIndividual = ontModel.createIndividual(compClass);
public ComponentBuilder withName(final String compName) {
name = compName;
return this;
}
ObjectProperty prop = ontModel.getObjectProperty(ICEConstants.NAMESPACE + "name");
/**
* This operation sets the id of the component. It should be called before the
* build operation.
*
* @param compId the component's id
* @return the updated component builder
*/
public ComponentBuilder withId(final long compId) {
id = compId;
return this;
}
/**
* This operation sets the description of the component. It should be called
* before the build operation.
*
* @param compDesc the description of the component
* @return the updated component builder
*/
public ComponentBuilder withDescription(final String compDesc) {
description = compDesc;
return this;
}
/**
* This operation sets the context tag of the component. It should be called
* before the build operation. The context is a special property that identifies
* the environment in which the component exists and can be used for
* specialization purposes when environments change.
*
* @param compDesc the context of the component
* @return the updated component builder
*/
public ComponentBuilder withContext(final String compContext) {
context = compContext;
return this;
}
/**
* This operation executes the construction process for the Component and builds
* the ontological entity.
*
* @param the data model to which the newly created resource should be attached.
* @param the IRI of the new component
* @return the fully initialized component based on the build parameters
*/
public Resource build(Model dataModel, final String iri) {
dataModel.createResource("https://www.galactic-empire.gov/data#Comp1", compClass)
.addProperty(prop, "Tk-421");
Resource resource = dataModel.createResource(iri, compClass)
.addProperty(nameProp, name)
.addProperty(idProp, String.valueOf(id))
.addProperty(contextProp, context)
.addProperty(descProp, description);
return compIndividual;
return resource;
}
}
......@@ -13,6 +13,7 @@ package org.eclipse.ice.data;
/**
* This class stores ICE Data Model constants used throughout the code base.
*
* @author Jay Jay Billings
*
*/
......@@ -21,6 +22,31 @@ public class ICEConstants {
/**
* Root Namespace of the ICE ontology
*/
public static String NAMESPACE = "https://www.eclipse.org/ice";
public static String NAMESPACE = "https://www.eclipse.org/ice#";
/**
* Fully qualified type name of ICE Components
*/
public static String COMPONENT = NAMESPACE + "Component";
/**
* Fully qualified type name of ICE Identifiable names
*/
public static String NAME = NAMESPACE + "name";
/**
* Fully qualified type name of ICE Identifiable descriptions
*/
public static String DESCRIPTION = NAMESPACE + "desc";
/**
* Fully qualified type name of ICE Identifiable context
*/
public static String CONTEXT = NAMESPACE + "context";
/**
* Fully qualified type name of ICE Identifiable identifier numbers
*/
public static String ID = NAMESPACE + "identifier";
}
......@@ -41,7 +41,7 @@ public class ComponentBuilderTest {
protected static Model dataModel;
// Ontology namespace
protected String namespace = "https://www.eclipse.org/ice#";
protected String namespace = "https://www.galactic-empire.gov/data#";
/**
* @throws java.lang.Exception
......@@ -65,8 +65,9 @@ public class ComponentBuilderTest {
*/
@Test
public void testBuild() {
Resource comp = null;
comp = builder.build(dataModel);
// Create the IRI
String iri = namespace + "Comp1";
Resource comp = builder.build(dataModel,iri);
// Make sure the component exists
assertNotNull(comp);
// Check the namespace
......
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