View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  /*
17   * Created on 2005/08/06
18   *
19   * TODO To change the template for this generated file go to
20   * Window - Preferences - Java - Code Style - Code Templates
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 	/* for vistitor pattern */
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 }