KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > panels > InstallationGroupPanelAutomationHelper


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2007 JBoss Inc
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21 package com.izforge.izpack.panels;
22
23 import java.util.HashMap JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Vector JavaDoc;
26
27 import net.n3.nanoxml.XMLElement;
28
29 import com.izforge.izpack.Pack;
30 import com.izforge.izpack.installer.AutomatedInstallData;
31 import com.izforge.izpack.installer.PanelAutomation;
32 import com.izforge.izpack.panels.InstallationGroupPanel.GroupData;
33 import com.izforge.izpack.util.Debug;
34
35 /**
36  * An automation helper for the InstallationGroupPanel
37  *
38  * @author Scott.Stark@jboss.org
39  * @version $Revision:$
40  */

41 public class InstallationGroupPanelAutomationHelper
42     implements PanelAutomation
43 {
44     /**
45      *
46      */

47     public void makeXMLData(AutomatedInstallData idata, XMLElement panelRoot)
48     {
49         GroupData[] rows = (GroupData[]) idata.getAttribute("GroupData");
50         HashMap JavaDoc packsByName = (HashMap JavaDoc) idata.getAttribute("packsByName");
51         // Write out the group to pack mappings
52
for(int n = 0; n < rows.length; n ++)
53         {
54             GroupData gd = rows[n];
55             XMLElement xgroup = new XMLElement("group");
56             xgroup.setAttribute("name", gd.name);
57             Iterator JavaDoc names = gd.packNames.iterator();
58             while( names.hasNext() )
59             {
60                 String JavaDoc name = (String JavaDoc) names.next();
61                 Pack pack = (Pack) packsByName.get(name);
62                 int index = idata.availablePacks.indexOf(pack);
63                 XMLElement xpack = new XMLElement("pack");
64                 xpack.setAttribute("name", name);
65                 xpack.setAttribute("index", ""+index);
66                 xgroup.addChild(xpack);
67             }
68             panelRoot.addChild(xgroup);
69         }
70     }
71
72     /**
73      * TODO Need to add a InstallationGroupPanelAutomationHelper to read the
74      * xml data to allow an install group to specify the selected packs.
75      */

76     public boolean runAutomated(AutomatedInstallData idata,
77             XMLElement panelRoot)
78     {
79         String JavaDoc installGroup = idata.getVariable("INSTALL_GROUP");
80         Debug.trace("InstallationGroupPanelAutomationHelper: runAutomated, INSTALL_GROUP: "+installGroup);
81         if( installGroup != null )
82         {
83             Vector JavaDoc groups = panelRoot.getChildrenNamed("group");
84             for(int i = 0; i < groups.size(); i ++)
85             {
86                 XMLElement group = (XMLElement) groups.get(i);
87                 String JavaDoc name = group.getAttribute("name");
88                 Debug.trace("InstallationGroupPanelAutomationHelper: Checking INSTALL_GROUP against: "+name);
89                 if( name.equalsIgnoreCase(installGroup) )
90                 {
91                     Debug.trace("Found INSTALL_GROUP match for: "+installGroup);
92                     idata.selectedPacks.clear();
93                     Vector JavaDoc packs = group.getChildrenNamed("pack");
94                     Debug.trace(name+" pack count: "+packs.size());
95                     Debug.trace("Available pack count: "+idata.availablePacks.size());
96                     for(int j = 0; j < packs.size(); j ++)
97                     {
98                         XMLElement xpack = (XMLElement) packs.get(j);
99                         String JavaDoc pname = xpack.getAttribute("name");
100                         String JavaDoc indexStr = xpack.getAttribute("index");
101                         int index = Integer.parseInt(indexStr);
102                         if( index >= 0 )
103                         {
104                             Pack pack = (Pack) idata.availablePacks.get(index);
105                             idata.selectedPacks.add(pack);
106                             Debug.trace("Added pack: "+pack.name);
107                         }
108                     }
109                     Debug.trace("Set selectedPacks to: "+idata.selectedPacks);
110                     break;
111                 }
112             }
113         }
114         return true;
115     }
116
117 }
118
Popular Tags