KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Created on 19 avr. 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 import hero.interfaces.*;
15 import hero.interfaces.ProjectSessionHome;
16 import hero.interfaces.ProjectSession;
17
18
19 /**
20  * The aim of this class is to transform data from a Bonita project to a xml file
21  * @author sempereb
22  */

23 public class BonitaProjectAdapter {
24
25
26
27
28     /**
29      * Default class constructor
30      */

31     public BonitaProjectAdapter(){};
32     
33     
34     
35
36         
37     /**
38      * Get the bonita properties as key value hash map
39      * @param theProjectName : The project concerned.
40      * @return HashMap the table containing the properties.
41      */

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

68             //Property value of Bonita
69
BnProjectPropertyValue pv = null;
70             
71             //The current key of the property value object
72
String JavaDoc currentKey = "";
73             
74             //The current value of the property value object
75
String JavaDoc currentValue = "";
76             String JavaDoc possibleValue = "";
77
78             //For all the keys we have to retrieve the associated value
79
Iterator JavaDoc it = collectionProperties.iterator();
80             
81             while (it.hasNext())
82             {
83                 //Getting the values
84
pv = (BnProjectPropertyValue)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                                 // we add a pipe | after each possible values
102
currentValue = currentValue + "|" + (String JavaDoc)itValues.next();
103                             }
104                         }
105
106                 //Adding key and value in a hashMap
107
hMap.put(currentKey, 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      * @return Document document with the process information : name & properties.
128      * @throws IOExecption
129      */

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

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