KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > ejb > burlap > BurlapStub


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.ejb.burlap;
30
31 import com.caucho.hessian.io.HessianRemoteObject;
32 import com.caucho.hessian.io.HessianRemoteResolver;
33 import com.caucho.log.Log;
34 import com.caucho.vfs.Path;
35 import com.caucho.vfs.ReadStream;
36 import com.caucho.vfs.ReadWritePair;
37 import com.caucho.vfs.Vfs;
38 import com.caucho.vfs.WriteStream;
39
40 import java.io.IOException JavaDoc;
41 import java.rmi.RemoteException JavaDoc;
42 import java.util.logging.Level JavaDoc;
43 import java.util.logging.Logger JavaDoc;
44
45 /**
46  * Base class for generated object stubs.
47  */

48 public abstract class BurlapStub implements HessianRemoteObject {
49   private static final Logger JavaDoc log = Log.open(BurlapStub.class);
50   
51   protected String JavaDoc _url;
52   protected transient Path _urlPath;
53   protected transient BurlapClientContainer _client;
54   protected transient HessianRemoteResolver _resolver;
55
56   /**
57    * Initializes the stub with its remote information.
58    *
59    * @param client the client container
60    * @param handle the corresponding handle for the stub
61    */

62   void _init(String JavaDoc url, BurlapClientContainer client)
63   {
64     _url = url;
65     _urlPath = Vfs.lookup(url);
66
67     _burlap_setClientContainer(client);
68
69     if (log.isLoggable(Level.FINER))
70       log.finer("burlap stub:" + _urlPath + " " + this);
71   }
72
73   /* XXX:
74   public String getBurlapURL()
75   {
76     return _url;
77   }
78   */

79   public String JavaDoc getHessianURL()
80   {
81     return _url;
82   }
83
84   void _burlap_setURLPath(Path urlPath)
85   {
86     _urlPath = urlPath;
87     
88     if (log.isLoggable(Level.FINER))
89       log.finer("burlap setURL:" + _urlPath + " " + this);
90
91     _url = _urlPath.getURL();
92   }
93
94   void _burlap_setClientContainer(HessianRemoteResolver resolver)
95   {
96     _resolver = resolver;
97     if (resolver instanceof BurlapClientContainer)
98       _client = (BurlapClientContainer) resolver;
99   }
100
101   protected BurlapWriter _burlap_openWriter()
102     throws RemoteException JavaDoc
103   {
104     try {
105       ReadWritePair pair = _urlPath.openReadWrite();
106       ReadStream is = pair.getReadStream();
107       WriteStream os = pair.getWriteStream();
108
109       if (_client != null) {
110     String JavaDoc auth = _client.getBasicAuthentication();
111     if (auth != null)
112       os.setAttribute("Authorization", auth);
113       }
114
115       BurlapWriter out = new BurlapWriter(is, os);
116
117       out.setRemoteResolver(_resolver);
118
119       return out;
120     } catch (IOException JavaDoc e) {
121       throw new RemoteException JavaDoc(String.valueOf(e));
122     }
123   }
124
125   protected void _burlap_freeWriter(BurlapWriter out)
126     throws IOException JavaDoc
127   {
128     out.close();
129   }
130 }
131
Popular Tags