本文整理了Java中javax.jcr.Node.addMixin()
方法的一些代码示例,展示了Node.addMixin()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.addMixin()
方法的具体详情如下:
包路径:javax.jcr.Node
类名称:Node
方法名:addMixin
[英]Adds the mixin node type named mixinName
to this node. If this node is already of type mixinName
(either due to a previously added mixin or due to its primary type, through inheritance) then this method has no effect. Otherwise mixinName
is added to this node's jcr:mixinTypes
property.
Semantically, the new node type may take effect immediately, on dispatch or on persist. The behavior adopted must be the same as the behavior adopted for #setPrimaryType and the behavior that occurs when a node is first created.
A ConstraintViolationException
is thrown either immediately, on dispatch or on persist, if a conflict with another assigned mixin or the primary node type or for an implementation-specific reason. Implementations may differ on when this validation is done.
In some implementations it may only be possible to add mixin types before a a node is persisted for the first time. I such cases any later calls to addMixin
will throw a ConstraintViolationException
either immediately, on dispatch or on persist.
A NoSuchNodeTypeException
is thrown either immediately, on dispatch or on persist, if the specified mixinName
is not recognized. Implementations may differ on when this validation is done.
A VersionException
is thrown either immediately, on dispatch or on persist, if this node is read-only due to a checked-in node. Implementations may differ on when this validation is done.
A LockException
is thrown either immediately, on dispatch or on persist, if a lock prevents the addition of the mixin. Implementations may differ on when this validation is done.
[中]将名为mixinName
的mixin节点类型添加到此节点。如果此节点已经是mixinName
类型(由于先前添加的mixin或由于其主类型,通过继承),则此方法无效。否则,mixinName
将添加到此节点的jcr:mixinTypes
属性。
从语义上讲,新节点类型可能会在分派或持久化时立即生效。所采用的行为必须与#setPrimaryType所采用的行为以及首次创建节点时发生的行为相同。
如果与另一个指定的mixin或主节点类型发生冲突,或者由于特定于实现的原因,在分派或持久化时立即抛出ConstraintViolationException
。在完成此验证时,实现可能会有所不同。
在某些实现中,可能只有在第一次持久化节点之前才能添加mixin类型。我认为,在这种情况下,以后任何对addMixin
的呼叫都会立即抛出ConstraintViolationException
,无论是在发送时还是在持续时。
如果指定的mixinName
无法识别,则NoSuchNodeTypeException
会在分派或持久化时立即抛出。在完成此验证时,实现可能会有所不同。
如果此节点由于签入节点而为只读,则在分派或持久化时立即抛出VersionException
。在完成此验证时,实现可能会有所不同。
如果锁阻止添加mixin,则LockException
会在分派时或持久化时立即抛出。在完成此验证时,实现可能会有所不同。
代码示例来源:origin: ModeShape/modeshape
@Override
public void recordRow( Node outputNode,
String[] columns ) throws RepositoryException {
Node rowNode = outputNode.addNode(ROW);
for (String column : columns) {
Node columnNode = rowNode.addNode(COLUMN);
columnNode.addMixin(COLUMN);
columnNode.setProperty(DATA, column);
}
}
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-workflow
private Node createNode(String name, final String type) throws RepositoryException, WorkflowException {
Node folder = rootSession.getNodeByIdentifier(subject.getIdentifier());
name = NodeNameCodec.encode(name);
if (isSameNameSibling(name, folder)){
throw new WorkflowException(MessageFormat.format(
"A node with name {0} already exists in folder {1}. Not allowed to create same-name siblings",
name, folder.getPath()));
}
final Node handle = folder.addNode(name, NT_HANDLE);
handle.addMixin(MIX_REFERENCEABLE);
final Node document = handle.addNode(name, type);
document.setProperty(HIPPO_AVAILABILITY, new String[] { "live", "preview" });
return document;
}
代码示例来源:origin: apache/jackrabbit-oak
@Test
public void testAddMixinWithoutPermission() throws Exception {
try {
childNode.addMixin(mixinName);
testSession.save();
fail("TestSession does not have sufficient privileges to add a mixin type.");
} catch (AccessDeniedException e) {
// success
}
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
@Test
public void testIsAvailableForItemThatIsMarkedAsDeleted() throws RepositoryException {
// GIVEN
Node node = webSiteSession.getRootNode().addNode("node2", NodeTypes.Page.NAME);
node.addMixin(NodeTypes.Deleted.NAME);
// WHEN
Object itemId = JcrItemUtil.getItemId(node);
boolean isAvailable = rule.isAvailableForItem(itemId);
// THEN
assertTrue(isAvailable);
}
代码示例来源:origin: ModeShape/modeshape
@Test
public void shouldNotAllowUpdatingNodesInReadOnlyProjection() throws Exception {
Node file = session.getNode("/testRoot/readonly/dir3/simple.json");
try {
file.addMixin("flex:anyProperties");
file.setProperty("extraProp", "extraValue");
session.save();
fail("failed to throw read-only exception");
} catch (RepositoryException e) {
// expected
}
}
代码示例来源:origin: ModeShape/modeshape
@Test
public void shouldBeAbleToVersionOutsideOfUserTransaction() throws Exception {
VersionManager vm = session.getWorkspace().getVersionManager();
Node node = session.getRootNode().addNode("Test3");
node.addMixin("mix:versionable");
node.setProperty("name", "lalalal");
node.setProperty("code", "lalalal");
session.save();
vm.checkin(node.getPath());
}
代码示例来源:origin: info.magnolia/magnolia-core
@Test
public void testIsNodeTypeWithSetMixin() throws Exception {
// GIVEN
final Node newNode = new MockNode();
final String mixin = NodeTypes.Activatable.NAME;
newNode.addMixin(mixin);
// WHEN
final boolean result = newNode.isNodeType(mixin);
// THEN
assertTrue(result);
}
代码示例来源:origin: apache/jackrabbit-oak
public void testLastModifiedBy() throws RepositoryException {
Node testNode = testSession.getNode(testRoot);
testNode.addMixin(NodeTypeConstants.MIX_LASTMODIFIED);
testNode.setProperty(propertyName1, "any value");
testSession.save();
assertTrue(testNode.hasProperty(NodeTypeConstants.JCR_LASTMODIFIEDBY));
assertEquals(testSession.getUserID(), testNode.getProperty(NodeTypeConstants.JCR_LASTMODIFIEDBY).getString());
removeTestUser();
testSession.refresh(false);
// EXERCISE: do you expect the property to be still present? explain why and fix the test if necessary.
assertTrue(testNode.hasProperty(NodeTypeConstants.JCR_LASTMODIFIEDBY));
}
代码示例来源:origin: apache/jackrabbit-oak
@Test
public void testCugInvalidPrincipals() throws Exception {
Node targetNode = getTargetNode();
targetNode.addMixin(CugConstants.MIX_REP_CUG_MIXIN);
doImport(getTargetPath(), XML_CUG_POLICY);
Node cugNode = targetNode.getNode(CugConstants.REP_CUG_POLICY);
Value[] principalNames = cugNode.getProperty(CugConstants.REP_PRINCIPAL_NAMES).getValues();
assertPrincipalNames(ImmutableSet.of(EveryonePrincipal.NAME), principalNames);
getImportSession().save();
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
@Test
public void testIsAvailableForItemThatIsMarkedAsDeleted() throws RepositoryException {
// GIVEN
Node node = webSiteSession.getRootNode().addNode("node2", NodeTypes.Page.NAME);
node.addMixin(NodeTypes.Deleted.NAME);
// WHEN
Object itemId = JcrItemUtil.getItemId(node);
boolean isAvailable = rule.isAvailableForItem(itemId);
// THEN
assertFalse(isAvailable);
}
代码示例来源:origin: ModeShape/modeshape
@Test
public void shouldAllowAdditionIfResidualPropertyDoesNotConflict() throws Exception {
session.getRootNode().addNode("a", "nt:unstructured");
session.save();
Node rootNode = session.getRootNode();
Node nodeA = rootNode.getNode("a");
nodeA.setProperty(PROPERTY_B, 10L);
assertThat(nodeA.canAddMixin(MIXIN_TYPE_WITH_AUTO_PROP), is(true));
nodeA.addMixin(MIXIN_TYPE_WITH_AUTO_PROP);
}
代码示例来源:origin: apache/jackrabbit-oak
public void testReferenceableChild() throws RepositoryException {
Node node = testRootNode.addNode(nodeName1, ntUnstructured);
node.addMixin(mixVersionable);
Node child = node.addNode(nodeName2, ntUnstructured);
child.addMixin(mixReferenceable);
superuser.save();
VersionManager vMgr = superuser.getWorkspace().getVersionManager();
vMgr.checkin(node.getPath());
}
代码示例来源:origin: org.modeshape/modeshape-sequencer-text
@Override
public void recordRow( Node outputNode,
String[] columns ) throws RepositoryException {
Node rowNode = outputNode.addNode(ROW);
for (String column : columns) {
Node columnNode = rowNode.addNode(COLUMN);
columnNode.addMixin(COLUMN);
columnNode.setProperty(DATA, column);
}
}
}
代码示例来源:origin: apache/jackrabbit-oak
@Test
public void testCugInvalidPrincipals() throws Exception {
Node targetNode = getTargetNode();
targetNode.addMixin(CugConstants.MIX_REP_CUG_MIXIN);
doImport(getTargetPath(), XML_CUG_POLICY);
Node cugNode = targetNode.getNode(CugConstants.REP_CUG_POLICY);
Value[] principalNames = cugNode.getProperty(CugConstants.REP_PRINCIPAL_NAMES).getValues();
assertPrincipalNames(PRINCIPAL_NAMES, principalNames);
getImportSession().save();
}
代码示例来源:origin: ModeShape/modeshape
@Test
public void shouldAllowRemovalIfExistingChildNodeWouldHaveDefinition() throws Exception {
Node a = session.getRootNode().addNode("a", "nt:unstructured");
a.addMixin(MIXIN_TYPE_B);
a.addNode(CHILD_NODE_B);
session.save();
Node rootNode = session.getRootNode();
Node nodeA = rootNode.getNode("a");
nodeA.removeMixin(MIXIN_TYPE_B);
}
代码示例来源:origin: apache/jackrabbit
@Override
protected void setUp() throws Exception {
super.setUp();
// create some nodes below the test root in order to apply ac-stuff
Node node = testRootNode.addNode(nodeName1, testNodeType);
node.addMixin(NodeType.MIX_LOCKABLE);
superuser.save();
path = node.getPath();
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-workflow
private static Node newRequestNode(Node parent) throws RepositoryException {
JcrUtils.ensureIsCheckedOut(parent);
Node requestNode = parent.addNode(HippoStdPubWfNodeType.HIPPO_REQUEST, HippoStdPubWfNodeType.NT_HIPPOSTDPUBWF_REQUEST);
requestNode.setProperty(HippoStdPubWfNodeType.HIPPOSTDPUBWF_CREATION_DATE, Calendar.getInstance());
requestNode.addMixin(JcrConstants.MIX_REFERENCEABLE);
return requestNode;
}
代码示例来源:origin: apache/jackrabbit-oak
@Test
public void testCugValidPrincipals() throws Exception {
testGroup = ((JackrabbitSession) adminSession).getUserManager().createGroup(new PrincipalImpl(TEST_GROUP_PRINCIPAL_NAME));
adminSession.save();
Node targetNode = getTargetNode();
targetNode.addMixin(CugConstants.MIX_REP_CUG_MIXIN);
doImport(getTargetPath(), XML_CUG_POLICY);
adminSession.save();
}
代码示例来源:origin: apache/jackrabbit-oak
public void testRecreateVersionableNodeWithRemovedChild() throws Exception {
Node node = testRootNode.addNode(nodeName1, ntUnstructured);
node.addMixin(mixVersionable);
node.addNode(nodeName2, ntUnstructured).setProperty(propertyName1, "foo");
superuser.save();
VersionManager vm = superuser.getWorkspace().getVersionManager();
vm.checkin(node.getPath());
// re-create node
node.remove();
node = testRootNode.addNode(nodeName1, ntUnstructured);
node.addMixin(mixVersionable);
superuser.save();
}
代码示例来源:origin: ModeShape/modeshape
protected void initializeData() throws Exception {
Node root = session.getRootNode();
Node a = root.addNode("a");
Node b = a.addNode("b");
Node c = b.addNode("c");
a.addMixin("mix:lockable");
a.setProperty("stringProperty", "value");
b.addMixin("mix:referenceable");
b.setProperty("booleanProperty", true);
c.setProperty("stringProperty", "value");
c.setProperty("multiLineProperty", MULTI_LINE_VALUE);
session.save();
}
内容来源于网络,如有侵权,请联系作者删除!