KickJava   Java API By Example, From Geeks To Geeks.

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


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.MessageValue;
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 MessageValueFactory implements ValueFactory {
15     public final static String JavaDoc ID = "id";
16     public final static String JavaDoc ARGUMENTS = "arguments";
17
18     public Class JavaDoc getValueClass() {
19         return MessageValue.class;
20     }
21     
22     public String JavaDoc getElementName() {
23         return "message";
24     }
25     
26     public Value load(Element element) {
27         String JavaDoc messageId = element.getAttributeValue(ID);
28         List JavaDoc children = new ArrayList JavaDoc();
29         for ( Iterator JavaDoc i = element.getChildren().iterator(); i.hasNext(); ) {
30             Element childElement = (Element)i.next();
31             children.add(ValueFactoryManager.getInstance().loadValue(childElement));
32         }
33         return new MessageValue(messageId, (Value[])children.toArray(new Value[children.size()]));
34     }
35
36     public void save(Value value, XMLStringWriter writer) {
37         MessageValue messageValue = (MessageValue)value;
38         writer.writeStartTag(XMLWriter.createStartTag(getElementName(), ID, messageValue.getId()));
39         Value []arguments = messageValue.getArguments();
40         for ( int i = 0; i < arguments.length; i++ ) {
41             ValueFactoryManager.getInstance().saveValue(arguments[i], writer);
42         }
43         writer.writeEndTag(XMLWriter.createEndTag(getElementName()));
44     }
45
46     public ValueDescriptor loadDescriptor(Element element) {
47         return new MessageValueDescriptor();
48     }
49 }
Popular Tags