|
Release Planner v1.0 | ||||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||||
See:
Description
| Interface Summary | |
| DOMObject.Iterator | Used to iterate across DOMObjects. |
| DOMRelation.Endpoint.Iterator | Used to iterate across the endpoints of a relationship. |
| DOMRelation.Instance.Iterator | Used to iterate across the instances of a relationship. |
| Class Summary | |
| DOMObject | The common baseclass for all DOM objects and relations. |
| DOMRelation | This class represents meta-information about DOM relations. |
| DOMRelation.Endpoint | The end-point (left or right) of a relationship. |
| DOMRelation.Instance | Baseclass for relationship instances. |
| DOMRelation.Left | The left endpoint of a relationship. |
| DOMRelation.Right | The right endpoint of a relationship. |
This package implements a framework for storing objects and their relationships.
There are two main baseclasses, DOMObject and DOMRelation. DOMObject is a baseclass for any type of domain object, e.g.,
package rp.util.dom.test;
import rp.util.dom.*;
class Person extends DOMObject {
private String name;
public Person(String name) { this.name = name; }
public String getName() { return name; }
}
DOMRelation is not a baseclass. Instances of DOMRelation contain meta-information about relationships, e.g.,
private static DOMRelation metainfo = new DOMRelation("IsBossOf");
static {
metainfo.setLeftClassName("rp.util.dom.test.Manager");
metainfo.setRightClassName("rp.util.dom.test.Employee");
metainfo.setLeftName("manages");
metainfo.setRightName("is managed by");
metainfo.setLeftNumericity(1,1); // sets min and max numericty on the left side
metainfo.setRightNumericity(2,MANY); // sets min and max numericty on the right side
}
DOMRelation nests a set of related classes used to implements relationship instances. These are:
In addition, various iterators classes are defined. By convention, a class 'Iterator' defined as a static contained class of a class X will iterate over objects of type X. Therefore a DOMObject.Iterator iterates over DOMObjects, a DOMRelation.Iterator iterates over DOMRelation meta-objects, a DOMRelation.Instance.Iterator iterates over instances of relations, and a DOMRelation.Endpoint.Iterator iterates over Endpoints (left or right).
Below is an example that shows how to define and establish a relationship.
package rp.util.dom.test;
import rp.util.dom.*;
class Person extends DOMObject {
private String name;
public Person(String name) { this.name = name; }
public String getName() { return name; }
}
class Manager extends Person {
public IsBossOf.Left employees = new IsBossOf.Left(this);
public Manager(String name) { super(name); }
}
class Employee extends Person {
public IsBossOf.Right manager = new IsBossOf.Right(this);
public Employee(String name) { super(name); }
}
class IsBossOf extends DOMRelation.Instance {
private static DOMRelation metainfo = new DOMRelation("IsBossOf");
static {
metainfo.setLeftClassName("rp.util.dom.test.Manager");
metainfo.setRightClassName("rp.util.dom.test.Employee");
metainfo.setLeftName("manages");
metainfo.setRightName("is managed by");
metainfo.setLeftNumericity(1,1); // sets min and max numericty on the left side
metainfo.setRightNumericity(2,MANY); // sets min and max numericty on the right side
}
public static DOMRelation get() { return metainfo; }
public DOMRelation getRelation() { return metainfo; }
// an example of an attribute on a relation. DOMRelation.Instance extends DOMObject.
public java.util.Date whenStartedManaging;
// Establish a relationship between m and e
public IsBossOf(Manager m, Employee e) {
super(m.employees, e.manager);
}
static class Left extends DOMRelation.Left {
public Left(DOMObject o) { super(o); }
public DOMRelation getRelation() { return metainfo; }
}
static class Right extends DOMRelation.Right {
public Right(DOMObject o) { super(o); }
public DOMRelation getRelation() { return metainfo; }
}
}
public class Test {
public static void main(String args[]) {
Manager sally = new Manager("Sally");
Employee jack = new Employee("Jack");
Employee jill = new Employee("Jill");
new IsBossOf(sally,jack);
new IsBossOf(sally,jill);
for(DOMObject.Iterator i = sally.employees.iterator(); i.hasNext(); )
System.out.println( ((Employee)i.next()).getName() );
}
}
|
Release Planner v1.0 | ||||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||||