// Copyright 2003-2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Apache.Avalon.Castle.ManagementExtensions.Default
{
using System;
using System.Reflection;
///
/// Summary description for MDefaultServer.
///
public class MDefaultServer : MarshalByRefObject, MServer
{
protected MRegistry registry;
public MDefaultServer()
{
// TODO: Allow customisation of MRegistry
registry = new Default.MDefaultRegistry(this);
SetupRegistry();
}
private void SetupRegistry()
{
RegisterManagedObject(registry, MConstants.REGISTRY_NAME);
}
#region MServer Members
///
/// TODO: Summary
///
///
///
public Object Instantiate(String typeName)
{
if (typeName == null)
{
throw new ArgumentNullException("typeName");
}
Type targetType = Type.GetType(typeName, true, true);
object instance = AppDomain.CurrentDomain.CreateInstanceAndUnwrap(
targetType.Assembly.FullName, targetType.FullName);
return instance;
}
///
/// Instantiates the specified type using the server domain.
///
///
///
///
public Object Instantiate(String assemblyName, String typeName)
{
if (assemblyName == null)
{
throw new ArgumentNullException("assemblyName");
}
if (typeName == null)
{
throw new ArgumentNullException("typeName");
}
object instance = AppDomain.CurrentDomain.CreateInstanceAndUnwrap(
assemblyName, typeName);
return instance;
}
///
/// TODO: Summary
///
///
///
///
public ManagedInstance CreateManagedObject(String typeName, ManagedObjectName name)
{
if (typeName == null)
{
throw new ArgumentNullException("typeName");
}
if (name == null)
{
throw new ArgumentNullException("name");
}
Object instance = Instantiate(typeName);
return RegisterManagedObject(instance, name);
}
///
/// TODO: Summary
///
///
///
///
///
public ManagedInstance CreateManagedObject(String assemblyName, String typeName, ManagedObjectName name)
{
if (assemblyName == null)
{
throw new ArgumentNullException("assemblyName");
}
if (typeName == null)
{
throw new ArgumentNullException("typeName");
}
if (name == null)
{
throw new ArgumentNullException("name");
}
Object instance = Instantiate(assemblyName, typeName);
return RegisterManagedObject(instance, name);
}
///
/// TODO: Summary
///
///
///
///
public ManagedInstance RegisterManagedObject(Object instance, ManagedObjectName name)
{
if (instance == null)
{
throw new ArgumentNullException("instance");
}
if (name == null)
{
throw new ArgumentNullException("name");
}
return registry.RegisterManagedObject(instance, name);
}
///
/// TODO: Summary
///
///
///
public ManagedInstance GetManagedInstance(ManagedObjectName name)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
return registry.GetManagedInstance(name);
}
///
/// TODO: Summary
///
///
public void UnregisterManagedObject(ManagedObjectName name)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
registry.UnregisterManagedObject(name);
}
///
/// Invokes an action in managed object
///
///
///
///
///
///
/// If domain name is not found.
public Object Invoke(ManagedObjectName name, String action, Object[] args, Type[] signature)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
if (action == null)
{
throw new ArgumentNullException("action");
}
return registry.Invoke(name, action, args, signature);
}
///
/// Returns the info (attributes and operations) about the specified object.
///
///
///
/// If domain name is not found.
public ManagementInfo GetManagementInfo(ManagedObjectName name)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
return registry.GetManagementInfo(name);
}
///
/// Gets an attribute value of the specified managed object.
///
///
///
///
/// If domain name is not found.
public Object GetAttribute(ManagedObjectName name, String attributeName)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
if (attributeName == null)
{
throw new ArgumentNullException("attributeName");
}
return registry.GetAttributeValue(name, attributeName);
}
///
/// Sets an attribute value of the specified managed object.
///
///
///
///
/// If domain name is not found.
public void SetAttribute(ManagedObjectName name, String attributeName, Object attributeValue)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
if (attributeName == null)
{
throw new ArgumentNullException("attributeName");
}
registry.SetAttributeValue(name, attributeName, attributeValue);
}
///
/// Returns an array of registered domains.
///
/// a list of domains
public String[] GetDomains()
{
return registry.GetDomains();
}
///
/// Queries the registerd components.
///
///
public ManagedObjectName[] Query(ManagedObjectName query)
{
return registry.Query(query);
}
#endregion
}
}