1 22 23 28 29 package org.xquark.mapper.storage; 30 31 import java.util.List ; 32 33 import org.xml.sax.InputSource ; 34 import org.xquark.mapper.RepositoryException; 35 import org.xquark.mapper.mapping.MappingConstants; 36 import org.xquark.mapper.util.DestructionToken; 37 import org.xquark.schema.Schema; 38 import org.xquark.schema.SchemaConstants; 39 import org.xquark.schema.SchemaManager; 40 import org.xquark.schema.validation.SchemaValidationContext; 41 import org.xquark.xml.xdbc.XMLDBCException; 42 43 46 public class SchemaSAXHandler extends CollectionFiler 47 { 48 private static final String RCSRevision = "$Revision: 1.2 $"; 49 private static final String RCSName = "$Name: $"; 50 51 52 public SchemaSAXHandler(_RepositoryCollection collection, 53 SchemaValidationContext schemaContext, 54 DestructionToken destructor) 55 throws XMLDBCException 56 { 57 super(collection, schemaContext, true, destructor); } 59 60 protected void endParsing()throws Exception 61 { 62 super.endParsing(); 63 flushBuffer(); 65 SchemaManager manager = collection.getMetadata().getRepository().getSchemaManager(); 67 68 Schema schema = manager.loadSchema(collection.getRepositoryConnection(), new InputSource (getDocumentId())); 70 if (schema == null) 71 throw new RepositoryException(RepositoryException.CONSISTENCY_ERROR, "The schema could not be loaded."); 72 73 String targetNamespace = schema.getNamespace(); 74 if (targetNamespace == null) 75 targetNamespace = NO_NAMESPACE_SCHEMA_ID; 76 else if (targetNamespace.equals(SchemaConstants.XMLSCHEMA_URI) 77 || targetNamespace.equals(MappingConstants.MAPPING_URI)) 78 throw new RepositoryException(RepositoryException.ALREADY_EXISTS, 79 "This schema could not be stored in the repository since it is a system schema."); 80 81 List usingCollections = collection.getRepositoryConnection().getCollectionsUsingNamespace(targetNamespace); 83 if (usingCollections.size() != 0) 84 throw new RepositoryException(RepositoryException.NOT_ALLOWED, 85 "This namespace is still used by documents stored in the following collection: " 86 + usingCollections + ". Adding such a schema would alter the metadata for these documents."); 87 else 88 { 89 List usingMappings = collection.getRepositoryConnection().getMappingsUsingNamespace(targetNamespace); 90 if (usingMappings.size() != 0) 91 throw new RepositoryException(RepositoryException.NOT_ALLOWED, 92 "This namespace is still used by mapping files: " 93 + usingMappings + ". Adding such a schema would alter the metadata for these documents."); 94 } 95 96 if (collection.containsDocument(targetNamespace)) throw new RepositoryException(RepositoryException.ALREADY_EXISTS, 99 "The namespace of the schema is already in use in the system repository."); 100 ((SchemaXMLCollection)collection).renameDocument(getDocumentId(), targetNamespace, false); docID = targetNamespace; 104 } 105 106 } 107 | Popular Tags |