KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mediator > decomposer > Utils


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 package org.xquark.mediator.decomposer;
24
25 import java.util.*;
26
27 import org.xquark.xquery.metadata.MetaDataImpl;
28 import org.xquark.xquery.parser.Variable;
29 import org.xquark.xquery.parser.XQueryException;
30 import org.xquark.xquery.parser.XQueryExpression;
31
32 public class Utils {
33     // **********************************************************************
34
// * VERSIONING
35
// **********************************************************************
36
private static final String JavaDoc RCSRevision = "$Revision: 1.3 $";
37     private static final String JavaDoc RCSName = "$Name: $";
38
39     // **********************************************************************
40
// * CLASS VARIABLES
41
// **********************************************************************
42

43     // **********************************************************************
44
// * INITIALIZATION
45
// **********************************************************************
46

47     /*
48     static public void FillSources(XQueryFile arg, UnitEnvironment environment, MetaData metadata) throws XQueryException {
49             for (int i = 0; i < arg.getUnits().size(); i++) FillSources((XQueryUnit)arg.getUnits().get(i),environment,metadata);
50     }
51     
52     static public void FillSources(XQueryUnit arg, UnitEnvironment environment, MetaData metadata) throws XQueryException {
53             for (int i = 0; i < arg.getExpressions().size(); i++) FillSources((XQueryExpression)arg.getExpressions().get(i),environment,metadata);
54     }
55      */

56
57     /**
58      * Finds out on which sources this sources a <code>XQueryExpression</code> is defined, and
59      * attach this information (a List of String presenting source names)to this <code>XQueryExpression</code>.
60      * @param arg
61      * @param metadata
62      * @throws XQueryException
63      * note : this is not recursive, only this <code>arg</code>, none of its child traited.
64      */

65     static public void fillSources(XQueryExpression arg, MetaDataImpl metadata, boolean force) throws XQueryException {
66
67         // if it already has been generated
68
if (arg.getSourceNames() != null) {
69             return;
70         }
71         //arg.setSources(new ArrayList(1));
72

73         MakeStepsListVisitor stepvisitor = new MakeStepsListVisitor(metadata, true);
74         arg.accept(stepvisitor);
75
76         if (force || arg.getSourceNames() == null || arg.getSourceNames().isEmpty()) {
77
78             // CHANGE 11/04/2003
79
Set set = stepvisitor.getStepsLists().getRegisteredVariables();
80             if (set == null) {
81                 arg.setSourceNames(null);
82                 arg.setUrls(null);
83                 return;
84             }
85             Set sources = null;
86             Set urls = null;
87             for (Iterator it = set.iterator(); it.hasNext();) {
88                 Variable var = (Variable) it.next();
89                 if (var.getSourceNames() != null && !var.getSourceNames().isEmpty()) {
90                     if (sources == null)
91                         sources = new HashSet(var.getSourceNames());
92                     else
93                         sources.addAll(var.getSourceNames());
94                 }
95                 if (var.getUrls() != null && !var.getUrls().isEmpty()) {
96                     if (urls == null)
97                         urls = new HashSet(var.getUrls());
98                     else
99                         urls.addAll(var.getUrls());
100                 }
101             }
102             arg.setSourceNames(sources);
103             arg.setUrls(urls);
104
105             // ArrayList paths = stepvisitor.getStepsLists().getStepsLists();
106
//
107
// if (paths != null && !paths.isEmpty()) {
108
// PathResolver pathresolver = new PathResolver(metadata);
109
// pathresolver.resolveStepsList(paths);
110
// ArrayList sourceNames = pathresolver.getSourceNames();
111
// if (arg.getSourceNames() == null)
112
// arg.setSourceNames(sourceNames);
113
// else {
114
// for (int i=0;i<sourceNames.size();i++) {
115
// if (!arg.getSourceNames().contains(sourceNames.get(i)))
116
// arg.getSourceNames().add(sourceNames.get(i));
117
// }
118
// }
119
// ArrayList urls = pathresolver.getUrls();
120
// if (urls != null && !urls.isEmpty()) {
121
// if (arg.getUrls() == null)
122
// arg.setUrls(urls);
123
// else
124
// arg.getUrls().addAll(urls);
125
// }
126
// }
127
}
128         //else arg.setSources(new ArrayList(1));
129

130         // GenerateSourceForSonsVisitor visitor = new GenerateSourceForSonsVisitor(environment, metadata);
131
// arg.accept(visitor);
132
}
133
134     /**
135      *
136      */

137     public static String JavaDoc makeIndent(int indent) {
138         char[] buf = new char[indent];
139         for (int i = 0; i < buf.length; i++)
140             buf[i] = '\t';
141         return new String JavaDoc(buf);
142     }
143 }
144
Popular Tags