KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > enhancer > impl > MethodAction


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.jdo.api.persistence.enhancer.impl;
26
27 import java.util.Map JavaDoc;
28 //@olsen: disabled feature
29
/*
30 import java.util.Set;
31 import java.util.HashSet;
32 import java.util.Enumeration;
33 */

34
35 import com.sun.jdo.api.persistence.enhancer.classfile.*;
36
37 import com.sun.jdo.api.persistence.enhancer.util.Support;
38
39 //@olsen: cosmetics
40
//@olsen: moved: this class -> package impl
41
//@olsen: subst: /* ... */ -> // ...
42
//@olsen: subst: FilterEnv -> Environment
43
//@olsen: dropped parameter 'Environment env', use association instead
44
//@olsen: subst: Hashtable -> Map, Set, HashSet
45
//@olsen: subst: theClass, classAction -> ca
46
//@olsen: added: support for I18N
47
//@olsen: subst: FilterError -> UserException, assert()
48
//@olsen: removed: old, disabled ODI code
49

50
51 /**
52  * MethodAction controls the annotation actions applied to a single
53  * method of a class.
54  */

55 class MethodAction
56     //@olsen: not needed
57
//implements AnnotationConstants
58
extends Support {
59
60     /* hash table for lookup of known ok Generic attributes */
61 //@olsen: disabled feature
62
/*
63     private static Set safeGenericAttributes;
64
65     private static void addSafeAttribute(String attrName) {
66         safeGenericAttributes.add(attrName);
67     }
68
69     static {
70         safeGenericAttributes = new HashSet();
71
72         // Microsoft COM attributes
73         addSafeAttribute("COM_Class_type");
74         addSafeAttribute("COM_DispMethod");
75         addSafeAttribute("COM_ExposedAs");
76         addSafeAttribute("COM_ExposedAs_Group");
77         addSafeAttribute("COM_FuncDesc");
78         addSafeAttribute("COM_Guid");
79         addSafeAttribute("COM_GuidPool");
80         addSafeAttribute("COM_MapsTo");
81         addSafeAttribute("COM_MethodPool");
82         addSafeAttribute("COM_ProxiesTo");
83         addSafeAttribute("COM_Safety");
84         addSafeAttribute("COM_TypeDesc");
85         addSafeAttribute("COM_VarTypeDesc");
86         addSafeAttribute("COM_VtblMethod");
87     }
88 */

89
90     /* The parent ClassAction of this MethodAction */
91     //@olsen: made final
92
private final ClassAction ca;
93
94     /* The method to which the actions apply */
95     //@olsen: made final
96
private final ClassMethod theMethod;
97
98     /* The code annotater for the method */
99     //@olsen: made final
100
private final MethodAnnotater annotater;
101
102     /* Central repository for the options and classes */
103     //@olsen: added association
104
//@olsen: made final
105
private final Environment env;
106
107     /**
108      * Returns true if any code annotations need to be performed on
109      * this method.
110      */

111     boolean needsAnnotation() {
112         return annotater.needsAnnotation();
113     }
114
115     /**
116      * Returns the method for which this MethodAction applies
117      */

118     ClassMethod method() {
119         return theMethod;
120     }
121
122     /**
123      * Constructor
124      */

125     //@olsen: added parameter 'env' for association
126
MethodAction(ClassAction ca,
127                  ClassMethod method,
128                  Environment env) {
129         this.ca = ca;
130         theMethod = method;
131         this.env = env;
132         annotater = new MethodAnnotater(ca, method, env);
133     }
134
135     /**
136      * Examine the method to determine what actions are required
137      */

138     void check() {
139         annotater.checkMethod();
140 //@olsen: disabled feature
141
/*
142         if (env.verbose()) {
143             CodeAttribute codeAttr = theMethod.codeAttribute();
144             if (codeAttr != null) {
145                 Enumeration e = codeAttr.attributes().elements();
146                 while (e.hasMoreElements()) {
147                     ClassAttribute attr = (ClassAttribute) e.nextElement();
148                     if ((attr instanceof GenericAttribute) &&
149                         safeGenericAttributes.contains(attr.attrName().asString())) {
150                         String userClass = ca.classControl().userClassName();
151                         String msg = "method " + userClass +
152                             "." + theMethod.name().asString() +
153                             Descriptor.userMethodArgs(theMethod.signature().asString()) +
154                             " contains an unrecognized attribute of type " +
155                             attr.attrName().asString() + ". " +
156                             "Please check with Object Design support to see " +
157                             "whether this is a problem.";
158                         env.warning(msg, userClass);
159                     }
160                 }
161             }
162         }
163 */

164     }
165
166     /**
167      * Retarget class references according to the class name mapping
168      * table.
169      */

170 //@olsen: disabled feature
171
/*
172     void retarget(Map classTranslations) {
173         // No action needed currently
174     }
175 */

176
177     /**
178      * Perform annotations
179      */

180     void annotate() {
181         annotater.annotateMethod();
182     }
183 }
184
Popular Tags