View Javadoc

1   package org.andromda.core.simpleuml;
2   
3   import java.lang.reflect.Method;
4   import java.util.Collection;
5   import java.util.Iterator;
6   import java.util.Vector;
7   
8   import org.andromda.core.uml14.UMLStaticHelper;
9   import org.omg.uml.UmlPackage;
10  
11  /***
12   * dynamic proxy for a Model: dynamically supports the UMLModel, 
13   * and org.omg.uml.UmlPackage interfaces.
14   * 
15   * @author <A HREF="http://www.amowers.com">Anthony Mowers</A>
16   *.
17   */
18  public class PModel 
19      implements 
20          UMLModel,
21          java.lang.reflect.InvocationHandler 
22  {
23      
24      private UmlPackage model;
25      private UMLStaticHelper scriptHelper;
26  
27  	public Collection getPackages() {
28          Collection packages = 
29              model.getModelManagement().getUmlPackage().refAllOfType();
30          Collection packageProxies = new Vector();
31          
32          for (Iterator i= packages.iterator();i.hasNext();)
33          {
34              org.omg.uml.modelmanagement.UmlPackage o = 
35                  (org.omg.uml.modelmanagement.UmlPackage)i.next();
36              o = PPackage.newInstance(scriptHelper,o);
37              packageProxies.add(o);
38          }
39          
40          return</strong> packageProxies;
41  	}
42  
43      public static UmlPackage newInstance(
44          UMLStaticHelper scriptHelper,
45          UmlPackage model)
46      {
47          Class[] interfaces = new Class[]
48              {
49              UMLModel.class,
50              UmlPackage.class
51              };
52  
53          return (UmlPackage)java.lang.reflect.Proxy.newProxyInstance(
54              model.getClass().getClassLoader(),
55              interfaces,
56              new PModel(model, scriptHelper));
57      }
58  
59  
60      
61      private PModel(
62          UmlPackage model,
63          UMLStaticHelper scriptHelper)
64      {
65          this.model = model;
66          this.scriptHelper = scriptHelper;
67      }
68  
69      public Object invoke(Object proxy, Method m, Object[] args)
70          throws Throwable
71      {
72          if (m.getDeclaringClass().isAssignableFrom(this.getClass()))
73          {
74              return m.invoke(this, args);
75          }
76  
77          return m.invoke(model, args);
78      }
79  }