return;
}
DN target = buildTarget( DN.fromName( name ) );
ServerEntry serverEntry = null;
try
{
serverEntry = ServerEntryUtils.toServerEntry( AttributeUtils.toCaseInsensitive( attrs ), target,
getDirectoryService().getSchemaManager() );
}
catch ( LdapInvalidAttributeTypeException liate )
{
throw new InvalidAttributesException( liate.getMessage() );
}
// No object binding so we just add the attributes
if ( null == obj )
{
ServerEntry clone = ( ServerEntry ) serverEntry.clone();
try
{
doAddOperation( target, clone );
}
catch ( Exception e )
{
JndiUtils.wrap( e );
}
return;
}
// First, use state factories to do a transformation
DirStateFactory.Result res = DirectoryManager.getStateToBind( obj, name, this, getEnvironment(), attrs );
ServerEntry outServerEntry = null;
try
{
outServerEntry = ServerEntryUtils.toServerEntry(
res.getAttributes(), target, getDirectoryService().getSchemaManager() );
}
catch ( LdapInvalidAttributeTypeException le )
{
throw new InvalidAttributesException( le.getMessage() );
}
if ( outServerEntry != serverEntry )
{
ServerEntry clone = ( ServerEntry ) serverEntry.clone();
if ( ( outServerEntry != null ) && ( outServerEntry.size() > 0 ) )
{
for ( EntryAttribute attribute : outServerEntry )
{
try
{
clone.put( attribute );
}
catch ( LdapException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
try
{
// setup the op context
doAddOperation( target, clone );
}
catch ( Exception e )
{
JndiUtils.wrap( e );
}
return;
}
// Check for Referenceable
if ( obj instanceof Referenceable )
{
throw new NamingException( I18n.err( I18n.ERR_493 ) );
}
// Store different formats
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 clone = ( ServerEntry ) serverEntry.clone();
if ( outServerEntry != null && outServerEntry.size() > 0 )
{
for ( EntryAttribute attribute : outServerEntry )
{
try
{
clone.put( attribute );
}
catch ( LdapException le )
{
throw new InvalidAttributesException( le.getMessage() );
}
}
}
try
{
// Serialize object into entry attributes and add it.
JavaLdapSupport.serialize( serverEntry, obj, getDirectoryService().getSchemaManager() );
// setup the op context
doAddOperation( target, clone );
}
catch ( Exception e )
{
JndiUtils.wrap( e );
}
}
else if ( obj instanceof DirContext )
{
// Grab attributes and merge with outAttrs
ServerEntry entry = null;
try
{
entry = ServerEntryUtils.toServerEntry( ( ( DirContext ) obj ).getAttributes( "" ), target,
getDirectoryService().getSchemaManager() );
}
catch ( LdapInvalidAttributeTypeException liate )
{
throw new InvalidAttributeIdentifierException( liate.getMessage() );
}
if ( ( outServerEntry != null ) && ( outServerEntry.size() > 0 ) )
{
for ( EntryAttribute attribute : outServerEntry )
{
try
{
entry.put( attribute );
}
catch ( LdapException le )
{
throw new InvalidAttributeValueException( le.getMessage() );
}