KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javacore > jmiimpl > javamodel > AnnotationTypeClassImpl


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.modules.javacore.jmiimpl.javamodel;
20
21 import java.util.List JavaDoc;
22 import org.netbeans.mdr.storagemodel.StorableClass;
23 import org.netbeans.jmi.javamodel.*;
24 import org.netbeans.mdr.handlers.ClassProxyHandler;
25 import org.netbeans.mdr.persistence.StorageException;
26 import org.netbeans.mdr.storagemodel.StorableBaseObject;
27 import org.netbeans.modules.javacore.ClassIndex;
28
29 /**
30  *
31  * @author Pavel Flaska
32  */

33 public abstract class AnnotationTypeClassImpl extends ClassProxyHandler implements AnnotationTypeClass {
34
35     /** Creates a new instance of AnnotationTypeClassImpl */
36     public AnnotationTypeClassImpl(StorableClass s) {
37         super(s);
38     }
39     
40     public AnnotationType createAnnotationType() {
41         return create(null, null, 0, null, null, null, null, null, null);
42     }
43     
44     public AnnotationType createAnnotationType(String JavaDoc name,
45                                                List JavaDoc annotations,
46                                                int modifiers,
47                                                String JavaDoc javadocText,
48                                                JavaDoc javadoc,
49                                                List JavaDoc contents,
50                                                MultipartId superClassName,
51                                                List JavaDoc interfaceNames,
52                                                List JavaDoc typeParameters)
53     {
54         return create(name, annotations, modifiers, javadocText, javadoc, contents, superClassName, interfaceNames, typeParameters);
55     }
56     
57     protected abstract AnnotationType super_createAnnotationType();
58     protected abstract AnnotationType super_createAnnotationType(String JavaDoc name,
59                                                List JavaDoc annotations,
60                                                int modifiers,
61                                                String JavaDoc javadocText,
62                                                JavaDoc javadoc,
63                                                List JavaDoc contents,
64                                                MultipartId superClassName,
65                                                List JavaDoc interfaceNames,
66                                                List JavaDoc typeParameters);
67     
68     public Type resolve(String JavaDoc name) {
69         if (name == null) return null; // throw new NullPointerException();
70

71         _lock(false);
72         try {
73             JavaModelPackage pkg = (JavaModelPackage) refImmediatePackage();
74             JavaClassClassImpl cls = (JavaClassClassImpl) pkg.getJavaClass();
75             JavaClass result = cls.resolveClass(name, true);
76
77             if (result == null || !(result instanceof AnnotationType)) {
78                 // annotation type was not found - create UnresolvedAnnotationType
79
UnresolvedAnnotationTypeClassImpl ann=(UnresolvedAnnotationTypeClassImpl)pkg.getUnresolvedAnnotationType();
80                 result = ann.resolveUnresolved(name);
81             }
82             return result;
83         } finally {
84             _unlock();
85         }
86     }
87     
88     protected SemiPersistentElement createTransient() {
89         try {
90             StorableBaseObject s = _getDelegate();
91             DeferredObject o = new DeferredObject(null, s.getMdrStorage(), s.getImmediatePackageId(), s.getOutermostPackageId(), s.getMetaObject(), (StorableClass) s, null, true);
92             SemiPersistentElement result = (SemiPersistentElement) _getRepository().getHandler(o);
93             return result;
94         } catch (StorageException e) {
95             throw new RuntimeException JavaDoc();
96         }
97     }
98     
99     public AnnotationTypeImpl create(String JavaDoc name, int modifiers, boolean isTransient) {
100         AnnotationTypeImpl result;
101         if (isTransient) {
102             result = (AnnotationTypeImpl) createTransient();
103             result.setName(name);
104             result.setModifiers(modifiers);
105         } else {
106             result = (AnnotationTypeImpl) super_createAnnotationType(name, null, modifiers, null, null, null, null, null, null);
107             if (name != null) {
108                 JavaModelPackage srcExtent = (JavaModelPackage) refOutermostPackage();
109                 ClassIndex index = ClassIndex.getIndex(srcExtent);
110                 index.addClass(result, name, result.getSimpleName());
111             }
112         }
113         return result;
114     }
115
116     private AnnotationTypeImpl create(String JavaDoc name,
117                                       List JavaDoc annotations,
118                                       int modifiers,
119                                       String JavaDoc javadocText,
120                                       JavaDoc javadoc,
121                                       List JavaDoc contents,
122                                       MultipartId superClassName,
123                                       List JavaDoc interfaceNames,
124                                       List JavaDoc typeParameters)
125     {
126         boolean fail = true;
127         _lock(true);
128         try {
129             AnnotationTypeImpl result = create(name, modifiers, false);
130             result.setNew();
131             result.setData(annotations, javadocText, javadoc);
132             fail = false;
133             return result;
134         } finally {
135             _unlock(fail);
136         }
137     }
138     
139 }
140
Popular Tags