package org.splat.dal.bo.som;
+
/**
* Publication objects are the way to reference document versions from a Project Element.
* As such, a Document version is added (or published) to a Project Element through a Publication object.
import org.splat.dal.bo.kernel.Relation;
import org.splat.som.Step;
-
+/**
+ * Persistent class representing a tag of a document published in a study/scenario activity.
+ */
public class Publication extends Persistent {
-// Persistent fields
- private Document mydoc;
- private ProjectElement owner; // Either Study or Scenario, depending on the step involved by the publication
- private char isnew; // True if this references a document version new for the owner project element
+ // Persistent fields
+ /**
+ * Persistent field. The published document.
+ */
+ private Document mydoc;
+ /**
+ * Persistent field. Either Study or Scenario, depending on the step involved by the publication.
+ */
+ private ProjectElement owner;
+ /**
+ * Persistent field. True if this references a document version new for the owner project element.
+ */
+ private char isnew;
-// Transient fields
- private Step mystep;
+ // Transient fields
+ /**
+ * Transient field. The step where the document is published.
+ */
+ private Step mystep;
-// ==============================================================================================================================
-// Construction
-// ==============================================================================================================================
+ // ==============================================================================================================================
+ // Construction
+ // ==============================================================================================================================
-/**
+ /**
* Get the mystep.
+ *
* @return the mystep
*/
public Step getStep() {
return mystep;
}
+
/**
* Set the mystep.
- * @param aStep the mystep to set
+ *
+ * @param aStep
+ * the mystep to set
*/
- public void setStep(Step aStep) {
+ public void setStep(final Step aStep) {
this.mystep = aStep;
}
- // Database fetch constructor
- public Publication () {
-// ------------------------
- mystep = null;
- }
-// Internal constructors
- public Publication (Document doc, ProjectElement publisher) {
-// --------------------------------------------------------------
- mydoc = doc;
- mystep = null;
- owner = publisher;
- isnew = 'Y';
- }
-// ==============================================================================================================================
-// Member functions
-// ==============================================================================================================================
-
- public Relation addDependency (Publication to) {
-// ----------------------------------------------
- return this.addDependency(to.value());
- }
-
- public Relation addDependency (Document to) {
-// -------------------------------------------
- if (to == null) return null;
- else return mydoc.addRelation( new UsesRelation(mydoc, to) );
- }
-/**
- * Returns either the Study Scenario or the Study itself to which this publication belongs, depending on the Study Step into
- * which the referenced document has been published.<br/>
- * If this publication belongs to a Study, the Project Element returned is the Study returned by getOwnerStudy().
- *
- * @return the Study Scenario or the Study to which this publication belongs to
- * @see #getOwnerStudy()
- */
- public ProjectElement getOwner () {
-// ---------------------------------
- return owner;
- }
+ /**
+ * Database fetch constructor.
+ */
+ public Publication() {
+ super();
+ mystep = null;
+ }
+
+ /**
+ * Internal constructors.
+ *
+ * @param doc
+ * the published document
+ * @param publisher
+ * the project element where the document is published
+ */
+ public Publication(final Document doc, final ProjectElement publisher) {
+ super();
+ mydoc = doc;
+ mystep = null;
+ owner = publisher;
+ isnew = 'Y';
+ }
+
+ // ==============================================================================================================================
+ // Member functions
+ // ==============================================================================================================================
+
+ public Relation addDependency(final Publication to) {
+ return this.addDependency(to.value());
+ }
+
+ public Relation addDependency(final Document to) {
+ Relation res = null;
+ if (to != null) {
+ res = mydoc.addRelation(new UsesRelation(mydoc, to));
+ }
+ return res;
+ }
+
+ /**
+ * Returns either the Study Scenario or the Study itself to which this publication belongs, depending on the Study Step into which the
+ * referenced document has been published.<br/> If this publication belongs to a Study, the Project Element returned is the Study
+ * returned by getOwnerStudy().
+ *
+ * @return the Study Scenario or the Study to which this publication belongs to
+ * @see #getOwnerStudy()
+ */
+ public ProjectElement getOwner() {
+ return owner;
+ }
- /**
+ /**
* Set the owner.
- * @param owner the owner to set
+ *
+ * @param owner
+ * the owner to set
*/
- public void setOwner(ProjectElement owner) {
+ public void setOwner(final ProjectElement owner) {
this.owner = owner;
}
- public Study getOwnerStudy () {
-// -----------------------------
- if (owner instanceof Study) return (Study)owner;
- else return ((Scenario)owner).getOwnerStudy();
- }
+ /**
+ * Returns the study where the document is published.
+ *
+ * @return the owner study
+ */
+ public Study getOwnerStudy() {
+ return owner.getOwnerStudy();
+ }
-/**
- * Returns the state of this published document.
- * It is the same than the state of the referenced document, unless this publication is out-of-date, in which case it is
- * In-Work state.
- *
- * @see #outdate()
- * @see #isOutdated()
- */
- public ProgressState getProgressState () {
-// ----------------------------------------
- if (this.isOutdated()) return ProgressState.inWORK; // Overrides the document state
- else return mydoc.getProgressState();
- }
-
- public List<Publication> getRelations (Class<? extends Relation> type) {
-// ----------------------------------------------------------------------
- if (type == null) return null;
-
- List<Publication> result = new ArrayList<Publication>();
- List<Relation> relist = mydoc.getRelations(type);
- for (Iterator<Relation> i=relist.iterator(); i.hasNext();) {
- Relation relation = i.next();
- Document relatedoc = (Document)relation.getTo();
- Publication related = owner.getPublication(relatedoc);
- if (related != null) {
- result.add(related);
- } else
- if (owner instanceof Scenario) { // The relation may cross steps belonging to a scenario and its owner study
- related = ((Scenario)owner).getOwnerStudy().getPublication(relatedoc);
- if (related != null) result.add(related);
- }
- }
- return result;
- }
-
- public File getSourceFile () {
-// ----------------------------
- return mydoc.getSourceFile();
- }
-
- public boolean isNewForOwner () {
-// -------------------------------
- return (isnew == 'Y');
- }
-
- public boolean isOutdated () {
-// ----------------------------
- return (isnew == 'O');
- }
-
- /**
+ /**
+ * Returns the state of this published document. It is the same than the state of the referenced document, unless this publication is
+ * out-of-date, in which case it is In-Work state.
+ *
+ * @see #outdate()
+ * @see #isOutdated()
+ * @return the document progress state
+ */
+ public ProgressState getProgressState() {
+ ProgressState res;
+ if (this.isOutdated()) {
+ res = ProgressState.inWORK; // Overrides the document state
+ } else {
+ res = mydoc.getProgressState();
+ }
+ return res;
+ }
+
+ public List<Publication> getRelations(final Class<? extends Relation> type) {
+ if (type == null) {
+ return null;
+ }
+
+ List<Publication> result = new ArrayList<Publication>();
+ List<Relation> relist = mydoc.getRelations(type);
+ for (Iterator<Relation> i = relist.iterator(); i.hasNext();) {
+ Relation relation = i.next();
+ Document relatedoc = (Document) relation.getTo();
+ Publication related = owner.getPublication(relatedoc);
+ if (related != null) {
+ result.add(related);
+ } else if (owner instanceof Scenario) { // The relation may cross steps belonging to a scenario and its owner study
+ related = owner.getOwnerStudy().getPublication(relatedoc);
+ if (related != null) {
+ result.add(related);
+ }
+ }
+ }
+ return result;
+ }
+
+ public File getSourceFile() {
+ return mydoc.getSourceFile();
+ }
+
+ public boolean isNewForOwner() {
+ return (isnew == 'Y');
+ }
+
+ public boolean isOutdated() {
+ return (isnew == 'O');
+ }
+
+ /**
* Get the isnew.
+ *
* @return the isnew
*/
public char getIsnew() {
return isnew;
}
+
/**
* Set the isnew.
- * @param isnew the isnew to set
+ *
+ * @param isnew
+ * the isnew to set
*/
- public void setIsnew(char isnew) {
+ public void setIsnew(final char isnew) {
this.isnew = isnew;
}
-
-/**
- * Returns the document version referenced by this Publication.
- */
- public Document value () {
-// ------------------------
- return mydoc;
- }
+
+ /**
+ * Returns the document version referenced by this Publication.
+ */
+ public Document value() {
+ return mydoc;
+ }
+
/**
* Set the mydoc.
- * @param mydoc the mydoc to set
+ *
+ * @param mydoc
+ * the mydoc to set
*/
- public void setValue (Document aDoc) {
+ public void setValue(final Document aDoc) {
this.mydoc = aDoc;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.dal.bo.kernel.Persistent#evict()
+ */
+ @Override
+ public void evict() {
+ super.evict();
+ // Evict the document
+ if (value() != null) {
+ value().evict();
+ }
+ }
}
\ No newline at end of file