Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / Tools / ManagedExtensions / ManagementExtensions / Default / MDefaultServer.cs
blob224f219ce66046bdd1a71e48455a2cf4b74a99ed
1 // Copyright 2003-2004 DigitalCraftsmen - http://www.digitalcraftsmen.com.br/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.ManagementExtensions.Default
17 using System;
18 using System.Reflection;
20 /// <summary>
21 /// Summary description for MDefaultServer.
22 /// </summary>
23 public class MDefaultServer : MarshalByRefObject, MServer
25 protected MRegistry registry;
27 public MDefaultServer()
29 // TODO: Allow customisation of MRegistry
31 registry = new Default.MDefaultRegistry(this);
33 SetupRegistry();
36 private void SetupRegistry()
38 RegisterManagedObject(registry, MConstants.REGISTRY_NAME);
41 #region MServer Members
43 /// <summary>
44 /// TODO: Summary
45 /// </summary>
46 /// <param name="typeName"></param>
47 /// <returns></returns>
48 public Object Instantiate(String typeName)
50 if (typeName == null)
52 throw new ArgumentNullException("typeName");
55 Type targetType = Type.GetType(typeName, true, true);
57 object instance = AppDomain.CurrentDomain.CreateInstanceAndUnwrap(
58 targetType.Assembly.FullName, targetType.FullName);
60 return instance;
63 /// <summary>
64 /// Instantiates the specified type using the server domain.
65 /// </summary>
66 /// <param name="typeName"></param>
67 /// <param name="typeName"></param>
68 /// <returns></returns>
69 public Object Instantiate(String assemblyName, String typeName)
71 if (assemblyName == null)
73 throw new ArgumentNullException("assemblyName");
75 if (typeName == null)
77 throw new ArgumentNullException("typeName");
80 object instance = AppDomain.CurrentDomain.CreateInstanceAndUnwrap(
81 assemblyName, typeName);
83 return instance;
86 /// <summary>
87 /// TODO: Summary
88 /// </summary>
89 /// <param name="typeName"></param>
90 /// <param name="name"></param>
91 /// <returns></returns>
92 public ManagedInstance CreateManagedObject(String typeName, ManagedObjectName name)
94 if (typeName == null)
96 throw new ArgumentNullException("typeName");
98 if (name == null)
100 throw new ArgumentNullException("name");
103 Object instance = Instantiate(typeName);
104 return RegisterManagedObject(instance, name);
107 /// <summary>
108 /// TODO: Summary
109 /// </summary>
110 /// <param name="assemblyName"></param>
111 /// <param name="typeName"></param>
112 /// <param name="name"></param>
113 /// <returns></returns>
114 public ManagedInstance CreateManagedObject(String assemblyName, String typeName, ManagedObjectName name)
116 if (assemblyName == null)
118 throw new ArgumentNullException("assemblyName");
120 if (typeName == null)
122 throw new ArgumentNullException("typeName");
124 if (name == null)
126 throw new ArgumentNullException("name");
129 Object instance = Instantiate(assemblyName, typeName);
130 return RegisterManagedObject(instance, name);
134 /// <summary>
135 /// TODO: Summary
136 /// </summary>
137 /// <param name="instance"></param>
138 /// <param name="name"></param>
139 /// <returns></returns>
140 public ManagedInstance RegisterManagedObject(Object instance, ManagedObjectName name)
142 if (instance == null)
144 throw new ArgumentNullException("instance");
146 if (name == null)
148 throw new ArgumentNullException("name");
151 return registry.RegisterManagedObject(instance, name);
154 /// <summary>
155 /// TODO: Summary
156 /// </summary>
157 /// <param name="name"></param>
158 /// <returns></returns>
159 public ManagedInstance GetManagedInstance(ManagedObjectName name)
161 if (name == null)
163 throw new ArgumentNullException("name");
166 return registry.GetManagedInstance(name);
169 /// <summary>
170 /// TODO: Summary
171 /// </summary>
172 /// <param name="name"></param>
173 public void UnregisterManagedObject(ManagedObjectName name)
175 if (name == null)
177 throw new ArgumentNullException("name");
180 registry.UnregisterManagedObject(name);
183 /// <summary>
184 /// Invokes an action in managed object
185 /// </summary>
186 /// <param name="name"></param>
187 /// <param name="action"></param>
188 /// <param name="args"></param>
189 /// <param name="signature"></param>
190 /// <returns></returns>
191 /// <exception cref="InvalidDomainException">If domain name is not found.</exception>
192 public Object Invoke(ManagedObjectName name, String action, Object[] args, Type[] signature)
194 if (name == null)
196 throw new ArgumentNullException("name");
198 if (action == null)
200 throw new ArgumentNullException("action");
202 return registry.Invoke(name, action, args, signature);
205 /// <summary>
206 /// Returns the info (attributes and operations) about the specified object.
207 /// </summary>
208 /// <param name="name"></param>
209 /// <returns></returns>
210 /// <exception cref="InvalidDomainException">If domain name is not found.</exception>
211 public ManagementInfo GetManagementInfo(ManagedObjectName name)
213 if (name == null)
215 throw new ArgumentNullException("name");
218 return registry.GetManagementInfo(name);
221 /// <summary>
222 /// Gets an attribute value of the specified managed object.
223 /// </summary>
224 /// <param name="name"></param>
225 /// <param name="attributeName"></param>
226 /// <returns></returns>
227 /// <exception cref="InvalidDomainException">If domain name is not found.</exception>
228 public Object GetAttribute(ManagedObjectName name, String attributeName)
230 if (name == null)
232 throw new ArgumentNullException("name");
234 if (attributeName == null)
236 throw new ArgumentNullException("attributeName");
239 return registry.GetAttributeValue(name, attributeName);
242 /// <summary>
243 /// Sets an attribute value of the specified managed object.
244 /// </summary>
245 /// <param name="name"></param>
246 /// <param name="attributeName"></param>
247 /// <param name="attributeValue"></param>
248 /// <exception cref="InvalidDomainException">If domain name is not found.</exception>
249 public void SetAttribute(ManagedObjectName name, String attributeName, Object attributeValue)
251 if (name == null)
253 throw new ArgumentNullException("name");
255 if (attributeName == null)
257 throw new ArgumentNullException("attributeName");
260 registry.SetAttributeValue(name, attributeName, attributeValue);
263 /// <summary>
264 /// Returns an array of registered domains.
265 /// </summary>
266 /// <returns>a list of domains</returns>
267 public String[] GetDomains()
269 return registry.GetDomains();
272 /// <summary>
273 /// Queries the registerd components.
274 /// </summary>
275 /// <returns></returns>
276 public ManagedObjectName[] Query(ManagedObjectName query)
278 return registry.Query(query);
281 #endregion