Project

General

Profile

1
package eu.dnetlib.enabling.is.registry.schema;
2

    
3
import java.io.StringReader;
4

    
5
import javax.xml.XMLConstants;
6
import javax.xml.transform.stream.StreamSource;
7
import javax.xml.validation.Schema;
8
import javax.xml.validation.SchemaFactory;
9

    
10
import org.apache.commons.logging.Log;
11
import org.apache.commons.logging.LogFactory;
12
import org.springframework.beans.factory.annotation.Required;
13
import org.xml.sax.SAXException;
14

    
15
import eu.dnetlib.rmi.enabling.ISLookUpException;
16
import eu.dnetlib.rmi.enabling.ISLookUpService;
17

    
18
/**
19
 * manages the resource schemas through the registry service.
20
 * 
21
 * @author marko
22
 * 
23
 */
24
public class ResourceSchemaDAOImpl implements ResourceSchemaDAO {
25

    
26
	private ISLookUpService isLookup;
27

    
28
	/**
29
	 * logger.
30
	 */
31
	private static final Log log = LogFactory.getLog(ResourceSchemaDAOImpl.class); // NOPMD by marko on 11/24/08 5:02 PM
32

    
33
	/**
34
	 * {@inheritDoc}
35
	 * 
36
	 * @see eu.dnetlib.enabling.is.registry.schema.ResourceSchemaDAO#getResourceSchema(java.lang.String)
37
	 */
38
	@Override
39
	public Schema getResourceSchema(final String resourceType) {
40
		try {
41
			final String schemaSource = isLookup.getResourceTypeSchema(resourceType);
42
			if (schemaSource == null || schemaSource.isEmpty()) {
43
				log.warn("cannot find resource type " + resourceType);
44
				return null;
45
			}
46
			return SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(new StreamSource(new StringReader(schemaSource)));
47
		} catch (ISLookUpException e) {
48
			log.warn("cannot find resource type" + resourceType, e);
49
			return null;
50
		} catch (SAXException e) {
51
			log.fatal("cannot parse resource type schema", e);
52
			return null;
53
		}
54
	}
55

    
56
	public ISLookUpService getIsLookup() {
57
		return isLookup;
58
	}
59

    
60
	@Required
61
	public void setIsLookup(final ISLookUpService isLookup) {
62
		this.isLookup = isLookup;
63
	}
64

    
65
}
(4-4/4)