KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collection JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import javax.jmi.reflect.ConstraintViolationException;
27
28 import org.netbeans.jmi.javamodel.TagDefinition;
29 import org.netbeans.jmi.javamodel.TagDefinitionClass;
30 import org.netbeans.mdr.handlers.ClassProxyHandler;
31 import org.netbeans.mdr.persistence.MOFID;
32 import org.netbeans.mdr.persistence.StorageException;
33 import org.netbeans.mdr.storagemodel.StorableBaseObject;
34 import org.netbeans.mdr.storagemodel.StorableClass;
35 import org.netbeans.mdr.util.DebugException;
36
37 /** TagDefinition class proxy interface.implementation
38  *
39  * @author Vladimir Hudec
40  */

41 public abstract class TagDefinitionClassImpl extends ClassProxyHandler implements TagDefinitionClass {
42     private static final String JavaDoc MOFID_PREFIX = "tagdefinition:"; // NOI18N
43
private static Map JavaDoc allInstances;
44     
45     /** Creates a new instance of PackageClassImpl */
46     public TagDefinitionClassImpl(StorableClass s) {
47         super(s);
48     }
49
50     
51     public TagDefinition resolve(String JavaDoc name) {
52         if (name == null)
53             throw new ConstraintViolationException(this, refMetaObject(), "Cannot create instances of TagDefinition with null name supplied."); // NOI18N
54

55         initInstances();
56         try {
57             return _createTagDefinition(name);
58         }
59         catch (StorageException e) {
60             throw new DebugException();
61         }
62     }
63
64     /**
65      * Creates an instance object having attributes initialized by the passed
66      * values.
67      * @param name
68      * @return The created instance object.
69      */

70     public TagDefinition createTagDefinition(String JavaDoc name) {
71         return resolve(name);
72     }
73     
74     /**
75      * The default factory operation used to create an instance object.
76      * @return The created instance object.
77      */

78     public TagDefinition createTagDefinition() {
79         throw new ConstraintViolationException(this, refMetaObject(), "Cannot create instances of TagDefinition without name supplied."); // NOI18N
80
}
81     
82     
83     private TagDefinition _createTagDefinition(String JavaDoc name) throws StorageException {
84         TagDefinitionImpl tagDefinition = (TagDefinitionImpl) allInstances.get(name);
85         if (tagDefinition != null)
86             return tagDefinition;
87             
88         try {
89             StorableBaseObject s = _getDelegate();
90             DeferredObject o = new DeferredObject(new MOFID(name.hashCode(), MOFID_PREFIX + name), s.getMdrStorage(), s.getImmediatePackageId(), s.getOutermostPackageId(), s.getMetaObject(), (StorableClass) s, null);
91             tagDefinition = (TagDefinitionImpl) _getRepository().getHandler(o);
92             tagDefinition.name = name;
93             allInstances.put(name, tagDefinition);
94         }
95         catch (StorageException e) {
96             throw new DebugException();
97         }
98
99         return tagDefinition;
100     }
101     
102     private void initInstances() {
103         if (allInstances == null) {
104             allInstances=new HashMap JavaDoc();
105             try {
106                 _createTagDefinition("author"); // NOI18N
107
_createTagDefinition("version"); // NOI18N
108
_createTagDefinition("param"); // NOI18N
109
_createTagDefinition("return"); // NOI18N
110
_createTagDefinition("exception"); // NOI18N
111
_createTagDefinition("see"); // NOI18N
112
_createTagDefinition("since"); // NOI18N
113
_createTagDefinition("serial"); // NOI18N
114
_createTagDefinition("deprecated"); // NOI18N
115
}
116             catch (StorageException e) {
117                 throw new DebugException();
118             }
119         }
120     }
121     
122     protected Collection JavaDoc _allOfClass(boolean recursive) {
123         initInstances();
124         return Collections.unmodifiableCollection(allInstances.values());
125     }
126 }
127
Popular Tags