Commit dfa065b5 authored by Sara Bertocco's avatar Sara Bertocco
Browse files

Added missing methods

parent 12d3aa54
Loading
Loading
Loading
Loading
Loading
+60 −0
Original line number Diff line number Diff line
@@ -9,6 +9,9 @@ import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import net.ivoa.xml.vospace.v2.ContainerNode;
import net.ivoa.xml.vospace.v2.DataNode;
import net.ivoa.xml.vospace.v2.StructuredDataNode;

public class NodeUtils {

@@ -164,4 +167,61 @@ public class NodeUtils {
        return true;
    }
    
        
        

    public static String getDbNodeType(Node node) {
        if (node instanceof ContainerNode) {
            return "container";
        } else if (node instanceof DataNode) {
            return "data";
        }
        throw new UnsupportedOperationException("Unable to retrieve database node type for class " + node.getClass().getCanonicalName());
    }
     

    public static String getNodeName(String path) {
        String[] parsedPath = path.split("/");

        return parsedPath[parsedPath.length - 1];
    }

    
    public static String getNodeName(Node myNode) {
        String uri = myNode.getUri();
        return getNodeName(uri);
    }
        

    public static boolean getIsBusy(Node myNode) {

        if (myNode instanceof DataNode) {

            DataNode dataNode = (DataNode) myNode;
            return dataNode.isBusy();
        }

        return false;
    }
    
    
    public static Node getTypedNode(String type) {
        Node node;
        switch (type) {
            case "container":
                node = new ContainerNode();
                break;
            case "data":
                node = new DataNode();
                break;
            case "structured":
                node = new StructuredDataNode();
                break;
            default:
                throw new UnsupportedOperationException("Node type " + type + " not supported yet");
        }
        return node;
    }
    

}