コード例 #1
0
    protected void setProperty(Node node, Property property, boolean isMultiValued)
        throws RepositoryException {
      Name name = property.getName();
      if (name.equals(JcrLexicon.PRIMARY_TYPE)) return;
      if (name.equals(ModeShapeIntLexicon.NODE_DEFINITON)) return;
      if (name.equals(ModeShapeIntLexicon.MULTI_VALUED_PROPERTIES)) return;
      if (name.equals(JcrLexicon.MIXIN_TYPES)) {
        for (Object mixinVvalue : property.getValuesAsArray()) {
          String mixinTypeName = stringFor(mixinVvalue);
          node.addMixin(mixinTypeName);
        }
        return;
      }

      // Otherwise, just set the normal property. First determine the expected type ...
      String propertyName = stringFor(name);
      if (isMultiValued) {
        Value[] values = new Value[property.size()];
        int index = 0;
        PropertyType propertyType = null;
        for (Object value : property) {
          if (value == null) continue;
          if (propertyType == null) propertyType = PropertyType.discoverType(value);
          values[index] = convertToJcrValue(propertyType, value);
          ++index;
        }
        node.setProperty(propertyName, values);
      } else {
        Object firstValue = property.getFirstValue();
        PropertyType propertyType = PropertyType.discoverType(firstValue);
        Value value = convertToJcrValue(propertyType, firstValue);
        node.setProperty(propertyName, value);
      }
    }
コード例 #2
0
  protected void assertMatchesStore(AbstractJcrNode jcrNode) throws RepositoryException {
    // Find the corresponding session node ...
    Node<JcrNodePayload, JcrPropertyPayload> nodeInfo =
        cache.findNode(jcrNode.nodeId, jcrNode.path());
    // And the graph node ...
    org.modeshape.graph.Node dnaNode = store.getNodeAt(jcrNode.location);

    assertThat(nodeInfo.getLocation(), is(dnaNode.getLocation()));
    Set<Name> propertyNames = nodeInfo.getPropertyNames();
    for (Name propertyName : propertyNames) {
      PropertyInfo<JcrPropertyPayload> info = nodeInfo.getProperty(propertyName);
      assertThat(info.getName(), is(propertyName));
      assertThat(info.getProperty().getName(), is(propertyName));
      Property actual = dnaNode.getProperty(propertyName);
      if (actual != null) {
        assertThat(info.getProperty().size(), is(actual.size()));
        assertThat(info.getProperty().getValuesAsArray(), is(actual.getValuesAsArray()));
      } else {
        if (propertyName.equals(JcrLexicon.UUID)) {
          // check for a ModeShape UUID property ...
          actual = dnaNode.getProperty(ModeShapeLexicon.UUID);
          if (actual != null) {
            assertThat(info.getProperty().size(), is(actual.size()));
            assertThat(info.getProperty().getValuesAsArray(), is(actual.getValuesAsArray()));
          } else {
            fail("missing property \"" + propertyName + "\" on " + dnaNode);
          }
        } else if (propertyName.equals(JcrLexicon.PRIMARY_TYPE)) {
          // This is okay
        } else if (propertyName.equals(ModeShapeIntLexicon.MULTI_VALUED_PROPERTIES)) {
          // This is okay
        } else {
          fail("missing property \"" + propertyName + "\" on " + dnaNode);
        }
      }
    }
  }