1 package org.andromda.core.translation;
2
3 import org.andromda.core.common.AndroMDALogger;
4 import org.andromda.core.common.ExceptionUtils;
5 import org.andromda.core.namespace.NamespaceComponents;
6 import org.andromda.core.translation.library.LibraryTranslation;
7 import org.andromda.core.translation.library.LibraryTranslationFinder;
8 import org.apache.log4j.Logger;
9
10
11
12
13
14
15
16
17 public class ExpressionTranslator
18 {
19 private static final Logger logger = Logger.getLogger(ExpressionTranslator.class);
20 private static final ExpressionTranslator translator = new ExpressionTranslator();
21
22
23
24
25
26
27 public static ExpressionTranslator instance()
28 {
29 return translator;
30 }
31
32
33
34
35
36 public void initialize()
37 {
38
39 AndroMDALogger.initialize();
40
41
42 NamespaceComponents.instance().discover();
43 }
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 public Expression translate(
62 final String translationName,
63 final String expression,
64 final Object contextElement)
65 {
66 ExceptionUtils.checkEmpty("translationName", translationName);
67 ExceptionUtils.checkEmpty("expression", expression);
68
69 Expression translatedExpression = null;
70 try
71 {
72 final LibraryTranslation libraryTranslation =
73 LibraryTranslationFinder.findLibraryTranslation(translationName);
74
75 if (libraryTranslation != null)
76 {
77 final Translator translator = libraryTranslation.getTranslator();
78 translatedExpression = translator.translate(translationName, expression, contextElement);
79 }
80 else
81 {
82 logger.error("ERROR! No translation found with name --> '" + translationName + '\'');
83 }
84 }
85 catch (final Throwable throwable)
86 {
87 throw new TranslatorException(throwable);
88 }
89 return translatedExpression;
90 }
91 }