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 java.util.Map;
19  
20  import javax.servlet.http.HttpServletRequest;
21  
22  import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
23  import org.seasar.tuigwaa.model.DAOService;
24  import org.seasar.tuigwaa.model.ModelService;
25  import org.seasar.tuigwaa.model.core.TgwEntity;
26  import org.seasar.tuigwaa.plugin.TgwPluginUtils;
27  import org.seasar.tuigwaa.util.TgwContext;
28  
29  import com.isenshi.util.functor.UnaryProcedure;
30  
31  public class RowDeleteProcedure implements UnaryProcedure {
32  
33  	private String entityName;
34  
35  	public RowDeleteProcedure() {
36  	}
37  
38  	public RowDeleteProcedure(String entityName) {
39  		this.entityName = entityName;
40  	}
41  
42  	public void setEntityName(String entityName) {
43  		this.entityName = entityName;
44  	}
45  
46  	public String getEntityName() {
47  		return entityName;
48  	}
49  
50  	public void run(Object obj) {
51  		DAOService daoService = (DAOService) SingletonS2ContainerFactory
52  				.getContainer().getComponent(DAOService.class);
53  		ModelService entityService = (ModelService) SingletonS2ContainerFactory
54  				.getContainer().getComponent(ModelService.class);
55  
56  		String siteName = TgwContext.getSiteName();
57  
58  		HttpServletRequest request = SingletonS2ContainerFactory.getContainer()
59  				.getRequest();
60  		Map map = TgwPluginUtils.getEntityNameMapFromRequest(request);
61  
62  		String idStr = (String) map.get(entityName);
63  		if (idStr == null) {
64  			return;
65  		}
66  		Long id = Long.valueOf(idStr);
67  
68  		if (id.longValue() > 0) {
69  			TgwEntity entity = entityService.getEntity(siteName, entityName);
70  			daoService.getDAO(entity).delete(id);
71  		}
72  	}
73  }