1 19 package org.netbeans.lib.jmi.xmi; 20 21 import java.util.*; 22 import javax.jmi.reflect.*; 23 import javax.jmi.model.*; 24 25 import org.w3c.dom.*; 26 27 import org.netbeans.api.mdr.*; 28 29 import org.netbeans.lib.jmi.util.*; 30 31 36 public abstract class XmiMofUtils extends XmiUtils implements XmiConstants { 37 38 39 40 41 public XmiMofUtils() { 42 } 43 44 public static StructuralFeature getMetaFeature(String attributeName, RefClass proxyClass) { 45 StructuralFeature result = null; 46 Object metaObject = null; 47 MofClass metaProxyClass = (MofClass)proxyClass.refMetaObject(); 48 try { 49 metaObject = metaProxyClass.lookupElementExtended( getShortName( attributeName ) ); 50 if ( metaObject instanceof StructuralFeature ) result = (StructuralFeature)metaObject; 51 } catch (javax.jmi.model.NameNotFoundException e) { 52 } 54 return result; 55 } 56 57 public static void showAllAttributes(Collection attributes) { 58 Logger.getDefault().log("Attributes - length : "+ attributes.size()); 59 for (Iterator it = attributes.iterator(); it.hasNext(); ) { 60 Object att = it.next(); 61 if (att instanceof ModelElement) 62 Logger.getDefault().log("Attributes : "+((ModelElement)att).getName() ); 63 else 64 if (att != null) 65 Logger.getDefault().log("Attributes : "+att + " - of class : " +att.getClass() ); 66 else 67 Logger.getDefault().log("Attributes : NULLLLLLLLL " ); 68 } 69 } 70 71 public static String showCollectionAsString(Collection attributes, String separator) { 72 String message = null; 73 for (Iterator it = attributes.iterator(); it.hasNext(); ) { 74 Object att = it.next(); 75 message = message+separator+message; 76 } 77 message = message.substring( message.indexOf( separator )+separator.length() ); 78 return message; 79 } 80 81 public static Collection getAllSupertypesContainedObjects(RefClass proxyClass) { 82 ArrayList result = new ArrayList(); 83 ArrayList allContainedObjects = new ArrayList(); 84 MofClass metaProxyClass = (MofClass)proxyClass.refMetaObject(); 85 List superClasses = metaProxyClass.allSupertypes(); 86 Namespace namespace = null; 87 for (Iterator it = superClasses.iterator(); it.hasNext(); ) { 88 namespace = (Namespace)it.next(); 89 allContainedObjects.addAll( namespace.getContents() ); 90 } 91 allContainedObjects.addAll( metaProxyClass.getContents() );; 92 for (Iterator it = allContainedObjects.iterator(); it.hasNext(); ) { 93 RefObject refObject = (RefObject)it.next(); 94 if ( (refObject instanceof Attribute) && ( !((Attribute)refObject).isDerived() ) ) result.add( refObject ); 95 } 96 allContainedObjects.clear(); 97 allContainedObjects = null; 98 return result; 99 } 100 101 public static Reference getReferenceMetaFeature(String referenceNodeName, RefClass proxyClass) { 102 Reference result = null; 103 StructuralFeature metaFeature = getMetaFeature(referenceNodeName, proxyClass); 104 if (metaFeature instanceof Reference) result = (Reference)metaFeature; 105 return result; 106 } 107 108 public static Attribute getAttributeMetaFeature(String referenceNodeName, RefClass proxyClass) { 109 Attribute result = null; 110 StructuralFeature metaFeature = getMetaFeature(referenceNodeName, proxyClass); 111 if (metaFeature instanceof Attribute) result = (Attribute)metaFeature; 112 return result; 113 } 114 } 115 | Popular Tags |