001: // Copyright 2006, 2007 The Apache Software Foundation
002: //
003: // Licensed under the Apache License, Version 2.0 (the "License");
004: // you may not use this file except in compliance with the License.
005: // You may obtain a copy of the License at
006: //
007: // http://www.apache.org/licenses/LICENSE-2.0
008: //
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014:
015: package org.apache.tapestry.ioc;
016:
017: import java.util.Collection;
018: import java.util.Collections;
019: import java.util.List;
020:
021: import org.apache.tapestry.ioc.internal.util.CollectionFactory;
022:
023: public class StaticModule {
024: private static boolean _instantiated;
025:
026: private static boolean _fredRan;
027:
028: private static boolean _decoratorRan;
029:
030: public StaticModule() {
031: setInstantiated(true);
032: }
033:
034: public static Runnable buildFred() {
035: return new Runnable() {
036: public void run() {
037: setFredRan(true);
038: }
039: };
040: }
041:
042: public static Runnable buildBarney() {
043: return new Runnable() {
044: public void run() {
045: }
046: };
047: }
048:
049: public static Runnable decorateBarney(final Object delegate) {
050: return new Runnable() {
051: public void run() {
052: setDecoratorRan(true);
053:
054: ((Runnable) delegate).run();
055: }
056: };
057: }
058:
059: public static synchronized void setFredRan(boolean fredRan) {
060: _fredRan = fredRan;
061: }
062:
063: public static synchronized boolean getFredRan() {
064: return _fredRan;
065: }
066:
067: public static synchronized void setInstantiated(boolean instantiated) {
068: _instantiated = instantiated;
069: }
070:
071: public static synchronized boolean isInstantiated() {
072: return _instantiated;
073: }
074:
075: public static synchronized void setDecoratorRan(boolean decoratorRan) {
076: _decoratorRan = decoratorRan;
077: }
078:
079: public static synchronized boolean getDecoratorRan() {
080: return _decoratorRan;
081: }
082:
083: public static NameListHolder buildNames(
084: final Collection<String> configuration) {
085: return new NameListHolder() {
086: public List<String> getNames() {
087: List<String> result = CollectionFactory
088: .newList(configuration);
089:
090: Collections.sort(result);
091:
092: return result;
093: }
094: };
095: }
096:
097: public static void contributeNames(
098: Configuration<String> configuration) {
099: configuration.add("Fred");
100: }
101:
102: }
|