/**
  * Return a dependency model matching the supplied descriptor. If no model matches the supplied
  * descriptor the implementation will return null.
  *
  * @param dependency the dependency descriptor
  * @return the matching stage model
  */
 public DependencyModel getDependencyModel(DependencyDescriptor dependency) {
   DependencyModel[] models = getDependencyModels();
   for (int i = 0; i < models.length; i++) {
     DependencyModel model = models[i];
     if (dependency.equals(model.getDependency())) {
       return model;
     }
   }
   return null;
 }
 /**
  * Return TRUE is this model is capable of supporting a supplied depedendency.
  *
  * @param dependency the dependency descriptor
  * @return true if this model can fulfill the dependency
  */
 public boolean isaCandidate(DependencyDescriptor dependency) {
   return isaCandidate(dependency.getReference());
 }
  /**
   * Creation of a new deployment model.
   *
   * @param context the deployment context
   */
  public DefaultComponentModel(ComponentContext context, SecurityModel security)
      throws ModelException {
    super(context, security);

    m_context = context;

    m_activation = getDefaultActivationPolicy();

    setCollectionPolicy(m_context.getComponentProfile().getCollectionPolicy());

    ClassLoader classLoader = m_context.getClassLoader();

    if (isConfigurable()) {
      final Configuration defaults = m_context.getType().getConfiguration();
      final Configuration explicit = m_context.getComponentProfile().getConfiguration();
      final Configuration consolidated = consolidateConfigurations(explicit, defaults);
      if (consolidated != null) {
        m_config = consolidated;
      } else {
        m_config = EMPTY_CONFIGURATION;
      }
    }

    if (isParameterizable()) {
      Parameters staticDefaults = m_context.getType().getParameters();
      final Parameters parameters = m_context.getComponentProfile().getParameters();
      if (parameters != null) {
        if (null == staticDefaults) {
          m_parameters = parameters;
        } else {
          m_parameters = new Parameters();
          m_parameters.merge(staticDefaults);
          m_parameters.merge(parameters);
        }
      } else {
        if (null == staticDefaults) {
          m_parameters = Parameters.EMPTY_PARAMETERS;
        } else {
          m_parameters = staticDefaults;
        }
      }
    }

    final ContextDescriptor contextDescriptor = m_context.getType().getContext();
    final ContextDirective contextDirective = m_context.getComponentProfile().getContext();
    final Logger log = getLogger().getChildLogger("context");
    m_contextModel = new DefaultContextModel(log, contextDescriptor, contextDirective, context);

    //
    // create the dependency models for subsequent assembly
    // management
    //

    DependencyDescriptor[] dependencies = m_context.getType().getDependencies();
    m_dependencies = new DefaultDependencyModel[dependencies.length];

    for (int i = 0; i < dependencies.length; i++) {
      DependencyDescriptor descriptor = dependencies[i];
      DependencyDirective directive =
          context.getComponentProfile().getDependencyDirective(descriptor.getKey());
      m_dependencies[i] =
          new DefaultDependencyModel(
              context.getLogger().getChildLogger("deps"),
              context.getPartitionName(),
              context.getProfile().getName(),
              descriptor,
              directive);
    }

    //
    // create the stage models for subsequent assembly
    // management
    //

    StageDescriptor[] stages = m_context.getType().getStages();
    m_stages = new DefaultStageModel[stages.length];

    for (int i = 0; i < stages.length; i++) {
      StageDescriptor descriptor = stages[i];
      StageDirective directive =
          context.getComponentProfile().getStageDirective(descriptor.getKey());
      m_stages[i] =
          new DefaultStageModel(
              context.getLogger().getChildLogger("stages"),
              context.getPartitionName(),
              descriptor,
              directive);
    }
  }