001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 021 package org.apache.geronimo.tomcat; 022 023 024 import java.lang.reflect.InvocationTargetException; 025 026 import javax.naming.Context; 027 import javax.naming.NamingException; 028 029 import org.apache.InstanceManager; 030 import org.apache.geronimo.j2ee.annotation.Holder; 031 032 /** 033 * @version $Rev: 543827 $ $Date: 2007-06-02 22:05:28 -0400 (Sat, 02 Jun 2007) $ 034 */ 035 public class TomcatInstanceManager implements InstanceManager { 036 037 private final Holder holder; 038 private final ClassLoader classLoader; 039 private final Context context; 040 041 042 public TomcatInstanceManager(Holder holder, ClassLoader classLoader, Context context) { 043 this.holder = holder; 044 this.classLoader = classLoader; 045 this.context = context; 046 } 047 048 public Object newInstance(String fqcn, ClassLoader classLoader) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException { 049 return holder.newInstance(fqcn, classLoader, context); 050 } 051 052 public Object newInstance(String className) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException { 053 return holder.newInstance(className, classLoader, context); 054 } 055 056 public void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException { 057 try { 058 holder.destroyInstance(o); 059 } catch (Exception e) { 060 throw new InvocationTargetException(e, "Attempted to destroy instance"); 061 } 062 } 063 064 public void newInstance(Object o) throws IllegalAccessException, InvocationTargetException, NamingException { 065 throw new UnsupportedOperationException("separate instantiation and injection is not supported"); 066 } 067 }