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.foundation.core.ModelElement; 10 import org.omg.uml.foundation.core.TaggedValue; 11 12 13 /*** 14 * dynamic proxy for a ModelElement: dynamically supports the UMLModelElement, 15 * and org.omg.uml.foundation.core.ModelElement interfaces. 16 * 17 *@author <A HREF="http://www.amowers.com">Anthony Mowers</A> 18 */ 19 public class PModelElement 20 implements 21 java.lang.reflect.InvocationHandler, 22 UMLModelElement 23 { 24 protected ModelElement modelElement; 25 protected UMLStaticHelper scriptHelper; 26 27 public static ModelElement newInstance( 28 UMLStaticHelper scriptHelper, 29 ModelElement modelElement) 30 { 31 Class[] interfaces = { 32 UMLClassifier.class, 33 ModelElement.class 34 }; 35 36 return (ModelElement)java.lang.reflect.Proxy.newProxyInstance( 37 modelElement.getClass().getClassLoader(), 38 interfaces, 39 new PModelElement(modelElement, scriptHelper)); 40 } 41 42 protected PModelElement( 43 ModelElement modelElement, 44 UMLStaticHelper scriptHelper) 45 { 46 this.scriptHelper = scriptHelper; 47 this.modelElement = modelElement; 48 } 49 50 51 public Object invoke(Object proxy, Method m, Object[] args) 52 throws Throwable 53 { 54 if (m.getDeclaringClass().isAssignableFrom(this.getClass())) 55 { 56 return m.invoke(this, args); 57 } 58 59 return m.invoke(modelElement, args); 60 } 61 62 public Collection getTaggedValues() 63 { 64 Collection taggedValues = scriptHelper.getTaggedValues(modelElement); 65 Collection taggedValueProxies = new Vector(); 66 67 for (Iterator i = taggedValues.iterator(); i.hasNext(); ) 68 { 69 TaggedValue taggedValue = (TaggedValue)i.next(); 70 taggedValueProxies.add( 71 PTaggedValue.newInstance(scriptHelper,taggedValue) 72 ); 73 } 74 75 76 return taggedValueProxies; 77 } 78 79 public Object getId() 80 { 81 return this.modelElement; 82 } 83 } 84