History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/com/sun/jmx/mbeanserver/NamedObject.java (1 of 18352 files). Show all

Unified · Split

java/pkg/com/sun/jmx/mbeanserver/NamedObject.java+122−0
@@ -0,0 +1,122 @@
1/*
2 * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.jmx.mbeanserver;
27
28import javax.management.* ;
29
30
31
32/**
33 * This class is used for storing a pair (name, object) where name is
34 * an object name and object is a reference to the object.
35 *
36 * @since 1.5
37 */
38public class NamedObject {
39
40
41 /**
42 * Object name.
43 */
44 private final ObjectName name;
45
46 /**
47 * Object reference.
48 */
49 private final DynamicMBean object;
50
51
52 /**
53 * Allows a named object to be created.
54 *
55 *@param objectName The object name of the object.
56 *@param object A reference to the object.
57 */
58 public NamedObject(ObjectName objectName, DynamicMBean object) {
59 if (objectName.isPattern()) {
60 throw new RuntimeOperationsException(new IllegalArgumentException("Invalid name->"+ objectName.toString()));
61 }
62 this.name= objectName;
63 this.object= object;
64 }
65
66 /**
67 * Allows a named object to be created.
68 *
69 *@param objectName The string representation of the object name of the object.
70 *@param object A reference to the object.
71 *
72 *@exception MalformedObjectNameException The string passed does not have the format of a valid ObjectName
73 */
74 public NamedObject(String objectName, DynamicMBean object) throws MalformedObjectNameException{
75 ObjectName objName= new ObjectName(objectName);
76 if (objName.isPattern()) {
77 throw new RuntimeOperationsException(new IllegalArgumentException("Invalid name->"+ objName.toString()));
78 }
79 this.name= objName;
80 this.object= object;
81 }
82
83 /**
84 * Compares the current object name with another object name.
85 *
86 * @param object The Named Object that the current object name is to be
87 * compared with.
88 *
89 * @return True if the two named objects are equal, otherwise false.
90 */
91 public boolean equals(Object object) {
92 if (this == object) return true;
93 if (object == null) return false;
94 if (!(object instanceof NamedObject)) return false;
95 NamedObject no = (NamedObject) object;
96 return name.equals(no.getName());
97 }
98
99
100 /**
101 * Returns a hash code for this named object.
102 *
103 */
104 public int hashCode() {
105 return name.hashCode();
106 }
107
108 /**
109 * Get the object name.
110 */
111 public ObjectName getName() {
112 return name;
113 }
114
115 /**
116 * Get the object
117 */
118 public DynamicMBean getObject() {
119 return object;
120 }
121
122 }