KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > descriptor > ValueFactoryManager


1 /*
2  * $Header: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/descriptor/Attic/ValueFactoryManager.java,v 1.1 2004/08/04 15:22:48 dflorey Exp $
3  * $Revision: 1.1 $
4  * $Date: 2004/08/04 15:22:48 $
5  *
6  * ====================================================================
7  *
8  * Copyright 2004 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.projector.descriptor;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.apache.slide.projector.value.Value;
31 import org.jdom.Element;
32
33 import de.zeigermann.xml.XMLStringWriter;
34
35 /**
36  * The AdapterManager
37  *
38  */

39 public class ValueFactoryManager {
40     private final static ValueFactoryManager valueDescriptorManager = new ValueFactoryManager();
41     private List JavaDoc registeredDescriptorFactories = new ArrayList JavaDoc();
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 JavaDoc 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 JavaDoc 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 JavaDoc 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