[teiid-commits] teiid SVN: r891 - trunk/adminshell/src/main/resources/scripts.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Thu May 7 23:17:07 EDT 2009


Author: vhalbert at redhat.com
Date: 2009-05-07 23:17:07 -0400 (Thu, 07 May 2009)
New Revision: 891

Modified:
   trunk/adminshell/src/main/resources/scripts/adminapi.bsh
   trunk/adminshell/src/main/resources/scripts/util.bsh
Log:
Teiid 470 - added new importconnectorbinding method to adminapi.bsh script and fixed the util.bsh script because of malform exceptions after the xml file was converted to char[].

Modified: trunk/adminshell/src/main/resources/scripts/adminapi.bsh
===================================================================
--- trunk/adminshell/src/main/resources/scripts/adminapi.bsh	2009-05-07 23:17:59 UTC (rev 890)
+++ trunk/adminshell/src/main/resources/scripts/adminapi.bsh	2009-05-08 03:17:07 UTC (rev 891)
@@ -175,7 +175,34 @@
     return currentContext().internalAdmin.addConnectorBinding(name, readTextFile(xmlFile), new AdminOptions(option));
 }
 
+
 /**
+ * Import a {@link ConnectorBinding} into the Configuration.
+ *
+ * @param name
+ *            is the Connector Binding name that will be added to Configuration
+ * @param binding
+ *            byte array of the connector binding xml file
+ * @param AdminOptions that defines the options on how to import theconnector binding.
+ * There are choices about what to do when a connector binding with the given identifier 
+ @ already exists in the system. 
+ * See the interface {@link AdminOptions.OnConflict} for details.
+ * <p>
+ * Another option is to ignore a binding connection password decrypt error, when adding a connector
+ * binding whose password was encrypted with a different keystore, so that the new password property
+ * can be set after the connector binding has been added.</p>
+ * @throws AdminException
+ *             if there's a system error.
+ * @return the {@link ConnectorBinding} representing the current property values and runtime state.
+ * @since 4.3
+ */
+ConnectorBinding addConnectorBinding(String name, String xmlFile, AdminOptions options){
+    debug("Adding Connector Binding " + name + " from a byte array");
+    checkAdmin();    
+    return currentContext().internalAdmin.addConnectorBinding(name, readTextFile(xmlFile), options);
+}
+
+/**
  * Deploy a {@link ConnectorBinding} to Configuration
  *
  * @param connectorBindingIdentifier

Modified: trunk/adminshell/src/main/resources/scripts/util.bsh
===================================================================
--- trunk/adminshell/src/main/resources/scripts/util.bsh	2009-05-07 23:17:59 UTC (rev 890)
+++ trunk/adminshell/src/main/resources/scripts/util.bsh	2009-05-08 03:17:07 UTC (rev 891)
@@ -1,6 +1,7 @@
 import java.io.*;
 import com.metamatrix.admin.api.core.*;
 import com.metamatrix.admin.api.objects.*;
+import com.metamatrix.core.util.*;
 
 debug=false;
 
@@ -12,13 +13,14 @@
 }
 
 byte[] readBinaryFile(String fileName) {
+    InputStream is = null;
     
     if(fileName == null) {
         throw new IOException("fileName is null");
     }
     try {
         //try to load file from the classpath
-        InputStream is = Object.class.getResourceAsStream("/"+fileName);
+        is = Object.class.getResourceAsStream("/"+fileName);
          
         byte[] result;
         if (is == null) {
@@ -26,38 +28,50 @@
             is = new FileInputStream(new File(fileName));
         }
     
-        //convert to bytes
+
+    }catch(Exception e) {
+         if (is == null) {
+         	try {
+            //load from "hardcoded" path        
+            	is = new FileInputStream(new File(fileName));
+            }catch(Exception e2) {
+                
+       			 e.printStackTrace(); 
+        		 return null;
+            }
+         } 
+
+    }
+    
+	//convert to bytes
         result = convertToByteArray(is);
-        is.close();    
+        try {
+        	is.close();
+        }catch(Exception e3) {
+        }    
         return result;
-    }catch(e) {
-        e.printStackTrace(); 
-    }
-    return null;
 }
 
 char[] readTextFile(String fileName) {
     if(fileName == null) {
         throw new IOException("fileName is null");
     }
+    char[] result = null;
+
+    try {
+      File file = new File(fileName);
+ 
+    // changed to use the ObectConverterUtil, instead of the
+    // convertToCharArray() method because it doesn't completely
+    // convert the file, the XML reader throws a malform exception
+    // the test case for ServerAdminImpl also the ObjectConverterUtil
+    // that's why this was changed to use it
+      result = ObjectConverterUtil.convertFileToCharArray(file, null);
     
-    try {
-        //try to load file from the classpath
-        InputStream is = Object.class.getResourceAsStream("/"+fileName);
-        
-        char[] result;
-        if (is == null) {
-            //load from "hardcoded" path
-            is = new FileInputStream(new File(fileName));
-        }
-        
-        //   convert to bytes
-        result = convertToCharArray(is);
-        is.close();    
-        return result;
     }catch(e) {
         e.printStackTrace();
-    }
+    } 
+    return result;
 }
 
 byte[] convertToByteArray(InputStream in) throws IOException {




More information about the teiid-commits mailing list