use of org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl in project jackrabbit by apache.
the class NodeImpl method createChildNode.
protected synchronized NodeImpl createChildNode(Name name, NodeTypeImpl nodeType, NodeId id) throws RepositoryException {
// create a new node state
NodeState nodeState = stateMgr.createTransientNodeState(id, nodeType.getQName(), getNodeId(), ItemState.STATUS_NEW);
// create Node instance wrapping new node state
NodeImpl node;
try {
// NOTE: since the node is not yet connected to its parent, avoid
// calling ItemManager#getItem(ItemId) which may include a permission
// check (with subsequent usage of the hierarachy-mgr -> error).
// just let the mgr create the new node that is known to exist and
// which has not been accessed before.
node = (NodeImpl) itemMgr.createItemInstance(nodeState);
} catch (RepositoryException re) {
// something went wrong
stateMgr.disposeTransientItemState(nodeState);
// re-throw
throw re;
}
// modify the state of 'this', i.e. the parent node
NodeState thisState = (NodeState) getOrCreateTransientItemState();
// add new child node entry
thisState.addChildNodeEntry(name, nodeState.getNodeId());
// add 'auto-create' properties defined in node type
for (PropertyDefinition aPda : nodeType.getAutoCreatedPropertyDefinitions()) {
PropertyDefinitionImpl pd = (PropertyDefinitionImpl) aPda;
node.createChildProperty(pd.unwrap().getName(), pd.getRequiredType(), pd);
}
// recursively add 'auto-create' child nodes defined in node type
for (NodeDefinition aNda : nodeType.getAutoCreatedNodeDefinitions()) {
NodeDefinitionImpl nd = (NodeDefinitionImpl) aNda;
node.createChildNode(nd.unwrap().getName(), (NodeTypeImpl) nd.getDefaultPrimaryType(), null);
}
return node;
}
use of org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl in project jackrabbit by apache.
the class NodeImpl method getOrCreateProperty.
/**
* @param name
* @param type
* @param multiValued
* @param exactTypeMatch
* @param status
* @return
* @throws ConstraintViolationException if no applicable property definition
* could be found
* @throws RepositoryException if another error occurs
*/
protected synchronized PropertyImpl getOrCreateProperty(Name name, int type, boolean multiValued, boolean exactTypeMatch, BitSet status) throws ConstraintViolationException, RepositoryException {
status.clear();
if (isNew() && !hasProperty(name)) {
// this is a new node and the property does not exist yet
// -> no need to check item manager
PropertyDefinitionImpl def = getApplicablePropertyDefinition(name, type, multiValued, exactTypeMatch);
PropertyImpl prop = createChildProperty(name, type, def);
status.set(CREATED);
return prop;
}
/*
* Please note, that this implementation does not win a price for beauty
* or speed. It's never a good idea to use exceptions for semantical
* control flow.
* However, compared to the previous version, this one is thread save
* and makes the test/get block atomic in respect to transactional
* commits. the test/set can still fail.
*
* Old Version:
NodeState thisState = (NodeState) state;
if (thisState.hasPropertyName(name)) {
/**
* the following call will throw ItemNotFoundException if the
* current session doesn't have read access
/
return getProperty(name);
}
[...create block...]
*/
PropertyId propId = new PropertyId(getNodeId(), name);
try {
return (PropertyImpl) itemMgr.getItem(propId);
} catch (AccessDeniedException ade) {
throw new ItemNotFoundException(name.toString());
} catch (ItemNotFoundException e) {
// does not exist yet or has been removed transiently:
// find definition for the specified property and (re-)create property
PropertyDefinitionImpl def = getApplicablePropertyDefinition(name, type, multiValued, exactTypeMatch);
PropertyImpl prop;
if (stateMgr.hasTransientItemStateInAttic(propId)) {
// remove from attic
try {
stateMgr.disposeTransientItemStateInAttic(stateMgr.getAttic().getItemState(propId));
} catch (ItemStateException ise) {
// shouldn't happen because we checked if it is in the attic
throw new RepositoryException(ise);
}
prop = (PropertyImpl) itemMgr.getItem(propId);
PropertyState state = (PropertyState) prop.getOrCreateTransientItemState();
state.setMultiValued(multiValued);
state.setType(type);
getNodeState().addPropertyName(name);
} else {
prop = createChildProperty(name, type, def);
}
status.set(CREATED);
return prop;
}
}
use of org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl in project jackrabbit by apache.
the class AddMixinOperation method perform.
public Object perform(SessionContext context) throws RepositoryException {
int permissions = Permission.NODE_TYPE_MNGMT;
// is required in addition.
if (MIX_VERSIONABLE.equals(mixinName) || MIX_SIMPLE_VERSIONABLE.equals(mixinName)) {
permissions |= Permission.VERSION_MNGMT;
}
context.getItemValidator().checkModify(node, CHECK_LOCK | CHECK_CHECKED_OUT | CHECK_CONSTRAINTS | CHECK_HOLD, permissions);
NodeTypeManagerImpl ntMgr = context.getNodeTypeManager();
NodeTypeImpl mixin = ntMgr.getNodeType(mixinName);
if (!mixin.isMixin()) {
throw new RepositoryException(context.getJCRName(mixinName) + " is not a mixin node type");
}
Name primaryTypeName = node.getNodeState().getNodeTypeName();
NodeTypeImpl primaryType = ntMgr.getNodeType(primaryTypeName);
if (primaryType.isDerivedFrom(mixinName)) {
// new mixin is already included in primary type
return this;
}
// build effective node type of mixin's & primary type in order
// to detect conflicts
NodeTypeRegistry ntReg = context.getNodeTypeRegistry();
EffectiveNodeType entExisting;
try {
// existing mixin's
Set<Name> mixins = new HashSet<Name>(node.getNodeState().getMixinTypeNames());
// build effective node type representing primary type including
// existing mixin's
entExisting = ntReg.getEffectiveNodeType(primaryTypeName, mixins);
if (entExisting.includesNodeType(mixinName)) {
// new mixin is already included in existing mixin type(s)
return this;
}
// add new mixin
mixins.add(mixinName);
// try to build new effective node type (will throw in case
// of conflicts)
ntReg.getEffectiveNodeType(primaryTypeName, mixins);
} catch (NodeTypeConflictException e) {
throw new ConstraintViolationException(e.getMessage(), e);
}
// try to revert the changes in case an exception occurs
try {
// modify the state of this node
NodeState thisState = (NodeState) node.getOrCreateTransientItemState();
// add mixin name
Set<Name> mixins = new HashSet<Name>(thisState.getMixinTypeNames());
mixins.add(mixinName);
thisState.setMixinTypeNames(mixins);
// set jcr:mixinTypes property
node.setMixinTypesProperty(mixins);
// add 'auto-create' properties defined in mixin type
for (PropertyDefinition aPda : mixin.getAutoCreatedPropertyDefinitions()) {
PropertyDefinitionImpl pd = (PropertyDefinitionImpl) aPda;
// make sure that the property is not already defined
// by primary type or existing mixin's
NodeTypeImpl declaringNT = (NodeTypeImpl) pd.getDeclaringNodeType();
if (!entExisting.includesNodeType(declaringNT.getQName())) {
node.createChildProperty(pd.unwrap().getName(), pd.getRequiredType(), pd);
}
}
// recursively add 'auto-create' child nodes defined in mixin type
for (NodeDefinition aNda : mixin.getAutoCreatedNodeDefinitions()) {
NodeDefinitionImpl nd = (NodeDefinitionImpl) aNda;
// make sure that the child node is not already defined
// by primary type or existing mixin's
NodeTypeImpl declaringNT = (NodeTypeImpl) nd.getDeclaringNodeType();
if (!entExisting.includesNodeType(declaringNT.getQName())) {
node.createChildNode(nd.unwrap().getName(), (NodeTypeImpl) nd.getDefaultPrimaryType(), null);
}
}
} catch (RepositoryException re) {
// try to undo the modifications by removing the mixin
try {
node.removeMixin(mixinName);
} catch (RepositoryException re1) {
// silently ignore & fall through
}
throw re;
}
return this;
}
use of org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl in project jackrabbit by apache.
the class NodeTypeDefinitionImpl method getDeclaredPropertyDefinitions.
/**
* {@inheritDoc}
*/
public PropertyDefinition[] getDeclaredPropertyDefinitions() {
QPropertyDefinition[] pda = ntd.getPropertyDefs();
PropertyDefinition[] propDefs = new PropertyDefinition[pda.length];
for (int i = 0; i < pda.length; i++) {
propDefs[i] = new PropertyDefinitionImpl(pda[i], null, resolver, valueFactory);
}
return propDefs;
}
use of org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl in project jackrabbit by apache.
the class NodeTypeManagerImpl method getPropertyDefinition.
/**
* @param def prop def
* @return the property definition
*/
@Override
public PropertyDefinitionImpl getPropertyDefinition(QPropertyDefinition def) {
synchronized (pdCache) {
PropertyDefinitionImpl pdi = pdCache.get(def);
if (pdi == null) {
pdi = new PropertyDefinitionImpl(def, this, context, context.getValueFactory());
pdCache.put(def, pdi);
}
return pdi;
}
}
Aggregations