You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@directory.apache.org by Yiannis Mavroukakis <im...@gameaccount.com> on 2009/03/18 10:57:38 UTC

[ApacheDS] Using LdifEntry with a ModifyOperationContext

Hello everyone :-)

I've got a problem trying to use LdifEntry with ModifyOperationContext. 
If you remember from
previous emails, I'm using LdifEntry because it can be serialized. I'm 
stuffing my Modification
objects in the LdifEntry object like so

        for( AttributeType attributeType : list )
        {
            EntryAttribute entryAttribute = ( (ServerAttribute) entry
                    .get( attributeType ) ).toClientAttribute( );
            ldiff.addAttribute( entryAttribute );
            if( changeType.equals( ChangeType.Modify ) )
            {
                ClientModification mod = new ClientModification(
                        ModificationOperation.REPLACE_ATTRIBUTE ,
                        entryAttribute );
                ldiff.addModificationItem( mod );
            }
        }

This serializes fine, however ModifyOperationContext.modify() gives me a

java.lang.ClassCastException: 
org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute 
cannot be cast to org.apache.directory.server.core.entry.ServerAttribute

when I pass the LdifEntry object modification list to it because it 
expects ServerAttributes and not ClientAttributes and as far as I can 
remember, ServerAttributes are not serializable (?). Is there any way I 
can get around this requirement?

Thanks guys,

Yiannis

Re: [ApacheDS] Using LdifEntry with a ModifyOperationContext

Posted by Yiannis Mavroukakis <im...@gameaccount.com>.
I'm sure it is :-)
https://issues.apache.org/jira/browse/DIRSERVER-1331 priority is bogus, 
please change it to whatever
you see appropriate :-)

Y.

Emmanuel Lecharny wrote:
> Yiannis Mavroukakis wrote:
>> A little note, this would have been sooo much easier if Ldif had a 
>> getAttributes() method..I could
>> simply then create a new Modification list with ServerAttributes 
>> derived from the ClientAttributes..
> The LdifEntry class existed before the Clent and Server Entry classes. 
> Those last two are not perfect too, especially as many functions using 
> them don't have an implicit conversion. The problem is that we aren't 
> using the generic Entry interface , which would have been better. But 
> it's not that simple...
>
> Defining a new API is just a complex task !
>
> Btw, what about creating a JIRA for the lack of getAttributes() method 
> in Ldif ?
>

Re: [ApacheDS] Using LdifEntry with a ModifyOperationContext

Posted by Emmanuel Lecharny <el...@apache.org>.
Yiannis Mavroukakis wrote:
> A little note, this would have been sooo much easier if Ldif had a 
> getAttributes() method..I could
> simply then create a new Modification list with ServerAttributes 
> derived from the ClientAttributes..
The LdifEntry class existed before the Clent and Server Entry classes. 
Those last two are not perfect too, especially as many functions using 
them don't have an implicit conversion. The problem is that we aren't 
using the generic Entry interface , which would have been better. But 
it's not that simple...

Defining a new API is just a complex task !

Btw, what about creating a JIRA for the lack of getAttributes() method 
in Ldif ?

-- 
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org



Re: [ApacheDS] Using LdifEntry with a ModifyOperationContext

Posted by Yiannis Mavroukakis <im...@gameaccount.com>.
A little note, this would have been sooo much easier if Ldif had a 
getAttributes() method..I could
simply then create a new Modification list with ServerAttributes derived 
from the ClientAttributes..

Y.

Yiannis Mavroukakis wrote:
>
> Hello everyone :-)
>
> I've got a problem trying to use LdifEntry with 
> ModifyOperationContext. If you remember from
> previous emails, I'm using LdifEntry because it can be serialized. I'm 
> stuffing my Modification
> objects in the LdifEntry object like so
>
>        for( AttributeType attributeType : list )
>        {
>            EntryAttribute entryAttribute = ( (ServerAttribute) entry
>                    .get( attributeType ) ).toClientAttribute( );
>            ldiff.addAttribute( entryAttribute );
>            if( changeType.equals( ChangeType.Modify ) )
>            {
>                ClientModification mod = new ClientModification(
>                        ModificationOperation.REPLACE_ATTRIBUTE ,
>                        entryAttribute );
>                ldiff.addModificationItem( mod );
>            }
>        }
>
> This serializes fine, however ModifyOperationContext.modify() gives me a
>
> java.lang.ClassCastException: 
> org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute 
> cannot be cast to org.apache.directory.server.core.entry.ServerAttribute
>
> when I pass the LdifEntry object modification list to it because it 
> expects ServerAttributes and not ClientAttributes and as far as I can 
> remember, ServerAttributes are not serializable (?). Is there any way 
> I can get around this requirement?
>
> Thanks guys,
>
> Yiannis

Re: [ApacheDS] Using LdifEntry with a ModifyOperationContext

Posted by Yiannis Mavroukakis <im...@gameaccount.com>.
I am a fool, I should have googled this a bit further..it's the Change 
Sequence Number..

Yiannis Mavroukakis wrote:
> Or maybe there is!..Almost a result, I am doing this now,
>
>  List<Modification> modItems = ServerEntryUtils.toServerModification(
>                                ldifEntry.getModificationItemsArray( ) ,
>                                directoryService.getRegistries( 
> ).getAttributeTypeRegistry( ) );
>                       modOp.modify( ldifEntry.getDn( ) , modItems 
> ,clusterBypass );
>
> Modification: replace
> , attribute :     entryCSN: '0x32 0x30 0x30 0x39 0x30 0x33 0x31 0x31 
> 0x31 0x37 0x33 0x31 0x33 0x31 0x2E 0x30 ...'
>
> It now blows up with the following exception,
>
> javax.naming.NoPermissionException: Cannot modify the attribute 
> 'entryCSN']
>
> Why is it not possible to modify this? Is this a per-server unique 
> value? And if so I assume it won't hurt if I don't include it in the 
> Modification List in ldifEntry?
>
> Thanks guys,
>
> Yiannis.
>
> Yiannis Mavroukakis wrote:
>> Ouch I just realised this won't really ever 
>> work..ModifyOperationContext requires a ServerModification item for 
>> it to work, which in turns requires ServerAttribute to be constructed 
>> and I can't get any of them out of an Ldif object in the context of a 
>> Modify operation...double damn!
>>
>> Y.
>>
>> Yiannis Mavroukakis wrote:
>>>
>>>
>>> Emmanuel Lecharny wrote:
>>>> Yiannis Mavroukakis wrote:
>>>>>
>>>>> Hello everyone :-)
>>>>>
>>>>> I've got a problem trying to use LdifEntry with 
>>>>> ModifyOperationContext. If you remember from
>>>>> previous emails, I'm using LdifEntry because it can be serialized. 
>>>>> I'm stuffing my Modification
>>>>> objects in the LdifEntry object like so
>>>>>
>>>>>        for( AttributeType attributeType : list )
>>>>>        {
>>>>>            EntryAttribute entryAttribute = ( (ServerAttribute) entry
>>>>>                    .get( attributeType ) ).toClientAttribute( );
>>>>>            ldiff.addAttribute( entryAttribute );
>>>>>            if( changeType.equals( ChangeType.Modify ) )
>>>>>            {
>>>>>                ClientModification mod = new ClientModification(
>>>>>                        ModificationOperation.REPLACE_ATTRIBUTE ,
>>>>>                        entryAttribute );
>>>>>                ldiff.addModificationItem( mod );
>>>>>            }
>>>>>        }
>>>>>
>>>>> This serializes fine, however ModifyOperationContext.modify() 
>>>>> gives me a
>>>>>
>>>>> java.lang.ClassCastException: 
>>>>> org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute 
>>>>> cannot be cast to 
>>>>> org.apache.directory.server.core.entry.ServerAttribute
>>>>>
>>>>> when I pass the LdifEntry object modification list to it because 
>>>>> it expects ServerAttributes and not ClientAttributes and as far as 
>>>>> I can remember, ServerAttributes are not serializable (?). Is 
>>>>> there any way I can get around this requirement?
>>>> Just store the initial entry.getAttribute() into the modification :
>>>>
>>>>       for( AttributeType attributeType : list )
>>>>       {
>>>>           EntryAttribute entryAttribute = ( (ServerAttribute) entry
>>>>                   .get( attributeType ) ).toClientAttribute( );
>>>>           ldiff.addAttribute( entryAttribute );
>>>>           if( changeType.equals( ChangeType.Modify ) )
>>>>           {
>>>>               ClientModification mod = new ClientModification(
>>>>                       ModificationOperation.REPLACE_ATTRIBUTE ,
>>>>                       entry.get( attributeType ) 
>>>> );                  <----------------------
>>>>               ldiff.addModificationItem( mod );
>>>>           }
>>>>       }
>>>>
>>>> It should work.
>>>>
>>>>
>>> Whoops :-)
>>>
>>> 81d:36
>>> java.lang.IllegalStateException: Cannot use standard serialization 
>>> for a ServerAttribute
>>>        at 
>>> org.apache.directory.server.core.entry.DefaultServerAttribute.writeExternal(DefaultServerAttribute.java:1190) 
>>>
>>>        at 
>>> java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1421) 
>>>
>>>

Re: [ApacheDS] Trunk build fail

Posted by Yiannis Mavroukakis <im...@gameaccount.com>.
Thanks Chris :-)

Chris Custine wrote:
> Sorry about that!  I will be fixing this shortly.
>
> Chris
>
> --
> Chris Custine
> FUSESource :: http://fusesource.com
> My Blog :: http://blog.organicelement.com
> Apache ServiceMix :: http://servicemix.apache.org
> Apache Directory Server :: http://directory.apache.org
>
>
> On Thu, Mar 19, 2009 at 6:04 AM, Yiannis Mavroukakis <
> imavroukakis@gameaccount.com> wrote:
>
>   
>> Hello :-)
>>
>> Trying to build the latest trunk, I'm getting this
>>
>> Downloading:
>> http://repository.apache.org/snapshots/org/springframework/osgi/spring-osgi-extender/1.2.0-rc1-SNAPSHOT/spring-osgi-extender-1.2.0-rc1-SNAPSHOT.pom
>> Downloading:
>> http://repository.apache.org/snapshots/org/springframework/osgi/spring-osgi-core/1.2.0-rc1-SNAPSHOT/spring-osgi-core-1.2.0-rc1-SNAPSHOT.pom
>> Downloading:
>> http://repository.apache.org/snapshots/org/springframework/osgi/spring-osgi-extender/1.2.0-rc1-SNAPSHOT/spring-osgi-extender-1.2.0-rc1-SNAPSHOT.jar
>> Downloading:
>> http://repository.apache.org/snapshots/org/springframework/osgi/spring-osgi-core/1.2.0-rc1-SNAPSHOT/spring-osgi-core-1.2.0-rc1-SNAPSHOT.jar
>> [INFO]
>> ------------------------------------------------------------------------
>> [ERROR] BUILD ERROR
>> [INFO]
>> ------------------------------------------------------------------------
>> [INFO] Failed to resolve artifact.
>>
>>
>> Browsing the repository, springframework doesn't seem to be there..
>>
>> Thanks,
>>
>> Yiannis.
>>
>>     
>
>   

Re: [ApacheDS] Trunk build fail

Posted by Chris Custine <ch...@gmail.com>.
Sorry about that!  I will be fixing this shortly.

Chris

--
Chris Custine
FUSESource :: http://fusesource.com
My Blog :: http://blog.organicelement.com
Apache ServiceMix :: http://servicemix.apache.org
Apache Directory Server :: http://directory.apache.org


On Thu, Mar 19, 2009 at 6:04 AM, Yiannis Mavroukakis <
imavroukakis@gameaccount.com> wrote:

> Hello :-)
>
> Trying to build the latest trunk, I'm getting this
>
> Downloading:
> http://repository.apache.org/snapshots/org/springframework/osgi/spring-osgi-extender/1.2.0-rc1-SNAPSHOT/spring-osgi-extender-1.2.0-rc1-SNAPSHOT.pom
> Downloading:
> http://repository.apache.org/snapshots/org/springframework/osgi/spring-osgi-core/1.2.0-rc1-SNAPSHOT/spring-osgi-core-1.2.0-rc1-SNAPSHOT.pom
> Downloading:
> http://repository.apache.org/snapshots/org/springframework/osgi/spring-osgi-extender/1.2.0-rc1-SNAPSHOT/spring-osgi-extender-1.2.0-rc1-SNAPSHOT.jar
> Downloading:
> http://repository.apache.org/snapshots/org/springframework/osgi/spring-osgi-core/1.2.0-rc1-SNAPSHOT/spring-osgi-core-1.2.0-rc1-SNAPSHOT.jar
> [INFO]
> ------------------------------------------------------------------------
> [ERROR] BUILD ERROR
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Failed to resolve artifact.
>
>
> Browsing the repository, springframework doesn't seem to be there..
>
> Thanks,
>
> Yiannis.
>

[ApacheDS] Trunk build fail

Posted by Yiannis Mavroukakis <im...@gameaccount.com>.
Hello :-)

Trying to build the latest trunk, I'm getting this

Downloading: 
http://repository.apache.org/snapshots/org/springframework/osgi/spring-osgi-extender/1.2.0-rc1-SNAPSHOT/spring-osgi-extender-1.2.0-rc1-SNAPSHOT.pom
Downloading: 
http://repository.apache.org/snapshots/org/springframework/osgi/spring-osgi-core/1.2.0-rc1-SNAPSHOT/spring-osgi-core-1.2.0-rc1-SNAPSHOT.pom
Downloading: 
http://repository.apache.org/snapshots/org/springframework/osgi/spring-osgi-extender/1.2.0-rc1-SNAPSHOT/spring-osgi-extender-1.2.0-rc1-SNAPSHOT.jar
Downloading: 
http://repository.apache.org/snapshots/org/springframework/osgi/spring-osgi-core/1.2.0-rc1-SNAPSHOT/spring-osgi-core-1.2.0-rc1-SNAPSHOT.jar
[INFO] 
------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] 
------------------------------------------------------------------------
[INFO] Failed to resolve artifact.


Browsing the repository, springframework doesn't seem to be there..

Thanks,

Yiannis.

Re: [ApacheDS] Using LdifEntry with a ModifyOperationContext

Posted by Emmanuel Lecharny <el...@apache.org>.
Yiannis Mavroukakis wrote:
> Or maybe there is!..Almost a result, I am doing this now,
>
>  List<Modification> modItems = ServerEntryUtils.toServerModification(
>                                ldifEntry.getModificationItemsArray( ) ,
>                                directoryService.getRegistries( 
> ).getAttributeTypeRegistry( ) );
>                       modOp.modify( ldifEntry.getDn( ) , modItems 
> ,clusterBypass );
>
> Modification: replace
> , attribute :     entryCSN: '0x32 0x30 0x30 0x39 0x30 0x33 0x31 0x31 
> 0x31 0x37 0x33 0x31 0x33 0x31 0x2E 0x30 ...'
>
> It now blows up with the following exception,
>
> javax.naming.NoPermissionException: Cannot modify the attribute 
> 'entryCSN']
>
> Why is it not possible to modify this? Is this a per-server unique 
> value? And if so I assume it won't hurt if I don't include it in the 
> Modification List in ldifEntry?
It's an operational Attribute. Only the server can modify it.

-- 
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org



Re: [ApacheDS] Using LdifEntry with a ModifyOperationContext

Posted by Yiannis Mavroukakis <im...@gameaccount.com>.
Or maybe there is!..Almost a result, I am doing this now,

  List<Modification> modItems = ServerEntryUtils.toServerModification(
                                ldifEntry.getModificationItemsArray( ) ,
                                directoryService.getRegistries( 
).getAttributeTypeRegistry( ) );
                       
modOp.modify( ldifEntry.getDn( ) , modItems ,clusterBypass );
 
Modification: replace
, attribute :     entryCSN: '0x32 0x30 0x30 0x39 0x30 0x33 0x31 0x31 
0x31 0x37 0x33 0x31 0x33 0x31 0x2E 0x30 ...'

It now blows up with the following exception,

javax.naming.NoPermissionException: Cannot modify the attribute 'entryCSN']

Why is it not possible to modify this? Is this a per-server unique 
value? And if so I assume it won't hurt if I don't include it in the 
Modification List in ldifEntry?

Thanks guys,

Yiannis.

Yiannis Mavroukakis wrote:
> Ouch I just realised this won't really ever 
> work..ModifyOperationContext requires a ServerModification item for it 
> to work, which in turns requires ServerAttribute to be constructed and 
> I can't get any of them out of an Ldif object in the context of a 
> Modify operation...double damn!
>
> Y.
>
> Yiannis Mavroukakis wrote:
>>
>>
>> Emmanuel Lecharny wrote:
>>> Yiannis Mavroukakis wrote:
>>>>
>>>> Hello everyone :-)
>>>>
>>>> I've got a problem trying to use LdifEntry with 
>>>> ModifyOperationContext. If you remember from
>>>> previous emails, I'm using LdifEntry because it can be serialized. 
>>>> I'm stuffing my Modification
>>>> objects in the LdifEntry object like so
>>>>
>>>>        for( AttributeType attributeType : list )
>>>>        {
>>>>            EntryAttribute entryAttribute = ( (ServerAttribute) entry
>>>>                    .get( attributeType ) ).toClientAttribute( );
>>>>            ldiff.addAttribute( entryAttribute );
>>>>            if( changeType.equals( ChangeType.Modify ) )
>>>>            {
>>>>                ClientModification mod = new ClientModification(
>>>>                        ModificationOperation.REPLACE_ATTRIBUTE ,
>>>>                        entryAttribute );
>>>>                ldiff.addModificationItem( mod );
>>>>            }
>>>>        }
>>>>
>>>> This serializes fine, however ModifyOperationContext.modify() gives 
>>>> me a
>>>>
>>>> java.lang.ClassCastException: 
>>>> org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute 
>>>> cannot be cast to 
>>>> org.apache.directory.server.core.entry.ServerAttribute
>>>>
>>>> when I pass the LdifEntry object modification list to it because it 
>>>> expects ServerAttributes and not ClientAttributes and as far as I 
>>>> can remember, ServerAttributes are not serializable (?). Is there 
>>>> any way I can get around this requirement?
>>> Just store the initial entry.getAttribute() into the modification :
>>>
>>>       for( AttributeType attributeType : list )
>>>       {
>>>           EntryAttribute entryAttribute = ( (ServerAttribute) entry
>>>                   .get( attributeType ) ).toClientAttribute( );
>>>           ldiff.addAttribute( entryAttribute );
>>>           if( changeType.equals( ChangeType.Modify ) )
>>>           {
>>>               ClientModification mod = new ClientModification(
>>>                       ModificationOperation.REPLACE_ATTRIBUTE ,
>>>                       entry.get( attributeType ) );                  
>>> <----------------------
>>>               ldiff.addModificationItem( mod );
>>>           }
>>>       }
>>>
>>> It should work.
>>>
>>>
>> Whoops :-)
>>
>> 81d:36
>> java.lang.IllegalStateException: Cannot use standard serialization 
>> for a ServerAttribute
>>        at 
>> org.apache.directory.server.core.entry.DefaultServerAttribute.writeExternal(DefaultServerAttribute.java:1190) 
>>
>>        at 
>> java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1421) 
>>
>>

Re: [ApacheDS] Using LdifEntry with a ModifyOperationContext

Posted by Yiannis Mavroukakis <im...@gameaccount.com>.
Ouch I just realised this won't really ever work..ModifyOperationContext 
requires a ServerModification item for it to work, which in turns 
requires ServerAttribute to be constructed and I can't get any of them 
out of an Ldif object in the context of a Modify operation...double damn!

Y.

Yiannis Mavroukakis wrote:
>
>
> Emmanuel Lecharny wrote:
>> Yiannis Mavroukakis wrote:
>>>
>>> Hello everyone :-)
>>>
>>> I've got a problem trying to use LdifEntry with 
>>> ModifyOperationContext. If you remember from
>>> previous emails, I'm using LdifEntry because it can be serialized. 
>>> I'm stuffing my Modification
>>> objects in the LdifEntry object like so
>>>
>>>        for( AttributeType attributeType : list )
>>>        {
>>>            EntryAttribute entryAttribute = ( (ServerAttribute) entry
>>>                    .get( attributeType ) ).toClientAttribute( );
>>>            ldiff.addAttribute( entryAttribute );
>>>            if( changeType.equals( ChangeType.Modify ) )
>>>            {
>>>                ClientModification mod = new ClientModification(
>>>                        ModificationOperation.REPLACE_ATTRIBUTE ,
>>>                        entryAttribute );
>>>                ldiff.addModificationItem( mod );
>>>            }
>>>        }
>>>
>>> This serializes fine, however ModifyOperationContext.modify() gives 
>>> me a
>>>
>>> java.lang.ClassCastException: 
>>> org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute 
>>> cannot be cast to 
>>> org.apache.directory.server.core.entry.ServerAttribute
>>>
>>> when I pass the LdifEntry object modification list to it because it 
>>> expects ServerAttributes and not ClientAttributes and as far as I 
>>> can remember, ServerAttributes are not serializable (?). Is there 
>>> any way I can get around this requirement?
>> Just store the initial entry.getAttribute() into the modification :
>>
>>       for( AttributeType attributeType : list )
>>       {
>>           EntryAttribute entryAttribute = ( (ServerAttribute) entry
>>                   .get( attributeType ) ).toClientAttribute( );
>>           ldiff.addAttribute( entryAttribute );
>>           if( changeType.equals( ChangeType.Modify ) )
>>           {
>>               ClientModification mod = new ClientModification(
>>                       ModificationOperation.REPLACE_ATTRIBUTE ,
>>                       entry.get( attributeType ) );                  
>> <----------------------
>>               ldiff.addModificationItem( mod );
>>           }
>>       }
>>
>> It should work.
>>
>>
> Whoops :-)
>
> 81d:36
> java.lang.IllegalStateException: Cannot use standard serialization for 
> a ServerAttribute
>        at 
> org.apache.directory.server.core.entry.DefaultServerAttribute.writeExternal(DefaultServerAttribute.java:1190) 
>
>        at 
> java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1421) 
>
>

Re: [ApacheDS] Using LdifEntry with a ModifyOperationContext

Posted by Yiannis Mavroukakis <im...@gameaccount.com>.

Emmanuel Lecharny wrote:
> Yiannis Mavroukakis wrote:
>>
>> Hello everyone :-)
>>
>> I've got a problem trying to use LdifEntry with 
>> ModifyOperationContext. If you remember from
>> previous emails, I'm using LdifEntry because it can be serialized. 
>> I'm stuffing my Modification
>> objects in the LdifEntry object like so
>>
>>        for( AttributeType attributeType : list )
>>        {
>>            EntryAttribute entryAttribute = ( (ServerAttribute) entry
>>                    .get( attributeType ) ).toClientAttribute( );
>>            ldiff.addAttribute( entryAttribute );
>>            if( changeType.equals( ChangeType.Modify ) )
>>            {
>>                ClientModification mod = new ClientModification(
>>                        ModificationOperation.REPLACE_ATTRIBUTE ,
>>                        entryAttribute );
>>                ldiff.addModificationItem( mod );
>>            }
>>        }
>>
>> This serializes fine, however ModifyOperationContext.modify() gives me a
>>
>> java.lang.ClassCastException: 
>> org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute 
>> cannot be cast to org.apache.directory.server.core.entry.ServerAttribute
>>
>> when I pass the LdifEntry object modification list to it because it 
>> expects ServerAttributes and not ClientAttributes and as far as I can 
>> remember, ServerAttributes are not serializable (?). Is there any way 
>> I can get around this requirement?
> Just store the initial entry.getAttribute() into the modification :
>
>       for( AttributeType attributeType : list )
>       {
>           EntryAttribute entryAttribute = ( (ServerAttribute) entry
>                   .get( attributeType ) ).toClientAttribute( );
>           ldiff.addAttribute( entryAttribute );
>           if( changeType.equals( ChangeType.Modify ) )
>           {
>               ClientModification mod = new ClientModification(
>                       ModificationOperation.REPLACE_ATTRIBUTE ,
>                       entry.get( attributeType ) );                  
> <----------------------
>               ldiff.addModificationItem( mod );
>           }
>       }
>
> It should work.
>
>
Whoops :-)

81d:36
java.lang.IllegalStateException: Cannot use standard serialization for a 
ServerAttribute
        at 
org.apache.directory.server.core.entry.DefaultServerAttribute.writeExternal(DefaultServerAttribute.java:1190)
        at 
java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1421)


Re: [ApacheDS] Using LdifEntry with a ModifyOperationContext

Posted by Emmanuel Lecharny <el...@apache.org>.
Yiannis Mavroukakis wrote:
>
> Hello everyone :-)
>
> I've got a problem trying to use LdifEntry with 
> ModifyOperationContext. If you remember from
> previous emails, I'm using LdifEntry because it can be serialized. I'm 
> stuffing my Modification
> objects in the LdifEntry object like so
>
>        for( AttributeType attributeType : list )
>        {
>            EntryAttribute entryAttribute = ( (ServerAttribute) entry
>                    .get( attributeType ) ).toClientAttribute( );
>            ldiff.addAttribute( entryAttribute );
>            if( changeType.equals( ChangeType.Modify ) )
>            {
>                ClientModification mod = new ClientModification(
>                        ModificationOperation.REPLACE_ATTRIBUTE ,
>                        entryAttribute );
>                ldiff.addModificationItem( mod );
>            }
>        }
>
> This serializes fine, however ModifyOperationContext.modify() gives me a
>
> java.lang.ClassCastException: 
> org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute 
> cannot be cast to org.apache.directory.server.core.entry.ServerAttribute
>
> when I pass the LdifEntry object modification list to it because it 
> expects ServerAttributes and not ClientAttributes and as far as I can 
> remember, ServerAttributes are not serializable (?). Is there any way 
> I can get around this requirement?
Just store the initial entry.getAttribute() into the modification :

       for( AttributeType attributeType : list )
       {
           EntryAttribute entryAttribute = ( (ServerAttribute) entry
                   .get( attributeType ) ).toClientAttribute( );
           ldiff.addAttribute( entryAttribute );
           if( changeType.equals( ChangeType.Modify ) )
           {
               ClientModification mod = new ClientModification(
                       ModificationOperation.REPLACE_ATTRIBUTE ,
                       entry.get( attributeType ) );                  
<----------------------
               ldiff.addModificationItem( mod );
           }
       }

It should work.


-- 
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org