1 package org.apache.slide.projector.descriptor; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.List ; 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 ID = "id"; 16 public final static String ARGUMENTS = "arguments"; 17 18 public Class getValueClass() { 19 return MessageValue.class; 20 } 21 22 public String getElementName() { 23 return "message"; 24 } 25 26 public Value load(Element element) { 27 String messageId = element.getAttributeValue(ID); 28 List children = new ArrayList (); 29 for ( Iterator 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 |