KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > bridge > ClassesCollection


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
20 package org.netbeans.modules.java.bridge;
21
22 // import java.beans.PropertyChangeEvent;
23
import java.util.*;
24 import java.util.Iterator JavaDoc;
25
26 import org.openide.src.*;
27
28 import javax.jmi.reflect.RefObject;
29
30 import org.netbeans.jmi.javamodel.JavaClass;
31 import org.netbeans.modules.javacore.jmiimpl.javamodel.JavaClassImpl;
32
33 class ClassesCollection extends ObjectsCollection {
34
35     static final ClassElement[] EMPTY = new ClassElement[0];
36
37     public ClassesCollection(FeaturesCollection members) {
38         super (members);
39     }
40
41     public RefObject createFeature(RefObject parent, Element elem) {
42         return members.createClass ((ClassElement) elem);
43     }
44     
45     public Element [] getEmptyArray () {
46         return EMPTY;
47     }
48     
49     public String JavaDoc getPropertyName () {
50         return ElementProperties.PROP_CLASSES;
51     }
52     
53     public boolean isOfType (RefObject feature) {
54         return feature instanceof JavaClass;
55     }
56     
57     public Element createElement (RefObject innerClass) {
58         return (ClassElement) members.model.createInnerClass (members.getParentClass (), (JavaClass)innerClass).getElement ();
59     }
60  
61     public ClassElement getClass(Identifier name) {
62         members.repository.beginTrans(false);
63         try {
64             if (isValid()) {
65                 String JavaDoc simpleName = name.getName();
66                 JavaClass innerClass = members.javaClass.getInnerClass(simpleName, false);
67                 if (innerClass == null)
68                     return null;
69                 String JavaDoc fqn = name.getFullName ();
70                 if (!fqn.equals (name.getName ()) && !fqn.equals (innerClass.getName ()))
71                     return null;
72                 return (ClassElement) cachedElement (innerClass);
73             } else {
74                 return null;
75             }
76         } finally {
77             members.repository.endTrans();
78         }
79     }
80     
81     public ClassElement[] getClasses () {
82         return (ClassElement[]) getElements ();
83     }
84     
85     public boolean matches (Element elem, RefObject f) {
86         JavaClass javaClass = (JavaClass) f;
87         ClassElement classElem = (ClassElement) elem;
88         String JavaDoc simpleName = javaClass.getSimpleName();
89         return classElem.getName ().getName ().equals (simpleName);
90     }
91     
92     public int getPositionalValue () {
93         return ObjectsCollection.POS_VAL_CLASS;
94     }
95 }
96
Popular Tags