use of org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder in project jackrabbit by apache.
the class ClusterRecordTest method testNodeTypeReregistration.
/**
* Test producing and consuming a node type reregistration.
* @throws Exception
*/
public void testNodeTypeReregistration() 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.REREGISTER, list);
master.reregistered(ntd.build());
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.commons.nodetype.QNodeTypeDefinitionBuilder in project jackrabbit by apache.
the class NodeTypeReader method getNodeTypeDef.
/**
* Returns the node type definition specified by the current element.
*
* @return node type definition
* @throws InvalidNodeTypeDefException if the definition is invalid
* @throws NameException if the definition contains an
* illegal name
* @throws NamespaceException if a namespace is not defined
*/
private QNodeTypeDefinition getNodeTypeDef() throws InvalidNodeTypeDefException, NameException, NamespaceException {
QNodeTypeDefinitionBuilder type = new QNodeTypeDefinitionBuilder();
type.setName(resolver.getQName(walker.getAttribute(Constants.NAME_ATTRIBUTE)));
type.setMixin(Boolean.valueOf(walker.getAttribute(Constants.ISMIXIN_ATTRIBUTE)));
type.setOrderableChildNodes(Boolean.valueOf(walker.getAttribute(Constants.HASORDERABLECHILDNODES_ATTRIBUTE)));
type.setAbstract(Boolean.valueOf(walker.getAttribute(Constants.ISABSTRACT_ATTRIBUTE)));
if (walker.getAttribute(Constants.ISQUERYABLE_ATTRIBUTE) != null) {
type.setQueryable(Boolean.valueOf(walker.getAttribute(Constants.ISQUERYABLE_ATTRIBUTE)));
}
String primaryItemName = walker.getAttribute(Constants.PRIMARYITEMNAME_ATTRIBUTE);
if (primaryItemName != null && primaryItemName.length() > 0) {
type.setPrimaryItemName(resolver.getQName(primaryItemName));
}
// supertype declarations
if (walker.enterElement(Constants.SUPERTYPES_ELEMENT)) {
List<Name> supertypes = new ArrayList<Name>();
while (walker.iterateElements(Constants.SUPERTYPE_ELEMENT)) {
supertypes.add(resolver.getQName(walker.getContent()));
}
type.setSupertypes(supertypes.toArray(new Name[supertypes.size()]));
walker.leaveElement();
}
// property definitions
List<QPropertyDefinition> properties = new ArrayList<QPropertyDefinition>();
while (walker.iterateElements(Constants.PROPERTYDEFINITION_ELEMENT)) {
QPropertyDefinitionBuilder def = getPropDef();
def.setDeclaringNodeType(type.getName());
properties.add(def.build());
}
type.setPropertyDefs(properties.toArray(new QPropertyDefinition[properties.size()]));
// child node definitions
List<QNodeDefinition> nodes = new ArrayList<QNodeDefinition>();
while (walker.iterateElements(Constants.CHILDNODEDEFINITION_ELEMENT)) {
QNodeDefinitionBuilder def = getChildNodeDef();
def.setDeclaringNodeType(type.getName());
nodes.add(def.build());
}
type.setChildNodeDefs(nodes.toArray(new QNodeDefinition[nodes.size()]));
return type.build();
}
use of org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder 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.commons.nodetype.QNodeTypeDefinitionBuilder 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();
}
}
use of org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder in project jackrabbit by apache.
the class CyclicNodeTypeRegistrationTest method testRegisterCyclicChildNodeTypes.
/**
* Tests, if it is possible to register node types with simple
* cyclic dependencies.
*/
public void testRegisterCyclicChildNodeTypes() {
/**
* Constructs node types with the following structure:
* [foo]
* + myBarInFoo (bar)
*
* [bar]
* + myFooInBar (foo)
*/
final QNodeTypeDefinitionBuilder foo = new QNodeTypeDefinitionBuilder();
foo.setName(nameFactory.create("", "foo"));
foo.setSupertypes(new Name[] { NameConstants.NT_BASE });
final QNodeTypeDefinitionBuilder bar = new QNodeTypeDefinitionBuilder();
bar.setName(nameFactory.create("", "bar"));
bar.setSupertypes(new Name[] { NameConstants.NT_BASE });
QNodeDefinitionBuilder myBarInFoo = new QNodeDefinitionBuilder();
myBarInFoo.setRequiredPrimaryTypes(new Name[] { bar.getName() });
myBarInFoo.setName(nameFactory.create("", "myBarInFoo"));
myBarInFoo.setDeclaringNodeType(foo.getName());
QNodeDefinitionBuilder myFooInBar = new QNodeDefinitionBuilder();
myFooInBar.setRequiredPrimaryTypes(new Name[] { foo.getName() });
myFooInBar.setName(nameFactory.create("", "myFooInBar"));
myFooInBar.setDeclaringNodeType(bar.getName());
foo.setChildNodeDefs(new QNodeDefinition[] { myBarInFoo.build() });
bar.setChildNodeDefs(new QNodeDefinition[] { myFooInBar.build() });
ntDefCollection = new LinkedList<QNodeTypeDefinition>();
ntDefCollection.add(foo.build());
ntDefCollection.add(bar.build());
try {
ntreg.registerNodeTypes(ntDefCollection);
} catch (InvalidNodeTypeDefException e) {
assertFalse(e.getMessage(), true);
e.printStackTrace();
} catch (RepositoryException e) {
assertFalse(e.getMessage(), true);
e.printStackTrace();
}
boolean allNTsAreRegistered = ntreg.isRegistered(foo.getName()) && ntreg.isRegistered(bar.getName());
assertTrue(allNTsAreRegistered);
}
Aggregations