labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
Subject svn commit: r793022 - /labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/
Date Fri, 10 Jul 2009 16:30:03 GMT
Author: simoneg
Date: Fri Jul 10 16:30:02 2009
New Revision: 793022

URL: http://svn.apache.org/viewvc?rev=793022&view=rev
Log:
LABS-352 : experimental interfaces for "pieces".

Added:
    labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/
    labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/BasicOutputPiece.java
    labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/BeanAwarePiece.java
    labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/FormAwarePiece.java
    labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/HtmlFormPiece.java
    labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/HtmlOutputPiece.java
    labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/HtmlPieces.java
    labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/NodeAwarePiece.java

Added: labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/BasicOutputPiece.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/BasicOutputPiece.java?rev=793022&view=auto
==============================================================================
--- labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/BasicOutputPiece.java
(added)
+++ labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/BasicOutputPiece.java
Fri Jul 10 16:30:02 2009
@@ -0,0 +1,38 @@
+package org.apache.magma.website.beansview.pieces;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.magma.basics.MagmaException;
+import org.apache.magma.beans.PropertyInfo;
+import org.apache.magma.conversion.Converter;
+import org.apache.magma.conversion.Converters;
+import org.apache.magma.i18n.Formatter;
+import org.apache.magma.i18n.Formatters;
+
+public abstract class BasicOutputPiece implements HtmlOutputPiece<Object>, BeanAwarePiece
{ 
+
+	public void output(Object value, Writer output) {
+		try {
+			PropertyInfo property = getProperty();
+			if (property == null) {
+				Formatter formatter = Formatters.getFormatterFor(value.getClass());
+				if (formatter != null) {
+					output.write(formatter.to(value));
+					return;
+				}
+				Converter converter = Converters.getConverterFor(value.getClass());
+				if (converter != null) {
+					output.write(converter.to(value));
+					return;
+				}
+				output.write(value.toString());
+				return;
+			}
+			output.write(property.toUser(value));
+		} catch (IOException e) {
+			throw new MagmaException(e, "Error rendering piece");
+		}
+	}
+
+}

Added: labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/BeanAwarePiece.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/BeanAwarePiece.java?rev=793022&view=auto
==============================================================================
--- labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/BeanAwarePiece.java
(added)
+++ labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/BeanAwarePiece.java
Fri Jul 10 16:30:02 2009
@@ -0,0 +1,36 @@
+package org.apache.magma.website.beansview.pieces;
+
+import org.apache.magma.beans.PropertyInfo;
+import org.apache.magma.view.tree.FieldNode;
+import org.apache.magma.website.beansview.ShowBean;
+
+public interface BeanAwarePiece {
+
+	public Object getBean();
+	public PropertyInfo getProperty();
+	
+	public static aspect BeanAwarePieceImpl {
+		private Object BeanAwarePiece.bean;
+		private PropertyInfo BeanAwarePiece.property;
+		
+		public Object BeanAwarePiece.getBean() {
+			return bean;
+		}
+		
+		public PropertyInfo BeanAwarePiece.getProperty() {
+			return property;
+		}
+	}
+	
+	public static aspect BeanAwarePieceWormHole {
+		after(FieldNode node, ShowBean sb) returning(BeanAwarePiece p) : 
+			execution(public * BeanAwarePiece+.createFor(..)) && 
+			cflow(execution(* ShowBean+.createFieldNodeOutput(FieldNode, ..)) && args(node,
..) && this(sb)) {
+			
+			p.bean = sb.getBean();
+			p.property = node.getProperty();
+		}
+	}
+	
+	
+}

Added: labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/FormAwarePiece.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/FormAwarePiece.java?rev=793022&view=auto
==============================================================================
--- labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/FormAwarePiece.java
(added)
+++ labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/FormAwarePiece.java
Fri Jul 10 16:30:02 2009
@@ -0,0 +1,29 @@
+package org.apache.magma.website.beansview.pieces;
+
+import org.apache.magma.view.tree.FieldNode;
+import org.apache.magma.website.beansview.ShowBean;
+import org.apache.magma.website.beansview.SmartForm;
+
+public interface FormAwarePiece {
+
+	public SmartForm getForm();
+	
+	public static aspect FormAwarePieceImpl {
+		private SmartForm FormAwarePiece.form = null;
+		
+		public SmartForm FormAwarePiece.getForm() {
+			return form;
+		}
+	}
+	
+	public static aspect FormAwarePieceWormHole {
+		after(SmartForm form) returning(FormAwarePiece p) : 
+			execution(public * FormAwarePiece+.createFor(..)) && 
+			cflow(execution(* SmartForm.doShow(..)) && this(form)) {
+			
+			p.form = form;
+			
+		}
+	}
+	
+}

Added: labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/HtmlFormPiece.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/HtmlFormPiece.java?rev=793022&view=auto
==============================================================================
--- labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/HtmlFormPiece.java
(added)
+++ labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/HtmlFormPiece.java
Fri Jul 10 16:30:02 2009
@@ -0,0 +1,16 @@
+package org.apache.magma.website.beansview.pieces;
+
+import java.io.Writer;
+import java.util.Map;
+
+public interface HtmlFormPiece<T> {
+	
+	public boolean handles(Class<?> clazz);
+	
+	public HtmlFormPiece<T> createFor(Class<? extends T> clazz);
+	
+	public void createFormInput(T value, String id, Writer output);
+	
+	public T parse(Map<String, String> binding, String id);
+
+}

Added: labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/HtmlOutputPiece.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/HtmlOutputPiece.java?rev=793022&view=auto
==============================================================================
--- labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/HtmlOutputPiece.java
(added)
+++ labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/HtmlOutputPiece.java
Fri Jul 10 16:30:02 2009
@@ -0,0 +1,13 @@
+package org.apache.magma.website.beansview.pieces;
+
+import java.io.Writer;
+
+public interface HtmlOutputPiece<T> {
+	
+	public boolean outputs(Class<?> clazz);
+	
+	public HtmlOutputPiece<T> createFor(Class<? extends T> clazz);
+	
+	public void output(T value, Writer output);
+	
+}

Added: labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/HtmlPieces.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/HtmlPieces.java?rev=793022&view=auto
==============================================================================
--- labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/HtmlPieces.java
(added)
+++ labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/HtmlPieces.java
Fri Jul 10 16:30:02 2009
@@ -0,0 +1,29 @@
+package org.apache.magma.website.beansview.pieces;
+
+import java.util.Iterator;
+
+import org.apache.magma.basics.services.ServiceFinder;
+import org.apache.magma.conversion.Converter;
+
+public class HtmlPieces {
+
+	public static <T> HtmlOutputPiece<T> outputFor(Class<T> clazz) {
+		Iterator<HtmlOutputPiece> providers = ServiceFinder.findProviders(HtmlOutputPiece.class);
+		while (providers.hasNext()) {
+			HtmlOutputPiece piece = providers.next();
+			if (piece.outputs(clazz)) return piece.createFor(clazz); 
+		}
+		return null;		
+	}
+	
+	public static <T> HtmlFormPiece<T> formFor(Class<T> clazz) {
+		Iterator<HtmlFormPiece> providers = ServiceFinder.findProviders(HtmlFormPiece.class);
+		while (providers.hasNext()) {
+			HtmlFormPiece piece = providers.next();
+			if (piece.handles(clazz)) return piece.createFor(clazz); 
+		}
+		return null;		
+	}
+	
+	
+}

Added: labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/NodeAwarePiece.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/NodeAwarePiece.java?rev=793022&view=auto
==============================================================================
--- labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/NodeAwarePiece.java
(added)
+++ labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/pieces/NodeAwarePiece.java
Fri Jul 10 16:30:02 2009
@@ -0,0 +1,28 @@
+package org.apache.magma.website.beansview.pieces;
+
+import org.apache.magma.view.tree.FieldNode;
+import org.apache.magma.website.beansview.ShowBean;
+
+public interface NodeAwarePiece {
+
+	public FieldNode getFieldNode();
+	
+	public static aspect NodeAwarePieceImpl {
+		private FieldNode NodeAwarePiece.node = null;
+		
+		public FieldNode NodeAwarePiece.getFieldNode() {
+			return node;
+		}
+	}
+	
+	public static aspect NodeAwarePieceWormHole {
+		after(FieldNode node) returning(NodeAwarePiece p) : 
+			execution(public * NodeAwarePiece+.createFor(..)) && 
+			cflow(execution(* ShowBean.createFieldNodeOutput(FieldNode, ..)) && args(node,
..)) {
+			
+			p.node = node;
+			
+		}
+	}
+	
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message