Author: giacomo
Date: Wed Mar 23 13:52:41 2005
New Revision: 158837

URL: http://svn.apache.org/viewcvs?view=rev&rev=158837
Log:
added discussed features to flow-jxpath selection list including new 'bean' 
Datatype

Added:
    
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertor.java
    
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertorBuilder.java
    
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl/BeanType.java
    
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl/BeanTypeBuilder.java
Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/conf/forms-datatype.xconf
    
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/Constants.java
    
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/EnumSelectionList.java
    
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionList.java
    
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/conf/forms-datatype.xconf
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/conf/forms-datatype.xconf?view=diff&r1=158836&r2=158837
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/conf/forms-datatype.xconf 
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/conf/forms-datatype.xconf Wed 
Mar 23 13:52:41 2005
@@ -75,6 +75,11 @@
           <convertor name="enum" 
src="org.apache.cocoon.forms.datatype.convertor.EnumConvertorBuilder"/>
         </convertors>
       </datatype>
+      <datatype name="bean" 
src="org.apache.cocoon.forms.datatype.typeimpl.BeanTypeBuilder">
+        <convertors default="bean" plain="bean">
+          <convertor name="bean" 
src="org.apache.cocoon.forms.datatype.convertor.BeanConvertorBuilder"/>
+        </convertors>
+      </datatype>
     </datatypes>
     <validation-rules>
       <!-- old-style datatype validators (deprecated) -->

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/Constants.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/Constants.java?view=diff&r1=158836&r2=158837
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/Constants.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/Constants.java
 Wed Mar 23 13:52:41 2005
@@ -49,5 +49,8 @@
 
     /** 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:";
 
 }

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/EnumSelectionList.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/EnumSelectionList.java?view=diff&r1=158836&r2=158837
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/EnumSelectionList.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/EnumSelectionList.java
 Wed Mar 23 13:52:41 2005
@@ -56,8 +56,6 @@
  * @version $Id$
  */
 public class EnumSelectionList implements SelectionList {
-    public static final String I18N_NS = "http://apache.org/cocoon/i18n/2.1";;
-    public static final String I18N_PREFIX_COLON = "i18n:";
     public static final String TEXT_EL = "text";
 
     private Datatype datatype;
@@ -108,9 +106,9 @@
                     contentHandler.startElement(Constants.INSTANCE_NS, 
ITEM_EL, Constants.INSTANCE_PREFIX_COLON + ITEM_EL, itemAttrs);
                     contentHandler.startElement(Constants.INSTANCE_NS, 
LABEL_EL, Constants.INSTANCE_PREFIX_COLON + LABEL_EL, 
XMLUtils.EMPTY_ATTRIBUTES);
                     // TODO: make i18n element optional
-                    contentHandler.startElement(I18N_NS, TEXT_EL, 
I18N_PREFIX_COLON + TEXT_EL, XMLUtils.EMPTY_ATTRIBUTES);
+                    contentHandler.startElement(Constants.I18N_NS, TEXT_EL, 
Constants.I18N_PREFIX_COLON + TEXT_EL, XMLUtils.EMPTY_ATTRIBUTES);
                     contentHandler.characters(stringValue.toCharArray(), 0, 
stringValue.length());
-                    contentHandler.endElement(I18N_NS, TEXT_EL, 
I18N_PREFIX_COLON + TEXT_EL);
+                    contentHandler.endElement(Constants.I18N_NS, TEXT_EL, 
Constants.I18N_PREFIX_COLON + TEXT_EL);
                     contentHandler.endElement(Constants.INSTANCE_NS, LABEL_EL, 
Constants.INSTANCE_PREFIX_COLON + LABEL_EL);
                     contentHandler.endElement(Constants.INSTANCE_NS, ITEM_EL, 
Constants.INSTANCE_PREFIX_COLON + ITEM_EL);
                 }

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionList.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionList.java?view=diff&r1=158836&r2=158837
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionList.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionList.java
 Wed Mar 23 13:52:41 2005
@@ -22,6 +22,7 @@
 import org.apache.cocoon.components.ContextHelper;
 import org.apache.cocoon.components.flow.FlowHelper;
 import org.apache.cocoon.forms.Constants;
+import org.apache.cocoon.forms.util.I18nMessage;
 import org.apache.cocoon.xml.AttributesImpl;
 import org.apache.cocoon.xml.XMLUtils;
 import org.apache.commons.jxpath.JXPathContext;
@@ -46,13 +47,31 @@
     private String labelPath;
     private Datatype datatype;
     private Object model;
-
-    public FlowJXPathSelectionList(Context context, String listPath, String 
valuePath, String labelPath, Datatype datatype) {
+    private boolean nullable = false; 
+    private String nullText;
+    private boolean nullTextIsI18nKey = false;
+    private String i18nCatalog;
+    private boolean labelIsI18nKey = false;
+
+    public FlowJXPathSelectionList(Context context, 
+                                   String listPath, 
+                                   String valuePath, 
+                                   String labelPath, 
+                                   Datatype datatype,
+                                   String nullText, 
+                                   boolean nullTextIsI18nKey, 
+                                   String i18nCatalog, 
+                                   boolean labelIsI18nKey) {
         this.context = context;
         this.listPath = listPath;
         this.valuePath = valuePath;
         this.labelPath = labelPath;
         this.datatype = datatype;
+        this.nullText = nullText;
+        this.nullable = (nullText != null);
+        this.nullTextIsI18nKey = nullTextIsI18nKey;
+        this.i18nCatalog =i18nCatalog;
+        this.labelIsI18nKey = labelIsI18nKey;
     }
 
     /**
@@ -100,6 +119,39 @@
 
         // Start the selection-list
         contentHandler.startElement(Constants.INSTANCE_NS, SELECTION_LIST_EL, 
Constants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL, XMLUtils.EMPTY_ATTRIBUTES);
+        if( this.nullable ) {
+            final AttributesImpl voidAttrs = new AttributesImpl(  );
+            voidAttrs.addCDATAAttribute( "value", "" );
+            contentHandler.startElement( Constants.INSTANCE_NS, ITEM_EL,
+                                         Constants.INSTANCE_PREFIX_COLON +
+                                         ITEM_EL, voidAttrs );
+
+            if( this.nullText != null ) {
+                contentHandler.startElement( Constants.INSTANCE_NS, LABEL_EL,
+                                             Constants.INSTANCE_PREFIX_COLON +
+                                             LABEL_EL, 
XMLUtils.EMPTY_ATTRIBUTES );
+
+                if( this.nullTextIsI18nKey ) {
+                    if( ( this.i18nCatalog != null ) &&
+                        ( this.i18nCatalog.trim(  ).length(  ) > 0 ) ) {
+                        new I18nMessage( this.nullText, this.i18nCatalog 
).toSAX( contentHandler );
+                    } else {
+                        new I18nMessage( this.nullText ).toSAX( contentHandler 
);
+                    }
+                } else {
+                    contentHandler.characters( this.nullText.toCharArray(  ), 
0,
+                                               this.nullText.length(  ) );
+                }
+
+                contentHandler.endElement( Constants.INSTANCE_NS, LABEL_EL,
+                                           Constants.INSTANCE_PREFIX_COLON +
+                                           LABEL_EL );
+            }
+
+            contentHandler.endElement( Constants.INSTANCE_NS, ITEM_EL,
+                                       Constants.INSTANCE_PREFIX_COLON +
+                                       ITEM_EL );
+        }
 
         while(iter.hasNext()) {
             String stringValue = "";
@@ -135,6 +187,15 @@
                 contentHandler.startElement(Constants.INSTANCE_NS, LABEL_EL, 
Constants.INSTANCE_PREFIX_COLON + LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES);
                 if (label instanceof XMLizable) {
                     ((XMLizable)label).toSAX(contentHandler);
+                }  else if( this.labelIsI18nKey ) {
+                    String stringLabel = label.toString();
+
+                    if( ( this.i18nCatalog != null ) &&
+                        ( this.i18nCatalog.trim(  ).length(  ) > 0 ) ) {
+                        new I18nMessage( stringLabel, this.i18nCatalog 
).toSAX( contentHandler );
+                    } else {
+                        new I18nMessage( stringLabel ).toSAX( contentHandler );
+                    }
                 } else {
                     String stringLabel = label.toString();
                     contentHandler.characters(stringLabel.toCharArray(), 0, 
stringLabel.length());

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java?view=diff&r1=158836&r2=158837
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java
 Wed Mar 23 13:52:41 2005
@@ -18,9 +18,12 @@
 import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.cocoon.forms.Constants;
 import org.apache.cocoon.forms.util.DomHelper;
 import org.w3c.dom.Element;
 
+import java.util.Map;
+
 /**
  * Builds a selection list that will take its values from the flow page data.
  * The items list and, for each item, its value and label, are fetched using
@@ -56,10 +59,37 @@
     public SelectionList build(Element selectionListElement, Datatype 
datatype) throws Exception {
 
         String listPath = DomHelper.getAttribute(selectionListElement, 
"list-path");
-        String keyPath = DomHelper.getAttribute(selectionListElement, 
"value-path");
-        String valuePath = DomHelper.getAttribute(selectionListElement, 
"label-path");
-
-        return new FlowJXPathSelectionList(context, listPath, keyPath, 
valuePath, datatype);
+        String valuePath = DomHelper.getAttribute(selectionListElement, 
"value-path");
+        Map nspfx = DomHelper.getInheritedNSDeclarations(selectionListElement);
+        String i18nPfx = (String)nspfx.get( Constants.I18N_NS );
+        String labelPath = DomHelper.getAttribute(selectionListElement, 
"label-path", null);
+        boolean labelIsI18nKey = false;
+        if( labelPath == null )
+        {
+            labelPath = DomHelper.getAttribute(selectionListElement, i18nPfx + 
":label-path");
+            labelIsI18nKey = true;
+        }
+        String nullText = DomHelper.getAttribute(selectionListElement, 
"null-text", null);
+        boolean nullTextIsI18nKey = false;
+        if( nullText == null ) {
+            nullText = DomHelper.getAttribute(selectionListElement, i18nPfx + 
":null-text", null);
+            if( nullText != null ) {
+                nullTextIsI18nKey = true;
+            }
+        }
+        
+        String i18nCatalog = DomHelper.getAttribute(selectionListElement, 
"catalogue", null);
+
+
+        return new FlowJXPathSelectionList(context, 
+                                           listPath, 
+                                           valuePath, 
+                                           labelPath, 
+                                           datatype, 
+                                           nullText, 
+                                           nullTextIsI18nKey, 
+                                           i18nCatalog, 
+                                           labelIsI18nKey);
     }
 
 }

Added: 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertor.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertor.java?view=auto&rev=158837
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertor.java
 (added)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertor.java
 Wed Mar 23 13:52:41 2005
@@ -0,0 +1,145 @@
+/*
+ * 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.datatype.convertor;
+
+import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.commons.jxpath.JXPathContext;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+
+/**
+ * Converts String representation of beans to bean instances and vice versa.
+ * 
+ * <p>
+ * Sometimes the toString() method doesn't give a good representation of a
+ * Java Bean suited for selection list IDs. For this an optional  
+ * &lt;fd:id-path&gt;jx-path&lt;/fd:id-path&gt; attribute can be specified to 
+ * have this convertor to use a different string representation.
+ * </p>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
+ * @version $Id: BeanConvertor.java,v 1.3 2004/12/30 13:37:45 giacomo Exp $
+ */
+public class BeanConvertor
+    implements Convertor
+{
+    //~ Instance fields 
--------------------------------------------------------
+
+    private Class m_class;
+
+    private Map m_objects = new WeakHashMap(  );
+
+    private String m_idPath;
+
+    //~ Constructors 
-----------------------------------------------------------
+
+    /**
+     * Construct a new BeanConvertor for a class
+     *
+     * @param className The package-qualified name of the class implementing
+     *        the typesafe enum pattern.
+     * @param idPath Path to the identity field of the bean
+     *
+     * @throws CascadingRuntimeException If the class cannot be found
+     */
+    public BeanConvertor( final String className,
+                          final String idPath )
+    {
+        try
+        {
+            m_class = Class.forName( className );
+        }
+        catch( ClassNotFoundException e )
+        {
+            throw new CascadingRuntimeException( "Class " + className +
+                                                 " not found", e );
+        }
+
+        m_idPath = idPath;
+    }
+
+    //~ Methods 
----------------------------------------------------------------
+
+    /**
+     * @see org.apache.cocoon.forms.datatype.convertor.Convertor#getTypeClass()
+     */
+    public Class getTypeClass(  )
+    {
+        return m_class;
+    }
+
+    /**
+     * @see 
org.apache.cocoon.forms.datatype.convertor.Convertor#convertFromString(java.lang.String,
+     *      java.util.Locale,
+     *      org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache)
+     */
+    public ConversionResult convertFromString( final String value,
+                                               final Locale locale,
+                                               final FormatCache formatCache )
+    {
+        return new ConversionResult( m_objects.get( value ) );
+    }
+
+    /**
+     * @see 
org.apache.cocoon.forms.datatype.convertor.Convertor#convertToString(java.lang.Object,
+     *      java.util.Locale,
+     *      org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache)
+     */
+    public String convertToString( final Object value,
+                                   final Locale locale,
+                                   final FormatCache formatCache )
+    {
+        String idValue = "";
+
+        if( null != value )
+        {
+            if( m_idPath != null )
+            {
+                final JXPathContext ctx = JXPathContext.newContext( value );
+                idValue = ctx.getValue( m_idPath ).toString(  );
+            }
+            else
+            {
+                idValue = value.toString(  );
+            }
+        }
+
+        m_objects.put( idValue, value );
+
+        return idValue;
+    }
+
+    /**
+     * We do not enerate any SAX events
+     *
+     * @param contentHandler The contentHandler
+     * @param locale The locale
+     *
+     * @throws SAXException Just in case of failure that could never happen
+     */
+    public void generateSaxFragment( final ContentHandler contentHandler,
+                                     final Locale locale )
+        throws SAXException
+    {
+        // intentionally empty
+    }
+}

Added: 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertorBuilder.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertorBuilder.java?view=auto&rev=158837
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertorBuilder.java
 (added)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertorBuilder.java
 Wed Mar 23 13:52:41 2005
@@ -0,0 +1,79 @@
+/*
+ * 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.datatype.convertor;
+
+import org.apache.cocoon.forms.Constants;
+import org.apache.cocoon.forms.util.DomHelper;
+
+import org.w3c.dom.Element;
+
+
+/**
+ * Creates [EMAIL PROTECTED] BeanConvertor}s
+ * 
+ * <p>
+ * The optional &lt;fd:bean&gt;FQCN&lt;/fd:bean&gt; attribute is used to give 
+ * this convertor a hint of which concrete bean class we are going to work 
with.
+ * If this attribute is not specified java.lang.Object is used.
+ * <p>
+ * Sometimes the toString() method doesn't give a good representation of a
+ * Java Bean suited for selection list IDs. For this an optional  
+ * &lt;fd:id-path&gt;jx-path&lt;/fd:id-path&gt; attribute can be specified to 
+ * have this convertor to use a different string representation.
+ * </p>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
+ * @version $Id: BeanConvertorBuilder.java,v 1.2 2004/12/27 13:30:48 giacomo 
Exp $
+ */
+public class BeanConvertorBuilder
+    implements ConvertorBuilder
+{
+    //~ Methods 
----------------------------------------------------------------
+
+    /**
+     * Build a [EMAIL PROTECTED] BeanConvertor}
+     *
+     * @param configElement The configuration element
+     *
+     * @return An initialized [EMAIL PROTECTED] Convertor}
+     *
+     * @throws Exception In case of failure
+     */
+    public Convertor build( final Element configElement )
+        throws Exception
+    {
+        if( configElement == null )
+        {
+            return null;
+        }
+
+        final Element beanEl =
+            DomHelper.getChildElement( configElement, Constants.DEFINITION_NS,
+                                       "bean", false );
+        final String clazz =
+            ( ( beanEl == null ) ? Object.class.getName(  )
+              : beanEl.getFirstChild(  ).getNodeValue(  ) );
+        final Element idPathEl =
+            DomHelper.getChildElement( configElement, Constants.DEFINITION_NS,
+                                       "id-path", false );
+        final String idPath =
+            ( ( idPathEl != null )
+              ? idPathEl.getFirstChild(  ).getNodeValue(  ) : null );
+        final BeanConvertor convertor = new BeanConvertor( clazz, idPath );
+
+        return convertor;
+    }
+}

Added: 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl/BeanType.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl/BeanType.java?view=auto&rev=158837
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl/BeanType.java
 (added)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl/BeanType.java
 Wed Mar 23 13:52:41 2005
@@ -0,0 +1,75 @@
+/*
+ * 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.datatype.typeimpl;
+
+import org.apache.cocoon.forms.datatype.convertor.Convertor;
+
+
+/**
+ * The CForm type of a bean
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
+ * @version $Id: BeanType.java,v 1.1 2004/12/21 14:37:32 giacomo Exp $
+ */
+public class BeanType
+    extends AbstractDatatype
+{
+    //~ Constructors 
-----------------------------------------------------------
+
+    /**
+     * Creates a new BeanType object.
+     *
+     * @param arrayType whether it's an array or not
+     * @param builder The [EMAIL PROTECTED] BeanTypeBuilder}
+     */
+    public BeanType( final boolean arrayType,
+                     final BeanTypeBuilder builder )
+    {
+        super(  );
+        setArrayType( arrayType );
+        setBuilder( builder );
+    }
+
+    //~ Methods 
----------------------------------------------------------------
+
+    /**
+     * @see org.apache.cocoon.forms.datatype.Datatype#getDescriptiveName()
+     */
+    public String getDescriptiveName(  )
+    {
+        final Class c1 = this.getConvertor(  ).getTypeClass(  );
+
+        return this.getConvertor(  ).getTypeClass(  ).getName(  );
+    }
+
+    /**
+     * We make sure the plain Convertor is the same
+     *
+     * @return The convertor
+     */
+    public Convertor getPlainConvertor(  )
+    {
+        return getConvertor(  );
+    }
+
+    /**
+     * @see org.apache.cocoon.forms.datatype.Datatype#getTypeClass()
+     */
+    public Class getTypeClass(  )
+    {
+        return this.getConvertor(  ).getTypeClass(  );
+    }
+}

Added: 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl/BeanTypeBuilder.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl/BeanTypeBuilder.java?view=auto&rev=158837
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl/BeanTypeBuilder.java
 (added)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl/BeanTypeBuilder.java
 Wed Mar 23 13:52:41 2005
@@ -0,0 +1,49 @@
+/*
+ * 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.datatype.typeimpl;
+
+import org.apache.cocoon.forms.datatype.Datatype;
+import org.apache.cocoon.forms.datatype.DatatypeManager;
+
+import org.w3c.dom.Element;
+
+
+/**
+ * Builder for [EMAIL PROTECTED] BeanType}
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
+ * @version $Id: BeanTypeBuilder.java,v 1.1 2004/12/21 14:37:32 giacomo Exp $
+ */
+public class BeanTypeBuilder
+    extends AbstractDatatypeBuilder
+{
+    //~ Methods 
----------------------------------------------------------------
+
+    /**
+     * @see 
org.apache.cocoon.forms.datatype.DatatypeBuilder#build(org.w3c.dom.Element,
+     *      boolean, org.apache.cocoon.forms.datatype.DatatypeManager)
+     */
+    public Datatype build( final Element datatypeElement,
+                           final boolean arrayType,
+                           final DatatypeManager datatypeManager )
+        throws Exception
+    {
+        final BeanType type = new BeanType( arrayType, this );
+        buildValidationRules( datatypeElement, type, datatypeManager );
+        buildConvertor( datatypeElement, type );
+        return type;
+    }
+}


Reply via email to