Search in sources :

Example 1 with TranslatorProperty

use of org.teiid.translator.TranslatorProperty in project teiid by teiid.

the class TranslatorUtil method readTranslatorPropertyAsExtendedMetadataProperties.

private static void readTranslatorPropertyAsExtendedMetadataProperties(VDBTranslatorMetaData metadata, ExtendedPropertyMetadataList propertyDefns, Object instance, Class clazz) {
    Map<Method, TranslatorProperty> tps = TranslatorUtil.getTranslatorProperties(clazz);
    for (Method m : tps.keySet()) {
        Object defaultValue = getDefaultValue(instance, m, tps.get(m));
        TranslatorProperty tp = tps.get(m);
        boolean importProperty = tp.category() == TranslatorProperty.PropertyType.IMPORT;
        if (defaultValue != null && !importProperty) {
            metadata.addProperty(getPropertyName(m), defaultValue.toString());
        }
        ExtendedPropertyMetadata epm = new ExtendedPropertyMetadata();
        epm.category = tp.category().name();
        // $NON-NLS-1$
        epm.name = importProperty ? "importer." + getPropertyName(m) : getPropertyName(m);
        epm.description = tp.description();
        epm.advanced = tp.advanced();
        if (defaultValue != null) {
            epm.defaultValue = defaultValue.toString();
        }
        epm.displayName = tp.display();
        epm.masked = tp.masked();
        epm.required = tp.required();
        epm.dataType = m.getReturnType().getCanonicalName();
        // allowed values
        if (m.getReturnType().isEnum()) {
            epm.allowed = new ArrayList<String>();
            Object[] constants = m.getReturnType().getEnumConstants();
            for (int i = 0; i < constants.length; i++) {
                epm.allowed.add(((Enum<?>) constants[i]).name());
            }
            // $NON-NLS-1$
            epm.dataType = "java.lang.String";
        }
        propertyDefns.add(epm);
    }
}
Also used : Method(java.lang.reflect.Method) TranslatorProperty(org.teiid.translator.TranslatorProperty)

Example 2 with TranslatorProperty

use of org.teiid.translator.TranslatorProperty in project teiid by teiid.

the class TranslatorUtil method buildTranslatorProperties.

private static void buildTranslatorProperties(Class<?> attachmentClass, Map<Method, TranslatorProperty> props) {
    Class<?>[] baseInterfaces = attachmentClass.getInterfaces();
    for (Class<?> clazz : baseInterfaces) {
        buildTranslatorProperties(clazz, props);
    }
    Class<?> superClass = attachmentClass.getSuperclass();
    if (superClass != null) {
        buildTranslatorProperties(superClass, props);
    }
    Method[] methods = attachmentClass.getMethods();
    for (Method m : methods) {
        TranslatorProperty tp = m.getAnnotation(TranslatorProperty.class);
        if (tp != null) {
            props.put(m, tp);
        }
    }
}
Also used : Method(java.lang.reflect.Method) TranslatorProperty(org.teiid.translator.TranslatorProperty)

Example 3 with TranslatorProperty

use of org.teiid.translator.TranslatorProperty in project teiid by teiid.

the class TranslatorUtil method injectProperties.

private static void injectProperties(ExecutionFactory ef, final VDBTranslatorMetaData data) throws InvocationTargetException, IllegalAccessException, TeiidException {
    Map<Method, TranslatorProperty> props = TranslatorUtil.getTranslatorProperties(ef.getClass());
    Map<String, String> p = data.getPropertiesMap();
    TreeMap<String, String> caseInsensitiveProps = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
    /*
		VDBTranslatorMetaData parent = data.getParent();
		while (parent != null) {
			for (Map.Entry<String, String> entry : parent.getPropertiesMap().entrySet()) {
				if (!caseInsensitiveProps.containsKey(entry.getKey()) && entry.getValue() != null) {
					caseInsensitiveProps.put(entry.getKey(), entry.getValue());
				}
			}
			parent = parent.getParent();
		}
		*/
    synchronized (p) {
        caseInsensitiveProps.putAll(p);
    }
    caseInsensitiveProps.remove(DEPLOYMENT_NAME);
    for (Method method : props.keySet()) {
        TranslatorProperty tp = props.get(method);
        String propertyName = getPropertyName(method);
        String value = caseInsensitiveProps.remove(propertyName);
        if (value != null) {
            Method setterMethod = getSetter(ef.getClass(), method);
            setterMethod.invoke(ef, convert(value, method.getReturnType()));
        } else if (tp.required()) {
            throw new TeiidException(RuntimePlugin.Event.TEIID40027, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40027, tp.display()));
        }
    }
    caseInsensitiveProps.remove(Translator.EXECUTION_FACTORY_CLASS);
    if (!caseInsensitiveProps.isEmpty()) {
        LogManager.logWarning(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40001, caseInsensitiveProps.keySet(), data.getName()));
    }
}
Also used : Method(java.lang.reflect.Method) TreeMap(java.util.TreeMap) TranslatorProperty(org.teiid.translator.TranslatorProperty) TeiidException(org.teiid.core.TeiidException)

Aggregations

Method (java.lang.reflect.Method)3 TranslatorProperty (org.teiid.translator.TranslatorProperty)3 TreeMap (java.util.TreeMap)1 TeiidException (org.teiid.core.TeiidException)1