use of org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl 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.core.nodetype.NodeTypeManagerImpl in project jackrabbit by apache.
the class NodeImpl method getApplicableChildNodeDefinition.
/**
* Returns the applicable child node definition for a child node with the
* specified name and node type.
*
* @param nodeName
* @param nodeTypeName
* @return
* @throws ConstraintViolationException if no applicable child node definition
* could be found
* @throws RepositoryException if another error occurs
*/
protected NodeDefinitionImpl getApplicableChildNodeDefinition(Name nodeName, Name nodeTypeName) throws ConstraintViolationException, RepositoryException {
NodeTypeManagerImpl ntMgr = sessionContext.getNodeTypeManager();
QNodeDefinition cnd = getEffectiveNodeType().getApplicableChildNodeDef(nodeName, nodeTypeName, sessionContext.getNodeTypeRegistry());
return ntMgr.getNodeDefinition(cnd);
}
use of org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl in project jackrabbit by apache.
the class LostFromCacheIssueTest method setUp.
public void setUp() throws Exception {
super.setUp();
Workspace workspace = superuser.getWorkspace();
NamespaceRegistry namespaceRegistry = workspace.getNamespaceRegistry();
NodeTypeManager ntmgr = workspace.getNodeTypeManager();
NodeTypeRegistry nodetypeRegistry = ((NodeTypeManagerImpl) ntmgr).getNodeTypeRegistry();
try {
namespaceRegistry.registerNamespace(NAMESPACE_PREFIX, NAMESPACE_URI);
} catch (NamespaceException ignore) {
//already exists
}
QNodeTypeDefinition nodeTypeDefinition = new QNodeTypeDefinitionImpl(((SessionImpl) superuser).getQName(NODETYPE_1), Name.EMPTY_ARRAY, Name.EMPTY_ARRAY, true, false, true, false, null, QPropertyDefinition.EMPTY_ARRAY, QNodeDefinition.EMPTY_ARRAY);
try {
nodetypeRegistry.registerNodeType(nodeTypeDefinition);
} catch (InvalidNodeTypeDefException ignore) {
//already exists
}
nodeTypeDefinition = new QNodeTypeDefinitionImpl(((SessionImpl) superuser).getQName(NODETYPE_2), Name.EMPTY_ARRAY, Name.EMPTY_ARRAY, true, false, true, false, null, QPropertyDefinition.EMPTY_ARRAY, QNodeDefinition.EMPTY_ARRAY);
try {
nodetypeRegistry.registerNodeType(nodeTypeDefinition);
} catch (InvalidNodeTypeDefException ignore) {
//already exists
}
getOrCreate(superuser.getRootNode(), TESTNODE_PATH);
superuser.save();
}
use of org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl in project jackrabbit by apache.
the class ObservationManagerImpl method createEventFilter.
/**
* Creates a new event filter with the given restrictions.
*
* @param eventTypes A combination of one or more event type constants encoded as a bitmask.
* @param absPaths absolute paths.
* @param isDeep a <code>boolean</code>.
* @param uuid array of UUIDs.
* @param nodeTypeName array of node type names.
* @param noLocal a <code>boolean</code>.
* @param noExternal a <code>boolean</code>.
* @param noInternal a <code>boolean</code>.
* @return the event filter with the given restrictions.
* @throws RepositoryException if an error occurs.
*/
public EventFilter createEventFilter(int eventTypes, List<String> absPaths, boolean isDeep, String[] uuid, String[] nodeTypeName, boolean noLocal, boolean noExternal, boolean noInternal) throws RepositoryException {
// create NodeType instances from names
NodeTypeImpl[] nodeTypes;
if (nodeTypeName == null) {
nodeTypes = null;
} else {
NodeTypeManagerImpl ntMgr = session.getNodeTypeManager();
nodeTypes = new NodeTypeImpl[nodeTypeName.length];
for (int i = 0; i < nodeTypes.length; i++) {
nodeTypes[i] = (NodeTypeImpl) ntMgr.getNodeType(nodeTypeName[i]);
}
}
List<Path> paths = new ArrayList<Path>();
for (String absPath : absPaths) {
try {
Path normalizedPath = session.getQPath(absPath).getNormalizedPath();
if (!normalizedPath.isAbsolute()) {
throw new RepositoryException("absPath must be absolute");
}
paths.add(normalizedPath);
} catch (NameException e) {
String msg = "invalid path syntax: " + absPath;
log.debug(msg);
throw new RepositoryException(msg, e);
}
}
NodeId[] ids = null;
if (uuid != null) {
ids = new NodeId[uuid.length];
for (int i = 0; i < uuid.length; i++) {
ids[i] = NodeId.valueOf(uuid[i]);
}
}
// create filter
return new EventFilter(session, eventTypes, paths, isDeep, ids, nodeTypes, noLocal, noExternal, noInternal);
}
Aggregations