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.database.util;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.seasar.tuigwaa.database.function.criteria.AbstractCriteriaFunction;
22  import org.seasar.tuigwaa.database.function.criteria.ICriteria;
23  import org.seasar.tuigwaa.util.TgwContext;
24  
25  public class FileDataManager {
26  
27  	private static final String ATTR_NAME = "org.seasar.tuigwaa.database.util.FileDataManager";
28  
29  	private static final String ATTR_NAME_DELETED = "org.seasar.tuigwaa.database.util.FileDataManager_DELETED";
30  
31  	public static void addFileData(FileData filedata) {
32  		List list = (List) TgwContext.getRequestAttribute(ATTR_NAME);
33  		if (list == null) {
34  			list = new ArrayList();
35  			TgwContext.setRequestAttribute(ATTR_NAME, list);
36  		}
37  		list.add(filedata);
38  	}
39  
40  	public static void addDeletedFileData(FileData filedata){
41  		List list = (List) TgwContext.getRequestAttribute(ATTR_NAME_DELETED);
42  		if (list == null) {
43  			list = new ArrayList();
44  			TgwContext.setRequestAttribute(ATTR_NAME_DELETED, list);
45  		}
46  		list.add(filedata);
47  	}
48  		
49  	public static List getFileDataList() {
50  		return (List) TgwContext.getRequestAttribute(ATTR_NAME);
51  	}
52  
53  	public static List getDeletedFileDataList(){
54  		return (List) TgwContext.getRequestAttribute(ATTR_NAME_DELETED);
55  	}
56  		
57  	public static FileDataCriteria getCriteria(FileData fileData) {
58  		return new FileDataCriteria(fileData.getEntityName(), fileData
59  				.getAttrName(), fileData.getEntityId());
60  	}
61  
62  	public static class FileDataCriteria extends AbstractCriteriaFunction {
63  
64  		private String entityName;
65  
66  		private String attrName;
67  
68  		private String entityId;
69  
70  		public FileDataCriteria(String entityName, String attrName,
71  				String entityId) {
72  			this.entityName = entityName;
73  			this.attrName = attrName;
74  			this.entityId = entityId;
75  		}
76  
77  		public Object evaluate(ICriteria criteria) {
78  			return evaluate(criteria, null);
79  		}
80  
81  		public Object evaluate(ICriteria criteria, Object right) {
82  			criteria.addEq("entityName", entityName);
83  			criteria.addEq("attrName", attrName);
84  			criteria.addEq("entityId", entityId);
85  			return criteria;
86  		}
87  	}
88  }