001: /**
002: * generated by RDFReactor on 9:59 on 29.2005
003: */package org.ontoware.semversion;
004:
005: import java.util.Calendar;
006:
007: import org.ontoware.rdf2go.model.Model;
008: import org.ontoware.rdf2go.model.node.URI;
009: import org.ontoware.rdfreactor.runtime.RDFDataException;
010: import org.ontoware.semversion.impl.UserImpl;
011:
012: /**
013: * Any item that is versioned. Versioned items have a comment, label, creation
014: * time, deletion time, provenance, tags, a URI, a User who created it, optional
015: * user-define meta-data.
016: *
017: * @author voelkel
018: */
019: public abstract class VersionedItem {
020:
021: private org.ontoware.semversion.impl.generated.VersionedItem versionedItem;
022: private Session session;
023:
024: /**
025: * Returns a Java wrapper over an RDF object, identified by URI. Creating
026: * two wrappers for the same instanceURI is legal.
027: *
028: * @param model
029: * RDF2GO Model implementation, see http://rdf2go.ontoware.org
030: * @param uri
031: * URI of this instance
032: */
033: public VersionedItem(Model model, Session session, URI uri) {
034: this .versionedItem = new org.ontoware.semversion.impl.generated.VersionedItem(
035: model, uri, true);
036: this .session = session;
037: }
038:
039: public Session getSession() {
040: return this .session;
041: }
042:
043: /**
044: * @return one of the comments.
045: */
046: public String getComment() {
047: // this is dropping all other comments besides the first
048: return this .versionedItem.getAllComment_as().firstValue();
049: }
050:
051: /**
052: * @return the creation time of this item
053: */
054: public Calendar getCreationTime() throws RDFDataException {
055: return this .versionedItem.getCreationTime();
056: }
057:
058: // /**
059: // * @return the deletionTime, or FOREVER if no deletion time has been set
060: // * yet. A version with no deletion time is considered to be 'live'.
061: // */
062: // public Calendar getDeletionTime() throws RDFDataException {
063: // Calendar deletionTime = this.versionedItem.getDeletionTime();
064: // if (deletionTime == null)
065: // return TransactionTime.FOREVER;
066: // else
067: // return deletionTime;
068: // }
069:
070: public String getLabel() {
071: return this .versionedItem.getAllLabel_as().firstValue();
072: }
073:
074: /**
075: * @return the provenance URI or null if none has been set
076: */
077: public URI getProvenance() throws RDFDataException {
078: return this .versionedItem.getProvenance();
079: }
080:
081: protected SemVersion getSemVersion() {
082: return (SemVersion) versionedItem.getModel().getProperty(
083: SemVersion.SEMVERSIONIMPL);
084: }
085:
086: /**
087: * Tags are used e.g. to tag things as 'suggestion'
088: *
089: * @return a tag, if this item has one. Otherwise null.
090: */
091: protected String getTag() throws RDFDataException {
092: return this .versionedItem.getAllTag_as().firstValue();
093: }
094:
095: // /**
096: // * @return the transaction time, which contains creation and deletio time
097: // */
098: // public TransactionTime getTransactionTime() {
099: // try {
100: // Calendar start = this.getCreationTime();
101: // Calendar end = this.getDeletionTime();
102: // TransactionTime t = new TransactionTime(start, end);
103: // return t;
104: // } catch (RDFDataException e) {
105: // throw new RuntimeException(e);
106: // }
107: // }
108:
109: public URI getURI() {
110: return this .versionedItem.getResource().asURI();
111: }
112:
113: /**
114: * @return the creator of this item
115: */
116: public User getUser() {
117: org.ontoware.semversion.impl.generated.User u = this .versionedItem
118: .getAuthor();
119: if (u == null)
120: return null;
121: else
122: return new UserImpl(u);
123: }
124:
125: /**
126: * @return the URI of the graph which contains additional metadata in RDF
127: */
128: public URI getUserdefinedMetadata() {
129: return this .versionedItem.getUserdefinedMetadata();
130: }
131:
132: // /**
133: // * removes a value
134: // */
135: // protected void removeCreationTime(long value) {
136: // this.versionedItem.removeCreationTime();
137: // }
138: //
139: // /**
140: // * removes a value
141: // */
142: // protected void removeDeletionTime(long value) {
143: // this.versionedItem.removeDeletionTime();
144: // }
145:
146: public void setComment(String comment) {
147: this .versionedItem.setComment(comment);
148: }
149:
150: /**
151: * removes all values and sets this one
152: */
153: protected void setCreationTime(Calendar value)
154: throws RDFDataException {
155: this .versionedItem.setCreationTime(value);
156: }
157:
158: // /**
159: // * removes all values and sets this one
160: // */
161: // protected void setDeletionTime(Calendar value) throws RDFDataException {
162: // this.versionedItem.setDeletionTime(value);
163: // }
164:
165: public void setLabel(String label) {
166: this .versionedItem.setLabel(label);
167: }
168:
169: /**
170: * removes all values and sets this one
171: */
172: protected void setProvenance(URI value) throws RDFDataException {
173: if (value != null)
174: this .versionedItem.setProvenance(value);
175: }
176:
177: /**
178: * removes all values and sets this one
179: */
180: protected void setTag(String value) throws RDFDataException {
181: this .versionedItem.setTag(value);
182: }
183:
184: /**
185: * removes all values and sets this one
186: */
187: protected void setUser(User value) throws RDFDataException {
188: this .versionedItem
189: .setAuthor(((org.ontoware.semversion.impl.UserImpl) value)
190: .getUser());
191: }
192:
193: /**
194: * removes all values and sets this one
195: */
196: protected void setUserdefinedMetadata(URI value) {
197: this.versionedItem.setUserdefinedMetadata(value);
198: }
199:
200: }
|