I have created a testcase in branch Dev2X that shows how to transform a UML model after it has been read from the XMI file. The testcase is in:
test/src/org/andromda/core/mdr/MDRepositoryTransformationTest One set of javadocs to look at that might help understand the example is at: http://www.gentleware.com/support/developer/jmi-uml1.4/org/omg/uml/modelmana gement/Model.html Notice the import list in the code. There is no explicit dependency upon the NetBeans Meta Data Repository. Any complexity that is in the code is actually a direct result of the complexity of the UML1.4 meta-model. Therefore one might argue that no matter what technology you use to transform your UML model the complexity of the transformations would be pretty much the same. The main way that the transformation could be made simpler is if one were to dumb down the meta-model and use a meta-model that is simpler than UML1.4 . Of course a meta-model simpler than UML 1.4 might not be able to generate code for business processes, state machines, and use case driven test cases. The code for that testcase is: /* * Created on Jul 27, 2003 * */ package org.andromda.core.mdr; import java.io.IOException; import java.net.URL; import java.util.Collection; import java.util.Iterator; import junit.framework.TestCase; import org.andromda.core.TestModel; import org.andromda.core.common.RepositoryReadException; import org.omg.uml.UmlPackage; import org.omg.uml.foundation.core.Attribute; import org.omg.uml.foundation.core.ModelElement; import org.omg.uml.foundation.core.Namespace; import org.omg.uml.foundation.core.UmlClass; import org.omg.uml.modelmanagement.Model; import org.omg.uml.modelmanagement.ModelManagementPackage; /** * @author amowers * * */ public class MDRepositoryTransformationTest extends TestCase { private URL modelURL = null; private MDRepositoryFacade repository = null; /** * Constructor for MDRepositoryTransformationTest. * @param arg0 */ public MDRepositoryTransformationTest(String arg0) { super(arg0); } /* * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); if (modelURL == null) { modelURL = new URL(TestModel.XMI_FILE_URL); repository = new MDRepositoryFacade(); } } /** * Demonstrates how to dynamically add an attribute onto a class in * a model. * * It loads a model from XMI file, looks a class with a particular * fully qualified name and adds an attribute onto that class. * * @throws Exception */ public void testTransformModel() throws Exception { try { repository.readModel(modelURL); UmlPackage umlPackage = (UmlPackage) repository.getModel(); ModelManagementPackage modelManagementPackage = umlPackage.getModelManagement(); // A given XMI file can contain multiple models. // Use the first model in the XMI file Model model = (Model) (modelManagementPackage .getModel() .refAllOfType() .iterator() .next()); // look for a class with the name 'org.EntityBean' String[] fqn = { "org", "EntityBean" }; UmlClass umlClass = (UmlClass) getModelElement(model, fqn, 0); // create an attribute Attribute attribute = umlPackage.getCore().getAttribute().createAttribute(); attribute.setName("attributeAA"); // assign the attribute to the class attribute.setOwner(umlClass); } catch (IOException ioe) { assertNull(ioe.getMessage(), ioe); } catch (RepositoryReadException rre) { assertNull(rre.getMessage(), rre); } } private static ModelElement getModelElement( Namespace namespace, String[] fqn, int pos) { if ((namespace == null) || (fqn == null) || (pos > fqn.length)) { return null; } if (pos == fqn.length) { return namespace; } Collection elements = namespace.getOwnedElement(); for (Iterator i = elements.iterator(); i.hasNext();) { ModelElement element = (ModelElement) i.next(); if (element.getName().equals(fqn[pos])) { int nextPos = pos + 1; if (nextPos == fqn.length) { return element; } if (element instanceof Namespace) { return getModelElement((Namespace) element, fqn, nextPos); } return null; } } return null; } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); } } ------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 _______________________________________________ Andromda-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/andromda-devel
