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/09/08
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.common;
23  
24  import java.io.File;
25  import java.util.ArrayList;
26  import java.util.Collection;
27  import java.util.Iterator;
28  import java.util.List;
29  import java.util.Map;
30  
31  import org.seasar.tuigwaa.model.DAOServiceImpl.FunctionSet;
32  import org.seasar.tuigwaa.model.core.TgwAttribute;
33  import org.seasar.tuigwaa.model.core.TgwEntity;
34  import org.seasar.tuigwaa.model.core.impl.FkAttribute;
35  import org.seasar.tuigwaa.util.TgwContext;
36  import org.seasar.tuigwaa.util.TgwPathResolver;
37  
38  import com.isenshi.util.PathUtils;
39  import com.isenshi.util.ResourceUtils;
40  
41  /***
42   * @author nishioka
43   * 
44   * TODO To change the template for this generated type comment go to Window -
45   * Preferences - Java - Code Style - Code Templates
46   */
47  public class EntityInfo {
48  
49  	private TgwEntity entity_;
50  
51  	private FunctionSet functionSet;
52  
53  	public EntityInfo(TgwEntity entity, FunctionSet functionSet) {
54  		this.entity_ = entity;
55  		this.functionSet = functionSet;
56  	}
57  
58  	public TgwEntity getEntity() {
59  		return this.entity_;
60  	}
61  
62  	public List getFkAttributeList() {
63  		List list = new ArrayList();
64  		for (Iterator i = entity_.getFieldList().iterator(); i.hasNext();) {
65  			TgwAttribute attr = (TgwAttribute) i.next();
66  			if (attr instanceof FkAttribute) {
67  				list.add(attr);
68  			}
69  		}
70  		return list;
71  	}
72  	
73  	public boolean isAvailableWithSpreadsheet(){		
74  		boolean flag = 
75  			EntityUtils.hasAttribute(entity_,TgwAttribute.TYPE_BOOLEAN) ||
76  			EntityUtils.hasAttribute(entity_,TgwAttribute.TYPE_FILE);		
77  		return flag;
78  	}
79  	
80  	public Map getDataFilterMap() {
81  		return functionSet.getDataFilterFunctionMap();
82  	}
83  
84  	public Collection getDataFilterList() {
85  		return functionSet.getDataFilterFunctionMap().values();
86  	}
87  
88  	public Collection getAggregationFuncList() {
89  		return functionSet.getAggregationExeFunctionMap().values();
90  	}
91  
92  	public Collection getValueAggFuncList() {
93  		return functionSet.getValueExeFunctionMap().values();
94  	}
95  
96  	public Collection getSearchFormList() {
97  		return functionSet.getSearchExeFunctionMap().values();
98  	}
99  
100 	public Collection getCustomFormList() {
101 		return functionSet.getCustomFormFunctionMap().values();
102 	}
103 
104 	public Collection getUpdateRuleList() {
105 		return functionSet.getCustomUpdateFunctionMap().values();
106 	}
107 
108 	public Collection getFunctionList() {
109 		List list = new ArrayList();
110 		list.addAll(getDataFilterList());
111 		list.addAll(getAggregationFuncList());
112 		return list;
113 	}
114 
115 	public String[] getFormTemplates() {
116 		return getTemplates("form");
117 	}
118 
119 	public String[] getTableTemplates() {
120 		return getTemplates("table");
121 	}
122 
123 	public String[] getDataTemplates(){
124 		return getTemplates("data");
125 	}
126 	
127 	public String[] getTemplates(String type) {
128 		String siteName = TgwContext.getSiteName();
129 		String path = TgwPathResolver.getTemplatePath(siteName, entity_
130 				.getName(), type, null, null);
131 		File file = ResourceUtils.getFile(path);
132 
133 		if (file == null || !file.exists()) {
134 			return null;
135 		}
136 
137 		String[] fileNames = file.list();
138 		if (fileNames == null) {
139 			return null;
140 		}
141 
142 		String[] ret = new String[fileNames.length];
143 		for (int i = 0; i < ret.length; i++) {
144 			ret[i] = PathUtils.getFileName(fileNames[i]);
145 		}
146 
147 		return ret;
148 	}
149 }