001: /*
002:
003: Derby - Class org.apache.derby.impl.services.bytecode.VMTypeIdCacheable
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.services.bytecode;
023:
024: import org.apache.derby.iapi.services.cache.Cacheable;
025: import org.apache.derby.iapi.services.cache.CacheManager;
026:
027: import org.apache.derby.iapi.services.sanity.SanityManager;
028:
029: import org.apache.derby.iapi.services.classfile.ClassHolder;
030:
031: /**
032: * This class implements a Cacheable for a Byte code generator cache of
033: * VMTypeIds. It maps a Java class or type name to a VM type ID.
034: */
035: class VMTypeIdCacheable implements Cacheable {
036: /* The VM name of the Java class name */
037: // either a Type (java type) or a String (method descriptor)
038: private Object descriptor;
039:
040: /* This is the identity */
041: private Object key;
042:
043: /* Cacheable interface */
044:
045: /** @see Cacheable#clearIdentity */
046: public void clearIdentity() {
047: }
048:
049: /** @see Cacheable#getIdentity */
050: public Object getIdentity() {
051: return key;
052: }
053:
054: /** @see Cacheable#createIdentity */
055: public Cacheable createIdentity(Object key, Object createParameter) {
056: if (SanityManager.DEBUG) {
057: SanityManager
058: .THROWASSERT("VMTypeIdCacheable.create() called!");
059: }
060: return this ;
061: }
062:
063: /** @see Cacheable#setIdentity */
064: public Cacheable setIdentity(Object key) {
065:
066: this .key = key;
067: if (key instanceof String) {
068: /* The identity is the Java class name */
069: String javaName = (String) key;
070:
071: /* Get the VM type name associated with the Java class name */
072: String vmName = ClassHolder
073: .convertToInternalDescriptor(javaName);
074: descriptor = new Type(javaName, vmName);
075: } else {
076: descriptor = ((BCMethodDescriptor) key)
077: .buildMethodDescriptor();
078: }
079:
080: return this ;
081: }
082:
083: /** @see Cacheable#clean */
084: public void clean(boolean remove) {
085: /* No such thing as a dirty cache entry */
086: return;
087: }
088:
089: /** @see Cacheable#isDirty */
090: public boolean isDirty() {
091: /* No such thing as a dirty cache entry */
092: return false;
093: }
094:
095: /*
096: ** Class specific methods.
097: */
098:
099: /**
100: * Get the VM Type name (java/lang/Object) that is associated with this Cacheable
101: */
102:
103: Object descriptor() {
104: return descriptor;
105: }
106: }
|