X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fproducer%2FCompositeProducerFactory.java;h=23acbe1f315a9f5222eb2f9e64e0cc4966e56253;hb=ec89f6dc6e5cae2f6da9a2bb014eaac01beab882;hp=4019537564203f5608a3d4b0c724cff7d9c717a7;hpb=e42ecea2db8ff123f268edf48190d6b9b28fcedb;p=mir.git diff --git a/source/mircoders/producer/CompositeProducerFactory.java b/source/mircoders/producer/CompositeProducerFactory.java index 40195375..23acbe1f 100755 --- a/source/mircoders/producer/CompositeProducerFactory.java +++ b/source/mircoders/producer/CompositeProducerFactory.java @@ -1,18 +1,59 @@ +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with the com.oreilly.servlet library, any library + * licensed under the Apache Software License, The Sun (tm) Java Advanced + * Imaging library (JAI), The Sun JIMI library (or with modified versions of + * the above that use the same license as the above), and distribute linked + * combinations including the two. You must obey the GNU General Public + * License in all respects for all of the code used other than the above + * mentioned libraries. If you modify this file, you may extend this exception + * to your version of the file, but you are not obligated to do so. If you do + * not wish to do so, delete this exception statement from your version. + */ + package mircoders.producer; -import java.util.*; -import mir.entity.*; -import mir.producer.*; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import mir.producer.ProducerExc; +import mir.producer.ProducerFactory; +import mir.producer.ProducerFailure; public class CompositeProducerFactory implements ProducerFactory { - Map factories; // verb -> Vector ( ProducerFactory ) + private Map factories; // verb -> Vector ( ProducerFactory ) + private List verbs; + private String name; - public CompositeProducerFactory() { + public CompositeProducerFactory(String aName) { factories = new HashMap(); + verbs = new Vector(); + name = aName; } - public CompositeProducerFactory(ProducerFactory[] aSubProducerFactories) { - this(); + public CompositeProducerFactory(String aName, ProducerFactory[] aSubProducerFactories) { + this(aName); int i; @@ -21,15 +62,25 @@ public class CompositeProducerFactory implements ProducerFactory { } } - private List factoriesForVerb(String aVerb) { + private List findFactoriesForVerb(String aVerb) { + List result = (List) factories.get(aVerb); + + if (result==null) + result = new Vector(); + + return result; + } + + private List factoriesForVerb(ProducerVerb aVerb) { List result; - result=(List) factories.get(aVerb); + result=(List) factories.get(aVerb.getName()); if (result==null) { result=new Vector(); - factories.put(aVerb, result); + verbs.add(aVerb); + factories.put(aVerb.getName(), result); } return result; @@ -41,14 +92,14 @@ public class CompositeProducerFactory implements ProducerFactory { i=aFactory.verbs(); while (i.hasNext()) { - factoriesForVerb((String) i.next()).add(aFactory); + factoriesForVerb((ProducerVerb) i.next()).add(aFactory); } } public mir.producer.Producer makeProducer(String aVerb, Map aBasicValueSet) throws ProducerExc, ProducerFailure { CompositeProducer result = new CompositeProducer(); - Iterator i=factoriesForVerb(aVerb).iterator(); + Iterator i=findFactoriesForVerb(aVerb).iterator(); while (i.hasNext()) result.addProducer(((ProducerFactory) i.next()).makeProducer(aVerb, aBasicValueSet)); @@ -57,6 +108,10 @@ public class CompositeProducerFactory implements ProducerFactory { } public Iterator verbs() { - return factories.keySet().iterator(); + return verbs.iterator(); + } + + public String getName() { + return name; } }