01: package net.sourceforge.jaxor.parser;
02:
03: import net.sourceforge.jaxor.util.SystemException;
04:
05: import java.util.ArrayList;
06: import java.util.Collections;
07: import java.util.Iterator;
08: import java.util.List;
09:
10: /*
11: * User: Mike
12: * Date: Oct 21, 2002
13: * Time: 8:55:39 PM
14: */
15:
16: public class AttributeList {
17: private List _list = new ArrayList();
18:
19: public AttributeList(List list) {
20: _list = list;
21: }
22:
23: public void addAttribute(Attribute att) {
24: _list.add(att);
25: }
26:
27: public List asList() {
28: return Collections.unmodifiableList(_list);
29: }
30:
31: public List getPrimaryKey() {
32: List all = new ArrayList();
33: for (Iterator iterator = _list.iterator(); iterator.hasNext();) {
34: Attribute attribute = (Attribute) iterator.next();
35: if (attribute.isPrimaryKey()) {
36: all.add(attribute);
37: }
38: }
39: return all;
40: }
41:
42: public ParamList getPrimaryKeyAsParamList(Jaxor j) {
43: ParamList all = new ParamList();
44: for (Iterator iterator = _list.iterator(); iterator.hasNext();) {
45: Attribute attribute = (Attribute) iterator.next();
46: if (attribute.isPrimaryKey()) {
47: all.add(new Param(attribute, j));
48: }
49: }
50: return all;
51: }
52:
53: public ParamList getFactoryKeysAsParamList(Jaxor j) {
54: ParamList all = new ParamList();
55: for (Iterator iterator = _list.iterator(); iterator.hasNext();) {
56: Attribute attribute = (Attribute) iterator.next();
57: if (attribute.isPrimaryKey() && !attribute.isAutoAssign()) {
58: all.add(new Param(attribute, j));
59: }
60: }
61: return all;
62: }
63:
64: public Attribute findAttribute(String key) {
65: for (Iterator iterator = _list.iterator(); iterator.hasNext();) {
66: Attribute attribute = (Attribute) iterator.next();
67: if (attribute.getName().equalsIgnoreCase(key))
68: return attribute;
69: }
70: throw new SystemException("Failed to find attribute: " + key);
71: }
72: }
|