KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > services > bytecode > VMTypeIdCacheable


1 /*
2
3    Derby - Class org.apache.derby.impl.services.bytecode.VMTypeIdCacheable
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.services.bytecode;
23
24 import org.apache.derby.iapi.services.cache.Cacheable;
25 import org.apache.derby.iapi.services.cache.CacheManager;
26
27 import org.apache.derby.iapi.services.sanity.SanityManager;
28
29 import org.apache.derby.iapi.services.classfile.ClassHolder;
30
31 /**
32  * This class implements a Cacheable for a Byte code generator cache of
33  * VMTypeIds. It maps a Java class or type name to a VM type ID.
34  */

35 class VMTypeIdCacheable implements Cacheable {
36     /* The VM name of the Java class name */
37     // either a Type (java type) or a String (method descriptor)
38
private Object JavaDoc descriptor;
39
40     /* This is the identity */
41     private Object JavaDoc key;
42
43     /* Cacheable interface */
44
45     /** @see Cacheable#clearIdentity */
46     public void clearIdentity() {
47     }
48
49     /** @see Cacheable#getIdentity */
50     public Object JavaDoc getIdentity() {
51         return key;
52     }
53
54     /** @see Cacheable#createIdentity */
55     public Cacheable createIdentity(Object JavaDoc key, Object JavaDoc createParameter) {
56         if (SanityManager.DEBUG) {
57             SanityManager.THROWASSERT("VMTypeIdCacheable.create() called!");
58         }
59         return this;
60     }
61
62     /** @see Cacheable#setIdentity */
63     public Cacheable setIdentity(Object JavaDoc key) {
64
65         this.key = key;
66         if (key instanceof String JavaDoc) {
67             /* The identity is the Java class name */
68             String JavaDoc javaName = (String JavaDoc) key;
69
70             /* Get the VM type name associated with the Java class name */
71             String JavaDoc vmName = ClassHolder.convertToInternalDescriptor(javaName);
72             descriptor = new Type(javaName, vmName);
73         }
74         else
75         {
76             descriptor = ((BCMethodDescriptor) key).buildMethodDescriptor();
77         }
78
79         return this;
80     }
81
82     /** @see Cacheable#clean */
83     public void clean(boolean remove) {
84         /* No such thing as a dirty cache entry */
85         return;
86     }
87
88     /** @see Cacheable#isDirty */
89     public boolean isDirty() {
90         /* No such thing as a dirty cache entry */
91         return false;
92     }
93
94     /*
95     ** Class specific methods.
96     */

97
98     /**
99      * Get the VM Type name (java/lang/Object) that is associated with this Cacheable
100      */

101
102     Object JavaDoc descriptor() {
103         return descriptor;
104     }
105 }
106
Popular Tags