ActionFactory.java :  » Content-Management-System » webman » de » webman » acl » Java Open Source

Java Open Source » Content Management System » webman 
webman » de » webman » acl » ActionFactory.java
package de.webman.acl;

import com.teamkonzept.lib.ConfigurationManager;
import com.teamkonzept.lib.TKException;
import com.teamkonzept.lib.TKVector;
import de.webman.acl.db.*;
import de.webman.acl.resolver.ResolverFactory;
import com.teamkonzept.webman.mainint.WebmanExceptionHandler;

/**
 * Factory for action objects.
 *
 * @version 1.0
 * @since 1.0
 * @author © 2001 Webman AG
 */
public class ActionFactory
  extends ObjectFactoryBase
  implements ObjectFactory
{

  // $Header: /cvsroot/webman-cms/source/webman/de/webman/acl/ActionFactory.java,v 1.1 2001/08/20 08:25:07 mischa Exp $

  // Constants

  /**
   * Singleton instance.
   */
  private static ActionFactory SINGLETON = null;


  // Constructors

  /**
   * Inhibits instantiation from outside.
   */
  private ActionFactory ()
  {
    super();
  }


  // Instance

  /**
   * Returns the singleton instance of the factory.
   *
   * @return the singleton instance of the factory.
   * @exception com.teamkonzept.lib.TKException if an error occured during initialization.
   */
  public static synchronized final ActionFactory getInstance ()
    throws TKException
  {
    if (SINGLETON == null)
    {
      SINGLETON = new ActionFactory();
      SINGLETON.configurationChanged();
      ConfigurationManager.getInstance()
                .registerConfigurationListener(SINGLETON,
                                 PROPERTY_GROUP_NAME);
    }

    return SINGLETON;
  }


  // Method implementations

  /**
   * Returns the action database interface.
   *
   * @return the action database interface.
   */
  public final ObjectDBInterface getDBInterface ()
  {
    return ActionDBInterface.getInstance();
  }

  /**
   * Returns an action data wrapper.
   *
   * @param id the ID of the action.
   * @return an action data wrapper.
   */
  public final ObjectDBData getDBData (Integer id)
  {
    return new ActionDBData(id, null);
  }

  /**
   * Returns an action data wrapper.
   *
   * @param object the action.
   * @return an action data wrapper.
   */
  public final ObjectDBData getDBData (WMObject object)
  {
    return new ActionDBData((Action) object);
  }

  /**
   * Builds an concrete action object.
   *
   * @param data the initial action data.
   * @return an concrete action object.
   */
  public final WMObject buildObject (ObjectDBData data)
  {
    return new Action((ActionDBData) data);
  }


  // Convenience methods

  /**
   * Retrieves the specified action.
   *
   * @param id the ID of the action.
   * @return the specified action.
   * @exception com.teamkonzept.lib.TKException if an error occured during action retrieval.
   */
  public final Action getAction (Integer id)
    throws TKException
  {
    return (Action) getObject(id);
  }

  /**
   * Retrieves all known actions.
   *
   * @return all known actions.
   * @exception com.teamkonzept.lib.TKException if an error occured during action retrieval.
   */
  public final TKVector getActions ()
    throws TKException
  {
    return getObjects();
  }

  /**
   * Retrieves all actions referenced by the given event.
   *
   * @param event the event.
   * @return all actions referenced by the given event.
   * @exception com.teamkonzept.lib.TKException if an error occured during action retrieval.
   */
  public final TKVector getActions (Event event)
    throws TKException
  {
    TKVector objects = null;

    try
    {
      // Create appropriate data.
      ActionDBData data = new ActionDBData((Integer) null, null);
      data.setQuery(ActionDBInterface.WM_ACTION_EVENT_SELECT_BY_EVENT);
      data.setPrototype(new ObjectCollectionDBData(EventDBInterface.PRIMARY_KEY_NAME,
                               event.getID(),
                               ActionDBInterface.PRIMARY_KEY_NAME,
                               null));

      // Database lookup.
      objects = getObjects(getObjectIDs(data));
    }
    catch (Exception x)
    {
      throw WebmanExceptionHandler.getException(x);
    }

    return objects;
  }

  /**
   * Creates the specified action.
   *
   * @param name the name of the action.
   * @return the specified action.
   * @exception com.teamkonzept.lib.TKException if an error occured during action creation.
   */
  public final Action createAction (String name)
    throws TKException
  {
    return (Action) createObject(new ActionDBData(null,
                              name));
  }

  /**
   * Modifies the given action.
   *
   * @param action the action to be modified.
   * @exception com.teamkonzept.lib.TKException if an error occured during action modification.
   */
  public final void modifyAction (Action action)
    throws TKException
  {
    if (action.isModifiedAssociations())
    {
      ResolverFactory.getInstance().removeResolvers();
    }

    modifyObject(action);
  }

  /**
   * Deletes the given action.
   *
   * @param action the action to be deleted.
   * @exception com.teamkonzept.lib.TKException if an error occured during action deletion.
   */
  public final void deleteAction (Action action)
    throws TKException
  {
    ResolverFactory.getInstance().removeResolvers();

    deleteObject(action);
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.