Package de.odysseus.calyxo.base.conf.impl

Source Code of de.odysseus.calyxo.base.conf.impl.UseConfigImpl

/*
* Copyright 2004, 2005, 2006 Odysseus Software GmbH
*
* 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.
*/
package de.odysseus.calyxo.base.conf.impl;

import javax.servlet.jsp.el.ExpressionEvaluator;
import javax.servlet.jsp.el.VariableResolver;

import de.odysseus.calyxo.base.ModuleContext;
import de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.base.conf.MemberConfig;
import de.odysseus.calyxo.base.conf.UseConfig;

/**
* Use configuration implementation.
*
* @author Christoph Beck
*/
public class UseConfigImpl extends FeaturesConfigImpl implements UseConfig {
  private Object value;
  private MemberConfig member;

  /*
   * (non-Javadoc)
   * @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_getElementName()
   */
  protected String _getElementName() {
    return "use";
  }

  /* (non-Javadoc)
   * @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_addChildren(de.odysseus.calyxo.base.conf.impl.ConfigImpl.Elements)
   */
  protected void _addChildren(Elements elements) {
    super._addChildren(elements);
    elements.add(member);
  }

  /*
   * (non-Javadoc)
   * @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_putAttributes(de.odysseus.calyxo.base.conf.impl.ConfigImpl.Attributes)
   */
  protected void _putAttributes(Attributes map) {
    super._putAttributes(map);
    map.put("value", value);
  }

  /**
   * Answer array <code>{ "value" }</code>.
   * @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_getDynamicAttributes()
   */
  protected String[] _getDynamicAttributes() {
    return new String[]{ "value" };
  }

  /*
   * (non-Javadoc)
   * @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_resolve(javax.servlet.jsp.el.ExpressionEvaluator, javax.servlet.jsp.el.VariableResolver)
   */
  protected void _resolve(ExpressionEvaluator evaluator, VariableResolver variables) throws ConfigException {
    if ((value == null) == (member == null)) {
      throw new ConfigException("Either value attribute or nested member element required in " + toInlineString());
    }
    super._resolve(evaluator, variables);
  }

  /*
   * (non-Javadoc)
   * @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_evaluate(de.odysseus.calyxo.base.ModuleContext)
   */
  protected void _evaluate(ModuleContext context) throws ConfigException {
    super._evaluate(context);

    ClassLoader loader = context.getClassLoader();
    Object object = member == null ? value : member.get(loader);
    if (object == null) {
      throw new ConfigException("Cannot use null in " + toInlineString());
    }
    apply(object, loader);
  }

  /**
   * Get value property
   */
  public Object getValue() {
    return value;
  }

  /**
   * Set value property
   */
  public void setValue(Object value) {
    this.value = value;
  }

  /**
   * Get member configuration
   */
  public MemberConfig getMemberConfig() {
    return member;
  }

  /**
   * Get member configuration
   */
  public void setMemberConfig(MemberConfig member) {
    this.member = member;
  }
}
TOP

Related Classes of de.odysseus.calyxo.base.conf.impl.UseConfigImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.