01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.ioc;
16:
17: import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
18:
19: import java.util.Collection;
20: import java.util.Collections;
21: import java.util.List;
22:
23: import org.apache.tapestry.ioc.annotations.Match;
24: import org.apache.tapestry.ioc.annotations.Order;
25:
26: /**
27: * Module used to demonstrate decorator ordering.
28: */
29: public class FredModule {
30:
31: /**
32: * Doesn't matter what the service does, we just want to verify that the decorators are invoked
33: * in the order we expect.
34: */
35: public Runnable buildFred() {
36: return new Runnable() {
37: public void run() {
38: }
39: };
40: }
41:
42: @Match({"UnorderedNames","Fred"})
43: @Order("before:Beta")
44: public Object decorateAlpha(Object delegate, DecoratorList list) {
45: list.add("alpha");
46:
47: return null;
48: }
49:
50: @Match({"UnorderedNames","Fred"})
51: public Object decorateBeta(Object delegate, DecoratorList list) {
52: list.add("beta");
53:
54: return null;
55: }
56:
57: public NameListHolder buildUnorderedNames(
58: Collection<String> configuration) {
59: final List<String> sorted = newList(configuration);
60:
61: Collections.sort(sorted);
62:
63: return new NameListHolder() {
64:
65: public List<String> getNames() {
66: return sorted;
67: }
68:
69: };
70: }
71:
72: public NameListHolder buildOrderedNames(
73: final List<String> configuration) {
74: return new NameListHolder() {
75:
76: public List<String> getNames() {
77: return configuration;
78: }
79:
80: };
81: }
82:
83: public void contributeOrderedNames(
84: OrderedConfiguration<String> configuration) {
85: // Order "FRED" after "BARNEY"
86:
87: configuration.add("fred", "FRED", "after:barney");
88: configuration.add("barney", "BARNEY");
89: }
90:
91: public void contributeUnorderedNames(
92: Configuration<String> configuration) {
93: configuration.add("UnorderedNames");
94: configuration.add("Beta");
95: }
96: }
|