source: vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/BeanUtil.java@ 865

Last change on this file since 865 was 865, checked in by tobias, on Apr 20, 2010 at 5:21:42 PM

comments added
all methods of the wsdl file implemented

File size: 5.7 KB
Line 
1package de.dass_it.vanhelsing.gui;
2
3import javax.faces.application.FacesMessage;
4import javax.faces.application.FacesMessage.Severity;
5import javax.faces.context.FacesContext;
6import javax.faces.model.SelectItem;
7import java.util.ResourceBundle;
8import java.util.Locale;
9import java.util.HashMap;
10
11//import org.apache.log4j.Logger;
12
13/**
14 * Helper class to encapsulate common bean methods.
15 * Managed beans will extend this class either directly or
16 * via a data structure helper class like TreeNavigation
17 * @author tgoecke
18 */
19public class BeanUtil {
20 // Logging
21
22 // protected final Logger logger = Logger.getLogger(this.getClass());
23
24 // Messagebundles
25 /**
26 * getter method for a property value
27 * @param key key of the queried property, e.g. director.client.name.type
28 * @return s value of the property
29 */
30 public static String getProperty(String key) {
31 String s = PropertyBundle.getProperty(key);
32 return s;
33 }
34 /**
35 * convenience method to return all properties of a given attribute
36 * @param key key contains the key value of the set of properties for a given attribute<br/>
37 * except for the suffix which defines the content type of the property.
38 * @return bundle contains all four properties of an attribute
39 */
40 public static String[] getProperties(String key) {
41 String[] suffix = { "ref", "type", "required", "def" };
42 String[] bundle = new String[4];
43 for (int i = 0; i < 4; i++) {
44 bundle[i] = BeanUtil.getProperty(key + "." + suffix[i]);
45 }
46 return bundle;
47 }
48 /**
49 * returns true if the given attribute is required
50 * @param type resource type of the attribute, like Client
51 * @param key attribute name of the resource, like Port
52 * @return true if the field is required
53 */
54 public static boolean getRequired(String type, String key) {
55 String s = getFieldProperty(type, key, 2);
56 if (s.equals("true"))
57 return true;
58 return false;
59 }
60 /**
61 * returns the data type of a given attribute.
62 * @param type resource type of the attribute, like Client
63 * @param key attribute name of the resource, like Port
64 * @return data type of the attribute
65 */
66 public static String getDataType(String type, String key) {
67 return getFieldProperty(type, key, 1);
68 }
69
70 // getRenderer returns rendererType based on properties
71 /**
72 * returns the renderer for a given attribute
73 * @param type resource type of the attribute, like Client
74 * @param key attribute name of the resource, like Port
75 * @return "inputText", "radioGroup" or "selectOneMenu"
76 *
77 */
78 public static String getRenderer(String type, String key) {
79 return getFieldProperty(type, key, 0);
80 }
81 /**
82 * returns properties for a given attribute depending on the value of i.
83 * One should use the getter method for the property.
84 * @param type resource type of the attribute, like Client
85 * @param key attribute name of the resource, like Port
86 * @param i i maybe between 0 and 3. The return value of the method is selected by the value of i
87 * @return one of the four properties as a String of a given attribute.
88 */
89 public static String getFieldProperty(String type, String key, int i) {
90 String daemon = "director";
91 String res = "inputText";
92 if (type.startsWith("SD")) {
93 daemon = "storagedaemon";
94 }
95 if (type.startsWith("FD")) {
96 daemon = "filedaemon";
97 }
98 type = type.toLowerCase();
99 key = key.toLowerCase();
100 key = key.replaceAll(" ", "");
101 String result[] = getProperties((daemon + "." + type + "." + key));
102 if (i == 0) {
103 if (result[1].equals("boolean")) {
104 return "radioGroup";
105 }
106 if (!(result[0].equals("0"))) {
107 return "selectOneMenu";
108 }
109 return res;
110 }
111 if (i == 2)
112 return result[2];
113 if (i == 1)
114 return result[1];
115 if (i == 3)
116 return result[3];
117 return res;
118 }
119
120 // Statusmeldungen an den Client
121 /**
122 * sends an information type message to the message field at the bottom of the screen
123 * @param client could contain an identifier of a client. value can be set to null
124 * @param message the message to be displayed at the clients view
125 */
126 public static void setInfoMessage(String client, String message) {
127 FacesContext.getCurrentInstance().addMessage(client,
128 new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
129 }
130 /**
131 * sends an error type message to the message field at the bottom of the screen
132 * @param client could contain an identifier of a client. value can be set to null
133 * @param message the message to be displayed at the clients view
134 */
135 public static void setErrorMessage(String client, String message) {
136 FacesContext.getCurrentInstance()
137 .addMessage(
138 client,
139 new FacesMessage(FacesMessage.SEVERITY_ERROR, message,
140 message));
141 }
142
143 // Linkout to Bacula documentation
144 // ListItemsConfigView
145 // ListItemsTopologyView
146 // ListItemsJobSchedule
147
148 // GetParameterFromContext
149 /**
150 * returns values of a given parameter of the FacesContext
151 * @param name name of the parameter e.g. the id of a parameter in the view.
152 * @return value of a given parameter
153 */
154 public static String getRequestParameter(String name) {
155 return (String) FacesContext.getCurrentInstance().getExternalContext()
156 .getRequestParameterMap().get(name);
157 }
158 /**
159 * translation method for resource or object names.
160 * @param type untranslated name
161 * @return translated name if there is a translation. Otherwise type will be returned.
162 */
163 public static String getAccessType(String type) {
164 String result = new String();
165 HashMap<String, String> map = new HashMap<String, String>();
166 map.put("jobdefs", "job");
167 map.put("SDStorage", "Storage");
168 map.put("Storage", "SDStorage");
169 map.put("SDDevice", "Device");
170 map.put("Device", "SDDevice");
171 map.put("SDDevice", "Device");
172 result = map.get(type);
173 if (result != null)
174 return result;
175 return type;
176 }
177
178}
Note: See TracBrowser for help on using the repository browser.