001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.registration.impl;
023:
024: import org.jboss.portal.common.util.ParameterValidation;
025: import org.jboss.portal.registration.Consumer;
026: import org.jboss.portal.registration.Registration;
027: import org.jboss.portal.registration.RegistrationStatus;
028:
029: import javax.xml.namespace.QName;
030: import java.util.Collections;
031: import java.util.HashMap;
032: import java.util.Iterator;
033: import java.util.Map;
034:
035: /**
036: * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
037: * @version $Revision: 8784 $
038: * @since 2.6
039: */
040: public class RegistrationImpl implements Registration {
041:
042: private final String id;
043: private ConsumerImpl consumer;
044: private RegistrationStatus status;
045: private Map properties;
046: private String registrationHandle;
047:
048: public RegistrationImpl(String id, ConsumerImpl consumer,
049: RegistrationStatus status, Map properties) {
050: this .id = id;
051: this .consumer = consumer;
052: this .status = status;
053: this .properties = new HashMap(properties);
054: }
055:
056: public String getId() {
057: return id;
058: }
059:
060: public void setRegistrationHandle(String handle) {
061: this .registrationHandle = handle;
062: }
063:
064: public String getRegistrationHandle() {
065: return registrationHandle;
066: }
067:
068: public Consumer getConsumer() {
069: return consumer;
070: }
071:
072: public Map getProperties() {
073: return Collections.unmodifiableMap(properties);
074: }
075:
076: public void setPropertyValueFor(QName propertyName, Object value) {
077: ParameterValidation.throwIllegalArgExceptionIfNull(
078: propertyName, "Property name");
079: ParameterValidation.throwIllegalArgExceptionIfNull(value,
080: "Property value");
081:
082: // avoid modifying the properties if new value is the same as old one
083: Object oldValue = properties.get(propertyName);
084: if (!value.equals(oldValue)) {
085: properties.put(propertyName, value);
086: }
087: }
088:
089: public void setPropertyValueFor(String propertyName, Object value) {
090: ParameterValidation.throwIllegalArgExceptionIfNull(
091: propertyName, "Property name");
092: setPropertyValueFor(new QName(propertyName), value);
093: }
094:
095: public Object getPropertyValueFor(QName propertyName) {
096: ParameterValidation.throwIllegalArgExceptionIfNull(
097: propertyName, "Property name");
098: return properties.get(propertyName);
099: }
100:
101: public Object getPropertyValueFor(String propertyName) {
102: ParameterValidation.throwIllegalArgExceptionIfNull(
103: propertyName, "Property name");
104: return getPropertyValueFor(new QName(propertyName));
105: }
106:
107: public void removeProperty(QName propertyName) {
108: ParameterValidation.throwIllegalArgExceptionIfNull(
109: propertyName, "Property name");
110: properties.remove(propertyName);
111: }
112:
113: public void removeProperty(String propertyName) {
114: ParameterValidation.throwIllegalArgExceptionIfNull(
115: propertyName, "Property name");
116: removeProperty(new QName(propertyName));
117: }
118:
119: public boolean hasEqualProperties(Registration registration) {
120: if (registration == null) {
121: return false;
122: }
123:
124: Map other = registration.getProperties();
125: return hasEqualProperties(other);
126: }
127:
128: public boolean hasEqualProperties(Map registrationProperties) {
129: if (registrationProperties == null) {
130: return false;
131: }
132:
133: if (properties.size() != registrationProperties.size()) {
134: return false;
135: }
136:
137: // check properties
138: for (Iterator props = properties.entrySet().iterator(); props
139: .hasNext();) {
140: Map.Entry entry = (Map.Entry) props.next();
141:
142: // we should have a 1-1 match between name/value pair
143: QName name = (QName) entry.getKey();
144: if (!entry.getValue().equals(
145: registrationProperties.get(name))) {
146: return false;
147: }
148: }
149:
150: return true;
151: }
152:
153: public void setRegistrationPropertyValueFor(String propertyName,
154: Object value) {
155: setPropertyValueFor(new QName(propertyName), value);
156: }
157:
158: public RegistrationStatus getStatus() {
159: return status;
160: }
161:
162: public void setStatus(RegistrationStatus status) {
163: ParameterValidation.throwIllegalArgExceptionIfNull(status,
164: "RegistrationStatus");
165: this .status = status;
166: }
167:
168: public void clearAssociatedState() {
169: //todo: implement
170: }
171:
172: public void updateProperties(Map registrationProperties) {
173: properties = new HashMap(registrationProperties);
174: }
175:
176: }
|