01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.backend.list.helper.naming;
16:
17: import java.util.Iterator;
18: import java.util.LinkedList;
19: import java.util.List;
20:
21: /**
22: * Composite {@link NamingStrategy} that returns the result of the
23: * first child that gives a not-null value.
24: *
25: * @author Rein Raudjärv
26: *
27: * @since 1.1
28: */
29: public class OrNamingStrategy implements NamingStrategy {
30:
31: private final List children = new LinkedList();
32:
33: public void add(NamingStrategy namingStrategy) {
34: children.add(namingStrategy);
35: }
36:
37: public void addFirst(NamingStrategy namingStrategy) {
38: children.add(0, namingStrategy);
39: }
40:
41: public String fieldToColumnAlias(String fieldName) {
42: for (Iterator it = children.iterator(); it.hasNext();) {
43: NamingStrategy ns = (NamingStrategy) it.next();
44: String result = ns.fieldToColumnAlias(fieldName);
45: if (result != null) {
46: return result;
47: }
48: }
49: return fieldName; // do not change
50: }
51:
52: public String fieldToColumnName(String fieldName) {
53: for (Iterator it = children.iterator(); it.hasNext();) {
54: NamingStrategy ns = (NamingStrategy) it.next();
55: String result = ns.fieldToColumnName(fieldName);
56: if (result != null) {
57: return result;
58: }
59: }
60: return fieldName; // do not change
61: }
62:
63: }
|