use of com.centurylink.mdw.common.translator.VariableTranslator in project mdw-designer by CenturyLinkCloud.
the class DesignerProxy method getVariableInfo.
/**
* Must be called from the UI thread.
*/
public VariableTypeVO getVariableInfo(final VariableInstanceInfo varInstInfo) {
String varType = varInstInfo.getType();
VariableTranslator varTrans = getVariableTranslator(varType);
final VariableTypeVO varTypeVO = new VariableTypeVO(0L, varType, varTrans == null ? null : varTrans.getClass().getName());
if (varInstInfo.getStringValue() != null && varTypeVO.isJavaObjectType()) {
BusyIndicator.showWhile(MdwPlugin.getShell().getDisplay(), new Runnable() {
public void run() {
DocumentReference docRef = new DocumentReference(varInstInfo.getStringValue());
try {
Object obj = new JavaObjectTranslator().realToObject(getDocument(docRef).getContent());
varTypeVO.setVariableType(obj.getClass().getName());
varTypeVO.setUpdateable(obj instanceof SelfSerializable);
} catch (TranslationException ex) {
if (MdwPlugin.getSettings().isLogConnectErrors())
PluginMessages.log(ex);
try {
if (!project.checkRequiredVersion(6, 1, 1)) {
String path = "DocumentValue?format=xml&id=" + docRef.getDocumentId() + "&type=" + varTypeVO.getVariableType();
String resp = getRestfulServer().invokeResourceService(path);
Resource res = Resource.Factory.parse(resp, Compatibility.namespaceOptions());
for (Parameter param : res.getParameterList()) {
if ("className".equals(param.getName()))
varTypeVO.setVariableType(param.getStringValue());
else if ("isUpdateable".equals(param.getName()))
varTypeVO.setUpdateable(Boolean.parseBoolean(param.getStringValue()));
}
}
} catch (Exception ex2) {
throw new RuntimeException(ex2.getMessage(), ex2);
}
}
}
});
}
return varTypeVO;
}
use of com.centurylink.mdw.common.translator.VariableTranslator in project mdw-designer by CenturyLinkCloud.
the class DesignerProxy method getVariableTranslator.
private VariableTranslator getVariableTranslator(String varType) {
VariableTranslator vt = null;
VariableTypeVO vo = dataAccess.getVariableType(varType);
if (vo != null) {
try {
Class<? extends VariableTranslator> cl = Class.forName(vo.getTranslatorClass()).asSubclass(VariableTranslator.class);
vt = cl.newInstance();
} catch (Exception ex) {
// can't create translator
if (MdwPlugin.getSettings().isLogConnectErrors())
PluginMessages.log(ex);
}
}
return vt;
}
use of com.centurylink.mdw.common.translator.VariableTranslator in project mdw-designer by CenturyLinkCloud.
the class VariableHelper method isDocumentVariable.
/**
* This is another cheaper way for better guessing whether the variable
* is a document variable, when variable instance value is available
* @param vartype
* @param value variable instance value
* @return
*/
public static boolean isDocumentVariable(String vartype, String value) {
VariableTranslator translator;
VariableTypeVO vo = VariableTypeCache.getVariableTypeVO(vartype);
if (vo == null)
return false;
try {
Class<?> cl = Class.forName(vo.getTranslatorClass());
translator = (VariableTranslator) cl.newInstance();
return (translator instanceof DocumentReferenceTranslator);
} catch (Exception e) {
if (value == null)
return false;
return value.startsWith("DOCUMENT:");
}
}
use of com.centurylink.mdw.common.translator.VariableTranslator in project mdw-designer by CenturyLinkCloud.
the class DesignerProxy method isDocumentVariable.
private boolean isDocumentVariable(String type, String value) {
VariableTranslator translator;
VariableTypeVO vo = dataAccess.getVariableType(type);
if (vo == null)
return false;
try {
Class<?> cl = Class.forName(vo.getTranslatorClass());
translator = (VariableTranslator) cl.newInstance();
return (translator instanceof DocumentReferenceTranslator);
} catch (Exception e) {
if (value == null)
return false;
return value.startsWith("DOCUMENT:");
}
}
use of com.centurylink.mdw.common.translator.VariableTranslator in project mdw-designer by CenturyLinkCloud.
the class VariableHelper method isDocumentVariable.
/**
* Check if the variable type is of a document.
* Custom variable translators must be loaded from server to make
* the decision precise.
*
* @param vartype
* @param dao
* @return
*/
public static boolean isDocumentVariable(String vartype, DesignerDataAccess dao) {
VariableTranslator translator;
VariableTypeVO vo = VariableTypeCache.getVariableTypeVO(vartype);
if (vo == null)
return false;
try {
Class<?> cl = Class.forName(vo.getTranslatorClass());
translator = (VariableTranslator) cl.newInstance();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return (translator instanceof DocumentReferenceTranslator);
}
Aggregations