Пример #1
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.ReadAllPropertiesRequest)
  */
 @Override
 public void process(ReadAllPropertiesRequest request) {
   if (request == null) return;
   try {
     Workspace workspace = workspaceFor(request.inWorkspace());
     Node node = workspace.node(request.at());
     Location actualLocation = workspace.locationFor(node);
     request.setActualLocationOfNode(actualLocation);
     // Read the properties ...
     for (PropertyIterator iter = node.getProperties(); iter.hasNext(); ) {
       request.addProperty(workspace.propertyFor(iter.nextProperty()));
     }
     // Add in the 'jcr:uuid' property ...
     if (actualLocation.hasIdProperties()) {
       request.addProperty(workspace.propertyFor(ModeShapeLexicon.UUID, actualLocation.getUuid()));
     }
     // Get the number of children ...
     NodeIterator childIter = node.getNodes();
     int numChildren = (int) childIter.getSize();
     if (numChildren == -1) {
       numChildren = 0;
       while (childIter.hasNext()) {
         childIter.nextNode();
         ++numChildren;
       }
     }
     request.setNumberOfChildren(numChildren);
     setCacheableInfo(request);
   } catch (Throwable e) {
     request.setError(e);
   }
 }
Пример #2
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.ReadNodeRequest)
  */
 @Override
 public void process(ReadNodeRequest request) {
   if (request == null) return;
   try {
     Workspace workspace = workspaceFor(request.inWorkspace());
     Node node = workspace.node(request.at());
     Location actualLocation = workspace.locationFor(node);
     request.setActualLocationOfNode(actualLocation);
     // Read the children ...
     for (NodeIterator iter = node.getNodes(); iter.hasNext(); ) {
       request.addChild(workspace.locationFor(iter.nextNode()));
     }
     // Read the properties ...
     for (PropertyIterator iter = node.getProperties(); iter.hasNext(); ) {
       request.addProperty(workspace.propertyFor(iter.nextProperty()));
     }
     // Add in the 'jcr:uuid' property ...
     if (actualLocation.hasIdProperties()) {
       request.addProperty(workspace.propertyFor(ModeShapeLexicon.UUID, actualLocation.getUuid()));
     }
     setCacheableInfo(request);
   } catch (Throwable e) {
     request.setError(e);
   }
 }
Пример #3
0
 /**
  * Find the existing node given the location.
  *
  * @param location the location of the node, which must have a {@link Location#getPath() path}
  *     and/or {@link Location#getUuid() UUID}
  * @return the existing node; never null
  * @throws RepositoryException if there is an error working with the session
  * @throws PathNotFoundException if the node could not be found by its path
  */
 public Node node(Location location) throws RepositoryException {
   Node root = session.getRootNode();
   UUID uuid = location.getUuid();
   if (uuid != null) {
     try {
       return session.getNodeByIdentifier(uuid.toString());
     } catch (ItemNotFoundException e) {
       if (!location.hasPath()) {
         String msg = JcrConnectorI18n.unableToFindNodeWithUuid.text(getSourceName(), uuid);
         throw new PathNotFoundException(
             location, factories.getPathFactory().createRootPath(), msg);
       }
       // Otherwise, try to find it by its path ...
     }
   }
   if (location.hasPath()) {
     Path relativePath = location.getPath().relativeToRoot();
     ValueFactory<String> stringFactory = factories.getStringFactory();
     String relativePathStr = stringFactory.create(relativePath);
     try {
       return root.getNode(relativePathStr);
     } catch (javax.jcr.PathNotFoundException e) {
       // Figure out the lowest existing path ...
       Node node = root;
       for (Path.Segment segment : relativePath) {
         try {
           node = node.getNode(stringFactory.create(segment));
         } catch (javax.jcr.PathNotFoundException e2) {
           String pathStr = stringFactory.create(location.getPath());
           Path lowestPath = factories.getPathFactory().create(node.getPath());
           throw new PathNotFoundException(
               location,
               lowestPath,
               JcrConnectorI18n.nodeDoesNotExist.text(
                   getSourceName(), session.getWorkspace().getName(), pathStr));
         }
       }
     }
   }
   // Otherwise, we can't find the node ...
   String msg =
       JcrConnectorI18n.unableToFindNodeWithoutPathOrUuid.text(getSourceName(), location);
   throw new IllegalArgumentException(msg);
 }