no message
[mono.git] / mcs / class / corlib / System.Runtime.Remoting / Identity.cs
1 //
2 // System.Runtime.Remoting.Identity.cs
3 //
4 // Author: Lluis Sanchez Gual (lsg@ctv.es)
5 //
6 // (C) 2002, Lluis Sanchez Gual
7 //
8
9 using System.Runtime.Remoting.Messaging;
10 using System.Runtime.Remoting.Proxies;
11 using System.Runtime.Remoting.Contexts;
12
13 namespace System.Runtime.Remoting
14 {
15         internal class Identity
16         {
17                 // An Identity object holds remoting information about
18                 // an object. It can be used to store client side information
19                 // (information about how to reach the remote server),
20                 // and also to store server side information (information
21                 // about how to dispatch messages to the object in the server).
22
23                 // The object that this identity represents. Can be a MarshalByRefObject
24                 // (if it is a server object) or a transparent proxy (if it is a client
25                 // proxy to a remote object).
26                 object _realObject;
27
28                 Type _objectType;
29
30                 // URI of the object
31                 string _objectUri;
32
33                 // Message sink to use to send a message to the remote server
34                 IMessageSink _clientSink = null;
35
36                 // Message sink used in the server to dispatch a message
37                 // to the server object
38                 IMessageSink _serverSink = null;
39                 Context _context;
40
41                 ObjRef _objRef = null;
42
43                 public Identity(string objectUri, Context context, Type objectType)
44                 {
45                         _objectUri = objectUri;
46                         _context = context;
47                         _objectType = objectType;
48                 }
49
50                 public ObjRef CreateObjRef (Type requestedType)
51                 {
52                         // fixme: handle requested_type         
53                         if (requestedType == null) requestedType = _objectType;
54                         ObjRef res = new ObjRef ((MarshalByRefObject)_realObject, requestedType);
55                         res.URI = _objectUri;
56                         _objRef = res;
57                         return res;
58                 }
59
60                 public bool IsFromThisAppDomain
61                 {
62                         get
63                         {
64                                 // fixme: what if it is contextbound?
65                                 return (_clientSink == null);
66                         }
67                 }
68
69                 public object RealObject
70                 {
71                         get     { return _realObject; }
72                         set { _realObject = value; }
73                 }
74
75                 public string ObjectUri
76                 {
77                         get { return _objectUri; }
78                 }
79
80                 public IMessageSink ClientSink
81                 {
82                         get { return _clientSink; }
83                         set { _clientSink = value; }
84                 }
85
86                 public IMessageSink ServerSink
87                 {
88                         get 
89                         { 
90                                 if (_serverSink == null) {
91                                         _serverSink = _context.CreateServerObjectSinkChain((MarshalByRefObject)_realObject);
92                                 }
93                                 return _serverSink; 
94                         }
95                 }
96
97                 public Context Context
98                 {
99                         get { return _context; }
100                 }
101         }
102 }