Example usage for javax.xml.stream XMLStreamException XMLStreamException

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

Introduction

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

Prototype

public XMLStreamException(String msg, Location location) 

Source Link

Document

Construct an exception with the assocated message, exception and location.

Usage

From source file:org.apache.axis2.json.gson.GsonXMLStreamWriter.java

/**
 * Writes an attribute to the output stream
 *
 * @param prefix       the prefix for this attribute
 * @param namespaceURI the uri of the prefix for this attribute
 * @param localName    the local name of the attribute
 * @param value        the value of the attribute
 * @throws IllegalStateException               if the current state does not allow Attribute writing
 * @throws javax.xml.stream.XMLStreamException if the namespace URI has not been bound to a prefix and
 *                                             javax.xml.stream.isRepairingNamespaces has not been set to true
 *//*  w  w  w.  j  a v  a2 s  .  c  o m*/

public void writeAttribute(String prefix, String namespaceURI, String localName, String value)
        throws XMLStreamException {
    if ("http://www.w3.org/2001/XMLSchema-instance".equals(namespaceURI) && "nil".equals(localName)
            && "true".equals(value)) {
        try {
            jsonWriter.nullValue();
        } catch (IOException e) {
            throw new XMLStreamException("Failed to write attribute, 'nullValue'.", e);
        }
    }
}

From source file:org.apache.olingo.client.core.serialization.AtomGeoValueDeserializer.java

private List<Point> points(final XMLEventReader reader, final StartElement start,
        final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException {

    final List<Point> result = new ArrayList<Point>();

    boolean foundEndProperty = false;
    while (reader.hasNext() && !foundEndProperty) {
        final XMLEvent event = reader.nextEvent();

        if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
            final String[] pointInfo = event.asCharacters().getData().split(" ");

            final Point point = new Point(GeoUtils.getDimension(type), srid);
            try {
                point.setX(EdmDouble.getInstance().valueOfString(pointInfo[0], null, null,
                        Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class));
                point.setY(EdmDouble.getInstance().valueOfString(pointInfo[1], null, null,
                        Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class));
            } catch (EdmPrimitiveTypeException e) {
                throw new XMLStreamException("While deserializing point coordinates as double", e);
            }// w w w  .  j a  va2  s  .  c o  m
            result.add(point);
        }

        if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
            foundEndProperty = true;
        }
    }

    // handles bad input, e.g. things like <gml:pos/>
    if (result.isEmpty()) {
        result.add(new Point(GeoUtils.getDimension(type), srid));
    }

    return result;
}

From source file:org.apache.olingo.commons.core.data.AtomGeoValueDeserializer.java

private List<Point> points(final XMLEventReader reader, final StartElement start,
        final EdmPrimitiveTypeKind type, final String crs) throws XMLStreamException {

    final List<Point> result = new ArrayList<Point>();

    boolean foundEndProperty = false;
    while (reader.hasNext() && !foundEndProperty) {
        final XMLEvent event = reader.nextEvent();

        if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
            final String[] pointInfo = event.asCharacters().getData().split(" ");

            final Point point = new Point(GeoUtils.getDimension(type), crs);
            try {
                point.setX(EdmDouble.getInstance().valueOfString(pointInfo[0], null, null,
                        Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class));
                point.setY(EdmDouble.getInstance().valueOfString(pointInfo[1], null, null,
                        Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class));
            } catch (EdmPrimitiveTypeException e) {
                throw new XMLStreamException("While deserializing point coordinates as double", e);
            }// ww  w  .j  a  v  a 2  s.  c om
            result.add(point);
        }

        if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
            foundEndProperty = true;
        }
    }

    return result;
}

From source file:org.apache.olingo.commons.core.serialization.AtomDeserializer.java

private void common(final XMLEventReader reader, final StartElement start, final AbstractODataObject object,
        final String key) throws XMLStreamException {

    boolean foundEndElement = false;
    while (reader.hasNext() && !foundEndElement) {
        final XMLEvent event = reader.nextEvent();

        if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
            try {
                object.setCommonProperty(key, event.asCharacters().getData());
            } catch (ParseException e) {
                throw new XMLStreamException("While parsing Atom entry or feed common elements", e);
            }/*from   w  w  w.j a  va  2s.com*/
        }

        if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
            foundEndElement = true;
        }
    }
}

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

public XMLStreamReader getReader() throws XMLStreamException {
    try {//from www.  j av a2  s. co  m
        inputStream.reset();
    } catch (IOException e) {
        logger.error("#getReader. Could not reuse JSON stream from JSON Data Source. Error>> "
                + e.getLocalizedMessage());
        throw new XMLStreamException("Could not reuse JSON stream from JSON Data Source.", e);
    }
    return JsonUtil.getReader(inputStream, false); // Do not add PIs to the XML output of this reader
}

From source file:org.eclipse.smila.connectivity.framework.agent.jobfile.JobFileReader.java

/**
 * Reads in and processes a JobFile.//from   w ww.ja  va2s .c  o  m
 * 
 * @param url
 *          the url of the job file
 * @throws XMLStreamException
 *           the StAX Exception
 */
public void readJobFile(final URL url) throws XMLStreamException {
    // check parameters
    if (url == null) {
        throw new IllegalArgumentException("parameter url is null");
    }

    InputStream stream = null;
    try {
        stream = getInputStream(url);
        final XMLStreamReader staxReader = Activator.getXMLInputFactory().createXMLStreamReader(stream);
        parse(staxReader, url);
    } catch (XMLStreamException e) {
        throw e;
    } catch (Exception e) {
        final String msg = "Error while loading job file " + url;
        if (_log.isErrorEnabled()) {
            _log.error(msg, e);
        }
        throw new XMLStreamException(msg, e);
    } finally {
        IOUtils.closeQuietly(stream);
    }
}

From source file:org.rhq.enterprise.server.sync.importers.MetricTemplateImporter.java

@Override
public MetricTemplate unmarshallExportedEntity(ExportReader reader) throws XMLStreamException {
    try {//from   www .ja v a2  s .c o  m
        return (MetricTemplate) unmarshaller.unmarshal(reader);
    } catch (JAXBException e) {
        throw new XMLStreamException("Failed to unmarshal metric template.", e);
    }
}

From source file:org.wso2.appserver.integration.common.utils.SqlDataSourceUtil.java

public DataHandler createArtifact(String dbsFilePath)
        throws XMLStreamException, IOException, XPathExpressionException {

    if (automationContext == null) {
        init();/*from  w w w  .j  av a  2s  .c  o m*/
    }

    Assert.assertNotNull(jdbcUrl, "Initialize jdbcUrl");
    try {
        OMElement dbsFile = AXIOMUtil.stringToOM(FileManager.readFile(dbsFilePath));
        OMElement dbsConfig = dbsFile.getFirstChildWithName(new QName("config"));
        Iterator configElement1 = dbsConfig.getChildElements();
        while (configElement1.hasNext()) {
            OMElement property = (OMElement) configElement1.next();
            String value = property.getAttributeValue(new QName("name"));
            if ("org.wso2.ws.dataservice.protocol".equals(value)) {
                property.setText(jdbcUrl);
            } else if ("org.wso2.ws.dataservice.driver".equals(value)) {
                property.setText(jdbcDriver);
            } else if ("org.wso2.ws.dataservice.user".equals(value)) {
                property.setText(databaseUser);
            } else if ("org.wso2.ws.dataservice.password".equals(value)) {
                property.setText(databasePassword);
            }
        }
        log.debug(dbsFile);
        ByteArrayDataSource dbs = new ByteArrayDataSource(dbsFile.toString().getBytes());
        return new DataHandler(dbs);
    } catch (XMLStreamException e) {
        log.error("XMLStreamException when Reading Service File", e);
        throw new XMLStreamException("XMLStreamException when Reading Service File", e);
    } catch (IOException e) {
        log.error("IOException when Reading Service File", e);
        throw new IOException("IOException  when Reading Service File", e);
    }
}

From source file:org.wso2.carbon.appmgt.usage.client.APIUsageStatisticsClient.java

private OMElement queryForCacheHitCount(String fromDate, String toDate, Integer limit)
        throws APIMgtUsageQueryServiceClientException, SQLException, XMLStreamException {
    if (dataSource == null) {
        throw new APIMgtUsageQueryServiceClientException("BAM data source hasn't been initialized. Ensure "
                + "that the data source is properly configured in the APIUsageTracker configuration.");
    }/*from  w w  w .  j ava  2s . c om*/

    int resultsLimit = APIUsageStatisticsClientConstants.DEFAULT_RESULTS_LIMIT;
    if (limit != null) {
        resultsLimit = limit.intValue();
    }

    Connection connection = null;
    Statement statement = null;
    ResultSet rs = null;
    try {
        connection = dataSource.getConnection();
        statement = connection.createStatement();
        String query;
        String oracleQuery;
        if (fromDate != null && toDate != null) {
            query = "SELECT API,version, CACHEHIT,FULLREQUESTPATH  , sum(TOTAL_REQUEST_COUNT) AS TOTAL_REQUEST_COUNT,TIME "
                    + "FROM CACHE_REQUEST_SUMMARY WHERE TIME BETWEEN " + "\'" + fromDate + "\' AND \'" + toDate
                    + "\'" + " GROUP BY CACHEHIT,TIME,API,version,FULLREQUESTPATH ORDER BY time,CACHEHIT DESC";

            oracleQuery = "SELECT API,version, CACHEHIT,FULLREQUESTPATH  , sum(TOTAL_REQUEST_COUNT) AS TOTAL_REQUEST_COUNT,TIME  "
                    + "FROM CACHE_REQUEST_SUMMARY WHERE TIME BETWEEN" + "\'" + fromDate + "\' AND \'" + toDate
                    + "\'" + " AND ROWNUM <= " + resultsLimit
                    + "  GROUP BY CACHEHIT,TIME,API,version,FULLREQUESTPATH ORDER BY time,CACHEHIT DESC";
        } else {
            query = "SELECT API,version, CACHEHIT,FULLREQUESTPATH  , sum(TOTAL_REQUEST_COUNT) AS TOTAL_REQUEST_COUNT,TIME"
                    + "FROM CACHE_REQUEST_SUMMARY GROUP BY CACHEHIT,TIME,API,version,FULLREQUESTPATH ORDER BY time ,CACHEHIT DESC";

            oracleQuery = "SELECT API,version, CACHEHIT,FULLREQUESTPATH  , sum(TOTAL_REQUEST_COUNT) AS TOTAL_REQUEST_COUNT,TIME "
                    + "\"FROM CACHE_REQUEST_SUMMARY WHERE ROWNUM <= " + resultsLimit
                    + " GROUP BY CACHEHIT,TIME,API,version,FULLREQUESTPATH ORDER BY time,CACHEHIT DESC";

        }
        if ((connection.getMetaData().getDriverName()).contains("Oracle")) {
            query = oracleQuery;
        }
        rs = statement.executeQuery(query);
        StringBuilder returnStringBuilder = new StringBuilder("<omElement><rows>");
        int columnCount = rs.getMetaData().getColumnCount();
        while (rs.next()) {
            returnStringBuilder.append("<row>");
            for (int i = 1; i <= columnCount; i++) {
                String columnName = rs.getMetaData().getColumnName(i);
                String columnValue = rs.getString(columnName);
                returnStringBuilder.append("<" + columnName.toLowerCase() + ">" + columnValue + "</"
                        + columnName.toLowerCase() + ">");
            }
            returnStringBuilder.append("</row>");
        }
        returnStringBuilder.append("</rows></omElement>");
        String returnString = returnStringBuilder.toString();
        return AXIOMUtil.stringToOM(returnString);

    } catch (SQLException e) {
        throw new SQLException("Error when executing the SQL", e);
    } catch (XMLStreamException e) {
        throw new XMLStreamException("Error while reading the xml stream", e);
    } finally {
        APIMgtDBUtil.closeAllConnections(null, connection, rs);
    }
}

From source file:org.wso2.carbon.core.persistence.PersistenceUtils.java

public static OMElement getResourceDocumentElement(File resourceFile) throws XMLStreamException, IOException {
    OMElement resourceElement;/*  w w w  . ja v a 2s  .c  o  m*/
    FileInputStream fis = null;
    XMLStreamReader reader = null;

    try {
        fis = FileUtils.openInputStream(resourceFile);
        reader = xif.createXMLStreamReader(fis);

        StAXOMBuilder builder = new StAXOMBuilder(reader);
        resourceElement = builder.getDocumentElement();
        resourceElement.detach();
    } catch (XMLStreamException e) {
        throw new XMLStreamException(e.getMessage(), e);
    } catch (IOException e) {
        throw new IOException(e.getMessage(), e);
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
        try {
            if (reader != null) {
                reader.close();
            }
        } catch (XMLStreamException e) {
            log.error(e.getMessage(), e);
        }

    }
    return resourceElement;
}