| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hiveboard.util; |
| 16 | |
| 17 | import java.util.Map; |
| 18 | |
| 19 | import org.apache.commons.logging.Log; |
| 20 | |
| 21 | import net.sourceforge.hiveremoting.caucho.CauchoSerializerFactory; |
| 22 | |
| 23 | import com.caucho.hessian.io.Deserializer; |
| 24 | import com.caucho.hessian.io.HessianProtocolException; |
| 25 | |
| 26 | /** |
| 27 | * Special Caucho <code>SerializerFactory</code> used exclusively during abbot |
| 28 | * GUI testing to work around some class loading problems during tests. |
| 29 | * @author Jean-Francois Poilpret |
| 30 | */ |
| 31 | public class GuiTestingCauchoSerializerFactory extends CauchoSerializerFactory |
| 32 | { |
| 33 | public GuiTestingCauchoSerializerFactory(Map config, Log logger) |
| 34 | { |
| 35 | super(config, logger); |
| 36 | _loader = getClass().getClassLoader(); |
| 37 | } |
| 38 | |
| 39 | // CSOFF: IllegalCatchCheck |
| 40 | @Override public Deserializer getDeserializer(String type) |
| 41 | throws HessianProtocolException |
| 42 | { |
| 43 | ClassLoader loader = Thread.currentThread().getContextClassLoader(); |
| 44 | try |
| 45 | { |
| 46 | Thread.currentThread().setContextClassLoader(_loader); |
| 47 | Deserializer result = super.getDeserializer(type); |
| 48 | if (result == null) |
| 49 | { |
| 50 | _logger.debug("getDeserializer(\"" + type + "\") = null"); |
| 51 | } |
| 52 | return result; |
| 53 | } |
| 54 | catch (HessianProtocolException e) |
| 55 | { |
| 56 | _logger.error("getDeserializer(\"" + type + "\")", e); |
| 57 | throw e; |
| 58 | } |
| 59 | catch (RuntimeException e) |
| 60 | { |
| 61 | _logger.error("getDeserializer(\"" + type + "\")", e); |
| 62 | throw e; |
| 63 | } |
| 64 | finally |
| 65 | { |
| 66 | Thread.currentThread().setContextClassLoader(loader); |
| 67 | } |
| 68 | } |
| 69 | // CSON: IllegalCatchCheck |
| 70 | |
| 71 | private final ClassLoader _loader; |
| 72 | } |