01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.commons.betwixt.strategy.impl;
18:
19: import java.util.ArrayList;
20: import java.util.Collection;
21:
22: import org.apache.commons.betwixt.strategy.CollectiveTypeStrategy;
23:
24: /**
25: * Strategy that allows specific classes to be marked as
26: * collective ({@link #overrideCollective(Class)})
27: * or not collective ({@link #overrideNotCollective(Class)}).
28: * @since 0.8
29: */
30: public class OverrideCollectiveTypeStategy extends
31: CollectiveTypeStrategy {
32:
33: private final CollectiveTypeStrategy delegate;
34:
35: private final Collection collectiveClasses;
36: private final Collection notCollectiveClasses;
37:
38: /**
39: * Constructs a strategy which delegates to CollectiveTypeStrategy#DEFAULT
40: *
41: */
42: public OverrideCollectiveTypeStategy() {
43: this (CollectiveTypeStrategy.DEFAULT);
44: }
45:
46: /**
47: * Constructs a strategy which delegates all those that it does not override.
48: * @param delegate
49: */
50: public OverrideCollectiveTypeStategy(CollectiveTypeStrategy delegate) {
51: super ();
52: this .delegate = delegate;
53: collectiveClasses = new ArrayList();
54: notCollectiveClasses = new ArrayList();
55: }
56:
57: /**
58: * Marks the given type to be treated as collective.
59: * @param type <code>Class</code>, not null
60: */
61: public void overrideCollective(Class type) {
62: collectiveClasses.add(type);
63: }
64:
65: /**
66: * Marks the given type to be treated as not collective
67: * @param type
68: */
69: public void overrideNotCollective(Class type) {
70: notCollectiveClasses.add(type);
71: }
72:
73: /**
74: * @see CollectiveTypeStrategy#isCollective(Class)
75: */
76: public boolean isCollective(Class type) {
77: boolean result = delegate.isCollective(type);
78: if (collectiveClasses.contains(type)) {
79: result = true;
80: } else if (notCollectiveClasses.contains(type)) {
81: result = false;
82: }
83: return result;
84: }
85:
86: }
|