class JdomAnalysisRule implements AnalysisRule {

    @Override
    @SuppressWarnings("unchecked")
    public Set<Violation> analyze(final String prgXml) {
        final Set<Violation> violations = new HashSet<Violation>();
        try {
            final ClassLoaders classLoaders = new ClassLoaders();
            final Class<Document>[] classes = new Class[] { Document.class };
            final Document[] objects = new Document[] { new SAXBuilder().build(new StringReader(prgXml)) };
            classLoaders.put(Document.class.getClassLoader());
            final Enumeration<Delegate> delegates = Service.providers(new SPInterface(Delegate.class, classes, objects),
                    classLoaders);
            if (delegates != null) {
                String rulesToSkip = System.getProperty("rulesToSkip");
                if (rulesToSkip != null) {
                    rulesToSkip = ".*(" + rulesToSkip.replace(",", "|") + ")";
                }
                while (delegates.hasMoreElements()) {
                    Delegate delegate = delegates.nextElement();
                    if (rulesToSkip == null || !delegate.getClass().getName().matches(rulesToSkip)) {
                        violations.addAll(delegate.analyze());
                    }
                }
            }
        } catch (final JDOMException | IOException e) {
            throw new JdomException("Failed to analyze XML.", e);
        }
        return violations;
    }

}