Author: jkuhnert
Date: Sat Mar 11 17:24:19 2006
New Revision: 385231

URL: http://svn.apache.org/viewcvs?rev=385231&view=rev
Log:
Added first draft impl of JSONWriter. 

Added:
    
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/markup/JSONWriterImpl.java
    
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/markup/TestJSONWriter.java
Modified:
    jakarta/tapestry/trunk/.settings/org.eclipse.jdt.ui.prefs
    
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/AnnotationUtils.java
    
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/ClassAnnotationEnhancementWorker.java
    
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/ComponentAnnotationWorker.java
    
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlag.java
    
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlagAnnotationWorker.java
    
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/MethodAnnotationEnhancementWorker.java
    
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/SecondaryAnnotationWorker.java
    
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/IJSONWriter.java

Modified: jakarta/tapestry/trunk/.settings/org.eclipse.jdt.ui.prefs
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/.settings/org.eclipse.jdt.ui.prefs?rev=385231&r1=385230&r2=385231&view=diff
==============================================================================
--- jakarta/tapestry/trunk/.settings/org.eclipse.jdt.ui.prefs (original)
+++ jakarta/tapestry/trunk/.settings/org.eclipse.jdt.ui.prefs Sat Mar 11 
17:24:19 2006
@@ -1,4 +1,4 @@
-#Sat Mar 11 18:13:15 EST 2006
+#Sat Mar 11 20:18:44 EST 2006
 eclipse.preferences.version=1
 formatter_profile=_tapestry
 formatter_settings_version=10
@@ -12,4 +12,4 @@
 org.eclipse.jdt.ui.ondemandthreshold=99
 org.eclipse.jdt.ui.overrideannotation=true
 org.eclipse.jdt.ui.staticondemandthreshold=99
-org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" 
encoding\="UTF-8"?><templates><template autoinsert\="true" 
context\="gettercomment_context" deleted\="false" description\="Comment for 
getter method" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" 
name\="gettercomment">/**\n * @return the ${bare_field_name}\n 
*/</template><template autoinsert\="true" context\="settercomment_context" 
deleted\="false" description\="Comment for setter method" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" 
name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n 
*/</template><template autoinsert\="true" context\="constructorcomment_context" 
deleted\="false" description\="Comment for created constructors" 
enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" 
name\="constructorcomment">/**\n * ${tags}\n */</template><template 
autoinsert\="true" context\="filecomment_context" deleted\
 ="false" description\="Comment for created Java files" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" 
name\="filecomment">/**\n * \n */</template><template autoinsert\="true" 
context\="typecomment_context" deleted\="false" description\="Comment for 
created types" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" 
name\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n 
*/</template><template autoinsert\="true" context\="fieldcomment_context" 
deleted\="false" description\="Comment for fields" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" 
name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" 
context\="methodcomment_context" deleted\="false" description\="Comment for 
non-overriding methods" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" 
name\="methodcomment">/**\n * ${tags}\n */</template><template 
autoinsert\="true" context\="overridecomment_context" del
 eted\="false" description\="Comment for overriding methods" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" 
name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n 
*/</template><template autoinsert\="true" context\="newtype_context" 
deleted\="false" description\="Newly created files" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.newtype" 
name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template
 autoinsert\="true" context\="classbody_context" deleted\="false" 
description\="Code in new class type bodies" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.classbody" 
name\="classbody">\n</template><template autoinsert\="true" 
context\="interfacebody_context" deleted\="false" description\="Code in new 
interface type bodies" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" 
name\="interfacebody">\n</template><template autoinsert\="true" conte
 xt\="enumbody_context" deleted\="false" description\="Code in new enum type 
bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" 
name\="enumbody">\n</template><template autoinsert\="true" 
context\="annotationbody_context" deleted\="false" description\="Code in new 
annotation type bodies" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" 
name\="annotationbody">\n</template><template autoinsert\="true" 
context\="catchblock_context" deleted\="false" description\="Code in new catch 
blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" 
name\="catchblock">// ${todo} Auto-generated catch 
block\n${exception_var}.printStackTrace();</template><template 
autoinsert\="true" context\="methodbody_context" deleted\="false" 
description\="Code in created method stubs" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// 
${todo} Auto-generated method stub\n${body_statement}</templa
 te><template autoinsert\="true" context\="constructorbody_context" 
deleted\="false" description\="Code in created constructor stubs" 
enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" 
name\="constructorbody">${body_statement}\n// ${todo} Auto-generated 
constructor stub</template><template autoinsert\="true" 
context\="getterbody_context" deleted\="false" description\="Code in created 
getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" 
name\="getterbody">return ${field};</template><template autoinsert\="true" 
context\="setterbody_context" deleted\="false" description\="Code in created 
setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" 
name\="setterbody">${field} \= ${param};</template></templates>
+org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" 
encoding\="UTF-8"?><templates><template autoinsert\="true" 
context\="gettercomment_context" deleted\="false" description\="Comment for 
getter method" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" 
name\="gettercomment">/**\n * @return the ${bare_field_name}\n 
*/</template><template autoinsert\="true" context\="settercomment_context" 
deleted\="false" description\="Comment for setter method" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" 
name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n 
*/</template><template autoinsert\="true" context\="constructorcomment_context" 
deleted\="false" description\="Comment for created constructors" 
enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" 
name\="constructorcomment">/**\n * ${tags}\n */</template><template 
autoinsert\="false" context\="filecomment_context" deleted
 \="false" description\="Comment for created Java files" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">// 
Copyright ${date} The Apache Software Foundation\n//\n// Licensed under the 
Apache License, Version 2.0 (the "License");\n// you may not use this file 
except in compliance with the License.\n// You may obtain a copy of the License 
at\n//\n//     http\://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless 
required by applicable law or agreed to in writing, software\n// distributed 
under the License is distributed on an "AS IS" BASIS,\n// WITHOUT WARRANTIES OR 
CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the 
specific language governing permissions and\n// limitations under the 
License.</template><template autoinsert\="true" context\="typecomment_context" 
deleted\="false" description\="Comment for created types" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment
 ">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template 
autoinsert\="true" context\="fieldcomment_context" deleted\="false" 
description\="Comment for fields" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" 
name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" 
context\="methodcomment_context" deleted\="false" description\="Comment for 
non-overriding methods" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" 
name\="methodcomment">/**\n * ${tags}\n */</template><template 
autoinsert\="false" context\="overridecomment_context" deleted\="false" 
description\="Comment for overriding methods" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" 
name\="overridecomment">/** \n * [EMAIL PROTECTED] */</template><template 
autoinsert\="true" context\="newtype_context" deleted\="false" 
description\="Newly created files" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name
 
\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template
 autoinsert\="true" context\="classbody_context" deleted\="false" 
description\="Code in new class type bodies" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.classbody" 
name\="classbody">\n</template><template autoinsert\="true" 
context\="interfacebody_context" deleted\="false" description\="Code in new 
interface type bodies" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" 
name\="interfacebody">\n</template><template autoinsert\="true" 
context\="enumbody_context" deleted\="false" description\="Code in new enum 
type bodies" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" 
name\="enumbody">\n</template><template autoinsert\="true" 
context\="annotationbody_context" deleted\="false" description\="Code in new 
annotation type bodies" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="an
 notationbody">\n</template><template autoinsert\="true" 
context\="catchblock_context" deleted\="false" description\="Code in new catch 
blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" 
name\="catchblock">// ${todo} Auto-generated catch 
block\n${exception_var}.printStackTrace();</template><template 
autoinsert\="true" context\="methodbody_context" deleted\="false" 
description\="Code in created method stubs" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// 
${todo} Auto-generated method stub\n${body_statement}</template><template 
autoinsert\="true" context\="constructorbody_context" deleted\="false" 
description\="Code in created constructor stubs" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" 
name\="constructorbody">${body_statement}\n// ${todo} Auto-generated 
constructor stub</template><template autoinsert\="true" 
context\="getterbody_context" deleted\="false" description\="Co
 de in created getters" enabled\="true" 
id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" 
name\="getterbody">return ${field};</template><template autoinsert\="true" 
context\="setterbody_context" deleted\="false" description\="Code in created 
setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" 
name\="setterbody">${field} \= ${param};</template></templates>

Modified: 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/AnnotationUtils.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/AnnotationUtils.java?rev=385231&r1=385230&r2=385231&view=diff
==============================================================================
--- 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/AnnotationUtils.java
 (original)
+++ 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/AnnotationUtils.java
 Sat Mar 11 17:24:19 2006
@@ -28,8 +28,11 @@
  * @since 4.0
  */
 
-public class AnnotationUtils
+public final class AnnotationUtils
 {
+    /* defeat instantiation */
+    private AnnotationUtils() { }
+    
     /**
      * Determines the property name for a method, by stripping off the 
is/get/set prefix and
      * decapitalizing the first name.

Modified: 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/ClassAnnotationEnhancementWorker.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/ClassAnnotationEnhancementWorker.java?rev=385231&r1=385230&r2=385231&view=diff
==============================================================================
--- 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/ClassAnnotationEnhancementWorker.java
 (original)
+++ 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/ClassAnnotationEnhancementWorker.java
 Sat Mar 11 17:24:19 2006
@@ -40,7 +40,7 @@
      *            the location associated with the annotation
      */
 
-    public void performEnhancement(EnhancementOperation op, 
IComponentSpecification spec,
+    void performEnhancement(EnhancementOperation op, IComponentSpecification 
spec,
             Class baseClass, Location location);
 
 }

Modified: 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/ComponentAnnotationWorker.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/ComponentAnnotationWorker.java?rev=385231&r1=385230&r2=385231&view=diff
==============================================================================
--- 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/ComponentAnnotationWorker.java
 (original)
+++ 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/ComponentAnnotationWorker.java
 Sat Mar 11 17:24:19 2006
@@ -90,4 +90,4 @@
     {
         throw new 
ApplicationRuntimeException(AnnotationMessages.bindingWrongFormat(binding));
     }
-}
\ No newline at end of file
+}

Modified: 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlag.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlag.java?rev=385231&r1=385230&r2=385231&view=diff
==============================================================================
--- 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlag.java
 (original)
+++ 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlag.java
 Sat Mar 11 17:24:19 2006
@@ -20,6 +20,10 @@
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+/**
+ * 
+ * @author Howard Lewis Ship
+ */
 @Target(
 { ElementType.METHOD })
 @Retention(RetentionPolicy.RUNTIME)

Modified: 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlagAnnotationWorker.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlagAnnotationWorker.java?rev=385231&r1=385230&r2=385231&view=diff
==============================================================================
--- 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlagAnnotationWorker.java
 (original)
+++ 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlagAnnotationWorker.java
 Sat Mar 11 17:24:19 2006
@@ -22,6 +22,10 @@
 import org.apache.tapestry.spec.InjectSpecification;
 import org.apache.tapestry.spec.InjectSpecificationImpl;
 
+/**
+ * 
+ * @author Howard Lewis Ship
+ */
 public class InjectStateFlagAnnotationWorker implements 
MethodAnnotationEnhancementWorker
 {
 

Modified: 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/MethodAnnotationEnhancementWorker.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/MethodAnnotationEnhancementWorker.java?rev=385231&r1=385230&r2=385231&view=diff
==============================================================================
--- 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/MethodAnnotationEnhancementWorker.java
 (original)
+++ 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/MethodAnnotationEnhancementWorker.java
 Sat Mar 11 17:24:19 2006
@@ -42,6 +42,6 @@
      * @param location TODO
      */
 
-    public void performEnhancement(EnhancementOperation op, 
IComponentSpecification spec,
+    void performEnhancement(EnhancementOperation op, IComponentSpecification 
spec,
             Method method, Location location);
 }

Modified: 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/SecondaryAnnotationWorker.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/SecondaryAnnotationWorker.java?rev=385231&r1=385230&r2=385231&view=diff
==============================================================================
--- 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/SecondaryAnnotationWorker.java
 (original)
+++ 
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/SecondaryAnnotationWorker.java
 Sat Mar 11 17:24:19 2006
@@ -36,7 +36,7 @@
      *            to check
      * @return true if the worker should be invoked, false otherwise
      */
-    public boolean canEnhance(Method method);
+    boolean canEnhance(Method method);
 
     /**
      * Invoked an <em>all</em> workers in the command chain, if <em>any</em> 
worker returns true
@@ -52,6 +52,6 @@
      *            a resource representing the class; combined with the method a
      *            [EMAIL PROTECTED] org.apache.hivemind.Location} can be 
created
      */
-    public void peformEnhancement(EnhancementOperation op, 
IComponentSpecification spec,
+    void peformEnhancement(EnhancementOperation op, IComponentSpecification 
spec,
             Method method, Resource classResource);
 }

Modified: 
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/IJSONWriter.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/IJSONWriter.java?rev=385231&r1=385230&r2=385231&view=diff
==============================================================================
--- 
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/IJSONWriter.java 
(original)
+++ 
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/IJSONWriter.java 
Sat Mar 11 17:24:19 2006
@@ -24,5 +24,35 @@
  */
 public interface IJSONWriter
 {
+    /** begin json block. */
+    String BEGIN = "{";
+    /** end of json block. */
+    String END = "}";
     
+    /**
+     * Writes the key value pair as a <code>key:value</code> 
+     * property pair.
+     * 
+     * @param key 
+     *          The key value of the JSON property
+     * @param value
+     *          The value of the key property
+     */
+    void write(Object key, Object value);
+    
+    /**
+     * Begins a new block using the [EMAIL PROTECTED] #BEGIN} character.
+     */
+    void begin();
+    
+    /**
+     * Ends any open blocks using the [EMAIL PROTECTED] #END} character.
+     */
+    void end();
+    
+    /**
+     * Causes any un-ended blocks to be closed, as well as 
+     * any reasources associated with writer to be flushed/written.
+     */
+    void close();
 }

Added: 
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/markup/JSONWriterImpl.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/markup/JSONWriterImpl.java?rev=385231&view=auto
==============================================================================
--- 
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/markup/JSONWriterImpl.java
 (added)
+++ 
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/markup/JSONWriterImpl.java
 Sat Mar 11 17:24:19 2006
@@ -0,0 +1,112 @@
+// Copyright 2006 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.tapestry.markup;
+
+import java.io.PrintWriter;
+
+import org.apache.hivemind.util.Defense;
+import org.apache.tapestry.IJSONWriter;
+
+/**
+ * Implementation of [EMAIL PROTECTED] IJSONWriter}.
+ * 
+ * @author jkuhnert
+ */
+public class JSONWriterImpl implements IJSONWriter
+{   
+    /** Outputstream writer. */
+    protected PrintWriter _writer;
+    
+    /**
+     * For every [EMAIL PROTECTED] #start()} call there must be a corresponding
+     * end to close out the block, this counter is used to keep
+     * track of these calls.
+     */
+    private int _stackCount = 0;
+    
+    /**
+     * Tracks items written to a block, all items must be delimited by
+     * "," characters, so this keeps track of started lists.
+     */
+    private boolean _listOpen = false;
+    
+    /**
+     * Creates a new instance that will write all content to 
+     * the specified [EMAIL PROTECTED] PrintWriter}.
+     * 
+     * @param writer The outputstream to write to.
+     */
+    public JSONWriterImpl(PrintWriter writer)
+    {
+        Defense.notNull(writer, "writer");
+        
+        _writer = writer;
+        begin(); // all JSON responses must be contained by { } 
+    }
+    
+    /**
+     * [EMAIL PROTECTED]
+     */
+    public void write(Object key, Object value)
+    {
+        if (_listOpen)
+            _writer.write(",");
+        
+        _writer.write("\"" + key + "\"" + ":" + "\"" + value + "\"");
+        _listOpen = true;
+    }
+    
+    /** 
+     * [EMAIL PROTECTED]
+     */
+    public void begin()
+    {
+        _writer.print(BEGIN);
+        
+        _stackCount++;
+    }
+    
+    /** 
+     * [EMAIL PROTECTED]
+     */
+    public void end()
+    {
+        _writer.print(END);
+        
+        _stackCount--;
+    }
+    
+    /**
+     * 
+     * [EMAIL PROTECTED]
+     */
+    public void close()
+    {
+        while (_stackCount != 0)
+            end();
+        
+        _writer.flush();
+        _writer.close();
+    }
+    
+    /**
+     * The outputstream being used to write this 
+     * instance's content.
+     * @return 
+     */
+    protected PrintWriter getWriter()
+    {
+        return _writer;
+    }
+}

Added: 
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/markup/TestJSONWriter.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/markup/TestJSONWriter.java?rev=385231&view=auto
==============================================================================
--- 
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/markup/TestJSONWriter.java
 (added)
+++ 
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/markup/TestJSONWriter.java
 Sat Mar 11 17:24:19 2006
@@ -0,0 +1,80 @@
+// Copyright 2006 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.tapestry.markup;
+
+import java.io.PrintWriter;
+
+import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.IJSONWriter;
+
+import java.io.ByteArrayOutputStream;
+
+
+/**
+ * Tests functionality of the [EMAIL PROTECTED] IJSONWriter} class.
+ * 
+ * @author jkuhnert
+ */
+public class TestJSONWriter extends HiveMindTestCase
+{
+    
+    /**
+     * Tests creating a list of key/value pairs.
+     */
+    public void testPropertyList() 
+    {
+        String listGoal = 
"{\"red\":\"ball\",\"black\":\"cat\",\"orange\":\"orange\"}";
+        
+        IJSONWriter writer = newWriter();
+        
+        writer.write("red", "ball");
+        writer.write("black", "cat");
+        writer.write("orange", "orange");
+        
+        assertEquals(output(writer), listGoal);
+    }
+    
+    /**
+     * Gets the stored string output from the 
+     * local <code>outputBuffer</code>, after first
+     * closing the passed in [EMAIL PROTECTED] IJSONWriter}.
+     * 
+     * @param writer
+     * @return The string output that was written.
+     */
+    public String output(IJSONWriter writer)
+    {
+        writer.close();
+        return outputBuffer.toString();
+    }
+    
+    /* All writer content is written to this buffer */
+    protected ByteArrayOutputStream outputBuffer;
+    
+    /**
+     * Creates a writer instance that content can be asserted
+     * against.
+     * @return
+     */
+    protected JSONWriterImpl newWriter()
+    {
+        outputBuffer = new ByteArrayOutputStream();
+        PrintWriter pw = 
+            new PrintWriter(outputBuffer);
+        
+        JSONWriterImpl writer = new JSONWriterImpl(pw);
+        
+        return writer;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to