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  
19  package org.caleigo.core;
20  
21  import org.caleigo.core.exception.*;
22  
23  /*** <Description for AbstractAction>
24   *
25   * @author  Dennis Zikovic
26   * @version 1.00
27   *
28   *//*
29   *
30   * WHEN        WHO               WHY & WHAT
31   * -----------------------------------------------------------------------------
32   * 2002-09-10  Dennis Zikovic    Creation
33   */
34  public abstract class AbstractEntityAction implements IEntityAction
35  {
36      // Constants ---------------------------------------------------------------
37      
38      // Data members ------------------------------------------------------------
39      private DataBundleDescriptor mDataBundleDescriptor;
40      private IEntityDescriptor mEntityDescriptor;
41      
42      private String mCodeName;
43      private String mDisplayName;
44      private String mDisplayHint;
45      
46      private int mCategoryFlags;
47      
48      // Constructors ------------------------------------------------------------
49      
50      /*** Creates a new instance of AbstractAction.
51       */
52      public AbstractEntityAction(IEntityDescriptor entityDescriptor, String codeName, String displayName)
53      {
54          this(entityDescriptor, codeName, displayName, null);
55      }
56      
57      /*** Creates a new instance of AbstractAction.
58       */
59      public AbstractEntityAction(IEntityDescriptor entityDescriptor, String codeName, String displayName, String displayHint)
60      {
61          // Initialize data members. 
62          mDataBundleDescriptor = new DataBundleDescriptor();
63          mEntityDescriptor = entityDescriptor;
64          mCodeName = codeName;
65          mDisplayName = displayName;
66          mDisplayHint = displayHint;
67          
68          // Allow subclasses to define the data bundle descriptor.
69          this.defineDataDescriptor();
70      }
71      
72      // Abstract methods --------------------------------------------------------
73      
74      /*** Performs the actions logic using the provided IActionData object.
75       * This method is defined by the IAction interface. 
76       */
77      public abstract void perform(IDataBundle data);
78      
79      /*** This method is called by the action objects constructor once and only 
80       * once. The method is expected to define the action data requriments
81       * (IDataBundleDescriptor) using the diferent add methods for descriptors
82       * defined in this class.
83       */
84      public abstract void defineDataDescriptor();
85      
86      // IAction implemntation ---------------------------------------------------
87      
88      /*** Access method that returns the IActionDataDescriptor for the IActionData
89       * theat the called action needs to perform its logic payload.
90       */ 
91      public IDataBundleDescriptor getDataBundleDescriptor()
92      {
93          return mDataBundleDescriptor;
94      }
95      
96      /*** Access method that returns the IEntityDescriptor object that the 
97       * called action object is a part of.
98       */
99      public IEntityDescriptor getEntityDescriptor()
100     {
101         return mEntityDescriptor;
102     }
103     
104     /*** Access method that returns the code name that can be used to identify
105      * the called IAction object.
106      */
107     public String getCodeName()
108     {
109         return mCodeName;
110     }
111     
112     /*** Access method that returns a end-user presentable name that can be used 
113      * as button and meny labels.
114      */
115     public String getDisplayName()
116     {
117         return mDisplayName;
118     }
119     
120     /*** Access method that returns a end-user presentable hint text that can be 
121      * used as a help text or fly-by hint.
122      */
123     public String getDisplayHint()
124     {
125         return mDisplayHint;
126     }
127     
128     /*** Access method that return true if the called action object has
129      * of the provided category flag set to true. 
130      */
131     public boolean isInCategory(int category)
132     {
133         return (mCategoryFlags & category) == category;
134     }
135 
136     // Help methods ------------------------------------------------------------
137     protected void addDataTypeDescriptor(DataType dataType, String codeName, String displayName, String displayHint)
138     {
139         mDataBundleDescriptor.addDataTypeDescriptor(dataType, codeName, displayName, displayHint);
140     }
141     
142     protected void addEntityDescriptor(IEntityDescriptor entityDescriptor, String codeName, String displayName, String displayHint)
143     {
144         mDataBundleDescriptor.addEntityDescriptor(entityDescriptor, codeName, displayName, displayHint);
145     }
146     
147     protected void addSelectionDescriptor(IEntityDescriptor entityDescriptor, String codeName, String displayName, String displayHint)
148     {
149         mDataBundleDescriptor.addSelectionDescriptor(entityDescriptor, codeName, displayName, displayHint);
150     }
151     
152     /*** Help method that validates the provided data and throws an 
153      * InvalidDataException if the validation failed.
154      */
155     protected void validateData(IDataBundle data)
156     {
157         if(data==null)
158             throw new InvalidDataException("Data bundle may not be null.");
159         ValidationResult result = data.validateData();
160         if(!data.validateData().isValid())
161             throw new InvalidDataException(result.getDisplayMessage());
162     }
163     
164     /*** Can be used by subclasses to set the actions catagery flags.
165      */
166     protected void setCategoryFlags(int flags)
167     {
168         mCategoryFlags = flags;
169     }
170 }