KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Iterator JavaDoc;
23 import javax.jmi.reflect.RefObject;
24 import org.netbeans.jmi.javamodel.Field;
25 import org.openide.src.*;
26
27 class FieldsCollection extends ObjectsCollection {
28
29     static final FieldElement[] EMPTY = new FieldElement[0];
30
31     public FieldsCollection(FeaturesCollection members) {
32         super(members);
33     }
34
35     public RefObject createFeature(RefObject parent, Element elem) {
36         Field res = members.createField ((FieldElement) elem);
37         // res.setDeclaringClass ((JavaClass) parent);
38
return res;
39     }
40
41     public Element [] getEmptyArray () {
42         return EMPTY;
43     }
44     
45     public String JavaDoc getPropertyName () {
46         return ElementProperties.PROP_FIELDS;
47     }
48     
49     public boolean isOfType (RefObject feature) {
50         return feature instanceof Field;
51     }
52     
53     public Element createElement (RefObject field) {
54         return members.model.createField (members.getParentClass (), (Field)field).getElement ();
55     }
56     
57     public FieldElement getField(Identifier name) {
58         members.repository.beginTrans(false);
59         try {
60             if (isValid()) {
61                 String JavaDoc fieldName = name.getName();
62                 Field field = members.javaClass.getField (fieldName, false);
63                 return field == null ? null : (FieldElement)cachedElement (field);
64             } else {
65                 return null;
66             }
67         } finally {
68             members.repository.endTrans();
69         }
70     }
71     
72     public FieldElement [] getFields() {
73         return (FieldElement []) getElements ();
74     }
75         
76     public boolean matches (Element elem, RefObject f) {
77         Field field = (Field) f;
78         FieldElement fieldElem = (FieldElement) elem;
79         return field.getName ().equals (fieldElem.getName ().getName ());
80     }
81     
82     public int getPositionalValue () {
83         return ObjectsCollection.POS_VAL_FIELD;
84     }
85     
86 }
87
Popular Tags