[teiid-commits] teiid SVN: r3038 - in trunk: runtime/src/main/java/org/teiid/deployers and 2 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri Mar 25 13:48:34 EDT 2011


Author: shawkins
Date: 2011-03-25 13:48:34 -0400 (Fri, 25 Mar 2011)
New Revision: 3038

Modified:
   trunk/api/src/main/java/org/teiid/translator/TranslatorProperty.java
   trunk/runtime/src/main/java/org/teiid/deployers/TranslatorUtil.java
   trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties
   trunk/runtime/src/test/java/org/teiid/deployers/TestTranslatorUtil.java
Log:
TEIID-1513 making translator property name keys case insensitive.

Modified: trunk/api/src/main/java/org/teiid/translator/TranslatorProperty.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/TranslatorProperty.java	2011-03-25 16:06:26 UTC (rev 3037)
+++ trunk/api/src/main/java/org/teiid/translator/TranslatorProperty.java	2011-03-25 17:48:34 UTC (rev 3038)
@@ -28,7 +28,12 @@
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
-
+/**
+ * Annotates a property that can be externally configured.  
+ * The property name will be inferred from the method.
+ * Keep in mind that TranslatorProprties name are treated as case-insensitive 
+ * - do not annotate two methods in the same ExecutionFactory with the same case-insensitive name.
+ */
 @Target({ElementType.METHOD})
 @Retention(RetentionPolicy.RUNTIME)
 @Inherited

Modified: trunk/runtime/src/main/java/org/teiid/deployers/TranslatorUtil.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/TranslatorUtil.java	2011-03-25 16:06:26 UTC (rev 3037)
+++ trunk/runtime/src/main/java/org/teiid/deployers/TranslatorUtil.java	2011-03-25 17:48:34 UTC (rev 3038)
@@ -26,6 +26,7 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
+import java.util.TreeMap;
 
 import org.jboss.deployers.spi.DeploymentException;
 import org.teiid.adminapi.Translator;
@@ -33,6 +34,8 @@
 import org.teiid.core.TeiidException;
 import org.teiid.core.util.ReflectionHelper;
 import org.teiid.core.util.StringUtil;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
 import org.teiid.runtime.RuntimePlugin;
 import org.teiid.translator.ExecutionFactory;
 import org.teiid.translator.TranslatorProperty;
@@ -107,11 +110,13 @@
 	
 	private static void injectProperties(ExecutionFactory ef, final Translator data) throws InvocationTargetException, IllegalAccessException, DeploymentException{
 		Map<Method, TranslatorProperty> props = TranslatorUtil.getTranslatorProperties(ef.getClass());
-		
+		Map p = data.getProperties();
+		TreeMap<String, String> caseInsensitivProps = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
+		caseInsensitivProps.putAll(p);
 		for (Method method:props.keySet()) {
 			TranslatorProperty tp = props.get(method);
 			String propertyName = getPropertyName(method);
-			Object value = data.getPropertyValue(propertyName);
+			String value = caseInsensitivProps.remove(propertyName);
 			
 			if (value != null) {
 				Method setterMethod = getSetter(ef.getClass(), method);
@@ -120,6 +125,10 @@
 				throw new DeploymentException(RuntimePlugin.Util.getString("required_property_not_exists", tp.display())); //$NON-NLS-1$
 			}
 		}
+		caseInsensitivProps.remove(Translator.EXECUTION_FACTORY_CLASS);
+		if (!caseInsensitivProps.isEmpty()) {
+			LogManager.logWarning(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.getString("undefined_translator_props", caseInsensitivProps.keySet(), data.getName())); //$NON-NLS-1$
+		}
 	}
 	
 	public static String getPropertyName(Method method) {

Modified: trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties
===================================================================
--- trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties	2011-03-25 16:06:26 UTC (rev 3037)
+++ trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties	2011-03-25 17:48:34 UTC (rev 3038)
@@ -78,6 +78,7 @@
 translator_removed=Teiid translator "{0}" removed.
 no_set_method=No {0} method found for translator property {1} 
 required_property_not_exists=Required property "{0}" has no value. Deployment is incomplete.
+undefined_translator_props=The provided translator property values {0} were not used.  Please check the properties that are expected by translator {1}.
 name_not_found=Translator property "name" not defined for the deployment "{0}"
 translator_type_not_found=The parent translator defined not found in configuration "{0}"
 failed_to_load_odbc_metadata=Failed to load the ODBC metadata repository.

Modified: trunk/runtime/src/test/java/org/teiid/deployers/TestTranslatorUtil.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/deployers/TestTranslatorUtil.java	2011-03-25 16:06:26 UTC (rev 3037)
+++ trunk/runtime/src/test/java/org/teiid/deployers/TestTranslatorUtil.java	2011-03-25 17:48:34 UTC (rev 3038)
@@ -26,6 +26,7 @@
 import org.junit.Test;
 import org.teiid.adminapi.impl.TranslatorMetaData;
 import org.teiid.translator.ExecutionFactory;
+import org.teiid.translator.Translator;
 import org.teiid.translator.TranslatorProperty;
 
 @SuppressWarnings("nls")
@@ -43,6 +44,18 @@
 		assertEquals("correctly-assigned", my.getMyProperty());
 	}
 	
+	@Test public void testBuildExecutionFactoryCaseInsensitive() throws Exception {
+		TranslatorMetaData tm = new TranslatorMetaData();
+		
+		tm.addProperty("myproperty", "correctly-assigned");
+		tm.setExecutionFactoryClass(MyTranslator.class);
+		
+		MyTranslator my = (MyTranslator)TranslatorUtil.buildExecutionFactory(tm);
+		
+		assertEquals("correctly-assigned", my.getMyProperty());
+	}
+	
+	@Translator(name="my-translator")
 	public static class MyTranslator extends ExecutionFactory<Object, Object> {
 		String mine;
 		



More information about the teiid-commits mailing list