javax.xml.bind.DataBindingException Java Examples

The following examples show how to use javax.xml.bind.DataBindingException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeneralProcessorBuilderTest.java    From super-csv-annotation with Apache License 2.0 6 votes vote down vote up
@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);
            }
        }
 
Example #2
Source File: JaxbBuilder.java    From xmlunit with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #3
Source File: Aes57Utils.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #4
Source File: NdkMetadataHandler.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setMetadataAsXml(DescriptionMetadata<String> xmlData, String message, String typeRecord) throws DigitalObjectException {
    ModsDefinition mods;
    String modelId = handler.getModel().getPid();
    if (xmlData.getData() != null) {
        ValidationErrorHandler errHandler = new ValidationErrorHandler();
        try {
            String data = xmlData.getData();
            xmlData.setData(data);

            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, typeRecord);
}
 
Example #5
Source File: ModsUtils.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #6
Source File: FoxmlUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #7
Source File: GeneralProcessorBuilderTest.java    From super-csv-annotation with Apache License 2.0 5 votes vote down vote up
@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);
            }
        }
 
Example #8
Source File: XmlIO.java    From xlsmapper with Apache License 2.0 5 votes vote down vote up
/**
 * 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 AnnotationMappingInfo 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);
    }
    
}
 
Example #9
Source File: XmlIO.java    From xlsmapper with Apache License 2.0 5 votes vote down vote up
/**
 * 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 AnnotationMappingInfo 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);
    }
    
}
 
Example #10
Source File: XmlIO.java    From xlsmapper with Apache License 2.0 5 votes vote down vote up
/**
 * XMLを読み込み、{@link AnnotationMappingInfo}として取得する。
 * @since 0.5
 * @param reader
 * @return
 * @throws XmlOperateException XMLの読み込みに失敗した場合。
 * @throws IllegalArgumentException in is null.
 */
public static AnnotationMappingInfo load(final Reader reader) throws XmlOperateException {
    ArgUtils.notNull(reader, "reader");
    
    final AnnotationMappingInfo xmlInfo;
    
    try {
        xmlInfo = JAXB.unmarshal(reader, AnnotationMappingInfo.class);
    } catch (DataBindingException e) {
        throw new XmlOperateException("fail load xml with JAXB.", e);
    }
    
    return xmlInfo;
}
 
Example #11
Source File: XmlIO.java    From xlsmapper with Apache License 2.0 5 votes vote down vote up
/**
 * XMLを読み込み、{@link AnnotationMappingInfo}として取得する。
 * @param in
 * @return
 * @throws XmlOperateException XMLの読み込みに失敗した場合。
 * @throws IllegalArgumentException in is null.
 */
public static AnnotationMappingInfo load(final InputStream in) throws XmlOperateException {
    ArgUtils.notNull(in, "in");
    
    final AnnotationMappingInfo xmlInfo;
    
    try {
        xmlInfo = JAXB.unmarshal(in, AnnotationMappingInfo.class);
    } catch (DataBindingException e) {
        throw new XmlOperateException("fail load xml with JAXB.", e);
    }
    
    return xmlInfo;
}
 
Example #12
Source File: ModsUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #13
Source File: ModsUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #14
Source File: ModsUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @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);
    }
}
 
Example #15
Source File: DcUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #16
Source File: DcUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #17
Source File: JaxbCallback.java    From tessera with Apache License 2.0 5 votes vote down vote up
static <T> T execute(JaxbCallback<T> callback) {
    try {
        return callback.doExecute();
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
 
Example #18
Source File: FoxmlUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #19
Source File: Relations.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #20
Source File: Relations.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #21
Source File: PremisUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #22
Source File: PremisUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #23
Source File: MixUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #24
Source File: MixUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #25
Source File: NsesssUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #26
Source File: NsesssUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #27
Source File: ResolverXmlUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example #28
Source File: Aes57Utils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
public static void marshal(Result target, Object aesElement, boolean indent) {
    try {
        Marshaller m = defaultMarshaller(indent);
        m.marshal(aesElement, target);
    } catch (JAXBException ex) {
        throw new DataBindingException(ex);
    }
}
 
Example #29
Source File: JaxbCallbackTest.java    From tessera with Apache License 2.0 5 votes vote down vote up
@Test
public void executeThrowsJAXException() {

    final JAXBException exception = new JAXBException("GURU Meditation 22");

    final Throwable throwable = catchThrowable(() ->
        JaxbCallback.execute(() -> {
            throw exception;
        })
    );

    assertThat(throwable).isNotNull().isInstanceOf(DataBindingException.class).hasCause(exception);
}
 
Example #30
Source File: MachineRepository.java    From ia-rcade with Apache License 2.0 4 votes vote down vote up
/**
 * 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 cloneof = m.getCloneof();
      if (cloneof != null) {
        m.setClonedMachine(this.findByName(cloneof));
      }

      String romof = m.getRomof();
      if (romof != null) {
        m.setRomOfMachine(this.findByName(romof));
      }

    } 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;
}