Example usage for javax.xml.bind PropertyException printStackTrace

List of usage examples for javax.xml.bind PropertyException printStackTrace

Introduction

In this page you can find the example usage for javax.xml.bind PropertyException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this JAXBException and its stack trace (including the stack trace of the linkedException if it is non-null) to System.err .

Usage

From source file:org.genericprodigy.rp.heroquest.XmlMarshaller.java

/**
 * Marshals the {@link Model} object passed in to the {@code createInstance}
 * factory method into a new {@code MarshalledModel} entity object.
 *
 * @return {@link MarshalledModel} entity object with an XML representation
 * of the object state./*  w  ww.  j  a v  a2 s.  co m*/
 */
@Override
public MarshalledModel marshal() {
    MarshalledXml response = new MarshalledXml();

    String data = null;

    try {
        JAXBContext context = JAXBContext.newInstance(this.model.getClass());
        Marshaller marshaller = context.createMarshaller();
        StringWriter sw = new StringWriter();
        marshaller.marshal(this.model, sw);
        data = sw.toString();
        response.setData(data);
        log.debug("Output Xml = " + sw.toString());
    } catch (javax.xml.bind.PropertyException propEx) {
        log.error("javax.xml.bind.PropertyException caught: " + propEx.getMessage(), propEx);
        propEx.printStackTrace();
    } catch (javax.xml.bind.JAXBException jaxbEx) {
        log.error("javax.xml.bind.JAXBException caught: " + jaxbEx.getMessage(), jaxbEx);
        jaxbEx.printStackTrace();
    } catch (Exception ex) {
        log.error("Exception caught: " + ex.getMessage(), ex);
        ex.printStackTrace();
    }

    return (MarshalledModel) response;
}

From source file:org.genericprodigy.rp.heroquest.XmlMarshaller.java

/**
 * Unmarshals the {@link MarshalledModel} entity object from XML to a
 * {@link Model} object complete with existing state.
 *
 * @param data Marshalled entity representation of the object.
 * @return Unmarshalled entity object complete with state.
 *///  ww w. j a  v  a  2  s .co  m
@Override
public T unmarshal(MarshalledModel data) {

    MarshalledXml xml = (MarshalledXml) data;
    T response = null;

    try {
        JAXBContext context = JAXBContext.newInstance(this.model.getClass());
        Unmarshaller unmarshaller = context.createUnmarshaller();
        StringReader sr = new StringReader(xml.getData());
        this.model = (T) unmarshaller.unmarshal(sr);
    } catch (javax.xml.bind.PropertyException propEx) {
        log.error("javax.xml.bind.PropertyException caught: " + propEx.getMessage(), propEx);
        propEx.printStackTrace();
    } catch (javax.xml.bind.JAXBException jaxbEx) {
        log.error("javax.xml.bind.JAXBException caught: " + jaxbEx.getMessage(), jaxbEx);
        jaxbEx.printStackTrace();
    } catch (Exception ex) {
        log.error("Exception caught: " + ex.getMessage(), ex);
        ex.printStackTrace();
    }

    return this.model;

}

From source file:org.jetbrains.jet.grammar.GrammarGenerator.java

private static String generate(List<Token> tokens) throws IOException {
    StringWriter result = new StringWriter();

    Set<String> declaredSymbols = new HashSet<String>();
    Set<String> usedSymbols = new HashSet<String>();
    Multimap<String, String> usages = Multimaps.newSetMultimap(Maps.<String, Collection<String>>newHashMap(),
            new Supplier<Set<String>>() {
                @Override/*from www.j  a  va  2  s. c  om*/
                public Set<String> get() {
                    return Sets.newHashSet();
                }
            });

    Declaration lastDeclaration = null;
    for (Token advance : tokens) {
        if (advance instanceof Declaration) {
            Declaration declaration = (Declaration) advance;
            lastDeclaration = declaration;
            declaredSymbols.add(declaration.getName());
        } else if (advance instanceof Identifier) {
            Identifier identifier = (Identifier) advance;
            assert lastDeclaration != null;
            usages.put(identifier.getName(), lastDeclaration.getName());
            usedSymbols.add(identifier.getName());
        }
    }

    try {

        JAXBContext context = JAXBContext.newInstance(Annotation.class, Comment.class, Declaration.class,
                DocComment.class, Identifier.class, Other.class, StringToken.class, SymbolToken.class,
                Token.class, WhiteSpace.class, TokenList.class);
        Marshaller m = context.createMarshaller();
        TokenList list = new TokenList(tokens);
        list.updateUsages(usedSymbols, usages);
        m.marshal(list, result);

    } catch (PropertyException e) {
        e.printStackTrace();
    } catch (JAXBException e) {
        e.printStackTrace();
    }

    result.flush();
    result.close();
    return result.toString();
}

From source file:playground.meisterk.org.matsim.run.facilities.ShopsOf2005ToFacilities.java

private static void write() {

    System.out.println("Writing KML files out...");

    try {/*from  w  ww.  j av  a 2  s . c  o m*/
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(kmlObjectFactory.createKml(myKML), new FileOutputStream(kmlFilename));
    } catch (PropertyException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (JAXBException e) {
        e.printStackTrace();
    }

    KMZWriter writer;
    writer = new KMZWriter(kmlFilename);

    for (String icon : icons.values()) {
        try {
            writer.addNonKMLFile(MatsimResource.getAsInputStream(icon), icon);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    writer.writeMainKml(myKML);
    writer.close();

    System.out.println("done.");

}