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.FxSharedUtils;
036: import com.flexive.shared.ObjectWithLabel;
037: import com.flexive.shared.exceptions.FxNotFoundException;
038: import com.flexive.shared.value.FxString;
039:
040: import java.io.Serializable;
041:
042: /**
043: * Definition how languages are handled by a type
044: *
045: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
046: */
047: public enum LanguageMode implements Serializable, ObjectWithLabel {
048:
049: /**
050: * Content is not language dependent
051: */
052: None(0),
053:
054: /**
055: * One language per content may be defined
056: */
057: Single(1),
058:
059: /**
060: * Every property may exist in different languages
061: */
062: Multiple(2);
063:
064: private int id;
065:
066: /**
067: * Ctor
068: *
069: * @param id internal id
070: */
071: LanguageMode(int id) {
072: this .id = id;
073: }
074:
075: /**
076: * Getter for the internal id
077: *
078: * @return internal id
079: */
080: public int getId() {
081: return id;
082: }
083:
084: /**
085: * Get a LanguageMode by its id
086: *
087: * @param id internal id
088: * @return LanguageMode
089: * @throws FxNotFoundException on errors
090: */
091: public static LanguageMode getById(int id)
092: throws FxNotFoundException {
093: for (LanguageMode langMode : LanguageMode.values())
094: if (langMode.id == id)
095: return langMode;
096: throw new FxNotFoundException(
097: "ex.structure.languageMode.notFound.id", id);
098: }
099:
100: /**
101: * Check if the current mode can be upgraded to newMode
102: *
103: * @param newMode mode to upgrade to
104: * @return upgradeable
105: */
106: public boolean isUpgradeable(LanguageMode newMode) {
107: return newMode.getId() > this .getId();
108: }
109:
110: /**
111: * {@inheritDoc}
112: */
113: public FxString getLabel() {
114: return FxSharedUtils.getEnumLabel(this);
115: }
116: }
|