1 4 package org.oddjob.designer; 5 6 import java.io.ByteArrayInputStream ; 7 8 import org.apache.log4j.Logger; 9 import org.oddjob.arooa.ArooaException; 10 import org.oddjob.arooa.ArooaContext; 11 import org.oddjob.arooa.ArooaConstants; 12 import org.oddjob.arooa.handlers.MainHandler; 13 import org.oddjob.arooa.handlers.MappedPropertyHandler; 14 import org.oddjob.arooa.xml.XMLDefinitionHelper; 15 import org.oddjob.designer.arooa.DesignComponentHandler; 16 import org.oddjob.designer.arooa.DesignElementHandler; 17 import org.oddjob.designer.arooa.DesignValueHandler; 18 import org.oddjob.designer.factory.DesignFactory; 19 import org.oddjob.designer.model.DesignComponent; 20 import org.xml.sax.InputSource ; 21 22 26 public class DesignerXMLParser { 27 private static final Logger logger = Logger.getLogger(DesignerXMLParser.class); 28 29 public static class RootComponent { 30 DesignComponent component; 31 public void addComponent(DesignComponent component) { 32 this.component = component; 33 } 34 } 35 36 44 public static DesignComponent buildComponent(String xml) 45 throws ArooaException { 46 47 ArooaContext context = new ArooaContext(); 48 context.set(ArooaConstants.COMPONENT_FACTORY, DesignFactory.componentFactory()); 49 context.set(ArooaConstants.COMPONENT_HANDLER, new DesignComponentHandler()); 50 context.set(ArooaConstants.PROPERTY_HANDLER, new DesignValueHandler()); 51 context.set(ArooaConstants.MAPPED_HANDLER, new MappedPropertyHandler()); 52 context.set(ArooaConstants.ELEMENT_HANDLER, new DesignElementHandler()); 53 54 RootComponent rootComponent = new RootComponent(); 55 context.set(ArooaConstants.CURRENTLY_CONFIGURING, rootComponent); 56 57 XMLDefinitionHelper ph = new XMLDefinitionHelper(context); 58 59 ByteArrayInputStream in = new ByteArrayInputStream (xml.getBytes()); 60 InputSource inputSource = new InputSource (in); 61 ph.parse(inputSource, new MainHandler(new DesignComponentHandler())); 62 63 return rootComponent.component; 64 } 65 66 } 67 | Popular Tags |