[lsc-changes] r284 - lsc/trunk/src/main/java/org/lsc

sbahloul at lsc-project.org sbahloul at lsc-project.org
Tue Jul 7 13:17:58 CEST 2009


Author: sbahloul
Date: 2009-07-07 13:17:58 +0200 (Tue, 07 Jul 2009)
New Revision: 284

Modified:
   lsc/trunk/src/main/java/org/lsc/AbstractSynchronize.java
   lsc/trunk/src/main/java/org/lsc/SimpleSynchronize.java
Log:
Fixing bad parameter checking and missing bean attribution

Modified: lsc/trunk/src/main/java/org/lsc/AbstractSynchronize.java
===================================================================
--- lsc/trunk/src/main/java/org/lsc/AbstractSynchronize.java	2009-07-07 10:46:38 UTC (rev 283)
+++ lsc/trunk/src/main/java/org/lsc/AbstractSynchronize.java	2009-07-07 11:17:58 UTC (rev 284)
@@ -138,6 +138,7 @@
      *                the jndi destination service
      */
     protected final void clean2Ldap(final String syncName,
+    		final Class<AbstractBean> taskBeanClass,
             final ISrcService srcService,
             final IJndiDstService dstJndiService) {
 
@@ -166,11 +167,21 @@
         
         JndiModifications jm = null;
 //        LscObject srcObject = null;
-        AbstractBean bean = null;
         
         /** Hash table to pass objects into JavaScript condition */
         Map<String, Object> conditionObjects = null;
         
+        AbstractBean taskBean;
+		try {
+			taskBean = taskBeanClass.newInstance();
+		} catch (InstantiationException e) {
+            LOGGER.error("Error while instanciating taskbean class: " + e, e);
+            return;
+		} catch (IllegalAccessException e) {
+            LOGGER.error("Error while instanciating taskbean class: " + e, e);
+            return;
+		}
+        
         // Loop on all entries in the destination and delete them if they're not found in the source
         while (ids.hasNext()) {
             countAll++;
@@ -179,10 +190,10 @@
 
             try {
                 // Search for the corresponding object in the source
-            	bean = srcService.getBean(bean, id);
+            	taskBean = srcService.getBean(taskBean, id);
 
                 // If we didn't find the object in the source, delete it in the destination
-                if (bean == null) {
+                if (taskBean == null) {
                     // Retrieve condition to evaluate before deleting
                     Boolean doDelete = null;
                     String conditionString = syncOptions.getDeleteCondition();
@@ -198,7 +209,7 @@
 //	                        AbstractBean bean = dstJndiService.getBean(id);
 
 	                        // Log an error if the bean could not be retrieved! This shouldn't happen.
-	                        if (bean == null) {
+	                        if (taskBean == null) {
 	                            LOGGER.error("Could not retrieve the object " + id.getKey() + " from the directory!");
 	                            countError++;
 	                            continue;
@@ -206,7 +217,7 @@
 
 	                        // Put the bean in a map to pass to JavaScript evaluator
 	                        conditionObjects = new HashMap<String, Object>();
-	                        conditionObjects.put("dstBean", bean);	                    	
+	                        conditionObjects.put("dstBean", taskBean);	                    	
 	                    }
 
 	                    // Evaluate if we have to do something

Modified: lsc/trunk/src/main/java/org/lsc/SimpleSynchronize.java
===================================================================
--- lsc/trunk/src/main/java/org/lsc/SimpleSynchronize.java	2009-07-07 10:46:38 UTC (rev 283)
+++ lsc/trunk/src/main/java/org/lsc/SimpleSynchronize.java	2009-07-07 11:17:58 UTC (rev 284)
@@ -197,10 +197,12 @@
     }
     
 
-    private void checkTaskOldProperty(String taskName, String propertyName, String message) {
-   		String errorMessage = "Deprecated value specified in task " + taskName + " for " + propertyName + "! Please read upgrade notes ! (" + message + ")";
-   		LOGGER.fatal(errorMessage);
-   		throw new ExceptionInInitializerError(errorMessage);
+    private void checkTaskOldProperty(Properties props, String taskName, String propertyName, String message) {
+    	if(props.getProperty(TASKS_PROPS_PREFIX + "." + taskName + "." + propertyName) != null) {
+       		String errorMessage = "Deprecated value specified in task " + taskName + " for " + propertyName + "! Please read upgrade notes ! (" + message + ")";
+       		LOGGER.fatal(errorMessage);
+       		throw new ExceptionInInitializerError(errorMessage);
+    	}
     }
     
     private String getTaskPropertyAndCheckNotNull(String taskName, Properties props, String propertyName) {
@@ -238,7 +240,7 @@
 
             // Get all properties
             // TODO : nice error message if a class name is specified but doesn't exist
-            checkTaskOldProperty(taskName, OBJECT_PROPS_PREFIX, "Please take a look at upgrade notes at http://lsc-project.org/wiki/documentation/upgrade/1.1-1.2");
+            checkTaskOldProperty(lscProperties, taskName, OBJECT_PROPS_PREFIX, "Please take a look at upgrade notes at http://lsc-project.org/wiki/documentation/upgrade/1.1-1.2");
             String beanClassName = getTaskPropertyAndCheckNotNull(taskName, lscProperties, BEAN_PROPS_PREFIX);
             String srcServiceClass = getTaskPropertyAndCheckNotNull(taskName, lscProperties, SRCSERVICE_PROPS_PREFIX);
             String dstServiceClass = getTaskPropertyAndCheckNotNull(taskName, lscProperties, DSTSERVICE_PROPS_PREFIX);
@@ -262,7 +264,7 @@
                     Properties srcServiceProperties = Configuration.getAsProperties(LSC_PROPS_PREFIX + "."
                             + prefix + SRCSERVICE_PROPS_PREFIX);
                     
-                    Constructor<?> constrSrcJndiService = Class.forName(srcServiceClass).getConstructor(new Class[] { Properties.class, String.class });
+                    Constructor<?> constrSrcJndiService = Class.forName(srcServiceClass).getConstructor(new Class[] { Properties.class });
                     srcService = (ISrcService) constrSrcJndiService.newInstance(new Object[] { srcServiceProperties });
 
                     break;
@@ -274,13 +276,13 @@
                     return false;
             }
 
+            Class<AbstractBean> taskBean = (Class<AbstractBean>) Class.forName(beanClassName);
             // Do the work!
             switch(taskMode) {
                 case clean:
-                    clean2Ldap(taskName, srcService, dstJndiService);
+                    clean2Ldap(taskName, taskBean, srcService, dstJndiService);
                     break;
                 case sync:
-                    Class<AbstractBean> taskBean = (Class<AbstractBean>) Class.forName(beanClassName);
                     synchronize2Ldap(taskName, srcService, dstJndiService, taskBean, customLibrary);
                     break;
                 default:        



More information about the lsc-changes mailing list