01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.category;
19:
20: import java.util.ArrayList;
21: import java.util.List;
22:
23: import de.finix.contelligent.logging.LoggingService;
24:
25: /**
26: * A <code>CategorySubset</code> represents a set of
27: * {@link de.finix.contelligent.category.CategoryManager#isValid valid values}
28: * for an registered category. This set is returned by
29: * {@link #getSupportedValues} instead of all supported values of the original
30: * category.
31: */
32: public class CategorySubset implements Category {
33: final static org.apache.log4j.Logger log = LoggingService
34: .getLogger(CategorySubset.class);
35:
36: private Category category;
37:
38: private int hashCode;
39:
40: private List supportedValues = new ArrayList();
41:
42: public CategorySubset(Category category) {
43: this .category = category;
44: this .hashCode = category.getName().hashCode();
45: }
46:
47: public void addValue(String supportedValue)
48: throws CategoryException {
49: if (category.isValueSupported(supportedValue)) {
50: supportedValues.add(supportedValue);
51: } else {
52: throw new CategoryException("value '" + supportedValue
53: + "' not supported by category " + category);
54: }
55: }
56:
57: public String getName() {
58: return category.getName();
59: }
60:
61: public String getDefaultValue() {
62: return category.getDefaultValue();
63: }
64:
65: public String getFallbackValue(String value) {
66: return category.getFallbackValue(value);
67: }
68:
69: public String[] getSupportedValues() {
70: return (String[]) supportedValues
71: .toArray(new String[supportedValues.size()]);
72: }
73:
74: public boolean isValueSupported(String value) {
75: return category.isValueSupported(value);
76: }
77:
78: public boolean equals(Object o) {
79: if (this == o)
80: return true;
81: if (o instanceof Category) {
82: return this .getName().equals(((Category) o).getName());
83: }
84: return false;
85: }
86:
87: public int hashCode() {
88: return hashCode;
89: }
90:
91: public boolean hasSessionScope() {
92: return category.hasSessionScope();
93: }
94:
95: public boolean hasRequestScope() {
96: return category.hasRequestScope();
97: }
98: }
|