KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > orm > jpa > persistenceunit > SpringPersistenceUnitInfo


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.orm.jpa.persistenceunit;
18
19 import javax.persistence.spi.ClassTransformer;
20
21 import org.springframework.instrument.classloading.LoadTimeWeaver;
22 import org.springframework.instrument.classloading.SimpleThrowawayClassLoader;
23 import org.springframework.util.ClassUtils;
24
25 /**
26  * Subclass of MutablePersistenceUnitInfo that adds instrumentation
27  * hooks based on Spring's LoadTimeWeaver abstraction.
28  *
29  * <p>This class is restricted to package visibility, in contrast
30  * to its superclass.
31  *
32  * @author Rod Johnson
33  * @author Juergen Hoeller
34  * @author Costin Leau
35  * @since 2.0
36  * @see #setLoadTimeWeaver
37  * @see PersistenceUnitManager
38  */

39 class SpringPersistenceUnitInfo extends MutablePersistenceUnitInfo {
40
41     private LoadTimeWeaver loadTimeWeaver;
42
43
44     /**
45      * Set the LoadTimeWeaver SPI strategy interface used by Spring
46      * to add instrumentation to the current class loader.
47      */

48     public void setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver) {
49         this.loadTimeWeaver = loadTimeWeaver;
50     }
51
52     public ClassLoader JavaDoc getClassLoader() {
53         if (this.loadTimeWeaver != null) {
54             return this.loadTimeWeaver.getInstrumentableClassLoader();
55         }
56         else {
57             return ClassUtils.getDefaultClassLoader();
58         }
59     }
60
61     /**
62      * Method called by PersistenceProvider to add instrumentation to
63      * the current environment.
64      */

65     public void addTransformer(ClassTransformer classTransformer) {
66         if (this.loadTimeWeaver == null) {
67             throw new IllegalStateException JavaDoc("Cannot apply class transformer without LoadTimeWeaver specified");
68         }
69         this.loadTimeWeaver.addTransformer(new ClassFileTransformerAdapter(classTransformer));
70     }
71
72     public ClassLoader JavaDoc getNewTempClassLoader() {
73         if (this.loadTimeWeaver != null) {
74             return this.loadTimeWeaver.getThrowawayClassLoader();
75         }
76         else {
77             return new SimpleThrowawayClassLoader(ClassUtils.getDefaultClassLoader());
78         }
79     }
80
81 }
82
Popular Tags