Package javax.xml.bind.util

Examples of javax.xml.bind.util.ValidationEventCollector


    }
   
    // Convert the ComponentListType into a JAXBElement.
    ObjectFactory objFactory = new ObjectFactory();
    JAXBElement<ComponentListType> element = objFactory.createComponents(primaryObject);
    ValidationEventCollector validationEventCollector =
                                             new ValidationEventCollector();

    FileOutputStream fileOut = null;

    // open file
    if (file == null || file.equals("")) {
View Full Code Here


      throw new IllegalArgumentException(
          "XMLPersistence: File name is null, the empty string, or does not" +
          " exist.");
    }
   
    ValidationEventCollector validationEventCollector =
                                       new ValidationEventCollector();
    Schema schema;
    JAXBElement<ComponentListType> root = null;
    String errStr = null;
    ComponentListType componentListType = null;
   
View Full Code Here

    try {
      // Combine and apply schemas to the marshaller
      if (!schemabuilt && !sources.isEmpty()) {
        marshaller.setSchema(buildValidatingSchema());
        marshaller.setEventHandler(new ValidationEventCollector());
        schemabuilt = true;
      }

      // Marshall
      marshaller.marshal(xmlroot, output);

      // Check for validation errors (if validating)
      if (marshaller.getSchema() != null) {
        ValidationEventCollector vec = (ValidationEventCollector)marshaller.getEventHandler();
        if (vec.hasEvents()) {
          StringBuilder eventlist = new StringBuilder();
          for (ValidationEvent event: vec.getEvents()) {
            eventlist.append(event.getMessage()).append("\n");
          }
          throw new XMLException("Validation errors were detected in the output: " +
              eventlist.toString().trim());
        }
View Full Code Here

    try {
      // Combine and apply schemas to the unmarshaller
      if (!schemabuilt && !sources.isEmpty()) {
        unmarshaller.setSchema(buildValidatingSchema());
        unmarshaller.setEventHandler(new ValidationEventCollector());
        schemabuilt = true;
      }

      // Unmarshall
      T xmlroot = (T)unmarshaller.unmarshal(input);

      // Check for validation errors (if validating)
      if (unmarshaller.getSchema() != null) {
        ValidationEventCollector vec = (ValidationEventCollector)unmarshaller.getEventHandler();
        if (vec.hasEvents()) {
          StringBuilder eventlist = new StringBuilder();
          for (ValidationEvent event: vec.getEvents()) {
            eventlist.append(event.getMessage()).append("\n");
          }
          throw new XMLException("Validation errors were detected in the input: " +
              eventlist.toString().trim());
        }
View Full Code Here

             */
            InputSource inputSource = replaceTokensForParsing(configReader);

            SAXSource saxSource = new SAXSource(reader, inputSource);
            JAXBContext jc = JAXBContext.newInstance(ClientContainer.class );
            final ValidationEventCollector vec = new ValidationEventCollector();
           
            Unmarshaller u = jc.createUnmarshaller();
            u.setEventHandler(vec);
            result = (ClientContainer) u.unmarshal(saxSource);
            if (vec.hasEvents()) {
                /*
                 * The parser reported at least one warning or error.  If all
                 * events were warnings, display them as a message and continue.
                 * Otherwise there was at least one error or fatal, so say so
                 * and try to continue but say that such errors might be fatal
                 * in future releases.
                 */
                boolean isError = false;
                final StringBuilder sb = new StringBuilder();
                for (ValidationEvent ve : vec.getEvents()) {
                    sb.append(ve.getMessage()).append(LINE_SEP);
                    isError |= (ve.getSeverity() != ValidationEvent.WARNING);
                }
                final String messageIntroduction = localStrings.getLocalString(
                            AppClientFacade.class,
View Full Code Here

                }
                Schema schema = XMLUtils.getSchema(jc);
                schemas.putIfAbsent(jc, schema);
            }
          Unmarshaller u = jc.createUnmarshaller();
          ValidationEventCollector validationHandler = new ValidationEventCollector();
      u.setEventHandler(validationHandler);
          setSchema(jc, u);
          Object obj = u.unmarshal(reader);
          if (!clazz.isAssignableFrom(obj.getClass())) {
              throw CougarMarshallingException.unmarshallingException("xml", "Deserialised object was not of class "+clazz.getName(),false);
View Full Code Here

             */
            InputSource inputSource = replaceTokensForParsing(configReader);

            SAXSource saxSource = new SAXSource(reader, inputSource);
            JAXBContext jc = JAXBContext.newInstance(ClientContainer.class );
            final ValidationEventCollector vec = new ValidationEventCollector();

            Unmarshaller u = jc.createUnmarshaller();
            u.setEventHandler(vec);
            result = (ClientContainer) u.unmarshal(saxSource);
            if (vec.hasEvents()) {
                /*
                 * The parser reported at least one warning or error.  If all
                 * events were warnings, display them as a message and continue.
                 * Otherwise there was at least one error or fatal, so say so
                 * and try to continue but say that such errors might be fatal
                 * in future releases.
                 */
                boolean isError = false;
                final StringBuilder sb = new StringBuilder();
                for (ValidationEvent ve : vec.getEvents()) {
                    sb.append(ve.getMessage()).append(LINE_SEP);
                    isError |= (ve.getSeverity() != ValidationEvent.WARNING);
                }
                final String messageIntroduction = localStrings.getLocalString(
                            AppClientFacade.class,
View Full Code Here

    public Node2JAXB(ExtensionPointRegistry registry) {
        contextHelper = JAXBContextHelper.getInstance(registry);
    }

    public Object transform(Node source, TransformationContext context) {
        ValidationEventCollector validationEventCollector = new ValidationEventCollector();
        Object response = null;
        if (source == null)
            return null;
        try {
            JAXBContext jaxbContext = contextHelper.createJAXBContext(context, false);
            Object result;
            // TUSCANY-3791
            synchronized(source){
                /* some debug code
                System.setProperty("jaxb.debug", "true");
                unmarshaller.setListener(new DebugListener());
                */
                Unmarshaller unmarshaller = contextHelper.getUnmarshaller(jaxbContext);
                try {
                    validationEventCollector.reset();
                    unmarshaller.setEventHandler(validationEventCollector);
                    result = unmarshaller.unmarshal(source, JAXBContextHelper.getJavaType(context.getTargetDataType()));
                } finally {
                    contextHelper.releaseJAXBUnmarshaller(jaxbContext, unmarshaller);
                }
            }
            response = JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result);
        } catch (Exception e) {
            throw new TransformationException(e);
        }
       
        if (validationEventCollector.hasEvents()){
            String validationErrors = "";
            for(ValidationEvent event : validationEventCollector.getEvents()){
                validationErrors += "Event: " + event.getMessage() + " ";
            }
            throw new TransformationException(validationErrors);
        }
        return response;
View Full Code Here

TOP

Related Classes of javax.xml.bind.util.ValidationEventCollector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.