Am Donnerstag, 3. Mai 2007 schrieb Grégory Joseph:
> On May 3, 2007, at 15:46 , Oliver Lietz wrote:
> > Am Donnerstag, 3. Mai 2007 schrieb Grégory Joseph:
> > [...]
> >
> >> While on the subject of node types, I'd be interested to hear what
> >> you think/know about updating or changing them. That'd seem more
> >> interesting to me (I'm not sure I see the interest of namespaces
> >> other than avoiding clashes which could be avoided with prefixes
> >> too?) Say for the forum, I'm defining very precise node types, and
> >> it's very likely that these will evolve over time. Since its' just
> >> starting now, its ok <for me> to just drop my repo and start from
> >> scratch again. Any idea what can happen if one needs to change
> >> existing node types ?
> >
> > I haven't played with this features, they should be part of JCR2
> > and are not
> > (fully) implemented by Jackrabbit yet. Have a look at
> > http://jackrabbit.apache.org/api-1/org/apache/jackrabbit/core/
> > nodetype/NodeTypeDefDiff.html
> > Only TRIVIAL modifications can be handled by Jackrabbit. For now I
> > start also
> > from scratch.
>
> So that means we could still somehow handle this, getting such a diff
> object, and in the case we're in trivialdom, we can update (I'm
> guessing there's a JR specific api to do all that)
You do that with NodeTypeRegistry.html#reregisterNodeType(NodeTypeDef)
Source of that method below.
O.
/**
* @param ntd
* @return
* @throws NoSuchNodeTypeException
* @throws InvalidNodeTypeDefException
* @throws RepositoryException
*/
public synchronized EffectiveNodeType reregisterNodeType(NodeTypeDef ntd)
throws NoSuchNodeTypeException, InvalidNodeTypeDefException,
RepositoryException {
QName name = ntd.getName();
if (!registeredNTDefs.containsKey(name)) {
throw new NoSuchNodeTypeException(name.toString());
}
if (builtInNTDefs.contains(name)) {
throw new RepositoryException(name.toString()
+ ": can't reregister built-in node type.");
}
/**
* validate new node type definition
*/
validateNodeTypeDef(ntd, entCache, registeredNTDefs, nsReg, false);
/**
* build diff of current and new definition and determine type of
change
*/
NodeTypeDef ntdOld = (NodeTypeDef) registeredNTDefs.get(name);
NodeTypeDefDiff diff = NodeTypeDefDiff.create(ntdOld, ntd);
if (!diff.isModified()) {
// the definition has not been modified, there's nothing to do
here...
return getEffectiveNodeType(name);
}
if (diff.isTrivial()) {
/**
* the change is trivial and has no effect on current content
* (e.g. that would be the case when non-mandatory properties had
* been added);
* re-register node type definition and update caches &
* notify listeners on re-registration
*/
internalUnregister(name);
// remove old node type definition from store
customNTDefs.remove(name);
EffectiveNodeType entNew = internalRegister(ntd);
// add new node type definition to store
customNTDefs.add(ntd);
// persist node type definitions
persistCustomNodeTypeDefs(customNTDefs);
// notify listeners
notifyReRegistered(name);
return entNew;
}
String message = "The following nodetype change contains non-trivial
changes."
+ "Up until now only trivial changes are supported."
+ " (see javadoc for "
+ NodeTypeDefDiff.class.getName()
+ "):\n" + diff.toString();
throw new RepositoryException(message);
// TODO Implement checkForConflictingContent()
// make sure existing content would not conflict
// with new node type definition
//checkForConflictingContent(ntd);
//
// unregister old node type definition
//internalUnregister(name);
// register new definition
//EffectiveNodeType entNew = internalRegister(ntd);
//
// persist modified node type definitions
//customNTDefs.remove(name);
//customNTDefs.add(ntd);
//persistCustomNodeTypeDefs(customNTDefs);
//
// notify listeners
//notifyReRegistered(name);
//return entNew;
}
----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/developer.html
----------------------------------------------------------------