KickJava   Java API By Example, From Geeks To Geeks.

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


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 XML schemas
44  */

45 public class SchemaXMLCollection extends XMLCollectionImpl
46 {
47     private static final String JavaDoc RCSRevision = "$Revision: 1.2 $";
48     private static final String JavaDoc RCSName = "$Name: $";
49
50     /** Creates new SchemaCollection */
51     public SchemaXMLCollection(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 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         // TO IMPROVE : Not correct new XDBCFilerAdapter must be in front because it auto plugs
74
}
75     
76     // TO DO : ADD a getHandler(SchemaLocator) method...
77
public boolean removeDocument(String JavaDoc ID) throws XMLDBCException
78     {
79         protectReadOnlyMethod();
80         // first check it's not in use
81
List JavaDoc 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 JavaDoc 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         // unload the schema
98
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 JavaDoc it = getIdentifierList().iterator();
108         int docCount = 0;
109         
110         while (it.hasNext())
111         {
112             try
113             {
114                 removeDocument((String JavaDoc)it.next());
115                 docCount++;
116             }
117             catch (RepositoryException e)
118             {
119                 if (e.getCode() != RepositoryException.NOT_ALLOWED)
120                     throw e;
121                 // else schema used continue
122
}
123         }
124         return docCount;
125     }
126     
127     public boolean renameDocument(String JavaDoc oldID, String JavaDoc newID)
128     throws XMLDBCException
129     {
130        throw new UnsupportedOperationException JavaDoc("A schema cannot be renamed since its ID must be the target namespace URI");
131     }
132 }
133
Popular Tags