KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xquery > metadata > resolver > PathResolver


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.resolver;
25
26 import java.util.*;
27
28 import org.xquark.xpath.Axis;
29 import org.xquark.xpath.TypedXTreeNode;
30 import org.xquark.xpath.XTree;
31 import org.xquark.xquery.parser.*;
32 import org.xquark.xquery.parser.primitivefunctions.fnfunctions.FunctionCOLLECTION;
33 import org.xquark.xquery.parser.primitivefunctions.fnfunctions.FunctionDOC;
34
35 // ***************************************************************************
36
// * Class 'PathResolver'
37
// ***************************************************************************
38

39 /**
40  * The PathResolver is a class that allow resolving any path expression given in
41  * argument. The class structure is organized as following :
42  *
43  * <pre>
44  * PathResolver
45  * '-------------------------------------------------------------------------`
46  * | Path |
47  * | '-----------------------------------------------------------------` |
48  * | | Source | |
49  * | | '-----------------------------------` | |
50  * | | | ElementPath | | |
51  * | | | '------------` | | |
52  * | | | | node | | | |
53  * | | | sourcename '------------` | | |
54  * | | | | | | | |
55  * | | | '------------` | | |
56  * | | | | | | | |
57  * | | | '------------` | | |
58  * | | pathname `-----------------------------------' | |
59  * | | | |
60  * | | '-----------------------------------` | |
61  * | | | '------------` | | |
62  * | | | | | | | |
63  * | | | '------------` | | |
64  * | | | | | | | |
65  * | | | '------------` | | |
66  * | | | | | | | |
67  * | | | '------------` | | |
68  * | | `-----------------------------------' | |
69  * | `-----------------------------------------------------------------' |
70  * | |
71  * | '-----------------------------------------------------------------` |
72  * | | '-----------------------------------` | |
73  * | | | '------------` | | |
74  * | | | | | | | |
75  * | | | '------------` | | |
76  * | | | | | | | |
77  * | | | '------------` | | |
78  * | | | | | | | |
79  * | | | '------------` | | |
80  * | | `-----------------------------------' | |
81  *
82  * [...]
83  *
84  *
85  * '-------------------------------------------------------------------------`
86  * </pre>
87  *
88  */

89 public class PathResolver {
90     private static final String JavaDoc RCSRevision = "$Revision: 1.10 $";
91     private static final String JavaDoc RCSName = "$Name: $";
92     // **********************************************************************
93
// * Constant
94
// **********************************************************************
95
//public final static String COLLECTION = "collection";
96
//public final static char OPEN_PARENTHESIS = '(';
97
//public final static String CLOSE_PARENTHESIS = ")";
98
//public final static String COMA = ",";
99
public final static String JavaDoc COLON = ":";
100     public final static String JavaDoc STAR = "*";
101
102     // **********************************************************************
103
// * Fields
104
// **********************************************************************
105
/**
106      * A reference on the metadata
107      */

108     private MetadataAccess metadata = null;
109
110     /**
111      * A vector of Path.
112      */

113     private ArrayList resolvers = new ArrayList();
114
115     // for extraction speed up
116
private String JavaDoc path = null;
117     private ArrayList restrictedCollection = new ArrayList(1);
118     private ArrayList restrictedSource = new ArrayList(1);
119     private String JavaDoc restrictedDocument = null;
120
121     private Set sourceNames = new HashSet();
122     private Set urls = new HashSet();
123     private ArrayList nodes = new ArrayList(1);
124     // **********************************************************************
125
// * Constructor
126
// **********************************************************************
127

128     public PathResolver(MetadataAccess metadata) {
129         this.metadata = metadata;
130     }
131
132     private void clear() {
133         resolvers.clear();
134         sourceNames = new HashSet();
135         urls = new HashSet();
136         nodes = new ArrayList(1);
137     }
138     
139     // resolving paths
140
public void resolveSteps(InputFunctionCall expr) throws XQueryException {
141         if (expr == null)
142             return;
143         clear();
144         extractRestriction(expr);
145         Path p = null;
146         // if ((restrictedCollection == null) || (restrictedCollection.isEmpty()))
147
// p = new Path(steps, lemaker, metadata, null, null);
148
// else
149
p = new Path(expr, metadata, restrictedSource, restrictedCollection, restrictedDocument);
150         p.init();
151         resolvers.add(p);
152     }
153
154     public void resolveSteps(ArrayList steps) throws XQueryException {
155         if (steps == null || steps.isEmpty())
156             return;
157         clear();
158         extractRestriction((org.xquark.xquery.parser.Step) steps.get(0));
159         Path p = null;
160         // if ((restrictedCollection == null) || (restrictedCollection.isEmpty()))
161
// p = new Path(steps, lemaker, metadata, null, null);
162
// else
163
p = new Path(steps, metadata, restrictedSource, restrictedCollection, restrictedDocument);
164         p.init();
165         resolvers.add(p);
166     }
167
168     public void resolveStepsList(ArrayList stepslist) throws XQueryException {
169         if (stepslist == null || stepslist.isEmpty())
170             return;
171         clear();
172         for (int i = 0; i < stepslist.size(); i++) {
173             ArrayList steps = (ArrayList) stepslist.get(i);
174             if (steps == null || steps.isEmpty())
175                 continue;
176             extractRestriction((org.xquark.xquery.parser.Step) steps.get(0));
177             Path p = null;
178             // if ((restrictedCollection == null) || (restrictedCollection.isEmpty()))
179
// p = new Path(steps, lemaker, metadata, null, null);
180
// else
181
p = new Path(steps, metadata, restrictedSource, restrictedCollection, restrictedDocument);
182             p.init();
183             resolvers.add(p);
184         }
185     }
186
187     // for decomposing
188
private void extractRestriction(org.xquark.xquery.parser.XQueryExpression expr) {
189         restrictedCollection.clear();
190         restrictedSource.clear();
191         restrictedDocument = null;;
192         if (expr instanceof FunctionCOLLECTION) {
193             FunctionCOLLECTION funCol = (FunctionCOLLECTION)expr;
194             restrictedCollection.add(funCol.getCollectionName());
195             restrictedSource.add(funCol.getSourceName());
196         } else if (expr instanceof FunctionDOC) {
197             restrictedDocument = ((FunctionCall) expr).getArgument(0).getStringValue();
198         }
199     }
200     
201     private void extractRestriction(org.xquark.xquery.parser.Step step) {
202         extractRestriction(step.getExpression());
203     }
204
205     // private final String EVAL_SOURCE_NAME = "EVAL";
206
// private int evalSourceIndex = 0;
207

208     // **********************************************************************
209
// * Methods
210
// **********************************************************************
211

212 // /**
213
// * Return all path expression.
214
// *
215
// * @return a vector of all path name.
216
// */
217
// public ArrayList getPathNames() {
218
// if (!pathNames.isEmpty()) return pathNames;
219
// for (int i = 0; i < resolvers.size(); i++) {
220
// String pathname = ((Path) resolvers.get(i)).getPathName();
221
// if (!pathNames.contains(pathname))
222
// pathNames.add(pathname);
223
// }
224
// return pathNames;
225
// }
226

227     /**
228      * Return all sources names referenced.
229      *
230      * @return a vector of source name.
231      */

232     public Set getSourceNames() {
233         if (!sourceNames.isEmpty()) return sourceNames;
234         for (int i = 0; i < resolvers.size(); i++) {
235             ArrayList sources = ((Path) resolvers.get(i)).getSourceNames();
236             if (sources == null)
237                 continue;
238             for (int j = 0; j < sources.size(); j++) {
239                 String JavaDoc sourcename = (String JavaDoc) sources.get(j);
240                 if (!sourceNames.contains(sourcename))
241                 sourceNames.add(sourcename);
242             }
243         }
244         return sourceNames;
245     }
246
247     public Set getUrls() {
248         if (!urls.isEmpty()) return urls;
249         for (int i = 0; i < resolvers.size(); i++) {
250             String JavaDoc tmpstr = ((Path) resolvers.get(i)).getUrl();
251             if (tmpstr == null)
252                 continue;
253             if (!urls.contains(tmpstr))
254                 urls.add(tmpstr);
255         }
256         return urls;
257     }
258 // public ArrayList getArraySources() {
259
// ArrayList v = new ArrayList();
260
// for (int i = 0; i < resolvers.size(); i++) {
261
// ArrayList sources = ((Path) resolvers.get(i)).getSourceName();
262
// if (sources == null)
263
// continue;
264
// for (int j = 0; j < sources.size(); j++) {
265
// String sourcename = (String) sources.get(j);
266
// if (!v.contains(sourcename))
267
// v.add(sourcename);
268
// }
269
// }
270
// return v;
271
// }
272

273 // /**
274
// * Return all sources names for a given path expression.
275
// *
276
// * @param pathname the path expression to search source for.
277
// *
278
// * @return a vector of source name.
279
// */
280
// public ArrayList getSources(String pathname) {
281
// Path pname = getPathByPathName(pathname);
282
// if (pname == null)
283
// return null;
284
// return pname.getSourceNames();
285
// }
286

287 // // gets a path by full path name
288
// private Path getPathByFullPathName(String fullpathname) {
289
// for (int i = 0; i < resolvers.size(); i++) {
290
// Path pi = (Path) resolvers.get(i);
291
// if (fullpathname.equals(pi.getFullPathName()))
292
// return pi;
293
// }
294
// return null;
295
// }
296

297     /**
298      * Return the Path class whith the given name.
299      *
300      * @param orig_pathname the name of the Path class to return
301      *
302      * @return a reference on the associated Path class.
303      */

304     private Path getPathByPathName(String JavaDoc pathname) {
305         for (int i = 0; i < resolvers.size(); i++) {
306             Path pi = (Path) resolvers.get(i);
307             if (pathname.equals(pi.getPathName()))
308                 return pi;
309         }
310         return null;
311     }
312
313     /**
314      * Return all nodes answering the set of path expression, in all sources.
315      *
316      * @return a vector of nodes.
317      */

318     public ArrayList getNodes() {
319         if (!nodes.isEmpty()) return nodes;
320         for (int i = 0; i < resolvers.size(); i++) {
321             ArrayList elementnodes = ((Path) resolvers.get(i)).getNodes();
322             if (elementnodes != null)
323                 for (int j = 0; j < elementnodes.size(); j++) {
324                     TypedXTreeNode nodej = (TypedXTreeNode) elementnodes.get(j);
325                     // Ca ca marche pas bien (Stack overflow) : je commente en attendant, mais il va
326
// y avoir des doublons...
327
//if (! v.contains (nodej))
328
nodes.add(nodej);
329                 }
330         }
331         return nodes;
332     }
333
334     // **********************************************************************
335
// * Destructor
336
// **********************************************************************
337

338     /**
339      * Dereference allocated object which will be further be destroy
340      * by the garbage collector.
341      */

342     protected void finalize() throws Throwable JavaDoc {
343         super.finalize();
344         metadata = null;
345         resolvers = null;
346     }
347 }
348
349 /* ************************************************************************ */
350
351 /**
352  * A Path class. Used to describe a "XPath" path no considering
353  * the number of sources where the matching nodes are.
354  *
355  *
356  */

357 class Path {
358     private static final String JavaDoc RCSRevision = "$Revision: 1.10 $";
359     private static final String JavaDoc RCSName = "$Name: $";
360     private String JavaDoc pathname = null;
361     private String JavaDoc fullpathname = null;
362     private ArrayList sources = null;
363     private MetadataAccess metadata = null;
364     //private LocationExpression locationexpression = null;
365
private ArrayList steps = null;
366
367     private ArrayList restrictedSource = null;
368     private ArrayList restrictedCollection = null;
369     private String JavaDoc restrictedDocument = null;
370     private ArrayList nodes = null;
371
372     /**
373      * Create a path expression.
374      *
375      * @param pathname the name of the path
376      * (eg. <pre>//person/ * /town/ * /zip</pre>)
377      * @param metadata a reference on metadata in order to resolve the
378      * path expression.
379      */

380
381     public Path(ArrayList steps, MetadataAccess metadata, ArrayList restrictedSource, ArrayList restrictedCollection, String JavaDoc restrictedDocument) throws XQueryException {
382         // temporary code
383
this.steps = (ArrayList)steps.clone();
384         fullpathname = printSteps(steps, 0);
385         if (((org.xquark.xquery.parser.Step) steps.get(0)).getExpression() instanceof FunctionCOLLECTION) {
386             pathname = printSteps(steps, 1);
387             if (this.steps.size() == 1)
388                 this.steps = null;
389             else
390                 this.steps.remove(0);
391         }
392         else {
393             pathname = fullpathname;
394         }
395         //------------------
396
//sources = new ArrayList() ;
397
this.metadata = metadata;
398         if (restrictedSource.isEmpty())
399             restrictedSource = null;
400         this.restrictedSource = restrictedSource;
401         if (restrictedCollection.isEmpty())
402             restrictedCollection = null;
403         this.restrictedCollection = restrictedCollection;
404         this.restrictedDocument = restrictedDocument;
405         //this.locationexpression = lemaker.make(steps);
406
//this.steps = steps;
407
}
408
409     public Path(InputFunctionCall expr, MetadataAccess metadata, ArrayList restrictedSource, ArrayList restrictedCollection, String JavaDoc restrictedDocument) throws XQueryException {
410         // temporary code
411
fullpathname = expr.toString();
412         pathname = "";
413         //------------------
414
//sources = new ArrayList() ;
415
this.metadata = metadata;
416         if (restrictedSource.isEmpty())
417             restrictedSource = null;
418         this.restrictedSource = restrictedSource;
419         if (restrictedCollection.isEmpty())
420             restrictedCollection = null;
421         this.restrictedCollection = restrictedCollection;
422         this.restrictedDocument = restrictedDocument;
423         //this.locationexpression = null;
424
}
425
426
427     private String JavaDoc printSteps(ArrayList steps, int minIndex) {
428         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
429         for (int i = minIndex; i < steps.size(); i++) {
430             org.xquark.xquery.parser.Step stepi = (org.xquark.xquery.parser.Step) steps.get(i);
431             boolean separator = stepi.hasSeparator();
432             int axis = stepi.getAxis();
433             if (separator)
434                 buf.append('/');
435             if (axis != -1)
436                 buf.append(Axis.AXISSTRINGS[axis]);
437             buf.append(stepi.getExpression().toString());
438         }
439         return buf.toString();
440     }
441
442     /**
443      * initialize a Path structure (mandatory). Usually this should be called
444      * by the PathResolver initialization
445      */

446     public void init() {
447         if (restrictedDocument != null)
448             return;
449
450         Collection sourceCollection = metadata.getSources();
451         Iterator sourceIterator = sourceCollection.iterator();
452         while (sourceIterator.hasNext()) {
453             SourceMetadata sourceMetadata = (SourceMetadata) sourceIterator.next();
454             String JavaDoc sourcename = sourceMetadata.getSourceName();
455
456             if (restrictedSource != null)
457                 if ((!restrictedSource.contains(PathResolver.STAR)) && (!restrictedSource.contains(sourcename))) {
458                     continue;
459                 }
460
461             Collection collections = sourceMetadata.getCollectionsMetadata();
462             Iterator collectionsIterator = collections.iterator();
463
464             Source source = new Source(sourcename);
465             boolean sourceIsValid = false;
466             while (collectionsIterator.hasNext()) {
467                 CollectionMetadata collectionMetadata = (CollectionMetadata) collectionsIterator.next();
468                 String JavaDoc colname = collectionMetadata.getCollectionName();
469
470                 if (restrictedCollection != null) {
471                     boolean found = false;
472                     for (int r = 0; r < restrictedCollection.size(); r++) {
473                         String JavaDoc str = (String JavaDoc) restrictedCollection.get(r);
474                         if (!str.equals(PathResolver.STAR)) {
475                             if ((sourceMetadata.isCaseSensitive() && !str.equals(colname) && !colname.endsWith("." + str))) {
476                                 continue;
477                             }
478                             if (!sourceMetadata.isCaseSensitive()) {
479                                 if (str.equalsIgnoreCase(colname)) {
480                                     /* found */
481                                 } else {
482                                     int startIndex = colname.length() - str.length() - 1;
483                                     if (0 > startIndex) {
484                                         continue;
485                                     }
486                                     String JavaDoc suffix = colname.substring(startIndex, colname.length());
487                                     if (!suffix.equalsIgnoreCase("." + str)) {
488                                         continue;
489                                     }
490                                 }
491                             }
492                         }
493
494                         String JavaDoc sname = (String JavaDoc) restrictedSource.get(r);
495                         if ((!sname.equals(PathResolver.STAR)) && ((!sname.equals(sourcename))))
496                             continue;
497
498                         found = true;
499                         break;
500                     }
501                     if (!found)
502                         continue;
503                 }
504
505                 XTree schemaTree = collectionMetadata.getXTree();
506
507                 if (pathname.equals("")) {
508                     // if there are no path, use the whole root.
509
Collection c = schemaTree.getRoot().getChildren();
510                     if (c == null)
511                         continue;
512                     Object JavaDoc[] sn = c.toArray();
513                     TypedXTreeNode tmpNode = null;
514                     for (int l = 0; l < sn.length; l++) {
515                         tmpNode = (TypedXTreeNode) sn[l];
516                         //XMLSchemaTools.displayDeclaration (firstnode.getDeclaration ()) ;
517
source.add(colname, tmpNode);
518                     }
519                     sourceIsValid = true;
520                 } else {
521                     /*
522                     if (locationexpression == null)
523                         continue;
524                     */

525                     if (steps == null)
526                         continue;
527                     //Collection set = schemaTree.prune(locationexpression);
528
Collection set = schemaTree.prune(steps);
529                     if (set.size() > 0) {
530                         source.add(colname, set);
531                         sourceIsValid = true;
532                     }
533                 }
534
535             }
536             if (sourceIsValid == true) {
537                 if (sources == null)
538                     sources = new ArrayList();
539                 sources.add(source);
540             }
541         }
542     }
543
544     /**
545      * Return the path.
546      *
547      * @return the string respresentation of the path.
548      */

549     public String JavaDoc getPathName() {
550         return pathname;
551     }
552
553     /**
554      * Return the names of all sources.
555      *
556      * @return the names of all sources.
557      */

558     public ArrayList getSourceNames() {
559         if (sources == null)
560             return null;
561         ArrayList v = new ArrayList(sources.size());
562         for (int i = 0; i < sources.size(); i++) {
563             String JavaDoc sourcename = ((Source) sources.get(i)).getSourceName();
564             v.add(sourcename);
565         }
566         return v;
567     }
568
569     /**
570      * return an arraylist document names
571      */

572     public String JavaDoc getUrl() {
573         return restrictedDocument;
574     }
575
576     /**
577      * Return all nodes of all sources for the current path expression.
578      *
579      * @return all nodes of all sources for the current path expression.
580      */

581     public ArrayList getNodes() {
582         if (nodes != null) return nodes;
583         if (sources == null)
584             return null;
585         nodes = new ArrayList();
586         for (int i = 0; i < sources.size(); i++) {
587             ArrayList elementpaths = ((Source) sources.get(i)).getNodes();
588             if (elementpaths != null)
589                 for (int j = 0; j < elementpaths.size(); j++) {
590                     TypedXTreeNode nodej = (TypedXTreeNode) elementpaths.get(j);
591                     nodes.add(nodej);
592                 }
593         }
594         return nodes;
595     }
596
597 // /**
598
// * Return the vector of nodes asociated with the given source.
599
// *
600
// * @param sourcename the name of the source to work on.
601
// * @return a vector of nodes referenced by the source for the current
602
// * path expression.
603
// */
604
// public ArrayList getNodes(String sourcename) {
605
// Source sname = getSourceByName(sourcename);
606
// if (sname != null)
607
// return sname.getNodes();
608
// return null;
609
// }
610

611 // /**
612
// * Provided the name of one source, return a reference on the associated
613
// * source.
614
// *
615
// * @param orig_sourcename the name of the source to return.
616
// * @return a reference on the associated source. Null if no source
617
// * match the given name.
618
// */
619
// private Source getSourceByName(String orig_sourcename) {
620
// if (sources == null)
621
// return null;
622
// for (int i = 0; i < sources.size(); i++) {
623
//
624
// Source si = (Source) sources.get(i);
625
// String sourcename = si.getSourceName();
626
// if (orig_sourcename.equals(sourcename)) {
627
// return si;
628
// }
629
// }
630
// return null;
631
// }
632

633 // /**
634
// * Return all reference on schema nodes matching this source name and
635
// * this collection name.
636
// *
637
// * @param sourcename the source on which we work on.
638
// * @param colname the collection to find.
639
// */
640
// public ArrayList getNodesByCollection(String sourcename, String colname) {
641
// Source source = getSourceByName(sourcename);
642
// if (source == null) {
643
// System.err.println("No matching source " + sourcename);
644
// return null;
645
// }
646
// return source.getNodesByCollection(colname);
647
// }
648

649 // /**
650
// * Return all reference on schema nodes matching this source name and
651
// * this collection name.
652
// *
653
// * @param colname the collection to find.
654
// */
655
// public ArrayList getNodesByCollection(String colname) {
656
// if (sources == null)
657
// return null;
658
// ArrayList v = new ArrayList();
659
// for (int i = 0; i < sources.size(); i++) {
660
// Source si = (Source) sources.get(i);
661
// ArrayList vi = si.getNodesByCollection(colname);
662
// if (vi.size() > 0) {
663
// for (int j = 0; j < vi.size(); j++) {
664
// v.add(vi.get(j));
665
// }
666
// }
667
// }
668
// return v;
669
// }
670

671 // /**
672
// * Return all collection's name included in the specified source.
673
// *
674
// * @param sourcename the name of the source to work on.
675
// *
676
// * @return a vector of String representing the collections' name
677
// */
678
// public ArrayList getColname(String sourcename) {
679
// Source source = getSourceByName(sourcename);
680
// if (source == null) {
681
// System.err.println("No matching source " + sourcename);
682
// return null;
683
// }
684
// return source.getColname();
685
// }
686
}
687
688 /* ************************************************************************ */
689
690 /**
691  * This class refers <b>for a specific Expression Path</b> on of the sources
692  * matching the path.
693  */

694 class Source {
695     private static final String JavaDoc RCSRevision = "$Revision: 1.10 $";
696     private static final String JavaDoc RCSName = "$Name: $";
697     private String JavaDoc sourcename;
698
699     /**
700      * KEY : colname
701      * VALUE : vector of paths associated with this colname
702      */

703     private Hashtable elementpaths;
704
705     /**
706      * Construct a source with an associated sourcename.
707      *
708      * @param sourcename the name of the source.
709      */

710     public Source(String JavaDoc sourcename) {
711         this.sourcename = sourcename;
712         elementpaths = new Hashtable();
713     }
714
715     /**
716      * Return the hashmap colname/nodes
717      */

718     public Hashtable getElementPaths() {
719         return elementpaths;
720     }
721
722     /**
723      * Add a set of schema nodes to a source.
724      *
725      * @param nodes the set of schema node to associate to the source.
726      */

727     public void add(String JavaDoc colname, Collection nodes /* , String path */
728     ) {
729         for (Iterator iterator = nodes.iterator(); iterator.hasNext();) {
730             TypedXTreeNode node = (TypedXTreeNode) iterator.next();
731
732             ArrayList roots = (ArrayList) elementpaths.get(colname);
733             if (roots == null) {
734                 roots = new ArrayList();
735                 elementpaths.put(colname, roots);
736             }
737             // roots.add (new ElementPath (node)) ;
738
roots.add(node);
739         }
740     }
741
742     public void add(String JavaDoc colname, TypedXTreeNode node /* , String path */
743     ) {
744         ArrayList roots = null;
745         if ((roots = (ArrayList) elementpaths.get(colname)) == null) {
746             roots = new ArrayList();
747             elementpaths.put(colname, roots);
748         }
749         // roots.add (new ElementPath (node)) ;
750
roots.add(node);
751     }
752
753     /**
754      * Return the name of the source.
755      *
756      * @return the name of the source.
757      */

758     public String JavaDoc getSourceName() {
759         return sourcename;
760     }
761
762     /**
763      * Return the vector of elements associated with this source for
764      * the current expression path.
765      *
766      * @return the vector of nodes associated with this source for
767      * the current expression path.
768      */

769     public ArrayList getNodes() {
770         ArrayList v = new ArrayList();
771         for (Enumeration e = elementpaths.elements(); e.hasMoreElements();) {
772             ArrayList vep = (ArrayList) e.nextElement();
773
774             for (int i = 0; i < vep.size(); i++) {
775                 // ElementPath epi = (ElementPath) vep.get (i) ;
776
// v.add (epi.getNode ()) ;
777
v.add(vep.get(i));
778             }
779         }
780         return v;
781     }
782
783     /**
784      * Return all reference on schema nodes matching a collection name.
785      *
786      * @param colname the collection to find.
787      */

788     public ArrayList getNodesByCollection(String JavaDoc colname) {
789         ArrayList v = new ArrayList();
790         ArrayList vep = (ArrayList) elementpaths.get(colname);
791         if (vep == null)
792             return v;
793
794         for (int i = 0; i < vep.size(); i++) {
795             // ElementPath epi = (ElementPath) vep.get (i) ;
796
// v.add (epi.getNode ()) ;
797
v.add(vep.get(i));
798         }
799         return v;
800     }
801
802     /**
803      * Return all collection's name included.
804      *
805      * @return a vector of String representing the collections' name
806      */

807     public ArrayList getColname() {
808         ArrayList v = new ArrayList();
809         for (Enumeration e = elementpaths.keys(); e.hasMoreElements();) {
810             String JavaDoc colname = (String JavaDoc) e.nextElement();
811             v.add(colname);
812         }
813         return v;
814     }
815 }
816
817
Popular Tags