SPRNET-1109, SPRNET-1095: added xmldoc comments

This commit is contained in:
eeichinger
2008-11-14 19:48:57 +00:00
parent eb3dae49b5
commit d00c6c5dcd
5 changed files with 158 additions and 48 deletions

View File

@@ -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>

View File

@@ -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>
/// &lt;!-- actual objects 'calculatorService' and 'simpleCalculatorService' are defined elsewhere --&gt;
///
/// &lt;!-- Define the component for exporting 'calculatorService' --&gt;
/// &lt;object id=&quot;calculatorComponent&quot; type=&quot;Spring.EnterpriseServices.ServicedComponentExporter,
/// Spring.Services&quot;&gt;
/// &lt;property name=&quot;TargetName&quot; value=&quot;calculatorService&quot; /&gt;
/// &lt;property name=&quot;TypeAttributes&quot;&gt;
/// &lt;list&gt;
/// &lt;object type=&quot;System.EnterpriseServices.TransactionAttribute, System.EnterpriseServices&quot; /&gt;
/// &lt;/list&gt;
/// &lt;/property&gt;
/// &lt;property name=&quot;MemberAttributes&quot;&gt;
/// &lt;dictionary&gt;
/// &lt;entry key=&quot;*&quot;&gt;
/// &lt;list&gt;
/// &lt;object type=&quot;System.EnterpriseServices.AutoCompleteAttribute, System.EnterpriseServices&quot; /&gt;
/// &lt;/list&gt;
/// &lt;/entry&gt;
/// &lt;/dictionary&gt;
/// &lt;/property&gt;
/// &lt;/object&gt;
///
/// &lt;!-- Define the component for exporting 'simpleCalculatorService' --&gt;
/// &lt;object id=&quot;simpleCalculatorComponent&quot; type=&quot;Spring.EnterpriseServices.ServicedComponentExporter,
/// Spring.Services&quot;&gt;
/// &lt;property name=&quot;TargetName&quot; value=&quot;simpleCalculatorService&quot; /&gt;
/// &lt;/object&gt;
///
/// &lt;!-- Export components into assembly and autoregister with COM+ --&gt;
/// &lt;object type=&quot;Spring.EnterpriseServices.EnterpriseServicesExporter, Spring.Services&quot;&gt;
/// &lt;!-- assembly name to generated - will generate 'Spring.Calculator.EnterpriseServices.dll' --&gt;
/// &lt;property name=&quot;Assembly&quot; value=&quot;Spring.Calculator.EnterpriseServices&quot; /&gt;
///
/// &lt;!--
/// use Spring's ContextRegistry for managing services. If true, requires a file
/// 'Spring.Calculator.EnterpriseServices.dll.spring-context.xml' containing a
/// &lt;spring/context /&gt; section placed next to the generated assembly.
/// --&gt;
/// &lt;property name=&quot;UseSpring&quot; value=&quot;true&quot; /&gt;
///
/// &lt;property name=&quot;ApplicationName&quot; value=&quot;Spring Calculator Application&quot; /&gt;
/// &lt;property name=&quot;ActivationMode&quot; value=&quot;Library&quot; /&gt;
/// &lt;property name=&quot;Description&quot; value=&quot;Spring Calculator application&quot; /&gt;
/// &lt;property name=&quot;Components&quot;&gt;
/// &lt;list&gt;
/// &lt;ref object=&quot;calculatorComponent&quot; /&gt;
/// &lt;ref object=&quot;simpleCalculatorComponent&quot; /&gt;
/// &lt;/list&gt;
/// &lt;/property&gt;
/// &lt;/object&gt;
/// </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>
/// &lt;-- --&gt;
/// &lt;spring&gt;
/// &lt;context&gt;
/// &lt;resource uri=&quot;Config/services.xml&quot; /&gt;
/// &lt;/context&gt;
/// &lt;/spring&gt;
/// </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
/// , &quot;Spring.Services.dll&quot; );
/// servicesAssembly = System.Reflection.Assembly.LoadFrom(servicesAssemblyPath);
/// if (servicesAssembly == null)
/// {
/// // then let the normal loader handle the typeload
/// servicesAssembly = System.Reflection.Assembly.Load(&quot;Spring.Services, culture=neutral, version=x.x.x.x, publicKey=xxxxxxxx&quot;);
/// }
/// Type componentHelperType = servicesAssembly.GetType(&quot;Spring.EnterpriseServices.ServicedComponentHelper&quot;);
/// getObjectRef = (GetObjectHandler) Delegate.CreateDelegate(typeof(GetObjectHandler)
/// , componentHelperType.GetMethod(&quot;GetObject&quot;));
/// }
/// }
/// servicesAssembly = System.Reflection.Assembly.LoadFrom(servicesAssemblyPath);
/// if (servicesAssembly == null)
/// {
/// // then let the normal loader handle the typeload
/// servicesAssembly = System.Reflection.Assembly.Load(&quot;Spring.Services, culture=neutral, version=x.x.x.x, publicKey=xxxxxxxx&quot;);
/// }
///
/// Type componentHelperType = servicesAssembly.GetType(&quot;Spring.EnterpriseServices.ServicedComponentHelper&quot;);
/// getObjectRef = (GetObjectHandler) Delegate.CreateDelegate(typeof(GetObjectHandler)
/// , componentHelperType.GetMethod(&quot;GetObject&quot;));
/// }
/// }
/// </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();

View File

@@ -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 &lt;spring/context&gt; configuration sections for <see cref="ServicedComponent"/>s
/// generated by <see cref="EnterpriseServicesExporter"/>.
/// </summary>
/// <author>Erich Eichinger</author>
public class ServicedComponentContextHandler : ContextHandler
{}
}
}
#endif

View File

@@ -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

View File

@@ -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