KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > console > manager > interfaces > impl > DefaultTreeInfo


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.console.manager.interfaces.impl;
23
24 import org.jboss.console.manager.interfaces.ManageableResource;
25 import org.jboss.console.manager.interfaces.TreeAction;
26 import org.jboss.console.manager.interfaces.TreeInfo;
27 import org.jboss.console.manager.interfaces.TreeNode;
28 import org.jboss.console.manager.interfaces.TreeNodeMenuEntry;
29
30 import java.util.ArrayList JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.Iterator JavaDoc;
33
34 /**
35  * <description>
36  *
37  * @see <related>
38  *
39  * @author <a HREF="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>.
40  * @version $Revision: 37459 $
41  *
42  * <p><b>Revisions:</b>
43  *
44  * <p><b>December 16, 2002 Sacha Labourey:</b>
45  * <ul>
46  * <li> First implementation </li>
47  * </ul>
48  */

49
50 public class DefaultTreeInfo
51    implements TreeInfo
52 {
53    
54    // Constants -----------------------------------------------------
55

56    // Attributes ----------------------------------------------------
57

58    protected ManageableResource[] roots = null;
59    protected HashMap JavaDoc resources = new HashMap JavaDoc ();
60    protected TreeAction homeAction = null;
61    protected String JavaDoc jbossVersion = null;
62    protected long version = 0;
63    protected TreeNodeMenuEntry[] rootMenus = new TreeNodeMenuEntry[0];
64    protected String JavaDoc iconUrl = null;
65    
66    // Static --------------------------------------------------------
67

68    // Constructors --------------------------------------------------
69

70    public DefaultTreeInfo ()
71    {
72       Package JavaDoc jbossPackage = Package.getPackage("org.jboss");
73       jbossVersion = jbossPackage.getImplementationTitle() + " " +
74                jbossPackage.getImplementationVersion();
75
76    }
77    
78    // Public --------------------------------------------------------
79

80    public ManageableResource[] getRootResources ()
81    {
82       return this.roots;
83    }
84    
85    public void setRootResources (ManageableResource[] roots)
86    {
87       this.roots = roots;
88    }
89    
90    public synchronized TreeNode[] getTreesForResource (ManageableResource resource)
91    {
92       ArrayList JavaDoc content = (ArrayList JavaDoc)resources.get (resource);
93       if (content == null || content.size () == 0)
94          return null;
95       else
96       {
97          TreeNode[] result = new TreeNode[content.size ()];
98          return (TreeNode[])content.toArray (result);
99       }
100    }
101    
102    public synchronized void addTreeToResource (ManageableResource resource, TreeNode tree)
103    {
104       ArrayList JavaDoc content = (ArrayList JavaDoc)resources.get (resource);
105       if (content == null || content.size () == 0)
106       {
107          content = new ArrayList JavaDoc ();
108          resources.put (resource, content);
109       }
110       
111       if (!content.contains (tree))
112          content.add (tree);
113    }
114    
115    public TreeAction getHomeAction ()
116    {
117       return this.homeAction;
118    }
119       
120    public void setHomeAction (TreeAction homeAction)
121    {
122       this.homeAction = homeAction;
123    }
124    
125    public String JavaDoc getDescription ()
126    {
127       return jbossVersion;
128    }
129       
130    public void setRootMenus (TreeNodeMenuEntry[] menus)
131    {
132       this.rootMenus = menus;
133    }
134    
135    public TreeNodeMenuEntry[] getRootMenus ()
136    {
137       return this.rootMenus;
138    }
139
140     // Z implementation ----------------------------------------------
141

142    // Object overrides -----------------------------------------------
143

144    public String JavaDoc toString ()
145    {
146       String JavaDoc result = "Root: " + roots + "\n" ;
147       
148       Iterator JavaDoc iter = resources.keySet ().iterator ();
149       while (iter.hasNext ())
150       {
151          ManageableResource key = (ManageableResource)iter.next();
152          ArrayList JavaDoc content = (ArrayList JavaDoc)resources.get (key);
153          
154          result+=" Key: " + key + "\n";
155          
156          for (int i = 0; i < content.size(); i++)
157          {
158             result += " Value: " + content.get(i);
159          }
160       
161          result+=" ----\n";
162
163       }
164       return result;
165    }
166    
167    public long getTreeVersion ()
168    {
169       return this.version;
170    }
171    
172    public void setTreeVersion (long version)
173    {
174       this.version = version;
175    }
176    
177    public String JavaDoc getIconUrl ()
178    {
179       return this.iconUrl;
180    }
181    
182    public void setIconUrl (String JavaDoc url)
183    {
184       this.iconUrl = url;
185    }
186    
187    // Package protected ---------------------------------------------
188

189    // Protected -----------------------------------------------------
190

191    // Private -------------------------------------------------------
192

193    // Inner classes -------------------------------------------------
194

195 }
196
Popular Tags