001: package net.sourceforge.jaxor.parser;
002:
003: import java.util.ArrayList;
004: import java.util.Iterator;
005: import java.util.List;
006:
007: /*
008: * User: Mike
009: * Date: Aug 27, 2003
010: * Time: 7:57:13 PM
011: */
012:
013: public class EntityRef {
014:
015: private String _entity;
016: private String _query;
017: private String _find;
018: private String _alias;
019:
020: private List _keys = new ArrayList();
021:
022: public void setTable(String entity) {
023: _entity = entity;
024: }
025:
026: public void setAlias(String alias) {
027: _alias = alias;
028: }
029:
030: public String getTable() {
031: return _entity;
032: }
033:
034: public void addKey(Key k) {
035: _keys.add(k);
036: }
037:
038: public String getQuery() {
039: return _query;
040: }
041:
042: public void setFind(String find) {
043: _find = find;
044: }
045:
046: public void setQuery(String query) {
047: _query = query;
048: }
049:
050: private String getQueryAsArg() {
051: if (_query == null)
052: return "null";
053: return "\"" + _query + "\"";
054: }
055:
056: private String getFindAsArg() {
057: if (_find == null)
058: return "null";
059: return "\"" + _find + "\"";
060: }
061:
062: public boolean isUnique() {
063: return true;
064: }
065:
066: public List getRefKeys(Jaxor source, EntityCollection coll) {
067: List results = new ArrayList();
068: Jaxor target = coll.resolveEntity(_entity);
069: for (Iterator iterator = _keys.iterator(); iterator.hasNext();) {
070: Key key = (Key) iterator.next();
071: Attribute att = source.findAttribute(key.getSource());
072: Attribute targetAtt = target.findAttribute(key.getTarget());
073: String sourceMeta = "new " + source.getPackageName() + "."
074: + source.getEntity().getMetaName() + "().get"
075: + att.getJavaName() + "()";
076: String targetMeta = "new " + target.getPackageName() + "."
077: + target.getEntity().getMetaName() + "().get"
078: + targetAtt.getJavaName() + "()";
079: results.add(getName(coll) + ".getResolver().add("
080: + sourceMeta + "," + targetMeta + ");\n");
081: }
082: return results;
083: }
084:
085: public String getResolverConstructor(EntityCollection col,
086: Jaxor source) {
087: Jaxor target = col.resolveEntity(_entity);
088: String finder = target.getFinderImplFull();
089: String method = getResolverConstructor(finder);
090: return method;
091: }
092:
093: public String getType(EntityCollection col) {
094: Jaxor target = col.resolveEntity(_entity);
095: return target.getEntityClassFull();
096: }
097:
098: public String getName(EntityCollection col) {
099: Jaxor target = col.resolveEntity(_entity);
100: return getMethodName(target.getEntity().getInterfaceName());
101: }
102:
103: protected String getMethodName(String entityName) {
104: if (_alias == null)
105: return entityName;
106: else
107: return _alias;
108: }
109:
110: public String getResolverConstructor(String finder) {
111: return "new ReferenceResolver(" + finder + ".class,this,"
112: + isUnique() + "," + getQueryAsArg() + ","
113: + getFindAsArg() + ")";
114: }
115:
116: public List getKeys() {
117: return _keys;
118: }
119: }
|