本文整理汇总了Java中javax.xml.bind.util.JAXBSource类的典型用法代码示例。如果您正苦于以下问题:Java JAXBSource类的具体用法?Java JAXBSource怎么用?Java JAXBSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JAXBSource类属于javax.xml.bind.util包,在下文中一共展示了JAXBSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSourceImpl
import javax.xml.bind.util.JAXBSource; //导入依赖的package包/类
/**
* Returns a Source for reading the XML value designated by this SQLXML
* instance. <p>
*
* @param sourceClass The class of the source, or null. If null, then a
* DOMSource is returned.
* @return a Source for reading the XML value.
* @throws SQLException if there is an error processing the XML value
* or if the given <tt>sourceClass</tt> is not supported.
*/
protected <T extends Source>T getSourceImpl(
Class<T> sourceClass) throws SQLException {
if (JAXBSource.class.isAssignableFrom(sourceClass)) {
// Must go first presently, since JAXBSource extends SAXSource
// (purely as an implementation detail) and it's not possible
// to instantiate a valid JAXBSource with a Zero-Args
// constructor(or any subclass thereof, due to the finality of
// its private marshaller and context object attributes)
// FALL THROUGH... will throw an exception
} else if (StreamSource.class.isAssignableFrom(sourceClass)) {
return createStreamSource(sourceClass);
} else if ((sourceClass == null)
|| DOMSource.class.isAssignableFrom(sourceClass)) {
return createDOMSource(sourceClass);
} else if (SAXSource.class.isAssignableFrom(sourceClass)) {
return createSAXSource(sourceClass);
} else if (StAXSource.class.isAssignableFrom(sourceClass)) {
return createStAXSource(sourceClass);
}
throw JDBCUtil.invalidArgument("sourceClass: " + sourceClass);
}
示例2: getSourceImpl
import javax.xml.bind.util.JAXBSource; //导入依赖的package包/类
/**
* Returns a Source for reading the XML value designated by this SQLXML
* instance. <p>
*
* @param sourceClass The class of the source, or null. If null, then a
* DOMSource is returned.
* @return a Source for reading the XML value.
* @throws SQLException if there is an error processing the XML value
* or if the given <tt>sourceClass</tt> is not supported.
*/
protected <T extends Source>T getSourceImpl(
Class<T> sourceClass) throws SQLException {
if (JAXBSource.class.isAssignableFrom(sourceClass)) {
// Must go first presently, since JAXBSource extends SAXSource
// (purely as an implmentation detail) and it's not possible
// to instantiate a valid JAXBSource with a Zero-Args
// constructor(or any subclass thereof, due to the finality of
// its private marshaller and context object attrbutes)
// FALL THROUGH... will throw an exception
} else if (StreamSource.class.isAssignableFrom(sourceClass)) {
return createStreamSource(sourceClass);
} else if ((sourceClass == null)
|| DOMSource.class.isAssignableFrom(sourceClass)) {
return createDOMSource(sourceClass);
} else if (SAXSource.class.isAssignableFrom(sourceClass)) {
return createSAXSource(sourceClass);
} else if (StAXSource.class.isAssignableFrom(sourceClass)) {
return createStAXSource(sourceClass);
}
throw Util.invalidArgument("sourceClass: " + sourceClass);
}
示例3: getSourceImpl
import javax.xml.bind.util.JAXBSource; //导入依赖的package包/类
/**
* Returns a Source for reading the XML value designated by this SQLXML
* instance. <p>
*
* @param sourceClass The class of the source, or null. If null, then a
* DOMSource is returned.
* @return a Source for reading the XML value.
* @throws SQLException if there is an error processing the XML value
* or if the given <tt>sourceClass</tt> is not supported.
*/
protected <T extends Source>T getSourceImpl(
Class<T> sourceClass) throws SQLException {
if (JAXBSource.class.isAssignableFrom(sourceClass)) {
// Must go first presently, since JAXBSource extends SAXSource
// (purely as an implmentation detail) and it's not possible
// to instantiate a valid JAXBSource with a Zero-Args
// constructor(or any subclass thereof, due to the finality of
// its private marshaller and context object attrbutes)
// FALL THROUGH... will throw an exception
} else if (StreamSource.class.isAssignableFrom(sourceClass)) {
return createStreamSource(sourceClass);
} else if ((sourceClass == null)
|| DOMSource.class.isAssignableFrom(sourceClass)) {
return createDOMSource(sourceClass);
} else if (SAXSource.class.isAssignableFrom(sourceClass)) {
return createSAXSource(sourceClass);
} else if (StAXSource.class.isAssignableFrom(sourceClass)) {
return createStAXSource(sourceClass);
}
throw JDBCUtil.invalidArgument("sourceClass: " + sourceClass);
}
示例4: resolve
import javax.xml.bind.util.JAXBSource; //导入依赖的package包/类
@Override
public Source resolve(String href, String base) throws TransformerException {
String[] hrefParts = href.split(":");
String userID = hrefParts[1];
MCRUser user = null;
try {
if ("current".equals(userID)) {
user = MCRUserManager.getCurrentUser();
} else if ("getOwnedUsers".equals(userID)) {
return getOwnedUsers(hrefParts[2]);
} else {
user = MCRUserManager.getUser(userID);
}
if (user == null) {
return null;
}
return new JAXBSource(MCRUserTransformer.JAXB_CONTEXT, user.getSafeCopy());
} catch (JAXBException e) {
throw new TransformerException(e);
}
}
示例5: deepCopy
import javax.xml.bind.util.JAXBSource; //导入依赖的package包/类
private static <T> T deepCopy(T object, Class<T> clazz, String packages) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(packages);
// create marshaller which disable validation step
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setEventHandler(event -> true);
// create unmarshaller which disable validation step
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setEventHandler(event -> true);
JAXBElement<T> contentObject = new JAXBElement<>(new QName(clazz.getName()), clazz, object);
return unmarshaller.unmarshal(new JAXBSource(marshaller, contentObject), clazz).getValue();
} catch (JAXBException e) {
throw new ParseException("Time overlaps in <p> cannot be resolved.", e);
}
}
示例6: transformTtmlDocument
import javax.xml.bind.util.JAXBSource; //导入依赖的package包/类
/**
* Does TTML document transformation to another TTML document.
*
* @param tt source TTML document root element
* @param transformer transformer
* @return TTML document after transformation
*/
public static TtEltype transformTtmlDocument(TtEltype tt, Transformer transformer) {
JAXBElement<TtEltype> ttJaxb = new ObjectFactory().createTt(tt);
try {
JAXBContext jaxbc = createTtmlJaxbContext();
JAXBSource source = new JAXBSource(jaxbc, ttJaxb);
JAXBResult result = new JAXBResult(jaxbc);
// transform
transformer.transform(source, result);
return (TtEltype) ((JAXBElement<TtEltype>) result.getResult()).getValue();
} catch (JAXBException | TransformerException e) {
throw new ConvertException(e);
}
}
示例7: write
import javax.xml.bind.util.JAXBSource; //导入依赖的package包/类
@Deprecated
public void write(DigitalObjectHandler handler, ModsDefinition mods, String model, long timestamp, String message) throws DigitalObjectException {
try {
JAXBSource jaxbSource = new JAXBSource(ModsUtils.defaultMarshaller(false),
new cz.cas.lib.proarc.mods.ObjectFactory().createMods(mods));
// DO NOT include schemaLocation. Fedora validator does not accept it.
Transformer t = DcUtils.modsTransformer(model);
EditorResult result = editor.createResult();
JAXBResult jaxbResult = new JAXBResult(DcUtils.defaultUnmarshaller());
t.transform(jaxbSource, jaxbResult);
JAXBElement<OaiDcType> elm = (JAXBElement<OaiDcType>) jaxbResult.getResult();
OaiDcType dc = elm.getValue();
addDigitalObjectMetadata(handler, dc);
DcUtils.marshal(result, dc, false);
editor.write(result, timestamp, message);
} catch (TransformerException | JAXBException ex) {
throw new DigitalObjectException(object.getPid(), ex);
}
}
示例8: testTransformation
import javax.xml.bind.util.JAXBSource; //导入依赖的package包/类
@Test
public void testTransformation() throws Exception {
ModsDefinition mods = ModsUtils.unmarshalModsType(new StreamSource(DcStreamEditorTest.class.getResource("periodical.xml").toExternalForm()));
Transformer t = DcUtils.modsTransformer("model:periodical");
JAXBSource jaxbSource = new JAXBSource(ModsUtils.defaultMarshaller(false),
new ObjectFactory().createMods(mods));
StringWriter dump = new StringWriter();
t.transform(jaxbSource, new StreamResult(dump));
String toXml = dump.toString();
System.out.println(toXml);
HashMap<String, String> namespaces = new HashMap<String, String>();
namespaces.put("oai_dc", DcStreamEditor.DATASTREAM_FORMAT_URI);
namespaces.put("dc", "http://purl.org/dc/elements/1.1/");
XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
XMLAssert.assertXpathExists("/oai_dc:dc/dc:title[text()='main']", toXml);
XMLAssert.assertXpathExists("/oai_dc:dc/dc:title[text()='key']", toXml);
XMLAssert.assertXpathExists("/oai_dc:dc/dc:title[text()='alternative']", toXml);
XMLAssert.assertXpathEvaluatesTo("3", "count(/oai_dc:dc/dc:title)", toXml);
XMLAssert.assertXpathExists("/oai_dc:dc/dc:creator[text()='Boleslav']", toXml);
XMLAssert.assertXpathExists("/oai_dc:dc/dc:description[text()='poznámka']", toXml);
XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='uuid:40d13cb2-811f-468c-a6d3-1ad6b01f06f7']", toXml);
XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='isbn:0eaa6730']", toXml);
XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='issn-l:idIssn-l']", toXml);
XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='idWitEmptyType']", toXml);
XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='idWithoutType']", toXml);
// XXX needs more test
}
示例9: invoke
import javax.xml.bind.util.JAXBSource; //导入依赖的package包/类
public Source invoke(Source request)
{
try
{
JAXBContext jc = JAXBContext.newInstance(new Class[] { UserType.class });
UserType user = (UserType)jc.createUnmarshaller().unmarshal(request);
log.info("[string=" + user.getString() + ",qname=" + user.getQname() + "]");
return new JAXBSource(jc, user);
}
catch (RuntimeException rte)
{
throw rte;
}
catch (Exception e)
{
throw new WebServiceException(e);
}
}
示例10: render
import javax.xml.bind.util.JAXBSource; //导入依赖的package包/类
/**
* Render a jaxbElement with given xslt resource and
* @param writer write result to this writer
* @param jaxbModel date to render
* @param stylesheet xslt stylesheet resource
* @param parameters parameter for style sheet, like localizer, uriInfo (depends on stylesheet)
* @throws IOException
*/
public void render(Writer writer, Object jaxbModel, String stylesheet, Map<String, Object> parameters) throws IOException
{
try
{
// Create Transformer
Transformer transformer = transformerFactory.newTransformer(getStreamSource(stylesheet));
for(Entry<String, Object> entry : parameters.entrySet())
{
transformer.setParameter(entry.getKey(), entry.getValue());
}
// Source
JAXBContext jc = JAXBContext.newInstance(jaxbModel.getClass());
// Transform
transformer.transform(new JAXBSource(jc, jaxbModel), new StreamResult(writer));
}
catch(JAXBException | TransformerException e)
{
throw new IOException("Can't process stylesheet: " + stylesheet, e);
}
}
示例11: SourceBlockImpl
import javax.xml.bind.util.JAXBSource; //导入依赖的package包/类
/**
* Constructor called from factory
*
* @param busObject
* @param qName
* @param factory
*/
SourceBlockImpl(Source busObject, QName qName, BlockFactory factory)
throws WebServiceException {
super(busObject, null, qName, factory);
// Check validity of Source
if (busObject instanceof DOMSource ||
busObject instanceof SAXSource ||
busObject instanceof StreamSource ||
(busObject.getClass().equals(staxSource)) ||
busObject instanceof JAXBSource) {
// Okay, these are supported Source objects
if (log.isDebugEnabled()) {
log.debug("data object is a " + busObject.getClass().getName());
}
} else {
throw ExceptionFactory.makeWebServiceException(
Messages.getMessage("SourceNotSupported", busObject.getClass().getName()));
}
}
示例12: writeTo
import javax.xml.bind.util.JAXBSource; //导入依赖的package包/类
@Override
public void writeTo(
final Resource paramT,
final Class<?> paramClass,
final Type paramType,
final Annotation[] paramArrayOfAnnotation,
final MediaType paramMediaType,
final MultivaluedMap<String, Object> paramMultivaluedMap,
final OutputStream paramOutputStream)
throws IOException, WebApplicationException {
try {
final Source input = new JAXBSource(newJAXBContext(), paramT);
final Result result = new StreamResult(paramOutputStream);
this.transformer.transform(input, result);
} catch (JAXBException | TransformerException e) {
LOG.error("Could not produce result", e);
}
}
示例13: build
import javax.xml.bind.util.JAXBSource; //导入依赖的package包/类
@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);
}
}
示例14: export
import javax.xml.bind.util.JAXBSource; //导入依赖的package包/类
@Test
public void export() throws JAXBException, TransformerException
{
JAXBContext jc = JAXBContext.newInstance("com.healthcit.cacure.export.model");
File iFile = new File("C:\\temp\\moduleTest1.xml");
//File iFile = new File("C:\\temp\\formExportTest.xml");
//File iFile = new File("C:\\temp\\section1.1.xml");
//File iFile = new File("C:\\temp\\complexSkip2.xml");
//File iFile = new File("C:\\temp\\section3.1.xml");
File oFile = new File("C:\\temp\\Book2.xml");
Unmarshaller m = jc.createUnmarshaller();
Cure xml = (Cure)m.unmarshal(iFile);
StreamSource xslSource = new StreamSource("src//main//resources//xls.xsl");
//long formId = 9979;
//Cure xml = dataExporter.constructFormXML(formId);
JAXBSource xmlSource = new JAXBSource(jc, xml);
Transformer transformer = TransformerFactory.newInstance().newTransformer(xslSource);
transformer.transform(xmlSource,new StreamResult(oFile));
}
示例15: newJAXBSource
import javax.xml.bind.util.JAXBSource; //导入依赖的package包/类
public static JAXBSource newJAXBSource(JAXBContext jaxbContext, Object object)
{
try
{
return new JAXBSource(jaxbContext, object);
}
catch (JAXBException ex)
{
throw new FluentXmlProcessingException(ex);
}
}