1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.services.bytecode.VMTypeIdCacheable |
4 | |
5 | Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.impl.services.bytecode; |
22 | |
23 | import org.apache.derby.iapi.services.cache.Cacheable; |
24 | import org.apache.derby.iapi.services.cache.CacheManager; |
25 | |
26 | import org.apache.derby.iapi.services.sanity.SanityManager; |
27 | |
28 | import org.apache.derby.iapi.services.classfile.ClassHolder; |
29 | |
30 | /** |
31 | * This class implements a Cacheable for a Byte code generator cache of |
32 | * VMTypeIds. It maps a Java class or type name to a VM type ID. |
33 | */ |
34 | class VMTypeIdCacheable implements Cacheable { |
35 | /* The VM name of the Java class name */ |
36 | // either a Type (java type) or a String (method descriptor) |
37 | private Object descriptor; |
38 | |
39 | /* This is the identity */ |
40 | private Object key; |
41 | |
42 | /* Cacheable interface */ |
43 | |
44 | /** @see Cacheable#clearIdentity */ |
45 | public void clearIdentity() { |
46 | } |
47 | |
48 | /** @see Cacheable#getIdentity */ |
49 | public Object getIdentity() { |
50 | return key; |
51 | } |
52 | |
53 | /** @see Cacheable#createIdentity */ |
54 | public Cacheable createIdentity(Object key, Object createParameter) { |
55 | if (SanityManager.DEBUG) { |
56 | SanityManager.THROWASSERT("VMTypeIdCacheable.create() called!"); |
57 | } |
58 | return this; |
59 | } |
60 | |
61 | /** @see Cacheable#setIdentity */ |
62 | public Cacheable setIdentity(Object key) { |
63 | |
64 | this.key = key; |
65 | if (key instanceof String) { |
66 | /* The identity is the Java class name */ |
67 | String javaName = (String) key; |
68 | |
69 | /* Get the VM type name associated with the Java class name */ |
70 | String vmName = ClassHolder.convertToInternalDescriptor(javaName); |
71 | descriptor = new Type(javaName, vmName); |
72 | } |
73 | else |
74 | { |
75 | descriptor = ((BCMethodDescriptor) key).buildMethodDescriptor(); |
76 | } |
77 | |
78 | return this; |
79 | } |
80 | |
81 | /** @see Cacheable#clean */ |
82 | public void clean(boolean remove) { |
83 | /* No such thing as a dirty cache entry */ |
84 | return; |
85 | } |
86 | |
87 | /** @see Cacheable#isDirty */ |
88 | public boolean isDirty() { |
89 | /* No such thing as a dirty cache entry */ |
90 | return false; |
91 | } |
92 | |
93 | /* |
94 | ** Class specific methods. |
95 | */ |
96 | |
97 | /** |
98 | * Get the VM Type name (java/lang/Object) that is associated with this Cacheable |
99 | */ |
100 | |
101 | Object descriptor() { |
102 | return descriptor; |
103 | } |
104 | } |