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


Java ValidationEvent类代码示例

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


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

示例1: marshallToXml

import javax.xml.bind.ValidationEvent; //导入依赖的package包/类
public String marshallToXml(Statistics statistics) {
    try {
        Marshaller marshaller = jaxbContext.createMarshaller();
        StringWriter stringWriter = new StringWriter();
        List<ValidationEvent> validationEvents = new ArrayList<>();
        marshaller.setEventHandler(event -> {
            if (event.getSeverity() == ValidationEvent.ERROR ||
                    event.getSeverity() == ValidationEvent.FATAL_ERROR) {
                validationEvents.add(event);
            }
            //let the un-marshalling proceed to find any more problems
            return true;
        });
        marshaller.marshal(statistics, stringWriter);
        if (!validationEvents.isEmpty()) {
            String detail = validationEventsToString(validationEvents);
            throw new RuntimeException("Errors encountered marshalling xml: " + detail);
        }
        return stringWriter.toString();
    } catch (JAXBException e) {
        LOGGER.error("Error marshalling message value");
        throw new RuntimeException(String.format("Error marshalling message value"), e);
    }
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:25,代码来源:StatisticsMarshaller.java

示例2: setJaxbContext

import javax.xml.bind.ValidationEvent; //导入依赖的package包/类
public synchronized void setJaxbContext(Class... classesToBeBound) {
	try {
		setJaxbContext(JAXBContext.newInstance(classesToBeBound));
		
		// Every time we set the JAXBContext, we need to also set the marshaller and unmarshaller for EXICodec
		getExiCodec().setUnmarshaller(getJaxbContext().createUnmarshaller());
		getExiCodec().setMarshaller(getJaxbContext().createMarshaller());
		
		/*
		 * JAXB by default silently ignores errors. Adding this code to throw an exception if 
		 * something goes wrong.
		 */
		getExiCodec().getUnmarshaller().setEventHandler(
			    new ValidationEventHandler() {
			        @Override
					public boolean handleEvent(ValidationEvent event ) {
			            throw new RuntimeException(event.getMessage(),
			                                       event.getLinkedException());
			        }
			});
	} catch (JAXBException e) {
		getLogger().error("A JAXBException occurred while trying to set JAXB context", e);
	}
}
 
开发者ID:V2GClarity,项目名称:RISE-V2G,代码行数:25,代码来源:MessageHandler.java

示例3: print

import javax.xml.bind.ValidationEvent; //导入依赖的package包/类
public String print(XMLGregorianCalendar cal) {
    XMLSerializer xs = XMLSerializer.getInstance();

    QName type = xs.getSchemaType();
    if (type != null) {
        try {
            checkXmlGregorianCalendarFieldRef(type, cal);
            String format = xmlGregorianCalendarFormatString.get(type);
            if (format != null) {
                return format(format, cal);
            }
        } catch (javax.xml.bind.MarshalException e) {
            // see issue 649
            xs.handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, e.getMessage(),
                xs.getCurrentLocation(null) ));
            return "";
        }
    }
    return cal.toXMLFormat();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:RuntimeBuiltinLeafInfoImpl.java

示例4: serializeRoot

import javax.xml.bind.ValidationEvent; //导入依赖的package包/类
public void serializeRoot(BeanT bean, XMLSerializer target) throws SAXException, IOException, XMLStreamException {
    if(tagName==null) {
        Class beanClass = bean.getClass();
        String message;
        if (beanClass.isAnnotationPresent(XmlRootElement.class)) {
            message = Messages.UNABLE_TO_MARSHAL_UNBOUND_CLASS.format(beanClass.getName());
        } else {
            message = Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(beanClass.getName());
        }
        target.reportError(new ValidationEventImpl(ValidationEvent.ERROR,message,null, null));
    } else {
        target.startElement(tagName,bean);
        target.childAsSoleContent(bean,null);
        target.endElement();
        if (retainPropertyInfo) {
            target.currentProperty.remove();
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:ClassBeanInfoImpl.java

示例5: reportError

import javax.xml.bind.ValidationEvent; //导入依赖的package包/类
public void reportError( ValidationEvent ve ) throws SAXException {
    ValidationEventHandler handler;

    try {
        handler = marshaller.getEventHandler();
    } catch( JAXBException e ) {
        throw new SAXException2(e);
    }

    if(!handler.handleEvent(ve)) {
        if(ve.getLinkedException() instanceof Exception)
            throw new SAXException2((Exception)ve.getLinkedException());
        else
            throw new SAXException2(ve.getMessage());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:XMLSerializer.java

示例6: onIDREF

import javax.xml.bind.ValidationEvent; //导入依赖的package包/类
public String onIDREF( Object obj ) throws SAXException {
    String id;
    try {
        id = getIdFromObject(obj);
    } catch (JAXBException e) {
        reportError(null,e);
        return null; // recover by returning null
    }
    idReferencedObjects.add(obj);
    if(id==null) {
        reportError( new NotIdentifiableEventImpl(
            ValidationEvent.ERROR,
            Messages.NOT_IDENTIFIABLE.format(),
            new ValidationEventLocatorImpl(obj) ) );
    }
    return id;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:XMLSerializer.java

示例7: reconcileID

import javax.xml.bind.ValidationEvent; //导入依赖的package包/类
void reconcileID() throws SAXException {
    // find objects that were not a part of the object graph
    idReferencedObjects.removeAll(objectsWithId);

    for( Object idObj : idReferencedObjects ) {
        try {
            String id = getIdFromObject(idObj);
            reportError( new NotIdentifiableEventImpl(
                ValidationEvent.ERROR,
                Messages.DANGLING_IDREF.format(id),
                new ValidationEventLocatorImpl(idObj) ) );
        } catch (JAXBException e) {
            // this error should have been reported already. just ignore here.
        }
    }

    // clear the garbage
    idReferencedObjects.clear();
    objectsWithId.clear();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:XMLSerializer.java

示例8: handleEvent

import javax.xml.bind.ValidationEvent; //导入依赖的package包/类
/**
 * Reports an error to the user, and asks if s/he wants
 * to recover. If the canRecover flag is false, regardless
 * of the client instruction, an exception will be thrown.
 *
 * Only if the flag is true and the user wants to recover from an error,
 * the method returns normally.
 *
 * The thrown exception will be catched by the unmarshaller.
 */
public void handleEvent(ValidationEvent event, boolean canRecover ) throws SAXException {
    ValidationEventHandler eventHandler = parent.getEventHandler();

    boolean recover = eventHandler.handleEvent(event);

    // if the handler says "abort", we will not return the object
    // from the unmarshaller.getResult()
    if(!recover)    aborted = true;

    if( !canRecover || !recover )
        throw new SAXParseException2( event.getMessage(), locator,
            new UnmarshalException(
                event.getMessage(),
                event.getLinkedException() ) );
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:UnmarshallingContext.java

示例9: handleEvent

import javax.xml.bind.ValidationEvent; //导入依赖的package包/类
public boolean handleEvent( ValidationEvent event ) {
    events.add(event);

    boolean retVal = true;
    switch( event.getSeverity() ) {
        case ValidationEvent.WARNING:
            retVal = true; // continue validation
            break;
        case ValidationEvent.ERROR:
            retVal = true; // continue validation
            break;
        case ValidationEvent.FATAL_ERROR:
            retVal = false; // halt validation
            break;
        default:
            _assert( false,
                     Messages.format( Messages.UNRECOGNIZED_SEVERITY,
                             event.getSeverity() ) );
            break;
    }

    return retVal;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:ValidationEventCollector.java

示例10: marshallerFor

import javax.xml.bind.ValidationEvent; //导入依赖的package包/类
@Nonnull
private static javax.xml.bind.Marshaller marshallerFor(@Nonnull TestSuites element) {
    final javax.xml.bind.Marshaller marshaller;
    try {
        marshaller = JAXB_CONTEXT.createMarshaller();
        marshaller.setProperty(JAXB_FORMATTED_OUTPUT, true);
        marshaller.setEventHandler(new ValidationEventHandler() {
            @Override
            public boolean handleEvent(ValidationEvent event) {
                return true;
            }
        });
    } catch (final Exception e) {
        throw new RuntimeException("Could not create marshaller to marshall " + element + ".", e);
    }
    return marshaller;
}
 
开发者ID:echocat,项目名称:gradle-golang-plugin,代码行数:18,代码来源:TestSuites.java

示例11: marshalToStream

import javax.xml.bind.ValidationEvent; //导入依赖的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

示例12: validateParameters

import javax.xml.bind.ValidationEvent; //导入依赖的package包/类
private boolean validateParameters(ExpressiveDescriptor es, ArrayList<RenderingMethodParameterDescriptor> parameterdesc, List<ExpressiveParameter> parameters) {
    int errs = 0;
    for (RenderingMethodParameterDescriptor desc : parameterdesc) {
        ExpressiveParameter found = null;
        for (ExpressiveParameter param : parameters) {
            if (param.getName().equalsIgnoreCase(desc.getName())) {
                found = param;
            }
        }
        if (found == null & desc.isRequired()) {
            errs++;
            ((ValidationEventCollector) this.eventHandler).handleEvent(new SLDValidationEvent(ValidationEvent.ERROR, "Incomplete rendering method : the required expressive parameter "
                    + desc.getName() + " is missing", ll.getLocation(es)));
        }
    }
    return errs == 0;
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:18,代码来源:SLDXMLValidator.java

示例13: write

import javax.xml.bind.ValidationEvent; //导入依赖的package包/类
public static File write(DynamicVRPREPModel dynamicVRPREPModel, Path outputPath) throws JAXBException, SAXException {

		outputPath.getParent().toFile().mkdirs();

		InputStream stream = Instance.class.getResourceAsStream("/xsd/instance.xsd");
		Source schemaSource = new StreamSource(stream);
		SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
		Schema schema = sf.newSchema(schemaSource);

		JAXBContext jc = JAXBContext.newInstance(DynamicVRPREPModel.class);
		Marshaller marshaller = jc.createMarshaller();
		marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
		marshaller.setSchema(schema);
		marshaller.setEventHandler(new ValidationEventHandler() {
			public boolean handleEvent(ValidationEvent event) {
				System.err.println("MESSAGE:  " + event.getMessage());
				return true;
			}
		});
		marshaller.marshal(dynamicVRPREPModel, outputPath.toFile());

		return outputPath.toFile();

	}
 
开发者ID:MayerTh,项目名称:RVRPSimulator,代码行数:25,代码来源:DynamicVRPREPModel.java

示例14: writeToFile

import javax.xml.bind.ValidationEvent; //导入依赖的package包/类
public File writeToFile(Path outputPath) throws JAXBException, SAXException {
	outputPath.getParent().toFile().mkdirs();

	InputStream stream = Instance.class.getResourceAsStream("/xsd/instance.xsd");
	Source schemaSource = new StreamSource(stream);
	SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
	Schema schema = sf.newSchema(schemaSource);

	JAXBContext jc = JAXBContext.newInstance(ResultData.class);
	Marshaller marshaller = jc.createMarshaller();
	marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
	marshaller.setSchema(schema);
	marshaller.setEventHandler(new ValidationEventHandler() {
		public boolean handleEvent(ValidationEvent event) {
			System.err.println("MESSAGE:  " + event.getMessage());
			return true;
		}
	});
	marshaller.marshal(this, outputPath.toFile());
	return outputPath.toFile();
}
 
开发者ID:MayerTh,项目名称:RVRPSimulator,代码行数:22,代码来源:ResultData.java

示例15: createUnmarshaller

import javax.xml.bind.ValidationEvent; //导入依赖的package包/类
protected Unmarshaller createUnmarshaller() throws JAXBException, SAXException, FileNotFoundException,
    MalformedURLException {
    Unmarshaller unmarshaller = getContext().createUnmarshaller();
    if (schema != null) {
        unmarshaller.setSchema(cachedSchema);
        unmarshaller.setEventHandler(new ValidationEventHandler() {
            public boolean handleEvent(ValidationEvent event) {
                // stop unmarshalling if the event is an ERROR or FATAL
                // ERROR
                return event.getSeverity() == ValidationEvent.WARNING;
            }
        });
    }

    return unmarshaller;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:JaxbDataFormat.java


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