in core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java [1036:1159]
public void bind( Name name, Object obj ) throws NamingException
{
// First, use state factories to do a transformation
DirStateFactory.Result res = DirectoryManager.getStateToBind( obj, name, this, env, null );
Dn target = buildTarget( JndiUtils.fromName( name ) );
// let's be sure that the Attributes is case insensitive
Entry outServerEntry = null;
try
{
outServerEntry = ServerEntryUtils.toServerEntry( AttributeUtils.toCaseInsensitive( res
.getAttributes() ), target, service.getSchemaManager() );
}
catch ( LdapInvalidAttributeTypeException liate )
{
throw new NamingException( I18n.err( I18n.ERR_06012_CANT_BIND, obj ) );
}
if ( outServerEntry != null )
{
try
{
// Remember : a JNDI Bind is a LDAP Add ! Silly, insn't it ?
doAddOperation( target, outServerEntry );
}
catch ( Exception e )
{
JndiUtils.wrap( e );
}
return;
}
if ( obj instanceof Entry )
{
try
{
doAddOperation( target, ( Entry ) obj );
}
catch ( Exception e )
{
JndiUtils.wrap( e );
}
}
// Check for Referenceable
else if ( obj instanceof Referenceable )
{
throw new NamingException( I18n.err( I18n.ERR_06010_CANT_STORE_REFERENCEABLE ) );
}
// Store different formats
else if ( obj instanceof Reference )
{
// Store as ref and add outAttrs
throw new NamingException( I18n.err( I18n.ERR_06011_CANT_STORE_REFERENCE ) );
}
else if ( obj instanceof Serializable )
{
// Serialize and add outAttrs
Entry serverEntry = null;
try
{
serverEntry = service.newEntry( target );
}
catch ( LdapException le )
{
throw new NamingException( I18n.err( I18n.ERR_06012_CANT_BIND, obj ) );
}
// Get target and inject all rdn attributes into entry
injectRdnAttributeValues( target, serverEntry );
// Serialize object into entry attributes and add it.
try
{
JavaLdapSupport.serialize( serverEntry, obj, service.getSchemaManager() );
}
catch ( LdapException le )
{
throw new NamingException( I18n.err( I18n.ERR_06012_CANT_BIND, obj ) );
}
try
{
doAddOperation( target, serverEntry );
}
catch ( Exception e )
{
JndiUtils.wrap( e );
}
}
else if ( obj instanceof DirContext )
{
// Grab attributes and merge with outAttrs
Entry serverEntry = null;
try
{
serverEntry = ServerEntryUtils.toServerEntry( ( ( DirContext ) obj ).getAttributes( "" ),
target, service.getSchemaManager() );
}
catch ( LdapInvalidAttributeTypeException liate )
{
throw new NamingException( I18n.err( I18n.ERR_06012_CANT_BIND, obj ) );
}
injectRdnAttributeValues( target, serverEntry );
try
{
doAddOperation( target, serverEntry );
}
catch ( Exception e )
{
JndiUtils.wrap( e );
}
}
else
{
throw new NamingException( I18n.err( I18n.ERR_06012_CANT_BIND, obj ) );
}
}