01: package org.andromda.core.translation.library;
02:
03: import java.util.LinkedHashMap;
04: import java.util.Map;
05:
06: import org.andromda.core.common.BasePlugin;
07: import org.andromda.core.common.ClassUtils;
08: import org.andromda.core.common.ComponentContainer;
09: import org.andromda.core.common.ExceptionUtils;
10: import org.andromda.core.translation.Translator;
11:
12: /**
13: * The AndroMDA Translation Library implementation of the Plugin. Library instances are configured from
14: * <code>META-INF/andromda-translation-library.xml</code> files discovered on the classpath.
15: *
16: * @author Chad Brandon
17: */
18: public class Library extends BasePlugin {
19: private final Map libraryTranslations = new LinkedHashMap();
20:
21: /**
22: * The default Library constructor.
23: */
24: public Library() {
25: super ();
26: }
27:
28: /**
29: * Adds a new LibraryTranslation.
30: *
31: * @param libraryTranslation
32: */
33: public void addLibraryTranslation(
34: final LibraryTranslation libraryTranslation) {
35: ExceptionUtils.checkNull("libraryTranslation",
36: libraryTranslation);
37: libraryTranslation.setLibrary(this );
38: this .libraryTranslations.put(libraryTranslation.getName(),
39: libraryTranslation);
40: }
41:
42: /**
43: * Gets the LibraryTranslation instances (keyed by name) which are part of this Library.
44: *
45: * @return Map
46: */
47: public Map getLibraryTranslations() {
48: return this .libraryTranslations;
49: }
50:
51: /**
52: * Retrieves the LibraryTranslation with the specified name.
53: *
54: * @param name
55: * @return LibraryTranslation the LibraryTranslation corresponding to the <code>name</code>.
56: */
57: public LibraryTranslation getLibraryTranslation(final String name) {
58: ExceptionUtils.checkEmpty("name", name);
59: return (LibraryTranslation) this .libraryTranslations.get(name);
60: }
61:
62: /**
63: * Sets the <cod>translatorClass</code> that will perform the translation processing.
64: *
65: * @param translatorClass the Class for the Translator implementation.
66: */
67: public void setTranslator(final String translatorClass) {
68: try {
69: ComponentContainer.instance().registerDefaultComponent(
70: Translator.class,
71: ClassUtils.loadClass(translatorClass));
72: } catch (final Throwable throwable) {
73: throw new LibraryException(throwable);
74: }
75: }
76:
77: /**
78: * @see org.andromda.core.common.BasePlugin#populateTemplateContext(java.util.Map)
79: */
80: public void populateTemplateContext(final Map templateContext) {
81: super.populateTemplateContext(templateContext);
82: }
83: }
|