当前位置: 首页>>代码示例>>Java>>正文


Java MarshalException类代码示例

本文整理汇总了Java中javax.xml.bind.MarshalException的典型用法代码示例。如果您正苦于以下问题:Java MarshalException类的具体用法?Java MarshalException怎么用?Java MarshalException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MarshalException类属于javax.xml.bind包,在下文中一共展示了MarshalException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: marshallToString

import javax.xml.bind.MarshalException; //导入依赖的package包/类
private static String marshallToString(Object object,
        boolean includeXMLHeader) throws MarshalException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(
            100);
    try {
        JAXBContext context = JAXBContext.newInstance(object.getClass());
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, !includeXMLHeader);
        marshaller.marshal(object, byteArrayOutputStream);
        return new String(byteArrayOutputStream.toByteArray());
    } catch (Throwable e) {
        throw new MarshalException("Unable to marshal object to stream", e);
    } finally {
        IOUtils.closeQuietly(byteArrayOutputStream);
    }
}
 
开发者ID:webinerds,项目名称:s3-proxy-chunk-upload,代码行数:17,代码来源:JAXBUtils.java

示例2: convertJaxbException

import javax.xml.bind.MarshalException; //导入依赖的package包/类
/**
 * Convert the given {@code JAXBException} to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * @param ex {@code JAXBException} that occured
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertJaxbException(JAXBException ex) {
	if (ex instanceof ValidationException) {
		return new ValidationFailureException("JAXB validation exception", ex);
	}
	else if (ex instanceof MarshalException) {
		return new MarshallingFailureException("JAXB marshalling exception", ex);
	}
	else if (ex instanceof UnmarshalException) {
		return new UnmarshallingFailureException("JAXB unmarshalling exception", ex);
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown JAXB exception", ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:Jaxb2Marshaller.java

示例3: marshalToBytes

import javax.xml.bind.MarshalException; //导入依赖的package包/类
public static byte[] marshalToBytes(PcGtsType page) throws JAXBException {
	ValidationEventCollector vec = new ValidationEventCollector();
	Marshaller marshaller = createMarshaller(vec);
	
	ObjectFactory objectFactory = new ObjectFactory();
	JAXBElement<PcGtsType> je = objectFactory.createPcGts(page);
	byte[] data;
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	try {
		try {
			marshaller.marshal(je, out);
			data = out.toByteArray();
		} finally {
			out.close();
		}
	} catch (Exception e) {
		throw new MarshalException(e);
	}
	
	String msg=buildMsg(vec, page);
	if (!msg.startsWith(NO_EVENTS_MSG))
		logger.info(msg);
	
	return data;
}
 
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:26,代码来源:PageXmlUtils.java

示例4: marshalToBytes

import javax.xml.bind.MarshalException; //导入依赖的package包/类
public static <T> byte[] marshalToBytes(T object, Class<?>... nestedClasses) throws JAXBException {
	byte[] data;
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	try{
		try{
			marshalToStream(object, out, nestedClasses);
			data = out.toByteArray();
		} finally {
			out.close();
		}
	} catch (Exception e){
		throw new MarshalException(e);
	}
	
	return data;
}
 
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:17,代码来源:JaxbUtils.java

示例5: marshal

import javax.xml.bind.MarshalException; //导入依赖的package包/类
/**
 * Turns an individual JAXB element into an XML fragment string using the given validation mode.
 *
 * @throws MarshalException if schema validation failed
 */
public String marshal(JAXBElement<?> element, ValidationMode validationMode)
    throws MarshalException {
  os.reset();
  marshaller.setSchema((validationMode == STRICT) ? schema : null);
  try {
    marshaller.marshal(element, os);
  } catch (JAXBException e) {
    throwIfInstanceOf(e, MarshalException.class);
    throw new RuntimeException("Mysterious XML exception", e);
  }
  String fragment = new String(os.toByteArray(), UTF_8);
  int endOfFirstLine = fragment.indexOf(">\n");
  verify(endOfFirstLine > 0, "Bad XML fragment:\n%s", fragment);
  String firstLine = fragment.substring(0, endOfFirstLine + 2);
  String rest = fragment.substring(firstLine.length());
  return XMLNS_PATTERN.matcher(firstLine).replaceAll("") + rest;
}
 
开发者ID:google,项目名称:nomulus,代码行数:23,代码来源:XmlFragmentMarshaller.java

示例6: getDetail

import javax.xml.bind.MarshalException; //导入依赖的package包/类
/**
 * Attempt to get the most informative detail from the given exception
 * @param e Exception to dig
 * @return Detail String
 */
protected String getDetail(final Exception e) {
    
    if (e == null) return null;
    
    if (e instanceof ValidationException || e instanceof MarshalException) {
        
        Throwable t = e.getCause();
        
        if (t != null) {
            while (t.getCause() != null) {
                t = t.getCause();
            }
            return t.getMessage();
        }
    }
    
    if (e instanceof IllegalArgumentException) {
        return "Unable to parse XML: " + e.getMessage();
    }
    
    return e.getMessage();
}
 
开发者ID:laverca,项目名称:laverca,代码行数:28,代码来源:JaxbDeserializer.java

示例7: marshal

import javax.xml.bind.MarshalException; //导入依赖的package包/类
/**
 * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
 */
@Override
public NameAndNamespacePair marshal(NameAndNamespacePair v) throws Exception {
    if (v != null) {
        if (StringUtils.isBlank(v.getName())) {
            throw new MarshalException("Cannot export a name-and-namespace pair with a blank name");
        } else if (StringUtils.isBlank(v.getNamespaceCode())) {
            throw new MarshalException("Cannot export a name-and-namespace pair with a blank namespace code");
        } else if (CoreServiceApiServiceLocator.getNamespaceService().getNamespace(v.getNamespaceCode()) == null) {
            throw new MarshalException("Cannot export a name-and-namespace pair with invalid or unknown namespace \"" + v.getNamespaceCode() + "\"");
        }
        
        v.setName(new NormalizedStringAdapter().marshal(v.getName()));
        v.setNamespaceCode(v.getNamespaceCode());
    }
    return v;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:20,代码来源:NameAndNamespacePairValidatingAdapter.java

示例8: write

import javax.xml.bind.MarshalException; //导入依赖的package包/类
private void write( XMLSerializable obj, ContentHandler writer )
    throws JAXBException {

    try {
        if( getSchemaLocation()!=null || getNoNSSchemaLocation()!=null ) {
            // if we need to add xsi:schemaLocation or its brother,
            // throw in the component to do that.
            writer = new SchemaLocationFilter(
                getSchemaLocation(),
                getNoNSSchemaLocation(),
                writer );
        }
        
        SAXMarshaller serializer = new SAXMarshaller(writer,prefixMapper,this);
    
        // set a DocumentLocator that doesn't provide any information
        writer.setDocumentLocator( new LocatorImpl() );
        writer.startDocument();
        serializer.childAsBody(obj,null);
        writer.endDocument();
        
        serializer.reconcileID();   // extra check
    } catch( SAXException e ) {
        throw new MarshalException(e);
    }
}
 
开发者ID:nhrdl,项目名称:javacash,代码行数:27,代码来源:MarshallerImpl.java

示例9: _adaptM

import javax.xml.bind.MarshalException; //导入依赖的package包/类
private OnWire _adaptM(XMLSerializer serializer, InMemory v) throws MarshalException {
    XmlAdapter<OnWire,InMemory> a = serializer.getAdapter(adapter);
    try {
        return a.marshal(v);
    } catch (Exception e) {
        serializer.handleError(e,v,null);
        throw new MarshalException(e);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:BridgeAdapter.java

示例10: marshal

import javax.xml.bind.MarshalException; //导入依赖的package包/类
void marshal(InMemory o, XMLSerializer out) throws IOException, SAXException, XMLStreamException {
    try {
        core.marshal(_adaptM( XMLSerializer.getInstance(), o ), out );
    } catch (MarshalException e) {
        // recover from error by not marshalling this element.
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:BridgeAdapter.java

示例11: testMarshalError

import javax.xml.bind.MarshalException; //导入依赖的package包/类
@Test
public void testMarshalError() throws JAXBException {
  try {
    MarshalHelper.marshalError(car);
    fail("no exception thrown");
  } catch (MarshalException e) {
    logger.error("MarshalException", e);
    assertTrue(e.toString()
        .contains("is missing an @XmlRootElement annotation"));
  }
}
 
开发者ID:code-not-found,项目名称:jaxb,代码行数:12,代码来源:MarshalHelperTest.java

示例12: marshalOrDie

import javax.xml.bind.MarshalException; //导入依赖的package包/类
/**
 * Turns XJC element into XML fragment, converting {@link MarshalException}s to {@link
 * RuntimeException}s.
 */
public String marshalOrDie(JAXBElement<?> element) {
  try {
    return marshal(element);
  } catch (MarshalException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:12,代码来源:RdeMarshaller.java

示例13: marshalResource

import javax.xml.bind.MarshalException; //导入依赖的package包/类
private DepositFragment marshalResource(
    RdeResourceType type, ImmutableObject resource, JAXBElement<?> element) {
  String xml = "";
  String error = "";
  try {
    xml = marshal(element);
  } catch (MarshalException e) {
    error = String.format("RDE XML schema validation failed: %s\n%s%s\n",
        Key.create(resource),
        e.getLinkedException(),
        getMarshaller().marshalLenient(element));
    logger.severe(e, error);
  }
  return DepositFragment.create(type, xml, error);
}
 
开发者ID:google,项目名称:nomulus,代码行数:16,代码来源:RdeMarshaller.java

示例14: marshalLenient

import javax.xml.bind.MarshalException; //导入依赖的package包/类
/** Turns an individual JAXB element into an XML fragment string. */
public String marshalLenient(JAXBElement<?> element) {
  try {
    return marshal(element, LENIENT);
  } catch (MarshalException e) {
    throw new RuntimeException("MarshalException shouldn't be thrown in lenient mode", e);
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:9,代码来源:XmlFragmentMarshaller.java

示例15: marshal

import javax.xml.bind.MarshalException; //导入依赖的package包/类
/**
 * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
 */
@Override
public NameAndNamespacePair marshal(String v) throws Exception {
    if (v != null) {
        Template permissionTemplate = KimApiServiceLocator.getPermissionService().getPermissionTemplate(v);
        if (permissionTemplate == null) {
            throw new MarshalException("Cannot find permission template with ID \"" + v + "\"");
        }
        return new NameAndNamespacePair(permissionTemplate.getNamespaceCode(), permissionTemplate.getName());
    }
    return null;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:15,代码来源:NameAndNamespacePairToPermTemplateIdAdapter.java


注:本文中的javax.xml.bind.MarshalException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。