SPRNET-1109, SPRNET-1095: added xmldoc comments
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<spring>
|
||||
<context>
|
||||
<resource uri="Config/services.xml" />
|
||||
</context>
|
||||
<context>
|
||||
<resource uri="Config/services.xml" />
|
||||
</context>
|
||||
</spring>
|
||||
@@ -1,7 +1,7 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,12 +41,84 @@ namespace Spring.EnterpriseServices
|
||||
/// Exports specified components as ServicedComponents.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <p>
|
||||
/// <para>
|
||||
/// This class will create ServicedComponent wrapper for each of the
|
||||
/// specified components and register them with the Component Services.
|
||||
/// </p>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// First you need to generate and register your components. This is done by writing a simple e.g. console application using a configuration as shown below:
|
||||
/// <code>
|
||||
/// <!-- actual objects 'calculatorService' and 'simpleCalculatorService' are defined elsewhere -->
|
||||
///
|
||||
/// <!-- Define the component for exporting 'calculatorService' -->
|
||||
/// <object id="calculatorComponent" type="Spring.EnterpriseServices.ServicedComponentExporter,
|
||||
/// Spring.Services">
|
||||
/// <property name="TargetName" value="calculatorService" />
|
||||
/// <property name="TypeAttributes">
|
||||
/// <list>
|
||||
/// <object type="System.EnterpriseServices.TransactionAttribute, System.EnterpriseServices" />
|
||||
/// </list>
|
||||
/// </property>
|
||||
/// <property name="MemberAttributes">
|
||||
/// <dictionary>
|
||||
/// <entry key="*">
|
||||
/// <list>
|
||||
/// <object type="System.EnterpriseServices.AutoCompleteAttribute, System.EnterpriseServices" />
|
||||
/// </list>
|
||||
/// </entry>
|
||||
/// </dictionary>
|
||||
/// </property>
|
||||
/// </object>
|
||||
///
|
||||
/// <!-- Define the component for exporting 'simpleCalculatorService' -->
|
||||
/// <object id="simpleCalculatorComponent" type="Spring.EnterpriseServices.ServicedComponentExporter,
|
||||
/// Spring.Services">
|
||||
/// <property name="TargetName" value="simpleCalculatorService" />
|
||||
/// </object>
|
||||
///
|
||||
/// <!-- Export components into assembly and autoregister with COM+ -->
|
||||
/// <object type="Spring.EnterpriseServices.EnterpriseServicesExporter, Spring.Services">
|
||||
/// <!-- assembly name to generated - will generate 'Spring.Calculator.EnterpriseServices.dll' -->
|
||||
/// <property name="Assembly" value="Spring.Calculator.EnterpriseServices" />
|
||||
///
|
||||
/// <!--
|
||||
/// use Spring's ContextRegistry for managing services. If true, requires a file
|
||||
/// 'Spring.Calculator.EnterpriseServices.dll.spring-context.xml' containing a
|
||||
/// <spring/context /> section placed next to the generated assembly.
|
||||
/// -->
|
||||
/// <property name="UseSpring" value="true" />
|
||||
///
|
||||
/// <property name="ApplicationName" value="Spring Calculator Application" />
|
||||
/// <property name="ActivationMode" value="Library" />
|
||||
/// <property name="Description" value="Spring Calculator application" />
|
||||
/// <property name="Components">
|
||||
/// <list>
|
||||
/// <ref object="calculatorComponent" />
|
||||
/// <ref object="simpleCalculatorComponent" />
|
||||
/// </list>
|
||||
/// </property>
|
||||
/// </object>
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// To load your objectdefinitions at runtime of the components, place a configuration file next to the assembly
|
||||
/// generated by the exporter, using the filename of the exported assembly, postfixing it with '.spring-context.config'.
|
||||
/// Taking the example above, the file must be named 'Spring.Calculator.EnterpriseServices.dll.spring-context.xml' and look like:
|
||||
/// <code>
|
||||
/// <-- -->
|
||||
/// <spring>
|
||||
/// <context>
|
||||
/// <resource uri="Config/services.xml" />
|
||||
/// </context>
|
||||
/// </spring>
|
||||
/// </code>
|
||||
/// This file should point to the service object definitions you exported using <see cref="EnterpriseServicesExporter"/> with a
|
||||
/// configuration as shown above.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <seealso cref="ServicedComponentExporter"/>
|
||||
/// <author>Aleksandar Seovic</author>
|
||||
/// <author>Erich Eichinger</author>
|
||||
public class EnterpriseServicesExporter : IInitializingObject, IObjectFactoryAware
|
||||
{
|
||||
#region Fields
|
||||
@@ -334,31 +406,31 @@ namespace Spring.EnterpriseServices
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// internal class SpringServicedComponent
|
||||
/// {
|
||||
/// protected delegate object GetObjectHandler(ServicedComponent servicedComponent, string targetName);
|
||||
/// internal class SpringServicedComponent
|
||||
/// {
|
||||
/// protected delegate object GetObjectHandler(ServicedComponent servicedComponent, string targetName);
|
||||
///
|
||||
/// protected static readonly GetObjectHandler getObjectRef;
|
||||
/// protected static readonly GetObjectHandler getObjectRef;
|
||||
///
|
||||
/// static SpringServicedComponent()
|
||||
/// {
|
||||
/// // first look for a local copy
|
||||
/// System.Reflection.Assembly servicesAssembly;
|
||||
/// string servicesAssemblyPath = Path.Combine(
|
||||
/// static SpringServicedComponent()
|
||||
/// {
|
||||
/// // first look for a local copy
|
||||
/// System.Reflection.Assembly servicesAssembly;
|
||||
/// string servicesAssemblyPath = Path.Combine(
|
||||
/// new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName
|
||||
/// , "Spring.Services.dll" );
|
||||
/// servicesAssembly = System.Reflection.Assembly.LoadFrom(servicesAssemblyPath);
|
||||
/// if (servicesAssembly == null)
|
||||
/// {
|
||||
/// // then let the normal loader handle the typeload
|
||||
/// servicesAssembly = System.Reflection.Assembly.Load("Spring.Services, culture=neutral, version=x.x.x.x, publicKey=xxxxxxxx");
|
||||
/// }
|
||||
/// Type componentHelperType = servicesAssembly.GetType("Spring.EnterpriseServices.ServicedComponentHelper");
|
||||
/// getObjectRef = (GetObjectHandler) Delegate.CreateDelegate(typeof(GetObjectHandler)
|
||||
/// , componentHelperType.GetMethod("GetObject"));
|
||||
/// }
|
||||
/// }
|
||||
/// servicesAssembly = System.Reflection.Assembly.LoadFrom(servicesAssemblyPath);
|
||||
/// if (servicesAssembly == null)
|
||||
/// {
|
||||
/// // then let the normal loader handle the typeload
|
||||
/// servicesAssembly = System.Reflection.Assembly.Load("Spring.Services, culture=neutral, version=x.x.x.x, publicKey=xxxxxxxx");
|
||||
/// }
|
||||
///
|
||||
/// Type componentHelperType = servicesAssembly.GetType("Spring.EnterpriseServices.ServicedComponentHelper");
|
||||
/// getObjectRef = (GetObjectHandler) Delegate.CreateDelegate(typeof(GetObjectHandler)
|
||||
/// , componentHelperType.GetMethod("GetObject"));
|
||||
/// }
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
private Type CreateSpringServicedComponentType(ModuleBuilder module)
|
||||
@@ -369,10 +441,6 @@ namespace Spring.EnterpriseServices
|
||||
ILGenerator il = null;
|
||||
FieldBuilder getObjectRef = typeBuilder.DefineField("getObject", delegateType, FieldAttributes.Family | FieldAttributes.Static);
|
||||
|
||||
// MethodBuilder assemblyResolveHandler = GenerateOnAssemblyResolve(typeBuilder);
|
||||
|
||||
// static SpringServicedComponent() {
|
||||
// }
|
||||
ConstructorBuilder typeCtor = typeBuilder.DefineTypeInitializer();
|
||||
il = typeCtor.GetILGenerator();
|
||||
Label methodEnd = il.DefineLabel();
|
||||
|
||||
@@ -1,10 +1,41 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#if (!NET_1_0 && !MONO)
|
||||
|
||||
#region Imports
|
||||
|
||||
using System.EnterpriseServices;
|
||||
using Spring.Context.Support;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.EnterpriseServices
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// Handles loading of <spring/context> configuration sections for <see cref="ServicedComponent"/>s
|
||||
/// generated by <see cref="EnterpriseServicesExporter"/>.
|
||||
/// </summary>
|
||||
/// <author>Erich Eichinger</author>
|
||||
public class ServicedComponentContextHandler : ContextHandler
|
||||
{}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,13 +40,16 @@ namespace Spring.EnterpriseServices
|
||||
/// wrapper around target class.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <p>
|
||||
/// <para>
|
||||
/// Instances of this class should be used as elements in the Components
|
||||
/// list of the <see cref="EnterpriseServicesExporter"/> class, which will
|
||||
/// register them with COM+ Services.
|
||||
/// </p>
|
||||
/// register them with COM+ Services. For a full description on how to export
|
||||
/// and use services with COM+, see the <see cref="EnterpriseServicesExporter"/> reference.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <seealso cref="EnterpriseServicesExporter"/>
|
||||
/// <author>Aleksandar Seovic</author>
|
||||
/// <author>Erich Eichinger</author>
|
||||
public class ServicedComponentExporter : IInitializingObject, IObjectNameAware
|
||||
{
|
||||
#region Fields
|
||||
|
||||
@@ -18,17 +18,16 @@
|
||||
|
||||
#endregion
|
||||
|
||||
#if (!NET_1_0 && !MONO)
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.EnterpriseServices;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Xml;
|
||||
using Spring.Context;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Reflection.Dynamic;
|
||||
using ConfigXmlDocument = Spring.Util.ConfigXmlDocument;
|
||||
|
||||
#endregion
|
||||
@@ -36,7 +35,8 @@ using ConfigXmlDocument = Spring.Util.ConfigXmlDocument;
|
||||
namespace Spring.EnterpriseServices
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// This class supports <see cref="ServicedComponent"/>s exported using <see cref="EnterpriseServicesExporter"/>.
|
||||
/// and must never be used directly.
|
||||
/// </summary>
|
||||
/// <author>Erich Eichinger</author>
|
||||
public class ServicedComponentHelper
|
||||
@@ -50,8 +50,9 @@ namespace Spring.EnterpriseServices
|
||||
}
|
||||
|
||||
///<summary>
|
||||
/// Reads in the 'xxx.spring-context.xml' configuration file associated with the specified <paramref name="component"/>.
|
||||
/// See <see cref="EnterpriseServicesExporter"/> for an in-depth description on how to export and configure COM+ components.
|
||||
///</summary>
|
||||
///<param name="component"></param>
|
||||
private static void EnsureComponentContextRegistryInitialized(ServicedComponent component)
|
||||
{
|
||||
if (isInitialized) return;
|
||||
@@ -61,10 +62,14 @@ namespace Spring.EnterpriseServices
|
||||
if (isInitialized) return;
|
||||
isInitialized = true;
|
||||
|
||||
// this is to ensure, that assemblies place next to the component assembly can be loaded
|
||||
// even when they are not strong named.
|
||||
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
|
||||
FileInfo componentAssemblyFile = new FileInfo(component.GetType().Assembly.Location);
|
||||
componentDirectory = componentAssemblyFile.Directory.FullName;
|
||||
// switch to component assembly's directory (affects resolving relative paths during context instantiation!)
|
||||
Environment.CurrentDirectory = componentDirectory;
|
||||
// read in config file
|
||||
ConfigXmlDocument configDoc = new ConfigXmlDocument();
|
||||
FileInfo configFile = new FileInfo(componentAssemblyFile.FullName + ".spring-context.xml");
|
||||
if (configFile.Exists)
|
||||
@@ -74,6 +79,10 @@ namespace Spring.EnterpriseServices
|
||||
ServicedComponentContextHandler handler = new ServicedComponentContextHandler();
|
||||
lock (ContextRegistry.SyncRoot)
|
||||
{
|
||||
// it might accidentially have happend, that the contextregistry has already
|
||||
// been initialized using the client application's app.config configuration.
|
||||
// Most of the time this doesn't make sense to read a configuration from a
|
||||
// different AppDomain, thus we read in our own config file.
|
||||
ContextRegistry.Clear();
|
||||
handler.Create(null, null, configNode);
|
||||
}
|
||||
@@ -81,7 +90,7 @@ namespace Spring.EnterpriseServices
|
||||
}
|
||||
}
|
||||
|
||||
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
|
||||
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
|
||||
{
|
||||
string name = args.Name.Split(',')[0];
|
||||
Assembly assembly = Assembly.LoadFrom(Path.Combine(componentDirectory, name + ".dll"));
|
||||
@@ -89,16 +98,15 @@ namespace Spring.EnterpriseServices
|
||||
}
|
||||
|
||||
///<summary>
|
||||
/// Called by a <see cref="ServicedComponent"/> exported by <see cref="EnterpriseServicesExporter"/>
|
||||
/// to obtain a reference to the service it proxies.
|
||||
///</summary>
|
||||
///<param name="sender"></param>
|
||||
///<param name="targetName"></param>
|
||||
///<returns></returns>
|
||||
public static object GetObject(ServicedComponent sender, string targetName)
|
||||
{
|
||||
EnsureComponentContextRegistryInitialized(sender);
|
||||
return ContextRegistry.GetContext().GetObject(targetName);
|
||||
// return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user