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 MappingXMLCollection extends XMLCollectionImpl 46 { 47 private static final String RCSRevision = "$Revision: 1.1 $"; 48 private static final String RCSName = "$Name: $"; 49 50 51 public MappingXMLCollection(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 MappingSAXHandler 65 ( 66 this, 67 validationContext, 68 new XMLCollectionImpl.HandlerDestructor() 69 ); 70 validator.setSAXHandler(handler); 71 filers.add(handler); 72 return new XDBCFilerAdapter(validator, handler, handler, handler); 73 } 74 75 80 public boolean removeDocument(String ID) throws XMLDBCException 81 { 82 protectReadOnlyMethod(); 83 List usingCollections = repConnection.getCollectionsUsingMapping(ID); 85 if (usingCollections.size() != 0) 86 throw new RepositoryException(RepositoryException.NOT_ALLOWED, "Mapping is still used by the " 87 + usingCollections + " collections."); 88 return super.removeDocument(ID); 89 } 90 91 public int removeAllDocuments() throws XMLDBCException 92 { 93 protectReadOnlyMethod(); 94 Iterator it = getIdentifierList().iterator(); 95 int docCount = 0; 96 97 while (it.hasNext()) 98 { 99 try 100 { 101 removeDocument((String )it.next()); 102 docCount++; 103 } 104 catch (RepositoryException e) 105 { 106 if (e.getCode() != RepositoryException.NOT_ALLOWED) 107 throw e; 108 } 110 } 111 return docCount; 112 } 113 114 119 public boolean renameDocument(String oldID, String newID) throws XMLDBCException 120 { 121 protectReadOnlyMethod(); 122 List usingCollections = repConnection.getCollectionsUsingMapping(oldID); 124 if (usingCollections.size() != 0) 125 throw new RepositoryException(RepositoryException.NOT_ALLOWED, "Mapping is still used by the " 126 + usingCollections + " collections and cannot be renamed."); 127 return super.renameDocument(oldID, newID); 129 } 130 131 } 132 | Popular Tags |