1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.model.core.impl;
17
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21
22 import org.seasar.tuigwaa.model.common.DefaultTuigwaaElementVisitor;
23 import org.seasar.tuigwaa.model.common.TgwElementVisitor;
24 import org.seasar.tuigwaa.model.core.TgwAttribute;
25 import org.seasar.tuigwaa.model.core.TgwDomain;
26 import org.seasar.tuigwaa.model.core.TgwEntity;
27
28
29 public class TgwDomainImpl extends TgwElementImpl implements TgwDomain {
30
31 public TgwDomainImpl(String domainName) {
32 super();
33 setName(domainName);
34 }
35
36 public void addEntity(TgwEntity entity) {
37 addChild(entity);
38 }
39
40 public TgwEntity getEntity(String name) {
41 return (TgwEntity) getChild(name);
42 }
43
44 public TgwEntity getEntityByDisplayName(String displayName){
45 return (TgwEntity) getChildByDisplayName(displayName);
46 }
47
48 public TgwEntity removeEntity(String name) {
49 TgwEntity removedEntity = (TgwEntity) removeChild(name);
50
51 for (Iterator i = removedEntity.getFieldIterator(); i.hasNext();) {
52 TgwAttribute field = (TgwAttribute) i.next();
53 if (field instanceof FkAttribute) {
54 FkAttribute fk = (FkAttribute) field;
55 fk.getRefEntity().removeReferencedFkField(fk);
56 }
57 }
58 return removedEntity;
59 }
60
61 public List getEntityList() {
62 return getChildList();
63 }
64
65
66 public Iterator getEntityNameIterator() {
67 return getChildNameIterator();
68 }
69
70 public List getNewRefList(TgwEntity fromEntity) {
71 List list = new ArrayList();
72
73 if (fromEntity.getName() == null || fromEntity.getName().equals("")) {
74 list.addAll(getChildList());
75 return list;
76 }
77
78 for (Iterator i = getEntityList().iterator(); i.hasNext();) {
79 TgwEntity anEntity = (TgwEntity) i.next();
80 if (fromEntity.equals(anEntity)) {
81 continue;
82 }
83 Boolean bool = (Boolean) anEntity.accept(SEARCH_SELF_VISITOR,
84 fromEntity);
85 if (bool.booleanValue()) {
86 continue;
87 }
88 list.add(anEntity);
89 }
90 return list;
91 }
92
93
94 public Object accept(TgwElementVisitor visitor, Object data) {
95 return visitor.visit(this, data);
96 }
97
98 private static TgwElementVisitor SEARCH_SELF_VISITOR = new DefaultTuigwaaElementVisitor() {
99
100 public Object visit(FkAttribute field, Object fromEntity) {
101 TgwEntity refEntity = field.getRefEntity();
102 if (refEntity.equals((TgwEntity) fromEntity)) {
103 return Boolean.TRUE;
104 }
105 return refEntity.accept(this, fromEntity);
106 }
107
108 public Object visit(TgwEntity entity, Object fromEntity) {
109 Iterator itr = entity.getFieldIterator();
110 boolean flag = false;
111 while (itr.hasNext()) {
112 TgwAttribute attr = (TgwAttribute) itr.next();
113 Object ret = attr.accept(this, fromEntity);
114 if (ret != null && ((Boolean) ret).booleanValue()) {
115 flag = true;
116 }
117 }
118 return new Boolean(flag);
119 }
120 };
121 }