Am 10.10.14 um 16:48 schrieb Sandro Boehme:
> Am 09.10.14 06:23, schrieb Carsten Ziegeler:
>> Am 08.10.14 um 21:36 schrieb Sandro Boehme:
>>> It doesn't work as the wrapper uses the original resource metadata
>>> object.
>>> I could create a wrapper for the resource metadata as well and remove
>>> the lock check. This way I would need to dublicate all resource metadata
>>> methods in the resource metadata wrapper for the delegation. But every
>>> signature change in the evolution of the ResourceMetadata class would
>>> have to be synchronized with its wrapper. This seems to be a very tight
>>> dependency. Is this really the way to go?
>>>
>>
>> Usually you create a new metadata object for the resource wrapper. I see
>> that maybe our wrapper implementation should do this by default.
>> So I think, the right way is to create a new metadata object for the
>> wrapper and copy the metadata you want to keep from the original
>> resource.
>>
>> Carsten
>>
>
> The original resource could have a 'ResourceMetadata' or a
> 'JcrNodeResourceMetadata' object. I didn't find any other types but as a
> user of the resource API I would like to create a new metadata object
> not matter what type it is. For example if new metadata types are added
> I would not like to handle them seperately, right? The only way I know
> to do that would be to clone the metadata object like that:
>
> Resource newResource = new ResourceWrapper(originalResource) {
> @Override
> public ResourceMetadata getResourceMetadata() {
> ResourceMetadata metadata = (ResourceMetadata)
> getResource().getResourceMetadata().clone();
> return metadata;
> }
>
> };
>
>
> But in this case I would clone the status of the isReadOnly variable as
> well. If it would be 'true' because it has been returned from the
> ResourceResolver it would stay true and lead to the exception in the
> subject. To avoid that one could reset the isReadOnly to false in the
> clone method of 'ResourceMetadata' to make the method look like that:
> @Override
> public Object clone() {
> ResourceMetadata result = (ResourceMetadata) super.clone();
> result.lockedEntrySet = null;
> result.lockedKeySet = null;
> result.lockedValues = null;
> result.isReadOnly=false;
> return result;
> }
> But that be the right thing to do?
>
> Or is there an other way to create a new metadata object that I overlooked?
>
Metadata is an extension of Map/HashMap, so creating a new Map object
and doing a putAll() should do the trick
Carsten
--
Carsten Ziegeler
Adobe Research Switzerland
[email protected]