KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.apache.slide.projector.descriptor;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
6
7 import org.apache.slide.projector.value.ArrayValue;
8 import org.apache.slide.projector.value.Value;
9 import org.jdom.Element;
10
11 import de.zeigermann.xml.XMLStringWriter;
12 import de.zeigermann.xml.XMLWriter;
13
14 public class ArrayValueFactory implements ValueFactory {
15     public Class JavaDoc getValueClass() {
16         return ArrayValue.class;
17     }
18     
19     public String JavaDoc getElementName() {
20         return "array";
21     }
22     
23     public Value load(Element element) {
24         List JavaDoc children = new ArrayList JavaDoc();
25         for ( Iterator JavaDoc i = element.getChildren().iterator(); i.hasNext(); ) {
26             Element childElement = (Element)i.next();
27             children.add(ValueFactoryManager.getInstance().loadValue(childElement));
28         }
29         return new ArrayValue((Value [])children.toArray(new Value[children.size()]));
30     }
31
32     public void save(Value value, XMLStringWriter writer) {
33         Value[] array = ((ArrayValue)value).getArray();
34         writer.writeStartTag(XMLWriter.createStartTag(getElementName()));
35         for ( int i = 0; i < array.length; i++ ) {
36             ValueFactoryManager.getInstance().saveValue(array[i], writer);
37         }
38         writer.writeEndTag(XMLWriter.createEndTag(getElementName()));
39     }
40
41     public ValueDescriptor loadDescriptor(Element element) {
42         Element allowedArrayValueElement = (Element)element.getChildren().iterator().next();
43         ValueDescriptor allowedArrayValue = ValueFactoryManager.getInstance().loadValueDescriptor(allowedArrayValueElement);
44         return new ArrayValueDescriptor(allowedArrayValue);
45     }
46 }
Popular Tags