KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > management > ObjectAttribute


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.core.management;
17
18 import org.jmanage.util.StringUtils;
19 import org.jmanage.core.management.data.DataFormatUtil;
20
21 /**
22  *
23  * date: Aug 13, 2004
24  * @author Rakesh Kalra
25  */

26 public class ObjectAttribute implements java.io.Serializable JavaDoc {
27
28     public static final int STATUS_OK = 0;
29     public static final int STATUS_ERROR = 1;
30     public static final int STATUS_NOT_FOUND = 2;
31
32     private String JavaDoc name;
33     private Object JavaDoc value;
34     private int status = STATUS_OK;
35     private String JavaDoc errorString;
36
37     public ObjectAttribute(String JavaDoc name, Object JavaDoc value) {
38         this.name = name;
39         this.value = value;
40     }
41
42     public ObjectAttribute(String JavaDoc name, int status, String JavaDoc errorString){
43         this.name = name;
44         this.status = status;
45         this.errorString = errorString;
46     }
47
48     public boolean equals(Object JavaDoc o) {
49         if(o instanceof ObjectAttribute){
50             ObjectAttribute attr = (ObjectAttribute)o;
51             if(attr.name.equals(this.name) && attr.value.equals(this.value)){
52                 return true;
53             }
54         }
55         return false;
56     }
57
58     public String JavaDoc getName() {
59         return name;
60     }
61
62     public Object JavaDoc getValue() {
63         return value;
64     }
65
66     public int getStatus() {
67         return status;
68     }
69
70     public String JavaDoc getErrorString() {
71         return errorString;
72     }
73
74     public String JavaDoc getDisplayValue(){
75         String JavaDoc attrValue = null;
76         if(getStatus() == STATUS_OK){
77             attrValue = DataFormatUtil.format(getValue());
78         }else if(getStatus() == ObjectAttribute.STATUS_NOT_FOUND){
79             // todo: this will not work for CLI
80
attrValue = "<not found>";
81         }else{
82             // todo: this will not work for CLI
83
attrValue = "<error>";
84         }
85         return attrValue;
86     }
87 }
88
Popular Tags