Copied remotely
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Messaging / ConstructionCall.cs
1 //
2 // System.Runtime.Remoting.Messaging.ConstructionCall.cs
3 //
4 // Author: Lluis Sanchez Gual (lluis@ideary.com)
5 //
6 // (C) 2003, Lluis Sanchez Gual
7 //
8
9 //
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using System;
33 using System.Threading;
34 using System.Collections;
35 using System.Runtime.Remoting.Activation;
36 using System.Runtime.Serialization;
37 using System.Runtime.Remoting.Contexts;
38 using System.Runtime.Remoting.Proxies;
39
40 namespace System.Runtime.Remoting.Messaging
41 {
42         [Serializable] [CLSCompliant (false)]
43         public class ConstructionCall: MethodCall, IConstructionCallMessage
44         {
45                 IActivator _activator;
46                 object[] _activationAttributes;
47                 IList _contextProperties;
48                 Type _activationType;
49                 string _activationTypeName;
50                 bool _isContextOk;
51                 [NonSerialized] RemotingProxy _sourceProxy;
52
53                 public ConstructionCall(IMessage msg): base (msg)
54                 {
55                         _activationTypeName = TypeName;
56                         _isContextOk = true;
57                 }
58
59                 internal ConstructionCall (Type type)
60                 {
61                         _activationType = type;
62                         _activationTypeName = type.AssemblyQualifiedName;
63                         _isContextOk = true;
64                 }
65
66                 public ConstructionCall (Header[] headers): base (headers)
67                 {
68                 }
69
70                 internal ConstructionCall (SerializationInfo info, StreamingContext context): base (info, context)
71                 {
72                 }
73
74                 internal override void InitDictionary()
75                 {
76                         ConstructionCallDictionary props = new ConstructionCallDictionary (this);
77                         ExternalProperties = props;
78                         InternalProperties = props.GetInternalProperties();
79                 }
80
81                 internal bool IsContextOk
82                 {
83                         get { return _isContextOk; }
84                         set { _isContextOk = value; }
85                 }
86
87                 public Type ActivationType 
88                 {
89                         get 
90                         { 
91                                 if (_activationType == null) _activationType = Type.GetType (_activationTypeName);
92                                 return _activationType; 
93                         }
94                 }
95
96                 public string ActivationTypeName 
97                 {
98                         get { return _activationTypeName; }
99                 }
100
101                 public IActivator Activator 
102                 {
103                         get { return _activator; }
104                         set { _activator = value; }
105                 }
106
107                 public object [] CallSiteActivationAttributes 
108                 {
109                         get { return _activationAttributes; }
110                 }
111
112                 internal void SetActivationAttributes (object [] attributes)
113                 {
114                         _activationAttributes = attributes;
115                 }
116
117                 public IList ContextProperties 
118                 {
119                         get 
120                         {
121                                 if (_contextProperties == null) _contextProperties = new ArrayList ();
122                                 return _contextProperties; 
123                         }
124                 }
125
126                 internal override void InitMethodProperty(string key, object value)
127                 {
128                         switch (key)
129                         {
130                                 case "__Activator" : _activator = (IActivator) value; return;
131                                 case "__CallSiteActivationAttributes" : _activationAttributes = (object[]) value; return;
132                                 case "__ActivationType" : _activationType = (Type) value; return;
133                                 case "__ContextProperties" : _contextProperties = (IList) value; return;
134                                 case "__ActivationTypeName" : _activationTypeName = (string) value; return;
135                                 default: base.InitMethodProperty (key, value); return;
136                         }
137                 }
138
139                 public override void GetObjectData (SerializationInfo info, StreamingContext context)
140                 {
141                         base.GetObjectData (info, context);
142
143                         IList props = _contextProperties;
144                         if (props != null && props.Count == 0) props = null;
145
146                         info.AddValue ("__Activator", _activator);
147                         info.AddValue ("__CallSiteActivationAttributes", _activationAttributes);
148                         info.AddValue ("__ActivationType", null);
149                         info.AddValue ("__ContextProperties", props);
150                         info.AddValue ("__ActivationTypeName", _activationTypeName);
151                 } 
152                 
153                 public override IDictionary Properties 
154                 {
155                         get { return base.Properties; }
156                 }
157                 
158                 internal RemotingProxy SourceProxy
159                 {
160                         get { return _sourceProxy; }
161                         set {_sourceProxy = value; }
162                 }
163         }
164 }