[MOBY-guts] biomoby commit
Gary Schiltz
gss at pub.open-bio.org
Wed Sep 14 22:06:10 UTC 2005
gss
Wed Sep 14 18:06:10 EDT 2005
Update of /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph
In directory pub.open-bio.org:/tmp/cvs-serv17011/src/org/semanticmoby/graph
Modified Files:
MOBYCollection.java MOBYSubject.java MOBYGraphNode.java
MOBYOrderedCollection.java MOBYResizableCollection.java
MOBYEnumeration.java MOBYFixedCollection.java MOBYObject.java
MOBYGraph.java MOBYMappingElement.java
MOBYUnorderedCollection.java
Added Files:
MOBYServiceSet.java MOBYPropValStmt.java
CollectionWrapper.java ContainerWrapper.java MOBYService.java
ListWrapper.java
Removed Files:
MOBYPropertyValueConstraint.java MOBYProviderSet.java
MOBYDescriptor.java MOBYDocument.java MOBYOntology.java
MOBYNonPositiveIntegerConstraint.java MOBYPropertyValue.java
MOBYDateConstraint.java MOBYSingleElement.java
MOBYIntegerConstraint.java
MOBYNonNegativeIntegerConstraint.java MOBYProvider.java
MOBYPropertyValueStatement.java MOBYNumericConstraint.java
MOBYLiteral.java MOBYPropertyValueException.java
MOBYResource.java
Log Message:
Major API overhaul
moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph MOBYServiceSet.java,NONE,1.1 MOBYPropValStmt.java,NONE,1.1 CollectionWrapper.java,NONE,1.1 ContainerWrapper.java,NONE,1.1 MOBYService.java,NONE,1.1 ListWrapper.java,NONE,1.1 MOBYCollection.java,1.2,1.3 MOBYSubject.java,1.2,1.3 MOBYGraphNode.java,1.2,1.3 MOBYOrderedCollection.java,1.2,1.3 MOBYResizableCollection.java,1.2,1.3 MOBYEnumeration.java,1.2,1.3 MOBYFixedCollection.java,1.2,1.3 MOBYObject.java,1.2,1.3 MOBYGraph.java,1.1,1.2 MOBYMappingElement.java,1.2,1.3 MOBYUnorderedCollection.java,1.2,1.3 MOBYPropertyValueConstraint.java,1.1,NONE MOBYProviderSet.java,1.2,NONE MOBYDescriptor.java,1.2,NONE MOBYDocument.java,1.2,NONE MOBYOntology.java,1.2,NONE MOBYNonPositiveIntegerConstraint.java,1.1,NONE MOBYPropertyValue.java,1.1,NONE MOBYDateConstraint.java,1.1,NONE MOBYSingleElement.java,1.2,NONE MOBYIntegerConstraint.java,1.1,NONE MOBYNonNegativeIntegerConstraint.java,1.1,NONE MOBYProvider.java,1.2,NONE MOBYPropertyValueS!
tatement.java,1.1,NONE MOBYNumericConstraint.java,1.1,NONE MOBYLiteral.java,1.1,NONE MOBYPropertyValueException.java,1.1,NONE MOBYResource.java,1.1,NONE
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYCollection.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYCollection.java 2005/03/21 21:29:44 1.2
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYCollection.java 2005/09/14 22:06:10 1.3
@@ -3,6 +3,7 @@
import java.util.*;
import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator;
/**
* A common abstract class for collections, both fixed sized and
@@ -10,54 +11,61 @@
*/
public abstract class MOBYCollection extends MOBYGraphNode
{
- /**
- * A list to hold the elements of the collection
- */
- protected List elements = new ArrayList();
+ protected CollectionWrapper wrapper;
/**
- * Create an instance with the initial list of elements
- * @param initialElements the initial elements
+ * Creates an instance for the given model and defining statement
*/
- public MOBYCollection(List initialElements, Resource resource,
- Model model)
- {
- super(resource, model);
+ public MOBYCollection(Model jenaModel, Statement definingStmt,
+ CollectionWrapper wrapper, List items) {
+ super(jenaModel, definingStmt);
+ this.wrapper = wrapper;
- if (initialElements != null) {
- elements.addAll(initialElements);
+ for (Iterator it = items.iterator(); it.hasNext();)
+ {
+ MOBYGraphNode node = (MOBYGraphNode) it.next();
+ wrapper.add(node);
}
}
/**
- * Return the size of the collection.
+ * Returns the size of the collection.
*/
public int size()
{
- return elements.size();
+ return wrapper.size();
}
-
+
/**
- * Return an iterator for traversing the elements
+ * Returns an iterator for traversing the elements
*/
- public Iterator iterator()
+ public ExtendedIterator iterator()
{
- return elements.iterator();
+ return wrapper.iterator();
}
- /**
- * Return whether or not this object is a collection.
- */
- public boolean isCollection()
+ public void add(MOBYGraphNode node)
{
- return true;
+ wrapper.add(node);
}
+
/**
- * Return whether or not this object is a singular element.
+ * Remove from the model all statements that make up this API object.
+ * This includes the defining statement (bnode rdf:type rdf:List), the
+ * statements that make up each of the nested API objects, and the
+ * statements that make this an RDF List, which are encapsulated in
+ * the Jena RDFList object.
*/
- public boolean isSingular()
+ public void removeStatements()
{
- return false;
+ ExtendedIterator it = wrapper.iterator();
+ while (it.hasNext())
+ {
+ MOBYGraphNode node = (MOBYGraphNode) it.next();
+ node.removeStatements();
+ }
+ it.close();
+ wrapper.removeStatements();
}
}
\ No newline at end of file
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYSubject.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYSubject.java 2005/03/21 21:29:44 1.2
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYSubject.java 2005/09/14 22:06:10 1.3
@@ -1,12 +1,19 @@
package org.semanticmoby.graph;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import org.semanticmoby.graph.*;
+import org.semanticmoby.vocabulary.MOBY;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.vocabulary.RDF;
/**
- * An object that represents the subject of one or more mappings. In
+ * A class that represents the subject of one or more mappings. In
* RDF graph terms, this represents a node (either blank or a resource)
* that is a moby:Subject, an RDF data structure (List, Bag, Seq, Alt),
* or both.
@@ -23,24 +30,87 @@
{
/**
* The collection of direct mappings, i.e. moby:mapsTo statements
- * whose subject is this.
+ * whose subject is this; keyed by the mapsTo statement.
*/
- private MOBYUnorderedCollection directMappings;
+ private Map directMappingStmts;
- public MOBYSubject(Resource resource, MOBYFixedCollection statements,
- MOBYUnorderedCollection directMappings,
- MOBYCollection nestedMappings, Model underlying)
+ /**
+ * Creates an instance with the given parameters; should be called from
+ * parsing code.
+ */
+ public MOBYSubject(Model jenaModel, Statement definingStmt, List propValStmts,
+ Map directMappingStmts, MOBYCollection nestedMappings)
{
- super(resource, statements, nestedMappings, underlying);
- this.directMappings = directMappings;
+ super(jenaModel, definingStmt, propValStmts, nestedMappings);
+ this.directMappingStmts = directMappingStmts;
}
-
+
+ /**
+ * Creates an instance with the given parameters; should be called
+ * when creating an instance from scratch (i.e. not from parsing).
+ */
+ public MOBYSubject(Model jenaModel, Resource head, List propValStmts,
+ List directMappings, MOBYCollection nestedMappings)
+ {
+ super(jenaModel,
+ jenaModel.createStatement(head, RDF.type, MOBY.Subject),
+ propValStmts, nestedMappings);
+
+ for (Iterator it = directMappings.iterator(); it.hasNext();)
+ {
+ MOBYGraphNode node = (MOBYGraphNode) it.next();
+ addDirectMapping(node);
+ }
+ }
+
+ /**
+ * Add the given node to the direct mappings, and add a mapsTo
+ * statement to the underlying model
+ */
+ public void addDirectMapping(MOBYGraphNode node)
+ {
+ this.directMappingStmts.put(
+ node,
+ jenaModel.createStatement(
+ getResource(), MOBY.mapsTo, node.getResource()));
+ }
+
+ /**
+ * Remove the given node from the direct mappings and remove the
+ * underlying RDF statements from the Jena model
+ */
+ public void removeDirectMapping(MOBYGraphNode node)
+ {
+ Statement stmt = (Statement) directMappingStmts.get(node);
+ if (stmt != null) {
+ jenaModel.remove(stmt);
+ }
+ node.removeStatements();
+ }
+
/**
- * Return the collection of direct mappings, i.e. moby:mapsTo statements
- * whose subject is this.
+ * Return an iterator over the direct mappings
+ */
+ public Iterator getDirectMappings()
+ {
+ return directMappingStmts.keySet().iterator();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.semanticmoby.graph.MOBYGraphNode#removeStatements()
*/
- public MOBYUnorderedCollection getDirectMappings()
+ public void removeStatements()
{
- return directMappings;
+ super.removeStatements();
+ if (directMappingStmts != null)
+ {
+ for (Iterator it = directMappingStmts.keySet().iterator(); it.hasNext();)
+ {
+ MOBYGraphNode node = (MOBYGraphNode) it.next();
+ removeDirectMapping(node);
+ }
+ directMappingStmts = null;
+ }
}
}
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYGraphNode.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYGraphNode.java 2005/03/21 21:29:44 1.2
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYGraphNode.java 2005/09/14 22:06:10 1.3
@@ -3,31 +3,88 @@
import com.hp.hpl.jena.rdf.model.*;
/**
- * An abstract class for nodes in an RDF graph; these nodes are either
- * collections or singular elements.
+ * An abstract class for representing parts of a MOBY graph structure.
*/
-public abstract class MOBYGraphNode extends MOBYDescriptor
+public abstract class MOBYGraphNode
{
- public MOBYGraphNode(Resource resource, Model model)
+ /**
+ * The underlying Jena model that holds the statements for this
+ * graph component
+ */
+ protected Model jenaModel;
+
+ /**
+ * Graph nodes all have an rdf:type statement that makes them what they
+ * are, with the exception of MOBYMappingElement instances, which can at
+ * times have no defining statement (see the discussion in the class
+ * documentation for MOBYMappingElement).
+ */
+ protected Statement definingStmt;
+
+ /**
+ * Creates an instance for the given model and defining statement
+ */
+ protected MOBYGraphNode(Model jenaModel, Statement definingStmt)
{
- super(resource, model);
+ this.jenaModel = jenaModel;
+ this.definingStmt = definingStmt;
+
+ if (definingStmt != null) {
+ jenaModel.add(definingStmt);
+ }
}
-
+
/**
- * Return whether or not this node represents a blank node
+ * Returns the model that holds statements describing this component
*/
- public boolean isBlank()
+ public Model getJenaModel()
{
- return (resource == null) || (resource.getURI() == null);
+ return jenaModel;
}
/**
- * Return whether or not this object is a collection.
+ * Returns the defining statement for this component
*/
- public abstract boolean isCollection();
+ public Statement getDefiningStmt()
+ {
+ return definingStmt;
+ }
/**
- * Return whether or not this object is a singular element.
+ * Returns the resource that is the subject of the defining statement
+ * if it has one, else returns null;
*/
- public abstract boolean isSingular();
+ public Resource getResource()
+ {
+ return (definingStmt == null) ? null : definingStmt.getSubject();
+ }
+
+ /**
+ * Removes the statements representing this component; subclasses should
+ * also call removeDefiningStatement() and call removeStatements() on all
+ * MOBYGraphNode instances nested within them.
+ */
+ public abstract void removeStatements();
+
+ /**
+ * Removes and nulls out the defining statement if it has not already
+ * been removed and nulled out.
+ */
+ protected void removeDefiningStatement()
+ {
+ if (definingStmt != null)
+ {
+ jenaModel.remove(definingStmt);
+ definingStmt = null;
+ }
+ }
+
+ /**
+ * Returns the URI of the underlying resource if there is a defining
+ * statement, else returns null.
+ */
+ public String getURI()
+ {
+ return (getResource() == null) ? null : getResource().getURI();
+ }
}
\ No newline at end of file
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYOrderedCollection.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYOrderedCollection.java 2005/03/21 21:29:44 1.2
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYOrderedCollection.java 2005/09/14 22:06:10 1.3
@@ -3,6 +3,7 @@
import java.util.*;
import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.vocabulary.RDF;
/**
* A class representing collections that can be resized (i.e.
@@ -12,47 +13,24 @@
public class MOBYOrderedCollection extends MOBYResizableCollection
{
/**
- * Create an instance with no elements
- * @param resource the resource node that represents this collection
- * @param underlyingJenaModel the Jena model from which this is stored
+ * Constructor for creating a fixed collection API object from scratch.
*/
- public MOBYOrderedCollection(Resource resource,
- Model underlyingJenaModel)
+ public MOBYOrderedCollection(Model jenaModel, Resource head, List items)
{
- super(null, resource, underlyingJenaModel);
+ super(jenaModel,
+ jenaModel.createStatement(head, RDF.type, RDF.Seq),
+ new ContainerWrapper((Seq) head.as(Seq.class)), items);
}
/**
- * Create an instance with the initial list of elements
- * @param initialElements the initial elements
- * @param resource the resource node that represents this collection
- * @param underlyingJenaModel the Jena model from which this is stored
+ * Create an instance with the list of items
*/
- public MOBYOrderedCollection(List initialElements, Resource resource,
- Model underlyingJenaModel)
+ public MOBYOrderedCollection(Model jenaModel, Statement definingStmt,
+ List items)
{
- super(initialElements, resource, underlyingJenaModel);
- }
-
- /**
- * Return the element at the given index
- * @param index the zero-based index of the element to retrieve
- * @return the element
- */
- public Object get(int index)
- {
- return elements.get(index);
- }
-
- /**
- * Add the given element to the collection so that its new
- * zero-based index is given index
- * @param index the zero-based index at which the new element
- * should be added
- * @param elementToAdd the element to add
- */
- public void add(int index, Object elementToAdd)
- {
- elements.add(index, elementToAdd);
+ super(jenaModel,
+ definingStmt,
+ new ContainerWrapper((Seq) definingStmt.getSubject().as(Seq.class)),
+ items);
}
}
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYResizableCollection.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYResizableCollection.java 2005/03/21 21:29:44 1.2
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYResizableCollection.java 2005/09/14 22:06:10 1.3
@@ -3,59 +3,23 @@
import java.util.*;
import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.vocabulary.RDF;
/**
* A class representing collections that can be resized (i.e.
* elements added to or removed from); such collections can be
- * either ordered or unordered.
+ * either ordered or unordered. This corresponds to the three
+ * RDF container classes, namely Bag, Seq, and Alt.
*/
public abstract class MOBYResizableCollection extends MOBYCollection
{
/**
- * Create an instance with no elements
- * @param resource the resource node that represents this collection
- * @param model the Jena model from which this is derived
+ * Constructor for creating a resizable collection API object from scratch.
*/
- public MOBYResizableCollection(Resource resource, Model model)
+ public MOBYResizableCollection(Model jenaModel, Statement definingStmt,
+ CollectionWrapper wrapper, List items)
{
- super(null, resource, model);
- }
-
- /**
- * Create an instance with the initial list of elements
- * @param initialElements the initial elements
- * @param resource the resource node that represents this collection
- * @param underlyingJenaModel the Jena model from which this is stored
- */
- public MOBYResizableCollection(List initialElements, Resource resource,
- Model underlyingJenaModel)
- {
- super(initialElements, resource, underlyingJenaModel);
- }
-
- /**
- * Add an element to the collection
- * @param elementToAdd the element to add to the collection
- */
- public void add(Object elementToAdd)
- {
- elements.add(elementToAdd);
- }
-
- /**
- * Remove an element from the collection
- * @param elementToRemove the element to remove
- */
- public void remove(Object elementToRemove)
- {
- elements.remove(elementToRemove);
- }
-
- /**
- * Remove all the elements from the collection
- */
- public void clear()
- {
- elements.clear();
+ super(jenaModel, definingStmt, wrapper, items);
}
}
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYEnumeration.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYEnumeration.java 2005/03/21 21:29:44 1.2
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYEnumeration.java 2005/09/14 22:06:10 1.3
@@ -3,6 +3,7 @@
import java.util.*;
import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.vocabulary.RDF;
/**
* A class representing collections that can be resized (i.e.
@@ -14,25 +15,24 @@
public class MOBYEnumeration extends MOBYUnorderedCollection
{
/**
- * Create an instance with no elements
- * @param resource the resource node that represents this collection
- * @param underlyingJenaModel the Jena model from which this is stored
+ * Constructor for creating a fixed collection API object from scratch.
*/
- public MOBYEnumeration(Resource resource,
- Model underlyingJenaModel)
+ public MOBYEnumeration(Model jenaModel, Resource head, List items)
{
- super(null, resource, underlyingJenaModel);
+ super(jenaModel,
+ jenaModel.createStatement(head, RDF.type, RDF.Alt),
+ new ContainerWrapper((Alt) head.as(Alt.class)), items);
}
/**
- * Create an instance with the initial list of elements
- * @param initialElements the initial elements
- * @param resource the resource node that represents this collection
- * @param underlyingJenaModel the Jena model from which this is stored
+ * Create an instance with the list of items
*/
- public MOBYEnumeration(List initialElements, Resource resource,
- Model underlyingJenaModel)
+ public MOBYEnumeration(Model jenaModel, Statement definingStmt,
+ List items)
{
- super(initialElements, resource, underlyingJenaModel);
+ super(jenaModel,
+ definingStmt,
+ new ContainerWrapper((Alt) definingStmt.getSubject().as(Alt.class)),
+ items);
}
}
\ No newline at end of file
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYFixedCollection.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYFixedCollection.java 2005/03/21 21:29:44 1.2
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYFixedCollection.java 2005/09/14 22:06:10 1.3
@@ -3,32 +3,34 @@
import java.util.*;
import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.vocabulary.RDF;
/**
- * A class for holding an ordered, fixed sized collection
- * of objects; corresponds to an RDF List.
+ * A class for holding an ordered, fixed sized collection of API objects
+ * (subclasses of MOBYGraphNode); corresponds to an RDF List.
*/
public class MOBYFixedCollection extends MOBYCollection
{
/**
- * Create an instance with the initial list of elements
- * @param initialElements the initial elements
- * @param resource the resource node that represents this collection
- * @param model the Jena model from which this is derived
+ * Constructor for creating a fixed collection API object from scratch.
*/
- public MOBYFixedCollection(List initialElements, Resource resource,
- Model model)
+ public MOBYFixedCollection(Model jenaModel, Resource head, List items)
{
- super(initialElements, resource, model);
+ super(jenaModel,
+ jenaModel.createStatement(head, RDF.type, RDF.List),
+ new ListWrapper((RDFList) head.as(RDFList.class)), items);
}
/**
- * Return the element at the given index
- * @param index the zero-based index of the element to retrieve
- * @return the element
+ * Create an instance with the list of items
*/
- public Object get(int index)
+ public MOBYFixedCollection(Model jenaModel, Statement definingStmt,
+ List items)
{
- return elements.get(index);
+ super(jenaModel,
+ definingStmt,
+ new ListWrapper((RDFList) definingStmt.getSubject().as(RDFList.class)),
+ items);
}
}
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYObject.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYObject.java 2005/03/21 21:29:44 1.2
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYObject.java 2005/09/14 22:06:10 1.3
@@ -1,16 +1,44 @@
package org.semanticmoby.graph;
+import java.util.List;
+
+import org.semanticmoby.vocabulary.MOBY;
+
import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.vocabulary.RDF;
/**
- * An object that represents the object of a mapping.
+ * A class that represents the object of one or more mappings. In
+ * RDF graph terms, this represents a node (either blank or a resource)
+ * that is a moby:Subject, an RDF data structure (List, Bag, Seq, Alt),
+ * or both.
+ * <p>
+ * As an RDF data structure, it can have one or more elements, each
+ * of which can itself be either a moby:Object, an RDF data structure,
+ * or both. This collection of elements is returned by getNestedMappings().
*/
public class MOBYObject extends MOBYMappingElement
{
- public MOBYObject(Resource resource, MOBYFixedCollection statements,
- MOBYCollection nestedElements, Model underlying)
+ /**
+ * Creates an instance with the given parameters; should be called from
+ * parsing code.
+ */
+ public MOBYObject(Model jenaModel, Statement definingStmt,
+ List propValStmts, MOBYCollection nestedMappings)
+ {
+ super(jenaModel, definingStmt, propValStmts, nestedMappings);
+ }
+
+ /**
+ * Creates an instance with the given parameters; should be called
+ * when creating an instance from scratch (i.e. not from parsing).
+ */
+ public MOBYObject(Model jenaModel, Resource head, List propValStmts,
+ MOBYCollection nestedMappings)
{
- super(resource, statements, nestedElements, underlying);
+ super(jenaModel,
+ jenaModel.createStatement(head, RDF.type, MOBY.Object),
+ propValStmts, nestedMappings);
}
}
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYGraph.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYGraph.java 2004/11/23 00:18:46 1.1
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYGraph.java 2005/09/14 22:06:10 1.2
@@ -1,26 +1,105 @@
package org.semanticmoby.graph;
+import org.semanticmoby.vocabulary.MOBY;
+
import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.vocabulary.RDF;
/**
- * This class represents singular (i.e. not collection) subgraphs
- * that have a single mapping.
+ * This class represents a singular (i.e. not collection) subgraph
+ * that has a single mapping.
*/
-public class MOBYGraph extends MOBYSingleElement
+public class MOBYGraph extends MOBYGraphNode
{
+ /**
+ * Wrapper object for the underlying subgraph pointed to by a
+ * hasMapping property
+ */
private MOBYGraphNode hasMapping;
- public MOBYGraph(Resource resource, MOBYGraphNode hasMapping, Model underlying)
+ /**
+ * The statement that asserts that this graph has the mapping wrapped
+ * by the hasMapping instance variable
+ */
+ private Statement hasMappingStmt;
+
+ /**
+ * Creates an instance for the given model, defining statement,
+ * hasMapping statement, and MOBYGraphNode that was parsed from
+ * the value of the hasMapping statement
+ */
+ public MOBYGraph(Model jenaModel, Statement definingStmt,
+ Statement hasMappingStmt, MOBYGraphNode hasMapping)
{
- super(resource, underlying);
+ super(jenaModel, definingStmt);
+ this.hasMappingStmt = hasMappingStmt;
this.hasMapping = hasMapping;
}
+
+ /**
+ * Creates an instance from scratch
+ */
+ public MOBYGraph(Model jenaModel)
+ {
+ super(jenaModel,
+ jenaModel.createStatement(
+ jenaModel.createResource(), RDF.type, MOBY.Graph));
+ }
+
+ /**
+ * Creates an instance from scratch, and includes an initial mapping
+ */
+ public MOBYGraph(Model jenaModel, MOBYGraphNode hasMapping)
+ {
+ this(jenaModel);
+ setHasMapping(hasMapping);
+ }
+
+ /**
+ * Sets the value of a hasMapping instance variable, and adds a hasMapping
+ * statement to the underlying model.
+ */
+ public void setHasMapping(MOBYGraphNode hasMapping)
+ {
+ removeHasMapping();
+ this.hasMapping = hasMapping;
+ hasMappingStmt = jenaModel.createStatement(
+ getResource(), MOBY.hasMapping, hasMapping.getResource());
+ jenaModel.add(hasMappingStmt);
+ }
+
+ /**
+ * Removes the hasMapping statement from the underlying model and nulls
+ * the hasMapping instance variable
+ */
+ public void removeHasMapping()
+ {
+ if (hasMapping != null)
+ {
+ jenaModel.remove(hasMappingStmt);
+ hasMappingStmt = null;
+ hasMapping.removeStatements();
+ hasMapping = null;
+ }
+ }
/**
- * Return the object of this graph's hasMapping property.
+ * Returns the object of this graph's hasMapping property.
*/
public MOBYGraphNode getHasMapping()
{
return hasMapping;
}
+
+ /*
+ * (non-Javadoc)
+ * @see org.semanticmoby.graph.MOBYGraphNode#removeStatements()
+ */
+ public void removeStatements()
+ {
+ removeDefiningStatement();
+ if (hasMapping != null) {
+ hasMapping.removeStatements();
+ }
+ }
}
\ No newline at end of file
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYMappingElement.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYMappingElement.java 2005/03/21 21:29:44 1.2
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYMappingElement.java 2005/09/14 22:06:10 1.3
@@ -1,37 +1,91 @@
package org.semanticmoby.graph;
-
+import java.util.Iterator;
+import java.util.List;
import com.hp.hpl.jena.rdf.model.*;
-
-public class MOBYMappingElement extends MOBYSingleElement
+/**
+ * This class represents graph nodes that are within a containing subgraph,
+ * which is pointed to by a hasMapping or mapsTo property. Such nodes can have
+ * property value setting statements (instances of MOBYPropertyValueStatement)
+ * associated with them. If the containing subgraph is pointed to by a
+ * hasMapping property, the node can optionally be an instance of moby:Subject,
+ * in which case its defining statement is the rdf:type statement making that
+ * assertion; if it is not a moby:Subject, then the defining statement is null.
+ * Similarly, if the containing subgraph is pointed to by a mapsTo property,
+ * the node can optionally be an instance of moby:Object, in which case its
+ * defining statement is the rdf:type statement making that assertion; if it
+ * is not a moby:Object, then the defining statement is null.
+ * <br><br>
+ * Nodes represented by this class can also optionally be instances of
+ * collections (subclasses of MOBYCollection), in which case their collective
+ * nature is expressed through the nestedMappings instance variable.
+ */
+public abstract class MOBYMappingElement extends MOBYGraphNode
{
- private MOBYFixedCollection statements;
- private MOBYCollection nestedElements;
+ /**
+ * Property value statements whose subjects are this node's resource
+ */
+ private List propValStmts;
- public MOBYMappingElement(Resource resource, MOBYFixedCollection statements,
- MOBYCollection nestedElements, Model underlying)
+ /**
+ * A view of this node as a collection
+ */
+ private MOBYCollection nestedMappings;
+
+ /**
+ * Creates an instance with the given parameters.
+ */
+ protected MOBYMappingElement(Model jenaModel, Statement definingStmt,
+ List propValStmts, MOBYCollection nestedMappings)
{
- super(resource, underlying);
- this.statements = statements;
- this.nestedElements = nestedElements;
+ super(jenaModel, definingStmt);
+ this.propValStmts = propValStmts;
+ this.nestedMappings = nestedMappings;
}
-
+
/**
- * Return the collection of property-setting statements associated
+ * Returns the collection of property-setting statements associated
* with this mapping element.
*/
- public MOBYFixedCollection getPropertyValueStatements()
+ public List getPropValStmts()
{
- return statements;
+ return propValStmts;
}
/**
- * Return the collection of mappings that are nested within this
+ * Returns the collection of mappings that are nested within this
* mapping element through its role as a data structure.
*/
- public MOBYCollection getNestedElements() {
- return nestedElements;
+ public MOBYCollection getNestedMappings()
+ {
+ return nestedMappings;
}
-
-}
+
+ /**
+ * Removes the statements associated with this objects nested within
+ * this object.
+ */
+ public void removeStatements()
+ {
+ removeDefiningStatement();
+ if (propValStmts != null)
+ {
+ for (Iterator it = propValStmts.iterator(); it.hasNext();)
+ {
+ MOBYPropValStmt stmt = (MOBYPropValStmt) it.next();
+ stmt.removeStatements();
+ }
+ propValStmts = null;
+ }
+ if (nestedMappings != null)
+ {
+ for (Iterator it = nestedMappings.iterator(); it.hasNext();)
+ {
+ MOBYGraphNode node = (MOBYGraphNode) it.next();
+ node.removeStatements();
+ }
+ nestedMappings = null;
+ }
+ }
+}
\ No newline at end of file
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYUnorderedCollection.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYUnorderedCollection.java 2005/03/21 21:29:44 1.2
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/MOBYUnorderedCollection.java 2005/09/14 22:06:10 1.3
@@ -3,6 +3,8 @@
import java.util.*;
import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.vocabulary.RDF;
/**
* A class representing collections that can be resized (i.e.
@@ -12,25 +14,33 @@
public class MOBYUnorderedCollection extends MOBYResizableCollection
{
/**
- * Create an instance with no elements
- * @param resource the resource node that represents this collection
- * @param underlyingJenaModel the Jena model from which this is stored
+ * Constructor for creating a fixed collection API object from scratch.
*/
- public MOBYUnorderedCollection(Resource resource,
- Model underlyingJenaModel)
+ public MOBYUnorderedCollection(Model jenaModel, Resource head, List items)
{
- super(null, resource, underlyingJenaModel);
+ super(jenaModel,
+ jenaModel.createStatement(head, RDF.type, RDF.Bag),
+ new ContainerWrapper((Bag) head.as(Bag.class)), items);
}
/**
- * Create an instance with the initial list of elements
- * @param initialElements the initial elements
- * @param resource the resource node that represents this collection
- * @param underlyingJenaModel the Jena model from which this is stored
+ * Create an instance with the list of items
*/
- public MOBYUnorderedCollection(List initialElements, Resource resource,
- Model underlyingJenaModel)
+ public MOBYUnorderedCollection(Model jenaModel, Statement definingStmt,
+ List items)
{
- super(initialElements, resource, underlyingJenaModel);
+ super(jenaModel,
+ definingStmt,
+ new ContainerWrapper((Bag) definingStmt.getSubject().as(Bag.class)),
+ items);
+ }
+
+ /**
+ * Constructor for creating an unordered collection API object from scratch.
+ */
+ public MOBYUnorderedCollection(Model jenaModel, Statement definingStmt,
+ CollectionWrapper wrapper, List items)
+ {
+ super(jenaModel, definingStmt, wrapper, items);
}
}
\ No newline at end of file
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYPropertyValueConstraint.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYProviderSet.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYDescriptor.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYDocument.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYOntology.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYNonPositiveIntegerConstraint.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYPropertyValue.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYDateConstraint.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYSingleElement.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYIntegerConstraint.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYNonNegativeIntegerConstraint.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYProvider.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYPropertyValueStatement.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYNumericConstraint.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYLiteral.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYPropertyValueException.java,v: No such file or directory
rcsdiff: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/semanticmoby/graph/RCS/MOBYResource.java,v: No such file or directory
More information about the MOBY-guts
mailing list