Java 类javax.xml.bind.DataBindingException 实例源码

项目:proarc    文件:ModsUtils.java   
public static ModsDefinition unmarshalModsType(Source source) {
    try {
        Object unmarshaled = defaultUnmarshaller().unmarshal(source);
        if (unmarshaled instanceof JAXBElement) {
            unmarshaled = ((JAXBElement) unmarshaled).getValue();
        }
        ModsDefinition mods;
        if (unmarshaled instanceof ModsCollectionDefinition) {
            ModsCollectionDefinition mc = (ModsCollectionDefinition) unmarshaled;
            mods = mc.getMods().get(0);
        } else if (unmarshaled instanceof ModsDefinition) {
            mods = (ModsDefinition) unmarshaled;
        } else {
            throw new IllegalStateException(String.valueOf(unmarshaled));
        }
        return mods;
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:proarc    文件:NdkMetadataHandler.java   
@Override
public void setMetadataAsXml(DescriptionMetadata<String> xmlData, String message) throws DigitalObjectException {
    ModsDefinition mods;
    String modelId = handler.relations().getModel();
    if (xmlData.getData() != null) {
        ValidationErrorHandler errHandler = new ValidationErrorHandler();
        try {
            Validator validator = ModsUtils.getSchema().newValidator();
            validator.setErrorHandler(errHandler);
            validator.validate(new StreamSource(new StringReader(xmlData.getData())));
            checkValidation(errHandler, xmlData);
            mods = ModsUtils.unmarshalModsType(new StreamSource(new StringReader(xmlData.getData())));
        } catch (DataBindingException | SAXException | IOException ex) {
            checkValidation(errHandler, xmlData);
            throw new DigitalObjectValidationException(xmlData.getPid(),
                        xmlData.getBatchId(), ModsStreamEditor.DATASTREAM_ID, null, ex)
                    .addValidation("mods", ex.getMessage());
        }
    } else {
        mods = createDefault(modelId);
    }
    write(modelId, mods, xmlData, message);
}
项目:glyphpicker    文件:MemorizedCharactersLoader.java   
/**
 * Saves the memorized tab.
 *
 * @param glyphDefinitions the glyph definitions
 */
public void save(GlyphDefinitions glyphDefinitions) {
    File path = new File(pathName);
    glyphDefinitions.setVersion(properties.getProperty("config.version"));
    Boolean pathExists = path.exists() || path.mkdir();
    if (pathExists) {
        File file = new File(path, fileName);
        LOGGER.info("Storing memorized characters table.");
        try {
            JAXB.marshal(glyphDefinitions, file);
        } catch (DataBindingException e) {
            LOGGER.error("Error storing config.", e);
        }
    } else {
        JOptionPane.showMessageDialog(
                null,
                String.format(
                        i18n.getString(this.getClass().getSimpleName()
                                + ".couldNotCreateFolder"), pathName),
                i18n.getString(this.getClass().getSimpleName()
                        + ".storeError"), JOptionPane.ERROR_MESSAGE);
    }
}
项目:glyphpicker    文件:MemorizedCharactersLoader.java   
/**
 * Loads the memorized tab.
 *
 * @return the glyph definitions
 */
public GlyphDefinitions load() {
    File file = new File(pathName + "/" + fileName);
    GlyphDefinitions glyphDefinitions = null;

    if (file.exists()) {
        try {
            glyphDefinitions = JAXB.unmarshal(file, GlyphDefinitions.class);
        } catch (DataBindingException e) {
            LOGGER.error("Error unmarshalling user data.", e);
        }
    }

    if (glyphDefinitions == null) {
        glyphDefinitions = new GlyphDefinitions();
    }
    return glyphDefinitions;
}
项目:xmlunit    文件:JaxbBuilder.java   
@Override
public Source build() {
    try {
        if (marshaller == null) {
            createDefaultMarshaller();
        }

        final Object jaxbObject = getPreparedJaxbObject();
        final JAXBSource jaxbSource = new JAXBSource(marshaller, jaxbObject);
        // the fake InputSource cannot be used (the Convert.java
        // will create a working one if it is null)
        jaxbSource.setInputSource(null);
        return jaxbSource;
    } catch (final JAXBException e) {
        throw new DataBindingException(e);
    }
}
项目:super-csv-annotation    文件:GeneralProcessorBuilderTest.java   
@Override
        public String print(final SampleObject object) {

            try(StringWriter writer = new StringWriter()) {
                Marshaller marshaller = context.createMarshaller();
                marshaller.setSchema(schema);
                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

                marshaller.marshal(object, writer);

//                JAXB.marshal(object, writer);
                writer.flush();
                String text = writer.toString();
                return text;

            } catch(IOException | JAXBException | DataBindingException e) {
                throw new TextPrintException(object, e);
            }
        }
项目:proarc    文件:ResolverXmlUtils.java   
public static String toString(Import imp) {
    StringWriter dump = new StringWriter();
    try {
        defaultRegistrationContext().createMarshaller().marshal(imp, dump);
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
    return dump.toString();
}
项目:proarc    文件:NsesssUtils.java   
public static void marshal(Result target, Object object, boolean indent) {
    try {
        Marshaller m = defaultMarshaller(indent);
        m.marshal(object, target);
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:proarc    文件:NsesssUtils.java   
public static <T> T unmarshal(Source source, Class<T> type) {
    try {
        JAXBElement<T> item = defaultUnmarshaller().unmarshal(source, type);
        return item.getValue();
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:proarc    文件:MixUtils.java   
public static void marshal(Result target, Object mixElement, boolean indent) {
    try {
        Marshaller m = defaultMarshaller(indent);
        m.marshal(mixElement, target);
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:proarc    文件:MixUtils.java   
public static <T> T unmarshal(Source source, Class<T> type) {
    try {
        JAXBElement<T> item = defaultUnmarshaller().unmarshal(source, type);
        return item.getValue();
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:proarc    文件:PremisUtils.java   
public static void marshal(Result target, Object mixElement, boolean indent) {
    try {
        Marshaller m = defaultMarshaller(indent);
        m.marshal(mixElement, target);
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:proarc    文件:PremisUtils.java   
public static <T> T unmarshal(Source source, Class<T> type) {
    try {
        JAXBElement<T> item = defaultUnmarshaller().unmarshal(source, type);
        return item.getValue();
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:proarc    文件:Relations.java   
public static void marshal(Result target, Rdf rdf, boolean indent) {
    try {
        Marshaller m = defaultMarshaller(indent);
        m.marshal(rdf, target);
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:proarc    文件:Relations.java   
public static <T> T unmarshal(Source source, Class<T> type) {
    try {
        JAXBElement<T> item = defaultUnmarshaller().unmarshal(source, type);
        return item.getValue();
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:proarc    文件:FoxmlUtils.java   
public static void marshal(Result target, DigitalObject dobj, boolean indent) {
    try {
        Marshaller m = defaultMarshaller(indent);
        m.marshal(dobj, target);
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:proarc    文件:FoxmlUtils.java   
public static <T> T unmarshal(Source source, Class<T> type) {
    try {
        JAXBElement<T> item = defaultUnmarshaller().unmarshal(source, type);
        return item.getValue();
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:proarc    文件:DcUtils.java   
public static void marshal(Result target, OaiDcType oaidc, boolean indent) {
    try {
        Marshaller m = defaultMarshaller(indent);
        m.marshal(new ObjectFactory().createDc(oaidc), target);
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:proarc    文件:DcUtils.java   
public static <T> T unmarshal(Source source, Class<T> type) {
    try {
        JAXBElement<T> item = defaultUnmarshaller().unmarshal(source, type);
        return item.getValue();
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:proarc    文件:ModsUtils.java   
/**
 * @see cz.cas.lib.proarc.mods.package-info.java contains name space prefix mapping.
 */
public static void marshal(Result target, ModsDefinition mods, boolean indent) {
    try {
        Marshaller m = defaultMarshaller(indent);
        m.marshal(new ObjectFactory().createMods(mods), target);
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:proarc    文件:ModsUtils.java   
public static void marshal(Result target, Object modsElement, boolean indent) {
    try {
        Marshaller m = defaultMarshaller(indent);
        m.marshal(modsElement, target);
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:proarc    文件:ModsUtils.java   
public static <T> T unmarshal(Source source, Class<T> type) {
    try {
        JAXBElement<T> item = defaultUnmarshaller().unmarshal(source, type);
        return item.getValue();
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
项目:Hotel-Reservation-Tool    文件:GuestDataUpdateReceiver.java   
@Override
public void onMessage(Message message) {
    LOGGER.info(() -> "Received message " + message);

    try {
        GuestModel guest = JAXB.unmarshal(new StringReader(message.getBody(String.class)), GuestModel.class);
        LOGGER.info(() -> "Received " + guest);

        guestModelRepository.storeGuestModel(guest);
    } catch (DataBindingException | JMSException e) {
        LOGGER.log(SEVERE, "Cannot handle message " + message, e);
    }
}
项目:glyphpicker    文件:ConfigLoader.java   
/**
 * Saves the config.
 */
public void save() {
    File path = new File(pathName);
    if (path.exists() || path.mkdir()) {
        File file = new File(path, fileName);
        LOGGER.info("Storing config.");
        try {
            JAXB.marshal(config, file);
        } catch (DataBindingException e) {
            LOGGER.error("Error storing config.", e);
        }
    } else {
        LOGGER.error("Could not create folder " + pathName);
    }
}
项目:xlsmapper    文件:XmlIO.java   
/**
 * XMLを読み込み、{@link XmlInfo}として取得する。
 * @param in
 * @return
 * @throws XmlOperateException XMLの読み込みに失敗した場合。
 * @throws IllegalArgumentException in is null.
 */
public static XmlInfo load(final InputStream in) throws XmlOperateException {
    ArgUtils.notNull(in, "in");

    final XmlInfo xmlInfo;

    try {
        xmlInfo = JAXB.unmarshal(in, XmlInfo.class);
    } catch (DataBindingException e) {
        throw new XmlOperateException("fail load xml with JAXB.", e);
    }

    return xmlInfo;
}
项目:xlsmapper    文件:XmlIO.java   
/**
 * XMLを読み込み、{@link XmlInfo}として取得する。
 * @since 0.5
 * @param reader
 * @return
 * @throws XmlOperateException XMLの読み込みに失敗した場合。
 * @throws IllegalArgumentException in is null.
 */
public static XmlInfo load(final Reader reader) throws XmlOperateException {
    ArgUtils.notNull(reader, "reader");

    final XmlInfo xmlInfo;

    try {
        xmlInfo = JAXB.unmarshal(reader, XmlInfo.class);
    } catch (DataBindingException e) {
        throw new XmlOperateException("fail load xml with JAXB.", e);
    }

    return xmlInfo;
}
项目:xlsmapper    文件:XmlIO.java   
/**
 * XMLをファイルに保存する。
 * @since 1.1
 * @param xmlInfo XML情報。
 * @param out
 * @throws XmlOperateException XMLの書き込みに失敗した場合。
 * @throws IllegalArgumentException xmlInfo is null.
 * @throws IllegalArgumentException writer is null.
 */
public static void save(final XmlInfo xmlInfo, final OutputStream out) throws XmlOperateException {
    ArgUtils.notNull(xmlInfo, "xmlInfo");
    ArgUtils.notNull(out, "out");

    try {
        JAXB.marshal(xmlInfo, out);

    } catch (DataBindingException e) {
        throw new XmlOperateException("fail save xml with JAXB.", e);
    }

}
项目:xlsmapper    文件:XmlIO.java   
/**
 * XMLをファイルに保存する。
 * @since 1.1
 * @param xmlInfo XML情報。
 * @param writer
 * @throws XmlOperateException XMLの書き込みに失敗した場合。
 * @throws IllegalArgumentException xmlInfo is null.
 * @throws IllegalArgumentException writer is null.
 */
public static void save(final XmlInfo xmlInfo, final Writer writer) throws XmlOperateException {
    ArgUtils.notNull(xmlInfo, "xmlInfo");
    ArgUtils.notNull(writer, "writer");

    try {
        JAXB.marshal(xmlInfo, writer);

    } catch (DataBindingException e) {
        throw new XmlOperateException("fail save xml with JAXB.", e);
    }

}
项目:super-csv-annotation    文件:GeneralProcessorBuilderTest.java   
@Override
        public SampleObject parse(final String text) {

            try {
                Unmarshaller unmashaller = context.createUnmarshaller();
                unmashaller.setSchema(schema);

//                SampleObject object = JAXB.unmarshal(new StringReader(text), SampleObject.class);
                SampleObject object = (SampleObject) unmashaller.unmarshal(new StringReader(text));
                return object;
            } catch(JAXBException | DataBindingException e) {
                throw new TextParseException(text, SampleObject.class);
            }
        }
项目:brigen-base    文件:XmlDelegaterImpl.java   
private static void check() {
    try {
        Class.forName(DataBindingException.class.getName());
        Class.forName(JAXB.class.getName());
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
项目:brigen-base    文件:XmlDelegaterImpl.java   
@Override
public <T> T unmarshal(String xml, Class<T> clazz) throws XmlException {
    try {
        return JAXB.unmarshal(xml, clazz);
    } catch (DataBindingException e) {
        throw new XmlException(e);
    }
}
项目:brigen-base    文件:XmlDelegaterImpl.java   
@Override
public <T> T unmarshal(Reader xml, Class<T> clazz) throws XmlException {
    try {
        return JAXB.unmarshal(xml, clazz);
    } catch (DataBindingException e) {
        throw new XmlException(e);
    }
}
项目:brigen-base    文件:XmlDelegaterImpl.java   
@Override
public String marshal(Object obj) throws XmlException {
    StringWriter sw = new StringWriter();
    try {
        JAXB.marshal(obj, sw);
    } catch (DataBindingException e) {
        throw new XmlException(e);
    }
    return sw.toString();
}
项目:brigen-base    文件:XmlDelegaterImpl.java   
@Override
public void marshal(Object obj, Writer out) throws XmlException {
    try {
        JAXB.marshal(obj, out);
    } catch (DataBindingException e) {
        throw new XmlException(e);
    }
}
项目:ia-mame    文件:MachineRepository.java   
/**
 * Return a MameSystem object corresponding
 * to the given system name
 */
public Machine findByName (String machineName) 
        throws IOException, 
            InterruptedException, 
            MachineDoesntExistException {

    // Call MameRuntime to get Xml data of the given system,
    // then unmarshall it
    String[] mameCommandLine = {"-listxml", machineName};
    InputStream is;

    MameXmlContainer ms = null;

    try {
        is = this.mame.executeAndReturnStdoutAsInputStream(
                mameCommandLine);
        ms = JAXB.unmarshal(is, MameXmlContainer.class);
    } catch (MameExecutionException | DataBindingException e) {

        throw (MachineDoesntExistException) 
            new MachineDoesntExistException(
            String.format("The machine '%s' doesn't exist or is not " 
                    + "supported by the provided Mame version:",
                machineName)).initCause(e);
    }

    Machine machine = null;
    Set<Machine> subMachines = new HashSet<>();

    for (Machine m: ms.getMachines()) {

        if (m.getName().equals(machineName.toLowerCase())) {

            machine = m;

            String parentMachineName = m.getRomof();
            if(parentMachineName != null) {
                m.setParentMachine(
                        this.findByName(parentMachineName));
            }

        } else {
            // Others machines of the set are considered "subMachines"
            subMachines.add(m);
        }

    }

    if (machine == null) {
        throw new RuntimeException(String.format(
            "Unhandled case: Mame returned no errors while searching " 
                + "for machine %s but the machine has not been found " 
                + "on the XML content", 
            machineName));
    }

    machine.setSubMachines(subMachines);

    return machine;
}