當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。