[seam-commits] Seam SVN: r10690 - in modules/trunk/faces/src/main/java/org/jboss/seam/faces: annotations and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Apr 28 23:35:22 EDT 2009


Author: shane.bryzak at jboss.com
Date: 2009-04-28 23:35:21 -0400 (Tue, 28 Apr 2009)
New Revision: 10690

Added:
   modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataBinderClass.java
   modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataModel.java
   modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataModelSelection.java
   modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataModelSelectionIndex.java
   modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataSelectorClass.java
   modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/
   modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataBinder.java
   modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataModelBinder.java
   modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataModelIndexSelector.java
   modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataModelSelector.java
   modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataSelector.java
Log:
add datamodel stuff

Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataBinderClass.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataBinderClass.java	                        (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataBinderClass.java	2009-04-29 03:35:21 UTC (rev 10690)
@@ -0,0 +1,27 @@
+package org.jboss.seam.faces.annotations;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.jboss.seam.faces.databinding.DataBinder;
+
+/**
+ * Meta-annotation that specifies that an annotation
+ * is a databinding annotation, ie. that it results
+ * in outjection of a wrapped representation of the
+ * annotated component attribute value.
+ * 
+ * @see org.jboss.seam.databinding.DataBinder
+ * @author Gavin King
+ */
+ at Target(ANNOTATION_TYPE)
+ at Retention(RUNTIME)
+ at Documented
+public @interface DataBinderClass
+{
+   Class<? extends DataBinder> value();
+}

Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataModel.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataModel.java	                        (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataModel.java	2009-04-29 03:35:21 UTC (rev 10690)
@@ -0,0 +1,57 @@
+//$Id: DataModel.java 2169 2006-10-10 03:48:19Z gavin $
+package org.jboss.seam.faces.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import javax.context.ScopeType;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.jboss.seam.faces.annotations.DataBinderClass;
+import org.jboss.seam.faces.databinding.DataModelBinder;
+
+/**
+ * Outjects a collection to the same scope as the owning component
+ * (or to the EVENT scope in the case of a stateless component),
+ * after wrapping as a JSF DataModel (a List as a ListDataModel, a
+ * Map as a MapDataModel, a Set as a SetDataModel, an array as an 
+ * ArrayDataModel). Note that the List, Map, Set or array
+ * will be re-wrapped and re-outjected each time the current
+ * component value is different to the value held by the
+ * context variable as determined by calling equals() on the 
+ * underlying collection.
+ * 
+ * @author Gavin King
+ * 
+ * @see org.jboss.seam.jsf.ListDataModel
+ * @see org.jboss.seam.jsf.MapDataModel
+ * @see org.jboss.seam.jsf.SetDataModel
+ * @see org.jboss.seam.jsf.ArrayDataModel
+ */
+ at Target({FIELD, METHOD})
+ at Retention(RUNTIME)
+ at Documented
+ at DataBinderClass(DataModelBinder.class)
+public @interface DataModel
+{
+   /**
+    * The context variable name. Defaults to the name of 
+    * the annotated field or getter method.
+    */
+   String value() default "";
+   
+   /**
+    * Specifies the scope to outject the DataModel to. 
+    * If no scope is explicitly specified, the scope of 
+    * the component with the @DataModel attribute is used. 
+    * But if the component scope is STATELESS, the EVENT 
+    * scope is used.
+    * 
+    */
+   Class<? extends Annotation> scope();
+}

Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataModelSelection.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataModelSelection.java	                        (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataModelSelection.java	2009-04-29 03:35:21 UTC (rev 10690)
@@ -0,0 +1,33 @@
+//$Id: DataModelSelection.java 2025 2006-09-18 16:43:02Z gavin $
+package org.jboss.seam.faces.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.jboss.seam.faces.databinding.DataModelSelector;
+
+/**
+ * Injects the selected row data of a DataModel. 
+ * Intended for use with @DataModel.
+ * 
+ * @author Gavin King
+ * @see DataModel
+ */
+ at Target({FIELD, METHOD})
+ at Retention(RUNTIME)
+ at Documented
+ at DataSelectorClass(DataModelSelector.class)
+public @interface DataModelSelection
+{
+   /**
+    * The context variable name of the DataModel. Defaults 
+    * to the name for the outjected @DataModel if there
+    * is exactly one @DataModel for the component.
+    */
+   String value() default "";
+}

Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataModelSelectionIndex.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataModelSelectionIndex.java	                        (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataModelSelectionIndex.java	2009-04-29 03:35:21 UTC (rev 10690)
@@ -0,0 +1,34 @@
+//$Id: DataModelSelectionIndex.java 2025 2006-09-18 16:43:02Z gavin $
+package org.jboss.seam.faces.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.jboss.seam.faces.databinding.DataModelIndexSelector;
+
+/**
+ * Injects the selected row index of a ListDataModel,
+ * MapDataModel or ArrayDataModel. Intended for use 
+ * with @DataModel.
+ * 
+ * @author Gavin King
+ * @see DataModel
+ */
+ at Target({FIELD, METHOD})
+ at Retention(RUNTIME)
+ at Documented
+ at DataSelectorClass(DataModelIndexSelector.class)
+public @interface DataModelSelectionIndex
+{
+   /**
+    * The context variable name of the DataModel. Defaults 
+    * to the name for the outjected @DataModel if there
+    * is exactly one @DataModel for the component.
+    */
+   String value() default "";
+}

Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataSelectorClass.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataSelectorClass.java	                        (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/annotations/DataSelectorClass.java	2009-04-29 03:35:21 UTC (rev 10690)
@@ -0,0 +1,27 @@
+package org.jboss.seam.faces.annotations;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.jboss.seam.faces.databinding.DataSelector;
+
+/**
+ * Meta-annotation that specifies that an annotation
+ * is a dataselection annotation, ie. that it results
+ * in injection of the selected item of some databound
+ * data.
+ * 
+ * @see org.jboss.seam.databinding.DataSelector
+ * @author Gavin King
+ */
+ at Target(ANNOTATION_TYPE)
+ at Retention(RUNTIME)
+ at Documented
+public @interface DataSelectorClass
+{
+   Class<? extends DataSelector> value();
+}

Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataBinder.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataBinder.java	                        (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataBinder.java	2009-04-29 03:35:21 UTC (rev 10690)
@@ -0,0 +1,23 @@
+package org.jboss.seam.faces.databinding;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * Allows some "bound type" to be exposed to 
+ * the user interface via a "wrapper type".
+ * 
+ * @author Gavin King
+ *
+ * @param <Out> the annotation type
+ * @param <Type> the bound type
+ * @param <WrapperType> the wrapper type
+ */
+public interface DataBinder<Out extends Annotation, Type, WrapperType>
+{
+   String getVariableName(Out out);
+   Class<? extends Annotation> getVariableScope(Out out);
+   WrapperType wrap(Out out, Type value);
+   Type getWrappedData(Out out, WrapperType wrapper);
+   Object getSelection(Out out, WrapperType wrapper);
+   boolean isDirty(Out out, WrapperType wrapper, Type value);
+}

Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataModelBinder.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataModelBinder.java	                        (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataModelBinder.java	2009-04-29 03:35:21 UTC (rev 10690)
@@ -0,0 +1,66 @@
+package org.jboss.seam.faces.databinding;
+
+import java.lang.annotation.Annotation;
+import java.util.Map;
+
+import javax.inject.Current;
+
+import org.jboss.seam.faces.annotations.DataModel;
+import org.jboss.seam.faces.DataModels;
+
+/**
+ * Exposes a List, array, Map or Set to the UI as a JSF DataModel
+ * 
+ * @author Gavin King
+ */
+public class DataModelBinder implements DataBinder<DataModel, Object, javax.faces.model.DataModel>
+{
+   @Current DataModels dataModels;
+   
+   public String getVariableName(DataModel out)
+   {
+      return out.value();
+   }
+
+   public Class<? extends Annotation> getVariableScope(DataModel out)
+   {
+      return out.scope();
+   }
+
+   public javax.faces.model.DataModel wrap(DataModel out, Object value)
+   {
+      return dataModels.getDataModel(value);
+   }
+
+   public Object getWrappedData(DataModel out, javax.faces.model.DataModel wrapper)
+   {
+      return wrapper.getWrappedData();
+   }
+
+   public Object getSelection(DataModel out, javax.faces.model.DataModel wrapper)
+   {
+      if ( wrapper.getRowCount()==0 || wrapper.getRowIndex()<0 || 
+           wrapper.getRowIndex()>=wrapper.getRowCount())
+      {
+         return null;
+      } 
+      else
+      {
+         Object rowData = wrapper.getRowData();
+         if (rowData instanceof Map.Entry)
+         {
+            return ( (Map.Entry) rowData ).getValue();
+         }
+         else
+         {
+            return rowData;
+         }
+      }
+   }
+
+   public boolean isDirty(DataModel out, javax.faces.model.DataModel wrapper, Object value)
+   {
+      return !getWrappedData(out, wrapper).equals(value);
+   }
+   
+}

Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataModelIndexSelector.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataModelIndexSelector.java	                        (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataModelIndexSelector.java	2009-04-29 03:35:21 UTC (rev 10690)
@@ -0,0 +1,42 @@
+package org.jboss.seam.faces.databinding;
+
+import java.util.Map;
+
+import javax.faces.model.DataModel;
+
+import org.jboss.seam.faces.annotations.DataModelSelectionIndex;
+
+/**
+ * Extracts the selected "index" (the row index, or the key of a map) from a JSF DataModel.
+ * 
+ * @author Gavin King
+ */
+public class DataModelIndexSelector implements DataSelector<DataModelSelectionIndex, DataModel>
+{
+
+   public String getVariableName(DataModelSelectionIndex in)
+   {
+      return in.value();
+   }
+
+   public Object getSelection(DataModelSelectionIndex in, DataModel wrapper)
+   {
+      if ( wrapper.getRowCount()==0 || wrapper.getRowIndex()<0 )
+      {
+         return null;
+      }
+      else
+      {
+         Object rowData = wrapper.getRowData();
+         if (rowData instanceof Map.Entry)
+         {
+            return ( (Map.Entry) rowData ).getKey();
+         }
+         else
+         {
+            return wrapper.getRowIndex();
+         }
+      }
+   }
+   
+}

Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataModelSelector.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataModelSelector.java	                        (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataModelSelector.java	2009-04-29 03:35:21 UTC (rev 10690)
@@ -0,0 +1,42 @@
+package org.jboss.seam.faces.databinding;
+
+import java.util.Map;
+
+import javax.faces.model.DataModel;
+
+import org.jboss.seam.faces.annotations.DataModelSelection;
+
+/**
+ * Extracts the selected object (the element, or the value of a map) from a JSF DataModel.
+ * 
+ * @author Gavin King
+ */
+public class DataModelSelector implements DataSelector<DataModelSelection, DataModel>
+{
+   
+   public String getVariableName(DataModelSelection in)
+   {
+      return in.value();
+   }
+
+   public Object getSelection(DataModelSelection in, DataModel wrapper)
+   {
+      if ( wrapper.getRowCount()==0 || wrapper.getRowIndex()<0 )
+      {
+         return null;
+      }
+      else
+      {
+         Object rowData = wrapper.getRowData();
+         if (rowData instanceof Map.Entry)
+         {
+            return ( (Map.Entry) rowData ).getValue();
+         }
+         else
+         {
+            return rowData;
+         }
+      }
+   }
+   
+}

Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataSelector.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataSelector.java	                        (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/databinding/DataSelector.java	2009-04-29 03:35:21 UTC (rev 10690)
@@ -0,0 +1,18 @@
+package org.jboss.seam.faces.databinding;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * Allows extraction of the selected item
+ * from some "wrapper type".
+ * 
+ * @author Gavin King
+ *
+ * @param <In> the annotation type
+ * @param <WrapperType> the wrapper type
+ */
+public interface DataSelector<In extends Annotation, WrapperType>
+{
+   String getVariableName(In in);
+   Object getSelection(In in, WrapperType wrapper);
+}




More information about the seam-commits mailing list