KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mapper > storage > MappingXMLCollection


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 /*
24  * SchemaCollection.java
25  *
26  * Created on 29 mai 2001, 11:27
27  */

28
29 package org.xquark.mapper.storage;
30
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
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 /**
43  * Special XML Collection for storing mappings
44  */

45 public class MappingXMLCollection extends XMLCollectionImpl
46 {
47 private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
48 private static final String JavaDoc RCSName = "$Name: $";
49
50     /** Creates new SchemaCollection */
51     public MappingXMLCollection(CollectionMetadata metadata, _RepositoryConnection connection,DestructionToken destructor)
52     {
53         super(metadata, connection, destructor);
54     }
55
56     /* Overriding */
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     /** Remove an XML document from this repository.
76      * @param ID The name used to identify the document in
77      * the repository.
78      * @throws RepositoryException Application exception.
79      */

80     public boolean removeDocument(String JavaDoc ID) throws XMLDBCException
81     {
82         protectReadOnlyMethod();
83         // Check in the dbms that the mapping file is not used by an existing collection
84
List JavaDoc 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 JavaDoc it = getIdentifierList().iterator();
95         int docCount = 0;
96         
97         while (it.hasNext())
98         {
99             try
100             {
101                 removeDocument((String JavaDoc)it.next());
102                 docCount++;
103             }
104             catch (RepositoryException e)
105             {
106                 if (e.getCode() != RepositoryException.NOT_ALLOWED)
107                     throw e;
108                 // else mapping used : continue
109
}
110         }
111         return docCount;
112     }
113     
114     /** Rename an XML document. That is to say, change its ID.
115      * @param oldID The old ID of the document.
116      * @param newID new ID of the document.
117      * @throws RepositoryException Application exception.
118      */

119     public boolean renameDocument(String JavaDoc oldID, String JavaDoc newID) throws XMLDBCException
120     {
121         protectReadOnlyMethod();
122         // Check in the dbms that the mapping file is not used by an existing collection
123
List JavaDoc 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         // TO IMPROVE change collection reference
128
return super.renameDocument(oldID, newID);
129     }
130     
131 }
132
Popular Tags