use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.
the class NodeTypeImpl method canAddChildNode.
/**
* @see javax.jcr.nodetype.NodeType#canAddChildNode(String, String)
*/
public boolean canAddChildNode(String childNodeName, String nodeTypeName) {
try {
Name ntName = resolver().getQName(nodeTypeName);
QNodeTypeDefinition def = ntMgr.getNodeTypeDefinition(ntName);
ent.checkAddNodeConstraints(resolver().getQName(childNodeName), def, definitionProvider());
return true;
} catch (NameException be) {
// implementation specific exception, fall through
} catch (RepositoryException re) {
// fall through
}
return false;
}
use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.
the class WorkspaceManager method createNodeTypeRegistry.
/**
* @param nsRegistry The namespace registry.
* @return an instance of <code>NodeTypeRegistryImpl</code>.
*/
private NodeTypeRegistryImpl createNodeTypeRegistry(NamespaceRegistry nsRegistry) {
NodeTypeStorage ntst = new NodeTypeStorage() {
public Iterator<QNodeTypeDefinition> getAllDefinitions() throws RepositoryException {
return service.getQNodeTypeDefinitions(sessionInfo);
}
public Iterator<QNodeTypeDefinition> getDefinitions(Name[] nodeTypeNames) throws NoSuchNodeTypeException, RepositoryException {
return service.getQNodeTypeDefinitions(sessionInfo, nodeTypeNames);
}
public void registerNodeTypes(QNodeTypeDefinition[] nodeTypeDefs, boolean allowUpdate) throws RepositoryException {
service.registerNodeTypes(sessionInfo, nodeTypeDefs, allowUpdate);
}
public void unregisterNodeTypes(Name[] nodeTypeNames) throws NoSuchNodeTypeException, RepositoryException {
service.unregisterNodeTypes(sessionInfo, nodeTypeNames);
}
};
NodeTypeCache ntCache = NodeTypeCache.getInstance(service, sessionInfo.getUserID());
ntst = ntCache.wrap(ntst);
return NodeTypeRegistryImpl.create(ntst, nsRegistry);
}
use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.
the class RepositoryServiceImpl method getQNodeTypeDefinitions.
/**
* {@inheritDoc}
*/
public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo, Name[] nodetypeNames) throws RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>();
for (Name nodetypeName : nodetypeNames) {
try {
String ntName = sInfo.getNamePathResolver().getJCRName(nodetypeName);
NodeType nt = ntMgr.getNodeType(ntName);
defs.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory()));
// in addition pack all supertypes into the return value
NodeType[] supertypes = nt.getSupertypes();
for (NodeType supertype : supertypes) {
defs.add(new QNodeTypeDefinitionImpl(supertype, sInfo.getNamePathResolver(), getQValueFactory()));
}
} catch (NameException e) {
throw new RepositoryException(e);
}
}
return defs.iterator();
}
use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.
the class ClusterRecordTest method testNodeTypeRegistration.
/**
* Test producing and consuming a node type registration.
* @throws Exception
*/
public void testNodeTypeRegistration() throws Exception {
QNodeTypeDefinitionBuilder ntd = new QNodeTypeDefinitionBuilder();
ntd.setName(NameFactoryImpl.getInstance().create("", "test"));
ntd.setSupertypes(new Name[] { NameConstants.NT_BASE });
ArrayList<QNodeTypeDefinition> list = new ArrayList<QNodeTypeDefinition>();
list.add(ntd.build());
NodeTypeEvent event = new NodeTypeEvent(NodeTypeEvent.REGISTER, list);
master.registered(event.getCollection());
SimpleEventListener listener = new SimpleEventListener();
slave.setListener((NodeTypeEventListener) listener);
slave.sync();
assertEquals(1, listener.getClusterEvents().size());
assertEquals(listener.getClusterEvents().get(0), event);
}
use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.
the class CyclicNodeTypeRegistrationTest method testRegisterSimpleMissingNodeTypes.
/**
* A simple check, if a missing node type is found
*/
public void testRegisterSimpleMissingNodeTypes() {
/**
* Constructs node types with the following structure:
* [foo]
* + myNTInFoo (I_am_an_invalid_required_primary_type)
*
*/
final QNodeTypeDefinitionBuilder foo = new QNodeTypeDefinitionBuilder();
foo.setName(nameFactory.create("", "foo"));
foo.setSupertypes(new Name[] { NameConstants.NT_BASE });
QNodeDefinitionBuilder myBarInFoo = new QNodeDefinitionBuilder();
myBarInFoo.setRequiredPrimaryTypes(new Name[] { nameFactory.create("", "I_am_an_invalid_required_primary_type") });
myBarInFoo.setName(nameFactory.create("", "myNTInFoo"));
myBarInFoo.setDeclaringNodeType(foo.getName());
foo.setChildNodeDefs(new QNodeDefinition[] { myBarInFoo.build() });
ntDefCollection = new LinkedList<QNodeTypeDefinition>();
ntDefCollection.add(foo.build());
try {
ntreg.registerNodeTypes(ntDefCollection);
assertFalse("Missing node type not found", true);
} catch (InvalidNodeTypeDefException e) {
assertTrue(true);
} catch (RepositoryException e) {
assertFalse("Wrong Exception thrown on missing node type.", true);
e.printStackTrace();
}
}
Aggregations