

/*                                         
 *  T H E                                     Copyright (c) The Theory Center,
 *                                            Inc. 1997-1999. All Rights Re-
 * |||||  ||                                  served. Unpublished rights re-
 *   ||   ||                                  served under the copyright laws
 *   ||   ||||    |||    |||   |||||  |  ||   of the United States. The soft-
 *   ||   ||  |  |   |  ||  |  ||  |  |  ||   ware contained on this media is
 *   ||   ||  |  |||||  ||  |  ||     |  ||   proprietary to and embodies the
 *   ||   ||  |  |      ||  |  ||      ||||   confidential technology of
 *   ||   ||  |   |||    |||   ||         |   The Theory Center. The possession
 *                                     ||||   or receipt of this information
 *                                            does not convey any right to dis-
 *  |||                   ||                  close its contents, reproduce it,
 * ||  |                  ||                  or use,  or license the use, for
 * ||      |||   ||||    ||||   |||   |||||   manufacture or sale, the informa-
 * ||     |   |  ||  |    ||   |   |  ||  |   tion or anything described
 * ||     |||||  ||  |    ||   |||||  ||      therein. Any use, disclosure, or
 * ||  |  |      ||  |    ||   |      ||      reproduction without The Theory
 *  |||    |||   ||  |    ||    |||   ||      Center's prior written permission
 *                                            is strictly prohibited.
 *
 * Generated By Theory's SmartGenerator:
 * At Mon Aug 09 13:22:16 EDT 1999
 *
 * $Header: /smart/src/examples/extending/AlphaNumericSequencerExtensionImpl.java 7     8/25/99 1:13p Derrick $
 */


package examples.extending;

import theory.smart.foundation.*;
import theory.smart.util.*;

import java.util.*;
import java.rmi.*;
import javax.ejb.*;
import javax.naming.*;
import com.sun.java.util.collections.TreeMap;
import com.sun.java.util.collections.TreeSet;
import com.sun.java.util.collections.LinkedList;
import com.sun.java.util.collections.ArrayList;
import com.sun.java.util.collections.Iterator;
import com.sun.java.util.collections.ListIterator;
import theory.smart.util.DatabaseConnection;
import theory.smart.util.TcBmp;

//$Import$_Begin ------------ CUSTOM CODE ---------------
// Place additional import statements here
//$Import$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/**
 * 
 *
 * <pre>
 * Primary Key = {@link examples.extending.AlphaNumericSequencerExtensionPk examples.extending.AlphaNumericSequencerExtensionPk}
 * </pre>
 *
 * @see examples.extending.AlphaNumericSequencerExtension
 * @see examples.extending.AlphaNumericSequencerExtensionHome
 * @see examples.extending.AlphaNumericSequencerExtensionValue
 */
public class AlphaNumericSequencerExtensionImpl extends theory.smart.axiom.util.AlphaNumericSequencerImpl
//$Implements$_Begin ------------ CUSTOM CODE ---------------
// Add interfaces that are implemented here
//$Implements$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
{

//$AdditionalAttributeDeclarations$_Begin ------------ CUSTOM CODE ---------------
// Add additional attribute declarations here
//$AdditionalAttributeDeclarations$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



public AlphaNumericSequencerExtensionImpl() throws CreateException
{
  super();

//$Constructor$_Begin ------------ CUSTOM CODE ---------------
// Add constructor code here
//$Constructor$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
/**
 * Get all of AlphaNumericSequencerExtension's attributes.
 *
 * @return AlphaNumericSequencerExtensionValue the AlphaNumericSequencerExtension value object
 */
public AlphaNumericSequencerExtensionValue getAlphaNumericSequencerExtensionByValue() throws RemoteException
//$getByValueMethodException$_Begin ------------ CUSTOM CODE ---------------
// Add additional exceptions here
//$getByValueMethodException$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
{
	AlphaNumericSequencerExtensionValue value = new AlphaNumericSequencerExtensionValue();



value.identifier = identifier;
value.prefix = prefix;
value.numDigits = numDigits;
value.suffix = suffix;
value.step = step;
value.counter = counter;

//$getByValueMethod$_Begin ------------ CUSTOM CODE ---------------
// Add custom code here
//$getByValueMethod$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

	return value;
}

/**
 * Set all of AlphaNumericSequencerExtension's attributes to the passed in value.
 * Note: Primary key attributes are not set.
 *
 * @param AlphaNumericSequencerExtensionValue the AlphaNumericSequencerExtension value object
 */
public void setAlphaNumericSequencerExtensionByValue(AlphaNumericSequencerExtensionValue value) throws RemoteException
//$setByValueMethodException$_Begin ------------ CUSTOM CODE ---------------
// Add additional exceptions here
//$setByValueMethodException$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
{

super.setAlphaNumericSequencerByValue((theory.smart.axiom.util.AlphaNumericSequencerValue) value);
	// do nothing for PrimaryKey



//$setByValueMethod$_Begin ------------ CUSTOM CODE ---------------
// Add custom code here
//$setByValueMethod$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}

public examples.extending.AlphaNumericSequencerExtensionPk ejbCreate(examples.extending.AlphaNumericSequencerExtensionPk alphaNumericSequencerExtensionPk) throws CreateException, RemoteException
{
  try {
	  Properties env = ctx.getEnvironment();
	  String persistenceType = env.getProperty("PersistenceType");
	  if (persistenceType != null && persistenceType.equals("BMP")) {
		String persistenceTcBmp = env.getProperty("PersistenceTcBmpClass");
		String persistenceDbConn = env.getProperty("PersistenceDbConnClass");
		DatabaseConnection dbConn = (DatabaseConnection) Class.forName(persistenceDbConn).newInstance();
		dbConn.setContext(ctx);
		TcBmp tcBmp = (TcBmp) Class.forName(persistenceTcBmp).newInstance();
		tcBmp.setDatabaseConnection(dbConn);
		tcBmp.create(alphaNumericSequencerExtensionPk, this);
	  } else {
            super.ejbCreate((theory.smart.axiom.util.AlphaNumericSequencerPk) alphaNumericSequencerExtensionPk);
	  }
  } catch (java.lang.Exception e) {
  	throw new javax.ejb.CreateException (e.getMessage());
  }


//$EjbCreate$_Begin ------------ CUSTOM CODE ---------------
// Add custom code here
//$EjbCreate$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
return alphaNumericSequencerExtensionPk;
}

public void ejbPostCreate(examples.extending.AlphaNumericSequencerExtensionPk alphaNumericSequencerExtensionPk) throws CreateException, RemoteException
{
super.ejbPostCreate((theory.smart.axiom.util.AlphaNumericSequencerPk) alphaNumericSequencerExtensionPk);

//$EjbPostCreate$_Begin ------------ CUSTOM CODE ---------------
// Add custom code here
//$EjbPostCreate$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}

public void ejbLoad() throws java.rmi.RemoteException
{
  try {
	  Properties env = ctx.getEnvironment();
	  String persistenceType = env.getProperty("PersistenceType");
	  if (persistenceType != null && persistenceType.equals("BMP")) {
		String persistenceTcBmp = env.getProperty("PersistenceTcBmpClass");
		String persistenceDbConn = env.getProperty("PersistenceDbConnClass");
		DatabaseConnection dbConn = (DatabaseConnection) Class.forName(persistenceDbConn).newInstance();
		dbConn.setContext(ctx);
		TcBmp tcBmp = (TcBmp) Class.forName(persistenceTcBmp).newInstance();
		tcBmp.setDatabaseConnection(dbConn);
		tcBmp.refresh(ctx.getPrimaryKey(),this);
	  }  else {
 	    super.ejbLoad();
	  }
  } catch (java.lang.Exception e) {
  	throw new java.rmi.RemoteException (e.getMessage());
  }


//$EjbLoad$_Begin ------------ CUSTOM CODE ---------------
// Add custom code here
//$EjbLoad$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}

public void ejbStore() throws java.rmi.RemoteException
{
  try {
	  
	  Properties env = ctx.getEnvironment();
	  String persistenceType = env.getProperty("PersistenceType");
	  if (persistenceType != null && persistenceType.equals("BMP")) {
		String persistenceTcBmp = env.getProperty("PersistenceTcBmpClass");
		String persistenceDbConn = env.getProperty("PersistenceDbConnClass");
		DatabaseConnection dbConn = (DatabaseConnection) Class.forName(persistenceDbConn).newInstance();
		dbConn.setContext(ctx);
		TcBmp tcBmp = (TcBmp) Class.forName(persistenceTcBmp).newInstance();
		tcBmp.setDatabaseConnection(dbConn);
		tcBmp.update(ctx.getPrimaryKey(),this);
	  }	 else {
 	    super.ejbStore();
	  }
  } catch (java.lang.Exception e) {
  	throw new java.rmi.RemoteException (e.getMessage());
  }

//$EjbStore$_Begin ------------ CUSTOM CODE ---------------
// Add custom code here
//$EjbStore$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}

public void ejbRemove() throws java.rmi.RemoteException, javax.ejb.RemoveException
{
	try {
		Properties env = ctx.getEnvironment();
	  	String persistenceType = env.getProperty("PersistenceType");
	  	if (persistenceType != null && persistenceType.equals("BMP")) {
			String persistenceTcBmp = env.getProperty("PersistenceTcBmpClass");
			String persistenceDbConn = env.getProperty("PersistenceDbConnClass");
			DatabaseConnection dbConn = (DatabaseConnection) Class.forName(persistenceDbConn).newInstance();
			dbConn.setContext(ctx);
			TcBmp tcBmp = (TcBmp) Class.forName(persistenceTcBmp).newInstance();
			tcBmp.setDatabaseConnection(dbConn);
			tcBmp.remove(ctx.getPrimaryKey());
		} else {
 	 		super.ejbRemove();
	  	}
	  } catch (java.lang.Exception e) {
 	 	throw new java.rmi.RemoteException (e.getMessage());
  	}



//$EjbRemove$_Begin ------------ CUSTOM CODE ---------------
// Add custom code here
//$EjbRemove$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}

public void ejbActivate() throws java.rmi.RemoteException
{
  super.ejbActivate();

//$EjbActivate$_Begin ------------ CUSTOM CODE ---------------
// Add custom code here
//$EjbActivate$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}

public void ejbPassivate() throws java.rmi.RemoteException
{
  super.ejbPassivate();

//$EjbPassivate$_Begin ------------ CUSTOM CODE ---------------
// Add custom code here
//$EjbPassivate$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}

public void setEntityContext(EntityContext ctx) throws java.rmi.RemoteException 
{
  super.setEntityContext(ctx);
//$SetEntityContext$_Begin ------------ CUSTOM CODE ---------------
// Add custom code here
//$SetEntityContext$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}

public void unsetEntityContext() throws java.rmi.RemoteException 
{
  super.unsetEntityContext();
//$UnsetEntityContext$_Begin ------------ CUSTOM CODE ---------------
// Add custom code here
//$UnsetEntityContext$_End   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}

// find the item.
public examples.extending.AlphaNumericSequencerExtensionPk ejbFindByPrimaryKey(examples.extending.AlphaNumericSequencerExtensionPk pk)  throws FinderException, RemoteException
{
	try {
		Properties env = ctx.getEnvironment();
	  	String persistenceType = env.getProperty("PersistenceType");
	  	if (persistenceType != null && persistenceType.equals("BMP")) {
			String persistenceTcBmp = env.getProperty("PersistenceTcBmpClass");
			String persistenceDbConn = env.getProperty("PersistenceDbConnClass");
			DatabaseConnection dbConn = (DatabaseConnection) Class.forName(persistenceDbConn).newInstance();
			dbConn.setContext(ctx);
			TcBmp tcBmp = (TcBmp) Class.forName(persistenceTcBmp).newInstance();
			tcBmp.setDatabaseConnection(dbConn);
		        tcBmp.refresh(pk,this);
		 	return pk;
		}
	} catch (FinderException fe) {
	      	throw fe;
	} catch (java.lang.Exception e) {
 	 	throw new java.rmi.RemoteException (e.getMessage());
	}
    return pk;
}

public Enumeration ejbFindAll() throws FinderException, RemoteException
{
	Enumeration enum = null;
	try {
		Properties env = ctx.getEnvironment();
	  	String persistenceType = env.getProperty("PersistenceType");
	  	if (persistenceType != null && persistenceType.equals("BMP")) {
			String persistenceTcBmp = env.getProperty("PersistenceTcBmpClass");
			String persistenceDbConn = env.getProperty("PersistenceDbConnClass");
			DatabaseConnection dbConn = (DatabaseConnection) Class.forName(persistenceDbConn).newInstance();
			dbConn.setContext(ctx);
			TcBmp tcBmp = (TcBmp) Class.forName(persistenceTcBmp).newInstance();
			tcBmp.setDatabaseConnection(dbConn);
		 	enum = tcBmp.findAll();
		}
	} catch (java.lang.Exception e) {
 	 	throw new java.rmi.RemoteException (e.getMessage());
  	}
	return enum;
}


  /**
   * This method returns the CURRENT value of the sequencer. (using a hex counter)
   *
   * @see #getNextValue
   */
  
  public String getValue() throws java.rmi.RemoteException
  {
    // convert to hex
    String counterStr = Integer.toHexString(counter);
    
    return prefix + counterStr + suffix;
  }


}