001: package org.garret.rdf;
002:
003: import java.util.*;
004: import java.io.*;
005: import org.garret.perst.*;
006:
007: /**
008: * Version of the object
009: */
010: public class Thing extends Persistent {
011: /**
012: * Object version history
013: */
014: public VersionHistory vh;
015:
016: /**
017: * Particular version of type of the object
018: */
019: public Thing type;
020:
021: /**
022: * Version creation timestamp
023: */
024: public Date timestamp;
025:
026: /**
027: * Property values
028: */
029: public PropVal[] props;
030:
031: /**
032: * Check if it is the latest version in version history
033: * @return true if version is the last in version history
034: */
035: public boolean isLatest() {
036: return vh.getLatest() == this ;
037: }
038:
039: /**
040: * Get values of the property with given name
041: * @param propName name of the proiperty
042: */
043: public Object[] get(String propName) {
044: if (Symbols.Timestamp.equals(propName)) {
045: return new Object[] { timestamp };
046: }
047: ArrayList list = new ArrayList();
048: for (int i = 0; i < props.length; i++) {
049: PropVal prop = props[i];
050: if (prop.def.name.equals(propName)) {
051: list.add(prop.val);
052: }
053: }
054: return list.toArray();
055: }
056:
057: /**
058: * Check if object belongs to the partiular type
059: * @param superType version history representing object type
060: * @param kind search kind
061: * @param timestamp timestamp used to locate version
062: * @return true if type of the object is the same or is subtype of specified type
063: */
064: public boolean isInstanceOf(VersionHistory super Type,
065: SearchKind kind, Date timestamp) {
066: return type.isSubTypeOf(super Type, kind, timestamp);
067: }
068:
069: /** This method is applicable only to objects represnting types and
070: * checks if this type is the same or subtype of specified type
071: * @param superType version history representing object type
072: * @param kind search kind
073: * @param timestamp timestamp used to locate version
074: * @return true if this type is the same or is subtype of specified type
075: */
076: public boolean isSubTypeOf(VersionHistory super Type,
077: SearchKind kind, Date timestamp) {
078: if (vh == super Type) {
079: return true;
080: }
081: Object[] subtypes = get(Symbols.Subtype);
082: for (int i = 0; i < subtypes.length; i++) {
083: VersionHistory subtype = (VersionHistory) subtypes[i];
084: if (kind == SearchKind.AllVersions) {
085: for (int j = subtype.versions.size(); --j >= 0;) {
086: Thing type = (Thing) subtype.versions.get(j);
087: if (type.isSubTypeOf(super Type, kind, timestamp)) {
088: return true;
089: }
090: }
091: } else {
092: Thing type = subtype.getVersion(kind, timestamp);
093: if (type != null
094: && type.isSubTypeOf(super Type, kind, timestamp)) {
095: return true;
096: }
097: }
098: }
099: return false;
100: }
101: }
|