On Jan 10, 2010, at 4:23 PM, Sergiu Dumitriu wrote:
On 01/10/2010 03:12 PM, Vincent Massol wrote:
On Jan 9, 2010, at 1:25 PM, Pascal Voitot wrote:
does it mean all scripts using the older
functions will need to be updated?
There's only one gotcha right now with what I have on my machine (not committed) and
I'm still hesitating. Internally I've modified the field containing the objects
from
private Map<String, Vector<BaseObject>> objects
to
private Map<DocumentReference, List<BaseObject>> objects
This means that the old (deprecated APIs) have to wrap the internal map. For example when
XWikiDocument.getxWikiObjects() is called it returns a new Map, copying the internal map
to a map of type Map<String, Vector<BaseObject>>. The problem is that if you
have code like the following it'll now fail:
getxWikiObjects().put(something)
Then calling getxWikiObjects() again will not contain the "something" object.
IMO it's a bad usage of the API. Instead if you wish to add something you should call
addObject (now addXObject) for example. However it was allowed and will break old code
which would need to be modified to work.
WDYT? I don't see any solution to preserve the old behavior and at the same time move
to Map<DocumentReference, List<BaseObject>> objects
I think it's safe to make this change, since the behavior was not
documented, and at least in the official code it wasn't used.
Actually it's used in a lot of places in the old code... I've fixed the ones
I've found and I keep finding new ones. The latest example:
public XWikiDocument copyDocument(String newDocumentName, XWikiContext context)
throws XWikiException
{
loadAttachments(context);
loadArchive(context);
XWikiDocument newdoc = (XWikiDocument) clone();
newdoc.setOriginalDocument(null);
newdoc.setFullName(newDocumentName, context);
newdoc.setContentDirty(true);
newdoc.getxWikiClass().setName(newDocumentName);
Map<String, Vector<BaseObject>> objectclasses =
newdoc.getxWikiObjects();
if (objectclasses != null) {
for (Vector<BaseObject> objects : objectclasses.values()) {
if (objects != null) {
for (BaseObject object : objects) {
if (object != null) {
object.setName(newDocumentName);
// Since GUIDs are supposed to be Unique, although this
object holds the same data, it is
// not
// exactly the same object, so it should have a different
identifier.
object.setGuid(UUID.randomUUID().toString());
}
}
}
}
}
XWikiDocumentArchive archive = newdoc.getDocumentArchive();
if (archive != null) {
newdoc.setDocumentArchive(archive.clone(newdoc.getId(), context));
}
return newdoc;
}
As you can see object.setName() and object.setGuid() are used.
Hm, that's a different problem. This is not changing the map, but
changing the elements inside the map. Which means that although the
result of getXObjects would be an unmodifiable map, the entries inside
it would be the real, read-write objects.
--
Sergiu Dumitriu