001: /*
002: * This file is part of "SnipSnap Radeox Rendering Engine".
003: *
004: * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
005: * All Rights Reserved.
006: *
007: * Please visit http://radeox.org/ for updates and contact.
008: *
009: * --LICENSE NOTICE--
010: * Licensed under the Apache License, Version 2.0 (the "License");
011: * you may not use this file except in compliance with the License.
012: * You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: * --LICENSE NOTICE--
022: */
023:
024: package org.radeox.macro;
025:
026: import java.util.ArrayList;
027: import java.util.HashMap;
028: import java.util.Iterator;
029: import java.util.List;
030: import java.util.Map;
031:
032: import org.apache.commons.logging.Log;
033: import org.apache.commons.logging.LogFactory;
034: import org.radeox.api.engine.context.InitialRenderContext;
035: import org.radeox.api.macro.Macro;
036:
037: /**
038: * Repository for plugins
039: *
040: * @author Stephan J. Schmidt
041: * @version $Id: MacroRepository.java 7707 2006-04-12 17:30:19Z
042: * ian@caret.cam.ac.uk $
043: */
044:
045: public class MacroRepository extends PluginRepository {
046: private static Log log = LogFactory.getLog(MacroRepository.class);
047:
048: private InitialRenderContext context;
049:
050: protected static MacroRepository instance;
051:
052: protected List loaders;
053:
054: public synchronized static MacroRepository getInstance() {
055: if (null == instance) {
056: instance = new MacroRepository();
057: }
058: return instance;
059: }
060:
061: private void initialize(InitialRenderContext context) {
062: Iterator iterator = list.iterator();
063: while (iterator.hasNext()) {
064: Macro macro = (Macro) iterator.next();
065: macro.setInitialContext(context);
066: }
067: init();
068: }
069:
070: public void setInitialContext(InitialRenderContext context) {
071: this .context = context;
072: initialize(context);
073: }
074:
075: private void init() {
076: Map newPlugins = new HashMap();
077:
078: Iterator iterator = list.iterator();
079: while (iterator.hasNext()) {
080: Macro macro = (Macro) iterator.next();
081: newPlugins.put(macro.getName(), macro);
082: }
083: plugins = newPlugins;
084: }
085:
086: /**
087: * Loads macros from all loaders into plugins.
088: */
089: private void load() {
090: Iterator iterator = loaders.iterator();
091: while (iterator.hasNext()) {
092: MacroLoader loader = (MacroLoader) iterator.next();
093: loader.setRepository(this );
094: log.debug("Loading from: " + loader.getClass());
095: loader.loadPlugins(this );
096: }
097: }
098:
099: public void addLoader(MacroLoader loader) {
100: loader.setRepository(this );
101: loaders.add(loader);
102: plugins = new HashMap();
103: list = new ArrayList();
104: load();
105: }
106:
107: private MacroRepository() {
108: loaders = new ArrayList();
109: loaders.add(new MacroLoader());
110: load();
111: }
112: }
|