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:Main.java

public static String toXml(Object object) {
    final StringWriter out = new StringWriter();
    JAXBContext context = null;//  w  w w.jav  a 2  s  . co m
    try {
        context = JAXBContext.newInstance(object.getClass());
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(object, new StreamResult(out));
    } catch (PropertyException e) {
        e.printStackTrace();
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    return out.toString();
}

From source file:Main.java

public static <T> void marshal(Object jaxbElement, Class<T> jaxbFactory, OutputStream out)
        throws JAXBException {
    if (!(jaxbElement instanceof JAXBElement<?>)) {
        throw new JAXBException("Must be a instance of JAXBElement<?>");
    }/* ww  w.java2 s .c o m*/
    try {
        JAXBContext jc = JAXBContext.newInstance(jaxbFactory);
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(jaxbElement, out);

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

From source file:Main.java

public static <T> Document marshal(Object jaxbElement, Class<T> jaxbFactory) throws JAXBException {
    if (!(jaxbElement instanceof JAXBElement<?>)) {
        throw new JAXBException("Must be a instance of JAXBElement<?>");
    }//from  w  ww.  j  a va 2  s.c  o m
    Document doc = null;
    try {
        JAXBContext jc = JAXBContext.newInstance(jaxbFactory);
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        doc = builder.newDocument();
        marshaller.marshal(jaxbElement, doc);

    } catch (PropertyException e) {
        e.printStackTrace();
    } catch (JAXBException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
    return doc;
}

From source file:com.aionemu.packetsamurai.utils.collector.data.npcskills.NpcSkillsTool.java

public static void save() {
    ObjectFactory objFactory = new ObjectFactory();
    NpcSkillTemplates collection = objFactory.createNpcSkillTemplates();
    List<NpcSkillList> templateList = collection.getNpcskills();
    templateList.addAll(skillsByNpcId.values());
    Collections.sort(templateList);

    NpcSkillTemplate total = new NpcSkillTemplate();
    total.setSkillid(0);//w  w w  .j a va  2 s .c  o  m

    List<NpcSkillList> toRemove = new ArrayList<NpcSkillList>();

    for (NpcSkillList skillList : templateList) {
        HashMap<IntRange, Integer> useCounts = new HashMap<IntRange, Integer>();
        HashMap<NpcSkillTemplate, Integer> skillCounts = new HashMap<NpcSkillTemplate, Integer>();
        NpcSkillTemplate totalAttacks = null;
        int index = 0;

        if (skillList.getNpcskill().contains(total)) {
            totalAttacks = skillList.getNpcskill().get(index);
            index = skillList.getNpcskill().indexOf(total);
            skillList.getNpcskill().remove(index);
        }

        int useTotal = 0;
        int skillUseTotal = 0;
        for (NpcSkillTemplate template : skillList.getNpcskill())
            skillUseTotal += template.getStats().useCount;

        if (totalAttacks != null) {
            useTotal = totalAttacks.getStats().useCount;
            if (skillUseTotal > useTotal)
                useTotal = skillUseTotal;
        } else {
            useTotal = skillUseTotal;
        }

        if (skillList.getNpcskill().size() == 0) {
            toRemove.add(skillList);
            continue;
        } else if (useTotal == 0) {
            // old data from XML
            continue;
        }

        for (NpcSkillTemplate template : skillList.getNpcskill()) {
            if (useTotal < MAX_HITS_PER_NPC) {
                if (template.getStats().maxHp > 90)
                    template.setMaxhp(100);
                else if (template.getMaxhp() == null || template.getMaxhp() < template.getStats().maxHp)
                    template.setMaxhp(template.getStats().maxHp);
                if (template.getStats().minHp < 10)
                    template.setMinhp(0);
                else if (template.getMinhp() == null || template.getMinhp() > template.getStats().minHp)
                    template.setMinhp(template.getStats().minHp);
            } else {
                IntRange hpRange = new IntRange(template.getStats().minHp, template.getStats().maxHp);
                if (useCounts.containsKey(hpRange)) {
                    int oldCounts = useCounts.get(hpRange);
                    useCounts.put(hpRange, oldCounts + template.getStats().useCount);
                } else
                    useCounts.put(hpRange, template.getStats().useCount);
                skillCounts.put(template, template.getStats().useCount);
            }

            if (useTotal >= MAX_HITS_PER_NPC)
                template.setProbability(Math.round((float) template.getStats().useCount * 100 / useTotal));
            else {
                template.setProbability(25);
            }
        }
    }

    templateList.removeAll(toRemove);

    try {
        JAXBContext jaxbContext = JAXBContext
                .newInstance("com.aionemu.packetsamurai.utils.collector.data.npcskills");
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(collection, new FileOutputStream("data/npc_skills/npc_skills.xml"));
    } catch (PropertyException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    PacketSamurai.getUserInterface().log("Skills [Npcs] - Saved : " + templateList.size() + " Npc Skills!");
}

From source file:com.athena.peacock.controller.common.component.RHEVMRestTemplate.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private static String marshal(Object obj, String rootElementName) {
    StringWriter sw = new StringWriter();
    try {/*ww  w.  j a va2 s .  c  o m*/
        JAXBContext jaxbCtx = JAXBContext.newInstance(obj.getClass().getPackage().getName());
        Marshaller marshaller = jaxbCtx.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(new JAXBElement(new QName(rootElementName), obj.getClass(), obj), sw);
        sw.close();

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

    return sw.toString();
}

From source file:eu.openminted.toolkit.elsevier.retriever.JaxbMarshalingTest.java

@Test
public void shouldSerialise() {
    Marshaller marshaller = null;
    try {/*from  w  ww . j a va2s  . c o m*/
        marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        //            marshaller.setProperty("com.sun.xml.bind.xmlDeclaration", Boolean.FALSE);
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);

        Writer writer = new StringWriter();
        marshaller.marshal(testObject, writer);

        String serialised = writer.toString();
        //            serialised.replaceAll("<\\?xml version=\"1.0\" encoding=\"UTF\\-8\" standalone=\"yes\"\\?>", "");
        String testXmlAsString = FileUtils.readFileToString(new File("src/test/resources/S0140673616313228"),
                "UTF-8");

        System.out.println("serialised test object :\n" + serialised);
        System.out.println("test xml :\n" + testXmlAsString);

        //            Assert.assertEquals(asString, testXmlAsString);
    } catch (PropertyException ex) {
        ex.printStackTrace();
    } catch (JAXBException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:org.drools.semantics.lang.dl.DL_9_CompilationTest.java

private void checkJaxbRefresh(Object obj, ClassLoader urlKL) {
    try {/*  w  w w. ja  v  a 2  s .c o  m*/
        JAXBContext jaxbContext;
        jaxbContext = JAXBContext.newInstance(obj.getClass().getPackage().getName(), urlKL);
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        StringWriter sw = new StringWriter();
        marshaller.marshal(obj, sw);

        System.out.println(sw.toString());

        jaxbContext = JAXBContext.newInstance(obj.getClass().getPackage().getName(), urlKL);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        Marshaller marshaller2 = jaxbContext.createMarshaller();
        marshaller2.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller2.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        Object clone = unmarshaller.unmarshal(new StringReader(sw.toString()));

        StringWriter sw2 = new StringWriter();
        marshaller2.marshal(clone, sw2);
        System.err.println(sw2.toString());

        assertEquals(sw.toString(), sw2.toString());
    } catch (PropertyException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (JAXBException e) {
        fail(e.getMessage());
    }
}

From source file:org.efaps.twoplan.test.ProjectTest.java

@Test
public void Marschal() {

    try {//  www .j  a v a2 s.c om
        final Project project = new Project();
        project.setName("TestName");
        project.setContext("manual");
        project.setUuid("_-R1qgN9eEeGFYMDgrVHNxA");
        project.setStartDate(new DateTime());
        project.setFinishDate(new DateTime().plusMonths(1));

        final Calendar cal = new Calendar();
        cal.setContext("manual");
        cal.setUuid("__E2b0N9eEeGFYMDgrVHNxA");
        project.setCalendar(cal);

        final Maps map1 = new Maps();
        map1.setType("net.intime.crud.xml.map.path");

        final Entries entry = new Entries();
        entry.setKey("path");
        entry.setValue("demo");
        map1.getEntries().add(entry);
        project.getMaps().add(map1);

        final Maps map2 = new Maps();
        map2.setType("manual");

        final Entries entry2 = new Entries();
        entry2.setKey("net.intime.product.mapentry.standardWorkPackageType");
        entry2.setValue("2");
        map2.getEntries().add(entry2);
        project.getMaps().add(map2);

        final WorkPackage workPackage = new WorkPackage();
        workPackage.setName("WorkPackDemo1");
        workPackage.setContext("manual");
        workPackage.setUuid("_C0H6MN9wEeGFYMDgrVHNxA");
        workPackage.setDescription("hier ist der Text");
        workPackage.setType("manual");
        workPackage.setStartDate(new DateTime());
        workPackage.setFinishDate(new DateTime().plusWeeks(1));
        project.getWorkPackages().add(workPackage);

        final WorkPackage workPackage2 = new WorkPackage();
        workPackage2.setName("WorkPackDemo2");
        workPackage2.setContext("manual");
        workPackage2.setUuid("_C0H6MN9wE123YMDgrVHNxA");
        workPackage2.setDescription("hier ist der Text  nochmal");
        workPackage2.setType("manual");
        workPackage2.setStartDate(new DateTime().plusDays(2));
        workPackage2.setFinishDate(new DateTime().plusWeeks(2));
        project.getWorkPackages().add(workPackage2);

        final JAXBContext jc = JAXBContext.newInstance(AbstractObject.class, Calendar.class, Entries.class,
                Maps.class, Project.class, WorkPackage.class, DateTime.class);
        final Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(project, System.out);
    } catch (final PropertyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (final JAXBException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.genericprodigy.rp.heroquest.classes.ClassMarshaller.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./*from w  w  w  .j av  a  2  s  .c o m*/
 */
public MarshalledModel marshal() {

    MarshalledXml xml = 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();
        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();
    }

    xml.setData(data);
    return xml;
}

From source file:org.genericprodigy.rp.heroquest.classes.ClassMarshaller.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 .ja  va 2s  . c om
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;

}