com.bankframe.ei.ldap
Class LDAPEntityBean

java.lang.Object
  extended bycom.bankframe.ejb.EEntityBean
      extended bycom.bankframe.ei.ldap.LDAPEntityBean
All Implemented Interfaces:
javax.ejb.EnterpriseBean, javax.ejb.EntityBean, java.io.Serializable
Direct Known Subclasses:
LDAPBankFrameSessionBean

public abstract class LDAPEntityBean
extends EEntityBean

This class is the base class for Bean Managed EJB's that persist to/from an LDAP data source All bankframe entities that need to access LDAP data should derive from this class.

The derived class must implement the abstract getRdnAttributeName() method, In ldap terms the rdn ( Relative Distinguished Name ) is an entity's primary key.

The derived class can set and get attribute values using the put() and get() methods. Multi-valued attributes should be put and got using the putMultiple() and getMultiple() methods which expect the multiple values to be passed/returned as enumerations

The derived class can specifiy its LDAP objectclass(es) using the putObjectClass() method. The object's attributes and objectclasses MUST be

specified before a call to the LDAPEntityBean.ejbCreate() method is called.

The derived class's ejbCreate() method(s) should return an instance of the LDAPEntityBeanPK class or sub-class

Establishing a connection with the LDAP data source

The LDAPEntityBean uses the following rule to determine how to connect to the LDAP server
  1. Check the EJB deployment descriptor environment properties for a value named: ldap.serverContextAlias. This value defines an alias for the ldap connection to use. It passes this alias to LDAPServerContextFactory, which should return an instance of the appropriate context.

Sample Bean


import java.rmi.RemoteException;
import javax.ejb.CreateException;
import com.bankframe.ei.ldap.LDAPEntityBean;

public class ExampleLDAPBean extends LDAPEntityBean {
private final String RDN_ATTRIBUTE_NAME="cn";
// ejb creation method
public LDAPEntityBeanPK ejbCreate(String commonName) throws CreateException {
this.putObjectClass("container");
this.put(this.RDN_ATTRIBUTE_NAME,commonName);
return super.ejbCreate();
}
// required method
public void ejbPostCreate(String commonName) throws RemoteException, CreateException {
}
// required method
public String getRdnAttributeName() {
return this.RDN_ATTRIBUTE_NAME;
}
// EntityBean attribute getter
public String getCommonName() {
return this.get(this.RDN_ATTRIBUTE_NAME);
}
public LDAPEntityBeanPK ejbFindByPrimaryKey(LDAPEntityBeanPK primaryKey) throws FinderException {
return (LDAPEntityBeanPK)super.ldapFindByPrimaryKey(primaryKey);
}
public Enumeration ejbFindAll() throws FinderException {
return super.ldapFindAll(LDAPEntityBeanPK.class);
}
}

Using Custom Primary Key classes

In some cases it may not be possible to use the standard LDAPEntityBeanPK primary key class, for example if you wish to share the primary key class with a CMP entity bean. In this case you should create a primary key class that implements the LDAPPrimaryKey interface. The LDAP BMP bean class will also have to redefine the ejbFindByPrimaryKey() and ejbFindAll() methods. See the example below. See also com.bankframe.services.route.RoutePK.

Sample Primary Key class that can be used by CMP bean or LDAP BMP bean


import com.bankframe.ei.ldap.LDAPPrimaryKey;

public class ExamplePK implements LDAPrimaryKey {
public String attribute1;

ExamplePK() {};
ExamplePK(String attribute1) { this.attribute1 = attribute1; }

// LDAPPrimaryKey required methods

public String getRdnAttributeValue() { return this.attribute1; }
public void setRdnAttributeValue(String value) { this.attribute1 = value ;}
public boolean equals( Object o ) {
if ( o instanceof ExamplePK ) {
ExamplePK otherKey = (ExamplePK)o;
return this.attribute1.equals(otherKey.attribute1)
}
return false;
} public int hashCode() { return attribute1.hashCode(); }
}

The example EJB above would need to be adapted as follows to use this primary key class:


public ExamplePK ejbCreate(String commonName) throws CreateException {
this.putObjectClass("container");
this.put(this.RDN_ATTRIBUTE_NAME,commonName);
super.ldapCreate();
// create the primary key ourselves
return new ExamplePK(commonName);
}

public ExamplePK ejbFindByPrimaryKey(ExamplePK primaryKey) throws FinderException {
return (ExamplePK)super.ldapFindByPrimaryKey(primaryKey);
}

public Enumeration ejbFindAll() throws FinderException {
return super.ldapFindAll(ExamplePK.class);
}

Author:
etu
See Also:
Serialized Form

Field Summary
static java.lang.String LDAP_SERVER_CONTEXT_ALIAS
           
 
Constructor Summary
LDAPEntityBean()
           
 
Method Summary
 void ejbActivate()
          This method is called by the EJB Container when this entity instance is activated, i.e.
 void ejbLoad()
          This method is called by the EJB Container when this entity instance must referesh its instance data from the data source
 void ejbPassivate()
          This method is called by the EJB Container when this entity instance is about to be passivated, i.e.
 void ejbRemove()
          This method is called by the EJB Container when this entity instance is about to be removed, the data in the LDAP server should be deleted
 void ejbStore()
          This method is called by the EJB Container when this entity instance should be persisted to the LDAP server
 java.lang.Object get(java.lang.String key)
          This method retireves the specified ldap attribute
 java.util.Enumeration getMultiple(java.lang.String key)
          This method retrieves an ldap attribute that contains more than one value
 LDAPPrimaryKey getPrimaryKey()
          This method gets the Primary Key for this entity bean
abstract  java.lang.String getRdnAttributeName()
          This method must be implemented by all derived classes.
 LDAPEntityBeanPK ldapCreate()
          This method initialises the bean, create the entry on the ldap server and create a primary key instance
 void put(java.lang.String key, java.lang.Object value)
          This method stores the specified ldap attribute
 void putMultiple(java.lang.String key, java.util.Enumeration values)
          This method stores multiple values in an attribute
 void putObjectClass(java.lang.String objectClass)
          This method stores the ldap object's objectclass.
 void setEntityContext(javax.ejb.EntityContext ctx)
          This method is called by the EJB Container to store the entity's context
 DataPacket toDataPacket()
          This method provides a default implementation of toDataPacket() by copying the values of each of the attributes to the dataPacket
 void unsetEntityContext()
          This method is called by the EJB Container when this entity bean instance is about to returned to the free bean pool.
 
Methods inherited from class com.bankframe.ejb.EEntityBean
toString, validate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LDAP_SERVER_CONTEXT_ALIAS

public static final java.lang.String LDAP_SERVER_CONTEXT_ALIAS
See Also:
Constant Field Values
Constructor Detail

LDAPEntityBean

public LDAPEntityBean()
Method Detail

ejbActivate

public void ejbActivate()
This method is called by the EJB Container when this entity instance is activated, i.e. is about to be used

Specified by:
ejbActivate in interface javax.ejb.EntityBean
Overrides:
ejbActivate in class EEntityBean

ejbLoad

public void ejbLoad()
This method is called by the EJB Container when this entity instance must referesh its instance data from the data source

Specified by:
ejbLoad in interface javax.ejb.EntityBean
Overrides:
ejbLoad in class EEntityBean

ejbPassivate

public void ejbPassivate()
This method is called by the EJB Container when this entity instance is about to be passivated, i.e. is no longer going to be used

Specified by:
ejbPassivate in interface javax.ejb.EntityBean
Overrides:
ejbPassivate in class EEntityBean

ejbRemove

public void ejbRemove()
This method is called by the EJB Container when this entity instance is about to be removed, the data in the LDAP server should be deleted

Specified by:
ejbRemove in interface javax.ejb.EntityBean
Overrides:
ejbRemove in class EEntityBean

ejbStore

public void ejbStore()
This method is called by the EJB Container when this entity instance should be persisted to the LDAP server

Specified by:
ejbStore in interface javax.ejb.EntityBean
Overrides:
ejbStore in class EEntityBean

get

public java.lang.Object get(java.lang.String key)
This method retireves the specified ldap attribute

Parameters:
key - Name of the attribute to retrieve

getMultiple

public java.util.Enumeration getMultiple(java.lang.String key)
This method retrieves an ldap attribute that contains more than one value

Parameters:
key - Name of the attribute to retrieve

getPrimaryKey

public LDAPPrimaryKey getPrimaryKey()
This method gets the Primary Key for this entity bean


getRdnAttributeName

public abstract java.lang.String getRdnAttributeName()
This method must be implemented by all derived classes. It should return a string containing the name of the LDAP attribute which is used as the entry's relative distinguished name ( ie primary key )

Returns:
String containing entry's rdn attribute name

ldapCreate

public LDAPEntityBeanPK ldapCreate()
                            throws javax.ejb.CreateException
This method initialises the bean, create the entry on the ldap server and create a primary key instance

Throws:
javax.ejb.CreateException - if the entry cannot be created

put

public void put(java.lang.String key,
                java.lang.Object value)
This method stores the specified ldap attribute

Parameters:
key - Name of the attribute
value - The data to store

putMultiple

public void putMultiple(java.lang.String key,
                        java.util.Enumeration values)
This method stores multiple values in an attribute

Parameters:
key - Name of the attribute
values - The data to store

putObjectClass

public void putObjectClass(java.lang.String objectClass)
This method stores the ldap object's objectclass. More than one objectclass may be specified by calling this method more than once. It is not necessary to specifiy the 'top' objectclass, this is done automatically


setEntityContext

public void setEntityContext(javax.ejb.EntityContext ctx)
                      throws java.rmi.RemoteException
This method is called by the EJB Container to store the entity's context

Specified by:
setEntityContext in interface javax.ejb.EntityBean
Overrides:
setEntityContext in class EEntityBean
Parameters:
ctx - - the context of the entity.
Throws:
java.rmi.RemoteException

toDataPacket

public DataPacket toDataPacket()
This method provides a default implementation of toDataPacket() by copying the values of each of the attributes to the dataPacket

Specified by:
toDataPacket in class EEntityBean

unsetEntityContext

public void unsetEntityContext()
                        throws java.rmi.RemoteException
This method is called by the EJB Container when this entity bean instance is about to returned to the free bean pool.

Specified by:
unsetEntityContext in interface javax.ejb.EntityBean
Overrides:
unsetEntityContext in class EEntityBean
Throws:
java.rmi.RemoteException


Copyright © 2004 Siebel Systems, Inc. All rights reserved.