KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > mbeanserver > NamedObject


1 /*
2  * @(#)NamedObject.java 1.31 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.jmx.mbeanserver;
9
10 import javax.management.* ;
11  
12
13
14 /**
15  * This class is used for storing a pair (name, object) where name is
16  * an object name and object is a reference to the object.
17  *
18  * @since 1.5
19  * @since.unbundled JMX RI 1.2
20  */

21 public class NamedObject {
22
23
24     /**
25      * Object name.
26      */

27     private ObjectName name;
28     
29     /**
30      * Object reference.
31      */

32     private Object JavaDoc object= null;
33     
34
35     /**
36      * Allows a named object to be created.
37      *
38      *@param objectName The object name of the object.
39      *@param object A reference to the object.
40      */

41     public NamedObject(ObjectName objectName, Object JavaDoc object) {
42     if (objectName.isPattern()) {
43         throw new RuntimeOperationsException(new IllegalArgumentException JavaDoc("Invalid name->"+ objectName.toString()));
44     }
45     this.name= objectName;
46     this.object= object;
47     }
48
49     /**
50      * Allows a named object to be created.
51      *
52      *@param objectName The string representation of the object name of the object.
53      *@param object A reference to the object.
54      *
55      *@exception MalformedObjectNameException The string passed does not have the format of a valid ObjectName
56      */

57     public NamedObject(String JavaDoc objectName, Object JavaDoc object) throws MalformedObjectNameException{
58     ObjectName objName= new ObjectName(objectName);
59     if (objName.isPattern()) {
60         throw new RuntimeOperationsException(new IllegalArgumentException JavaDoc("Invalid name->"+ objName.toString()));
61     }
62     this.name= objName;
63     this.object= object;
64     }
65   
66     /**
67      * Compares the current object name with another object name.
68      *
69      * @param object The Named Object that the current object name is to be
70      * compared with.
71      *
72      * @return True if the two named objects are equal, otherwise false.
73      */

74     public boolean equals(Object JavaDoc object) {
75         if (this == object) return true;
76         if (object == null) return false;
77         if (!(object instanceof NamedObject)) return false;
78         NamedObject no = (NamedObject) object;
79         return name.equals(no.getName());
80     }
81
82
83     /**
84      * Returns a hash code for this named object.
85      *
86      */

87     public int hashCode() {
88         return name.hashCode();
89     }
90
91     /**
92      * Get the object name.
93      */

94     public ObjectName getName() {
95     return name;
96     }
97    
98     /**
99      * Get the object
100      */

101     public Object JavaDoc getObject() {
102     return object;
103    }
104     
105  }
106
Popular Tags