Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Context/Context
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6819/src/Spring/Spring.Context/Context
Added Files:
ApplicationContextException.cs ApplicationEvent.cs
IApplicationContext.cs IApplicationContextAware.cs
IConfigurableApplicationContext.cs
IHierarchicalMessageSource.cs IMessageSource.cs
IMessageSourceResolvable.cs IResourceLoaderAware.cs
NoSuchMessageException.cs
Log Message:
initial port of interfaces of context package.
--- NEW FILE: IApplicationContext.cs ---
#region Licence
/*
* Copyright 2002-2004 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
#region Imports
using System;
using Spring.Objects.Factory;
using Spring.Core.IO;
#endregion
namespace Spring.Context
{
/// <summary> Central interface to provide configuration for an application.
/// This is read-only while the application is running, but may be
/// reloaded if the implementation supports this.
/// </summary>
///
/// <remarks>
/// <p>An ApplicationContext provides:
/// <ul>
/// <li>Bean factory methods, inherited from ListableBeanFactory.
/// This avoids the need for applications to use singletons.
/// </li>
/// <li>The ability to resolve messages, supporting internationalization.
/// Inherited from the MessageSource interface.
/// </li>
/// <li>The ability to load file resources in a generic fashion.
/// Inherited from the ResourceLoader interface.
/// </li>
/// <li>The ability to publish events. Implementations must provide a means
/// of registering event listeners.
/// </li>
/// <li>Inheritance from a parent context. Definitions in a descendant context
/// will always take priority. This means, for example, that a single parent
/// context can be used by an entire web application, while each servlet has
/// its own child context that is independent of that of any other servlet.
/// </li>
/// </ul>
/// </p>
///
/// <p>In addition to standard bean factory lifecycle capabilities,
/// ApplicationContext implementations need to detect ApplicationContextAware
/// beans and invoke the setApplicationContext method accordingly.
/// <see cref="Spring.Context.ApplicationContextAware"/>
/// </p>
/// </remarks>
///
/// <author>Rod Johnson</author>
/// <author>Juergen Hoeller</author>
/// <author>Mark Pollack (.NET)</author>
public interface IApplicationContext : IListableObjectFactory, IHierarchicalObjectFactory, IMessageSource, IResourceLoader
{
/// <summary> Return the timestamp when this context was first loaded.</summary>
/// <returns> the timestamp (ms) when this context was first loaded
/// </returns>
long StartupDate
{
get;
}
/// <summary> Return the parent context, or null if there is no parent,
/// and this is the root of the context hierarchy.
/// </summary>
/// <returns> the parent context, or null if there is no parent
/// </returns>
IApplicationContext GetParent();
/// <summary> Return a friendly name for this context.</summary>
/// <returns> a display name for this context
/// </returns>
string GetDisplayName();
/// <summary> Notify all listeners registered with this application of an application
/// event. Events may be framework events (such as RequestHandledEvent)
/// or application-specific events.
/// </summary>
/// <param name="event">event to publish
/// </param>
void OnApplicationEvent(ApplicationEvent appEvent);
}
}
--- NEW FILE: IConfigurableApplicationContext.cs ---
#region Licence
/*
* Copyright 2002-2004 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
using Spring.Objects.Factory.Config;
using System;
namespace Spring.Context
{
/// <summary>SPI interface to be implemented by most if not all application contexts.
/// </summary>
///
/// <remarks>
/// <p>Provides means to configure an application context in addition to the
/// application context client methods in the ApplicationContext interface.</p>
///
/// <p>Configuration and lifecycle methods are encapsulated here to avoid
/// making them obvious to ApplicationContext client code.</p>
///
/// </remarks>
/// <author>Juergen Hoeller</author>
/// <author>Mark Pollack (.NET)</author>
public interface IConfigurableApplicationContext : IApplicationContext
{
/// <summary> Return the internal object factory of this application context.
/// </summary>
/// <remarks>
/// Can be used to access specific functionality of the factory.
/// <p>Note that this is just guaranteed to return a non-null instance
/// <i>after</i> the context has been refreshed at least once.
/// </p>
/// <p>Note: Do not use this to post-process the object factory; singletons
/// will already have been instantiated before. Use a IObjectFactoryPostProcessor
/// to intercept the object factory setup process before beans get touched.
/// </p>
/// </remarks>
IConfigurableListableObjectFactory ObjectFactory
{
get;
}
/// <summary> Set the parent of this application context.</summary>
/// <remarks>
/// <p>Note that the parent shouldn't be changed: It should only be set outside
/// a constructor if it isn't available when an object of this class is created,
/// for example in case of WebApplicationContext setup.</p>
/// </remarks>
/// <param name="parent">The parent context
/// </param>
void SetParent(IApplicationContext parent);
/// <summary> Add a new BeanFactoryPostProcessor that will get applied to the internal
/// object factory of this application context on refresh, before any of the
/// bean definitions get evaluated. To be invoked during context configuration.
/// </summary>
/// <param name="objectFactoryPostProcessor">the factory processor to register
/// </param>
void AddObjectFactoryPostProcessor(IObjectFactoryPostProcessor objectFactoryPostProcessor);
/// <summary> Load or refresh the persistent representation of the configuration,
/// which might an XML file, properties file, or relational database schema.
/// </summary>
/// <exception cref="Spring.Context.ApplicationContextException">if the config cannot be loaded
/// </exception>
/// <exception cref="Spring.Objects.ObjectsException">if the bean factory could not be initialized
/// </exception>
void Refresh();
/// <summary> Close this application context, releasing all resources and locks that the
/// implementation might hold.
/// </summary>
/// <remarks>
/// This includes disposing all cached singleton objects.
/// <p>Note: Does <i>not</i> invoke close on a parent context.</p>
/// </remarks>
/// <exception cref="Spring.Context.ApplicationContextException">
/// if there were fatal errors
/// </exception>
void Close();
}
}
--- NEW FILE: IMessageSource.cs ---
#region Licence
/*
* Copyright 2002-2004 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
using System;
namespace Spring.Context
{
/// <summary> Interface to be implemented by objects that can resolve messages.
/// This enables parameterization and internationalization of messages.
/// </summary>
///
/// <remarks>
/// <p>Spring provides one out-of-the-box implementations for production:
/// <ul>
/// <li><b>ResourceManagerMessageSource</b>, built on standard ResourceManager</li>
/// </ul>
/// </p>
/// </remarks>
///
/// <author>Rod Johnson</author>
/// <author>Juergen Hoeller</author>
/// <author>Mark Pollack (.NET)</author>
public interface IMessageSource
{
/// <summary> Try to resolve the message. Return default message if no message was found.</summary>
///
/// <param name="name">The name of the resource to get. This is typically
/// a sort of "fully qualified name" meaning projectname.namespace.resourcefile-basename
/// For example a project name "MyApp" with a resource files named res.resx in the
/// MyWinforms namespace would be "MyApp.MyWinforms.res"
/// </param>
/// <param name="args">The array of arguments that will be filled in for params within
/// the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
/// or null if none.
/// </param>
/// <param name="culture">The Cultureinfo object that represents the culture
/// for which the resource is localized.
/// </param>
/// <param name="defaultMessage">String to return if the lookup fails
/// </param>
/// <returns>the resolved message if the lookup was successful;
/// otherwise the default message passed as a parameter
/// </returns>
string GetMessage(string name, object[] args, string defaultMessage, System.Globalization.CultureInfo locale);
/// <summary> Try to resolve the message. Treat as an error if the message can't be found.</summary>
/// <param name="name">The name of the resource to get. This is typically
/// a sort of "fully qualified name" meaning projectname.namespace.resourcefile-basename
/// For example a project name "MyApp" with a resource files named res.resx in the
/// MyWinforms namespace would be "MyApp.MyWinforms.res"
/// </param>
/// <param name="args">Array of arguments that will be filled in for params within
/// the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
/// or null if none.
/// </param>
/// <param name="culture">The Cultureinfo object that represents the culture
/// for which the resource is localized.
/// </param>
/// <returns>The resolved message
/// </returns>
/// <exception cref="Spring.Context.NoSuchMessageException">
/// if the message wasn't found
/// </exception>
string GetMessage(string code, object[] args, System.Globalization.CultureInfo locale);
/// <summary> Try to resolve the message using all the attributes contained within the
/// IMessageSourceResolvable argument that was passed in.
/// </summary>
/// <remarks>
/// <p>NOTE: We must throw a NoSuchMessageException on this method
/// since at the time of calling this method we aren't able to determine if the
/// <code>defaultMessage</code> property of the resolvable is null or not.
/// </p>
/// </remarks>
/// <param name="resolvable">value object storing attributes required to properly resolve a message
/// </param>
/// <param name="culture">The CultureInfo object that represents the culture
/// for which the resource is localized.
/// <returns>The resolved message
/// </returns>
/// <exception cref="Spring.Context.NoSuchMessageException">
/// if the message wasn't found
/// </exception>
string GetMessage(IMessageSourceResolvable resolvable, System.Globalization.CultureInfo locale);
}
}
--- NEW FILE: IMessageSourceResolvable.cs ---
#region Licence
/*
* Copyright 2002-2004 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
using System;
namespace Spring.Context
{
/// <summary> Interface for objects that are suitable for message resolution in a
/// MessageSource. Spring's own validation error classes implement this
/// interface.
/// </summary>
/// <author>Juergen Hoeller</author>
/// <author>Mark Pollack (.NET)</author>
public interface IMessageSourceResolvable
{
/// <summary> Return the codes to be used to resolve this message, in the order that
/// they should get tried. The last code will therefore be the default one.
/// </summary>
/// <returns> A String array of codes which are associated with this message
/// </returns>
string[] Codes
{
get;
}
/// <summary> Return the array of arguments to be used to resolve this message.</summary>
/// <returns> an array of objects to be used as parameters to replace
/// placeholders within the message text
/// </returns>
object[] Arguments
{
get;
}
/// <summary> Return the default message to be used to resolve this message.</summary>
/// <returns> the default message, or null if no default
/// </returns>
string DefaultMessage
{
get;
}
}
}
--- NEW FILE: IResourceLoaderAware.cs ---
#region Licence
/*
* Copyright 2002-2004 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
#region Imports
using Spring.Core.IO;
using System;
#endregion
namespace Spring.Context
{
/// <summary> Interface to be implemented by any object that wishes to be notified
/// of the ResourceLoader (typically the ApplicationContext) that it runs in.
/// </summary>
///
/// <remarks>
/// <p>Note that Resource dependencies can also be exposed as bean properties
/// of type Resource, populated via Strings with automatic type conversion by
/// the bean factory. This removes the need for implementing any callback
/// interface just for the purpose of accessing a specific file resource.
/// </p>
///
///
/// <p>You typically need a ResourceLoader when your application object has
/// to access a variety of file resources whose names are calculated. A good
/// strategy is to make the object use a DefaultResourceLoader but still
/// implement ResourceLoaderAware to allow for overriding when running in an
/// IApplicationContext. See ReloadableResourceBundleMessageSource for an example.
/// </p>
///
/// </remarks>
/// <author>Juergen Hoeller</author>
/// <author>Mark Pollack (.NET)</author>
/// <see cref="Spring.Context.IApplicationContextAware"/>
/// <see cref="Spring.Objects.Factory.IInitializingBean"/>
/*
/// <see cref="org.springframework.core.io.DefaultResourceLoader">
/// </seealso>
/// <seealso cref="org.springframework.context.support.ReloadableResourceBundleMessageSource">
/// </seealso>
*/
public interface IResourceLoaderAware
{
/// <summary> Set the ResourceLoader that this object runs in.</summary>
/// <remarks>
/// <p>Invoked after population of normal objects properties but before an init
/// callback like InitializingObjects's afterPropertiesSet or a custom init-method.
/// Invoked before ApplicationContextAware's setApplicationContext.</p>
/// </remarks>
/// <param name="resourceLoader">ResourceLoader object to be used by this object
/// </param>
IResourceLoader ResourceLoader
{
set;
}
}
}
--- NEW FILE: IHierarchicalMessageSource.cs ---
#region Licence
/*
* Copyright 2002-2004 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
using System;
namespace Spring.Context
{
/// <summary>Sub-interface of MessageSource to be implemented by objects that
/// can resolve messages hierarchically.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Juergen Hoeller</author>
/// <author>Mark Pollack (.NET)</author>
public interface IHierarchicalMessageSource
{
/// <summary>
/// The parent message source used to try and resolve
/// messages that ths object can't resolve. If null no further
/// resolution is possible.
/// </summary>
IMessageSource ParentMessageSource
{
get;
set;
}
}
}
--- NEW FILE: NoSuchMessageException.cs ---
#region Licence
/*
* Copyright 2002-2004 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
using System.Globalization;
using System;
namespace Spring.Context
{
/// <summary> Exception thrown when a message can't be resolved.</summary>
/// <author>Rod Johnson</author>
/// <author>Mark Pollack (.NET)</author>
[Serializable]
public class NoSuchMessageException : SystemException
{
/// <summary> Create a new exception.</summary>
/// <param name="code">code that could not be resolved for given Culture
/// </param>
/// <param name="culture">The CultureInfo that was used to search for the code within
/// </param>
public NoSuchMessageException(string code, CultureInfo locale):base("No message found under code '" + code + "' for locale '" + locale + "'.")
{
}
/// <summary> Create a new exception.</summary>
/// <param name="code">code that could not be resolved for given locale
/// </param>
//UPGRADE_TODO: Method 'java.util.Locale.getDefault' was converted to 'System.Threading.Thread.CurrentThread.CurrentCulture' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_3"'
public NoSuchMessageException(System.String code):base("No message found under code '" + code + "' for locale '" + System.Threading.Thread.CurrentThread.CurrentCulture + "'.")
{
}
}
}
--- NEW FILE: ApplicationEvent.cs ---
#region Licence
/*
* Copyright 2002-2004 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
using System;
namespace Spring.Context
{
/// <summary> Class to be extended by all application events.</summary>
///
/// <remarks>
/// Abstract as it doesn't make sense for generic events
/// to be published directly.
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Mark Pollack (.NET)</author>
[Serializable]
public abstract class ApplicationEvent : System.EventArgs
{
/// <summary> Return the system time in milliseconds when the event happened.</summary>
/// <returns> The system time in milliseconds when the event happened
/// </returns>
virtual public long Timestamp
{
get
{
return timestamp;
}
}
/// <summary>System time when the event happened </summary>
private long timestamp;
/// <summary> Creates a new ApplicationEvent.</summary>
/// <param name="source">component that published the event
/// </param>
public ApplicationEvent(System.Object source) : base()
{
timestamp = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
}
}
}
--- NEW FILE: ApplicationContextException.cs ---
#region Licence
/*
* Copyright 2002-2004 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
using Spring.Objects;
using System;
namespace Spring.Context
{
/// <summary> Exception thrown during application context initialization.</summary>
/// <author>Rod Johnson</author>
/// <author>Mark Pollack (.NET)</author>
[Serializable]
public class ApplicationContextException : FatalObjectException
{
/// <summary> Constructs an ApplicationContextException
/// with the specified detail message and no root cause.
/// </summary>
/// <param name="msg">the detail message
/// </param>
public ApplicationContextException(string msg) : base(msg)
{
}
/// <summary> Constructs an ApplicationContextException
/// with the specified detail message and the given root cause.
/// </summary>
/// <param name="msg">the detail message
/// </param>
public ApplicationContextException(string msg, Exception ex) : base(msg, ex)
{
}
}
}
--- NEW FILE: IApplicationContextAware.cs ---
#region Licence
/*
* Copyright 2002-2004 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
using System;
namespace Spring.Context
{
/// <summary> Interface to be implemented by any object that wishes to be notified
/// of the ApplicationContext that it runs in.
/// </summary>
///
/// <remarks>
/// <p>Implementing this interface makes sense for example when an object
/// requires access to a set of collaborating object. Note that configuration
/// via object references is preferable to implementing this interface just
/// for object lookup purposes.</p>
///
/// <p>This interface can also be implemented if an object needs access to file
/// resources, i.e. wants to call getResource, or access to the MessageSource.
/// However, it is preferable to implement the more specific ResourceLoaderAware
/// interface respectively receive a reference to the MessageSource bean in that
/// scenario.</p>
///
/// <p>Note that Resource dependencies can also be exposed as object properties
/// of type Resource, populated via Strings with automatic type conversion by
/// the bean factory. This removes the need for implementing any callback
/// interface just for the purpose of accessing a specific file resource.</p>
///
/// <p>ApplicationObjectSupport is a convenience base class for
/// application objects, implementing this interface.</p>
///
/// <p>For a list of all object lifecycle methods, see the ObjectFactory.</p>
///
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Mark Pollack (.NET)</author>
/// <see cref="Spring.Context.ResourceLoaderAware"/>
/// <!-- <see cref="Spring.Context.Support.ApplicationObjectSupport"/> -->
/// <see cref="Spring.Objects.Factory.IObjectFactoryAware"/>
/// <see cref="Spring.Objects.Factory.IInitializingBean"/>
/// <see cref="Spring.Objects.Factory.IObjectFactory"/>
public interface IApplicationContextAware
{
/// <summary> Set the ApplicationContext that this object runs in.</summary>
/// <remarks>
/// Normally this call will be used to initialize the object.
/// <p>Invoked after population of normal bean properties but before an init
/// callback like InitializingBean's afterPropertiesSet or a custom init-method.
/// Invoked after ResourceLoaderAware's setResourceLoader.</p>
/// </remarks>
/// <param name="applicationContext">IApplicationContext object to be used by this object
/// </param>
/// <exception cref="Spring.Context.ApplicationContextException">
/// in case of applicationContext initialization errors
/// </exception>
/// <exception cref="Spring.Objects.ObjectsException">
/// if thrown by application applicationContext methods.
/// </exception>
/// <exception cref="Spring.Objects.Factory.ObjectInitializationException"/>
void SetApplicationContext(IApplicationContext applicationContext);
}
}
|