Package javax.xml.bind.util

Examples of javax.xml.bind.util.ValidationEventCollector


                String xsd = this.generateSchema(type);
                SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
                Schema schema = sf.newSchema(new StreamSource(new StringReader(xsd)));

                ValidationEventCollector eventHandler = new ValidationEventCollector();
                unmarshaller.setEventHandler(eventHandler);
                unmarshaller.setSchema(schema);

                JAXBElement<T> element = unmarshaller.unmarshal(source, type);
                if (eventHandler.hasEvents()) {
                    throw generateValidationError(type, eventHandler);
                }

                return element.getValue();
            }
View Full Code Here


        testPluginJarIsReadable(pluginJarFileUrl);

        JarInputStream jis = null;
        JarEntry descriptorEntry = null;
        ValidationEventCollector validationEventCollector = new ValidationEventCollector();
        try {
            jis = new JarInputStream(pluginJarFileUrl.openStream());
            JarEntry nextEntry = jis.getNextJarEntry();
            while (nextEntry != null && descriptorEntry == null) {
                if (PLUGIN_DESCRIPTOR_PATH.equals(nextEntry.getName())) {
View Full Code Here

     * @param is input to check
     * @return parsed PluginDescriptor
     * @throws PluginContainerException if validation fails
     */
    public static PluginDescriptor parsePluginDescriptor(InputStream is) throws PluginContainerException {
        return parsePluginDescriptor(is, new ValidationEventCollector());
    }
View Full Code Here

            URL pluginSchemaURL = getClass().getClassLoader().getResource("rhq-plugin.xsd");
            Schema pluginSchema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(
                pluginSchemaURL);
            unmarshaller.setSchema(pluginSchema);

            ValidationEventCollector validationEventCollector = new ValidationEventCollector();
            unmarshaller.setEventHandler(validationEventCollector);

            PluginDescriptor pluginDescriptor = (PluginDescriptor) unmarshaller.unmarshal(is);

            for (ValidationEvent event : validationEventCollector.getEvents()) {
                log.debug("Plugin [" + pluginDescriptor.getName() + "] descriptor messages {Severity: "
                    + event.getSeverity() + ", Message: " + event.getMessage() + ", Exception: "
                    + event.getLinkedException() + "}");
            }
View Full Code Here

        JAXBContext jaxbContext = JAXBContext.newInstance(DescriptorPackages.PC_PLUGIN);
        URL pluginSchemaURL = getClass().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);
        unmarshaller.unmarshal(descriptorUrl.openStream());
    }
View Full Code Here

        JAXBContext jaxbContext = JAXBContext.newInstance(DescriptorPackages.PC_PLUGIN);
        URL pluginSchemaURL = this.getClass().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);
        if (descriptorUrl == null)
            throw new FileNotFoundException("File " + descriptorFile + " not found");
        return (PluginDescriptor) unmarshaller.unmarshal(descriptorUrl.openStream());
View Full Code Here

        // Enable schema validation
        URL pluginSchemaURL = XmlIndexParser.class.getClassLoader().getResource(PLUGIN_SCHEMA_PATH);
        Schema pluginSchema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(pluginSchemaURL);
        unmarshaller.setSchema(pluginSchema);

        ValidationEventCollector vec = new ValidationEventCollector();
        unmarshaller.setEventHandler(vec);

        BufferedReader reader = new BufferedReader(new InputStreamReader(indexStream));
        JAXBElement<PackageType> packagesXml = (JAXBElement<PackageType>) unmarshaller.unmarshal(reader);

        for (ValidationEvent event : vec.getEvents()) {
            log.debug("URL content source index [" + indexUrl + "] message {Severity: " + event.getSeverity()
                + ", Message: " + event.getMessage() + ", Exception: " + event.getLinkedException() + "}");
        }

        Map<String, RemotePackageInfo> fileList = new HashMap<String, RemotePackageInfo>();
View Full Code Here

    @Test
    public void readDescriptor() throws JAXBException {
        JAXBContext jaxbContext = JAXBContext.newInstance(DescriptorPackages.PC_PLUGIN);

        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        ValidationEventCollector vec = new ValidationEventCollector();
        unmarshaller.setEventHandler(vec);
        PluginDescriptor plugin = (PluginDescriptor) unmarshaller.unmarshal(new File(
            "src/test/xml/rhq-plugin-jmx-server-test.xml"));

        for (ValidationEvent event : vec.getEvents()) {
            System.out.println(event.getSeverity() + ":" + event.getMessage() + "    " + event.getLinkedException());
        }

        System.out.println(plugin.getDisplayName());
    }
View Full Code Here

                    unmarshaller = getServerPluginDescriptorUnmarshaller();
                    Object jaxbElement = unmarshaller.unmarshal(jis);
                    pluginDescriptor = ((JAXBElement<? extends ServerPluginDescriptorType>) jaxbElement).getValue();
                } finally {
                    if (unmarshaller != null) {
                        ValidationEventCollector validationEventCollector =
                                (ValidationEventCollector)unmarshaller.getEventHandler();
                        logValidationEvents(pluginJarFileUrl, validationEventCollector);
                    }
                }
            }
View Full Code Here

        }

        Schema pluginSchema = schemaFactory.newSchema(schemaSources);
        unmarshaller.setSchema(pluginSchema);

        ValidationEventCollector vec = new ValidationEventCollector();
        unmarshaller.setEventHandler(vec);

        return unmarshaller;
    }
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.