stateMgr.store(newChildState);
// add new child node entry to new node
newState.addChildNodeEntry(entry.getName(), newChildState.getNodeId());
}
// init version history if needed
VersionHistoryInfo history = null;
if (versionable && flag == COPY) {
NodeId copiedFrom = null;
if (fullVersionable) {
// base version of copied versionable node is reference value of
// the histories jcr:copiedFrom property
PropertyId propId = new PropertyId(srcState.getNodeId(), NameConstants.JCR_BASEVERSION);
PropertyState prop = (PropertyState) srcStateMgr.getItemState(propId);
copiedFrom = prop.getValues()[0].getNodeId();
}
InternalVersionManager manager = session.getInternalVersionManager();
history = manager.getVersionHistory(session, newState, copiedFrom);
}
// copy properties
for (Name propName : srcState.getPropertyNames()) {
Path propPath = PathFactoryImpl.getInstance().create(srcPath, propName, true);
if (!srcAccessMgr.canRead(propPath)) {
continue;
}
PropertyId propId = new PropertyId(srcState.getNodeId(), propName);
PropertyState srcChildState =
(PropertyState) srcStateMgr.getItemState(propId);
/**
* special handling required for properties with special semantics
* (e.g. those defined by mix:referenceable, mix:versionable,
* mix:lockable, et.al.)
*
* todo FIXME delegate to 'node type instance handler'
*/
QPropertyDefinition def = ent.getApplicablePropertyDef(
srcChildState.getName(), srcChildState.getType(),
srcChildState.isMultiValued());
if (NameConstants.MIX_LOCKABLE.equals(def.getDeclaringNodeType())) {
// skip properties defined by mix:lockable
continue;
}
PropertyState newChildState =
copyPropertyState(srcChildState, id, propName, def);
if (history != null) {
if (fullVersionable) {
if (propName.equals(NameConstants.JCR_VERSIONHISTORY)) {
// jcr:versionHistory
InternalValue value = InternalValue.create(
history.getVersionHistoryId());
newChildState.setValues(new InternalValue[] { value });
} else if (propName.equals(NameConstants.JCR_BASEVERSION)
|| propName.equals(NameConstants.JCR_PREDECESSORS)) {
// jcr:baseVersion or jcr:predecessors
InternalValue value = InternalValue.create(
history.getRootVersionId());
newChildState.setValues(new InternalValue[] { value });
} else if (propName.equals(NameConstants.JCR_ISCHECKEDOUT)) {
// jcr:isCheckedOut
newChildState.setValues(new InternalValue[]{InternalValue.create(true)});
}