/* * Moonlight|3D Copyright (C) 2006 The Moonlight|3D team * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Created on Apr 13, 2006 */ package ml.backend.sg; import java.util.ArrayList; import ml.core.exceptions.Exception; import ml.core.helper.DefaultFactory; import ml.core.helper.Factory; import org.w3c.dom.Element; public class Manager { private static ArrayList nodeFactories; static { nodeFactories=new ArrayList(); nodeFactories.add(new DefaultFactory("Reference",Reference.class)); nodeFactories.add(new DefaultFactory("Root",Root.class)); } public static void registerNodeFactory(Factory factory) { nodeFactories.add(factory); } public static void unregisterNodeFactory(String factoryName) { for(Factory factory : nodeFactories) { if(factory.getName().equals(factoryName)) { nodeFactories.remove(factory); return; } } } public Manager() { } public Node createNode(String typeName) throws Exception { for(Factory factory : nodeFactories) { if(factory.getName().equals(typeName)) { return (Node)factory.createNew(); } } throw new Exception("unable to find SG node factory for given type"); } public Node loadFromXML(Element rootElement) throws Exception { Node node; node=createNode(rootElement.getAttribute("type")); node.loadFromXML(this,rootElement); return node; } }