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;
025:
026: import java.util.HashMap;
027: import java.util.Iterator;
028: import java.util.Map;
029:
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032: import org.radeox.api.engine.RenderEngine;
033: import org.radeox.engine.BaseRenderEngine;
034: import org.radeox.util.Service;
035:
036: /**
037: * Acess point to dock several different rendering engines into e.g. SnipSnap.
038: * Will be replaced by PicoContainer (but kept for compatibility)
039: *
040: * @author Stephan J. Schmidt
041: * @version $Id: EngineManager.java 7707 2006-04-12 17:30:19Z
042: * ian@caret.cam.ac.uk $
043: */
044:
045: public class EngineManager {
046: private static Log log = LogFactory.getLog(EngineManager.class);
047:
048: public static final String DEFAULT = "radeox";
049:
050: private static Map availableEngines = new HashMap();
051:
052: static {
053: Iterator iterator = Service.providers(RenderEngine.class);
054: while (iterator.hasNext()) {
055: try {
056: RenderEngine engine = (RenderEngine) iterator.next();
057: registerEngine(engine);
058: log.debug("Loaded RenderEngine: "
059: + engine.getClass().getName());
060: } catch (Exception e) {
061: log.warn("EngineManager: unable to load RenderEngine",
062: e);
063: }
064: }
065: }
066:
067: /**
068: * Different RenderEngines can register themselves with the EngineManager
069: * factory to be available with EngineManager.getInstance();
070: *
071: * @param engine
072: * RenderEngine instance, e.g. SnipRenderEngine
073: */
074: public static synchronized void registerEngine(RenderEngine engine) {
075: if (null == availableEngines) {
076: availableEngines = new HashMap();
077: }
078: availableEngines.put(engine.getName(), engine);
079: }
080:
081: /**
082: * Get an instance of a RenderEngine. This is a factory method.
083: *
084: * @param name
085: * Name of the RenderEngine to get
086: * @return engine RenderEngine for the requested name
087: */
088: public static synchronized RenderEngine getInstance(String name) {
089: if (null == availableEngines) {
090: availableEngines = new HashMap();
091: }
092:
093: // Logger.debug("Engines: " + availableEngines);
094: return (RenderEngine) availableEngines.get(name);
095: }
096:
097: /**
098: * Get an instance of a RenderEngine. This is a factory method. Defaults to
099: * a default RenderEngine. Currently this is a basic EngineManager with no
100: * additional features that is distributed with Radeox.
101: *
102: * @return engine default RenderEngine
103: */
104: public static synchronized RenderEngine getInstance() {
105: // availableEngines = null;
106: if (null == availableEngines) {
107: availableEngines = new HashMap();
108: }
109:
110: if (!availableEngines.containsKey(DEFAULT)) {
111: RenderEngine engine = new BaseRenderEngine();
112: availableEngines.put(engine.getName(), engine);
113: }
114:
115: return (RenderEngine) availableEngines.get(DEFAULT);
116: }
117:
118: public static String getVersion() {
119: return "0.5.1";
120: }
121: }
|