01: package net.sourceforge.squirrel_sql.plugins.hibernate.completion;
02:
03: import net.sourceforge.squirrel_sql.plugins.hibernate.mapping.MappedClassInfo;
04: import net.sourceforge.squirrel_sql.plugins.hibernate.mapping.PropertyInfo;
05: import net.sourceforge.squirrel_sql.fw.completion.util.CompletionParser;
06: import net.sourceforge.squirrel_sql.fw.completion.CompletionInfo;
07:
08: import java.util.Collection;
09: import java.util.List;
10: import java.util.Collections;
11: import java.util.ArrayList;
12:
13: public class AliasInfo extends CompletionInfo {
14: private MappedClassInfo _mci;
15: private String _alias;
16: private String _toString;
17:
18: public AliasInfo(MappedClassInfo mci, String alias) {
19: _mci = mci;
20: _alias = alias;
21:
22: _toString = alias + " (alias for " + _mci.getSimpleClassName()
23: + ")";
24: }
25:
26: public boolean matches(CompletionParser parser) {
27: return _alias.startsWith(parser.getStringToReplace());
28: }
29:
30: public String getCompareString() {
31: return _alias;
32: }
33:
34: public ArrayList<PropertyInfo> getQualifiedMatchingAttributes(
35: CompletionParser parser) {
36: if (1 < parser.size() && parser.getToken(0).equals(_alias)) {
37: return _mci
38: .getQualifiedMatchingAttributes(new CompletionParser(
39: _mci.getClassName() + "."
40: + parser.getAllButFirst()));
41: } else {
42: return new ArrayList<PropertyInfo>();
43: }
44: }
45:
46: public String toString() {
47: return _toString;
48: }
49:
50: public PropertyInfo getAttributeByName(String attrName) {
51: return _mci.getAttributeByName(attrName);
52: }
53: }
|