1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.seasar.tuigwaa.model.core.impl;
23
24 import java.util.Iterator;
25
26 import org.seasar.framework.container.S2Container;
27 import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
28 import org.seasar.tuigwaa.model.ModelService;
29 import org.seasar.tuigwaa.model.common.TgwAttributeVisitor;
30 import org.seasar.tuigwaa.model.common.TgwElementVisitor;
31 import org.seasar.tuigwaa.model.core.RelationAttribute;
32 import org.seasar.tuigwaa.model.core.TgwEntity;
33
34
35 /***
36 * タイプがリストから複数文字列選択・関連データのリストに対応
37 *
38 * @author nishioka
39 */
40 public class SetAttribute extends AbstractAttribute implements LinkAttribute ,RelationAttribute{
41
42 public static final String OPTION_M2M = "m-to-m";
43
44 private TgwEntity refEntity;
45
46 private FkAttribute inverseField;
47
48 private String[] tmpRestrictions;
49
50 public String getType() {
51 return TYPE_SET;
52 }
53
54
55
56 public TgwEntity getRefEntity() {
57 return refEntity;
58 }
59
60 public void setRestrictions(String[] restrictions) {
61 this.tmpRestrictions = restrictions;
62
63 }
64
65 public String[] getRestrictions() {
66 return tmpRestrictions;
67 }
68
69 public void setRefEntity(TgwEntity refEntity) {
70 this.refEntity = refEntity;
71 }
72
73 public void setRefEntityName(String refEntityName) {
74 String schema = getEntity().getDomainName();
75 TgwEntity entity = getEntityService().getEntity(schema, refEntityName);
76 setRefEntity(entity);
77 }
78
79 public String getRefEntityName() {
80 if (getRefEntity() != null) {
81 return getRefEntity().getName();
82 }
83 return null;
84 }
85
86 private ModelService getEntityService() {
87 S2Container container = SingletonS2ContainerFactory.getContainer();
88 return (ModelService) container.getComponent(ModelService.class);
89 }
90
91 public FkAttribute getInverseField() {
92 return inverseField;
93 }
94
95 public void setInverseField(FkAttribute inverseField) {
96 this.inverseField = inverseField;
97 }
98
99 public void connectFkField() {
100 Iterator itr = getEntity().getReferencedFkFieldList().iterator();
101 while (itr.hasNext()) {
102 FkAttribute fkField = (FkAttribute) itr.next();
103 if (fkField.getEntity().equals(this.getRefEntity())) {
104 fkField.setInverseField(this);
105 this.setInverseField(fkField);
106 }
107 }
108 }
109
110
111 public Object accept(TgwElementVisitor visitor, Object data) {
112 return visitor.visit(this, data);
113 }
114
115 public Object accept(TgwAttributeVisitor visitor, Object data) {
116 return visitor.visit(this, data);
117 }
118
119 }