2 * Copyright (C) 2001, 2002 The Mir-coders group
4 * This file is part of Mir.
6 * Mir is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Mir is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Mir; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * In addition, as a special exception, The Mir-coders gives permission to link
21 * the code of this program with the com.oreilly.servlet library, any library
22 * licensed under the Apache Software License, The Sun (tm) Java Advanced
23 * Imaging library (JAI), The Sun JIMI library (or with modified versions of
24 * the above that use the same license as the above), and distribute linked
25 * combinations including the two. You must obey the GNU General Public
26 * License in all respects for all of the code used other than the above
27 * mentioned libraries. If you modify this file, you may extend this exception
28 * to your version of the file, but you are not obligated to do so. If you do
29 * not wish to do so, delete this exception statement from your version.
32 package mircoders.localizer.basic;
36 import mir.producer.*;
37 import mir.generator.*;
38 import mir.producer.reader.*;
41 import mir.entity.adapter.*;
42 import mircoders.global.*;
43 import mircoders.global.*;
44 import mircoders.localizer.*;
45 import mircoders.producer.reader.*;
46 import mircoders.producer.*;
48 public class MirBasicProducerLocalizer implements MirProducerLocalizer {
49 private List producerFactories;
50 private Map nameToFactory;
51 private List allNewProducerTasks;
53 protected FileMonitor fileMonitor;
54 protected EntityAdapterModel model;
55 protected Generator.GeneratorLibrary generatorLibrary;
56 protected WriterEngine writerEngine;
58 protected static Logfile logger = Logfile.getInstance( MirGlobal.getConfigProperty("Home") + "/" + MirGlobal.getConfigProperty("Mir.Localizer.Logfile"));
60 public MirBasicProducerLocalizer() {
62 String allNewProducers = MirGlobal.getConfigProperty("Mir.Localizer.Producer.AllNewProducers");
63 allNewProducerTasks = ProducerEngine.ProducerTask.parseProducerTaskList(allNewProducers);
65 producerFactories = new Vector();
66 model = MirGlobal.localizer().dataModel().adapterModel();
67 generatorLibrary = MirGlobal.localizer().generators().makeProducerGeneratorLibrary();
68 writerEngine = MirGlobal.localizer().generators().makeWriterEngine();
69 nameToFactory = new HashMap();
72 logger.printError("MirBasicProducerLocalizer(): Exception "+t.getMessage());
73 model = new EntityAdapterModel();
77 public List factories() throws MirLocalizerExc {
78 if (fileMonitor==null || producerFactories == null || fileMonitor.hasChanged()) {
80 List newProducers = new Vector();
81 FileMonitor newFileMonitor = new FileMonitor();
82 setupFactories(newProducers, newFileMonitor);
84 producerFactories = newProducers;
85 fileMonitor = newFileMonitor;
86 logger.printInfo("MirBasicProducerLocalizer.factories(): successfully setup factories");
88 nameToFactory.clear();
89 Iterator i = producerFactories.iterator();
91 ProducerFactory factory = (ProducerFactory) i.next();
92 nameToFactory.put(factory.getName(), factory);
96 logger.printError("MirBasicProducerLocalizer.factories(): Unable to setup factories: "+t.getMessage());
100 return producerFactories;
103 protected void setupProducerNodeBuilderLibrary(ProducerNodeBuilderLibrary aLibrary) throws MirLocalizerFailure {
105 DefaultProducerNodeBuilders.registerBuilders(
106 aLibrary, model, generatorLibrary, writerEngine,
107 MirGlobal.getConfigProperty("Home"), MirGlobal.getConfigProperty("Producer.StorageRoot"));
108 SupplementalProducerNodeBuilders.registerBuilders(aLibrary, model);
110 catch (Throwable t) {
111 throw new MirLocalizerFailure(t.getMessage(), t);
115 protected void setupFactories(List aFactories, FileMonitor aFileMonitor) throws MirLocalizerExc, MirLocalizerFailure {
116 ProducerConfigReader reader;
117 ProducerNodeBuilderLibrary library = new ProducerNodeBuilderLibrary();
118 setupProducerNodeBuilderLibrary(library);
119 List usedFiles = new Vector();
122 aFileMonitor.clear();
123 reader = new ProducerConfigReader();
124 reader.parseFile(MirGlobal.getConfigProperty("Home") + File.separatorChar + MirGlobal.getConfigProperty("Mir.Localizer.ProducerConfigFile"), library, aFactories, usedFiles);
126 i = usedFiles.iterator();
128 aFileMonitor.addFile((File) i.next());
130 setupFactories(aFactories);
133 protected void setupFactories(List aFactories) throws MirLocalizerExc, MirLocalizerFailure {
134 CompositeProducerNode node;
138 new CompositeProducerFactory("media", new ProducerFactory[] {
139 new OldProducerAdapterFactory("images", new ProducerImages()),
140 new OldProducerAdapterFactory("audio", new ProducerAudio()),
141 new OldProducerAdapterFactory("video", new ProducerVideo()),
142 new OldProducerAdapterFactory("other", new ProducerOther())
146 catch (Exception e) {
147 throw new MirLocalizerFailure(e);
151 public void produceAllNew() {
152 MirGlobal.producerEngine().addTasks(allNewProducerTasks);
155 public ProducerFactory getFactoryForName(String aName) {
159 catch (Throwable t) {
162 return (ProducerFactory) nameToFactory.get(aName);