01: /**
02: * Copyright (C) 2001-2004 France Telecom R&D
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */package org.objectweb.speedo.generation.mivisitor;
18:
19: import java.util.Iterator;
20:
21: import org.objectweb.speedo.api.SpeedoException;
22: import org.objectweb.speedo.lib.Personality;
23: import org.objectweb.speedo.metadata.SpeedoField;
24: import org.objectweb.speedo.metadata.SpeedoIndex;
25: import org.objectweb.speedo.metadata.SpeedoPackage;
26:
27: /**
28: * @author Y.Bersihand
29: */
30: public class IndexVisitor extends AbstractMetaInfoVisitor {
31:
32: public IndexVisitor(Personality p) {
33: super (p);
34: }
35:
36: protected String getLoggerName() {
37: return super .getLoggerName() + ".index";
38: }
39:
40: public void visitIndex(SpeedoIndex si, SpeedoPackage sp)
41: throws SpeedoException {
42: //try to find the column name(s)
43: if (si.columnNames.isEmpty()) {
44: for (Iterator it = si.fieldNames.iterator(); it.hasNext();) {
45: String fieldName = (String) it.next();
46: //try to add the column name(s) to the index
47: SpeedoField sf = (SpeedoField) si.speedoClass.fields
48: .get(fieldName);
49: if (sf.columns != null && sf.columns.length != 0) {
50: for (int i = 0; i < sf.columns.length; i++) {
51: si.columnNames.add(sf.columns[i].name);
52: }
53: } else {
54: //by default, it is the field name
55: si.columnNames.add(fieldName);
56: }
57: }
58: }
59: sp.xmlDescriptor.mos.add(si);
60: super.visitIndex(si, sp);
61: }
62: }
|