コード例 #1
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.CreateNodeRequest)
   */
  @Override
  public void process(CreateNodeRequest request) {
    if (request == null) return;
    try {
      Workspace workspace = workspaceFor(request.inWorkspace());
      Node parent = workspace.node(request.under());
      String childName = workspace.stringFor(request.named());

      // Look for the primary type, if it was set on the request ...
      String primaryTypeName = null;
      for (Property property : request.properties()) {
        if (property.getName().equals(JcrLexicon.PRIMARY_TYPE)) {
          primaryTypeName = workspace.stringFor(property.getFirstValue());
          break;
        }
      }

      // Create the child node ...
      Node child = null;
      if (primaryTypeName != null) {
        child = parent.addNode(childName, primaryTypeName);
      } else {
        child = parent.addNode(childName);
      }
      assert child != null;

      // And set all of the properties on the new node ...
      workspace.setProperties(child, request);

      // Set up the actual results on the request ...
      request.setActualLocationOfNode(workspace.locationFor(child));
    } catch (Throwable e) {
      request.setError(e);
    }
  }
コード例 #2
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);
      }
    }
コード例 #3
0
ファイル: StoreProperties.java プロジェクト: kbachl/modeshape
 protected Set<Name> write(
     File propertiesFile, ExecutionContext context, Map<Name, Property> properties)
     throws RepositorySourceException {
   if (properties.isEmpty()) {
     if (propertiesFile.exists()) {
       // Delete the file ...
       propertiesFile.delete();
     }
     return Collections.emptySet();
   }
   Set<Name> names = new HashSet<Name>();
   try {
     ValueFactory<String> strings = context.getValueFactories().getStringFactory();
     Writer fileWriter = new FileWriter(propertiesFile);
     try {
       // Write the primary type first ...
       Property primaryType = properties.get(JcrLexicon.PRIMARY_TYPE);
       if (primaryType != null) {
         write(primaryType, fileWriter, strings);
         names.add(primaryType.getName());
       }
       // Then write the mixin types ...
       Property mixinTypes = properties.get(JcrLexicon.MIXIN_TYPES);
       if (mixinTypes != null) {
         write(mixinTypes, fileWriter, strings);
         names.add(mixinTypes.getName());
       }
       // Then write the UUID ...
       Property uuid = properties.get(JcrLexicon.UUID);
       if (uuid != null) {
         write(uuid, fileWriter, strings);
         names.add(uuid.getName());
       }
       // Then all the others ...
       for (Property property : properties.values()) {
         if (property == primaryType || property == mixinTypes || property == uuid) continue;
         write(property, fileWriter, strings);
         names.add(property.getName());
       }
     } finally {
       fileWriter.close();
     }
   } catch (IOException e) {
     throw new RepositorySourceException(sourceName, e);
   }
   return names;
 }
コード例 #4
0
    public void setProperties(Node node, Iterable<Property> properties) throws RepositoryException {
      // Look for the internal property that ModeShape uses to track which properties are
      // multi-valued w/r/t JCR ...
      Set<Name> multiValued = null;
      for (Property property : properties) {
        if (property.getName().equals(ModeShapeIntLexicon.MULTI_VALUED_PROPERTIES)) {
          // Go through the properties and see which properties are multi-valued ...
          multiValued = getMultiValuedProperties(property);
          break;
        }
      }
      if (multiValued == null) multiValued = Collections.emptySet();

      // Now set each of the properties ...
      for (Property property : properties) {
        setProperty(node, property, multiValued.contains(property.getName()));
      }
    }
コード例 #5
0
  /**
   * Add a request to update the property on the node at the supplied location. This request will
   * create the property if it does not yet exist.
   *
   * @param on the location of the node to be read
   * @param workspaceName the name of the workspace containing the node
   * @param property the new property on the node
   * @return this builder for method chaining; never null
   * @throws IllegalArgumentException if the location or workspace name is null or if there are no
   *     properties to update
   */
  public BatchRequestBuilder setProperty(Location on, String workspaceName, Property property) {
    // If there's a pending request ...
    if (pendingRequest != null) {
      // Compare the supplied location with that of the pending request
      if (pendingRequest.location.isSame(on)) {
        // They are the same location, so we can add the properties to the pending request ...
        pendingRequest.pendingProperties.put(property.getName(), property);
        return this;
      }
      // Not the exact same location, so push the existing pending request ...
      addPending();
    }

    // Record this operation as a pending change ...
    pendingRequest = new NodeChange(on, workspaceName);
    pendingRequest.pendingProperties.put(property.getName(), property);
    return this;
  }
コード例 #6
0
ファイル: StoreProperties.java プロジェクト: kbachl/modeshape
 protected Map<Name, Property> load(File propertiesFile, ExecutionContext context)
     throws RepositorySourceException {
   if (!propertiesFile.exists() || !propertiesFile.canRead()) return NO_PROPERTIES_MAP;
   try {
     String content = IoUtil.read(propertiesFile);
     ValueFactories factories = context.getValueFactories();
     PropertyFactory propFactory = context.getPropertyFactory();
     Map<Name, Property> result = new HashMap<Name, Property>();
     for (String line : StringUtil.splitLines(content)) {
       // Parse each line ...
       Property property = parse(line, factories, propFactory);
       if (property != null) {
         result.put(property.getName(), property);
       }
     }
     return result;
   } catch (IOException e) {
     throw new RepositorySourceException(sourceName, e);
   }
 }
コード例 #7
0
ファイル: StoreProperties.java プロジェクト: kbachl/modeshape
 protected void write(Property property, Writer stream, ValueFactory<String> strings)
     throws IOException {
   String name = strings.create(property.getName());
   stream.append(encoder.encode(name));
   if (property.isEmpty()) return;
   stream.append(" (");
   PropertyType type = PropertyType.discoverType(property.getFirstValue());
   stream.append(type.getName().toLowerCase());
   stream.append(") ");
   if (property.isMultiple()) {
     stream.append('[');
   }
   boolean first = true;
   boolean quote = type == PropertyType.STRING;
   for (Object value : property) {
     if (first) first = false;
     else stream.append(", ");
     String str = null;
     if (value instanceof Binary) {
       str = StringUtil.getHexString(((Binary) value).getBytes());
     } else {
       str = strings.create(value);
     }
     if (quote) {
       stream.append('"');
       stream.append(quoter.encode(str));
       stream.append('"');
     } else {
       stream.append(str);
     }
   }
   if (property.isMultiple()) {
     stream.append(']');
   }
   stream.append('\n');
   stream.flush();
 }
コード例 #8
0
 /**
  * Add a property that was read from the {@link RepositoryConnection}
  *
  * @param properties the properties that were read
  * @throws IllegalArgumentException if the property is null
  * @throws IllegalStateException if the request is frozen
  */
 public void addProperties(Iterable<Property> properties) {
   checkNotFrozen();
   for (Property property : properties) {
     this.properties.put(property.getName(), property);
   }
 }
コード例 #9
0
 /**
  * Add a property that was read from the {@link RepositoryConnection}
  *
  * @param property the property that was read
  * @return the previous property that had the same name, or null if there was no
  *     previously-recorded property with the same name
  * @throws IllegalArgumentException if the property is null
  * @throws IllegalStateException if the request is frozen
  */
 public Property addProperty(Property property) {
   checkNotFrozen();
   return this.properties.put(property.getName(), property);
 }