Ignore:
Timestamp:
Apr 16, 2010, 5:55:54 PM (14 years ago)
Author:
tobias
Message:

javadoc added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/BeanUtil.java

    r862 r864  
    11package de.dass_it.vanhelsing.gui;
    2 
    3 
    42
    53import javax.faces.application.FacesMessage;
     
    97import java.util.ResourceBundle;
    108import java.util.Locale;
    11 
    12 
     9import java.util.HashMap;
    1310
    1411//import org.apache.log4j.Logger;
    1512
    16 /*
     13/**
    1714 * Helper class to encapsulate common bean methods.
    1815 * Managed beans will extend this class either directly or
     
    2017 */
    2118public class BeanUtil {
    22         //Logging
    23    
    24         //protected final Logger logger = Logger.getLogger(this.getClass());
    25    
    26         //Messagebundles
    27         public static String getProperty(String key){
     19        // Logging
     20
     21        // protected final Logger logger = Logger.getLogger(this.getClass());
     22
     23        // Messagebundles
     24        /**
     25         * getter method for a property value
     26         * @param key   key of the queried property, e.g. director.client.name.type
     27         * @return s    value of the property
     28         */
     29        public static String getProperty(String key) {
    2830                String s = PropertyBundle.getProperty(key);
    2931                return s;
    3032        }
    31        
    32         public static String[] getProperties(String key){
    33                 String[] suffix = {"ref", "type", "required", "def"};
     33        /**
     34         *
     35         * @param key   key contains the key value of the set of properties for a given attribute<br/>
     36         *                              except for the suffix which defines the content type of the property.
     37         * @return      bundle  contains all four properties of an attribute
     38         */
     39        public static String[] getProperties(String key) {
     40                String[] suffix = { "ref", "type", "required", "def" };
    3441                String[] bundle = new String[4];
    3542                for (int i = 0; i < 4; i++) {
    36                         bundle[i] = BeanUtil.getProperty(key+"."+suffix[i]);
     43                        bundle[i] = BeanUtil.getProperty(key + "." + suffix[i]);
    3744                }
    3845                return bundle;
    3946        }
    40         public static boolean getRequired(String type, String key){
     47        /**
     48         *
     49         * @param type  resource type of the attribute, like Client
     50         * @param key   attribute name of the resource, like Port
     51         * @return              true if the field is required or false
     52         */
     53        public static boolean getRequired(String type, String key) {
    4154                String s = getFieldProperty(type, key, 2);
    42                 if (s.equals("true") )return true;
     55                if (s.equals("true"))
     56                        return true;
    4357                return false;
    4458        }
    45         public static String getDataType(String type, String key){
     59        /**
     60         * returns the data type of a given attribute.
     61         * @param type  resource type of the attribute, like Client
     62         * @param key   attribute name of the resource, like Port
     63         * @return              data type of the attribute
     64         */
     65        public static String getDataType(String type, String key) {
    4666                return getFieldProperty(type, key, 1);
    4767        }
    48         //getRenderer returns rendererType based on properties
    49         public static String getRenderer(String type, String key){
     68
     69        // getRenderer returns rendererType based on properties
     70        /**
     71         * returns the renderer for a given attribute
     72         * @param type  resource type of the attribute, like Client
     73         * @param key   attribute name of the resource, like Port
     74         * @return              "inputText", "radioGroup" or "selectOneMenu"
     75         *                             
     76         */
     77        public static String getRenderer(String type, String key) {
    5078                return getFieldProperty(type, key, 0);
    5179        }
    52         public static String getFieldProperty(String type, String key, int i){
     80        /**
     81         * returns properties for a given attribute depending on the value of i.
     82         * One should use the getter method for the property.
     83         * @param type  resource type of the attribute, like Client
     84         * @param key   attribute name of the resource, like Port
     85         * @param i             i maybe between 0 and 3. The return value of the method is selected by the value of i
     86         * @return              one of the four properties as a String of a given attribute.
     87         */
     88        public static String getFieldProperty(String type, String key, int i) {
    5389                String daemon = "director";
    5490                String res = "inputText";
    55                 if (type.startsWith("SD")){
     91                if (type.startsWith("SD")) {
    5692                        daemon = "storagedaemon";
    5793                }
    58                 if (type.startsWith("FD")){
     94                if (type.startsWith("FD")) {
    5995                        daemon = "filedaemon";
    6096                }
     
    6298                key = key.toLowerCase();
    6399                key = key.replaceAll(" ", "");
    64                 String result[] = getProperties((daemon+"."+type+"."+key));
     100                String result[] = getProperties((daemon + "." + type + "." + key));
    65101                if (i == 0) {
    66                         if (result[1].equals("boolean")){
    67                                 return "radioGroup"; 
     102                        if (result[1].equals("boolean")) {
     103                                return "radioGroup";
    68104                        }
    69                         if (!(result[0].equals("0"))){
     105                        if (!(result[0].equals("0"))) {
    70106                                return "selectOneMenu";
    71                         }               
     107                        }
    72108                        return res;
    73109                }
    74                 if (i == 2) return result[2];
    75                 if (i == 1) return result[1];
    76                 if (i == 3) return result[3];
     110                if (i == 2)
     111                        return result[2];
     112                if (i == 1)
     113                        return result[1];
     114                if (i == 3)
     115                        return result[3];
    77116                return res;
    78117        }
    79        
    80     //Statusmeldungen an den Client
    81     public static void setInfoMessage(String client, String message){
    82         FacesContext.getCurrentInstance().addMessage(client, new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
    83     }
    84     public static void setErrorMessage(String client, String message){
    85         FacesContext.getCurrentInstance().addMessage(client, new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message));
    86     }
    87    
    88         //Linkout to Bacula documentation
    89         //ListItemsConfigView
    90         //ListItemsTopologyView
    91         //ListItemsJobSchedule
    92        
    93         //GetParameterFromContext
    94         public static String getRequestParameter(String name){
    95                 return (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(name);
     118
     119        // Statusmeldungen an den Client
     120        /**
     121         * sends an information type message to the message field at the bottom of the screen
     122         * @param client        could contain an identifier of a client. value can be set to null
     123         * @param message       the message to be displayed at the clients view
     124         */
     125        public static void setInfoMessage(String client, String message) {
     126                FacesContext.getCurrentInstance().addMessage(client,
     127                                new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
    96128        }
    97        
    98         public static String getAccessType(String type){
    99                 if (type.equals("jobdefs")) return "job";
     129        /**
     130         * sends an error type message to the message field at the bottom of the screen
     131         * @param client        could contain an identifier of a client. value can be set to null
     132         * @param message       the message to be displayed at the clients view
     133         */
     134        public static void setErrorMessage(String client, String message) {
     135                FacesContext.getCurrentInstance()
     136                                .addMessage(
     137                                                client,
     138                                                new FacesMessage(FacesMessage.SEVERITY_ERROR, message,
     139                                                                message));
     140        }
     141
     142        // Linkout to Bacula documentation
     143        // ListItemsConfigView
     144        // ListItemsTopologyView
     145        // ListItemsJobSchedule
     146
     147        // GetParameterFromContext
     148        /**
     149         * returns values of a given parameter of the FacesContext
     150         * @param name  name of the parameter e.g. the id of a parameter in the view.   
     151         * @return      value of a given parameter
     152         */
     153        public static String getRequestParameter(String name) {
     154                return (String) FacesContext.getCurrentInstance().getExternalContext()
     155                                .getRequestParameterMap().get(name);
     156        }
     157        /**
     158         * translation method for resource or object names.
     159         * @param type  untranslated name
     160         * @return              translated name if there is a translation. Otherwise type will be returned.
     161         */
     162        public static String getAccessType(String type) {
     163                String result = new String();
     164                HashMap<String, String> map = new HashMap<String, String>();
     165                map.put("jobdefs", "job");
     166                map.put("SDStorage", "Storage");
     167                map.put("Storage", "SDStorage");
     168                map.put("SDDevice", "Device");
     169                map.put("Device", "SDDevice");
     170                map.put("SDDevice", "Device");
     171                result = map.get(type);
     172                if (result != null)
     173                        return result;
    100174                return type;
    101175        }
    102        
     176
    103177}
Note: See TracChangeset for help on using the changeset viewer.