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  package org.seasar.tuigwaa.logic.functor;
17  
18  import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
19  import org.seasar.tuigwaa.model.DAOService;
20  import org.seasar.tuigwaa.model.ModelService;
21  import org.seasar.tuigwaa.model.common.EntityDAO;
22  import org.seasar.tuigwaa.model.core.TgwEntity;
23  import org.seasar.tuigwaa.util.TgwContext;
24  import org.seasar.tuigwaa.util.functor.Op;
25  
26  import com.isenshi.util.functor.BinaryPredicate;
27  import com.isenshi.util.functor.UnaryPredicate;
28  
29  public class AggregationValuePredicate implements UnaryPredicate {
30  
31  	private String siteName;
32  
33  	private String entityName;
34  
35  	private String aggregationFuncName;
36  
37  	private Double value;
38  
39  	private String opcode;
40  
41  	public AggregationValuePredicate(){
42  	}
43  	
44  	public AggregationValuePredicate(String siteName, String entityName,
45  			String aggregationFuncName, Double value, String opcode) {
46  		this.siteName = siteName;
47  		this.entityName = entityName;
48  		this.aggregationFuncName = aggregationFuncName;
49  		this.value = value;
50  		this.opcode = opcode;
51  	}
52  
53  	/***
54  	 * @deprecated
55  	 */
56  	public void setSiteName(String siteName) {
57  		this.siteName = siteName;
58  	}
59  
60  	/***
61  	 * @deprecated
62  	 */
63  	public String getSiteName() {
64  		return TgwContext.getDomainName();
65  //		return siteName;
66  	}
67  
68  	public void setEntityName(String entityName) {
69  		this.entityName = entityName;
70  	}
71  
72  	public String getEntityName() {
73  		return entityName;
74  	}
75  
76  	public void setAggregationFuncName(String aggregationFuncName) {
77  		this.aggregationFuncName = aggregationFuncName;
78  	}
79  
80  	public String getAggregationFuncName() {
81  		return aggregationFuncName;
82  	}
83  
84  	public void setOpcode(String opcode) {
85  		this.opcode = opcode;
86  	}
87  
88  	public String getOpcode() {
89  		return opcode;
90  	}
91  
92  	public void setValue(Double value) {
93  		this.value = value;
94  	}
95  
96  	public Double getValue() {
97  		return value;
98  	}
99  
100 	public boolean test(Object obj) {
101 		// Ignore Input "obj"
102 
103 		ModelService entityService = (ModelService) SingletonS2ContainerFactory
104 				.getContainer().getComponent(ModelService.class);
105 		DAOService daoService = (DAOService) SingletonS2ContainerFactory
106 				.getContainer().getComponent(DAOService.class);
107 
108 		String domainName = TgwContext.getDomainName();
109 //		TgwEntity entity = entityService.getEntity(siteName, entityName);
110 		TgwEntity entity = entityService.getEntity(domainName, entityName);		
111 		EntityDAO dao = daoService.getDAO(entity);
112 
113 		Object ret = (Object) dao.getMethod(aggregationFuncName).evaluate();
114 		Double testValue = null;
115 		if(ret instanceof Integer){
116 			 double doubleValue = ((Integer)ret).doubleValue();
117 			 testValue = new Double(doubleValue);
118 		}else{
119 			testValue = (Double)ret;
120 		}
121 				
122 		BinaryPredicate predicate = Op.getInstance(getOpcode());
123 		return predicate.test(testValue, value);
124 	}
125 }