View Javadoc

1   /* (c) Copyright 2003 Caleigo AB, All rights reserved. 
2    * 
3    * This library is free software; you can redistribute it and/or
4    * modify it under the terms of the GNU Lesser General Public
5    * License as published by the Free Software Foundation; either
6    * version 2.1 of the License, or (at your option) any later version.
7    * 
8    * This library is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11   * Lesser General Public License for more details.
12   * 
13   * You should have received a copy of the GNU Lesser General Public
14   * License along with this library; if not, write to the Free Software
15   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16   *  
17   */
18  package org.caleigo.core;
19  
20  /*** <Description for ActionData>
21   *
22   * @author  Dennis Zikovic
23   * @version 1.00
24   *
25   *//*
26   *
27   * WHEN        WHO               WHY & WHAT
28   * -----------------------------------------------------------------------------
29   * 2002-09-11  Dennis Zikovic    Creation
30   */
31  public class DataBundle implements IDataBundle
32  {
33      // Data members ------------------------------------------------------------
34      private IDataBundleDescriptor mDataBundleDescriptor;
35      private Object[] mDataObjects;
36      
37      // Constructors ------------------------------------------------------------
38      
39      /*** Creates a new instance of ActionData
40       */
41      public DataBundle(IDataBundleDescriptor dataDescriptor)
42      {
43          mDataBundleDescriptor = dataDescriptor;
44          mDataObjects = new Object[mDataBundleDescriptor.getItemCount()];
45      }
46      
47      // IDataProvider implementation --------------------------------------------
48      
49      /*** Access method the returns the identified data from the object.
50       */
51      public Object getData(String codeName)
52      {
53          int index = mDataBundleDescriptor.getItemIndex(codeName);
54          if(index>0)
55              return this.getData(index);
56          else
57              return null;
58      }
59      
60      // IDataConsumer implementation --------------------------------------------
61      
62      /*** Sets the data identified by the provided code name.
63       */
64      public void setData(String codeName, Object value)
65      {
66          int index = mDataBundleDescriptor.getItemIndex(codeName);
67          if(index>0)
68              this.setData(index, value);
69      }
70      
71      /*** This method implies to the called object to fetch all data it can 
72       * consume from the provided IDataProvider object.
73       */    
74      public void setData(IDataProvider dataProvider)   
75      {
76          for(int j=0; j<mDataBundleDescriptor.getItemCount(); j++)
77              this.setData(mDataBundleDescriptor.getCodeName(j), dataProvider.getData(mDataBundleDescriptor.getCodeName(j)));
78      }
79      
80      // IActionData implementation ----------------------------------------------
81      
82      /*** Access method that returns the indexed data object.
83       */
84      public Object getData(int index)
85      {
86          return mDataObjects[index];
87      }
88      
89      /*** Mutation method that replaces the indexed data object with the provided
90       * object.
91       */
92      public void setData(int index, Object data)
93      {
94          mDataObjects[index] = data;
95      }
96      
97      /*** Access method that returns the IDataBundleDescriptor object that defines
98       * the called IDataBundle structure.
99       */
100     public IDataBundleDescriptor getDataBundleDescriptor()
101     {
102         return mDataBundleDescriptor;
103     }
104     
105     /*** Help method that validates the data contained in the called action data
106      * object and returns a ValidationResult object. Call isValid on the 
107      * returned object to verify data validity. Never returns null.
108      */
109     public ValidationResult validateData()
110     {
111         return mDataBundleDescriptor.validateData(this);
112     }
113 }