本文整理汇总了Java中javax.xml.bind.util.ValidationEventCollector.getEvents方法的典型用法代码示例。如果您正苦于以下问题:Java ValidationEventCollector.getEvents方法的具体用法?Java ValidationEventCollector.getEvents怎么用?Java ValidationEventCollector.getEvents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.bind.util.ValidationEventCollector
的用法示例。
在下文中一共展示了ValidationEventCollector.getEvents方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: marshalToStream
import javax.xml.bind.util.ValidationEventCollector; //导入方法依赖的package包/类
private static <T> ValidationEvent[] marshalToStream(T object, OutputStream out,
boolean doFormatting, MarshallerType type, Class<?>... nestedClasses) throws JAXBException {
ValidationEventCollector vec = new ValidationEventCollector();
final Marshaller marshaller;
// switch(type) {
// case JSON:
// marshaller = createJsonMarshaller(object, doFormatting, nestedClasses);
// break;
// default:
// marshaller = createXmlMarshaller(object, doFormatting, nestedClasses);
// break;
// }
marshaller = createXmlMarshaller(object, doFormatting, nestedClasses);
marshaller.setEventHandler(vec);
marshaller.marshal(object, out);
checkEvents(vec);
return vec.getEvents();
}
示例2: handleValidationEvents
import javax.xml.bind.util.ValidationEventCollector; //导入方法依赖的package包/类
/**
* If there are any events, convert the events into an error message string and throw a new InterfaceValidationException.
*
* @param jaxbException that prompted the check for validation events
* @param handler ValidationEventController with any validation events
* @param messageType String describing what type of message caused the error (Request, Response, or exception message)
*/
protected static void handleValidationEvents(JAXBException jaxbException, ValidationEventCollector handler,
String messageType) {
if (handler.hasEvents()) {
ValidationEvent[] events = handler.getEvents();
StringBuffer errorMessage = new StringBuffer();
for (int i = 0; i < events.length; i++) {
if (i > 0) {
errorMessage.append(" ");
}
errorMessage.append(events[i].getMessage());
}
if (jaxbException == null) {
throw new InterfaceValidationException(InterfaceValidationException.VALIDATION_ERROR,
InterfaceException.PRE_ENCAPSULATION, messageType, errorMessage);
}
else {
throw new InterfaceValidationException(jaxbException, InterfaceValidationException.VALIDATION_ERROR,
InterfaceException.PRE_ENCAPSULATION, messageType, errorMessage);
}
}
}
示例3: buildMsg
import javax.xml.bind.util.ValidationEventCollector; //导入方法依赖的package包/类
private static String buildMsg(ValidationEventCollector vec, PcGtsType page) {
String imgFn = "";
if (page.getPage()!=null) {
imgFn = page.getPage().getImageFilename();
}
String msg;
if (vec.hasEvents()) {
msg="Events occured while marshalling xml file: " + vec.getEvents().length;
} else {
msg=NO_EVENTS_MSG;
}
if (!imgFn.isEmpty()) msg += " (img: "+imgFn+")";
return msg;
}
示例4: checkEvents
import javax.xml.bind.util.ValidationEventCollector; //导入方法依赖的package包/类
private static void checkEvents(ValidationEventCollector vec) {
if (vec.hasEvents()) {
logger.info("Events occured while marshalling xml file: " + vec.getEvents().length);
ValidationEvent[] events = vec.getEvents();
for(ValidationEvent e : events){
logger.info(e.getMessage());
}
} else {
logger.debug("No events occured during marshalling xml file!");
}
}
示例5: read
import javax.xml.bind.util.ValidationEventCollector; //导入方法依赖的package包/类
private void read() throws JAXBException {
long currentTime = file.lastModified();
if (currentTime == lastModified) {
return ;
}
Unmarshaller unmarshaller = getUnmarshaller();
ValidationEventCollector errors = (ValidationEventCollector) unmarshaller.getEventHandler();
WorkflowDefinition fetchedWf = null;
try {
WorkflowDefinition wf = (WorkflowDefinition) unmarshaller.unmarshal(file);
if (!errors.hasEvents()) {
readCaches(wf);
fetchedWf = wf;
}
} catch (UnmarshalException ex) {
if (!errors.hasEvents()) {
throw ex;
}
} finally {
setProfiles(fetchedWf, currentTime);
}
if (errors.hasEvents()) {
StringBuilder err = new StringBuilder();
for (ValidationEvent event : errors.getEvents()) {
err.append(event).append('\n');
}
throw new JAXBException(err.toString());
}
}
示例6: validate
import javax.xml.bind.util.ValidationEventCollector; //导入方法依赖的package包/类
private void validate(ValidationEventCollector handler)
throws ValidationException {
if(handler.hasEvents()) {
ValidationEvent[] events = handler.getEvents();
StringBuilder sb = new StringBuilder();
for(ValidationEvent event : events) {
sb.append(event.getMessage());
}
throw new ValidationException(sb.toString());
}
}