DirStateFactory.Result res = DirectoryManager.getStateToBind( obj, name, this, env, null );
DN target = buildTarget( DN.fromName( name ) );
// let's be sure that the Attributes is case insensitive
ServerEntry outServerEntry = null;
try
{
outServerEntry = ServerEntryUtils.toServerEntry( AttributeUtils.toCaseInsensitive( res
.getAttributes() ), target, service.getSchemaManager() );
}
catch ( LdapInvalidAttributeTypeException liate )
{
throw new NamingException( I18n.err( I18n.ERR_495, obj ) );
}
if ( outServerEntry != null )
{
try
{
doAddOperation( target, outServerEntry );
}
catch ( Exception e )
{
JndiUtils.wrap( e );
}
return;
}
if ( obj instanceof ServerEntry )
{
try
{
doAddOperation( target, ( ServerEntry ) obj );
}
catch ( Exception e )
{
JndiUtils.wrap( e );
}
}
// Check for Referenceable
else if ( obj instanceof Referenceable )
{
throw new NamingException( I18n.err( I18n.ERR_493 ) );
}
// Store different formats
else if ( obj instanceof Reference )
{
// Store as ref and add outAttrs
throw new NamingException( I18n.err( I18n.ERR_494 ) );
}
else if ( obj instanceof Serializable )
{
// Serialize and add outAttrs
ServerEntry serverEntry = service.newEntry( target );
if ( ( outServerEntry != null ) && ( outServerEntry.size() > 0 ) )
{
for ( EntryAttribute serverAttribute : outServerEntry )
{
try
{
serverEntry.put( serverAttribute );
}
catch ( LdapException le )
{
throw new NamingException( I18n.err( I18n.ERR_495, 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_495, obj ) );
}
try
{
doAddOperation( target, serverEntry );
}
catch ( Exception e )
{
JndiUtils.wrap( e );
}
}
else if ( obj instanceof DirContext )
{
// Grab attributes and merge with outAttrs
ServerEntry serverEntry = null;
try
{
serverEntry = ServerEntryUtils.toServerEntry( ( ( DirContext ) obj ).getAttributes( "" ),
target, service.getSchemaManager() );
}
catch ( LdapInvalidAttributeTypeException liate )
{
throw new NamingException( I18n.err( I18n.ERR_495, obj ) );
}
if ( ( outServerEntry != null ) && ( outServerEntry.size() > 0 ) )
{
for ( EntryAttribute serverAttribute : outServerEntry )
{
try
{
serverEntry.put( serverAttribute );
}
catch ( LdapException le )
{
throw new NamingException( I18n.err( I18n.ERR_495, obj ) );
}