cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject svn commit: r157546 - in cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype: AbstractJavaSelectionList.java JavaSelectionList.java JavaSelectionListBuilder.java StaticSelectionList.java
Date Tue, 15 Mar 2005 14:52:14 GMT
Author: tim
Date: Tue Mar 15 06:52:12 2005
New Revision: 157546

URL: http://svn.apache.org/viewcvs?view=rev&rev=157546
Log:
Sync with trunk.

Modified:
    cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/AbstractJavaSelectionList.java
    cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/JavaSelectionList.java
    cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/JavaSelectionListBuilder.java
    cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/StaticSelectionList.java

Modified: cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/AbstractJavaSelectionList.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/AbstractJavaSelectionList.java?view=diff&r1=157545&r2=157546
==============================================================================
--- cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/AbstractJavaSelectionList.java
(original)
+++ cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/AbstractJavaSelectionList.java
Tue Mar 15 06:52:12 2005
@@ -1,12 +1,12 @@
 /*
  * 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.
@@ -31,26 +31,31 @@
 import org.apache.cocoon.xml.XMLUtils;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
+import org.apache.excalibur.xml.sax.XMLizable;
 
 /**
  * Abstract implementation of a JavaSelectionList
  */
 public abstract class AbstractJavaSelectionList implements JavaSelectionList,
-        Serviceable {
+                                                           Serviceable {
 
     protected Datatype datatype;
     protected ServiceManager manager;
 
     private HashMap attributes;
-    private List items = new ArrayList();
+    private List items;
     private boolean nullable;
-    private boolean rebuild = true;
+    private boolean rebuild;
+
+    public AbstractJavaSelectionList() {
+        this.items = new ArrayList();
+        this.rebuild = true;
+    }
+
+    public void service(ServiceManager manager) throws ServiceException {
+        this.manager = manager;
+    }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.cocoon.forms.datatype.JavaSelectionList#getAttribute(java.lang.String)
-     */
     public String getAttribute(String name) {
         if (this.attributes == null) {
             return null;
@@ -58,72 +63,31 @@
         return (String) this.attributes.get(name);
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.cocoon.forms.datatype.JavaSelectionList#removeAttribute(java.lang.String)
-     */
     public void removeAttribute(String name) {
         if (this.attributes != null) {
             this.attributes.remove(name);
         }
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.cocoon.forms.datatype.JavaSelectionList#setAttribute(java.lang.String,
-     *      java.lang.String)
-     */
     public void setAttribute(String name, String value) {
         if (this.attributes == null) {
             this.attributes = new HashMap();
         }
         this.attributes.put(name, value);
-
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
-     */
-    public void service(ServiceManager manager) throws ServiceException {
-        this.manager = manager;
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.cocoon.forms.datatype.JavaSelectionList#isNullable()
-     */
     public boolean isNullable() {
         return this.nullable;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.cocoon.forms.datatype.JavaSelectionList#setDatatype(org.apache.cocoon.forms.datatype.Datatype)
-     */
     public void setDatatype(Datatype datatype) {
         this.datatype = datatype;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.cocoon.forms.datatype.JavaSelectionList#setNullable(boolean)
-     */
     public void setNullable(boolean nullable) {
         this.nullable = nullable;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.cocoon.forms.datatype.SelectionList#getDatatype()
-     */
     public Datatype getDatatype() {
         return this.datatype;
     }
@@ -136,33 +100,33 @@
     }
 
     public void generateSaxFragment(ContentHandler contentHandler, Locale locale)
-            throws SAXException {
-        if (this.rebuild)
+    throws SAXException {
+        if (this.rebuild) {
             try {
                 this.items.clear();
-                this.rebuild = this.build();
+                this.rebuild = build();
             } catch (Exception e) {
                 e.printStackTrace();
             }
+        }
+
         Convertor.FormatCache formatCache = new DefaultFormatCache();
-        contentHandler.startElement(Constants.INSTANCE_NS, SELECTION_LIST_EL,
-                Constants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL,
-                XMLUtils.EMPTY_ATTRIBUTES);
-        if (nullable) {
+        contentHandler.startElement(Constants.INSTANCE_NS, SELECTION_LIST_EL, Constants.INSTANCE_PREFIX_COLON
+ SELECTION_LIST_EL, XMLUtils.EMPTY_ATTRIBUTES);
+
+        if (this.nullable) {
             AttributesImpl voidAttrs = new AttributesImpl();
             voidAttrs.addCDATAAttribute("value", "");
-            contentHandler.startElement(Constants.INSTANCE_NS, ITEM_EL,
-                    Constants.INSTANCE_PREFIX_COLON + ITEM_EL, voidAttrs);
-            contentHandler.endElement(Constants.INSTANCE_NS, ITEM_EL,
-                    Constants.INSTANCE_PREFIX_COLON + ITEM_EL);
+            contentHandler.startElement(Constants.INSTANCE_NS, ITEM_EL, Constants.INSTANCE_PREFIX_COLON
+ ITEM_EL, voidAttrs);
+            contentHandler.endElement(Constants.INSTANCE_NS, ITEM_EL, Constants.INSTANCE_PREFIX_COLON
+ ITEM_EL);
         }
+
         Iterator itemIt = items.iterator();
         while (itemIt.hasNext()) {
             SelectionListItem item = (SelectionListItem) itemIt.next();
             item.generateSaxFragment(contentHandler, locale, formatCache);
         }
-        contentHandler.endElement(Constants.INSTANCE_NS, SELECTION_LIST_EL,
-                Constants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL);
+
+        contentHandler.endElement(Constants.INSTANCE_NS, SELECTION_LIST_EL, Constants.INSTANCE_PREFIX_COLON
+ SELECTION_LIST_EL);
     }
 
     /**
@@ -174,7 +138,20 @@
 
     /**
      * Adds a new item to this selection list.
-     * 
+     *
+     * @param value
+     *            a value of the correct type (i.e. the type with which this
+     *            selectionlist is associated)
+     * @param label
+     *            string label, can be null.
+     */
+    protected void addItem(Object value, String label) {
+        this.items.add(new SelectionListItem(value, label));
+    }
+
+    /**
+     * Adds a new item to this selection list.
+     *
      * @param value
      *            a value of the correct type (i.e. the type with which this
      *            selectionlist is associated)
@@ -182,57 +159,57 @@
      *            a SAX-fragment such as a
      *            {@link org.apache.cocoon.xml.SaxBuffer}, can be null
      */
-    protected void addItem(Object value, String label) {
-        items.add(new SelectionListItem(value, label));
+    protected void addItem(Object value, XMLizable label) {
+        this.items.add(new SelectionListItem(value, label));
     }
 
     protected List getItems() {
-        return items;
+        return this.items;
     }
 
     private final class SelectionListItem {
         private final Object value;
 
-        private final String label;
+        private final Object label;
 
         public SelectionListItem(Object value, String label) {
             this.value = value;
             this.label = label;
         }
 
+        public SelectionListItem(Object value, XMLizable label) {
+            this.value = value;
+            this.label = label;
+        }
+
         public Object getValue() {
             return value;
         }
 
         public void generateSaxFragment(ContentHandler contentHandler,
-                Locale locale, Convertor.FormatCache formatCache)
-                throws SAXException {
-            AttributesImpl itemAttrs = new AttributesImpl();
+                                        Locale locale, Convertor.FormatCache formatCache)
+        throws SAXException {
             String stringValue;
             if (this.value == null) {
                 stringValue = "";
             } else {
-                stringValue = datatype.getConvertor().convertToString(value,
-                        locale, formatCache);
+                stringValue = datatype.getConvertor().convertToString(this.value, locale,
formatCache);
             }
-            itemAttrs.addCDATAAttribute("value", stringValue);
-            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);
-            if (label == null) {
-                contentHandler.characters(stringValue.toCharArray(), 0,
-                        stringValue.length());
+
+            AttributesImpl attrs = new AttributesImpl();
+            attrs.addCDATAAttribute("value", stringValue);
+            contentHandler.startElement(Constants.INSTANCE_NS, ITEM_EL, Constants.INSTANCE_PREFIX_COLON
+ ITEM_EL, attrs);
+            contentHandler.startElement(Constants.INSTANCE_NS, LABEL_EL, Constants.INSTANCE_PREFIX_COLON
+ LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES);
+            if (this.label == null) {
+                contentHandler.characters(stringValue.toCharArray(), 0, stringValue.length());
+            } else if (this.label instanceof XMLizable) {
+                ((XMLizable) this.label).toSAX(contentHandler);
             } else {
-                contentHandler.characters(label.toCharArray(), 0, label
-                        .length());
+                String stringLabel = (String) this.label;
+                contentHandler.characters(stringLabel.toCharArray(), 0, stringLabel.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);
+            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/whiteboard/forms/java/org/apache/cocoon/forms/datatype/JavaSelectionList.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/JavaSelectionList.java?view=diff&r1=157545&r2=157546
==============================================================================
--- cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/JavaSelectionList.java (original)
+++ cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/JavaSelectionList.java Tue
Mar 15 06:52:12 2005
@@ -1,12 +1,12 @@
 /*
  * 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.
@@ -17,20 +17,19 @@
 
 /**
  * A selection list that takes its values from the custom java class itself.
- *
- *  
+ * @version $Id$
  */
-public interface JavaSelectionList extends SelectionList{
-	
+public interface JavaSelectionList extends SelectionList {
+
 	void setDatatype(Datatype datatype);
-	
+
 	boolean isNullable();
-	
+
 	void setNullable(boolean nullable);
-	
+
 	String getAttribute(String name);
-	
+
 	void setAttribute(String name, String value);
-	
+
 	void removeAttribute(String name);
 }

Modified: cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/JavaSelectionListBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/JavaSelectionListBuilder.java?view=diff&r1=157545&r2=157546
==============================================================================
--- cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/JavaSelectionListBuilder.java
(original)
+++ cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/JavaSelectionListBuilder.java
Tue Mar 15 06:52:12 2005
@@ -1,12 +1,12 @@
 /*
  * 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.
@@ -19,6 +19,12 @@
 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.context.Contextualizable;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.avalon.framework.component.Component;
+
 import org.apache.cocoon.components.LifecycleHelper;
 import org.apache.cocoon.forms.util.DomHelper;
 import org.w3c.dom.Element;
@@ -27,67 +33,63 @@
 
 /**
  * Builds {@link SelectionList}s from a JavaSelectionList class
- * 
- *  
+ *
+ * @version $Id$
  */
-public class JavaSelectionListBuilder extends AbstractLogEnabled implements
-		SelectionListBuilder, Serviceable {
-
+public class JavaSelectionListBuilder extends AbstractLogEnabled
+                                      implements SelectionListBuilder,
+                                                 Contextualizable, Serviceable, ThreadSafe,
Component {
+
+    /**
+     * The Avalon Context
+     */
+    private Context context;
+
+    /**
+     * The Service Manager
+     */
 	private ServiceManager manager;
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.cocoon.forms.datatype.SelectionListBuilder#build(org.w3c.dom.Element,
-	 *      org.apache.cocoon.forms.datatype.Datatype)
-	 */
+    public void contextualize(Context context) throws ContextException {
+        this.context = context;
+    }
+
+    public void service(ServiceManager manager) throws ServiceException {
+        this.manager = manager;
+    }
+
 	public SelectionList build(Element selectionListElement, Datatype datatype)
-			throws Exception {
-		String className = DomHelper
-				.getAttribute(selectionListElement, "class");
-		boolean nullable = DomHelper.getAttributeAsBoolean(
-				selectionListElement, "nullable", true);
+    throws Exception {
+		String className = DomHelper.getAttribute(selectionListElement, "class");
+		boolean nullable = DomHelper.getAttributeAsBoolean(selectionListElement, "nullable", true);
 
 		try {
 			Class clasz = Class.forName(className);
 			if (JavaSelectionList.class.isAssignableFrom(clasz)) {
-				JavaSelectionList list = (JavaSelectionList) clasz
-						.newInstance();
-				LifecycleHelper.setupComponent(list, getLogger(), null,
-						this.manager, null, true);
+				JavaSelectionList list = (JavaSelectionList) clasz.newInstance();
+				LifecycleHelper.setupComponent(list, getLogger(), this.context, this.manager, null, true);
 				list.setDatatype(datatype);
 				list.setNullable(nullable);
+
                 // pass the attributes to the SelectionList
 				NamedNodeMap attrs = selectionListElement.getAttributes();
-				int size = attrs.getLength();
+				final int size = attrs.getLength();
 				for (int i = 0; i < size; i++) {
-					Node attr = attrs.item(i);
-					String name = attr.getNodeName();
+					final Node attr = attrs.item(i);
+					final String name = attr.getNodeName();
 					list.setAttribute(name, attr.getNodeValue());
 				}
+
 				return list;
 			} else {
+                getLogger().warn("Class " + className + " does not implement JavaSelectionList,
returning empty selection list.");
 				return new StaticSelectionList(datatype);
 			}
-		} catch (ClassNotFoundException e) {
-			e.printStackTrace();
-			throw e;
-		} catch (InstantiationException e) {
-			e.printStackTrace();
-			throw e;
-		} catch (IllegalAccessException e) {
-			e.printStackTrace();
+		} catch (Exception e) {
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Got exception in build, re-throwing", e);
+            }
 			throw e;
 		}
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
-	 */
-	public void service(ServiceManager manager) throws ServiceException {
-		this.manager = manager;
-
 	}
 }

Modified: cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/StaticSelectionList.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/StaticSelectionList.java?view=diff&r1=157545&r2=157546
==============================================================================
--- cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/StaticSelectionList.java
(original)
+++ cocoon/whiteboard/forms/java/org/apache/cocoon/forms/datatype/StaticSelectionList.java
Tue Mar 15 06:52:12 2005
@@ -1,12 +1,12 @@
 /*
  * 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.
@@ -35,16 +35,23 @@
  * the items in the list are build once from its source, and then list items are
  * cached as part of this object. In contrast, the {@link DynamicSelectionList}
  * will retrieve its content from its source each time it's needed.
- * 
+ *
  * @version $Id$
  */
 public class StaticSelectionList implements SelectionList {
-    /** The datatype to which this selection list belongs */
+    /**
+     * The datatype to which this selection list belongs
+     */
     private Datatype datatype;
-    private List items = new ArrayList();
+
+    /**
+     * List of SelectionListItems
+     */
+    private List items;
 
     public StaticSelectionList(Datatype datatype) {
         this.datatype = datatype;
+        this.items = new ArrayList();
     }
 
     public Datatype getDatatype() {
@@ -54,16 +61,18 @@
     public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws
SAXException {
         Convertor.FormatCache formatCache = new DefaultFormatCache();
         contentHandler.startElement(Constants.INSTANCE_NS, SELECTION_LIST_EL, Constants.INSTANCE_PREFIX_COLON
+ SELECTION_LIST_EL, XMLUtils.EMPTY_ATTRIBUTES);
-        Iterator itemIt = items.iterator();
+
+        Iterator itemIt = this.items.iterator();
         while (itemIt.hasNext()) {
-            SelectionListItem item = (SelectionListItem)itemIt.next();
+            final SelectionListItem item = (SelectionListItem) itemIt.next();
             item.generateSaxFragment(contentHandler, locale, formatCache);
         }
+
         contentHandler.endElement(Constants.INSTANCE_NS, SELECTION_LIST_EL, Constants.INSTANCE_PREFIX_COLON
+ SELECTION_LIST_EL);
     }
 
     public List getItems() {
-        return items;
+        return this.items;
     }
 
     /**
@@ -72,7 +81,7 @@
      * @param label a SAX-fragment such as a {@link org.apache.cocoon.xml.SaxBuffer}, can
be null
      */
     public void addItem(Object value, XMLizable label) {
-        items.add(new SelectionListItem(value, label));
+        this.items.add(new SelectionListItem(value, label));
     }
 
     public final class SelectionListItem {
@@ -89,21 +98,21 @@
         }
 
         public void generateSaxFragment(ContentHandler contentHandler, Locale locale, Convertor.FormatCache
formatCache)
-                throws SAXException
-        {
-            AttributesImpl itemAttrs = new AttributesImpl();
+        throws SAXException {
             String stringValue;
             if (this.value == null) {
                 // Null value translates into the empty string
                 stringValue = "";
             } else {
-                stringValue = datatype.getConvertor().convertToString(value, locale, formatCache);
+                stringValue = datatype.getConvertor().convertToString(this.value, locale,
formatCache);
             }
-            itemAttrs.addCDATAAttribute("value", stringValue);
-            contentHandler.startElement(Constants.INSTANCE_NS, ITEM_EL, Constants.INSTANCE_PREFIX_COLON
+ ITEM_EL, itemAttrs);
+
+            AttributesImpl attrs = new AttributesImpl();
+            attrs.addCDATAAttribute("value", stringValue);
+            contentHandler.startElement(Constants.INSTANCE_NS, ITEM_EL, Constants.INSTANCE_PREFIX_COLON
+ ITEM_EL, attrs);
             contentHandler.startElement(Constants.INSTANCE_NS, LABEL_EL, Constants.INSTANCE_PREFIX_COLON
+ LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES);
-            if (label != null) {
-                label.toSAX(contentHandler);
+            if (this.label != null) {
+                this.label.toSAX(contentHandler);
             } else {
                 contentHandler.characters(stringValue.toCharArray(), 0, stringValue.length());
             }



Mime
View raw message