Example usage for com.fasterxml.jackson.databind JsonNode getClass

List of usage examples for com.fasterxml.jackson.databind JsonNode getClass

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.commonwl.view.cwl.CWLService.java

/**
 * Get inputs or outputs from an in or out node
 * @param inOut The in or out node/*from ww w.j  av  a 2s .co  m*/
 * @return A map of input IDs and details related to them
 */
private Map<String, CWLElement> getStepInputsOutputs(JsonNode inOut) {
    Map<String, CWLElement> returnMap = new HashMap<>();

    if (inOut.getClass() == ArrayNode.class) {
        // array<WorkflowStepInput>
        for (JsonNode inOutNode : inOut) {
            if (inOutNode.getClass() == ObjectNode.class) {
                CWLElement inputOutput = new CWLElement();
                List<String> sources = extractSource(inOutNode);
                if (sources.size() > 0) {
                    for (String source : sources) {
                        inputOutput.addSourceID(stepIDFromSource(source));
                    }
                } else {
                    inputOutput.setDefaultVal(extractDefault(inOutNode));
                }
                returnMap.put(extractID(inOutNode), inputOutput);
            }
        }
    } else if (inOut.getClass() == ObjectNode.class) {
        // map<WorkflowStepInput.id, WorkflowStepInput.source>
        Iterator<Map.Entry<String, JsonNode>> iterator = inOut.fields();
        while (iterator.hasNext()) {
            Map.Entry<String, JsonNode> inOutNode = iterator.next();
            CWLElement inputOutput = new CWLElement();
            if (inOutNode.getValue().getClass() == ObjectNode.class) {
                JsonNode properties = inOutNode.getValue();
                if (properties.has(SOURCE)) {
                    inputOutput.addSourceID(stepIDFromSource(properties.get(SOURCE).asText()));
                } else {
                    inputOutput.setDefaultVal(extractDefault(properties));
                }
            } else if (inOutNode.getValue().getClass() == ArrayNode.class) {
                for (JsonNode key : inOutNode.getValue()) {
                    inputOutput.addSourceID(stepIDFromSource(key.asText()));
                }
            } else {
                inputOutput.addSourceID(stepIDFromSource(inOutNode.getValue().asText()));
            }
            returnMap.put(inOutNode.getKey(), inputOutput);
        }
    }

    return returnMap;
}

From source file:org.commonwl.view.cwl.CWLService.java

/**
 * Get inputs or outputs from an inputs or outputs node
 * @param inputsOutputs The inputs or outputs node
 * @return A map of input IDs and details related to them
 *///from w  w w. ja v  a 2  s  .  com
private Map<String, CWLElement> getInputsOutputs(JsonNode inputsOutputs) {
    Map<String, CWLElement> returnMap = new HashMap<>();

    if (inputsOutputs.getClass() == ArrayNode.class) {
        // Explicit ID and other fields within each list
        for (JsonNode inputOutput : inputsOutputs) {
            String id = inputOutput.get(ID).asText();
            if (id.charAt(0) == '#') {
                id = id.substring(1);
            }
            returnMap.put(id, getDetails(inputOutput));
        }
    } else if (inputsOutputs.getClass() == ObjectNode.class) {
        // ID is the key of each object
        Iterator<Map.Entry<String, JsonNode>> iterator = inputsOutputs.fields();
        while (iterator.hasNext()) {
            Map.Entry<String, JsonNode> inputOutputNode = iterator.next();
            returnMap.put(inputOutputNode.getKey(), getDetails(inputOutputNode.getValue()));
        }
    }

    return returnMap;
}

From source file:org.commonwl.view.cwl.CWLService.java

/**
 * Gets the details of an input or output
 * @param inputOutput The node of the particular input or output
 * @return An CWLElement object with the label, doc and type extracted
 *//*from  www.ja  va2s.  c  o  m*/
private CWLElement getDetails(JsonNode inputOutput) {
    if (inputOutput != null) {
        CWLElement details = new CWLElement();

        // Shorthand notation "id: type" - no label/doc/other params
        if (inputOutput.getClass() == TextNode.class) {
            details.setType(inputOutput.asText());
        } else {
            details.setLabel(extractLabel(inputOutput));
            details.setDoc(extractDoc(inputOutput));
            extractSource(inputOutput).forEach(details::addSourceID);
            details.setDefaultVal(extractDefault(inputOutput));

            // Type is only for inputs
            if (inputOutput.has(TYPE)) {
                details.setType(extractTypes(inputOutput.get(TYPE)));
            }
        }

        return details;
    }
    return null;
}

From source file:org.commonwl.view.cwl.CWLService.java

/**
 * Extract the source or outputSource from a node
 * @param node The node to have the sources extracted from
 * @return A list of strings for the sources
 *//*from  w ww .j a  v  a2s  . c om*/
private List<String> extractSource(JsonNode node) {
    if (node != null) {
        List<String> sources = new ArrayList<String>();
        JsonNode sourceNode = null;

        // outputSource and source treated the same
        if (node.has(OUTPUT_SOURCE)) {
            sourceNode = node.get(OUTPUT_SOURCE);
        } else if (node.has(SOURCE)) {
            sourceNode = node.get(SOURCE);
        }

        if (sourceNode != null) {
            // Single source
            if (sourceNode.getClass() == TextNode.class) {
                sources.add(stepIDFromSource(sourceNode.asText()));
            }
            // Can be an array of multiple sources
            if (sourceNode.getClass() == ArrayNode.class) {
                for (JsonNode source : sourceNode) {
                    sources.add(stepIDFromSource(source.asText()));
                }
            }
        }

        return sources;
    }
    return null;
}

From source file:org.commonwl.view.cwl.CWLService.java

/**
 * Extract the types from a node representing inputs or outputs
 * @param typeNode The root node representing an input or output
 * @return A string with the types listed
 *//*  w w  w  .  j a v  a 2  s .  co  m*/
private String extractTypes(JsonNode typeNode) {
    if (typeNode != null) {
        if (typeNode.getClass() == TextNode.class) {
            // Single type
            return typeNode.asText();
        } else if (typeNode.getClass() == ArrayNode.class) {
            // Multiple types, build a string to represent them
            StringBuilder typeDetails = new StringBuilder();
            boolean optional = false;
            for (JsonNode type : typeNode) {
                if (type.getClass() == TextNode.class) {
                    // This is a simple type
                    if (type.asText().equals("null")) {
                        // null as a type means this field is optional
                        optional = true;
                    } else {
                        // Add a simple type to the string
                        typeDetails.append(type.asText());
                        typeDetails.append(", ");
                    }
                } else if (typeNode.getClass() == ArrayNode.class) {
                    // This is a verbose type with sub-fields broken down into type: and other params
                    if (type.get(TYPE).asText().equals(ARRAY)) {
                        typeDetails.append(type.get(ARRAY_ITEMS).asText());
                        typeDetails.append("[], ");
                    } else {
                        typeDetails.append(type.get(TYPE).asText());
                    }
                }
            }

            // Trim off excessive separators
            if (typeDetails.length() > 1) {
                typeDetails.setLength(typeDetails.length() - 2);
            }

            // Add optional if null was included in the multiple types
            if (optional)
                typeDetails.append("?");

            // Set the type to the constructed string
            return typeDetails.toString();

        } else if (typeNode.getClass() == ObjectNode.class) {
            // Type: array and items:
            if (typeNode.has(ARRAY_ITEMS)) {
                return typeNode.get(ARRAY_ITEMS).asText() + "[]";
            }
        }
    }
    return null;
}