Example usage for com.fasterxml.jackson.databind.node ObjectNode ObjectNode

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode ObjectNode

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ObjectNode ObjectNode.

Prototype

ObjectNode

Source Link

Usage

From source file:net.sf.taverna.t2.activities.rshell.views.RshellConfigurationPanel.java

@Override
public void noteConfiguration() {
    setProperty("script", scriptConfigurationComponent.getScript());
    ObjectNode json = getJson();

    ObjectNode connection = json.objectNode();
    connection.put("hostname", hostnameField.getText());
    try {/*from   ww  w  .  j a  va 2 s.  co  m*/
        connection.put("port", Integer.parseInt(portField.getText()));
    } catch (NumberFormatException e) {
        connection.put("port", json.path("connection").path("port").asInt(RshellTemplateService.DEFAULT_PORT));
    }
    connection.put("keepSessionAlive", keepSessionAliveCheckBox.isSelected());
    json.put("connection", connection);

    List<ActivityPortConfiguration> inputPorts = getInputPorts();
    if (inputPorts.isEmpty()) {
        json.remove("inputTypes");
    } else {
        ArrayNode DataTypes = json.arrayNode();
        for (ActivityPortConfiguration activityPortConfiguration : inputPorts) {
            RshellActivityPortConfiguration portConfiguration = (RshellActivityPortConfiguration) activityPortConfiguration;
            ObjectNode semanticType = json.objectNode();
            DataTypes.add(semanticType);
            semanticType.put("port", portConfiguration.getName());
            semanticType.put("dataType", portConfiguration.getDataType().name());
        }
        json.put("inputTypes", DataTypes);
    }

    List<ActivityPortConfiguration> outputPorts = getOutputPorts();
    if (outputPorts.isEmpty()) {
        json.remove("outputTypes");
    } else {
        ArrayNode DataTypes = json.arrayNode();
        for (ActivityPortConfiguration activityPortConfiguration : outputPorts) {
            RshellActivityPortConfiguration portConfiguration = (RshellActivityPortConfiguration) activityPortConfiguration;
            ObjectNode semanticType = json.objectNode();
            DataTypes.add(semanticType);
            semanticType.put("port", portConfiguration.getName());
            semanticType.put("dataType", portConfiguration.getDataType().name());
        }
        json.put("outputTypes", DataTypes);
    }
}

From source file:org.apache.taverna.tavlang.tools.convert.ToJson.java

public ObjectNode toJson(WorkflowBundle wfBundle) {

    ObjectNode root = mapper.createObjectNode();
    ArrayNode contextList = root.arrayNode();
    root.put("@context", contextList);
    ObjectNode context = root.objectNode();
    contextList.add("https://w3id.org/scufl2/context");
    contextList.add(context);/*from  w w  w .  j a  v a 2  s. c o m*/
    URI base = wfBundle.getGlobalBaseURI();
    context.put("@base", base.toASCIIString());
    root.put("id", base.toASCIIString());

    // root.put("name", wfBundle.getName());
    // root.put("revisions", toJson(wfBundle.getCurrentRevision()));

    root.put("workflow", toJson(wfBundle.getMainWorkflow()));
    root.put("profile", toJson(wfBundle.getMainProfile()));

    return root;
}

From source file:net.sf.taverna.t2.uiexts.bioswr.model.HTTPBindingTemplateService.java

@Override
public Configuration getActivityConfiguration() {
    Configuration configuration = new Configuration();
    configuration.setType(GenericRESTTemplateService.ACTIVITY_TYPE.resolve("#Config"));

    Binding binding = operation.getParent();
    Interface _interface = binding.getInterface();

    Description description = binding.getParentElement();
    for (Service service : description.getAllServices()) {
        if (_interface.equals(service.getInterface())) {
            for (Endpoint endpoint : service.getEndpoints()) {
                if (binding.equals(endpoint.getBinding())) {
                    ObjectNode json = (ObjectNode) configuration.getJson();
                    ObjectNode requestNode = json.objectNode();
                    ArrayNode headersNode = requestNode.arrayNode();

                    HTTPBindingOperationExtensions ext = (HTTPBindingOperationExtensions) operation
                            .getComponentExtensions(WSDLPredefinedExtension.HTTP.URI);
                    String httpMethod = ext.getHttpMethod();
                    requestNode.put("httpMethod", httpMethod == null ? "GET" : httpMethod);

                    URI address = endpoint.getAddress();
                    StringBuilder url = new StringBuilder(address.toString());

                    String location = operation
                            .getExtensionAttribute(HTTPBindingOperationExtensions.HTTP_LOCATION_ATTR);
                    if (location != null) {
                        url.append(location);
                    }/*from  w w  w .  jav a2s .c  om*/

                    String inputSerialization = ext.getHttpInputSerialization();
                    if ("application/x-www-form-urlencoded".equals(inputSerialization)) {
                        putUrlEncodedInputs(operation, httpMethod, headersNode, url);
                    } else if ("application/xml".equals(inputSerialization)
                            && ("POST".equals(httpMethod) || "PUT".equals(httpMethod))) {
                        putXMLInputs(operation, headersNode);
                        headersNode.addObject().put("header", "Content-Type").put("value", "application/xml");
                    }

                    requestNode.put("absoluteURITemplate", url.toString());

                    String outputSerialization = ext.getHttpOutputSerialization();
                    if (outputSerialization != null) {
                        headersNode.addObject().put("header", "Accept").put("value", outputSerialization);
                    }

                    requestNode.set("headers", headersNode);
                    json.set("request", requestNode);
                    json.put("outgoingDataFormat", RESTActivity.DATA_FORMAT.String.name());
                    json.put("showRedirectionOutputPort", false);
                    json.put("showActualURLPort", false);
                    json.put("showResponseHeadersPort", false);
                    json.put("escapeParameters", true);

                }
            }
        }
    }

    return configuration;
}

From source file:org.apache.taverna.scufl2.translator.t2flow.t23activities.ExternalToolActivityParser.java

protected ObjectNode parseToolDescription(ObjectNode json, UsecaseDescription toolDesc,
        ParserState parserState) {//from  w ww. j  av  a  2 s.  com
    ObjectNode description = json.objectNode();
    description.put("dc:title", toolDesc.getUsecaseid());
    if (toolDesc.getGroup() != null)
        description.put("group", toolDesc.getGroup());
    if (toolDesc.getDescription() != null)
        description.put("dc:description", toolDesc.getDescription());

    description.put("command", toolDesc.getCommand());

    description.put("preparingTimeoutInSeconds", toolDesc.getPreparingTimeoutInSeconds());
    description.put("executionTimeoutInSeconds", toolDesc.getExecutionTimeoutInSeconds());

    // Ignoring tags, REs, queue__preferred, queue__deny

    ArrayNode staticInputs = json.arrayNode();
    // static inputs
    for (ScriptInputStatic inputStatic : toolDesc.getStaticInputs()
            .getDeUniLuebeckInbKnowarcUsecasesScriptInputStatic()) {
        ObjectNode input = json.objectNode();
        staticInputs.add(input);
        input.put("tag", inputStatic.getTag());
        input.put("file", inputStatic.isFile());
        input.put("tempFile", inputStatic.isTempFile());
        input.put("binary", inputStatic.isBinary());
        input.put("charsetName", inputStatic.getCharsetName());
        input.put("forceCopy", inputStatic.isForceCopy());
        if (inputStatic.getUrl() != null)
            input.put("url", inputStatic.getUrl());
        if (inputStatic.getContent() != null)
            input.put("content", inputStatic.getContent().getValue());
    }
    if (staticInputs.size() > 0)
        json.put("staticInputs", staticInputs);

    //      for (ScriptInputStatic inputStatic : toolDesc.getStaticInputs()
    //            .getDeUniLuebeckInbKnowarcUsecasesScriptInputStatic()) {
    //         String portName = inputStatic.getTag();
    //         PropertyResource staticInput = generatePortDefinition(portName, inputStatic.getTag(),
    //               inputStatic.getCharsetName(), true, false, inputStatic.isBinary(),
    //               inputStatic.isFile(), inputStatic.isTempFile(), inputStatic.isForceCopy(),
    //               false, true, parserState);
    //
    //         configResource.addProperty(ACTIVITY_URI.resolve("#staticInput"), staticInput);
    //         if (inputStatic.getUrl() != null) {
    //            staticInput.addPropertyReference(ACTIVITY_URI.resolve("#source"),
    //                  URI.create(inputStatic.getUrl()));
    //         } else {
    //            PropertyResource content = staticInput.addPropertyAsNewResource(
    //                  ACTIVITY_URI.resolve("#source"), CNT.resolve("#ContentAsText"));
    //            content.addPropertyAsString(CNT.resolve("#chars"), inputStatic.getContent()
    //                  .getValue());
    //            // TODO: Support bytes?
    //         }
    //      }

    // Inputs
    ArrayNode inputs = json.arrayNode();
    for (Entry entry : toolDesc.getInputs().getEntry()) {
        ObjectNode mapping = json.objectNode();
        mapping.put("port", entry.getString());
        ObjectNode input = json.objectNode();
        mapping.put("input", input);

        ScriptInputUser scriptInput = entry.getDeUniLuebeckInbKnowarcUsecasesScriptInputUser();
        input.put("tag", scriptInput.getTag());
        input.put("file", scriptInput.isFile());
        input.put("tempFile", scriptInput.isTempFile());
        input.put("binary", scriptInput.isBinary());

        input.put("charsetName", scriptInput.getCharsetName());
        input.put("forceCopy", scriptInput.isForceCopy());
        input.put("list", scriptInput.isList());
        input.put("concatenate", scriptInput.isConcatenate());
    }
    if (inputs.size() > 0)
        json.put("inputs", inputs);
    //      for (Entry entry : toolDesc.getInputs().getEntry()) {
    //         String portName = entry.getString();
    //         ScriptInputUser scriptInput = entry.getDeUniLuebeckInbKnowarcUsecasesScriptInputUser();
    //         PropertyResource portDef = generatePortDefinition(portName, scriptInput.getTag(),
    //               scriptInput.getCharsetName(), true, scriptInput.isList(),
    //               scriptInput.isBinary(), scriptInput.isFile(), scriptInput.isTempFile(),
    //               scriptInput.isForceCopy(), scriptInput.isConcatenate(), false, parserState);
    //         configResource.addProperty(Scufl2Tools.PORT_DEFINITION.resolve("#inputPortDefinition"),
    //               portDef);
    //      }

    // Outputs      
    ArrayNode outputs = json.arrayNode();
    for (Entry entry : toolDesc.getOutputs().getEntry()) {
        ObjectNode mapping = json.objectNode();
        mapping.put("port", entry.getString());
        ObjectNode output = json.objectNode();
        mapping.put("output", output);

        ScriptOutput scriptOutput = entry.getDeUniLuebeckInbKnowarcUsecasesScriptOutput();
        output.put("path", scriptOutput.getPath());
        output.put("binary", scriptOutput.isBinary());
    }
    if (outputs.size() > 0)
        json.put("outputs", outputs);
    //      for (Entry entry : toolDesc.getOutputs().getEntry()) {
    //         String portName = entry.getString();
    //         ScriptOutput scriptOutput = entry.getDeUniLuebeckInbKnowarcUsecasesScriptOutput();
    //         PropertyResource portDef = generatePortDefinition(portName, scriptOutput.getPath(),
    //               null, false, false, scriptOutput.isBinary(), true, false, false, false, false,
    //               parserState);
    //         configResource.addProperty(
    //               Scufl2Tools.PORT_DEFINITION.resolve("#outputPortDefinition"), portDef);
    // }

    json.put("includeStdIn", toolDesc.isIncludeStdIn());
    json.put("includeStdOut", toolDesc.isIncludeStdOut());
    json.put("includeStdErr", toolDesc.isIncludeStdErr());

    //      if (toolDesc.isIncludeStdIn()) {
    //         InputActivityPort stdin = new InputActivityPort(parserState.getCurrentActivity(), STDIN);
    //         stdin.setDepth(0);
    //      }
    //      if (toolDesc.isIncludeStdOut()) {
    //         OutputActivityPort stdout = new OutputActivityPort(parserState.getCurrentActivity(),
    //               STDOUT);
    //         stdout.setDepth(0);
    //         stdout.setGranularDepth(0);
    //      }
    //      if (toolDesc.isIncludeStdErr()) {
    //         OutputActivityPort stderr = new OutputActivityPort(parserState.getCurrentActivity(),
    //               STDERR);
    //         stderr.setDepth(0);
    //         stderr.setGranularDepth(0);
    //      }

    return description;
}

From source file:org.apache.taverna.scufl2.translator.t2flow.defaultactivities.RshellActivityParser.java

@Override
public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean,
        ParserState parserState) throws ReaderException {
    RShellConfig rshellConfig = unmarshallConfig(t2FlowParser, configBean, "xstream", RShellConfig.class);

    Configuration configuration = new Configuration();
    configuration.setParent(parserState.getCurrentProfile());

    ObjectNode json = (ObjectNode) configuration.getJson();
    configuration.setType(ACTIVITY_URI.resolve("#Config"));

    // Basic properties
    String script = rshellConfig.getScript();
    json.put("script", script);
    //      if (rshellConfig.getRVersion() != null) {
    //            json.put("rVersion", rshellConfig.getRVersion());
    //      }//from  ww w. jav  a  2s.  c  om

    // Connection
    ObjectNode connection = json.objectNode();
    json.put("connection", connection);
    RShellConnection conn = rshellConfig.getConnectionSettings();
    connection.put("hostname", conn.getHost());
    json.put("port", conn.getPort());

    // ignored - Taverna 2.3+ uses credential manager
    // connection.put("username", conn.getUsername());
    // connection.put("password", conn.getPassword());

    connection.put("keepSessionAlive", conn.isKeepSessionAlive());

    // ignoooooored - we won't support the legacy ones anymore
    // if (rshellConfig.getConnectionSettings().isNewRVersion() == null || !
    // rshellConfig.getConnectionSettings().isNewRVersion()) {
    // connection.put("legacy", true);
    // }

    // Activity ports
    Activity activity = parserState.getCurrentActivity();
    activity.getInputPorts().clear();
    activity.getOutputPorts().clear();

    for (ActivityPortDefinitionBean portBean : rshellConfig.getInputs()
            .getNetSfTavernaT2WorkflowmodelProcessorActivityConfigActivityInputPortDefinitionBean())
        parseAndAddInputPortDefinition(portBean, configuration, activity);
    for (ActivityPortDefinitionBean portBean : rshellConfig.getOutputs()
            .getNetSfTavernaT2WorkflowmodelProcessorActivityConfigActivityOutputPortDefinitionBean())
        parseAndAddOutputPortDefinition(portBean, configuration, activity);

    RShellSymanticType inputSymanticTypes = rshellConfig.getInputSymanticTypes();
    List<String> foundInputTypes = new ArrayList<>();

    ArrayNode inputPorts = json.arrayNode();
    json.put("inputTypes", inputPorts);
    for (RShellPortSymanticTypeBean symanticType : inputSymanticTypes
            .getNetSfTavernaT2ActivitiesRshellRShellPortSymanticTypeBean()) {
        ObjectNode port = json.objectNode();
        port.put("port", symanticType.getName());
        String dataType = symanticType.getSymanticType().getValue();
        String reference = symanticType.getSymanticType().getReference();
        if (reference != null) {
            Matcher matcher = strangeXpath.matcher(reference);
            if (matcher == null || !matcher.matches())
                throw new ReaderException("Unhandled xstream xpath expression: " + reference);
            String position = matcher.group(3);
            if (position == null)
                position = "1";
            dataType = foundInputTypes.get(Integer.parseInt(position) - 1);
        }

        foundInputTypes.add(dataType);
        // Even if it's null - so the index is correct

        if (dataType != null)
            port.put("dataType", dataType);
    }
    /*
     * FIXME: Avoid this repetition. Would require a fair bit of parser
     * state...
     */
    RShellSymanticType outputSymanticTypes = rshellConfig.getOutputSymanticTypes();
    List<String> foundOutputTypes = new ArrayList<>();
    ArrayNode outputPorts = json.arrayNode();
    json.put("outputTypes", outputPorts);

    for (RShellPortSymanticTypeBean symanticType : outputSymanticTypes
            .getNetSfTavernaT2ActivitiesRshellRShellPortSymanticTypeBean()) {
        ObjectNode port = json.objectNode();
        port.put("port", symanticType.getName());

        String dataType = symanticType.getSymanticType().getValue();
        String reference = symanticType.getSymanticType().getReference();
        if (reference != null) {
            /*
             * A lovely artifact of xstream 'efficiency' - Xpath
             * backpointers to previous elements. luckily we are here
             * restricted within this specific config bean.
             *
             * Example:
             * ../../net.sf.taverna.t2.activities.rshell.RShellPortSymanticTypeBean[3]/symanticType
             * ../../../inputSymanticTypes/net.sf.taverna.t2.activities.rshell.RShellPortSymanticTypeBean[2]/symanticType
             */

            Matcher matcher = strangeXpath.matcher(reference);
            if (matcher == null || !matcher.matches())
                throw new ReaderException("Unhandled xstream xpath expression: " + reference);

            boolean isInputSymantic = matcher.group(1) != null;
            String position = matcher.group(3);
            if (position == null)
                position = "1";
            if (isInputSymantic)
                dataType = foundInputTypes.get(Integer.parseInt(position) - 1);
            else
                dataType = foundOutputTypes.get(Integer.parseInt(position) - 1);
        }

        foundOutputTypes.add(dataType);
        // Even if it's null - so the index is correct

        if (dataType != null)
            port.put("dataType", dataType);
    }
    return configuration;
}

From source file:org.apache.taverna.scufl2.translator.t2flow.defaultactivities.AbstractActivityParser.java

protected ObjectNode parseAndAddOutputPortDefinition(ActivityPortDefinitionBean portBean,
        Configuration configuration, Activity activity) {
    ObjectNode configResource = (ObjectNode) configuration.getJson();
    OutputActivityPort outputPort = new OutputActivityPort();

    outputPort.setName(getPortElement(portBean, "name", String.class));
    outputPort.setParent(activity);/*  ww w . j  a v a  2 s  .com*/

    BigInteger depth = getPortElement(portBean, "depth", BigInteger.class);
    if (depth != null)
        outputPort.setDepth(depth.intValue());

    BigInteger granularDepth = getPortElement(portBean, "granularDepth", BigInteger.class);
    if (granularDepth != null)
        outputPort.setGranularDepth(granularDepth.intValue());

    ObjectNode portConfig = configResource.objectNode();
    //      PropertyResource portConfig = configResource.addPropertyAsNewResource(
    //            Scufl2Tools.PORT_DEFINITION.resolve("#outputPortDefinition"),
    //            Scufl2Tools.PORT_DEFINITION.resolve("#OutputPortDefinition"));

    @SuppressWarnings("unused")
    URI portUri = new URITools().relativeUriForBean(outputPort, configuration);
    //      portConfig.addPropertyReference(Scufl2Tools.PORT_DEFINITION.resolve("#definesOutputPort"), portUri);

    // Legacy duplication of port details for XMLSplitter activities
    portConfig.put("name", outputPort.getName());
    portConfig.put("depth", outputPort.getDepth());
    portConfig.put("granularDepth", outputPort.getDepth());

    parseMimeTypes(portBean, portConfig);
    return portConfig;
}

From source file:com.ethlo.geodata.restdocs.AbstractJacksonFieldSnippet.java

protected ObjectNode getSchema(Operation operation, final Class<?> pojo, boolean isResponse) {
    try {//from   w w  w .java 2  s .co  m
        final ObjectNode schema = (ObjectNode) generator.generateSchema(pojo, isResponse);

        final Collection<FieldDescriptor> fieldDescriptors = createFieldDescriptors(operation, pojo);

        // Add field descriptions on top of JSON schema
        fieldDescriptors.forEach(desc -> {
            final String[] pathArr = org.apache.commons.lang3.StringUtils.split(desc.getPath(), '.');
            final Iterator<String> path = Arrays.asList(pathArr).iterator();
            final ObjectNode definitionsNode = schema.get("definitions") != null
                    ? (ObjectNode) schema.get("definitions")
                    : schema.objectNode();
            handleSchema(pojo, schema, definitionsNode, desc, path);
        });

        allSchemas.put(pojo, schema);
        ((ObjectNode) schema).remove("definitions");

        return schema;
    } catch (RuntimeException exc) {
        exc.printStackTrace();
        throw exc;
    }
}

From source file:org.apache.taverna.scufl2.translator.t2flow.t23activities.XPathActivityParser.java

@Override
public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean,
        ParserState parserState) throws ReaderException {

    XPathConfig xpathConfig = unmarshallConfig(t2FlowParser, configBean, "xstream", XPathConfig.class);

    Configuration configuration = new Configuration();
    configuration.setParent(parserState.getCurrentProfile());
    parserState.setCurrentConfiguration(configuration);

    try {// w  w  w  . ja v  a2 s. c o m

        ObjectNode json = (ObjectNode) configuration.getJson();
        configuration.setType(ACTIVITY_URI.resolve("#Config"));

        String xmlDocument = xpathConfig.getXmlDocument();
        if (xmlDocument != null) {
            json.put("exampleXmlDocument", xmlDocument);
        }

        String xpathExpression = xpathConfig.getXpathExpression();
        json.put("xpathExpression", xpathExpression);

        ArrayNode namespaceMap = json.arrayNode();
        json.put("xpathNamespaceMap", namespaceMap);

        // TODO look at why the schema translation here is so wrong
        for (Entry list : xpathConfig.getXpathNamespaceMap().getEntry()) {
            String namespacePrefix = list.getContent().get(0).getValue();
            String namespaceURI = list.getContent().get(1).getValue();

            ObjectNode map = json.objectNode();
            map.put("prefix", namespacePrefix);
            map.put("uri", namespaceURI);
            namespaceMap.add(map);
        }
    } finally {
        parserState.setCurrentConfiguration(null);
    }
    return configuration;
}

From source file:com.msopentech.odatajclient.engine.data.json.JSONPropertyDeserializer.java

@Override
protected JSONProperty doDeserializeV4(JsonParser parser, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser);
    final JSONProperty property = new JSONProperty();

    try {// w w  w.j  av a  2 s  . c o  m
        final DocumentBuilder builder = ODataConstants.DOC_BUILDER_FACTORY.newDocumentBuilder();
        final Document document = builder.newDocument();

        Element content = document.createElement(ODataConstants.ELEM_PROPERTY);

        JsonNode subtree = null;
        if (tree.has(ODataConstants.JSON_VALUE)) {
            if (tree.has(v4AnnotationPrefix + ODataConstants.JSON_TYPE)
                    && StringUtils.isBlank(content.getAttribute(ODataConstants.ATTR_M_TYPE))) {

                content.setAttribute(ODataConstants.ATTR_M_TYPE,
                        tree.get(v4AnnotationPrefix + ODataConstants.JSON_TYPE).asText());
            }

            final JsonNode value = tree.get(ODataConstants.JSON_VALUE);
            if (value.isValueNode()) {
                content.appendChild(document.createTextNode(value.asText()));
            } else if (EdmSimpleType.isGeospatial(content.getAttribute(ODataConstants.ATTR_M_TYPE))) {
                subtree = tree.objectNode();
                ((ObjectNode) subtree).put(ODataConstants.JSON_VALUE, tree.get(ODataConstants.JSON_VALUE));
                if (StringUtils.isNotBlank(content.getAttribute(ODataConstants.ATTR_M_TYPE))) {
                    ((ObjectNode) subtree).put(ODataConstants.JSON_VALUE + "@" + ODataConstants.JSON_TYPE,
                            content.getAttribute(ODataConstants.ATTR_M_TYPE));
                }
            } else {
                subtree = tree.get(ODataConstants.JSON_VALUE);
            }
        } else {
            subtree = tree;
        }

        if (subtree != null) {
            DOMTreeUtilsV4.buildSubtree(content, subtree);
        }

        final List<Node> children = XMLUtils.getChildNodes(content, Node.ELEMENT_NODE);
        if (children.size() == 1) {
            final Element value = (Element) children.iterator().next();
            if (ODataConstants.JSON_VALUE.equals(XMLUtils.getSimpleName(value))) {
                if (StringUtils.isNotBlank(content.getAttribute(ODataConstants.ATTR_M_TYPE))) {
                    value.setAttribute(ODataConstants.ATTR_M_TYPE,
                            content.getAttribute(ODataConstants.ATTR_M_TYPE));
                }
                content = value;
            }
        }

        property.setContent(content);
    } catch (ParserConfigurationException e) {
        throw new JsonParseException("Cannot build property", parser.getCurrentLocation(), e);
    }

    return property;
}

From source file:org.apache.taverna.scufl2.translator.t2flow.t23activities.ExternalToolActivityParser.java

@Override
public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean,
        ParserState parserState) throws ReaderException {
    ExternalToolConfig externalToolConfig = null;
    UsecaseConfig usecaseConfig = null;/* w w  w  .  j  a v  a2  s. co  m*/

    try {
        externalToolConfig = unmarshallConfig(t2FlowParser, configBean, "xstream", ExternalToolConfig.class);
    } catch (ReaderException ex) {
        usecaseConfig = unmarshallConfig(t2FlowParser, configBean, "xstream", UsecaseConfig.class);
    }

    Configuration configuration = new Configuration();
    configuration.setParent(parserState.getCurrentProfile());
    parserState.setCurrentConfiguration(configuration);
    try {
        ObjectNode json = configuration.getJsonAsObjectNode();

        configuration.setType(ACTIVITY_URI.resolve("#Config"));

        if (usecaseConfig != null) {
            if (usecaseConfig.getRepositoryUrl() != null)
                json.put("repositoryUrl", usecaseConfig.getRepositoryUrl());
            json.put("toolId", usecaseConfig.getUsecaseid());
        } else if (externalToolConfig != null) {
            if (externalToolConfig.getRepositoryUrl() != null)
                json.put("repositoryUrl", externalToolConfig.getRepositoryUrl());
            json.put("toolId", externalToolConfig.getExternaltoolid());
            if (externalToolConfig.isEdited())
                json.put("edited", externalToolConfig.isEdited());
        }

        if (externalToolConfig != null) {
            Group group = externalToolConfig.getGroup();
            if (group != null) {
                ObjectNode invocationGroup = json.objectNode();
                json.put("invocationGroup", invocationGroup);
                invocationGroup.put("name", group.getInvocationGroupName());
                invocationGroup.put("mechanismType", group.getMechanismType());
                invocationGroup.put("mechanismName", group.getMechanismName());
                invocationGroup.put("mechanismXML", group.getMechanismXML());
            } else {
                json.put("mechanismType", externalToolConfig.getMechanismType());
                json.put("mechanismName", externalToolConfig.getMechanismName());
                json.put("mechanismXML", externalToolConfig.getMechanismXML());
            }
            //            URI mechanismTypeURI = ACTIVITY_URI.resolve("#"
            //                  + uriTools.validFilename(mechanismType));
            //            if (mappedMechanismTypes.containsKey(mechanismTypeURI)) {
            //               mechanismTypeURI = mappedMechanismTypes.get(mechanismTypeURI);
            //            }
            //            invocation.addPropertyReference(ACTIVITY_URI.resolve("#mechanismType"),
            //                  mechanismTypeURI);
            //
            //            invocation.addPropertyAsString(ACTIVITY_URI.resolve("#mechanismName"),
            //                  mechanismName);
            //            invocation.addProperty(ACTIVITY_URI.resolve("#mechanismXML"), new PropertyLiteral(
            //                  mechanismXML, PropertyLiteral.XML_LITERAL));

            // TODO: Extract SSH hostname etc. from mechanismXML
            //            parseMechanismXML(json);

            ObjectNode toolDescription = json.objectNode();
            parseToolDescription(toolDescription, externalToolConfig.getUseCaseDescription(), parserState);
            json.put("toolDescription", toolDescription);

            //            configResource.addProperty(ACTIVITY_URI.resolve("#invocationGroup"),
            //                  parseGroup(externalToolConfig.getGroup()));

        }

        return configuration;
    } finally {
        parserState.setCurrentConfiguration(null);
    }
}