Example usage for javax.xml.bind JAXBException getLocalizedMessage

List of usage examples for javax.xml.bind JAXBException getLocalizedMessage

Introduction

In this page you can find the example usage for javax.xml.bind JAXBException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.eclipse.winery.topologymodeler.addons.topologycompleter.helper.JAXBHelper.java

/**
 * Converts any object of the TOSCA data model to a JaxBObject.
 *
 * @param xmlString/* w  ww. jav a  2  s. c o m*/
 *            the {@link Definitions} object to be converted
 *
 * @return the unmarshalled {@link Definitions} object
 */
public static Definitions getXasJaxBObject(String xmlString) {
    try {
        StringReader reader = new StringReader(xmlString);
        Definitions jaxBDefinitions = (Definitions) createUnmarshaller().unmarshal(reader);

        return jaxBDefinitions;

    } catch (JAXBException e) {
        logger.error(e.getLocalizedMessage());
    }
    return null;

}

From source file:org.eclipse.winery.topologymodeler.addons.topologycompleter.helper.JAXBHelper.java

/**
 * Turns XML Strings into {@link TEntityTemplate} objects using JaxB.
 *
 * @param xmlString/*from   w  w w.  jav a 2s .co m*/
 *            the XMLString to be parsed
 * @return the parsed XMLString as {@link TEntityTemplate}
 */
public static List<TEntityTemplate> getEntityTemplatesAsJaxBObject(String xmlString) {
    try {
        StringReader reader = new StringReader(xmlString);

        Definitions jaxBDefinitions = (Definitions) createUnmarshaller().unmarshal(reader);
        TServiceTemplate serviceTemplate = (TServiceTemplate) jaxBDefinitions
                .getServiceTemplateOrNodeTypeOrNodeTypeImplementation().get(0);

        return serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate();

    } catch (JAXBException e) {
        logger.error(e.getLocalizedMessage());
    }
    return null;

}

From source file:org.eclipse.winery.topologymodeler.addons.topologycompleter.helper.JAXBHelper.java

/**
 * Marshalls a JAXB object of the TOSCA model to an XML string.
 *
 * @param clazz//from  w  ww  .j a va2s. c  om
 *           the class of the object
 * @param obj
 *           the object to be marshalled
 *
 * @return
 */
public static String getXMLAsString(@SuppressWarnings("rawtypes") Class clazz, Object obj) {
    try {
        @SuppressWarnings("rawtypes")
        JAXBElement rootElement = Util.getJAXBElement(clazz, obj);
        JAXBContext context = JAXBContext.newInstance(TDefinitions.class);
        Marshaller m;

        m = context.createMarshaller();

        StringWriter w = new StringWriter();
        m.marshal(rootElement, w);
        String res = w.toString();

        return res;
    } catch (JAXBException e) {
        logger.error(e.getLocalizedMessage());
    }
    return null;
}

From source file:org.eclipse.winery.topologymodeler.addons.topologycompleter.helper.JAXBHelper.java

/**
 * This method returns a {@link TTopologyTemplate} given as XML string as JaxBObject.
 *
 * @param xmlString/*from   w ww.j  a  v  a  2s. c  o  m*/
 *            the {@link TTopologyTemplate} to be unmarshalled
 *
 * @return the unmarshalled {@link TTopologyTemplate}
 */
public static TTopologyTemplate getTopologyAsJaxBObject(String xmlString) {
    try {

        logger.info("Getting Definitions Document...");

        StringReader reader = new StringReader(xmlString);

        // unmarshall the XML string
        Definitions jaxBDefinitions = (Definitions) createUnmarshaller().unmarshal(reader);
        TServiceTemplate serviceTemplate = (TServiceTemplate) jaxBDefinitions
                .getServiceTemplateOrNodeTypeOrNodeTypeImplementation().get(0);

        logger.info("Unmarshalling successful! ");

        return serviceTemplate.getTopologyTemplate();

    } catch (JAXBException e) {
        logger.error(e.getLocalizedMessage());
    }
    return null;
}

From source file:org.eclipse.winery.topologymodeler.addons.topologycompleter.helper.JAXBHelper.java

/**
 * This method returns {@link TRelationshipTemplate}s as a JaxBObject.
 *
 * @param xmlString/*from   w  ww.  j  a v  a  2s. c  o m*/
 *            the {@link TRelationshipTemplate} to be unmarshalled
 *
 * @return the unmarshalled {@link TRelationshipTemplate}
 */
public static List<TRelationshipTemplate> getRelationshipTemplatesAsJaxBObject(String xmlString) {
    try {
        StringReader reader = new StringReader(xmlString);

        // unmarshall
        Definitions jaxBDefinitions = (Definitions) createUnmarshaller().unmarshal(reader);
        TServiceTemplate serviceTemplate = (TServiceTemplate) jaxBDefinitions
                .getServiceTemplateOrNodeTypeOrNodeTypeImplementation().get(0);

        List<TRelationshipTemplate> foundRTs = new ArrayList<>();
        for (TEntityTemplate entity : serviceTemplate.getTopologyTemplate()
                .getNodeTemplateOrRelationshipTemplate()) {
            if (entity instanceof TRelationshipTemplate) {
                foundRTs.add((TRelationshipTemplate) entity);
            }
        }

        return foundRTs;

    } catch (JAXBException e) {
        logger.error(e.getLocalizedMessage());
    }
    return null;

}

From source file:com.jaspersoft.jasperserver.rest.services.RESTJobSummary.java

private String generateSummeryReport(JobSummary[] summaries) throws ServiceException {
    try {/*ww  w. j a va2 s . co  m*/
        StringWriter sw = new StringWriter();

        sw.append("<jobs>");

        for (int i = 0; i < summaries.length; i++) {
            restUtils.getMarshaller(JobSummary.class).marshal(summaries[i], sw);
            if (log.isDebugEnabled()) {
                log.debug("finished marshaling job: " + summaries[i].getId());
            }
        }
        sw.append("</jobs>");
        return sw.toString();
    } catch (JAXBException e) {
        throw new ServiceException(e.getLocalizedMessage());
    }
}

From source file:com.jaspersoft.jasperserver.rest.services.RESTRole.java

private String generateSummeryReport(WSRole[] roles) throws ServiceException {
    try {/*from w  ww  .  ja v  a2  s .  c o m*/
        StringWriter sw = new StringWriter();

        sw.append("<roles>");
        for (int i = 0; i < roles.length; i++) {
            restUtils.getMarshaller(WSUser.class, WSRole.class).marshal(roles[i], sw);
            if (log.isDebugEnabled()) {
                log.debug("finished marshaling role: " + roles[i].getTenantId());
            }
        }

        sw.append("</roles>");
        return sw.toString();
    } catch (JAXBException e) {
        throw new ServiceException(e.getLocalizedMessage());
    }
}

From source file:com.jaspersoft.jasperserver.rest.services.RESTUser.java

private String generateSummeryReport(WSUser[] users) throws ServiceException {
    try {//  w w w .j  ava  2  s .c  o m
        StringWriter sw = new StringWriter();

        sw.append("<users>");

        for (int i = 0; i < users.length; i++) {
            // user password shouldn't be in a response
            users[i].setPassword(null);
            restUtils.getMarshaller(WSUser.class, WSRole.class).marshal(users[i], sw);
            if (log.isDebugEnabled()) {
                log.debug("finished marshaling user: " + users[i].getTenantId());
            }
        }
        sw.append("</users>");
        return sw.toString();
    } catch (JAXBException e) {
        throw new ServiceException(e.getLocalizedMessage());
    }
}

From source file:com.netthreads.mavenize.Pommel.java

/**
 * Load mappings.//from w w  w .jav  a  2  s. c om
 *
 * @param name
 *            The resource file name.
 * @throws Exception
 */
public List<Mapping> loadDependencyMappings(String path) throws PommelException {
    logger.debug("Load mapping definitions..");

    List<Mapping> results = null;

    try {
        InputStream inputStream = null;

        // Try to load as a file
        inputStream = new FileInputStream(path);

        if (inputStream != null) {
            JAXBContext jaxbContext = JAXBContext.newInstance(Mappings.class);
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            Mappings mappings = ((Mappings) unmarshaller.unmarshal(inputStream));

            results = mappings.getMapping();
        } else {
            throw new PommelException("Can't find mapping file.");
        }
    } catch (JAXBException e) {
        throw new PommelException(e.getLocalizedMessage());
    } catch (FileNotFoundException e) {
        throw new PommelException(e.getLocalizedMessage());
    }

    return results;

}

From source file:uk.ac.lkl.cram.ui.ModuleFrame.java

private void saveModule() {
    try {/*from   w w  w.  j  a v  a  2  s . com*/
        //Create a marshaller to marshall the module
        ModuleMarshaller marshaller = new ModuleMarshaller(moduleFile);
        //Marshall the module
        marshaller.marshallModule(module);
        discardEdits();
    } catch (JAXBException ioe) {
        LOGGER.log(Level.SEVERE, "Failed to save file", ioe);
        JOptionPane.showMessageDialog(this, ioe.getLocalizedMessage(), "Unable to save module",
                JOptionPane.ERROR_MESSAGE);
    }
}