1 4 package org.sapia.soto.state.cocoon; 5 6 import org.apache.avalon.framework.parameters.Parameters; 7 import org.apache.avalon.framework.service.ServiceException; 8 import org.apache.avalon.framework.service.ServiceSelector; 9 10 import org.apache.cocoon.ProcessingException; 11 import org.apache.cocoon.environment.SourceResolver; 12 import org.apache.cocoon.generation.ServiceableGenerator; 13 14 import org.xml.sax.SAXException ; 15 16 import java.io.IOException ; 17 18 import java.util.Map ; 19 20 21 34 public class CocoonStateGenerator extends ServiceableGenerator { 35 public static final String STATE_COMPONENT_HINT = "provider"; 36 public static final String STATE_ID = "state"; 37 38 41 public void generate() throws IOException , SAXException , ProcessingException { 42 try { 43 String state = this.parameters.getParameter(STATE_ID); 44 45 if (state == null) { 46 throw new ProcessingException("'state-machine' parameter not specified"); 47 } 48 49 String provider = this.parameters.getParameter(STATE_COMPONENT_HINT); 50 51 if (provider == null) { 52 throw new ProcessingException("'provider' parameter not specified"); 53 } 54 55 ServiceSelector selector = null; 56 57 try { 58 selector = (ServiceSelector) this.manager.lookup(CocoonStateMachineComponent.ROLE + 59 "Selector"); 60 } finally { 61 if (selector != null) { 62 this.manager.release(selector); 63 } 64 } 65 66 CocoonStateMachineComponent svc = (CocoonStateMachineComponent) selector.select(provider); 67 svc.execute(state, this.objectModel, this.xmlConsumer); 68 } catch (ServiceException e) { 69 throw new ProcessingException("Could not lookup Cocoon state machine service", 70 e); 71 } catch (Exception e) { 72 throw new ProcessingException("Could not execute state", e); 73 } 74 } 75 76 79 public void setup(SourceResolver resolver, Map objectModel, String src, 80 Parameters params) throws ProcessingException, SAXException , IOException { 81 super.setup(resolver, objectModel, src, params); 82 } 83 } 84 | Popular Tags |