Salome HOME
Siman codebase is refactored. Spring beans are introduced in the context.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / som / File.java
diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/File.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/File.java
new file mode 100644 (file)
index 0000000..9da39a7
--- /dev/null
@@ -0,0 +1,110 @@
+package org.splat.dal.bo.som;
+/**
+ * Class of meta files representing physical files under the control of Study Manager.
+ * Typically, the files represented by this class are source files of Documents and exports in different formats.
+ * The path of such files is relative to the vault of the repository of Study Manager.
+ * When creating a Document, as the source file is produced by the caller which creates the Document, the corresponding
+ * physical file may not exist at instantiation time.
+ * 
+ * @author    Daniel Brunier-Coulin
+ * @copyright OPEN CASCADE 2012
+ */
+
+import java.util.Calendar;
+import java.util.Date;
+
+import org.splat.dal.bo.kernel.Persistent;
+import org.splat.dal.dao.som.Database;
+
+
+public class File extends Persistent {
+
+//  Persistent fields
+    protected String  format;
+    protected String  path;
+    protected Date    date;
+
+//  Transient fields
+    private   java.io.File  myfile;        // For optimization
+
+//  ==============================================================================================================================
+//  Construction
+//  ==============================================================================================================================
+
+//  Database fetch constructor
+    protected File () {
+//  -----------------
+      this.myfile = null;
+    }
+//  Internal constructors
+    protected File (String path) {
+//  ----------------------------
+      Calendar  current = Calendar.getInstance();
+      String[]  table   = path.split("\\x2E");
+
+      this.format = table[table.length-1];
+      this.path   = path;                  // The corresponding physical file may not exist yet
+      this.date   = current.getTime();     // Today
+      this.myfile = null;
+    }
+    protected File (String path, String format, Date date) {
+//  ------------------------------------------------------
+      this.path   = path;                  // The corresponding physical file may not exist yet
+      this.format = format;                // The format name may be different from the physical file extension
+      this.date   = date;
+      if (date == null) {
+        Calendar current = Calendar.getInstance();
+        this.date = current.getTime();     // Today
+      }
+      this.myfile = null;
+    }
+
+//  ==============================================================================================================================
+//  Public member functions
+//  ==============================================================================================================================
+/**
+ * Returns the data file associated to this meta file.
+ * 
+ * @return the associated data file. If this meta data is an empty document, the returned file does not exist.
+ */
+    public java.io.File asFile () {
+//  -----------------------------
+      if (myfile == null) myfile = new java.io.File(Database.getRepositoryVaultPath() + path);
+      return myfile;
+    }
+
+    public Date getDate () {
+//  ----------------------
+      return date;
+    }
+
+    public String getFormat () {
+//  --------------------------
+      return format;
+    }
+
+    public String getName () {
+//  ------------------------
+      return this.asFile().getName();
+    }
+
+    public String getRelativePath () {
+//  --------------------------------
+      return path;
+    }
+
+    public boolean exists () {             // Shortcut
+//  ------------------------
+      return (this.asFile().exists());
+    }
+
+//  ==============================================================================================================================
+//  Protected service
+//  ==============================================================================================================================
+
+    protected void changePath (String path) {
+//  ---------------------------------------
+      this.path   = path;
+      this.myfile = null;
+    }
+}
\ No newline at end of file