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.core.impl.portlet.state;
023:
024: import org.jboss.portal.registration.Consumer;
025: import org.jboss.portal.registration.ConsumerCapabilities;
026: import org.jboss.portal.registration.ConsumerGroup;
027: import org.jboss.portal.registration.DuplicateRegistrationException;
028: import org.jboss.portal.registration.RegistrationException;
029: import org.jboss.portal.registration.RegistrationStatus;
030: import org.jboss.portal.registration.impl.ConsumerCapabilitiesImpl;
031:
032: import java.util.Collection;
033: import java.util.Collections;
034: import java.util.HashSet;
035: import java.util.Set;
036:
037: /**
038: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
039: * @version $Revision: 8786 $
040: */
041: public class PersistentConsumer implements Consumer {
042:
043: // Persistent fields
044:
045: private Long key;
046: private String persistentId;
047: private String persistentName;
048: private RegistrationStatus persistentStatus;
049: private String persistentAgent;
050:
051: // Relationships
052:
053: private Set relatedRegistrations;
054: private PersistentConsumerGroup relatedGroup;
055:
056: // Runtime state
057:
058: private ConsumerCapabilities capabilities = new ConsumerCapabilitiesImpl();
059:
060: /**
061: * Manager constructor.
062: *
063: * @param id
064: * @param name
065: */
066: public PersistentConsumer(String id, String name) {
067: this .key = null;
068: this .persistentId = id;
069: this .persistentName = name;
070: this .persistentStatus = RegistrationStatus.PENDING;
071: this .relatedRegistrations = new HashSet();
072: this .relatedGroup = null;
073: this .persistentAgent = null;
074: }
075:
076: /** Hibernate constructor. */
077: PersistentConsumer() {
078: this .key = null;
079: this .persistentId = null;
080: this .persistentName = null;
081: this .persistentStatus = null;
082: this .relatedRegistrations = null;
083: this .relatedGroup = null;
084: this .persistentAgent = null;
085: }
086:
087: // Hibernate
088:
089: public Long getKey() {
090: return key;
091: }
092:
093: public void setKey(Long key) {
094: this .key = key;
095: }
096:
097: public String getPersistentId() {
098: return persistentId;
099: }
100:
101: public void setPersistentId(String persistentId) {
102: this .persistentId = persistentId;
103: }
104:
105: public String getPersistentName() {
106: return persistentName;
107: }
108:
109: public void setPersistentName(String persistentName) {
110: this .persistentName = persistentName;
111: }
112:
113: public RegistrationStatus getPersistentStatus() {
114: return persistentStatus;
115: }
116:
117: public void setPersistentStatus(RegistrationStatus persistentStatus) {
118: this .persistentStatus = persistentStatus;
119: }
120:
121: public String getPersistentAgent() {
122: return persistentAgent;
123: }
124:
125: public void setPersistentAgent(String persistentAgent) {
126: this .persistentAgent = persistentAgent;
127: }
128:
129: public Set getRelatedRegistrations() {
130: return relatedRegistrations;
131: }
132:
133: public void setRelatedRegistrations(Set relatedRegistrations) {
134: this .relatedRegistrations = relatedRegistrations;
135: }
136:
137: public PersistentConsumerGroup getRelatedGroup() {
138: return relatedGroup;
139: }
140:
141: public void setRelatedGroup(PersistentConsumerGroup relatedGroup) {
142: this .relatedGroup = relatedGroup;
143: }
144:
145: //
146:
147: public String getName() {
148: return persistentName;
149: }
150:
151: public RegistrationStatus getStatus() {
152: return persistentStatus;
153: }
154:
155: public void setStatus(RegistrationStatus status) {
156: this .persistentStatus = status;
157: }
158:
159: public Collection getRegistrations() throws RegistrationException {
160: return Collections.unmodifiableSet(relatedRegistrations);
161: }
162:
163: public ConsumerGroup getGroup() {
164: return relatedGroup;
165: }
166:
167: public String getId() {
168: return persistentId;
169: }
170:
171: public ConsumerCapabilities getCapabilities() {
172: return capabilities;
173: }
174:
175: public void setCapabilities(ConsumerCapabilities capabilities) {
176: this .capabilities = capabilities;
177: }
178:
179: public void setGroup(ConsumerGroup group)
180: throws RegistrationException,
181: DuplicateRegistrationException {
182: if (this .relatedGroup != null) {
183: this .relatedGroup.removeConsumer(this );
184: }
185:
186: //
187: if (group != null) {
188: group.addConsumer(this );
189: }
190: }
191:
192: public String getConsumerAgent() {
193: return persistentAgent;
194: }
195:
196: public void setConsumerAgent(String consumerAgent)
197: throws IllegalArgumentException, IllegalStateException {
198: this.persistentAgent = consumerAgent;
199: }
200: }
|