jai removed from license part 1
[mir.git] / source / mir / entity / adapter / EntityAdapterDefinition.java
index 68cdf2f..0c5bb63 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2001, 2002 The Mir-coders group
+ * Copyright (C) 2005 The Mir-coders group
  *
  * This file is part of Mir.
  *
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with  any library licensed under the Apache Software License,
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
- * (or with modified versions of the above that use the same license as the above),
- * and distribute linked combinations including the two.  You must obey the
- * GNU General Public License in all respects for all of the code used other than
- * the above mentioned libraries.  If you modify this file, you may extend this
+ * the code of this program with  any library licensed under the Apache Software License.
+ * You must obey the GNU General Public License in all respects for all of the code used
+ * other than the above mentioned libraries.  If you modify this file, you may extend this
  * exception to your version of the file, but you are not obligated to do so.
  * If you do not wish to do so, delete this exception statement from your version.
  */
 package mir.entity.adapter;
 
-import java.util.Calendar;\r
-import java.util.Date;\r
-import java.util.GregorianCalendar;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-import java.util.TimeZone;\r
-\r
-import mir.entity.Entity;\r
-import mir.misc.StringUtil;\r
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TimeZone;
+
+import mir.entity.Entity;
+import mir.misc.StringUtil;
 import mir.util.GeneratorFormatAdapters;
 
+/**
+ * <code>EntityAdapterDefinition</code> defines the fields for an entity adapter of
+ *  a particular "type". Custom calculated fields can be defined.
+ *
+ */
 public class EntityAdapterDefinition {
   private Map calculatedFields;
 
@@ -47,31 +49,76 @@ public class EntityAdapterDefinition {
     calculatedFields = new HashMap();
   }
 
+  /**
+   *
+   *
+   * @param anEntity the entity that will be wrapped by the entity adapter
+   * @param aModel the base model
+   * @return the resulting entity adapter
+   */
   public EntityAdapter makeEntityAdapter(Entity anEntity, EntityAdapterModel aModel) {
     return new EntityAdapter(anEntity, this, aModel);
   }
 
+  /**
+   *
+   * @param aFieldName
+   * @return the <code>CalculatedField</code> if it exists. <code>null</code> otherwise
+   */
   public CalculatedField getCalculatedField(String aFieldName) {
     return (CalculatedField) calculatedFields.get(aFieldName);
   }
 
+  /**
+   *
+   * @param aFieldName
+   * @return boolean true if aFieldName is a calculated Field
+   */
   public boolean hasCalculatedField(String aFieldName) {
     return calculatedFields.containsKey(aFieldName);
   }
 
+  /**
+   *
+   * @param aFieldName
+   * @param aField
+   */
   public void addCalculatedField(String aFieldName, CalculatedField aField) {
     calculatedFields.put(aFieldName, aField);
   }
 
+  /**
+   * To add a calculated field based on a "mir" date field: a string field of the form yyyyMMdd[hhmm]
+   *
+   * @param aDestinationFieldName
+   * @param aSourceFieldName
+   * @param aDefaultTimezone
+   */
   public void addMirDateField(String aDestinationFieldName, String aSourceFieldName, String aDefaultTimezone) {
     addCalculatedField(aDestinationFieldName, new MirDateField(aSourceFieldName, aDefaultTimezone));
   }
 
+  /**
+   * Adds a calculated field based on a db date field
+   *
+   * @param aDestinationFieldName the field name of the calculated field
+   * @param aSourceFieldName the field name of the entity (must be a date field)
+   * @param aDefaultTimezone the default timezone to use
+   */
   public void addDBDateField(String aDestinationFieldName, String aSourceFieldName, String aDefaultTimezone) {
     addCalculatedField(aDestinationFieldName, new DBDateField(aSourceFieldName, aDefaultTimezone));
   }
 
+  /**
+   * a calculated field: field gets its value from other fields.
+   */
   public interface CalculatedField {
+    /**
+     * Method to retrieve the calculated value of the field.
+     *
+     * @param anEntityAdapter the entity
+     * @return the value of the field.
+     */
     public Object getValue(EntityAdapter anEntityAdapter);
   }
 
@@ -85,9 +132,8 @@ public class EntityAdapterDefinition {
     }
 
     public Object getValue(EntityAdapter anEntityAdapter) {
-
          Object result = null;
-         String textValue = anEntityAdapter.getEntity().getValue(fieldName);
+         String textValue = anEntityAdapter.getEntity().getFieldValue(fieldName);
          Calendar calendar = GregorianCalendar.getInstance();
          int year;
          int month;
@@ -126,7 +172,7 @@ public class EntityAdapterDefinition {
 
     public Object getValue(EntityAdapter anEntityAdapter) {
       Object result = null;
-      String text = anEntityAdapter.getEntity().getValue(fieldName);
+      String text = anEntityAdapter.getEntity().getFieldValue(fieldName);
 
       if (text!=null) {
         try {