class DomBasedStubDescriptorFactory implements StubDescriptorFactory {

    @Override
    public synchronized StubDescriptor buildStubDescriptor(final InputStream inputStream) {
        try {
            Document document = xmlDocumentBuilder.buildDocument(inputStream, stubConfigSchema.getSchema());
            validate(document);
            stubResourceHolderUpdater.initializeTemporaryResourceHolder();
            configurationAccess.setProperties();
            StubDescriptor stubDescriptor = descriptorParser.parse(document);
            stubResourceHolderUpdater.updateResourceHolder();
            stubResourceHolderUpdater.clearTemporaryResourceHolder();
            StubDescriptorAttributes attributes = stubDescriptor.getAttributes();
            stubResourceHolderUpdater.addDocumentToResourceHolder(attributes.getGroupName(), document);
            return stubDescriptor;
        } catch (DocumentBuilderException e) {
            throw new DescriptorCannotBeParsedException("Stub descriptor cannot be parsed.", e);
        }
    }

}