// 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.Composition.Data { using System; using Apache.Avalon.Framework; using Apache.Avalon.Meta; /// Definition of the criteria for an explicit component profile. A profile, when /// included within the scope of a container declaration will be instantiated in /// the model as an EXPLICIT component profile resulting in the initiation of /// dependency resolution relative to the component as the target deployment /// objective. Multiple supplementary profiles may be packaged in a .xprofiles /// resources and will be assigned to the container automatically. In the absence /// of explicit or packaged profile directives, an implicit profile will be created /// for any component types declared under a jar manifest. /// ///

XML

///

A component element declares the profile to be applied during the instantiation /// of a component type. It includes a name and class declaration, logging directives /// (resolved relative to the component's container), context creation criteria, /// together with configuration or parameters information.

/// ///
	/// <!--
	/// Declaration of the services hosted by this container.  Service container here
	/// will be managed relative to other provider components at the same level and
	/// may be serviced by components declared in parent container.
	/// -->
	/// <component name="complex" class="org.apache.excalibur.playground.ComplexComponent" activation="startup">
	/// <!--
	/// Priority and target assignments for component specific logging categrories.
	/// -->
	/// <categories priority="DEBUG">
	/// <category name="init" priority="DEBUG" />
	/// </categories>
	/// <!--
	/// Context entry directives are normally only required in the case where the component
	/// type declares a required context type and entry values. Generally speaking, a component
	/// will normally qualify it's instantiation criteria through a configuration declaration.
	/// Any context values defined at this level will override context values supplied by the
	/// container.  The following two context directives for "location" and "home" demonstrate
	/// programatics creation of context values.  The first entry declares that the context
	/// value to be assigned to the key "location" shall be the String value "Paris".  The second
	/// context enty assignes the container's context value for "urn:avalon:home" to the component's
	/// context key of "home".
	/// -->
	/// <context>
	/// <entry key="location">Paris</entry>
	/// <include name="urn:avalon:home" key="home"/>
	/// </context>
	/// <!--
	/// Apply the following configuration when instantiating the component.  This configuration
	/// will be applied as the primary configuration in a cascading configuration chain.  A
	/// type may declare a default configuration under a "classname".xconfig file that will be
	/// used to dereference any configuration requests not resolvable by the configuration
	/// supplied here.
	/// -->
	/// <configuration>
	/// <message value="Hello"/>
	/// </configuration>
	/// <!--
	/// The parameterization criteria from this instance of the component type.
	/// -->
	/// <parameters/>
	/// </component>
	/// 
/// /// ///
/// Avalon Development Team /// /// $Revision: 1.2 $ $Date: 2004/02/28 22:15:36 $ /// public class ComponentProfile : DeploymentProfile { /// The assigned logging categories. private CategoriesDirective m_categories; /// The collection policy override. private CollectionPolicy m_collection; /// The component classname. private System.String m_classname; /// The parameters for component (if any). // private Parameters m_parameters; /// The configuration for component (if any). private IConfiguration m_configuration; /// The configuration for component (if any). private ContextDirective m_context; /// The dependency directives. private DependencyDirective[] m_dependencies; /// The stage directives. private StageDirective[] m_stages; //-------------------------------------------------------------------------- // constructor //-------------------------------------------------------------------------- /// Creation of a new profile using IMPLICT mode and LIBERAL collection /// policies. /// /// /// the name to assign to the component deployment scenario /// /// the classname of the component type /// public ComponentProfile(System.String name, System.String classname):this(name, ActivationPolicy.Lazy, Apache.Avalon.Meta.CollectionPolicy.Undefined, classname, null, null, null, null, null, Mode.Implicit) { } /// Creation of a new deployment profile using a supplied template profile. /// the name to assign to the created profile /// /// the template deployment profile /// public ComponentProfile(System.String name, ComponentProfile template):this(name, template.Activation, template.CollectionPolicy, template.m_classname, template.m_categories, template.m_context, template.m_dependencies, template.m_stages, template.m_configuration, Mode.Explicit) { } public ComponentProfile(System.String name, ActivationPolicy activation, Apache.Avalon.Meta.CollectionPolicy collection, System.String classname, CategoriesDirective categories, ContextDirective context, DependencyDirective[] dependencies, StageDirective[] stages, IConfiguration config, Mode mode) : base(name, activation, mode) { if (null == (System.Object) classname) { throw new System.NullReferenceException("classname"); } m_collection = collection; m_classname = classname; m_categories = categories; m_context = context; //m_parameters = parameters; m_configuration = config; if (null == dependencies) { m_dependencies = new DependencyDirective[0]; } else { m_dependencies = dependencies; } if (null == stages) { m_stages = new StageDirective[0]; } else { m_stages = stages; } } //-------------------------------------------------------------------------- // implementation //-------------------------------------------------------------------------- /// Return the component type classname. /// /// /// classname of the component type /// public virtual System.String Classname { get { return m_classname; } } /// Return the component collection policy. If null, the component /// type collection policy will apply. /// /// /// a HARD, WEAK, SOFT or UNDEFINED /// public virtual CollectionPolicy CollectionPolicy { get { return m_collection; } } /// Return the logging categories for the profile. /// /// /// the logger /// public virtual CategoriesDirective Categories { get { return m_categories; } } /// Return the context directive for the profile. /// /// /// the ContextDirective for the profile. /// public virtual ContextDirective Context { get { return m_context; } } /// Return the dependency directives. /// /// /// the set of DependencyDirective statements for the profile. /// public virtual DependencyDirective[] DependencyDirectives { get { return m_dependencies; } } /// Return the stage directives. /// /// /// the set of StageDirective statements for the profile. /// public virtual StageDirective[] StageDirectives { get { return m_stages; } } /// Return the Parameters for the profile. /// /// /// the Parameters for Component (if any). /// /* public virtual Parameters Parameters { get { return m_parameters; } } */ /// Return the base Configuration for the profile. The implementation /// garantees that the supplied configuration is not null. /// /// /// the base Configuration for profile. /// public virtual IConfiguration Configuration { get { return m_configuration; } } /// Return the dependency directive for a supplied key. /// /// /// the matching DependencyDirective (possibly null if /// no directive is declared for the given key) /// public virtual DependencyDirective getDependencyDirective(System.String key) { DependencyDirective[] directives = DependencyDirectives; for (int i = 0; i < directives.Length; i++) { DependencyDirective directive = directives[i]; if (directive.Key.Equals(key)) { return directive; } } return null; } /// Return the dependency directive for a supplied key. /// /// /// the matching DependencyDirective (possibly null if /// no directive is declared for the given key) /// public virtual StageDirective getStageDirective(System.String key) { StageDirective[] directives = StageDirectives; for (int i = 0; i < directives.Length; i++) { StageDirective directive = directives[i]; if (directive.Key.Equals(key)) { return directive; } } return null; } /// Returns a string representation of the profile. /// a string representation /// public override System.String ToString() { return "[" + Name + "]"; } } }