Example usage for javax.xml.stream XMLStreamException printStackTrace

List of usage examples for javax.xml.stream XMLStreamException printStackTrace

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:de.bund.bfr.fskml.MetadataDocument.java

/**
 * Creates a {@link MetadataDocument} with no replacements.
 *
 * @param template FSK model metadata/*from w w  w .  ja  v a2  s .c  o  m*/
 */
public MetadataDocument(FskMetaData template) {

    // Creates SBMLDocument for the primary model
    this.doc = new SBMLDocument(3, 1);

    addNamespaces(this.doc); // Adds namespaces to the SBMLDocument

    addDocumentAnnotation(template);

    // Creates model and names it
    Model model;
    if (StringUtils.isEmpty(template.modelId)) {
        model = this.doc.createModel();
    } else {
        model = this.doc.createModel(PMFUtil.createId(template.modelId));
    }

    if (StringUtils.isNotEmpty(template.modelName)) {
        model.setName(template.modelName);
    }

    // Set model notes
    if (StringUtils.isNotEmpty(template.notes)) {
        try {
            model.setNotes(template.notes);
        } catch (XMLStreamException e) {
            e.printStackTrace();
        }
    }

    // Creates and add compartment to the model
    addCompartment(model, template.matrix, template.matrixDetails);

    // Add unit definitions here (before parameters)
    addUnitDefintions(model, template.dependentVariables, template.independentVariables);

    // Adds dependent parameters
    template.dependentVariables.forEach(v -> addDependentVariable(model, v));

    // Add independent parameters
    template.independentVariables.forEach(v -> addIndependentVariable(model, v));

    // Add rule
    if (model.getNumParameters() > 0 && StringUtils.isNotEmpty(model.getParameter(0).getId())) {
        AssignmentRule rule = new AssignmentRule(3, 1);
        // Assigns the id of the dependent parameter which happens to be the first parameter of the model
        rule.setVariable(model.getParameter(0).getId());

        String modelClass = template.subject == null ? ModelClass.UNKNOWN.fullName()
                : template.subject.fullName();
        rule.setAnnotation(new RuleAnnotation(modelClass).annotation);
        model.addRule(rule);
    }
}

From source file:de.bund.bfr.fskml.MetadataDocument.java

public MetadataDocument(FskMetaData template, Map<String, String> replacements) {
    // Creates SBMLDocument for the primary model
    this.doc = new SBMLDocument(3, 1);

    addNamespaces(this.doc); // Adds namespaces to the SBMLDocument

    addDocumentAnnotation(template);/*from  w  w w  . j  a v  a 2  s.c  o m*/

    // Creates model and names it
    Model model;
    if (StringUtils.isEmpty(template.modelId)) {
        model = this.doc.createModel();
    } else {
        model = this.doc.createModel(PMFUtil.createId(template.modelId));
    }

    if (StringUtils.isNotEmpty(template.modelName)) {
        model.setName(template.modelName);
    }

    // Sets model notes
    if (StringUtils.isNotEmpty(template.notes)) {
        try {
            model.setNotes(template.notes);
        } catch (XMLStreamException e) {
            e.printStackTrace();
        }
    }

    // Creates and adds compartment to the model
    addCompartment(model, template.matrix, template.matrixDetails);

    // TODO: Creates and adds species to the model

    // Creates and adds species to the model if:
    // - template.organism is specified
    // - template.dependentVariable.unit is specified
    // - model has a compartment
    // if (!Strings.isNullOrEmpty(template.organism) &&
    // template.dependentVariable != null
    // && !Strings.isNullOrEmpty(template.dependentVariable.unit) &&
    // model.getNumCompartments() > 0) {
    // String speciesId = PMFUtil.createId(template.organism);
    // String speciesName = template.organism;
    // String speciesUnit =
    // PMFUtil.createId(template.dependentVariable.unit);
    // PMFSpecies species =
    // SBMLFactory.createPMFSpecies(model.getCompartment(0).getId(),
    // speciesId, speciesName,
    // speciesUnit);
    // model.addSpecies(species.getSpecies());
    // }

    // Add unit definitions here (before parameters)
    addUnitDefintions(model, template.dependentVariables, template.independentVariables);

    // Adds dep parameter
    template.dependentVariables.forEach(v -> addDependentVariable(model, v));

    // Adds independent parameters
    template.independentVariables.forEach(v -> addIndependentVariable(model, v));

    // Add rule
    if (model.getNumParameters() > 0 && StringUtils.isNotEmpty(model.getParameter(0).getId())) {
        AssignmentRule rule = new AssignmentRule(3, 1);
        // Assigns the id of the dependent parameter which happens to be the
        // first parameter of the model
        rule.setVariable(model.getParameter(0).getId());

        String modelClass = template.subject == null ? ModelClass.UNKNOWN.fullName()
                : template.subject.fullName();
        rule.setAnnotation(new RuleAnnotation(modelClass).annotation);
        model.addRule(rule);
    }

    // TODO: work in progress:
    // The ExternalModelDefinition and Submodel are requisites of the SBML replacements

    // ExternalModelDefinition
    CompSBMLDocumentPlugin docPlugin = (CompSBMLDocumentPlugin) this.doc.getPlugin(CompConstants.shortLabel);
    ExternalModelDefinition emd = docPlugin.createExternalModelDefinition("model_id");
    emd.setSource("a_file.sbml");
    emd.setModelRef("model_id");

    // Submodel
    CompModelPlugin modelPlugin = (CompModelPlugin) model.getPlugin(CompConstants.shortLabel);
    Submodel submodel = modelPlugin.createSubmodel("submodel_id");
    submodel.setModelRef("model_id");

    for (Map.Entry<String, String> entry : replacements.entrySet()) {
        Parameter parameter = model.getParameter(entry.getKey());

        CompSBasePlugin plugin = (CompSBasePlugin) parameter.getPlugin(CompConstants.shortLabel);
        ReplacedBy replacedBy = plugin.createReplacedBy();
        replacedBy.setIdRef(entry.getValue());
        replacedBy.setSubmodelRef(submodel.getId());
    }
}

From source file:nl.knaw.huygens.tei.xpath.XPathUtil.java

public static Map<String, String> getNamespaceInfo(String xml) {
    Map<String, String> namespaces = Maps.newIdentityHashMap();
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    try {//from   www  .j  a v a2 s .co  m
        XMLStreamReader xreader = inputFactory.createXMLStreamReader(IOUtils.toInputStream(xml, "UTF-8"));
        while (xreader.hasNext()) {
            if (xreader.next() == XMLStreamConstants.START_ELEMENT) {
                QName qName = xreader.getName();
                if (qName != null) {
                    addNamespace(namespaces, qName.getPrefix(), qName.getNamespaceURI());
                    for (int i = 0; i < xreader.getAttributeCount(); i++) {
                        addNamespace(namespaces, xreader.getAttributePrefix(i),
                                xreader.getAttributeNamespace(i));
                    }
                }
            }
        }
    } catch (XMLStreamException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return namespaces;
}

From source file:org.apache.synapse.commons.json.StreamBuilderFormatterTest.java

public void test7() {
    // The Input XML must be such that 1) it does not have mixed content 2) no attributes have same name even they
    // belong to different namespaces.
    // mixed content is not supported. ie both Text nodes and Elements as child nodes of an element.
    // cannot have same attribute names even with different ns s. That's because, we remove all namespace declarations
    // before converting to JSON.
    try {//from  ww w. j a  va 2s .  c  om
        MessageContext message = null;
        try {
            message = Util.newMessageContext(xmlString);
        } catch (XMLStreamException e) {
            e.printStackTrace();
        }
        //System.out.println(message.getEnvelope().getBody().toString());
        OutputStream out = Util.newOutputStream();
        formatter.writeTo(message, null, out, false);
        String outStr = new String(((ByteArrayOutputStream) out).toByteArray());
        //System.out.println(outStr);
        assertTrue(jsonString.equals(outStr));
    } catch (AxisFault axisFault) {
        axisFault.printStackTrace();
        assertTrue(false);
    }
}

From source file:org.apache.synapse.config.xml.MediatorFactoryFinder.java

public OMElement getCallTemplateFromConnector(OMElement connectorElem, String libraryName) {
    String callTemplateConfig = "<call-template target=\"synapse.lang.eip.sfdc.getContact\">\n"
            + "            <with-param name=\"p1\" value=\"abc\"/>\n"
            + "            <with-param name=\"p2\" value=\"efg\"/>\n" + "        </call-template>";
    OMElement callTemplateElem = null;//from   www  . j  a  va  2 s.co  m

    try {
        callTemplateElem = AXIOMUtil.stringToOM(callTemplateConfig);

    } catch (XMLStreamException e) {
        e.printStackTrace();
    }
    return callTemplateElem;
}

From source file:org.apache.synapse.transport.passthru.TargetRequest.java

/**
 * Handles the chuking messages in Passthough context, create a temporary buffer and calculate the message
 * size before writing to the external buffer, which is required the context of handling DISABLED chunking 
 * messages// ww  w  . j a  va  2s  . co m
 * 
 * @param conn
 * @param requestMsgCtx
 * @throws IOException
 * @throws AxisFault
 */
private void processChunking(NHttpClientConnection conn, MessageContext requestMsgCtx)
        throws IOException, AxisFault {
    String disableChunking = (String) requestMsgCtx.getProperty(PassThroughConstants.DISABLE_CHUNKING);
    String forceHttp10 = (String) requestMsgCtx.getProperty(PassThroughConstants.FORCE_HTTP_1_0);
    if ("true".equals(disableChunking) || "true".equals(forceHttp10)) {
        if (requestMsgCtx.getEnvelope().getBody().getFirstElement() == null) {
            BasicHttpEntity entity = (BasicHttpEntity) ((BasicHttpEntityEnclosingRequest) request).getEntity();
            try {
                RelayUtils.buildMessage(requestMsgCtx);
                this.hasEntityBody = true;
                Pipe pipe = (Pipe) requestMsgCtx.getProperty(PassThroughConstants.PASS_THROUGH_PIPE);
                if (pipe != null) {
                    pipe.attachConsumer(conn);
                    this.connect(pipe);
                    if (Boolean.TRUE
                            .equals(requestMsgCtx.getProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED))) {
                        ByteArrayOutputStream out = new ByteArrayOutputStream();
                        MessageFormatter formatter = MessageProcessorSelector
                                .getMessageFormatter(requestMsgCtx);
                        OMOutputFormat format = PassThroughTransportUtils.getOMOutputFormat(requestMsgCtx);
                        formatter.writeTo(requestMsgCtx, format, out, false);
                        OutputStream _out = pipe.getOutputStream();
                        IOUtils.write(out.toByteArray(), _out);

                        entity.setContentLength(new Long(out.toByteArray().length));
                        entity.setChunked(false);
                    }
                }
                // pipe.setSerializationComplete(true);
            } catch (XMLStreamException e) {
                e.printStackTrace();

            }
        }

    }
}

From source file:org.deegree.services.wps.WPService.java

private void doDescribeProcess(DescribeProcessRequest request, HttpResponseBuffer response)
        throws OWSException {

    LOG.trace("doDescribeProcess invoked, request: " + request);

    // check that all requested processes exist (and resolve special value 'ALL')
    List<WPSProcess> processes = new ArrayList<WPSProcess>();
    for (CodeType identifier : request.getIdentifiers()) {
        LOG.debug("Looking up process '" + identifier + "'");
        if (ALL_PROCESSES_IDENTIFIER.equals(identifier)) {
            processes.addAll(processManager.getProcesses().values());
            break;
        }/*from w  w  w  .  j av  a 2s.c  o  m*/
        WPSProcess process = processManager.getProcess(identifier);
        if (process != null) {
            processes.add(process);
        } else {
            throw new OWSException("InvalidParameterValue: Identifier\nNo process with id " + identifier
                    + " is registered in the WPS.", OWSException.INVALID_PARAMETER_VALUE);
        }
    }

    try {
        response.setContentType("text/xml; charset=UTF-8");
        XMLStreamWriter xmlWriter = response.getXMLWriter();

        Map<ProcessDefinition, String> processDefToWSDLUrl = new HashMap<ProcessDefinition, String>();
        for (WPSProcess process : processes) {
            ProcessDefinition processDef = process.getDescription();
            CodeType processId = new CodeType(processDef.getIdentifier().getValue(),
                    processDef.getIdentifier().getCodeSpace());
            // TODO WSDL
            // if ( processIdToWSDL.containsKey( processId ) ) {
            // String wsdlURL = OGCFrontController.getHttpGetURL()
            // + "service=WPS&version=1.0.0&request=GetWPSWSDL&identifier=" + processId.getCode();
            // processDefToWSDLUrl.put( processDef, wsdlURL );
            // }
        }

        DescribeProcessResponseXMLAdapter.export100(xmlWriter, processes, processDefToWSDLUrl);
        xmlWriter.flush();
    } catch (XMLStreamException e) {
        e.printStackTrace();
        LOG.error("Internal error: " + e.getMessage());
        throw new OWSException("Error occured while creating response for DescribeProcess operation",
                NO_APPLICABLE_CODE);
    } catch (IOException e) {
        throw new OWSException("Error occured while creating response for DescribeProcess operation",
                NO_APPLICABLE_CODE);
    } catch (Exception e) {
        e.printStackTrace();
        LOG.error("Internal error: " + e.getMessage());
    }

    LOG.trace("doDescribeProcess finished");
}

From source file:org.netbeans.jbatch.modeler.spec.core.Definitions.java

public static Definitions load(ModelerFile file, String definitionId) {
    File savedFile = file.getFile();
    Definitions definition_Load = null;//w w  w .j  a  v  a 2 s  . c o m
    boolean definitionExist = false;
    XMLStreamReader xsr = null;
    try {
        if (savedFile.length() != 0) {

            XMLInputFactory xif = XMLInputFactory.newFactory();
            StreamSource xml = new StreamSource(savedFile);
            xsr = xif.createXMLStreamReader(xml);
            xsr.nextTag();
            if (definitionId == null) {
                while (xsr.hasNext() && !definitionExist) {
                    if (xsr.getEventType() == XMLStreamConstants.START_ELEMENT
                            && xsr.getLocalName().equals("definitions")
                            && xsr.getAttributeValue(null, "id") == null) {
                        definitionExist = true;
                    } else {
                        xsr.next();
                    }
                }
            } else {
                while (xsr.hasNext() && !definitionExist) {
                    if (xsr.getEventType() == XMLStreamConstants.START_ELEMENT
                            && xsr.getLocalName().equals("definitions")
                            && definitionId.equals(xsr.getAttributeValue(null, "id"))) {
                        definitionExist = true;
                    } else {
                        xsr.next();
                    }
                }
            }

        }
        JAXBContext jobContext;
        Unmarshaller jobUnmarshaller;
        //            if (jobContext == null) {
        jobContext = JAXBContext.newInstance(new Class<?>[] { ShapeDesign.class, Definitions.class });
        //            }
        //            if (jobUnmarshaller == null) {
        jobUnmarshaller = jobContext.createUnmarshaller();
        jobUnmarshaller.setEventHandler(new ValidateJAXB());
        //            }
        if (definitionExist) {
            definition_Load = jobUnmarshaller.unmarshal(xsr, Definitions.class).getValue();//new StreamSource(savedFile)
        }
        if (xsr != null) {
            xsr.close();
        }

    } catch (XMLStreamException ex) {
        Exceptions.printStackTrace(ex);
    } catch (JAXBException ex) {
        //            io.getOut().println("Exception: " + ex.toString());
        ex.printStackTrace();
        System.out.println("Document XML Not Exist");
    }
    return definition_Load;
}

From source file:org.pentaho.platform.dataaccess.client.ConnectionServiceClient.java

public DatabaseConnection convertFromConnection(IConnection connection) throws ConnectionServiceException {
    String xml = getConnectionXml(connection);
    PostMethod callMethod = new PostMethod(serviceUrl + "/convertFromConnection"); //$NON-NLS-1$

    // add the xml to the request entity
    RequestEntity requestEntity = new StringRequestEntity(xml);
    callMethod.setRequestEntity(requestEntity);
    // get the result and parse de-serialize it
    Document doc = getResultDocument(callMethod);

    try {/*w w w .j  ava 2  s  . c o  m*/
        return getResponseDatabaseConnection(doc.getRootElement());
    } catch (XMLStreamException e) {
        e.printStackTrace();
        throw new ConnectionServiceException(e);
    } catch (AxisFault e) {
        e.printStackTrace();
        throw new ConnectionServiceException(e);
    } catch (Exception e) {
        e.printStackTrace();
        throw new ConnectionServiceException(e);
    }
}