1 // Copyright 2003-2004 DigitalCraftsmen - http://www.digitalcraftsmen.com.br/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using System
.Reflection
;
21 /// Summary description for MDefaultServer.
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);
36 private void SetupRegistry()
38 RegisterManagedObject(registry
, MConstants
.REGISTRY_NAME
);
41 #region MServer Members
46 /// <param name="typeName"></param>
47 /// <returns></returns>
48 public Object
Instantiate(String typeName
)
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
);
64 /// Instantiates the specified type using the server domain.
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");
77 throw new ArgumentNullException("typeName");
80 object instance
= AppDomain
.CurrentDomain
.CreateInstanceAndUnwrap(
81 assemblyName
, typeName
);
89 /// <param name="typeName"></param>
90 /// <param name="name"></param>
91 /// <returns></returns>
92 public ManagedInstance
CreateManagedObject(String typeName
, ManagedObjectName name
)
96 throw new ArgumentNullException("typeName");
100 throw new ArgumentNullException("name");
103 Object instance
= Instantiate(typeName
);
104 return RegisterManagedObject(instance
, name
);
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");
126 throw new ArgumentNullException("name");
129 Object instance
= Instantiate(assemblyName
, typeName
);
130 return RegisterManagedObject(instance
, name
);
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");
148 throw new ArgumentNullException("name");
151 return registry
.RegisterManagedObject(instance
, name
);
157 /// <param name="name"></param>
158 /// <returns></returns>
159 public ManagedInstance
GetManagedInstance(ManagedObjectName name
)
163 throw new ArgumentNullException("name");
166 return registry
.GetManagedInstance(name
);
172 /// <param name="name"></param>
173 public void UnregisterManagedObject(ManagedObjectName name
)
177 throw new ArgumentNullException("name");
180 registry
.UnregisterManagedObject(name
);
184 /// Invokes an action in managed object
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
)
196 throw new ArgumentNullException("name");
200 throw new ArgumentNullException("action");
202 return registry
.Invoke(name
, action
, args
, signature
);
206 /// Returns the info (attributes and operations) about the specified object.
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
)
215 throw new ArgumentNullException("name");
218 return registry
.GetManagementInfo(name
);
222 /// Gets an attribute value of the specified managed object.
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
)
232 throw new ArgumentNullException("name");
234 if (attributeName
== null)
236 throw new ArgumentNullException("attributeName");
239 return registry
.GetAttributeValue(name
, attributeName
);
243 /// Sets an attribute value of the specified managed object.
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
)
253 throw new ArgumentNullException("name");
255 if (attributeName
== null)
257 throw new ArgumentNullException("attributeName");
260 registry
.SetAttributeValue(name
, attributeName
, attributeValue
);
264 /// Returns an array of registered domains.
266 /// <returns>a list of domains</returns>
267 public String
[] GetDomains()
269 return registry
.GetDomains();
273 /// Queries the registerd components.
275 /// <returns></returns>
276 public ManagedObjectName
[] Query(ManagedObjectName query
)
278 return registry
.Query(query
);