use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.
the class TranslatorUtil method buildTranslatorMetadata.
public static VDBTranslatorMetaData buildTranslatorMetadata(ExecutionFactory factory, String moduleName) {
org.teiid.translator.Translator translator = factory.getClass().getAnnotation(org.teiid.translator.Translator.class);
if (translator == null) {
return null;
}
VDBTranslatorMetaData metadata = new VDBTranslatorMetaData();
String see = translator.deprecated();
if (see != null && see.length() > 0) {
// $NON-NLS-1$
metadata.addProperty("deprecated", see);
}
metadata.setName(translator.name());
metadata.setDescription(translator.description());
metadata.setExecutionFactoryClass(factory.getClass());
metadata.setModuleName(moduleName);
ExtendedPropertyMetadataList propertyDefns = new ExtendedPropertyMetadataList();
try {
Object instance = factory.getClass().newInstance();
buildTranslatorProperties(factory, metadata, propertyDefns, instance);
buildExtensionMetadataProperties(factory, metadata, propertyDefns, instance);
} catch (InstantiationException e) {
// ignore
} catch (IllegalAccessException e) {
// ignore
}
metadata.addAttchment(ExtendedPropertyMetadataList.class, propertyDefns);
return metadata;
}
use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.
the class TestTranslatorUtil method testBuildExecutionFactory.
@Test
public void testBuildExecutionFactory() throws Exception {
VDBTranslatorMetaData tm = new VDBTranslatorMetaData();
tm.addProperty("MyProperty", "correctly-assigned");
tm.setExecutionFactoryClass(MyTranslator.class);
MyTranslator my = (MyTranslator) TranslatorUtil.buildExecutionFactory(tm);
assertEquals("correctly-assigned", my.getMyProperty());
assertNull(my.other());
tm.addProperty("other", "foo");
tm.setExecutionFactoryClass(MyTranslator.class);
my = (MyTranslator) TranslatorUtil.buildExecutionFactory(tm);
assertEquals("foo", my.other());
}
use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.
the class TestTranslatorUtil method testImportProperties.
@Test
public void testImportProperties() throws Exception {
VDBTranslatorMetaData tm = new VDBTranslatorMetaData();
tm.setExecutionFactoryClass(MyTranslator.class);
tm.addProperty("MyProperty", "correctly-assigned");
MyTranslator my = (MyTranslator) TranslatorUtil.buildExecutionFactory(tm);
VDBTranslatorMetaData translator = TranslatorUtil.buildTranslatorMetadata(my, "my-module");
ExtendedPropertyMetadataList props = translator.getAttachment(ExtendedPropertyMetadataList.class);
ArrayList<ExtendedPropertyMetadata> importProperties = new ArrayList<ExtendedPropertyMetadata>();
for (ExtendedPropertyMetadata prop : props) {
if (prop.category().equals(PropertyType.IMPORT.name())) {
importProperties.add(prop);
}
}
assertEquals(1, importProperties.size());
assertEquals("importer.ImportProperty", importProperties.get(0).name);
assertEquals("java.lang.String", importProperties.get(0).dataType);
assertEquals(false, importProperties.get(0).required);
assertEquals(false, importProperties.get(0).advanced);
assertEquals("", importProperties.get(0).description);
assertEquals("Import Property", importProperties.get(0).displayName);
assertEquals(true, importProperties.get(0).editable);
assertEquals(false, importProperties.get(0).masked);
assertEquals("default-import-property", importProperties.get(0).defaultValue);
}
use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.
the class TestTranslatorUtil method testBuildExecutionFactoryWithDefaults.
@Test
public void testBuildExecutionFactoryWithDefaults() throws Exception {
VDBTranslatorMetaData tm = new VDBTranslatorMetaData();
VDBTranslatorMetaData parent = new VDBTranslatorMetaData();
parent.addProperty("myProperty", "default");
parent.setExecutionFactoryClass(MyTranslator.class);
tm.setParent(parent);
tm.addProperty("MyProperty", "correctly-assigned");
MyTranslator my = (MyTranslator) TranslatorUtil.buildExecutionFactory(tm);
assertEquals("correctly-assigned", my.getMyProperty());
}
use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.
the class TestTranslatorUtil method testBuildExecutionFactoryCaseInsensitive.
@Test
public void testBuildExecutionFactoryCaseInsensitive() throws Exception {
VDBTranslatorMetaData tm = new VDBTranslatorMetaData();
tm.addProperty("myproperty", "correctly-assigned");
tm.setExecutionFactoryClass(MyTranslator.class);
MyTranslator my = (MyTranslator) TranslatorUtil.buildExecutionFactory(tm);
assertEquals("correctly-assigned", my.getMyProperty());
}
Aggregations