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


Java ValidationEventCollector类代码示例

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


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

示例1: loadPluginDescriptor

import javax.xml.bind.util.ValidationEventCollector; //导入依赖的package包/类
/**
 * Loads the plugin descriptor from the specified file. The file path specified should
 * be a class path relative path. For example, if the descriptor file is located at
 * org.rhq.enterprise.server.configuration.my-descriptor.xml, then you should specify
 * /org/rhq/enterprise/server/configuration/my-descriptor.xml.
 *
 * @param pluginDescriptorURL The class path relative path of the descriptor file
 * @return The {@link PluginDescriptor}
 */
public static PluginDescriptor loadPluginDescriptor(URL pluginDescriptorURL) {
   try {
      JAXBContext jaxbContext = JAXBContext.newInstance(DescriptorPackages.PC_PLUGIN);
      URL pluginSchemaURL = PluginDescriptorUtil.class.getClassLoader().getResource("rhq-plugin.xsd");
      Schema pluginSchema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(
               pluginSchemaURL);
      Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
      ValidationEventCollector vec = new ValidationEventCollector();
      unmarshaller.setEventHandler(vec);
      unmarshaller.setSchema(pluginSchema);

      return (PluginDescriptor) unmarshaller.unmarshal(pluginDescriptorURL.openStream());
   } catch (Exception e) {
      throw new RuntimeException(e);
   }
}
 
开发者ID:rh-messaging,项目名称:Artemis-JON-plugin,代码行数:26,代码来源:PluginDescriptorUtil.java

示例2: toPluginDescriptor

import javax.xml.bind.util.ValidationEventCollector; //导入依赖的package包/类
/**
 * Transforms the given string into a plugin descriptor object.
 *
 * @param string The plugin descriptor specified as a string
 * @return The {@link PluginDescriptor}
 */
public static PluginDescriptor toPluginDescriptor(String string) {
   try {
      JAXBContext jaxbContext = JAXBContext.newInstance(DescriptorPackages.PC_PLUGIN);
      URL pluginSchemaURL = PluginMetadataParser.class.getClassLoader().getResource("rhq-plugin.xsd");
      Schema pluginSchema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(pluginSchemaURL);

      Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
      ValidationEventCollector vec = new ValidationEventCollector();
      unmarshaller.setEventHandler(vec);
      unmarshaller.setSchema(pluginSchema);

      StringReader reader = new StringReader(string);

      return (PluginDescriptor) unmarshaller.unmarshal(reader);
   }
   catch (Exception e) {
      throw new RuntimeException(e);
   }
}
 
开发者ID:rh-messaging,项目名称:Artemis-JON-plugin,代码行数:26,代码来源:PluginDescriptorUtil.java

示例3: marshalToBytes

import javax.xml.bind.util.ValidationEventCollector; //导入依赖的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: 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();
	}
 
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:22,代码来源:JaxbUtils.java

示例5: getUnmarshaller

import javax.xml.bind.util.ValidationEventCollector; //导入依赖的package包/类
private Unmarshaller getUnmarshaller() throws JAXBException {
    JAXBContext jctx = JAXBContext.newInstance(WorkflowDefinition.class);
    Unmarshaller unmarshaller = jctx.createUnmarshaller();
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    URL schemaUrl = WorkflowDefinition.class.getResource("workflow.xsd");
    Schema schema = null;
    try {
        schema = sf.newSchema(new StreamSource(schemaUrl.toExternalForm()));
    } catch (SAXException ex) {
        throw new JAXBException("Missing schema workflow.xsd!", ex);
    }
    unmarshaller.setSchema(schema);
    ValidationEventCollector errors = new ValidationEventCollector() {

        @Override
        public boolean handleEvent(ValidationEvent event) {
            super.handleEvent(event);
            return true;
        }

    };
    unmarshaller.setEventHandler(errors);
    return unmarshaller;
}
 
开发者ID:proarc,项目名称:proarc,代码行数:25,代码来源:WorkflowProfiles.java

示例6: 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);
        }
    }
}
 
开发者ID:OSEHRA-Sandbox,项目名称:MOCHA,代码行数:32,代码来源:XmlUtility.java

示例7: createMarshaller

import javax.xml.bind.util.ValidationEventCollector; //导入依赖的package包/类
private static Marshaller createMarshaller(ValidationEventCollector vec) throws JAXBException {
	JAXBContext jc = createPageJAXBContext();
	Marshaller m = jc.createMarshaller();
	m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
	m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
	m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaLocStr);
	m.setEventHandler(vec);
	m.setListener(new TrpPageMarshalListener());
	
	return m;
}
 
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:12,代码来源:PageXmlUtils.java

示例8: marshalToFile

import javax.xml.bind.util.ValidationEventCollector; //导入依赖的package包/类
public static File marshalToFile(PcGtsType page, File fileOut) throws JAXBException, IOException {
	ValidationEventCollector vec = new ValidationEventCollector();
	Marshaller marshaller = createMarshaller(vec);
	
	ObjectFactory objectFactory = new ObjectFactory();
	JAXBElement<PcGtsType> je = objectFactory.createPcGts(page);
		
	File backup=null;
	if (fileOut.exists()) {
		logger.debug("file exists: "+fileOut.getAbsolutePath()+ " - backing up!");
		backup = CoreUtils.backupFile(fileOut);
	}
	
	try {
		marshaller.marshal(je, fileOut);
	} catch (Exception e) {
		if (backup!=null) {
			logger.debug("restoring backup: "+backup.getAbsolutePath());
			FileUtils.copyFile(backup, fileOut);
		}
		if (e instanceof JAXBException)
			throw e;
		else			
			throw new JAXBException(e.getMessage(), e);
	} finally {
		if (backup!=null)
			backup.delete();
	}
	String msg=buildMsg(vec, page);
	if (!msg.startsWith(NO_EVENTS_MSG))
		logger.info(msg);
	
	return fileOut;
}
 
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:35,代码来源:PageXmlUtils.java

示例9: 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;
}
 
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:16,代码来源:PageXmlUtils.java

示例10: 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!");
	}
}
 
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:12,代码来源:JaxbUtils.java

示例11: 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());
    }
}
 
开发者ID:proarc,项目名称:proarc,代码行数:30,代码来源:WorkflowProfiles.java

示例12: loadDescriptor

import javax.xml.bind.util.ValidationEventCollector; //导入依赖的package包/类
/**
 * Parses and loads a particular plugin descriptor by stream, typically
 * obtained by calling {@link Class#getResourceAsStream(String)}.
 */
protected PluginDescriptor loadDescriptor(InputStream is) throws Exception {
    ValidationEventCollector vec = new ValidationEventCollector();
    PluginDescriptor pd = AgentPluginDescriptorUtil.parsePluginDescriptor(is, vec);
    if (vec.hasEvents())
        log.warn("Validation failed " + asList(vec.getEvents()));
    return pd;
}
 
开发者ID:genman,项目名称:rhq-plugins,代码行数:12,代码来源:ComponentTest.java

示例13: 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());
	}
}
 
开发者ID:betfair,项目名称:cougar,代码行数:12,代码来源:XMLUnMarshaller.java


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