KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > jmi > xmi > XmiMofUtils


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 /**
32  *
33  * @author msedliak
34  * @version
35  */

36 public abstract class XmiMofUtils extends XmiUtils implements XmiConstants {
37
38
39
40     /** Creates new BootReaderUtils */
41     public XmiMofUtils() {
42     }
43
44     public static StructuralFeature getMetaFeature(String JavaDoc attributeName, RefClass proxyClass) {
45         StructuralFeature result = null;
46         Object JavaDoc 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             //Logger.getDefault().log("Feature not found : "+attributeName);
53
}
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 JavaDoc 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 JavaDoc showCollectionAsString(Collection attributes, String JavaDoc separator) {
72         String JavaDoc message = null;
73         for (Iterator it = attributes.iterator(); it.hasNext(); ) {
74             Object JavaDoc 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 JavaDoc 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 JavaDoc 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