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);
}
}
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);
}
}
}
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()));
}
}
Aggregations