KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > webui > util > MBeanUtils


1 /**
2  * Copyright 2004-2005 jManage.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.jmanage.webui.util;
17
18 import org.jmanage.core.management.ObjectAttribute;
19 import org.jmanage.core.management.ObjectOperationInfo;
20 import org.jmanage.core.management.ObjectAttributeInfo;
21
22 import java.util.List JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Date JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import java.math.BigInteger JavaDoc;
27 import java.math.BigDecimal JavaDoc;
28 import java.lang.reflect.Array JavaDoc;
29
30 /**
31  * Contains some mbean utility methods, which are used in the web layer
32  *
33  * date: Oct 15, 2004
34  * @author Rakesh Kalra
35  */

36 public class MBeanUtils {
37
38     public static String JavaDoc jsEscape(String JavaDoc str){
39         StringBuffer JavaDoc buff = new StringBuffer JavaDoc(str.length());
40         for(int i=0; i<str.length(); i++){
41             final char ch = str.charAt(i);
42             if(ch == '"'){
43                 buff.append("&quot;");
44             }else if(ch == '\''){
45                 buff.append("\\");
46                 buff.append(ch);
47             }else{
48                 buff.append(ch);
49             }
50         }
51         return buff.toString();
52     }
53
54     // TODO: value should be converted to actual data type in the proper
55
// classloader: e.g. in the case of javax.managed.ObjectName
56
public static ObjectAttribute getObjectAttribute(
57             List JavaDoc attributeList,
58             ObjectAttributeInfo attrInfo){
59
60         String JavaDoc attrName = attrInfo.getName();
61         for(Iterator JavaDoc it=attributeList.iterator(); it.hasNext(); ){
62             ObjectAttribute attribute = (ObjectAttribute)it.next();
63             if(attribute != null && attribute.getName().equals(attrName)){
64                 return attribute;
65             }
66         }
67         return new ObjectAttribute(attrName, ObjectAttribute.STATUS_NOT_FOUND, null);
68     }
69
70     public static boolean isDataTypeEditable(String JavaDoc type){
71         if(type.equals("boolean")
72                 || type.equals("char")
73                 || type.equals("byte")
74                 || type.equals("short")
75                 || type.equals("int")
76                 || type.equals("long")
77                 || type.equals("float")
78                 || type.equals("double")
79                 || type.equals("void")
80                 || type.equals("java.lang.Boolean")
81                 || type.equals("java.lang.Character")
82                 || type.equals("java.lang.Byte")
83                 || type.equals("java.lang.Short")
84                 || type.equals("java.lang.Integer")
85                 || type.equals("java.lang.Long")
86                 || type.equals("java.lang.Float")
87                 || type.equals("java.lang.Double")
88                 || type.equals("java.lang.Void")
89                 || type.equals("java.lang.String")
90                 || type.equals("java.math.BigInteger")
91                 || type.equals("java.math.BigDecimal")
92                // || type.equals("java.util.Date") -- currently not supported
93
|| type.equals("javax.management.ObjectName")
94                 || isEditableArrayType(type)){
95
96             return true;
97         }
98         return false;
99     }
100
101     public static boolean isEditableArrayType(String JavaDoc type){
102         if(type.equals("[B") // byte array
103
|| type.equals("[C") // char array
104
|| type.equals("[D") // double array
105
|| type.equals("[F") // float array
106
|| type.equals("[I") // int array
107
|| type.equals("[J") // long array
108
|| type.equals("[S") // short array
109
|| type.equals("[Ljava.lang.Character;")
110                 || type.equals("[Ljava.lang.Byte;")
111                 || type.equals("[Ljava.lang.Short;")
112                 || type.equals("[Ljava.lang.Integer;")
113                 || type.equals("[Ljava.lang.Long;")
114                 || type.equals("[Ljava.lang.Float;")
115                 || type.equals("[Ljava.lang.Double;")
116                 || type.equals("[Ljava.lang.String;")){
117             return true;
118         }
119         return false;
120     }
121
122     public static String JavaDoc getImpact(int impact){
123         switch(impact){
124             case ObjectOperationInfo.INFO:
125                 return "Information";
126             case ObjectOperationInfo.ACTION:
127                 return "Action";
128             case ObjectOperationInfo.ACTION_INFO:
129                 return "Action and Information";
130             case ObjectOperationInfo.UNKNOWN:
131                 return "Unknown";
132             default:
133                 return "Invalid Impact Value";
134
135         }
136     }
137 }
138
Popular Tags