KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > cglib > proxysample > ProxySample


1 /*
2  * Copyright 2003 The Apache Software Foundation
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 net.sf.cglib.proxysample;
17
18 import java.lang.reflect.InvocationHandler JavaDoc;
19 import java.lang.reflect.UndeclaredThrowableException JavaDoc;
20
21 public final class ProxySample implements ProxySampleInterface_ReturnsObject, ProxySampleInterface_ReturnsBasic {
22     
23     private InvocationHandler JavaDoc handler = null;
24
25     protected ProxySample(InvocationHandler JavaDoc handler) {
26         this.handler = handler;
27     }
28
29     public String JavaDoc getKala(String JavaDoc kalamees) throws Exception JavaDoc {
30         String JavaDoc result = null;
31         try {
32             // invocation is also generated
33
result = (String JavaDoc) handler.invoke(this, ProxySampleInterface_ReturnsObject.class.getMethod("getKala", new Class JavaDoc[] {String JavaDoc.class}), new Object JavaDoc[] {kalamees});
34         } catch (ClassCastException JavaDoc e) {
35             throw e;
36         } catch (NoSuchMethodException JavaDoc e) {
37             throw new Error JavaDoc(e.getMessage());
38         } catch (RuntimeException JavaDoc e) {
39             throw e;
40         } catch (Exception JavaDoc e) {
41             // generated: catch the exception throwed by interface method and re-throw it
42
throw e;
43         } catch (Error JavaDoc e) {
44             throw e;
45         } catch (Throwable JavaDoc e) {
46             throw new UndeclaredThrowableException JavaDoc(e);
47         }
48         return result;
49     }
50
51     public int getKala(float kalamees) {
52         Integer JavaDoc result = null;
53         try {
54             // invocation is also generated
55
result = (Integer JavaDoc) handler.invoke(this, ProxySampleInterface_ReturnsBasic.class.getMethod("getKala", new Class JavaDoc[] {Float.TYPE}), new Object JavaDoc[] {new Float JavaDoc(kalamees)});
56         } catch (ClassCastException JavaDoc e) {
57             throw e;
58         } catch (NoSuchMethodException JavaDoc e) {
59             // ignore, the method has to be found, as this class is generated
60
} catch (RuntimeException JavaDoc e) {
61             throw e;
62         } catch (Error JavaDoc e) {
63             throw e;
64         } catch (Throwable JavaDoc e) {
65             throw new UndeclaredThrowableException JavaDoc(e);
66         }
67         return result.intValue();
68     }
69
70     /**
71      * @see java.lang.Object#toString()
72      */

73     public String JavaDoc toString() {
74         String JavaDoc result = null;
75         try {
76             // invocation is also generated
77
result = (String JavaDoc) handler.invoke(this, Object JavaDoc.class.getMethod("toString", null), null);
78         } catch (ClassCastException JavaDoc e) {
79             throw e;
80         } catch (NoSuchMethodException JavaDoc e) {
81             // ignore, the method has to be found, as this class is generated
82
} catch (RuntimeException JavaDoc e) {
83             throw e;
84         } catch (Error JavaDoc e) {
85             throw e;
86         } catch (Throwable JavaDoc e) {
87             throw new UndeclaredThrowableException JavaDoc(e);
88         }
89         return result;
90     }
91
92 }
93
Popular Tags