bloritsch 02/03/19 05:05:32 Modified: src/scratchpad/src/org/apache/cocoon/callback CallBackHandler.java XMLSource.java Added: src/scratchpad/src/org/apache/cocoon/callback DefaultCallBackHandler.java Log: first implementation Revision Changes Path 1.5 +2 -2 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/callback/CallBackHandler.java Index: CallBackHandler.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/callback/CallBackHandler.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CallBackHandler.java 18 Mar 2002 22:23:39 -0000 1.4 +++ CallBackHandler.java 19 Mar 2002 13:05:32 -0000 1.5 @@ -59,13 +59,13 @@ * events that an XML document may have. * * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a> - * @version $Id: CallBackHandler.java,v 1.4 2002/03/18 22:23:39 bloritsch Exp $ + * @version $Id: CallBackHandler.java,v 1.5 2002/03/19 13:05:32 bloritsch Exp $ */ public interface CallBackHandler extends Component { String ROLE = CallBackHandler.class.getName(); - XMLSource handleEvent( XMLEventDescriptor event ); + XMLSource handleEvent( String type, Parameters params ); XMLEventDescriptor resolve( XMLFragment fragment ); } 1.3 +3 -2 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/callback/XMLSource.java Index: XMLSource.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/callback/XMLSource.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- XMLSource.java 18 Mar 2002 21:22:51 -0000 1.2 +++ XMLSource.java 19 Mar 2002 13:05:32 -0000 1.3 @@ -50,15 +50,16 @@ */ package org.apache.cocoon.callback; +import org.apache.cocoon.environment.Source; import org.xml.sax.ContentHandler; /** * The XMLSource represents a CallBack enabled XML document. * * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a> - * @version $Id: XMLSource.java,v 1.2 2002/03/18 21:22:51 bloritsch Exp $ + * @version $Id: XMLSource.java,v 1.3 2002/03/19 13:05:32 bloritsch Exp $ */ -interface XMLSource +public interface XMLSource extends Source { void handle(ContentHandler content, CallBackHandler callBack); } 1.1 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/callback/DefaultCallBackHandler.java Index: DefaultCallBackHandler.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.callback; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.component.Composable; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.SAXConfigurationHandler; import org.apache.avalon.framework.parameters.Parameterizable; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.logger.LogEnabled; import org.apache.cocoon.xml.XMLFragment; import org.apache.cocoon.transformation.XIncludeTransformer; import java.util.Map; import java.util.HashMap; /** * The DefaultCallBackHandler is a proof of concept. It should be made to * dynamically assign XMLEventDescriptors. For now, I am merely performing * XInclude functionality. * * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a> * @version $Id: DefaultCallBackHandler.java,v 1.1 2002/03/19 13:05:32 bloritsch Exp $ */ public class DefaultCallBackHandler extends AbstractLogEnabled implements CallBackHandler, Composable, Parameterizable { private Map m_eventTypes = new HashMap(); private ComponentManager m_manager; private Parameters m_params; public DefaultCallBackHandler() { } public XMLSource handleEvent( String type, Parameters params ) { XMLCallBack callback = (XMLCallBack) m_eventTypes.get( type ); return callback.getFragment( params ); } public XMLEventDescriptor resolve( XMLFragment fragment ) { SAXConfigurationHandler handler = new SAXConfigurationHandler(); Configuration config = handler.getConfiguration(); DefaultXMLEventDescriptor descriptor = new DefaultXMLEventDescriptor(); descriptor.m_name = config.getAttribute( "type", "null" ); try { descriptor.m_params = Parameters.fromConfiguration( config ); } catch (Exception e) { getLogger().warn("Configuration does not have parameters", e); } return descriptor; } public void compose( ComponentManager manager ) { m_manager = manager; } public void parameterize( Parameters params ) { m_params = params; } public void initialize() throws Exception { String[] names = m_params.getNames(); ClassLoader loader = Thread.currentThread().getContextClassLoader(); for ( int i = 0; i < names.length; i++ ) { XMLCallBack callback = null; try { callback = (XMLCallBack) loader.loadClass( m_params.getParameter( names[i] ) ) .newInstance(); if (callback instanceof LogEnabled) { ((LogEnabled) callback).enableLogging( getLogger() ); } if (callback instanceof Composable) { ((Composable) callback).compose(m_manager); } if (callback instanceof Initializable) { ((Initializable) callback).initialize(); } m_eventTypes.put( names[i], callback ); } catch (Exception e) { getLogger().warn("Unable to resolve the event type " + names[i] + ", disabling its use", e); } } } protected final class DefaultXMLEventDescriptor implements XMLEventDescriptor { protected String m_name; protected Parameters m_params = new Parameters(); public String getName() { return m_name; } public Parameters getParameters() { return m_params; } } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]