Package org.jdesktop.wonderland.tools.wfs

Examples of org.jdesktop.wonderland.tools.wfs.WFSCellDirectory


            LOGGER.warning("Unable to find WFS with name " + wfsName);
            return Response.status(Response.Status.BAD_REQUEST).build();
        }
       
        // Fetch the root directory, check if null, but should never be
        WFSCellDirectory dir = wfs.getRootDirectory();
        if (dir == null) {
            LOGGER.warning("Unable to find WFS root with name " + wfsName);
            return Response.status(Response.Status.BAD_REQUEST).build();
        }
       
        // Split the path up into individual components. We then fetch the
        // objects down the chain. As a special case if path is an empty string,
        // then set paths[] to an empty array.
        String paths[] = new String[0];
        if (path.compareTo("") != 0) {
            paths = path.split("/");
        }
       
        // Loop through each component and find the subdirectory in turn.
        for (int i = 0; i < paths.length; i++) {

            // First fetch the cell. If it does not exist, then return a bad
            // response. This is an error since the path should never contain
            // a Cell that does not exist.
            WFSCell cell = dir.getCellByName(paths[i]);
            if (cell == null) {
                LOGGER.warning("Unable to find WFS Cell with path: " + path);
                return Response.status(Response.Status.BAD_REQUEST).build();
            }
           
            // Next, get the directory associated with the cell. All elements
            // the path should have a Cell directory, except perhaps for the
            // last element.
            dir = cell.getCellDirectory();
            if (dir == null && i < paths.length - 1) {
                // Some interior path does not have a Cell directory. This is
                // an error.
                LOGGER.warning("Unable to find WFS Cell directory with path: " +
                        path);
                return Response.status(Response.Status.BAD_REQUEST).build();
            }
            else if (dir == null) {
                // Otherwise, if the final path does not have a Cell directory,
                // this is ok. It just means that Cell has no children, so we
                // return an empty list.
                LOGGER.fine("Did not find a WFS Cell directory for path " +
                        path + ". This is ok, returning empty list.");
                CellList children = new CellList(path, new Cell[] {});
                return Response.ok(children).build();
            }
        }
       
        // If we have reached here, we have 'dir' with the directory in which
        // the cells should be. Create a WFSCellChildren object which is used
        // to serialize the result.
        String names[] = dir.getCellNames();
        if (names == null) {
            // If the directory exists, yet there are no children, this is ok.
            // Just return an empty list.
            LOGGER.fine("Did not find WFS Cell children for path " + path +
                    ". This is ok, returning empty list.");
            CellList children = new CellList(path, new Cell[]{});
            return Response.ok(children).build();
        }

        LOGGER.fine("For WFS Cell " + path + " # Children " + names.length);
       
        // Loop through and create the WFSCellChildren object, we need to
        // include the last modified time so that the client can check whether
        // the cell has been modified or not.
        LinkedList<Cell> list = new LinkedList<Cell>();
        for (String name : names) {
            WFSCell cell = dir.getCellByName(name);
            if (cell == null) {
                LOGGER.warning("No WFS cell exists with name " + name);
                continue;
            }
            LOGGER.fine("Found WFS child " + name + " in path " + path);
View Full Code Here


            ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST);
            return rb.build();
        }
       
        /* Fetch the root directory, check if null, but should never be */
        WFSCellDirectory dir = wfs.getRootDirectory();
        if (dir == null) {
            logger.warning("WFSManager: Unable to find WFS root with name " + wfsName);
            ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST);
            return rb.build();
        }
       
        /*
         * Split the path up into individual components. We then fetch the
         * object down the chain. We assume the last element is the file.
         */
        String paths[] = path.split("/");
        for (int i = 0; i < paths.length - 1; i++) {
            /*
             * First fetch the cell. If it does not exist, then return a bad
             * response.
             */
            WFSCell cell = dir.getCellByName(paths[i]);
            if (cell == null) {
                logger.warning("WFSManager: Unable to find cell with path: " + path);
                ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST);
                return rb.build();
            }
           
            /*
             * Next, get the directory associated with the cell. It also needs
             * to exist, otherwise, return a bad response.
             */
            if ((dir = cell.getCellDirectory()) == null) {
                logger.warning("WFSManager: Unable to find directory with path: " + path);
                ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST);
                return rb.build();
            }
        }
       
        /*
         * If we have reached here, we have one remaining element in the path
         * and 'dir' holds the directory in which the cell should be.
         */
        WFSCell cell = dir.getCellByName(paths[paths.length - 1]);
        if (cell == null) {
            logger.warning("WFSManager: Unable to find final cell with path: " + path);
            ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST);
            return rb.build();
        }
View Full Code Here

            ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST);
            return rb.build();
        }
       
        /* Fetch the root directory, check if null, but should never be */
        WFSCellDirectory rootDir = wfs.getRootDirectory();
        if (rootDir == null) {
            logger.warning("WFSManager: Unable to find WFS root with name " + wfsName);
            ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST);
            return rb.build();
        }
       
        /*
         * Find out whether we should reload the WFS as we read it. We acquire
         * ownership of the WFS momentarily to tell it to reload
         */
        if (reload != null && reload.compareTo("true") == 0) {
            try {
                wfs.acquireOwnership();
                rootDir.setReload();
                wfs.release();
            } catch (InterruptedException excp) {
                logger.warning("WFSManager: Unable to set WFS to reload " + excp.toString());
            }
        }
       
        /* A queue (last-in, first-out) containing a list of cell to search down */
        LinkedList<WFSCellDirectory> children = new LinkedList();
        children.addFirst(rootDir);
       
        /*
         * Perform a breadth-first search through the tree and add cells as we
         * discover them.
         */
        while (children.isEmpty() == false) {
            /* Fetch and remove the first on the list and load */
            WFSCellDirectory childdir = children.removeFirst();
            this.loadCells(childdir, children, cellList);
        }
       
        /* Convert the list of CellChilds to an array */
        Cell[] childs = cellList.toArray(new Cell[] {});
View Full Code Here

            logger.warning("[WFS] The WFS " + rootPath + " does not exist.");
            return Response.status(Status.BAD_REQUEST).build();
        }
       
        // Fetch the root directory, this should exist
        WFSCellDirectory wfsDirectory = wfs.getRootDirectory();
        if (wfsDirectory == null) {
            logger.warning("[WFS] Unable to find root directory for " + rootPath);
            return Response.status(Response.Status.BAD_REQUEST).build();
        }
       
        // Iterate through all of the parents of the cell and fetch the proper
        // directory to place the new cell in. We fetch the names of the parent
        // cell individually and jump down through the list of directories. Note
        // that all of the directories, except perhaps the last should exist,
        // so we flag an error if that is not the case. If the parent path is
        // null, then this is a cell at the root of the wfs
        if (cellDescriptor.getParentPath() != null) {
            String parentCells[] = cellDescriptor.getParentPath().getParentPaths();
            for (int i = 0; i < parentCells.length; i++) {
                // First fetch the cell. If it does not exist, then return a bad
                // response.
                WFSCell parentCell = wfsDirectory.getCellByName(parentCells[i]);
                if (parentCell == null) {
                    logger.warning("[WFS] Unable to find cell " + parentCells[i] +
                            " in WFS " + rootPath);
                    return Response.status(Response.Status.BAD_REQUEST).build();
                }

                // Next, get the directory associated with the cell. It also needs
                // to exist, otherwise, return a bad response. The only exception
                // is the last parent in the cell, which may not have its child
                // directory yet created.
                wfsDirectory = parentCell.getCellDirectory();
                if (i < parentCells.length - 1 && wfsDirectory == null) {
                    // This means that a parent cell directory, other than the
                    // immediate parent does not exist (which means the immediate
                    // parent cell does not exist, which is very bad!
                    logger.warning("[WFS] Unable to find directory for cell " +
                            parentCells[i] + " in WFS " + rootPath);
                    return Response.status(Response.Status.BAD_REQUEST).build();
                }
                else if (wfsDirectory == null) {
                    // Unless we are talking about the cell directory associated
                    // with the parent. In which case we should create it.
                    try {
                        wfs.acquireOwnership();
                        wfsDirectory = parentCell.createCellDirectory();
                        parentCell.write();
                    } catch (java.lang.InterruptedException excp) {
                        logger.log(Level.WARNING, "[WFS] Unable to lock WFS " +
                                rootPath, excp);
                        return Response.status(Response.Status.BAD_REQUEST).build();
                    } catch (java.lang.Exception excp) {
                        logger.log(Level.WARNING, "[WFS] Failed to create WFS " +
                                " directory " + rootPath);
                        return Response.status(Response.Status.BAD_REQUEST).build();
                    } finally {
                        wfs.release();
                    }
                }
            }
        }
       
        // When we have reached here, the directory in which to place the new
        // cell is in 'wfsDirectory'. We create the cell and write the WFS
        // back out to its disk. In this case, the cell name is the name of
        // the file, which should be <Cell Name>-<Cell ID>.
        try {
            wfs.acquireOwnership();
            String cellName = cellDescriptor.getCellUniqueName();
            WFSCell cell = wfsDirectory.addCell(cellName);
            if (cell == null) {
                logger.warning("[WFS] Failed to create cell " + cellName +
                        " in WFS " + rootPath);
                return Response.status(Response.Status.BAD_REQUEST).build();
            }
            cell.setCellSetup(cellDescriptor.getSetupInfo());
            wfsDirectory.write();
        } catch (java.lang.Exception excp) {
            logger.log(Level.WARNING, "[WFS] Unable to lock WFS " + rootPath, excp);
            return Response.status(Response.Status.BAD_REQUEST).build();
        } finally {
            wfs.release();
View Full Code Here

TOP

Related Classes of org.jdesktop.wonderland.tools.wfs.WFSCellDirectory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.