1 22 23 28 29 package org.xquark.mapper.storage; 30 31 import java.util.Iterator ; 32 import java.util.List ; 33 34 import org.xquark.mapper.RepositoryException; 35 import org.xquark.mapper.dbms._RepositoryConnection; 36 import org.xquark.mapper.metadata.CollectionMetadata; 37 import org.xquark.mapper.util.DestructionToken; 38 import org.xquark.schema.validation.SchemaValidationContext; 39 import org.xquark.xml.xdbc.XMLDBCException; 40 import org.xquark.xml.xdbc.XMLDocumentFiler; 41 42 45 public class SchemaXMLCollection extends XMLCollectionImpl 46 { 47 private static final String RCSRevision = "$Revision: 1.2 $"; 48 private static final String RCSName = "$Name: $"; 49 50 51 public SchemaXMLCollection(CollectionMetadata metadata, _RepositoryConnection connection, DestructionToken destructor) 52 { 53 super(metadata, connection, destructor); 54 } 55 56 57 public XMLDocumentFiler getDocumentFiler() throws XMLDBCException 58 { 59 protectReadOnlyMethod(); 60 SchemaValidationContext validationContext = 61 new SchemaValidationContext(repConnection.getSchemaManager()); 62 ValidatingFilerAdapter validator = new ValidatingFilerAdapter(validationContext, repConnection); 63 validator.setDocumentBase("http://www.fake.com/"); 64 CollectionFiler handler = new SchemaSAXHandler 65 ( 66 this, 67 validationContext, 68 new XMLCollectionImpl.HandlerDestructor() 69 ); 70 validator.setSAXHandler(handler); 71 filers.add(handler); 72 return new SchemaSavingFilter(new XDBCFilerAdapter(validator, handler, handler, handler)); 73 } 75 76 public boolean removeDocument(String ID) throws XMLDBCException 78 { 79 protectReadOnlyMethod(); 80 List usingCollections = repConnection.getCollectionsUsingNamespace(ID); 82 if (usingCollections.size() != 0) 83 throw new RepositoryException(RepositoryException.NOT_ALLOWED, 84 "This namespace is still used by documents stored in the following collection: " 85 + usingCollections + "."); 86 else 87 { 88 List usingMappings = repConnection.getMappingsUsingNamespace(ID); 89 if (usingMappings.size() != 0) 90 throw new RepositoryException(RepositoryException.NOT_ALLOWED, 91 "This namespace is still used by mapping files: " 92 + usingMappings + "."); 93 } 94 95 boolean ret = super.removeDocument(ID); 96 97 if (ID.equals(NO_NAMESPACE_SCHEMA_ID)) 99 ID = null; 100 getMetadata().getRepository().getSchemaManager().removeSchema(ID); 101 return ret; 102 } 103 104 public int removeAllDocuments() throws XMLDBCException 105 { 106 protectReadOnlyMethod(); 107 Iterator it = getIdentifierList().iterator(); 108 int docCount = 0; 109 110 while (it.hasNext()) 111 { 112 try 113 { 114 removeDocument((String )it.next()); 115 docCount++; 116 } 117 catch (RepositoryException e) 118 { 119 if (e.getCode() != RepositoryException.NOT_ALLOWED) 120 throw e; 121 } 123 } 124 return docCount; 125 } 126 127 public boolean renameDocument(String oldID, String newID) 128 throws XMLDBCException 129 { 130 throw new UnsupportedOperationException ("A schema cannot be renamed since its ID must be the target namespace URI"); 131 } 132 } 133 | Popular Tags |