// 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.Meta; /// A containment profile describes a containment context including /// a classloader and the set of profiles explicitly included within /// the a container. /// /// /// Avalon Development Team /// /// $Revision: 1.2 $ $Date: 2004/02/28 22:15:36 $ /// public class ContainmentProfile : DeploymentProfile { //======================================================================== // static //======================================================================== /// Container path delimiter. public const System.String DELIMITER = "/"; private static readonly ServiceDirective[] EMPTY_SERVICES; private static readonly DeploymentProfile[] EMPTY_PROFILES; private static readonly CategoriesDirective EMPTY_CATEGORIES = new CategoriesDirective(); private static readonly TypeLoaderDirective EMPTY_TYPELOADER = new TypeLoaderDirective(new LibraryDirective(), new ClasspathDirective()); //======================================================================== // state //======================================================================== /// The classloader directive. private TypeLoaderDirective m_typeloader; /// The published service directives. private ServiceDirective[] m_export; /// The profiles described within the scope of the containment profile. private DeploymentProfile[] m_profiles; /// The assigned logging categories. private CategoriesDirective m_categories; //-------------------------------------------------------------------------- // constructor //-------------------------------------------------------------------------- /// Creation of a new empty containment profile. public ContainmentProfile():this("container", null, null, null, null) { } /// Creation of a new containment profile. /// /// /// the profile name /// /// the description of the classloader to be /// created for this containment profile /// /// the set of servides that this component is /// dependent on for normal execution /// /// the set of profiles contained within this /// containment profile /// public ContainmentProfile(System.String name, TypeLoaderDirective typeloader, ServiceDirective[] exports, CategoriesDirective categories, DeploymentProfile[] profiles) : base(name, ActivationPolicy.Startup, Mode.Explicit) { m_categories = categories; m_typeloader = typeloader; m_profiles = profiles; m_export = exports; } //-------------------------------------------------------------------------- // implementation //-------------------------------------------------------------------------- /// Return the logging categories for the profile. /// /// /// the categories /// public virtual CategoriesDirective Categories { get { if (m_categories == null) return EMPTY_CATEGORIES; return m_categories; } } /// Return the classloader directive that describes the creation /// arguments for the classloader required by this container. /// /// /// the classloader directive /// public virtual TypeLoaderDirective TypeLoaderDirective { get { if (m_typeloader == null) return EMPTY_TYPELOADER; return m_typeloader; } } /// Return the set of service directives that describe the mapping /// between services exposrted by the container and its implementation /// model. /// /// /// the array of service directives /// public virtual ServiceDirective[] ExportDirectives { get { if (m_export == null) return EMPTY_SERVICES; return m_export; } } /// Retrieve a service directive matching a supplied class. /// /// /// the class to match /// /// the service directive or null if it does not exist /// public virtual ServiceDirective GetExportDirective(System.Type clazz) { System.String classname = clazz.FullName; ServiceDescriptor[] services = ExportDirectives; for (int i = 0; i < services.Length; i++) { ServiceDirective virtual_Renamed = (ServiceDirective) services[i]; if (virtual_Renamed.Reference.Type.Equals(clazz)) { return virtual_Renamed; } } return null; } /// Return the set of nested profiles wihin this containment profile. /// /// /// the profiles nested in this containment profile /// public virtual DeploymentProfile[] Profiles { get { if (m_profiles == null) return EMPTY_PROFILES; return m_profiles; } } /// Return the set of nested profiles contained within this profile matching /// the supplied mode. /// /// /// one of enumerated value {@link Mode#IMPLICIT}, /// {@link Mode#PACKAGED}, or {@link Mode#EXPLICIT} /// /// the profiles matching the supplied creation mode /// public virtual DeploymentProfile[] GetProfiles(Mode mode) { DeploymentProfile[] profiles = Profiles; return selectProfileByMode(profiles, mode); } /// Returns a sub-set of the supplied containers matching the supplied creation mode. /// the profiles to select from /// /// the creation mode to retrict the returned selection to /// /// the subset of the supplied profiles with a creation mode matching /// the supplied mode value /// private DeploymentProfile[] selectProfileByMode(DeploymentProfile[] profiles, Mode mode) { System.Collections.ArrayList list = new System.Collections.ArrayList(); for (int i = 0; i < profiles.Length; i++) { DeploymentProfile profile = profiles[i]; if (profile.Mode.Equals(mode)) { list.Add(profile); } } return (DeploymentProfile[]) list.ToArray( typeof(DeploymentProfile) ); } static ContainmentProfile() { EMPTY_SERVICES = new ServiceDirective[0]; EMPTY_PROFILES = new DeploymentProfile[0]; } } }