001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Kernel/Sources/es/udc/mypersonalizer/kernel/model/repository/interfaces/ServiceProperty.java,v 1.1.1.1 2004/03/25 12:08:36 fbellas Exp $
003: * $Revision: 1.1.1.1 $
004: * $Date: 2004/03/25 12:08:36 $
005: *
006: * =============================================================================
007: *
008: * Copyright (c) 2003, The MyPersonalizer Development Group
009: * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at
010: * University Of A Coruna
011: * All rights reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions are met:
015: *
016: * - Redistributions of source code must retain the above copyright notice,
017: * this list of conditions and the following disclaimer.
018: *
019: * - Redistributions in binary form must reproduce the above copyright notice,
020: * this list of conditions and the following disclaimer in the documentation
021: * and/or other materials provided with the distribution.
022: *
023: * - Neither the name of the University Of A Coruna nor the names of its
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
028: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
036: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037: * POSSIBILITY OF SUCH DAMAGE.
038: *
039: */
040:
041: package es.udc.mypersonalizer.kernel.model.repository.interfaces;
042:
043: import java.io.Serializable;
044: import es.udc.mypersonalizer.kernel.model.properties.Property;
045:
046: /**
047: * This class represents a configuration made for any service. The service
048: * property consists of a <code>ServicePropertyKey</code> and a
049: * <code>Property</code>. The key class uniquely identifies a service property
050: * instance of this class. The property contains the specific configuration
051: * made for a concrete service. The format of the property is defined by the
052: * service designer.
053: *
054: * @author Fernando Bellas
055: * @since 1.0
056: */
057: public class ServiceProperty implements Serializable {
058:
059: /**
060: * For interoperability with possible future changes.
061: *
062: */
063: private static final long serialVersionUID = 5745957883076459862L;
064:
065: /**
066: * The service property key.
067: *
068: * @serial
069: */
070: private ServicePropertyKey key = null;
071:
072: /**
073: * The service properties.
074: *
075: * @serial
076: */
077: private Property property = null;
078:
079: /**
080: * Constructs an instance of this class.
081: *
082: * @param key the service property key.
083: * @param property the service properties.
084: * @throws NullPointerException if <code>key</code> or
085: * <code>property</code> are <code>null</code>.
086: */
087: public ServiceProperty(ServicePropertyKey key, Property property) {
088:
089: if (key == null || property == null) {
090: throw new NullPointerException();
091: }
092:
093: this .key = key;
094: this .property = property;
095: }
096:
097: /**
098: * Gets the service property key.
099: *
100: * @return the service property key
101: */
102: public ServicePropertyKey getKey() {
103: return key;
104: }
105:
106: /**
107: * Gets the service properties.
108: *
109: * @return the service properties
110: */
111: public Property getProperty() {
112: return property;
113: }
114:
115: /**
116: * Sets the service properties.
117: *
118: * @param property the service properties
119: */
120: public void setProperty(Property property) {
121: this .property = property;
122: }
123:
124: /**
125: * Returns the hash code of an instance of this class. The resulting
126: * hash code is the sum of the key hash code and the property hash code.
127: *
128: * @return the hash code
129: */
130: public int hashCode() {
131: return key.hashCode() + property.hashCode();
132: }
133:
134: /**
135: * Returns if an instance of this class is equals to the one passed as a
136: * parameter. This method returns true if the key and the property of both
137: * instances are the same, and false otherwise.
138: *
139: * @param object the instance to be compared to.
140: * @return true if this instance and the one passed as a parameter are
141: * equal, false otherwise.
142: */
143: public boolean equals(Object object) {
144: if (object == null) {
145: return false;
146: }
147:
148: ServiceProperty serviceProperty = null;
149: try {
150: serviceProperty = (ServiceProperty) object;
151:
152: } catch (ClassCastException e) {
153: return false;
154: }
155:
156: if (key.equals(serviceProperty.getKey())
157: && property.equals(serviceProperty.getProperty())) {
158: return true;
159: }
160:
161: return false;
162: }
163: }
|