1 23 24 package org.apache.slide.projector.descriptor; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 import org.apache.slide.projector.value.Value; 31 import org.jdom.Element; 32 33 import de.zeigermann.xml.XMLStringWriter; 34 35 39 public class ValueFactoryManager { 40 private final static ValueFactoryManager valueDescriptorManager = new ValueFactoryManager(); 41 private List registeredDescriptorFactories = new ArrayList (); 42 43 public static ValueFactoryManager getInstance() { 44 return valueDescriptorManager; 45 } 46 47 public void registerDescriptorFactory(ValueFactory factory) { 48 registeredDescriptorFactories.add(factory); 49 } 50 51 public ValueDescriptor loadValueDescriptor(Element element) { 52 for ( Iterator i = registeredDescriptorFactories.iterator(); i.hasNext(); ) { 53 ValueFactory adapter = (ValueFactory)i.next(); 54 if ( element.getName().equals(adapter.getElementName()) ) { 55 return adapter.loadDescriptor(element); 56 } 57 } 58 return null; 59 } 60 61 public Value loadValue(Element element) { 62 for ( Iterator i = registeredDescriptorFactories.iterator(); i.hasNext(); ) { 63 ValueFactory adapter = (ValueFactory)i.next(); 64 if ( element.getName().equals(adapter.getElementName()) ) { 65 return adapter.load(element); 66 } 67 } 68 return null; 69 } 70 71 public void saveValue(Value value, XMLStringWriter xmlStringWriter) { 72 for ( Iterator i = registeredDescriptorFactories.iterator(); i.hasNext(); ) { 73 ValueFactory adapter = (ValueFactory)i.next(); 74 if ( value.getClass().equals(adapter.getValueClass()) ) { 75 adapter.save(value, xmlStringWriter); 76 } 77 } 78 } 79 } | Popular Tags |