geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r632155 - /geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
Date Thu, 28 Feb 2008 23:10:41 GMT
Author: dain
Date: Thu Feb 28 15:10:39 2008
New Revision: 632155

URL: http://svn.apache.org/viewvc?rev=632155&view=rev
Log:
Update existing spring.handlers and spring.schemas files if they already exist

Modified:
    geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java

Modified: geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java?rev=632155&r1=632154&r2=632155&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
(original)
+++ geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
Thu Feb 28 15:10:39 2008
@@ -20,10 +20,15 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Properties;
 
 import org.apache.xbean.spring.context.impl.NamespaceHelper;
 
@@ -73,24 +78,62 @@
         	
             // Generate spring 2.0 mapping
 	        file = new File(metaInfDir, "META-INF/spring.handlers");
-	        log.log("Generating Spring 2.0 handler mapping: " + file + " for namespace: " +
namespace);
-	        out = new PrintWriter(new FileWriter(file));
-	        try {
-	            out.println(namespace.replaceAll(":", "\\\\:") + "=" + NAMESPACE_HANDLER);
-	        } finally {
-	            out.close();
-	        }
+
+            Properties properties = new Properties();
+            if (!file.exists()) {
+                log.log("Generating Spring 2.0 handler mapping: " + file + " for namespace:
" + namespace);
+            } else {
+                log.log("Updating Spring 2.0 handler mapping: " + file + " for namespace:
" + namespace);
+
+                // read in current file
+                InputStream in = new FileInputStream(file);
+                try {
+                    properties.load(in);
+                } catch (IOException e) {
+                    in.close();
+                }
+            }
+
+            // add property
+            properties.put(namespace,  NAMESPACE_HANDLER);
+
+            // write properties
+            OutputStream fout = new FileOutputStream(file);
+            try {
+                properties.store(fout, "Generated by xbean-spring");
+            } finally {
+                fout.close();
+            }
         }
 
         if (schema != null && generateSpringSchemasFile ) {
             String cp = new File(metaInfDir).toURI().relativize(schema.toURI()).toString();
             file = new File(metaInfDir, "META-INF/spring.schemas");
-            log.log("Generating Spring 2.0 schema mapping: " + file + " for namespace: "
+ namespace);
-            out = new PrintWriter(new FileWriter(file));
+
+            Properties properties = new Properties();
+            if (!file.exists()) {
+                log.log("Generating Spring 2.0 schema mapping: " + file + " for namespace:
" + namespace);
+            } else {
+                log.log("Updating Spring 2.0 schema mapping: " + file + " for namespace:
" + namespace);
+
+                // read in current file
+                InputStream in = new FileInputStream(file);
+                try {
+                    properties.load(in);
+                } catch (IOException e) {
+                    in.close();
+                }
+            }
+
+            // add property
+            properties.put(namespace,  cp);
+
+            // write properties
+            OutputStream fout = new FileOutputStream(file);
             try {
-                out.println(namespace.replaceAll(":", "\\\\:") + "=" + cp);
+                properties.store(fout, "Generated by xbean-spring");
             } finally {
-                out.close();
+                fout.close();
             }
         }
     }



Mime
View raw message