KickJava   Java API By Example, From Geeks To Geeks.

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


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.jmi.javamodel.*;
23 import org.netbeans.mdr.handlers.ClassProxyHandler;
24 import org.netbeans.mdr.persistence.StorageException;
25 import org.netbeans.mdr.storagemodel.StorableBaseObject;
26 import org.netbeans.mdr.storagemodel.StorableClass;
27 import org.netbeans.modules.javacore.ClassIndex;
28
29 /**
30  *
31  * @author Martin Matula
32  */

33 public abstract class JavaEnumClassImpl extends ClassProxyHandler implements JavaEnumClass {
34 // [TODO] this class should probably extend SemiPersistentClass, since not all enumerations
35
// are persistent (local enumerations are not)
36

37     /** Creates a new instance of JavaClassClassImpl */
38     public JavaEnumClassImpl(StorableClass s) {
39         super(s);
40     }
41     
42     /**
43      * The default factory operation used to create an instance object.
44      * @return The created instance object.
45      */

46     public JavaEnum createJavaEnum() {
47         return create(null, null, 0, null, null, null, null, null);
48     }
49     
50     public JavaEnum createJavaEnum(String JavaDoc name, List JavaDoc annotations, int modifiers, String JavaDoc javadocText, JavaDoc javadoc, List JavaDoc features, MultipartId superClassName, List JavaDoc interfaceNames, List JavaDoc typeArguments, List JavaDoc constants) {
51         return create(name, annotations, modifiers, javadocText, javadoc, features, interfaceNames, constants);
52     }
53     
54     protected abstract JavaEnum super_createJavaEnum(String JavaDoc name, List JavaDoc annotations, int modifiers, String JavaDoc javadocText, JavaDoc javadoc, List JavaDoc features, MultipartId superClassName, List JavaDoc interfaceNames, List JavaDoc typeArguments, List JavaDoc constants);
55     protected abstract JavaEnum super_createJavaEnum();
56     
57     private JavaEnumImpl create(String JavaDoc name, List JavaDoc annotations, int modifiers, String JavaDoc javadocText, JavaDoc javadoc, List JavaDoc features, List JavaDoc interfaceNames, List JavaDoc constants) {
58         boolean fail = true;
59         _lock(true);
60         try {
61             JavaEnumImpl result = create(name, modifiers, false);
62             result.setNew();
63             result.setData(annotations, javadocText, javadoc, constants, features, interfaceNames);
64             fail = false;
65             return result;
66         } finally {
67             _unlock(fail);
68         }
69     }
70
71     protected SemiPersistentElement createTransient() {
72         try {
73             StorableBaseObject s = _getDelegate();
74             DeferredObject o = new DeferredObject(null, s.getMdrStorage(), s.getImmediatePackageId(), s.getOutermostPackageId(), s.getMetaObject(), (StorableClass) s, null, true);
75             SemiPersistentElement result = (SemiPersistentElement) _getRepository().getHandler(o);
76             return result;
77         } catch (StorageException e) {
78             throw new RuntimeException JavaDoc();
79         }
80     }
81
82     public JavaEnumImpl create(String JavaDoc name, int modifiers, boolean isTransient) {
83         JavaEnumImpl result;
84         if (isTransient) {
85             result = (JavaEnumImpl) createTransient();
86             boolean changes = result.disableChanges;
87             result.disableChanges = true;
88             try {
89                 result.setName(name);
90                 result.setModifiers(modifiers);
91             } finally {
92                 result.disableChanges = changes;
93             }
94         } else {
95             result = (JavaEnumImpl) super_createJavaEnum(name, null, modifiers, null, null, null, null, null, null, null);
96             if (name != null) {
97                 JavaModelPackage srcExtent = (JavaModelPackage) refImmediatePackage();
98                 ClassIndex index = ClassIndex.getIndex(srcExtent);
99                 index.addClass(result, name, result.getSimpleName());
100             }
101         }
102         return result;
103     }
104     
105     public org.netbeans.jmi.javamodel.Type resolve(java.lang.String JavaDoc name) {
106         JavaModelPackage pkg = (JavaModelPackage) refImmediatePackage();
107         return pkg.getType().resolve(name);
108     }
109 }
110
Popular Tags