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.structure;
034:
035: import com.flexive.shared.FxLanguage;
036: import com.flexive.shared.exceptions.FxNotFoundException;
037: import com.flexive.shared.security.ACL;
038: import com.flexive.shared.value.*;
039:
040: import java.io.Serializable;
041: import java.util.List;
042:
043: /**
044: * property definition
045: *
046: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
047: */
048: public class FxProperty extends FxStructureElement implements
049: Serializable {
050: private static final long serialVersionUID = 5343222808050017626L;
051: protected ACL ACL;
052: protected boolean overrideACL;
053: protected FxDataType dataType;
054: protected boolean fulltextIndexed;
055: protected FxType referencedType;
056: protected FxSelectList referencedList;
057: protected FxString defaultValue;
058: protected boolean systemInternal;
059: protected UniqueMode uniqueMode;
060:
061: public FxProperty(long id, String name,
062: FxMultiplicity multiplicity, ACL acl, FxDataType dataType) {
063: this (id, name, null, null, false, false, multiplicity, false,
064: acl, dataType, null, false, null, null,
065: UniqueMode.None, FxStructureOption
066: .getEmptyOptionList(5));
067: }
068:
069: public FxProperty(long id, String name, FxString label,
070: FxString hint, boolean systemInternal,
071: boolean overrideBaseMultiplicity,
072: FxMultiplicity multiplicity, boolean overrideACL, ACL ACL,
073: FxDataType dataType, FxString defaultValue,
074: boolean fulltextIndexed, FxType referencedType,
075: FxSelectList referencedList, UniqueMode uniqueMode,
076: List<FxStructureOption> options) {
077: super (id, name, label, hint, overrideBaseMultiplicity,
078: multiplicity, options);
079: this .systemInternal = systemInternal;
080: this .overrideACL = overrideACL;
081: this .ACL = ACL;
082: this .dataType = dataType;
083: this .defaultValue = defaultValue;
084: this .multiplicity = multiplicity;
085: this .fulltextIndexed = fulltextIndexed;
086: this .referencedType = referencedType;
087: this .referencedList = referencedList;
088: this .uniqueMode = uniqueMode;
089: }
090:
091: public FxPropertyEdit asEditable() {
092: return new FxPropertyEdit(this );
093: }
094:
095: /**
096: * May assignments override this properties ACL?
097: *
098: * @return if assignments may override this properties ACL?
099: */
100: public boolean mayOverrideACL() {
101: return overrideACL;
102: }
103:
104: /**
105: * Get the ACL
106: *
107: * @return ACL
108: */
109: public ACL getACL() {
110: return ACL;
111: }
112:
113: /**
114: * Get the data type
115: *
116: * @return data type
117: */
118: public FxDataType getDataType() {
119: return dataType;
120: }
121:
122: /**
123: * Default value as string representation
124: *
125: * @return default value as string representation
126: */
127: public FxString getDefaultValue() {
128: return defaultValue;
129: }
130:
131: /**
132: * May assignments override this properties multilanguage setting?
133: *
134: * @return if assignments may override this properties multilanguage setting?
135: */
136: public boolean mayOverrideMultiLang() {
137: return getOption(FxStructureOption.OPTION_MULTILANG)
138: .isOverrideable();
139: }
140:
141: /**
142: * Is this property available in multiple languages?
143: *
144: * @return property is available in multiple languages
145: */
146: public boolean isMultiLang() {
147: return getOption(FxStructureOption.OPTION_MULTILANG)
148: .isValueTrue();
149: }
150:
151: /**
152: * May assignments override this properties searchable flag?
153: *
154: * @return if assignments may override this properties searchable flag?
155: */
156: public boolean mayOverrideSearchable() {
157: return getOption(FxStructureOption.OPTION_SEARCHABLE)
158: .isOverrideable();
159: }
160:
161: /**
162: * Can this property be used in the visual query editor (UI hint)
163: *
164: * @return if property can be used in the visual query editor
165: */
166: public boolean isSearchable() {
167: return getOption(FxStructureOption.OPTION_SEARCHABLE)
168: .isValueTrue();
169: }
170:
171: /**
172: * Is this a system-internal property like ID or VERSION?
173: *
174: * @return property is system internal
175: */
176: public boolean isSystemInternal() {
177: return systemInternal;
178: }
179:
180: /**
181: * May assignments override this properties appearance in overviews?
182: *
183: * @return if assignments may override this properties appearance in overviews?
184: */
185: public boolean mayOverrideInOverview() {
186: return getOption(FxStructureOption.OPTION_SHOW_OVERVIEW)
187: .isOverrideable();
188: }
189:
190: /**
191: * Does this property appear in overviews?
192: *
193: * @return if this property appears in overviews
194: */
195: public boolean isInOverview() {
196: return getOption(FxStructureOption.OPTION_SHOW_OVERVIEW)
197: .isValueTrue();
198: }
199:
200: /**
201: * May assignments override this properties setting wether to use a HTML editor?
202: *
203: * @return if assignments may override this properties setting wether to use a HTML editor?
204: */
205: public boolean mayOverrideUseHTMLEditor() {
206: return getOption(FxStructureOption.OPTION_HTML_EDITOR)
207: .isOverrideable();
208: }
209:
210: /**
211: * Use a HTML editor for this property?
212: *
213: * @return use HTML editor
214: */
215: public boolean isUseHTMLEditor() {
216: return getOption(FxStructureOption.OPTION_HTML_EDITOR)
217: .isValueTrue();
218: }
219:
220: /**
221: * May assignments override this properties multiline setting?
222: *
223: * @return if assignments may override this properties multiline setting?
224: */
225: public boolean mayOverrideMultiLine() {
226: return getOption(FxStructureOption.OPTION_MULTILINE)
227: .isOverrideable();
228: }
229:
230: /**
231: * Show as multiple lines in editors?
232: *
233: * @return if this property appears in multiple lines
234: */
235: public boolean isMultiLine() {
236: return getOption(FxStructureOption.OPTION_MULTILINE)
237: .isValueTrue();
238: }
239:
240: /**
241: * Is this property fulltext indexed?
242: *
243: * @return is property fulltext indexed?
244: */
245: public boolean isFulltextIndexed() {
246: return fulltextIndexed;
247: }
248:
249: /**
250: * Does this property reference a FxType
251: *
252: * @return if this property references a FxType
253: */
254: public boolean hasReferencedType() {
255: return referencedType != null;
256: }
257:
258: /**
259: * Get referenced FxType
260: *
261: * @return referenced FxType
262: */
263: public FxType getReferencedType() {
264: return referencedType;
265: }
266:
267: /**
268: * Does this property reference a FxSelectList
269: *
270: * @return if this property references a FxSelectList
271: */
272: public boolean hasReferencedList() {
273: return referencedList != null;
274: }
275:
276: /**
277: * Get referenced FxSelectList
278: *
279: * @return referenced FxSelectList
280: */
281: public FxSelectList getReferencedList() {
282: return referencedList;
283: }
284:
285: /**
286: * Get the uniqueness mode of this property
287: *
288: * @return uniqueness mode of this property
289: */
290: public UniqueMode getUniqueMode() {
291: return uniqueMode;
292: }
293:
294: /**
295: * (Internal!) method to resolve referenced type in the second stage of loading the environment
296: *
297: * @param environment reference to the environment to resolve the referenced type
298: */
299: public void resolveReferencedType(FxEnvironment environment) {
300: if (this .referencedType == null || environment == null)
301: return;
302: this .referencedType = environment.getType(referencedType
303: .getId());
304: }
305:
306: /**
307: * Get an empty FxValue object for this property
308: *
309: * @return empty FxValue object
310: */
311: public FxValue getEmptyValue() {
312: return getEmptyValue(isMultiLang());
313: }
314:
315: /**
316: * Get an empty FxValue instance for this property in single or multi language mode.
317: * To be called from property assignments only!
318: *
319: * @param multiLang multi language
320: * @return empty FxValue instance for the data type
321: */
322: protected FxValue getEmptyValue(boolean multiLang) {
323: return getEmptyValue(multiLang, FxLanguage.DEFAULT_ID);
324: }
325:
326: /**
327: * Get an empty FxValue instance for this property in single or multi language mode.
328: * To be called from property assignments only!
329: *
330: * @param multiLang multi language
331: * @param lang language to initialize this value for
332: * @return empty FxValue instance for the data type
333: */
334: protected FxValue getEmptyValue(boolean multiLang, long lang) {
335: switch (this .getDataType()) {
336: case HTML:
337: return new FxHTML(multiLang, lang, FxHTML.EMPTY).setEmpty();
338: case String1024:
339: case Text:
340: return new FxString(multiLang, lang, FxString.EMPTY)
341: .setEmpty();
342: case Number:
343: return new FxNumber(multiLang, lang, FxNumber.EMPTY)
344: .setEmpty();
345: case LargeNumber:
346: return new FxLargeNumber(multiLang, lang,
347: FxLargeNumber.EMPTY).setEmpty();
348: case Float:
349: return new FxFloat(multiLang, lang, FxFloat.EMPTY)
350: .setEmpty();
351: case Double:
352: return new FxDouble(multiLang, lang, FxDouble.EMPTY)
353: .setEmpty();
354: case Date:
355: return new FxDate(multiLang, lang, FxDate.EMPTY).setEmpty();
356: case DateTime:
357: return new FxDateTime(multiLang, lang, FxDateTime.EMPTY)
358: .setEmpty();
359: case DateRange:
360: return new FxDateRange(multiLang, lang, FxDateRange.EMPTY)
361: .setEmpty();
362: case DateTimeRange:
363: return new FxDateTimeRange(multiLang, lang,
364: FxDateTimeRange.EMPTY).setEmpty();
365: case Boolean:
366: return new FxBoolean(multiLang, lang, FxBoolean.EMPTY)
367: .setEmpty();
368: case Binary:
369: return new FxBinary(multiLang, lang, FxBinary.EMPTY)
370: .setEmpty();
371: case Reference:
372: return new FxReference(multiLang, lang, FxReference.EMPTY)
373: .setEmpty();
374: case SelectOne:
375: return new FxSelectOne(multiLang, lang, this
376: .getReferencedList().getItems().get(0)).setEmpty();
377: case SelectMany:
378: return new FxSelectMany(multiLang, lang, new SelectMany(
379: this .getReferencedList())).setEmpty();
380: case InlineReference:
381: default:
382: throw new FxNotFoundException(
383: "ex.structure.datatype.notImplemented", this
384: .getDataType()).asRuntimeException();
385: }
386: }
387:
388: /**
389: * {@inheritDoc}
390: */
391: @Override
392: public boolean equals(Object obj) {
393: return obj instanceof FxProperty
394: && this .getId() == ((FxProperty) obj).getId();
395: }
396:
397: /**
398: * {@inheritDoc}
399: */
400: @Override
401: public int hashCode() {
402: return (int) this.getId();
403: }
404:
405: }
|