KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > hibernate > H2PropertyDescriptorProperty


1 /*
2  * Copyright 2005 Joe Walker
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 package org.directwebremoting.hibernate;
17
18 import java.beans.PropertyDescriptor JavaDoc;
19
20 import net.sf.hibernate.LazyInitializationException;
21
22 import org.directwebremoting.extend.MarshallException;
23 import org.directwebremoting.extend.Property;
24 import org.directwebremoting.impl.PropertyDescriptorProperty;
25
26 /**
27  * A {@link Property} that catches hiberntate exceptions.
28  * This is useful for Hibernate 2 where lazy loading results in an exception
29  * and you are unable to detect and prevent this.
30  * @author Joe Walker [joe at getahead dot ltd dot uk]
31  */

32 public class H2PropertyDescriptorProperty extends PropertyDescriptorProperty
33 {
34     /**
35      * Simple constructor
36      * @param descriptor The PropertyDescriptor that we are proxying to
37      */

38     public H2PropertyDescriptorProperty(PropertyDescriptor JavaDoc descriptor)
39     {
40         super(descriptor);
41     }
42
43     /* (non-Javadoc)
44      * @see org.directwebremoting.impl.PropertyDescriptorProperty#getValue(java.lang.Object)
45      */

46     public Object JavaDoc getValue(Object JavaDoc bean) throws MarshallException
47     {
48         try
49         {
50             return super.getValue(bean);
51         }
52         catch (LazyInitializationException ex)
53         {
54             return null;
55         }
56         catch (Exception JavaDoc ex)
57         {
58             throw new MarshallException(bean.getClass(), ex);
59         }
60     }
61 }
62
Popular Tags