KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mc > formgenerator > bonita > BonitaActivityAdapter


1 /*
2  * Created on 03 mai. 2004 by the Message Center Team
3  *
4  */

5 package mc.formgenerator.bonita;
6
7 import java.io.IOException JavaDoc;
8 import java.util.Collection JavaDoc;
9 import java.util.HashMap JavaDoc;
10 import java.util.Iterator JavaDoc;
11
12 import org.w3c.dom.Document JavaDoc;
13
14 //Bonita imports
15
import hero.interfaces.*;
16 import hero.interfaces.ProjectSessionHome;
17 import hero.interfaces.ProjectSession;
18
19
20 /**
21  * The aim of this class is to transform Bonita activity data to a xml file
22  * @author sempereb
23  */

24 public class BonitaActivityAdapter {
25
26
27
28
29     /**
30      * Default class constructor
31      */

32     public BonitaActivityAdapter(){};
33     
34     
35     
36
37         
38     /**
39      * Get the bonita properties for a specified activity as key value hash map
40      * @param theProjectName : The process concerned.
41      * @param theActivityName : The activity concerned.
42      * @return HashMap the table containing the properties.
43      */

44     private HashMap JavaDoc getHBonitaData(String JavaDoc theProjectName, String JavaDoc theActivityName){
45             
46         //Hash map where 'Bonita key - value' will be put
47
HashMap JavaDoc hMap = new HashMap JavaDoc();
48             
49         //The local home
50
ProjectSessionHome projecth = null;
51         
52         //The bean
53
ProjectSession project = null;
54         
55         try{
56             //Getting local home by using JNDI
57
projecth = ProjectSessionUtil.getHome();
58             
59             //Project creation
60
project = projecth.create();
61                       
62             //Project initialisation
63
project.initProject(theProjectName);
64             
65             //We are now able to acess Bonita api and get properties for the concerned
66
Collection JavaDoc collectionActivityProperties = project.getNodeProperties(theActivityName);
67             
68             //Number of bean instances responding
69

70             //Property value of Bonita
71
BnNodePropertyValue pv = null;
72             
73             //The current key of the property value object
74
String JavaDoc currentKey = "";
75             
76             //The current value of the property value object
77
String JavaDoc currentValue = "";
78
79             //For all the keys we have to retrieve the associated value
80
Iterator JavaDoc it = collectionActivityProperties.iterator();
81             
82             while (it.hasNext()){
83                 //Getting the values
84
pv = (BnNodePropertyValue)it.next();
85             
86                 //Retrieve the key
87
currentKey = pv.getTheKey();
88                 currentValue = pv.getTheValue();
89                 if (currentValue==null) currentValue = "";
90                 //And the value or possible values
91
Collection JavaDoc possibleValues = pv.getPossibleValues();
92                         if (possibleValues != null)
93                         {
94                     //Pb with the StringTokenizer if ""
95
if (currentValue.equals("")) currentValue=" ";
96                     //For all the keys we have to retrieve the associated value
97
Iterator JavaDoc itValues = possibleValues.iterator();
98                     // each possible values are added after the value
99
while (itValues.hasNext())
100                     {
101                                 currentValue = currentValue + "|" + (String JavaDoc)itValues.next();
102                             }
103                         }
104                 
105                 //Adding key and value in a hashMap
106
hMap.put(currentKey, currentValue);
107                 currentValue = "";
108             }
109
110             //Returns the hash map
111
return hMap;
112         }
113         catch(Exception JavaDoc e){
114             System.out.println(e + " " + e.getMessage());
115             return null;
116         }
117     }
118     
119     
120     
121
122     
123     /**
124      * Provides a Document output for Bonita data
125      * @param theHashMap : The table containing the properties.
126      * @param theProjectName : The project concerned.
127      * @param theProjectName the activity concerned in the project
128      * @return Document document with the activity information : project name & activity name & activity properties.
129      * @throws IOExecption
130      */

131     private Document JavaDoc generateBonitaDataDocument(HashMap JavaDoc theHashMap, String JavaDoc theProjectName, String JavaDoc theActivityName)
132         throws IOException JavaDoc{
133         
134         //DOM
135
Document JavaDoc document = null;
136         
137         //a parser to generate the xml document from the dataProcess
138
DocumentParser parser = new DocumentParser();
139         
140         //Create the dataProcess structure with bonita key value
141
DataActivity data = new DataActivity(theProjectName, theActivityName, theHashMap);
142             
143         //Generate the xml document representing the dataProcess
144
if( data != null )
145             document = parser.createDocument(data);
146             
147         return document;
148     }
149     
150     
151     
152     
153     /**
154      * Get the Bonita activity data identified by its name and put them in a DOM
155      * @param theProjectName the name of the project we have to get process informations
156      * @param theActivityName the name of the activityname concerned
157      * @return the document that represents bonita activity data
158      * @throws LoginException
159      * @throws IOException
160      */

161     public Document JavaDoc getActivityData(String JavaDoc theProjectName, String JavaDoc theActivityName)
162         throws IOException JavaDoc{
163         
164         //H map of Bonita data
165
HashMap JavaDoc bonitaMap = new HashMap JavaDoc();
166         
167         //Set Bonita data in H map
168
bonitaMap = this.getHBonitaData(theProjectName, theActivityName);
169         
170         //Document generated
171
return this.generateBonitaDataDocument(bonitaMap, theProjectName, theActivityName);
172     }
173 }
174
175
176
Popular Tags