01: /*
02:
03: Derby - Class org.apache.derby.iapi.services.loader.ClassFactoryContext
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (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.iapi.services.loader;
23:
24: import org.apache.derby.iapi.services.context.ContextImpl;
25: import org.apache.derby.iapi.services.context.ContextManager;
26: import org.apache.derby.iapi.services.property.PersistentSet;
27: import org.apache.derby.iapi.error.ExceptionSeverity;
28: import org.apache.derby.iapi.error.StandardException;
29:
30: /**
31: * Context that provides the correct ClassFactory for the
32: * current service. Allows stateless code to obtain the
33: * correct class loading scheme.
34: */
35: public abstract class ClassFactoryContext extends ContextImpl {
36:
37: public static final String CONTEXT_ID = "ClassFactoryContext";
38:
39: private final ClassFactory cf;
40:
41: protected ClassFactoryContext(ContextManager cm, ClassFactory cf) {
42:
43: super (cm, CONTEXT_ID);
44:
45: this .cf = cf;
46: }
47:
48: public final ClassFactory getClassFactory() {
49: return cf;
50: }
51:
52: /**
53: * Get the lock compatibility space to use for the
54: * transactional nature of the class loading lock.
55: * Used when the classpath changes or a database
56: * jar file is installed, removed or replaced.
57: */
58: public abstract Object getLockSpace() throws StandardException;
59:
60: /**
61: * Get the set of properties stored with this service.
62: */
63: public abstract PersistentSet getPersistentSet()
64: throws StandardException;
65:
66: /**
67: Get the mechanism to rad jar files. The ClassFactory
68: may keep the JarReader reference from the first class load.
69: */
70: public abstract JarReader getJarReader();
71:
72: /**
73: * Handle any errors. Only work here is to pop myself
74: * on a session or greater severity error.
75: */
76: public final void cleanupOnError(Throwable error) {
77: if (error instanceof StandardException) {
78:
79: StandardException se = (StandardException) error;
80:
81: if (se.getSeverity() >= ExceptionSeverity.SESSION_SEVERITY)
82: popMe();
83: }
84: }
85: }
|