You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/05/19 22:36:42 UTC

svn commit: r776450 - in /incubator/pivot/trunk/wtk/src/pivot/wtkx: Compiler.java Translator.java

Author: tvolkert
Date: Tue May 19 20:36:41 2009
New Revision: 776450

URL: http://svn.apache.org/viewvc?rev=776450&view=rev
Log:
Added new overload signature of pivot.wtkx.Translator.translate()

Modified:
    incubator/pivot/trunk/wtk/src/pivot/wtkx/Compiler.java
    incubator/pivot/trunk/wtk/src/pivot/wtkx/Translator.java

Modified: incubator/pivot/trunk/wtk/src/pivot/wtkx/Compiler.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtkx/Compiler.java?rev=776450&r1=776449&r2=776450&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtkx/Compiler.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtkx/Compiler.java Tue May 19 20:36:41 2009
@@ -16,7 +16,6 @@
  */
 package pivot.wtkx;
 
-import java.io.InputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 
@@ -62,14 +61,9 @@
         throws IOException {
         boolean success = false;
 
-        JavaFileObject javaFileObject = null;
-        InputStream inputStream = referenceClass.getResourceAsStream(resourceName);
+        Translator translator = new Translator();
+        JavaFileObject javaFileObject = translator.translate(referenceClass, resourceName);
         try {
-            Translator translator = new Translator();
-
-            javaFileObject = translator.translate(inputStream,
-                getPreferredClassName(referenceClass, resourceName));
-
             ArrayList<JavaFileObject> javaFileObjects = new ArrayList<JavaFileObject>(1);
             javaFileObjects.add(javaFileObject);
 
@@ -79,11 +73,7 @@
 
             success = task.call();
         } finally {
-            inputStream.close();
-
-            if (javaFileObject != null) {
-                javaFileObject.delete();
-            }
+            javaFileObject.delete();
         }
 
         return success;

Modified: incubator/pivot/trunk/wtk/src/pivot/wtkx/Translator.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtkx/Translator.java?rev=776450&r1=776449&r2=776450&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtkx/Translator.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtkx/Translator.java Tue May 19 20:36:41 2009
@@ -187,24 +187,57 @@
 
     private static final String SPACE = "";
 
+    /**
+     * Creates a new <tt>Translator</tt>.
+     */
     public Translator() {
         xmlInputFactory = XMLInputFactory.newInstance();
         xmlInputFactory.setProperty("javax.xml.stream.isCoalescing", true);
     }
 
     /**
-     * Reads WTKX input stream into a compilable file object. The file object
-     * will hold a class that implements the {@link Bindable.ObjectHierarchy}
-     * interface.
+     * Translates a WTKX resource into a Java source file. The translated class
+     * will implement the {@link Bindable.ObjectHierarchy} interface.
+     *
+     * @param referenceClass
+     * The class relative to which the WTKX resource can be found.
+     *
+     * @param resourceName
+     * A path name that identifies the WTKX resource. The path name should be
+     * of the form defined by {@link Class#getResource(String)} and is relative
+     * to the base package. Note that this is the same form as is defined in
+     * {@link Bindable.Load#resourceName()}.
+     *
+     * @return
+     * The Java source file representation of the WTKX resource.
+     */
+    public JavaFileObject translate(Class<?> referenceClass, String resourceName)
+        throws IOException {
+        JavaFileObject javaFileObject;
+
+        InputStream inputStream = referenceClass.getResourceAsStream(resourceName);
+        try {
+            javaFileObject = translate(inputStream,
+                Compiler.getPreferredClassName(referenceClass, resourceName));
+        } finally {
+            inputStream.close();
+        }
+
+        return javaFileObject;
+    }
+
+    /**
+     * Translates a WTKX input stream into a Java source file. The translated class
+     * will implement the {@link Bindable.ObjectHierarchy} interface.
      *
      * @param inputStream
-     * The data stream from which the WTKX will be read
+     * The data stream from which the WTKX will be read.
      *
      * @param className
      * The fully qualified class name of the class to generate.
      *
      * @return
-     * The compilable java file object represented by the WTKX
+     * The Java source file representation of the WTKX.
      */
     public JavaFileObject translate(InputStream inputStream, String className)
         throws IOException {