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

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

/*
* 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 de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.base.conf.ConstructorConfig;
import de.odysseus.calyxo.base.conf.ObjectConfig;

/**
* Object configuration implementation.
*
* @author Christoph Beck
*/
public class ObjectConfigImpl extends FeaturesConfigImpl implements ObjectConfig {
  private String className;
  private ConstructorConfig constructor;

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

  /* (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(constructor);
  }

  /*
   * (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("class", className);
  }

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

  /*
   * (non-Javadoc)
   * @see de.odysseus.calyxo.base.conf.ObjectConfig#create()
   */
  public Object create(ClassLoader loader) throws ConfigException {
    Object value = null;
    try {
      Class clazz = loader.loadClass(className);
      if (constructor == null) {
        value = clazz.newInstance();
      } else {
        value = constructor.invoke(clazz, loader);
      }
    } catch (Exception e) {
      throw new ConfigException(
        "Could not create object of class " + className + " in " + toInlineString(), e);
    }
    apply(value, loader);
    return value;
  }

  /**
   * Get className property
   */
  public String getClassName() {
    return className;
  }

  /**
   * Set className property
   */
  public void setClassName(String className) {
    this.className = className;
  }

  /**
   * Get constructor element
   */
  public ConstructorConfig getConstructorConfig() {
    return constructor;
  }

  /**
   * Set constructor element
   */
  public void setConstructorConfig(ConstructorConfig constructor) {
    this.constructor = constructor;
  }
}
TOP

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

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.