01: /***************************************************************
02: * This file is part of the [fleXive](R) project.
03: *
04: * Copyright (c) 1999-2008
05: * UCS - unique computing solutions gmbh (http://www.ucs.at)
06: * All rights reserved
07: *
08: * The [fleXive](R) project is free software; you can redistribute
09: * it and/or modify it under the terms of the GNU General Public
10: * License as published by the Free Software Foundation;
11: * either version 2 of the License, or (at your option) any
12: * later version.
13: *
14: * The GNU General Public License can be found at
15: * http://www.gnu.org/copyleft/gpl.html.
16: * A copy is found in the textfile GPL.txt and important notices to the
17: * license from the author are found in LICENSE.txt distributed with
18: * these libraries.
19: *
20: * This library is distributed in the hope that it will be useful,
21: * but WITHOUT ANY WARRANTY; without even the implied warranty of
22: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23: * GNU General Public License for more details.
24: *
25: * For further information about UCS - unique computing solutions gmbh,
26: * please see the company website: http://www.ucs.at
27: *
28: * For further information about [fleXive](R), please see the
29: * project website: http://www.flexive.org
30: *
31: *
32: * This copyright notice MUST APPEAR in all copies of the file!
33: ***************************************************************/package com.flexive.shared.configuration;
34:
35: import java.util.ArrayList;
36: import java.util.Collections;
37: import java.util.List;
38:
39: /** Parameter scopes */
40: public enum ParameterScope {
41: /** Global parameter */
42: GLOBAL,
43: /** Division parameter (with global configuration fallback) */
44: DIVISION(ParameterScope.GLOBAL),
45: /** Division parameter (without global configuration fallback) */
46: DIVISION_ONLY,
47: /** User parameter (with division and global configuration fallback) */
48: USER(ParameterScope.DIVISION),
49: /** User parameter (without fallback values) */
50: USER_ONLY;
51:
52: private List<ParameterScope> allFallbacks = new ArrayList<ParameterScope>();
53:
54: /**
55: * Create a new scope.
56: * @param fallbacks Fallback scope(s) to be used. Fallback scopes
57: * are applied recursively.
58: */
59: private ParameterScope(ParameterScope... fallbacks) {
60: // get fallback scopes recursively and put them in allFallbacks
61: for (ParameterScope scope : fallbacks) {
62: allFallbacks.add(scope);
63: List<ParameterScope> fb2 = scope.getFallbacks();
64: for (ParameterScope fallback : fb2) {
65: if (!allFallbacks.contains(fallback)) {
66: allFallbacks.add(fallback);
67: }
68: }
69: }
70: this .allFallbacks = Collections.unmodifiableList(allFallbacks);
71: }
72:
73: /**
74: * Return the fallback scopes for this scope config.
75: * @return the fallback scopes for this scope config.
76: */
77: public List<ParameterScope> getFallbacks() {
78: return this .allFallbacks;
79: }
80:
81: /**
82: * Returns true if the scope represents - directly or through
83: * its fallbacks - the given scope.
84: * @param scope the scope to be checked
85: * @return true if the scope represents - directly or through its fallbacks - the given scope.
86: */
87: public boolean hasScope(ParameterScope scope) {
88: return this .allFallbacks.indexOf(scope) != -1;
89: }
90: }
|