You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jh...@apache.org on 2005/11/03 15:00:48 UTC

svn commit: r330548 [84/132] - in /cocoon/whiteboard/maven2/cocoon-flat-layout: ./ cocoon-ajax-block/ cocoon-ajax-block/api/ cocoon-ajax-block/api/src/ cocoon-ajax-block/api/src/main/ cocoon-ajax-block/api/src/main/java/ cocoon-ajax-block/api/src/main/...

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/DefaultCacheManager.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/DefaultCacheManager.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/DefaultCacheManager.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/DefaultCacheManager.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,110 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms;
+
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.component.Component;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import org.apache.commons.collections.FastHashMap;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceValidity;
+
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * Component implementing the {@link CacheManager} role.
+ *
+ * @version $Id: DefaultCacheManager.java 289538 2005-09-16 13:46:22Z sylvain $
+ */
+public class DefaultCacheManager
+        extends AbstractLogEnabled
+        implements CacheManager, ThreadSafe, Serviceable, Disposable,
+                   Configurable, Component {
+// FIXME: Component is there to allow this block to also run in the 2.1 branch
+
+    protected ServiceManager manager;
+    protected Configuration configuration;
+    protected Map cache;
+
+    public DefaultCacheManager() {
+        this.cache = new FastHashMap();
+    }
+
+    public void service(ServiceManager serviceManager) throws ServiceException {
+        this.manager = serviceManager;
+    }
+
+    /**
+     * Configurable
+     */
+    public void configure(Configuration configuration) throws ConfigurationException {
+        this.configuration = configuration;
+    }
+
+    public Object get(Source source, String prefix) {
+        // Create a cache key
+        final String key = prefix + source.getURI();
+
+        // If object is not in the cache then return null
+        Object[] objectAndValidity = (Object[]) this.cache.get(key);
+        if (objectAndValidity == null) {
+            return null;
+        }
+
+        // If object is in the cache, check stored object validity
+        final SourceValidity validity = (SourceValidity) objectAndValidity[1];
+        int valid = validity.isValid();
+        if (valid == SourceValidity.UNKNOWN) {
+            // Compare against current source validity
+            valid = validity.isValid(source.getValidity());
+        }
+
+        // If stored object is not valid then remove object from cache and return null
+        if (valid != SourceValidity.VALID) {
+            this.cache.remove(key);
+            return null;
+        }
+
+        // If valid then return cached object
+        return objectAndValidity[0];
+    }
+
+    public void set(Object object, Source source, String prefix) throws IOException {
+        final String key = prefix + source.getURI();
+        final SourceValidity validity = source.getValidity();
+        if (validity != null) {
+            Object[] objectAndValidity = {object,  validity};
+            this.cache.put(key, objectAndValidity);
+        }
+    }
+
+    /**
+     * Disposable
+     */
+    public void dispose() {
+        this.manager = null;
+        this.cache = null;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/DefaultCacheManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/DefaultFormManager.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/DefaultFormManager.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/DefaultFormManager.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/DefaultFormManager.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,257 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms;
+
+import org.apache.avalon.framework.CascadingException;
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.component.Component;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.forms.formmodel.Form;
+import org.apache.cocoon.forms.formmodel.FormDefinition;
+import org.apache.cocoon.forms.formmodel.FormDefinitionBuilder;
+import org.apache.cocoon.forms.formmodel.WidgetDefinitionBuilder;
+import org.apache.cocoon.forms.formmodel.library.LibraryManager;
+import org.apache.cocoon.forms.formmodel.library.LibraryManagerImpl;
+import org.apache.cocoon.forms.util.DomHelper;
+import org.apache.cocoon.forms.util.SimpleServiceSelector;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
+
+/**
+ * Component implementing the {@link FormManager} role.
+ *
+ * @version $Id: DefaultFormManager.java 326838 2005-10-20 06:26:53Z sylvain $
+ */
+public class DefaultFormManager
+  extends AbstractLogEnabled
+  implements FormManager, Contextualizable, ThreadSafe, Serviceable, Disposable, Configurable, Component, Initializable {
+// FIXME: Component is there to allow this block to also run in the 2.1 branch
+
+    protected static final String PREFIX = "CocoonForm:";
+    protected ServiceManager manager;
+    protected Configuration configuration;
+    protected SimpleServiceSelector widgetDefinitionBuilderSelector;
+    protected CacheManager cacheManager;
+    
+    protected LibraryManagerImpl libraryManager;
+
+    private Context avalonContext;
+    public void contextualize(Context context) throws ContextException {
+		this.avalonContext = context;
+	}
+
+    /** Temporary internal method, don't rely on it's existence! Needed to access the context from flowscript. */
+    // FIXME (SW). Extending the FOM is needed.
+    public Context getAvalonContext() {
+        return this.avalonContext;
+    }
+
+    public void service(ServiceManager manager) throws ServiceException {
+        this.manager = manager;
+        this.cacheManager = (CacheManager)manager.lookup(CacheManager.ROLE);
+    }
+
+    /**
+     * Configurable
+     */
+    public void configure(Configuration configuration) throws ConfigurationException {
+        this.configuration = configuration;
+    }
+
+    public void initialize() throws Exception {
+
+        libraryManager = new LibraryManagerImpl();
+        libraryManager.enableLogging(getLogger().getChildLogger("library"));
+        libraryManager.service(new FormServiceManager());
+        libraryManager.configure(configuration.getChild("libraries"));
+        
+        widgetDefinitionBuilderSelector = new SimpleServiceSelector("widget", WidgetDefinitionBuilder.class);
+        widgetDefinitionBuilderSelector.contextualize(avalonContext);
+        widgetDefinitionBuilderSelector.service(new FormServiceManager());
+        widgetDefinitionBuilderSelector.configure(configuration.getChild("widgets"));
+        
+        libraryManager.initialize();
+    }
+    
+    public ServiceSelector getWidgetDefinitionBuilderSelector() {
+    	return this.widgetDefinitionBuilderSelector;
+    }
+
+    public Form createForm(Source source) throws Exception {
+        FormDefinition formDefinition = getFormDefinition(source);
+        Form form = (Form)formDefinition.createInstance();
+        form.initialize();
+        return form;
+    }
+
+    public Form createForm(String uri) throws Exception {
+        SourceResolver sourceResolver = null;
+        Source source = null;
+
+        try {
+            sourceResolver = (SourceResolver)manager.lookup(SourceResolver.ROLE);
+
+            source = sourceResolver.resolveURI(uri);
+            Form form = createForm(source);
+            return form;
+        } finally {
+            if (source != null) {
+                sourceResolver.release(source);
+            }
+            if (sourceResolver != null) {
+                manager.release(sourceResolver);
+            }
+        }
+    }
+
+    public Form createForm(Element formElement) throws Exception {
+        Form form = (Form)getFormDefinition(formElement).createInstance();
+        form.initialize();
+        return form;
+    }
+
+    public FormDefinition createFormDefinition(Element formElement) throws Exception {
+        return getFormDefinition(formElement);
+    }
+
+    public FormDefinition getFormDefinition(Source source) throws Exception {
+        FormDefinition formDefinition = (FormDefinition)this.cacheManager.get(source, PREFIX);
+        
+        if(formDefinition != null && formDefinition.getLocalLibrary().dependenciesHaveChanged())
+        	formDefinition = null; // invalidate
+        
+        if (formDefinition == null) {
+        	
+        	if(getLogger().isDebugEnabled())
+        		getLogger().debug("Building Form: "+source.getURI());
+        	
+            Document formDocument;
+            try {
+                InputSource inputSource = new InputSource(source.getInputStream());
+                inputSource.setSystemId(source.getURI());
+                formDocument = DomHelper.parse(inputSource, this.manager);
+            } catch (Exception e) {
+                throw new CascadingException("Could not parse form definition from " +
+                                             source.getURI(), e);
+            }
+
+            Element formElement = formDocument.getDocumentElement();
+            formDefinition = getFormDefinition(formElement);
+            this.cacheManager.set(formDefinition, source, PREFIX);
+        }
+        return formDefinition;
+    }
+
+    public FormDefinition getFormDefinition(Element formElement) throws Exception {
+        // check that the root element is a fd:form element
+        if (!(formElement.getLocalName().equals("form") || FormsConstants.DEFINITION_NS.equals(formElement.getNamespaceURI())))
+            throw new Exception("Expected a Cocoon Forms form element at " + DomHelper.getLocation(formElement));
+
+        FormDefinitionBuilder formDefinitionBuilder = (FormDefinitionBuilder)widgetDefinitionBuilderSelector.select("form");
+        return (FormDefinition)formDefinitionBuilder.buildWidgetDefinition(formElement);
+    }
+
+    public FormDefinition createFormDefinition(String uri) throws Exception {
+        SourceResolver sourceResolver = null;
+        Source source = null;
+        Document formDocument = null;
+
+        try {
+            sourceResolver = (SourceResolver)manager.lookup(SourceResolver.ROLE);
+            source = sourceResolver.resolveURI(uri);
+
+            try {
+                InputSource inputSource = new InputSource(source.getInputStream());
+                inputSource.setSystemId(source.getURI());
+                formDocument = DomHelper.parse(inputSource, this.manager);
+            } catch (Exception e) {
+                throw new CascadingException("Could not parse form definition from " +
+                                             source.getURI(), e);
+            }
+
+        } finally {
+            if (source != null)
+                sourceResolver.release(source);
+            if (sourceResolver != null)
+                manager.release(sourceResolver);
+        }
+
+        Element formElement = formDocument.getDocumentElement();
+        return getFormDefinition(formElement);
+    }
+
+    /**
+     * Disposable
+     */
+    public void dispose() {
+        if (this.widgetDefinitionBuilderSelector != null) {
+            this.widgetDefinitionBuilderSelector.dispose();
+            this.widgetDefinitionBuilderSelector = null;
+        }
+        if(this.libraryManager != null) {
+        	this.libraryManager.dispose();
+        	this.libraryManager = null;
+        }
+        this.manager.release(this.cacheManager);
+        this.cacheManager = null;
+        this.manager = null;
+    }
+    
+    
+    public class FormServiceManager implements ServiceManager {
+        final String WIDGET_DEFINITION_BUILDER_SELECTOR_ROLE = WidgetDefinitionBuilder.class.getName() + "Selector";
+        final String LIBRARY_MANAGER_ROLE = LibraryManager.ROLE;
+
+        public Object lookup(String name) throws ServiceException {
+            if (WIDGET_DEFINITION_BUILDER_SELECTOR_ROLE.equals(name))
+                return widgetDefinitionBuilderSelector;
+            else if(LIBRARY_MANAGER_ROLE.equals(name))
+            	return libraryManager;
+            else
+                return manager.lookup(name);
+        }
+
+        public boolean hasService(String name) {
+            if (WIDGET_DEFINITION_BUILDER_SELECTOR_ROLE.equals(name))
+                return true;
+            else if(LIBRARY_MANAGER_ROLE.equals(name))
+            	return true;
+            else
+                return manager.hasService(name);
+        }
+
+        public void release(Object service) {
+            if (service != widgetDefinitionBuilderSelector
+            		&& service != libraryManager)
+                manager.release(service);
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/DefaultFormManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormContext.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormContext.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormContext.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormContext.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,47 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms;
+
+import java.util.Locale;
+
+import org.apache.cocoon.environment.Request;
+
+/**
+ * @version $Id: FormContext.java 56582 2004-11-04 10:16:22Z sylvain $
+ * 
+ */
+public class FormContext {
+    
+    protected Request request;
+    protected Locale locale;
+
+    public FormContext(Request request, Locale locale) {
+        this.request = request;
+        this.locale = locale;
+    }
+
+    public FormContext(Request request) {
+        this(request, request.getLocale());
+    }
+
+    public Request getRequest() {
+        return request;
+    }
+
+    public Locale getLocale() {
+        return locale;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormManager.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormManager.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormManager.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormManager.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,82 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms;
+
+import org.apache.cocoon.forms.formmodel.Form;
+import org.apache.cocoon.forms.formmodel.FormDefinition;
+import org.apache.excalibur.source.Source;
+import org.w3c.dom.Element;
+
+/**
+ * Work interface for the component that can create {@link Form}s.
+ * 
+ * @version $Id: FormManager.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public interface FormManager {
+    
+    String ROLE = FormManager.class.getName();
+
+    /**
+     * Creates a form instance based on the XML form definition
+     * that can be read from the specified source.
+     *
+     * <p>To avoid having to resolve the Source object yourself,
+     * use the {@link #createForm(java.lang.String)} method.
+     *
+     * <p>The form definition will be cached, so that future form instances
+     * can be creted quickly.
+     */
+    Form createForm(Source source) throws Exception;
+
+    /**
+     * Creates a form instance based on the XML form definition
+     * that can be retrieved from the specified URI.
+     *
+     * <p>The form definition will be cached, so that future form instances
+     * can be creted quickly.
+     */
+    Form createForm(String uri) throws Exception;
+
+    /**
+     * Creates a form instance based on the XML form definition that is
+     * supplied as a DOM tree.
+     *
+     * <p>The specified element must be a fd:form element.
+     *
+     * <p>The Form Definition will not be cached.
+     */
+    Form createForm(Element formElement) throws Exception;
+
+    /**
+     * Creates a form definition based on the XML form definition that is
+     * supplied as a DOM tree.
+     *
+     * <p>The specified element must be a fd:form element.
+
+     * <p>The Form Definition will not be cached.
+     */
+    FormDefinition createFormDefinition(Element formElement) throws Exception;
+
+    /**
+     * Creates a form definition based on the XML form definition
+     * that can be retrieved from the specified URI.
+     *
+     * <p>The specified element must be a fd:form element.
+
+     * <p>The Form Definition will not be cached.
+     */
+    FormDefinition createFormDefinition(String uri) throws Exception;
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormsConstants.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormsConstants.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormsConstants.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormsConstants.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,56 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms;
+
+/**
+ * Various constants used in the Cocoon Forms framework.
+ * 
+ * @version $Id: FormsConstants.java 326838 2005-10-20 06:26:53Z sylvain $
+ */
+public class FormsConstants {
+// TODO : see this later
+//    /**
+//     * The value returned by {@link org.apache.cocoon.forms.formmodel.Widget#getValue()}
+//     * when the widget's value is invalid.
+//     */
+//    public static final Object INVALID_VALUE = new Object() {
+//        public String toString() {
+//            return "Invalid value";
+//        }
+//    };
+    
+    /** Namespace for Template elements */
+    public static final String TEMPLATE_NS = "http://apache.org/cocoon/forms/1.0#template";
+    public static final String TEMPLATE_PREFIX = "ft";
+    public static final String TEMPLATE_PREFIX_COLON = "ft:";
+
+    /** Namespace for Instance elements */
+    public static final String INSTANCE_NS = "http://apache.org/cocoon/forms/1.0#instance";
+    public static final String INSTANCE_PREFIX = "fi";
+    public static final String INSTANCE_PREFIX_COLON = "fi:";
+
+    /** Namespace for Definition elements */
+    public static final String DEFINITION_NS = "http://apache.org/cocoon/forms/1.0#definition";
+    public static final String DEFINITION_PREFIX = "fd";
+    public static final String DEFINITION_PREFIX_COLON = "fd:";
+
+    /** I18n catalogue containing the built-in messages. */
+    public static final String I18N_CATALOGUE = "forms";
+    public static final String I18N_NS = "http://apache.org/cocoon/i18n/2.1";
+    public static final String I18N_PREFIX = "i18n";
+    public static final String I18N_PREFIX_COLON = "i18n:";
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormsConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormsRuntimeException.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormsRuntimeException.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormsRuntimeException.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormsRuntimeException.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,44 @@
+/*
+ * Copyright 1999-200( The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms;
+
+import org.apache.cocoon.util.location.LocatedRuntimeException;
+import org.apache.cocoon.util.location.Location;
+
+/**
+ * An exception raised when some runtime error occurs in form handling. This is a
+ * located exception, which points to the relevant element declaration.
+ * 
+ * @version $Id: FormsRuntimeException.java 290455 2005-09-20 14:06:24Z sylvain $
+ */
+public class FormsRuntimeException extends LocatedRuntimeException {
+
+    public FormsRuntimeException(String message, Location location) {
+        super(message, location);
+    }
+
+    public FormsRuntimeException(String message, Throwable cause, Location location) throws LocatedRuntimeException {
+        super(message, cause, location);
+    }
+
+    public FormsRuntimeException(String message, Throwable cause) throws LocatedRuntimeException {
+        super(message, cause);
+    }
+
+    public FormsRuntimeException(String message) {
+        super(message);
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/FormsRuntimeException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/acting/AbstractFormsAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/acting/AbstractFormsAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/acting/AbstractFormsAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/acting/AbstractFormsAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,50 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.acting;
+
+import org.apache.cocoon.acting.Action;
+import org.apache.cocoon.forms.FormManager;
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceException;
+
+/**
+ * Abstract base class for Cocoon Forms actions.
+ * 
+ * @version $Id: AbstractFormsAction.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public abstract class AbstractFormsAction 
+  implements Action, ThreadSafe, Serviceable, Disposable {
+      
+    protected ServiceManager manager;
+    
+    protected FormManager formManager;
+
+    public void service(ServiceManager serviceManager) throws ServiceException {
+        this.manager = serviceManager;
+        this.formManager = (FormManager)serviceManager.lookup(FormManager.ROLE);
+    }
+
+    public void dispose() {
+        if (this.manager != null) {
+            this.manager.release( this.formManager );
+            this.manager = null;
+            this.formManager = null;
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/acting/AbstractFormsAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/acting/HandleFormSubmitAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/acting/HandleFormSubmitAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/acting/HandleFormSubmitAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/acting/HandleFormSubmitAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,92 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.acting;
+
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.acting.Action;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.forms.FormContext;
+import org.apache.cocoon.forms.event.FormHandler;
+import org.apache.cocoon.forms.formmodel.Form;
+import org.apache.cocoon.i18n.I18nUtils;
+import org.apache.cocoon.components.LifecycleHelper;
+import org.apache.excalibur.source.Source;
+
+import java.util.Map;
+import java.util.Collections;
+import java.util.Locale;
+
+/**
+ * An action that will create a form instance, let it handle the current request (and
+ * do validation), and will return not-null if validation was successfully or null when
+ * validation failed. In both cases, the created form instance is stored in a request attribute,
+ * so that it can be picked up later on by other components.
+ *
+ * <p>Required parameters:
+ * <ul>
+ *  <li><strong>form-definition</strong>: filename (URL) pointing to the form definition file
+ *  <li><strong>attribute-name</strong>: name of the request attribute in which the form instance should be stored
+ * </ul>
+ * 
+ * @version $Id: HandleFormSubmitAction.java 157080 2005-03-11 14:04:07Z sylvain $
+ */
+public class HandleFormSubmitAction extends AbstractFormsAction implements Action, ThreadSafe {
+
+    public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters parameters)
+            throws Exception {
+        String formSource = parameters.getParameter("form-definition");
+        String formAttribute = parameters.getParameter("attribute-name");
+        String formHandlerClassName = parameters.getParameter("formhandler", null);
+
+        Locale locale = Locale.getDefault();
+        String localeStr = parameters.getParameter("locale", null);
+        if (localeStr != null) {
+            locale = I18nUtils.parseLocale(localeStr, locale);
+        }
+
+        Source source = resolver.resolveURI(formSource);
+        try {
+            Form form = formManager.createForm(source);
+
+            Request request = ObjectModelHelper.getRequest(objectModel);
+            FormHandler formHandler = null;
+
+            if (formHandlerClassName != null) {
+                // TODO cache these classes
+                Class clazz = Class.forName(formHandlerClassName);
+                formHandler = (FormHandler)clazz.newInstance();
+                LifecycleHelper.setupComponent(formHandler, null, null, manager, null);
+                form.setFormHandler(formHandler);
+            }
+
+            FormContext formContext = new FormContext(request, locale);
+
+            boolean finished = form.process(formContext);
+            request.setAttribute(formAttribute, form);
+
+            if (finished) {
+                return Collections.EMPTY_MAP;
+            }
+            return null;
+        } finally {
+            resolver.release(source);
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/acting/HandleFormSubmitAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/acting/MakeFormAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/acting/MakeFormAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/acting/MakeFormAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/acting/MakeFormAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,72 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.acting;
+
+import org.apache.cocoon.acting.Action;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.forms.FormManager;
+import org.apache.cocoon.forms.formmodel.Form;
+import org.apache.excalibur.source.Source;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceException;
+
+import java.util.Map;
+
+/**
+ * An action that creates a new form instance and stores it in a request attribute.
+ *
+ * <p>Required parameters:
+ * <ul>
+ *  <li><strong>form-definition</strong>: filename (URL) of the form definition file
+ *  <li><strong>attribute-name</strong>: name of the request attribute in which to store the form instance
+ * </ul>
+ * 
+ * @version $Id: MakeFormAction.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class MakeFormAction implements Action, ThreadSafe, Serviceable {
+
+    FormManager formManager;
+
+    public void service(ServiceManager serviceManager) throws ServiceException {
+        formManager = (FormManager)serviceManager.lookup(FormManager.ROLE);
+    }
+
+    public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters parameters)
+            throws Exception {
+        String formSource = parameters.getParameter("form-definition");
+        String formAttribute = parameters.getParameter("attribute-name");
+
+        Source source = null;
+        try {
+            source = resolver.resolveURI(formSource);
+            Form form = formManager.createForm(source);
+
+            Request request = ObjectModelHelper.getRequest(objectModel);
+            request.setAttribute(formAttribute, form);
+        } finally {
+            resolver.release(source);
+        }
+
+        return null;
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/acting/MakeFormAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/AbstractCustomBinding.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/AbstractCustomBinding.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/AbstractCustomBinding.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/AbstractCustomBinding.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,97 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.binding;
+
+import org.apache.cocoon.forms.binding.library.Library;
+import org.apache.cocoon.forms.formmodel.Widget;
+import org.apache.commons.jxpath.JXPathContext;
+
+/**
+ * AbstractCustomBinding
+ */
+public abstract class AbstractCustomBinding implements Binding {
+
+    //TODO: following stuff should be removed after we cleaned out the Binding interface
+    private Binding parent;
+    private String id;
+
+    /**
+     * Sets parent binding.
+     */
+    public void setParent(Binding binding) {
+        this.parent = binding;
+    }
+    /**
+     * Returns binding definition id.
+     */
+    public String getId() {
+        return this.id;
+    }
+    public Binding getClass(String id) {
+        return this.parent.getClass(id);        
+    }
+    //TODO: end of stuff to clean out over time
+    //below is the real useful stuff...
+    
+    public boolean isValid() {
+    	return false; // pessimistic
+    }
+    public Library getLocalLibrary() {
+    	return null;
+    }
+    
+    /**
+     * Binding service method called upon loading.
+     * This will delegate to the overloaded version specific for this base-class.
+     * {@link #doLoad(Widget, JXPathContext)}
+     * 
+     * @param frmModel
+     * @param objModel
+     * @throws BindingException
+     */
+    public final void loadFormFromModel(Widget frmModel, Object objModel) throws BindingException {
+        try {
+            doLoad(frmModel, (JXPathContext)objModel);
+        } catch (Exception e) {
+            throw new BindingException("Error executing custom binding", e);
+        }
+    }
+
+    /**
+     * Binding service method called upon saving.
+     * This will delegate to the overloaded version specific for this base-class.
+     * {@link #doSave(Widget, JXPathContext)}
+     * 
+     * @param frmModel
+     * @param objModel
+     * @throws BindingException
+     */
+    public final void saveFormToModel(Widget frmModel, Object objModel) throws BindingException {
+        try {
+            doSave(frmModel, (JXPathContext)objModel);
+        } catch (Exception e) {
+            throw new BindingException("Error executing custom binding", e);
+        }
+    }
+    
+    /**
+     * 
+     * @param frmModel
+     * @param context
+     */
+    protected abstract void doLoad(Widget frmModel, JXPathContext context) throws Exception;
+    protected abstract void doSave(Widget frmModel, JXPathContext context) throws Exception;
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/AbstractCustomBinding.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/AggregateJXPathBinding.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/AggregateJXPathBinding.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/AggregateJXPathBinding.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/AggregateJXPathBinding.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,95 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.binding;
+
+import org.apache.cocoon.forms.formmodel.AggregateField;
+import org.apache.cocoon.forms.formmodel.Widget;
+import org.apache.commons.jxpath.JXPathContext;
+
+/**
+ * AggregateJXPathBinding provides an implementation of a {@link Binding}
+ * that narrows the context towards provided childbindings.
+ * <p>
+ * NOTES: <ol>
+ * <li>This Binding assumes that the provided widget-id points to a widget
+ * that contains other widgets.</li>
+ * </ol>
+ *
+ * @version $Id: AggregateJXPathBinding.java 289538 2005-09-16 13:46:22Z sylvain $
+ */
+public class AggregateJXPathBinding extends ComposedJXPathBindingBase {
+
+    private final String xpath;
+
+    private final String widgetId;
+
+    /**
+     * Constructs AggregateJXPathBinding
+     * @param widgetId
+     * @param xpath
+     * @param childBindings
+     */
+    public AggregateJXPathBinding(
+            JXPathBindingBuilderBase.CommonAttributes commonAtts,
+            String widgetId, String xpath, JXPathBindingBase[] childBindings) {
+        super(commonAtts, childBindings);
+        this.widgetId = widgetId;
+        this.xpath = xpath;
+    }
+    
+    public String getXPath() { return xpath; }
+    public String getId() { return widgetId; }
+
+    /**
+     * Narrows the scope on the form-model to the member widget-field, and
+     * narrows the scope on the object-model to the member xpath-context
+     * before continuing the binding over the child-bindings.
+     */
+    public void doLoad(Widget frmModel,
+            JXPathContext jxpc) throws BindingException {
+        AggregateField aggregate =
+            (AggregateField)selectWidget(frmModel, this.widgetId);
+        JXPathContext subContext =
+            jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
+        super.doLoad(aggregate, subContext);
+        aggregate.combineFields();
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Done loading " + toString());
+        }
+    }
+
+    /**
+     * Narrows the scope on the form-model to the member widget-field, and
+     * narrows the scope on the object-model to the member xpath-context
+     * before continuing the binding over the child-bindings.
+     */
+    public void doSave(Widget frmModel,
+            JXPathContext jxpc) throws BindingException {
+        AggregateField aggregate =
+            (AggregateField)selectWidget(frmModel, this.widgetId);
+        JXPathContext subContext =
+            jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
+        super.doSave(aggregate, subContext);
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Done saving " + toString());
+        }
+    }
+
+    public String toString() {
+        return "AggregateJXPathBinding [widget=" + this.widgetId +
+            ", xpath=" + this.xpath + "]";
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/AggregateJXPathBinding.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/AggregateJXPathBindingBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/AggregateJXPathBindingBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/AggregateJXPathBindingBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/AggregateJXPathBindingBuilder.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,69 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.binding;
+
+import org.apache.cocoon.forms.util.DomHelper;
+import org.w3c.dom.Element;
+
+/**
+ * AggregateJXPathBindingBuilder provides a helper class for the Factory
+ * implemented in {@link JXPathBindingManager} that helps construct the
+ * actual {@link AggregateJXPathBinding} out of the configuration in the
+ * provided configElement which looks like:
+ * <pre><code>
+ * &lt;fb:aggregate id="<i>widget-id</i>" path="<i>xpath-expression</i>"&gt;
+ *   &lt;fb:field id="<i>sub-widget-id</i>" path="<i>relative-xpath</i>" />
+ * &lt;/fb:aggregate&gt;
+ * </code></pre>
+ *
+ * @version $Id: AggregateJXPathBindingBuilder.java 289538 2005-09-16 13:46:22Z sylvain $
+ */
+public class AggregateJXPathBindingBuilder
+    extends JXPathBindingBuilderBase {
+
+    public JXPathBindingBase buildBinding(Element bindingElm, JXPathBindingManager.Assistant assistant)
+            throws BindingException {
+        try {
+            CommonAttributes commonAtts = JXPathBindingBuilderBase.getCommonAttributes(bindingElm);
+            String xpath = DomHelper.getAttribute(bindingElm, "path", null);
+            String widgetId = DomHelper.getAttribute(bindingElm, "id", null);
+            
+            JXPathBindingBase[] childBindings = new JXPathBindingBase[0];
+            
+            // do inheritance
+            AggregateJXPathBinding otherBinding = (AggregateJXPathBinding)assistant.getContext().getSuperBinding();
+            if(otherBinding!=null) {
+            	childBindings = otherBinding.getChildBindings();
+            	commonAtts = JXPathBindingBuilderBase.mergeCommonAttributes(otherBinding.getCommonAtts(),commonAtts);
+            	
+            	if(xpath==null)
+            		xpath = otherBinding.getXPath();
+            	if(widgetId==null)
+            		widgetId = otherBinding.getId();
+            }
+            
+            childBindings = assistant.makeChildBindings(bindingElm,childBindings);
+            
+
+            AggregateJXPathBinding aggregateBinding = new AggregateJXPathBinding(commonAtts, widgetId, xpath, childBindings);
+            return aggregateBinding;
+        } catch (BindingException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new BindingException("Error building aggregate field binding defined at " + DomHelper.getLocation(bindingElm), e);
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/AggregateJXPathBindingBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/Binding.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/Binding.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/Binding.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/Binding.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,73 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.binding;
+
+import org.apache.cocoon.forms.binding.library.Library;
+import org.apache.cocoon.forms.formmodel.Widget;
+
+/**
+ * Binding declares the methods to 'bind' (i.e. 'load' and 'save')
+ * information elements from some back-end model (2nd argument) to and from
+ * a existing Cocoon Form Widget.
+ *
+ * @version $Id: Binding.java 289538 2005-09-16 13:46:22Z sylvain $
+ */
+public interface Binding {
+
+    /**
+     * Sets parent binding.
+     * @param binding Parent of this binding.
+     */
+    void setParent(Binding binding);
+
+    /**
+     * Gets binding definition id.
+     */
+    String getId();
+    
+    /**
+     * returns the local library for this tree of bindings
+     */
+    Library getLocalLibrary();
+    
+    /**
+     * checks for deep validity of this binding tree (taking into accound included libraries)
+     */
+    boolean isValid();
+
+    /**
+     * Gets a binding class.
+     * @param id Id of binding class to get.
+     */
+    Binding getClass(String id);
+
+    /**
+     * Loads the information-elements from the objModel to the frmModel.
+     *
+     * @param frmModel
+     * @param objModel
+     */
+    void loadFormFromModel(Widget frmModel, Object objModel)
+            throws BindingException;
+
+    /**
+     * Saves the infortmation-elements to the objModel from the frmModel.
+     * @param frmModel
+     * @param objModel
+     */
+    void saveFormToModel(Widget frmModel, Object objModel)
+            throws BindingException;
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/Binding.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/BindingBuilderContext.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/BindingBuilderContext.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/BindingBuilderContext.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/BindingBuilderContext.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.binding;
+
+import org.apache.cocoon.forms.binding.library.Library;
+
+/**
+ * @version $Id: BindingBuilderContext.java 289538 2005-09-16 13:46:22Z sylvain $
+ */
+public class BindingBuilderContext {
+
+	private Library localLibrary = null;
+	private Binding superBinding = null;
+	
+	public BindingBuilderContext(BindingBuilderContext other) {
+		this.localLibrary = other.localLibrary;
+		this.superBinding = other.superBinding;
+	}
+	public BindingBuilderContext() {
+		this.localLibrary = null;
+		this.superBinding = null;
+	}
+	
+	public Library getLocalLibrary() {
+		return localLibrary;
+	}
+	public void setLocalLibrary(Library lib) {
+		this.localLibrary = lib;
+	}
+	public Binding getSuperBinding() {
+		return superBinding;
+	}
+	public void setSuperBinding(Binding binding) {
+		this.superBinding = binding;
+	}
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/BindingBuilderContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/BindingException.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/BindingException.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/BindingException.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/BindingException.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,48 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.binding;
+
+import org.apache.cocoon.util.location.LocatedException;
+import org.apache.cocoon.util.location.Location;
+
+/**
+ * This exception is thrown when something goes wrong with the binding.
+ *
+ * @version $Id: BindingException.java 290473 2005-09-20 15:30:48Z sylvain $
+ */
+public class BindingException extends LocatedException {
+
+    public BindingException(String message, Location location) {
+        super(message, location);
+        // TODO Auto-generated constructor stub
+    }
+
+    public BindingException(String message, Throwable cause, Location location) {
+        super(message, cause, location);
+        // TODO Auto-generated constructor stub
+    }
+
+    public BindingException(String message, Throwable cause) {
+        super(message, cause);
+        // TODO Auto-generated constructor stub
+    }
+
+    public BindingException(String message) {
+        super(message);
+        // TODO Auto-generated constructor stub
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/BindingException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/BindingManager.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/BindingManager.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/BindingManager.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/BindingManager.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,47 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.binding;
+
+import org.apache.excalibur.source.Source;
+
+/**
+ * BindingManager declares the factory method that produces actual Bindings.
+ * @version $Id: BindingManager.java 151179 2005-02-03 16:55:16Z tim $
+ */
+public interface BindingManager {
+
+    /**
+     * Avalon Role for this service interface.
+     */
+    String ROLE = BindingManager.class.getName();
+
+    /**
+     * Constant matching the namespace used for the Binding config files.
+     */
+    String NAMESPACE = "http://apache.org/cocoon/forms/1.0#binding";
+
+    /**
+     * Creates a binding from the XML config found at source parameter.
+     * The binding will be cached.
+     */
+    Binding createBinding(Source bindingFile) throws BindingException;
+
+    /**
+     * Creates a binding from the XML config found at bindingURI parameter.
+     * The binding will be cached.
+     */
+    Binding createBinding(String bindingURI) throws BindingException;
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/BindingManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/CaseJXPathBinding.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/CaseJXPathBinding.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/CaseJXPathBinding.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/CaseJXPathBinding.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,102 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.binding;
+
+import org.apache.cocoon.forms.formmodel.Union;
+import org.apache.cocoon.forms.formmodel.Widget;
+import org.apache.commons.jxpath.JXPathContext;
+
+/**
+ * CaseJXPathBinding provides an implementation of a {@link Binding}
+ * that narrows the context towards provided childbindings.
+ * <p>
+ * NOTES: <ol>
+ * <li>This Binding assumes that the provided widget-id points to a
+ * case of a union.</li>
+ * </ol>
+ *
+ * @version $Id: CaseJXPathBinding.java 289538 2005-09-16 13:46:22Z sylvain $
+ */
+public class CaseJXPathBinding extends ComposedJXPathBindingBase {
+
+    private final String xpath;
+
+    private final String widgetId;
+
+    /**
+     * Constructs CaseJXPathBinding
+     * @param commonAtts
+     * @param widgetId
+     * @param xpath
+     * @param childBindings
+     */
+    public CaseJXPathBinding(JXPathBindingBuilderBase.CommonAttributes commonAtts, String widgetId, String xpath, JXPathBindingBase[] childBindings) {
+        super(commonAtts, childBindings);
+        this.widgetId = widgetId;
+        this.xpath = xpath;
+    }
+
+    public String getXPath() { return xpath; }
+    public String getId() { return widgetId; }
+
+    /**
+     * Narrows the scope on the form-model to the member widget-field, and
+     * narrows the scope on the object-model to the member xpath-context
+     * before continuing the binding over the child-bindings.
+     */
+    public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException {
+        Union unionWidget = (Union)frmModel;
+        if (widgetId.equals(unionWidget.getValue())) {
+            // JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
+            Binding[] subBindings = getChildBindings();
+            if (subBindings != null) {
+                int size = subBindings.length;
+                for (int i = 0; i < size; i++) {
+                    subBindings[i].loadFormFromModel(unionWidget, jxpc);
+                }
+            }
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("done loading " + toString());
+            }
+        }
+    }
+
+    /**
+     * Narrows the scope on the form-model to the member widget-field, and
+     * narrows the scope on the object-model to the member xpath-context
+     * before continuing the binding over the child-bindings.
+     */
+    public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
+        Union unionWidget = (Union)frmModel;
+        if (widgetId.equals(unionWidget.getValue())) {
+            // JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
+            Binding[] subBindings = getChildBindings();
+            if (subBindings != null) {
+                int size = subBindings.length;
+                for (int i = 0; i < size; i++) {
+                    subBindings[i].saveFormToModel(unionWidget, jxpc);
+                }
+            }
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("done saving " + toString());
+            }
+        }
+    }
+
+    public String toString() {
+        return "CaseJXPathBinding [widget=" + this.widgetId + ", xpath=" + this.xpath + "]";
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/CaseJXPathBinding.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/CaseJXPathBindingBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/CaseJXPathBindingBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/CaseJXPathBindingBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/CaseJXPathBindingBuilder.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,68 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.binding;
+
+import org.apache.cocoon.forms.util.DomHelper;
+import org.w3c.dom.Element;
+
+/**
+ * CaseJXPathBindingBuilder provides a helper class for the Factory
+ * implemented in {@link JXPathBindingManager} that helps construct the
+ * actual {@link CaseJXPathBinding} out of the configuration in the
+ * provided configElement which looks like:
+ * <pre><code>
+ * &lt;fb:case id="<i>widget-id</i>" path="<i>xpath-expression</i>"
+ *     direction="<i>load|save</i>" lenient="<i>true|false</i>" &gt;
+ *   &lt;fb:field id="<i>sub-widget-id</i>" path="<i>relative-xpath</i>" />
+ * &lt;/fb:case&gt;
+ * </code></pre>
+ *
+ * @version $Id: CaseJXPathBindingBuilder.java 289538 2005-09-16 13:46:22Z sylvain $
+ */
+public class CaseJXPathBindingBuilder extends JXPathBindingBuilderBase {
+
+    public JXPathBindingBase buildBinding(Element bindingElm, JXPathBindingManager.Assistant assistant)
+            throws BindingException {
+        try {
+            String widgetId = DomHelper.getAttribute(bindingElm, "id", null);
+            CommonAttributes commonAtts = JXPathBindingBuilderBase.getCommonAttributes(bindingElm);
+            String xpath = DomHelper.getAttribute(bindingElm, "path", null);
+
+            JXPathBindingBase[] childBindings = new JXPathBindingBase[0];
+            
+            // do inheritance
+            CaseJXPathBinding otherBinding = (CaseJXPathBinding)assistant.getContext().getSuperBinding();
+            if(otherBinding!=null) {
+            	childBindings = otherBinding.getChildBindings();
+            	commonAtts = JXPathBindingBuilderBase.mergeCommonAttributes(otherBinding.getCommonAtts(),commonAtts);
+            	
+            	if(xpath==null)
+            		xpath = otherBinding.getXPath();
+            	if(widgetId==null)
+            		widgetId = otherBinding.getId();
+            }
+            
+            childBindings = assistant.makeChildBindings(bindingElm,childBindings);
+
+            CaseJXPathBinding caseBinding = new CaseJXPathBinding(commonAtts, widgetId, xpath, childBindings);
+            return caseBinding;
+        } catch (BindingException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new BindingException("Error building case binding defined at " + DomHelper.getLocation(bindingElm), e);
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/CaseJXPathBindingBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/ClassJXPathBinding.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/ClassJXPathBinding.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/ClassJXPathBinding.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/ClassJXPathBinding.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,74 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.binding;
+
+import org.apache.cocoon.forms.formmodel.Widget;
+import org.apache.commons.jxpath.JXPathContext;
+
+/**
+ * ClassJXPathBinding provides an implementation of a {@link Binding}
+ * which allows the specification of a class of reusable bindings.
+ * <p>
+ * NOTES: <ol>
+ * <li>This Binding uses the provided widget-id as the name for the class.</li>
+ * </ol>
+ *
+ * @version $Id: ClassJXPathBinding.java 151179 2005-02-03 16:55:16Z tim $
+ */
+public class ClassJXPathBinding extends ComposedJXPathBindingBase {
+
+    private final String widgetId;
+
+    /**
+     * Constructs ClassJXPathBinding
+     * @param commonAtts
+     * @param widgetId
+     * @param childBindings
+     */
+    public ClassJXPathBinding(JXPathBindingBuilderBase.CommonAttributes commonAtts, String widgetId, JXPathBindingBase[] childBindings) {
+        super(commonAtts, childBindings);
+        this.widgetId = widgetId;
+    }
+
+    /**
+     * Returns binding definition id.
+     */
+    public String getId() {
+        return widgetId;
+    }
+
+    /**
+     * Narrows the scope on the form-model to the member widget-field, and
+     * narrows the scope on the object-model to the member xpath-context
+     * before continuing the binding over the child-bindings.
+     */
+    public void doLoad(Widget frmModel, JXPathContext jxpc) {
+        // Do nothing
+    }
+
+    /**
+     * Narrows the scope on the form-model to the member widget-field, and
+     * narrows the scope on the object-model to the member xpath-context
+     * before continuing the binding over the child-bindings.
+     */
+    public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
+        // Do nothing
+    }
+
+    public String toString() {
+        return "ClassJXPathBinding [widget=" + this.widgetId + "]";
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/ClassJXPathBinding.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/ClassJXPathBindingBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/ClassJXPathBindingBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/ClassJXPathBindingBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/ClassJXPathBindingBuilder.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,68 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.binding;
+
+import org.apache.cocoon.forms.util.DomHelper;
+import org.w3c.dom.Element;
+
+/**
+ * ClassJXPathBindingBuilder provides a helper class for the Factory
+ * implemented in {@link JXPathBindingManager} that helps construct the
+ * actual {@link ClassJXPathBinding} out of the configuration in the
+ * provided configElement which looks like:
+ * <pre><code>
+ * &lt;fb:class id="<i>widget-id</i>"&gt;
+ *   &lt;fb:field id="<i>sub-widget-id</i>" path="<i>relative-xpath</i>"
+ *       direction="<i>load|save</i>" lenient="<i>true|false</i>"/&gt;
+ * &lt;/fb:class&gt;
+ * </code></pre>
+ *
+ * @version $Id: ClassJXPathBindingBuilder.java 289538 2005-09-16 13:46:22Z sylvain $
+ */
+public class ClassJXPathBindingBuilder
+    extends JXPathBindingBuilderBase {
+
+    public JXPathBindingBase buildBinding(Element bindingElm, JXPathBindingManager.Assistant assistant)
+            throws BindingException {
+        try {
+            String widgetId = DomHelper.getAttribute(bindingElm, "id", null);
+            CommonAttributes commonAtts = JXPathBindingBuilderBase.getCommonAttributes(bindingElm);
+
+            JXPathBindingBase[] childBindings = new JXPathBindingBase[0]; 
+            
+//          do inheritance
+            ClassJXPathBinding otherBinding = (ClassJXPathBinding)assistant.getContext().getSuperBinding();
+            if(otherBinding!=null) {
+            	childBindings = otherBinding.getChildBindings();
+            	commonAtts = JXPathBindingBuilderBase.mergeCommonAttributes(otherBinding.getCommonAtts(),commonAtts);
+            	
+            	if(widgetId==null)
+            		widgetId = otherBinding.getId();
+            }
+            
+            childBindings = assistant.makeChildBindings(bindingElm,childBindings);
+
+            
+            ClassJXPathBinding classBinding =
+                new ClassJXPathBinding(commonAtts, widgetId, childBindings);
+            return classBinding;
+        } catch (BindingException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new BindingException("Error building class binding defined at " + DomHelper.getLocation(bindingElm), e);
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/ClassJXPathBindingBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/ComposedJXPathBindingBase.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/ComposedJXPathBindingBase.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/ComposedJXPathBindingBase.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/ComposedJXPathBindingBase.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,123 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.binding;
+
+import java.util.Collections;
+import java.util.HashMap;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.forms.formmodel.Widget;
+import org.apache.commons.jxpath.JXPathContext;
+
+/**
+ * ComposedJXPathBindingBase provides a helper base class for subclassing
+ * into specific {@link JXPathBindingBase} implementations that have nested
+ * child-bindings.
+ *
+ * @version $Id: ComposedJXPathBindingBase.java 289715 2005-09-17 10:05:05Z sylvain $
+ */
+public class ComposedJXPathBindingBase extends JXPathBindingBase {
+    private final JXPathBindingBase[] subBindings;
+
+    public String getXPath() { return null; }
+    
+    /**
+     * Constructs ComposedJXPathBindingBase
+     *
+     * @param childBindings sets the array of childBindings
+     */
+    public ComposedJXPathBindingBase(JXPathBindingBuilderBase.CommonAttributes commonAtts, JXPathBindingBase[] childBindings) {
+        super(commonAtts);
+        this.subBindings = childBindings;
+        if (this.subBindings != null) {
+            for (int i = 0; i < this.subBindings.length; i++) {
+                this.subBindings[i].setParent(this);
+            }
+        }
+    }
+
+    /**
+     * Receives the logger to use for logging activity, and hands it over to
+     * the nested children.
+     */
+    public void enableLogging(Logger logger) {
+        super.enableLogging(logger);
+        if (this.subBindings != null) {
+            for (int i = 0; i < this.subBindings.length; i++) {
+                this.subBindings[i].enableLogging(logger);
+            }
+        }
+    }
+
+    /**
+     * Gets a binding class by id.
+     * @param id Id of binding class to get.
+     */
+    public Binding getClass(String id) {
+        if (classes == null) {
+            classes = new HashMap();
+            if (this.subBindings != null) {
+                for (int i = 0; i < this.subBindings.length; i++) {
+                    Binding binding = this.subBindings[i];
+                    if (binding instanceof ClassJXPathBinding) {
+                        String bindingId = binding.getId();
+                        if (bindingId != null)
+                          classes.put(bindingId, binding);
+                    }
+                }
+                
+                // Fee memory used by an empty map
+                if (classes.size() == 0) {
+                    classes = Collections.EMPTY_MAP;
+                }
+            }
+        }
+        return super.getClass(id);
+    }
+
+    /**
+     * Returns child bindings.
+     */
+    public JXPathBindingBase[] getChildBindings() {
+        return subBindings;
+    }
+
+    /**
+     * Actively performs the binding from the ObjectModel to the CForms-form
+     * by passing the task onto it's children.
+     */
+    public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException {
+        if (this.subBindings != null) {
+            int size = this.subBindings.length;
+            for (int i = 0; i < size; i++) {
+                this.subBindings[i].loadFormFromModel(frmModel, jxpc);
+            }
+        }
+    }
+
+    /**
+     * Actively performs the binding from the CForms-form to the ObjectModel
+     * by passing the task onto it's children.
+     */
+    public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
+        if (this.subBindings != null) {
+            int size = this.subBindings.length;
+            for (int i = 0; i < size; i++) {
+                this.subBindings[i].saveFormToModel(frmModel, jxpc);
+            }
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/binding/ComposedJXPathBindingBase.java
------------------------------------------------------------------------------
    svn:eol-style = native