KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gcc > rmi > iiop > compiler > SkelFactory


1 /*
2  * Copyright 2004 The Apache Software Foundation or its licensors, as
3  * applicable.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19 package gcc.rmi.iiop.compiler;
20
21 import gcc.*;
22 import gcc.rmi.iiop.*;
23 import gcc.rmi.iiop.compiler.SkelCompiler;
24 import gcc.util.*;
25 import java.util.*;
26
27 public class SkelFactory
28 {
29     protected static SkelFactory _sf = new SkelFactory();
30
31     protected SkelFactory()
32     {
33     }
34
35     public static SkelFactory getInstance()
36     {
37         return _sf;
38     }
39
40     // private data
41

42     private static HashMap _skelClassMap;
43
44     // internal methods
45

46     protected void init()
47     {
48         _skelClassMap = new HashMap();
49     }
50
51     protected Class loadStub(Class remoteInterface)
52     {
53         String className = remoteInterface.getName();
54         String skelClassName = className + "_Skeleton";
55
56         /*
57         StubClass sc = new StubClass();
58         if (sc.skelClass == null)
59         {
60             // Try generating skel class now.
61             System.out.println( "TODO: StubFactory.loadStub(): className = " + className );
62             StubCompiler skelCompiler = StubCompiler.getInstance(remoteInterface);
63             sc.skelClass = skelCompiler.getStubClass();
64         }
65
66         if (sc.skelClass != null)
67         {
68             try
69             {
70                 sc.getInstance = sc.skelClass.getMethod("$getInstance", ArrayUtil.EMPTY_CLASS_ARRAY);
71             }
72             catch (Exception ex)
73             {
74                 throw new SystemException(ex);
75             }
76         }
77
78         return sc;
79         */

80
81         Class sc = null;
82         try
83         {
84             sc = Class.forName( skelClassName );
85             SkelCompiler skelCompiler = new SkelCompiler(sc);
86             sc = skelCompiler.getSkelClass();
87         }
88         catch( Exception ex )
89         {
90             throw new SystemException( ex );
91         }
92
93         return sc;
94     }
95
96     // public methods
97

98     public RemoteObject getSkel(Class remoteInterface)
99     {
100         System.out.println( "SkelFactory.getSkel(): remoteInterface: " + remoteInterface );
101         try
102         {
103             Class sc = (Class)_skelClassMap.get(remoteInterface);
104             if (sc == null)
105             {
106                 synchronized (_skelClassMap)
107                 {
108                     sc = (Class)_skelClassMap.get(remoteInterface);
109                     if (sc == null)
110                     {
111                         sc = loadStub(remoteInterface);
112                         _skelClassMap.put(remoteInterface, sc);
113                     }
114                 }
115             }
116             //return (ObjectRef)sc.getInstance.invoke(sc.skelClass, ArrayUtil.EMPTY_OBJECT_ARRAY);
117
return (RemoteObject)sc.newInstance();
118         }
119         catch (Exception ex)
120         {
121             throw new SystemException(ex);
122         }
123     }
124
125     public Object getSkel(String remoteInterface)
126     {
127         return getSkel(ThreadContext.loadClass(remoteInterface));
128     }
129 }
130
Popular Tags