1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
34 private IDataBundleDescriptor mDataBundleDescriptor;
35 private Object[] mDataObjects;
36
37
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
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
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
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 }