KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xquery > metadata > MetaWrapper


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 package org.xquark.xquery.metadata;
25
26 import java.util.*;
27
28 import org.xml.sax.SAXException JavaDoc;
29 import org.xquark.xquery.metadata.resolver.CollectionMetadata;
30 import org.xquark.xquery.metadata.resolver.SourceMetadata;
31
32 // ***************************************************************************
33
// * Class 'MetaWrapper'
34
// ***************************************************************************
35

36 public class MetaWrapper implements SourceMetadata{
37     
38     // **********************************************************************
39
// * Constant
40
// **********************************************************************
41
private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
42     private static final String JavaDoc RCSName = "$Name: $";
43     // **********************************************************************
44
// * Fields
45
// **********************************************************************
46
private HashMap metacollections = null;
47     private String JavaDoc sourcename = null;
48     private MetaDataImpl metadata = null ;
49
50     
51     
52     // **********************************************************************
53
// * Constructor
54
// **********************************************************************
55
/**
56      * Construct the class MetaWrapper
57      *
58      * @param
59      */

60     public MetaWrapper(MetaDataImpl metadata) {
61         initMetaCollections();
62         this.metadata = metadata;
63     }
64
65     // use for importing this with new MetaData reference
66
public MetaWrapper(MetaDataImpl metadata, MetaWrapper oldwrapper) {
67         this.metadata = metadata;
68         initMetaCollections();
69         HashMap hm = oldwrapper.getMetaCollections () ;
70         for (Iterator it = hm.values ().iterator () ; it.hasNext () ; )
71         {
72             MetaCollection col = (MetaCollection) it.next () ;
73             MetaCollection newmetacol = new MetaCollection (metadata, col) ;
74             addMetaCollection (newmetacol) ;
75         }
76     }
77     
78     
79     // **********************************************************************
80
// * Methods
81
// **********************************************************************
82
/**
83      *
84      */

85     public void addMetaCollection(MetaCollection metacollection) {
86         // incorrect argument
87
if (metacollection == null) {
88             System.err.println("metacollection null") ;
89             return;
90         }
91         // get name of collection
92
String JavaDoc key = metacollection.getCollectionName();
93         // incorrect name
94
if (key == null) {
95             System.err.println("incorrect key name") ;
96             return;
97         }
98         // initialize collections if necessary
99
if (metacollections == null) {
100             initMetaCollections();
101         }
102         // verify collection of same name not present
103
if (metacollections.get(key) != null) {
104             return;
105         }
106         // add collection
107
metacollections.put(key, metacollection);
108     }
109     
110     
111     /**
112      *
113      */

114     public void initMetaCollections() {
115         metacollections = new HashMap();
116     }
117     
118     
119     /**
120      *
121      */

122     public String JavaDoc getSourceName() {
123         return sourcename;
124     }
125     
126     
127     /**
128      *
129      */

130     public void setSourceName(String JavaDoc sourcename) {
131         this.sourcename = sourcename;
132     }
133     
134     
135
136     
137     public Collection getCollectionsMetadata() {
138         if (metacollections == null) return null;
139         return metacollections.values();
140     }
141     
142     
143     /**
144      * Return the schematrees associated with this wrapper
145      */

146     public HashMap getSchemaTrees() throws SAXException JavaDoc {
147         HashMap collections = new HashMap();
148         Iterator it = metacollections.entrySet().iterator();
149         while (it.hasNext()) {
150             Map.Entry entry = (Map.Entry)it.next();
151             MetaCollection col = (MetaCollection)entry.getValue();
152             if (col.getXTree() != null) collections.put((String JavaDoc)entry.getKey(),col.getXTree());
153         }
154         return collections;
155     }
156     
157     public MetaCollection getMetaCollection(String JavaDoc colName) {
158         if (metacollections == null) return null;
159         return (MetaCollection)metacollections.get(colName);
160 // Collection metacols = metacollections.values();
161
// for (Iterator it = metacols.iterator();it.hasNext();) {
162
// MetaCollection metacol = (MetaCollection)it.next();
163
// if (metacol.getCollectionName().equals(colName))
164
// return metacol;
165
// }
166
// return null;
167
}
168
169     public HashMap getMetaCollections() {
170         return metacollections ;
171     }
172     
173     public MetaDataImpl getMetaData() {
174         return metadata ;
175     }
176     
177     public CollectionMetadata getCollectionMetadata(String JavaDoc colname) {
178         if (metacollections == null) return null;
179         return (CollectionMetadata)metacollections.get(colname.toUpperCase());
180     }
181     
182     public boolean isCaseSensitive() { return false; }
183     
184     public boolean isStrict() { return false; }
185
186     public List getCollectionsName ()
187     {
188         if (metacollections == null) return null;
189         List al = new ArrayList () ;
190         al.addAll(metacollections.keySet());
191 /*
192         for (Iterator it = metacollections.values ().iterator () ; it.hasNext () ; )
193         {
194 // MetaCollection col = (MetaCollection) it.next () ;
195 // String colname = col.getCollectionName () ;
196 // if ((colname != null) && (! al.contains (colname)))
197 // al.add (colname) ;
198             al.add(((MetaCollection) it.next()).getCollectionName());
199         }
200 */

201         return al ;
202
203     }
204     // **********************************************************************
205
// * Destructor
206
// **********************************************************************
207
/**
208      * Dereference allocated object which will be further be destroy
209      * by the garbage collector.
210      */

211     protected void finalize()
212     throws Throwable JavaDoc {
213         
214     }
215 }
216
Popular Tags