001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.shared.value;
034:
035: import com.flexive.shared.content.FxContent;
036: import com.flexive.shared.content.FxPK;
037: import com.flexive.shared.exceptions.FxApplicationException;
038: import com.flexive.shared.security.ACL;
039: import com.flexive.shared.workflow.Step;
040:
041: import java.io.Serializable;
042:
043: /**
044: * A referenced content - value class for FxReference
045: *
046: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
047: */
048: public class ReferencedContent extends FxPK implements Serializable {
049: private static final long serialVersionUID = 4530337199230606480L;
050: private String caption;
051: private Step step;
052: private ACL acl;
053: private FxContent content;
054: private boolean accessGranted;
055: private boolean resolved;
056:
057: /**
058: * Ctor
059: *
060: * @param pk referenced primary key
061: * @param caption caption of the referenced content, only available if loaded
062: * @param step the step
063: * @param acl the acl
064: */
065: public ReferencedContent(FxPK pk, String caption, Step step, ACL acl) {
066: super (pk.getId(), pk.getVersion());
067: this .caption = caption;
068: this .step = step;
069: this .acl = acl;
070: this .content = null;
071: this .accessGranted = false;
072: }
073:
074: /**
075: * Ctor
076: *
077: * @param pk referenced primary key
078: */
079: public ReferencedContent(FxPK pk) {
080: super (pk.getId(), pk.getVersion());
081: this .caption = "";
082: this .step = null;
083: this .acl = null;
084: this .content = null;
085: this .accessGranted = false;
086: }
087:
088: /**
089: * Ctor
090: *
091: * @param id id
092: * @param version version
093: */
094: public ReferencedContent(long id, int version) {
095: super (id, version);
096: this .caption = "";
097: this .step = null;
098: this .acl = null;
099: this .content = null;
100: this .accessGranted = false;
101: }
102:
103: /**
104: * Ctor
105: *
106: * @param id id
107: */
108: public ReferencedContent(long id) {
109: super (id);
110: this .caption = "";
111: this .step = null;
112: this .acl = null;
113: this .content = null;
114: this .accessGranted = false;
115: }
116:
117: /**
118: * Ctor
119: */
120: public ReferencedContent() {
121: super ();
122: this .caption = "";
123: this .step = null;
124: this .acl = null;
125: this .content = null;
126: this .accessGranted = false;
127: }
128:
129: /**
130: * Get the caption of the referenced content, only available if loaded
131: *
132: * @return caption of the referenced content, only available if loaded
133: */
134: public String getCaption() {
135: return caption;
136: }
137:
138: /**
139: * Is a step known for this reference?
140: *
141: * @return if a step is known for this reference
142: */
143: public boolean hasStep() {
144: return step != null;
145: }
146:
147: /**
148: * Is an ACL known for this reference?
149: *
150: * @return if an ACL is known for this reference
151: */
152: public boolean hasACL() {
153: return acl != null;
154: }
155:
156: /**
157: * Get the step for this reference
158: *
159: * @return step of this reference
160: */
161: public Step getStep() {
162: if (!hasStep())
163: throw new FxApplicationException(
164: "ex.content.reference.content.missing")
165: .asRuntimeException();
166: return step;
167: }
168:
169: /**
170: * Get the ACL for this reference
171: *
172: * @return ACL for this reference
173: */
174: public ACL getAcl() {
175: if (!hasACL())
176: throw new FxApplicationException(
177: "ex.content.reference.content.missing")
178: .asRuntimeException();
179: return acl;
180: }
181:
182: /**
183: * Is a loaded FxContent assigned for this reference?
184: *
185: * @return if a loaded FxContent is assigned for this reference
186: */
187: public boolean hasContent() {
188: return content != null;
189: }
190:
191: /**
192: * Get the assigned FxContent for this reference
193: *
194: * @return the assigned FxContent for this reference
195: */
196: public synchronized FxContent getContent() {
197: if (!hasContent())
198: throw new FxApplicationException(
199: "ex.content.reference.content.missing")
200: .asRuntimeException();
201: return content;
202: }
203:
204: /**
205: * Set the assigned FxContent for this reference
206: *
207: * @param content the assigned FxContent for this reference
208: */
209: public synchronized void setContent(FxContent content) {
210: if (!resolved) {
211: this .content = content;
212: accessGranted = content != null;
213: } else {
214: resolved = true;
215: }
216: }
217:
218: /**
219: * Is access to the referenced FxContent granted?
220: *
221: * @return if access to the referenced FxContent is granted
222: */
223: public boolean isAccessGranted() {
224: return accessGranted;
225: }
226:
227: /**
228: * Set if (read) access to the referenced instance is granted.
229: * This flag is usually set during creation of a ReferencedContent.
230: * Setting it to <code>true</code> will <b>not</b> enable you to read the referenced content ;-)
231: *
232: * @param accessGranted if access to the referenced content is granted
233: */
234: public void setAccessGranted(boolean accessGranted) {
235: this .accessGranted = accessGranted;
236: }
237:
238: /**
239: * {@inheritDoc}
240: */
241: @Override
242: public int hashCode() {
243: return super .hashCode() * 31 + caption.hashCode();
244: }
245:
246: /**
247: * Evaluates the given string value to an object of type ReferencedContent.
248: *
249: * @param value string value to be evaluated
250: * @return the value interpreted as ReferencedContent
251: */
252: public static ReferencedContent fromString(String value) {
253: return new ReferencedContent(FxPK.fromString(value));
254: }
255:
256: public String toStringExtended() {
257: return "ReferencedContent{pk=" + super .toString()
258: + ", caption=[" + caption + "]}";
259: }
260: }
|