01: package net.sourceforge.jaxor.parser;
02:
03: import net.sourceforge.jaxor.util.SystemException;
04:
05: import java.io.File;
06: import java.util.ArrayList;
07: import java.util.Iterator;
08: import java.util.List;
09: import java.util.Properties;
10:
11: import org.apache.velocity.runtime.log.LogSystem;
12:
13: /*
14: * User: Mike
15: * Date: Aug 27, 2003
16: * Time: 10:00:18 PM
17: */
18:
19: public class EntityCollection {
20: private final List _jaxorList = new ArrayList();
21: private final Generator _generator;
22: private final SourceMap _javadocBuilders;
23: private final Properties _mapperProps;
24:
25: public EntityCollection(Generator generator,
26: SourceMap javaDocBuilders, Properties mapperProps) {
27: _generator = generator;
28: _javadocBuilders = javaDocBuilders;
29: _mapperProps = mapperProps;
30: }
31:
32: public void add(Jaxor j) {
33: _jaxorList.add(j);
34: }
35:
36: public void generate(File _destDir, LogSystem logger) {
37: for (Iterator iterator = _jaxorList.iterator(); iterator
38: .hasNext();) {
39: Jaxor j = (Jaxor) iterator.next();
40: j.setDestDir(_destDir);
41: j.setConfig(_generator);
42: j.setMapperProps(_mapperProps);
43: j.setJavaDocBuilders(_javadocBuilders);
44: try {
45: j.execute(this , logger);
46: } catch (Exception e) {
47: throw new SystemException("Failed Generating: "
48: + j.getFullName(), e);
49: }
50: }
51: }
52:
53: public Jaxor resolveEntity(String entity) {
54: Jaxor result = null;
55: for (Iterator iterator = _jaxorList.iterator(); iterator
56: .hasNext();) {
57: Jaxor jaxor = (Jaxor) iterator.next();
58: if (jaxor.getEntity().getTableName().equalsIgnoreCase(
59: entity)
60: || jaxor.getFullName().equalsIgnoreCase(entity)) {
61: if (result != null)
62: throw new SystemException(
63: "Multiple entities were found for: "
64: + entity
65: + " Please use fully qualifed package name.");
66: result = jaxor;
67: }
68: }
69:
70: if (result != null)
71: return result;
72: throw new SystemException("Entity not found: " + entity);
73: }
74:
75: public Jaxor find(String fullEntityName) {
76: for (Iterator iterator = _jaxorList.iterator(); iterator
77: .hasNext();) {
78: Jaxor jaxor = (Jaxor) iterator.next();
79: String fullName = jaxor.getFullName();
80: if (fullName.equalsIgnoreCase(fullEntityName))
81: return jaxor;
82: }
83: return null;
84: }
85:
86: }
|