Path: blob/master/src/java.management/share/classes/com/sun/jmx/mbeanserver/NamedObject.java
41161 views
/*1* Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.jmx.mbeanserver;2627import javax.management.* ;28293031/**32* This class is used for storing a pair (name, object) where name is33* an object name and object is a reference to the object.34*35* @since 1.536*/37public class NamedObject {383940/**41* Object name.42*/43private final ObjectName name;4445/**46* Object reference.47*/48private final DynamicMBean object;495051/**52* Allows a named object to be created.53*54*@param objectName The object name of the object.55*@param object A reference to the object.56*/57public NamedObject(ObjectName objectName, DynamicMBean object) {58if (objectName.isPattern()) {59throw new RuntimeOperationsException(new IllegalArgumentException("Invalid name->"+ objectName.toString()));60}61this.name= objectName;62this.object= object;63}6465/**66* Allows a named object to be created.67*68*@param objectName The string representation of the object name of the object.69*@param object A reference to the object.70*71*@exception MalformedObjectNameException The string passed does not have the format of a valid ObjectName72*/73public NamedObject(String objectName, DynamicMBean object) throws MalformedObjectNameException{74ObjectName objName= new ObjectName(objectName);75if (objName.isPattern()) {76throw new RuntimeOperationsException(new IllegalArgumentException("Invalid name->"+ objName.toString()));77}78this.name= objName;79this.object= object;80}8182/**83* Compares the current object name with another object name.84*85* @param object The Named Object that the current object name is to be86* compared with.87*88* @return True if the two named objects are equal, otherwise false.89*/90public boolean equals(Object object) {91if (this == object) return true;92if (object == null) return false;93if (!(object instanceof NamedObject)) return false;94NamedObject no = (NamedObject) object;95return name.equals(no.getName());96}979899/**100* Returns a hash code for this named object.101*102*/103public int hashCode() {104return name.hashCode();105}106107/**108* Get the object name.109*/110public ObjectName getName() {111return name;112}113114/**115* Get the object116*/117public DynamicMBean getObject() {118return object;119}120121}122123124