javax.jcr.Node.addMixin()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(304)

本文整理了Java中javax.jcr.Node.addMixin()方法的一些代码示例,展示了Node.addMixin()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.addMixin()方法的具体详情如下:
包路径:javax.jcr.Node
类名称:Node
方法名:addMixin

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

  1. @Override
  2. public void recordRow( Node outputNode,
  3. String[] columns ) throws RepositoryException {
  4. Node rowNode = outputNode.addNode(ROW);
  5. for (String column : columns) {
  6. Node columnNode = rowNode.addNode(COLUMN);
  7. columnNode.addMixin(COLUMN);
  8. columnNode.setProperty(DATA, column);
  9. }
  10. }
  11. }

代码示例来源:origin: org.onehippo.cms7/hippo-repository-workflow

  1. private Node createNode(String name, final String type) throws RepositoryException, WorkflowException {
  2. Node folder = rootSession.getNodeByIdentifier(subject.getIdentifier());
  3. name = NodeNameCodec.encode(name);
  4. if (isSameNameSibling(name, folder)){
  5. throw new WorkflowException(MessageFormat.format(
  6. "A node with name {0} already exists in folder {1}. Not allowed to create same-name siblings",
  7. name, folder.getPath()));
  8. }
  9. final Node handle = folder.addNode(name, NT_HANDLE);
  10. handle.addMixin(MIX_REFERENCEABLE);
  11. final Node document = handle.addNode(name, type);
  12. document.setProperty(HIPPO_AVAILABILITY, new String[] { "live", "preview" });
  13. return document;
  14. }

代码示例来源:origin: apache/jackrabbit-oak

  1. @Test
  2. public void testAddMixinWithoutPermission() throws Exception {
  3. try {
  4. childNode.addMixin(mixinName);
  5. testSession.save();
  6. fail("TestSession does not have sufficient privileges to add a mixin type.");
  7. } catch (AccessDeniedException e) {
  8. // success
  9. }
  10. }

代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility

  1. @Test
  2. public void testIsAvailableForItemThatIsMarkedAsDeleted() throws RepositoryException {
  3. // GIVEN
  4. Node node = webSiteSession.getRootNode().addNode("node2", NodeTypes.Page.NAME);
  5. node.addMixin(NodeTypes.Deleted.NAME);
  6. // WHEN
  7. Object itemId = JcrItemUtil.getItemId(node);
  8. boolean isAvailable = rule.isAvailableForItem(itemId);
  9. // THEN
  10. assertTrue(isAvailable);
  11. }

代码示例来源:origin: ModeShape/modeshape

  1. @Test
  2. public void shouldNotAllowUpdatingNodesInReadOnlyProjection() throws Exception {
  3. Node file = session.getNode("/testRoot/readonly/dir3/simple.json");
  4. try {
  5. file.addMixin("flex:anyProperties");
  6. file.setProperty("extraProp", "extraValue");
  7. session.save();
  8. fail("failed to throw read-only exception");
  9. } catch (RepositoryException e) {
  10. // expected
  11. }
  12. }

代码示例来源:origin: ModeShape/modeshape

  1. @Test
  2. public void shouldBeAbleToVersionOutsideOfUserTransaction() throws Exception {
  3. VersionManager vm = session.getWorkspace().getVersionManager();
  4. Node node = session.getRootNode().addNode("Test3");
  5. node.addMixin("mix:versionable");
  6. node.setProperty("name", "lalalal");
  7. node.setProperty("code", "lalalal");
  8. session.save();
  9. vm.checkin(node.getPath());
  10. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. @Test
  2. public void testIsNodeTypeWithSetMixin() throws Exception {
  3. // GIVEN
  4. final Node newNode = new MockNode();
  5. final String mixin = NodeTypes.Activatable.NAME;
  6. newNode.addMixin(mixin);
  7. // WHEN
  8. final boolean result = newNode.isNodeType(mixin);
  9. // THEN
  10. assertTrue(result);
  11. }

代码示例来源:origin: apache/jackrabbit-oak

  1. public void testLastModifiedBy() throws RepositoryException {
  2. Node testNode = testSession.getNode(testRoot);
  3. testNode.addMixin(NodeTypeConstants.MIX_LASTMODIFIED);
  4. testNode.setProperty(propertyName1, "any value");
  5. testSession.save();
  6. assertTrue(testNode.hasProperty(NodeTypeConstants.JCR_LASTMODIFIEDBY));
  7. assertEquals(testSession.getUserID(), testNode.getProperty(NodeTypeConstants.JCR_LASTMODIFIEDBY).getString());
  8. removeTestUser();
  9. testSession.refresh(false);
  10. // EXERCISE: do you expect the property to be still present? explain why and fix the test if necessary.
  11. assertTrue(testNode.hasProperty(NodeTypeConstants.JCR_LASTMODIFIEDBY));
  12. }

代码示例来源:origin: apache/jackrabbit-oak

  1. @Test
  2. public void testCugInvalidPrincipals() throws Exception {
  3. Node targetNode = getTargetNode();
  4. targetNode.addMixin(CugConstants.MIX_REP_CUG_MIXIN);
  5. doImport(getTargetPath(), XML_CUG_POLICY);
  6. Node cugNode = targetNode.getNode(CugConstants.REP_CUG_POLICY);
  7. Value[] principalNames = cugNode.getProperty(CugConstants.REP_PRINCIPAL_NAMES).getValues();
  8. assertPrincipalNames(ImmutableSet.of(EveryonePrincipal.NAME), principalNames);
  9. getImportSession().save();
  10. }

代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility

  1. @Test
  2. public void testIsAvailableForItemThatIsMarkedAsDeleted() throws RepositoryException {
  3. // GIVEN
  4. Node node = webSiteSession.getRootNode().addNode("node2", NodeTypes.Page.NAME);
  5. node.addMixin(NodeTypes.Deleted.NAME);
  6. // WHEN
  7. Object itemId = JcrItemUtil.getItemId(node);
  8. boolean isAvailable = rule.isAvailableForItem(itemId);
  9. // THEN
  10. assertFalse(isAvailable);
  11. }

代码示例来源:origin: ModeShape/modeshape

  1. @Test
  2. public void shouldAllowAdditionIfResidualPropertyDoesNotConflict() throws Exception {
  3. session.getRootNode().addNode("a", "nt:unstructured");
  4. session.save();
  5. Node rootNode = session.getRootNode();
  6. Node nodeA = rootNode.getNode("a");
  7. nodeA.setProperty(PROPERTY_B, 10L);
  8. assertThat(nodeA.canAddMixin(MIXIN_TYPE_WITH_AUTO_PROP), is(true));
  9. nodeA.addMixin(MIXIN_TYPE_WITH_AUTO_PROP);
  10. }

代码示例来源:origin: apache/jackrabbit-oak

  1. public void testReferenceableChild() throws RepositoryException {
  2. Node node = testRootNode.addNode(nodeName1, ntUnstructured);
  3. node.addMixin(mixVersionable);
  4. Node child = node.addNode(nodeName2, ntUnstructured);
  5. child.addMixin(mixReferenceable);
  6. superuser.save();
  7. VersionManager vMgr = superuser.getWorkspace().getVersionManager();
  8. vMgr.checkin(node.getPath());
  9. }

代码示例来源:origin: org.modeshape/modeshape-sequencer-text

  1. @Override
  2. public void recordRow( Node outputNode,
  3. String[] columns ) throws RepositoryException {
  4. Node rowNode = outputNode.addNode(ROW);
  5. for (String column : columns) {
  6. Node columnNode = rowNode.addNode(COLUMN);
  7. columnNode.addMixin(COLUMN);
  8. columnNode.setProperty(DATA, column);
  9. }
  10. }
  11. }

代码示例来源:origin: apache/jackrabbit-oak

  1. @Test
  2. public void testCugInvalidPrincipals() throws Exception {
  3. Node targetNode = getTargetNode();
  4. targetNode.addMixin(CugConstants.MIX_REP_CUG_MIXIN);
  5. doImport(getTargetPath(), XML_CUG_POLICY);
  6. Node cugNode = targetNode.getNode(CugConstants.REP_CUG_POLICY);
  7. Value[] principalNames = cugNode.getProperty(CugConstants.REP_PRINCIPAL_NAMES).getValues();
  8. assertPrincipalNames(PRINCIPAL_NAMES, principalNames);
  9. getImportSession().save();
  10. }

代码示例来源:origin: ModeShape/modeshape

  1. @Test
  2. public void shouldAllowRemovalIfExistingChildNodeWouldHaveDefinition() throws Exception {
  3. Node a = session.getRootNode().addNode("a", "nt:unstructured");
  4. a.addMixin(MIXIN_TYPE_B);
  5. a.addNode(CHILD_NODE_B);
  6. session.save();
  7. Node rootNode = session.getRootNode();
  8. Node nodeA = rootNode.getNode("a");
  9. nodeA.removeMixin(MIXIN_TYPE_B);
  10. }

代码示例来源:origin: apache/jackrabbit

  1. @Override
  2. protected void setUp() throws Exception {
  3. super.setUp();
  4. // create some nodes below the test root in order to apply ac-stuff
  5. Node node = testRootNode.addNode(nodeName1, testNodeType);
  6. node.addMixin(NodeType.MIX_LOCKABLE);
  7. superuser.save();
  8. path = node.getPath();
  9. }

代码示例来源:origin: org.onehippo.cms7/hippo-repository-workflow

  1. private static Node newRequestNode(Node parent) throws RepositoryException {
  2. JcrUtils.ensureIsCheckedOut(parent);
  3. Node requestNode = parent.addNode(HippoStdPubWfNodeType.HIPPO_REQUEST, HippoStdPubWfNodeType.NT_HIPPOSTDPUBWF_REQUEST);
  4. requestNode.setProperty(HippoStdPubWfNodeType.HIPPOSTDPUBWF_CREATION_DATE, Calendar.getInstance());
  5. requestNode.addMixin(JcrConstants.MIX_REFERENCEABLE);
  6. return requestNode;
  7. }

代码示例来源:origin: apache/jackrabbit-oak

  1. @Test
  2. public void testCugValidPrincipals() throws Exception {
  3. testGroup = ((JackrabbitSession) adminSession).getUserManager().createGroup(new PrincipalImpl(TEST_GROUP_PRINCIPAL_NAME));
  4. adminSession.save();
  5. Node targetNode = getTargetNode();
  6. targetNode.addMixin(CugConstants.MIX_REP_CUG_MIXIN);
  7. doImport(getTargetPath(), XML_CUG_POLICY);
  8. adminSession.save();
  9. }

代码示例来源:origin: apache/jackrabbit-oak

  1. public void testRecreateVersionableNodeWithRemovedChild() throws Exception {
  2. Node node = testRootNode.addNode(nodeName1, ntUnstructured);
  3. node.addMixin(mixVersionable);
  4. node.addNode(nodeName2, ntUnstructured).setProperty(propertyName1, "foo");
  5. superuser.save();
  6. VersionManager vm = superuser.getWorkspace().getVersionManager();
  7. vm.checkin(node.getPath());
  8. // re-create node
  9. node.remove();
  10. node = testRootNode.addNode(nodeName1, ntUnstructured);
  11. node.addMixin(mixVersionable);
  12. superuser.save();
  13. }

代码示例来源:origin: ModeShape/modeshape

  1. protected void initializeData() throws Exception {
  2. Node root = session.getRootNode();
  3. Node a = root.addNode("a");
  4. Node b = a.addNode("b");
  5. Node c = b.addNode("c");
  6. a.addMixin("mix:lockable");
  7. a.setProperty("stringProperty", "value");
  8. b.addMixin("mix:referenceable");
  9. b.setProperty("booleanProperty", true);
  10. c.setProperty("stringProperty", "value");
  11. c.setProperty("multiLineProperty", MULTI_LINE_VALUE);
  12. session.save();
  13. }

相关文章