1 package org.andromda.core.anttasks;
2
3 import org.andromda.core.common.RepositoryFacade;
4 import org.andromda.core.common.ScriptHelper;
5 import org.apache.tools.ant.BuildException;
6
7 /***
8 *
9 * This class implements the <code><repository></code> tag
10 * which can used within the ant <code><andromda></code> tag
11 * to configure androMDA to use a different object model repository.
12 *
13 * <p> One application of this tag is that it supports the
14 * possibility of loading an object model from a source other
15 * than an XMI file. It could implemented by: <p>
16 *
17 * <ul>
18 * <li> introducing a new class that extends
19 * org.andromda.core.mdr.MDRespositoryFacade </li>
20 * <li> overriding the readModel(URL) method so
21 * that it reads the object model from the new object model source </li>
22 * <li> storing the results of the object model
23 * read into the MDR UML v1.4 repository </li>
24 * </ul>
25 *
26 * @author <A HREF="http://www.amowers.com">Anthony Mowers</A>
27 *
28 */
29 public class RepositoryConfiguration
30 {
31 private static final String DEFAULT_REPOSITORY_CLASSNAME =
32 "org.andromda.core.mdr.MDRepositoryFacade";
33 private static final String DEFAULT_SCRIPT_HELPER_CLASSNAME =
34 "org.andromda.core.simpleuml.SimpleOOHelper";
35 private Class repositoryClass = null;
36 private Class scriptHelperClass = null;
37
38
39 /***
40 * Sets the name of the class to use as the repository. The
41 * class must implement the RepositoryFacade interface.
42 *
43 * @see org.andromda.core.common.RepositoryFacade
44 *
45 * @param repositoryClassName
46 */
47 public void setClassname(String repositoryClassName)
48 {
49 try
50 {
51 repositoryClass = Class.forName(repositoryClassName);
52 }
53 catch (ClassNotFoundException cnfe)
54 {
55 throw new BuildException(cnfe);
56 }
57
58 }
59
60 /***
61 * Sets the name of the class that is used by AndroMDA to
62 * access object model elements from within he repository. The
63 * class must implement the ScriptHelper interface.
64 *
65 * <p> Unless specified otherwise by use of the
66 * <code><template></code> tag this transformer
67 * object will be the object used the code generation scripts
68 * to access the object model. </p>
69 *
70 * @see TemplateConfiguration
71 * @see org.andromda.core.common.ScriptHelper
72 *
73 * @param scriptHelperClassName
74 */
75 public void setTransformClassname(String scriptHelperClassName)
76 {
77 try
78 {
79 scriptHelperClass = Class.forName(scriptHelperClassName);
80 }
81 catch (ClassNotFoundException cnfe)
82 {
83 throw new BuildException(cnfe);
84 }
85 }
86
87 /***
88 * Creates an instance of the repository.
89 *
90 * @return RepositoryFacade
91 */
92 public RepositoryFacade createRepository()
93 {
94 RepositoryFacade instance = null;
95
96 try
97 {
98 if (repositoryClass == null)
99 {
100
101 repositoryClass =
102 Class.forName(DEFAULT_REPOSITORY_CLASSNAME);
103 }
104 instance = (RepositoryFacade) repositoryClass.newInstance();
105 }
106 catch (ClassNotFoundException cnfe)
107 {
108 throw new BuildException(
109 DEFAULT_REPOSITORY_CLASSNAME + " class could not be found",
110 cnfe);
111 }
112 catch (InstantiationException ie)
113 {
114 throw new BuildException(
115 "could not instantiate repository " + repositoryClass);
116 }
117 catch (IllegalAccessException iae)
118 {
119 throw new BuildException(
120 "unable to access repository constructor "
121 + repositoryClass
122 + "()");
123 }
124
125 return instance;
126 }
127
128
129
130 /***
131 * Creates an instance of the object model Transfomer.
132 *
133 * @return ScriptHelper
134 */
135 public ScriptHelper createTransform()
136 {
137 ScriptHelper instance = null;
138
139 try
140 {
141 if (scriptHelperClass == null)
142 {
143
144 scriptHelperClass =
145 Class.forName(DEFAULT_SCRIPT_HELPER_CLASSNAME);
146 }
147 instance = (ScriptHelper) scriptHelperClass.newInstance();
148 }
149 catch (ClassNotFoundException cnfe)
150 {
151 throw new BuildException(
152 DEFAULT_SCRIPT_HELPER_CLASSNAME + " class could not be found",
153 cnfe);
154 }
155 catch (InstantiationException ie)
156 {
157 throw new BuildException(
158 "could not instantiate transform " + scriptHelperClass);
159 }
160 catch (IllegalAccessException iae)
161 {
162 throw new BuildException(
163 "unable to access transform constructor "
164 + scriptHelperClass
165 + "()");
166 }
167
168 return instance;
169 }
170
171 }