001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.services.binding;
023:
024: /** A ServiceConfig is a mapping from an mbean service name to its
025: * ServiceBindings.
026: *
027: * @author <a href="mailto:bitpushr@rochester.rr.com">Mike Finn</a>.
028: * @author Scott.Stark@jboss.org
029: * @version $Revision: 57210 $
030: */
031: public class ServiceConfig implements Cloneable {
032: /** The javax.management.ObjectName string of the service the config
033: applies to.
034: */
035: private String serviceName;
036: /** The ServicesConfigDelegate implementation class
037: */
038: private String serviceConfigDelegateClassName;
039: /** An aribtrary object used to configure the behavior of
040: the ServicesConfigDelegate. An example would be an XML Element.
041: */
042: private Object serviceConfigDelegateConfig;
043: /** The bindings associated with the service
044: */
045: private ServiceBinding[] bindings;
046:
047: /** Creates a new instance of ServiceConfig */
048: public ServiceConfig() {
049: }
050:
051: /** Make a deep copy of the ServiceConfig bindings
052: */
053: public Object clone() {
054: ServiceConfig copy = new ServiceConfig();
055: // Immutable so no reason to copy
056: copy.serviceName = serviceName;
057: copy.serviceConfigDelegateClassName = serviceConfigDelegateClassName;
058: int length = bindings != null ? bindings.length : 0;
059: copy.bindings = new ServiceBinding[length];
060: for (int b = 0; b < length; b++) {
061: copy.bindings[b] = (ServiceBinding) bindings[b].clone();
062: }
063: return copy;
064: }
065:
066: /** Getter for property serviceName.
067: * @return Value of property serviceName.
068: */
069: public String getServiceName() {
070: return this .serviceName;
071: }
072:
073: /** Setter for property serviceName.
074: * @param serviceName New value of property serviceName.
075: */
076: public void setServiceName(String serviceName) {
077: this .serviceName = serviceName;
078: }
079:
080: /** Getter for property port.
081: * @return Value of property port.
082: */
083: public ServiceBinding[] getBindings() {
084: return this .bindings;
085: }
086:
087: /** Setter for property port.
088: * @param port New value of property port.
089: */
090: public void setBindings(ServiceBinding[] bindings) {
091: this .bindings = bindings;
092: }
093:
094: /** Getter for property serviceConfigDelegateClassName.
095: * @return Value of property serviceConfigDelegateClassName.
096: */
097: public String getServiceConfigDelegateClassName() {
098: return serviceConfigDelegateClassName;
099: }
100:
101: /** Setter for property serviceConfigDelegateClassName.
102: * @param serviceConfigDelegateClassName New value of property serviceConfigDelegateClassName.
103: */
104: public void setServiceConfigDelegateClassName(
105: String serviceConfigDelegateClassName) {
106: this .serviceConfigDelegateClassName = serviceConfigDelegateClassName;
107: }
108:
109: /** Getter for property serviceConfigDelegateConfig.
110: * @return Value of property serviceConfigDelegateConfig.
111: */
112: public Object getServiceConfigDelegateConfig() {
113: return serviceConfigDelegateConfig;
114: }
115:
116: /** Setter for property serviceConfigDelegateConfig.
117: * @param serviceConfigDelegateConfig New value of property serviceConfigDelegateConfig.
118: */
119: public void setServiceConfigDelegateConfig(
120: Object serviceConfigDelegateConfig) {
121: this .serviceConfigDelegateConfig = serviceConfigDelegateConfig;
122: }
123:
124: /** Equality is based on the serviceName string
125: */
126: public boolean equals(Object obj) {
127: boolean equals = false;
128: if (obj instanceof ServiceConfig) {
129: ServiceConfig sc = (ServiceConfig) obj;
130: equals = this .serviceName.equals(sc.serviceName);
131: } else {
132: equals = super .equals(obj);
133: }
134: return equals;
135: }
136:
137: /** The hash code is based on the serviceName string hashCode.
138: */
139: public int hashCode() {
140: int hashCode = serviceName == null ? 0 : serviceName.hashCode();
141: return hashCode;
142: }
143:
144: public String toString() {
145: StringBuffer buffer = new StringBuffer("ServiceConfig(name=");
146: buffer.append(serviceName);
147: buffer.append("), bindings=");
148: int length = bindings != null ? bindings.length : 0;
149: for (int b = 0; b < length; b++) {
150: buffer.append("\n" + bindings[b].toString());
151: }
152: return buffer.toString();
153: }
154:
155: }
|