[seam-commits] Seam SVN: r10276 - trunk/src/debug/com/sun/facelets.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Apr 2 14:01:34 EDT 2009


Author: norman.richards at jboss.com
Date: 2009-04-02 14:01:34 -0400 (Thu, 02 Apr 2009)
New Revision: 10276

Modified:
   trunk/src/debug/com/sun/facelets/StateWriterControl.java
Log:
JBSEAM-4070

Modified: trunk/src/debug/com/sun/facelets/StateWriterControl.java
===================================================================
--- trunk/src/debug/com/sun/facelets/StateWriterControl.java	2009-04-02 16:29:36 UTC (rev 10275)
+++ trunk/src/debug/com/sun/facelets/StateWriterControl.java	2009-04-02 18:01:34 UTC (rev 10276)
@@ -1,6 +1,7 @@
 package com.sun.facelets;
 
 import java.io.Writer;
+import java.lang.reflect.*;
 
 import javax.faces.context.ResponseWriter;
 
@@ -11,26 +12,80 @@
  * since we are not calling Facelets in the normal way (and hence it is not
  * completely initialized).
  */
-public class StateWriterControl
-{
-   public static void initialize(Writer writer)
-   {
-      new StateWriter(writer, 1024);
-   }
-   
-   public static ResponseWriter createClone(ResponseWriter writer) {
-      return writer.cloneWithWriter(StateWriter.getCurrentInstance());
-   }
-   
-   public static boolean isStateWritten() {
-      return StateWriter.getCurrentInstance().isStateWritten();
-   }
-   
-   public static String getAndResetBuffer() {
-      return StateWriter.getCurrentInstance().getAndResetBuffer();
-   }
-   
-   public static void release() {
-      StateWriter.getCurrentInstance().release();
-   }
+public class StateWriterControl {
+    final static String STATEWRITER_CLASS_NAME = "com.sun.facelets.StateWriter";
+
+    static Class getStateWriter() {
+        try {
+            return Class.forName(STATEWRITER_CLASS_NAME);
+        } catch (Exception e) {
+            throw new RuntimeException("Could not load class com.sun.facelets.StateWriter using reflection", e);
+        }
+    }
+
+    public static void initialize(Writer writer) {
+        try {
+            Class sw = getStateWriter();
+            Constructor constructor = sw.getConstructor(Writer.class, int.class);
+            constructor.setAccessible(true);
+            constructor.newInstance(writer, 1024);
+        } catch (Exception e) {
+            throw new RuntimeException("Could not initilise com.sun.facelets.StateWriter using reflection", e);
+        }
+    }
+
+    public static ResponseWriter createClone(ResponseWriter writer) {
+        try {
+            Class sw = getStateWriter();
+            Method meth = sw.getMethod("getCurrentInstance");
+            meth.setAccessible(true);
+            Writer w = (Writer) meth.invoke(null);
+            return writer.cloneWithWriter(w);
+        } catch (Exception e) {
+            throw new RuntimeException("Could not create clone of com.sun.facelets.StateWriter using reflection", e);
+        }
+    }
+
+    public static boolean isStateWritten() {
+        try {
+            Class sw = getStateWriter();
+            Method meth = sw.getMethod("getCurrentInstance");
+            meth.setAccessible(true);
+            Object o = meth.invoke(null);
+            Method instMeth = sw.getMethod("isStateWritten");
+            instMeth.setAccessible(true);
+            return (Boolean) instMeth.invoke(o);
+        } catch (Exception e) {
+            throw new RuntimeException("Could not call isStateWritten on com.sun.facelets.StateWriter using reflection", e);
+        }
+    }
+
+    public static String getAndResetBuffer() {
+        try {
+            Class sw = getStateWriter();
+            Method meth = sw.getMethod("getCurrentInstance");
+            meth.setAccessible(true);
+            Object o = meth.invoke(null);
+            Method instMeth = sw.getMethod("getAndResetBuffer");
+            instMeth.setAccessible(true);
+            return (String) instMeth.invoke(o);
+        } catch (Exception e) {
+            throw new RuntimeException("Could not call getAndResetBuffer on com.sun.facelets.StateWriter using reflection", e);
+        }
+    }
+
+    public static void release() {
+        try {
+            Class sw = getStateWriter();
+            Method meth = sw.getMethod("getCurrentInstance");
+            meth.setAccessible(true);
+            Object o = meth.invoke(null);
+            Method instMeth = sw.getMethod("release");
+            instMeth.setAccessible(true);
+            instMeth.invoke(o);
+        } catch (Exception e) {
+            throw new RuntimeException("Could not call release on com.sun.facelets.StateWriter using reflection",e);
+        }
+    }
+
 }




More information about the seam-commits mailing list