Java tutorial
/* file of LaBeeFramework https://www.bee-wkspace.com/ Copyright (C) 2016- Naoki Yoshioka (ARTS Laboratory) http://www.arts-lab.net/dev/ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. */ package com.bee_wkspace.labee_fw.app.base; import javax.servlet.http.Cookie; import com.bee_wkspace.labee_fw.common.LogWriter; import com.bee_wkspace.labee_fw.common.MessageLabelUtil; import com.bee_wkspace.labee_fw.common.StringUtil; import com.bee_wkspace.labee_fw.common.SysMsgCodeDefine; import com.bee_wkspace.labee_fw.common.db.DBAccess; import com.bee_wkspace.labee_fw.core.ResourceMng; import com.bee_wkspace.labee_fw.core.SystemConfigMng; import com.bee_wkspace.labee_fw.core.base.BaseBlogic; import com.bee_wkspace.labee_fw.core.context.JsonValueContext; import com.bee_wkspace.labee_fw.core.context.ResponseContext; import com.bee_wkspace.labee_fw.core.context.ScreenContext; import com.bee_wkspace.labee_fw.exception.FwException; import com.fasterxml.jackson.databind.ObjectMapper; /** * Web?<br> * <br> * ???????????? ????<br> * ????<br> * <br> * ????????????<b>Blogic</b>????<br> * ()<br> * * <b>@FwBlogic(beanReuse = true)</b><br> * public class <b>TestBlogic</b> extends BaseBlogic < TestBean > { } <br> * <br> * * ????????????????<br> * ???????????DB????????????<br> * ??(JSP)??TGT(?)?EXE(?)??????HTML???<br> * ?????????????<br> * 1??????1??(??)?????<br> * JSP????JSP????1???????<br> * <br> * ????????????????????<br> * ???????????????????????????<br> * ?????????????????????<br> * ????????????????????????????clearSessionBeanData<br> * ????????<br> * ????FwBlogic?beanReuse??<br> * beanReuse?true??????false?????<br> * * <br> * * ??????????<b>@FwExeMethod</b>?<br> * ?ResponseContext????<br> * ??????(P1,P2,P3)????????????????<br> * ()<br> * * <b>@FwExeMethod</b><br> * public <b>ResponseContext start</b>(String param1) {<br> * System.out.println(param1);<br> * return <b>responseContext;</b><br> * }<br> * <br> * <b>?</b><br> * ??????????????<br> * ????()<br> * ?????????????????<br> * ???JSP(HTML)????"userId"?????????????setUserId(String * value)????<br> * setUserId(String paramName, String value )??<br> * ???doAutoBeanSetter()??setUserId??<br> * ????set + ??(??)????<br> * (???<b>@AutoSetterParam</b>????)<br> * ?<br> * <b>@AutoSetterParam</b><br> * public void <b>setUserId</b>(String value) {<br> * this.userId = value;<br> * }<br> * <br> * * ????JSP????????????ResponseContext??<br> * ??????????????????????<br> * <b>JSP?</b><br> * ??????"Blogic"?????ID???ScreenDefine.csv???JSP???<br> * <br> * <b>???</b><br> * ?setDelegateResponse??????????????<br> * ?????????????????<br> * <br> * <b>????</b><br> * ?setRedirectResponse??????????????<br> * ???????????????HTTP??<br> * <br> * <b>URL??</b><br> * ?setRedirectURL?????????????URL??<br> * ?????URL??URL????<br> * <br> * ???????CSV?JSON???XML?????<br> * ()??CSV???<br> * String csvData = "aaa,bbbb,123,";<br> * responseContext.setResponseType(ResponseContext.RESPONSE_TYPE_CSV);<br> * responseContext.setResponseEncType(CommonDefine.ENCODE_UTF_8);<br> * responseContext.setResponseCsv(csvData);<br> * responseContext.setExportFileName("Sample.csv");<br> * * <br> * <br> * ??<b>com.bee_wkspace.labee_fw.core.base.BaseBlogic</b> * ???????<br> * ?<b>com.bee_wkspace.labee_fw.common.db.DBAccess</b>???( * ?? <b>dba</b>)<br> * ????????<br> * <b>preProcess()</b>???????<br> * <b>finallyProcess()</b>???????<br> * ??????????????<br> * <b>preProcess()</b>?<b>finallyProcess()</b>????????<br> * ???????????<br> * (??????????????)<br> * * <br> * ?????SQL???????????????<br> * () <b>dba.commi()</b>, <b>dba.rollback()</b><br> * * @author ARTS Laboratory * * $Id: AppBaseBlogic.java 554 2016-08-12 21:19:00Z pjmember $ */ public class AppBaseBlogic<T extends AppBaseBean> extends BaseBlogic<T> { /** DB */ protected DBAccess dba = null; /** * * */ public AppBaseBlogic() { super(); } /** * ??<br> * * @throws FwException * @see com.bee_wkspace.labee_fw.core.base.BaseBlogic#init() */ @Override public void init() throws FwException { super.init(); ScreenContext screenContext = settingScreenContext(env.getTargetName()); bean.setScreenContext(screenContext); bean.setEnv(env); } /** * ?????<br> * (?????????????????)<br> * ??????<br> * ???????? * * @return ?<br> * ?false?????????????? * @throws Exception * @see com.bee_wkspace.labee_fw.core.base.BaseBlogic#preProcess() */ @Override public boolean preProcess() throws Exception { super.preProcess(); if (SystemConfigMng.isUseDatabaseFlg()) { openDB(); } // ? bean.initError(); return true; } /** * ??????<br> * (?????????????????)<br> * ???????? * * @throws Exception * @see com.bee_wkspace.labee_fw.core.base.BaseBlogic#postProcess() */ @Override public void postProcess() throws Exception { super.postProcess(); } /** * ?????????????<br> * (?????????????????)<br> * ??????<br> * ???????? * * @throws Exception * @see com.bee_wkspace.labee_fw.core.base.BaseBlogic#finallyProcess() */ @Override public void finallyProcess() throws Exception { super.finallyProcess(); // ? if (SystemConfigMng.isUseDatabaseFlg()) { closeDB(); } } /** * Ajax????DOM????JSON????<br> * ?JsonValueContext?DOM?ID???????JSON?????<br> * * @param jsonvalContext DOM????JSON * @return ? */ protected ResponseContext setAjaxJsonResponse(JsonValueContext jsonvalContext) { try { if (jsonvalContext != null) { ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(jsonvalContext.getJsonValues()); responseContext.setResponseType(ResponseContext.RESPONSE_TYPE_JSON); responseContext.setResponseJson(json); } } catch (Exception e) { e.printStackTrace(); } return responseContext; } /** * ??ID?JSP??????<br> * JSP?????Bean????????<br> * JSP???????????? * * @param screenId ?ID * @return ? * @throws FwException */ protected ResponseContext setOtherScreenIdResponse(String screenId) throws FwException { ScreenContext screenContext = settingScreenContext(screenId); bean.setScreenContext(screenContext); return responseContext; } /** * ??????????<br> * ?????id???<br> * ?????5?????????<br> * ????<br> * * @param idName ID?? * @param value */ protected void addPasswdSetCookie(String idName, String value) { Cookie cookie = new Cookie(idName, value); cookie.setMaxAge(5); bean.addPasswdSetName(idName); super.addCookie(cookie); } /** * DB? * * @throws Exception */ protected void openDB() throws Exception { try { if (dba == null) { dba = new DBAccess(); } dba.openDB(); } catch (Exception e) { LogWriter.error(e); throw e; } } /** * DB? */ protected void closeDB() { try { if (dba != null) { dba.closeDB(); dba = null; } } catch (Exception e) { LogWriter.error(e); } } /** * ???? * * @param screnId ?ID * @return ? * @throws FwException */ private ScreenContext settingScreenContext(String screnId) throws FwException { ScreenContext screenContext = ResourceMng.getScreenContext(screnId); if (screenContext == null) { throw new FwException(MessageLabelUtil.getMessage(SysMsgCodeDefine.SYS10012, SystemConfigMng.getSystemLocale(), screnId)); } // ?? if (env.isSmtPhoneFlg() && StringUtil.isNull(screenContext.getJspSphone())) { responseContext.setForwardPath(screenContext.getJspSphone()); // ?? } else if (env.isTabletPadFlg() && StringUtil.isNull(screenContext.getJspTablet())) { responseContext.setForwardPath(screenContext.getJspTablet()); // PC?? } else { responseContext.setForwardPath(screenContext.getJspPC()); } responseContext.setResponseType(ResponseContext.RESPONSE_TYPE_WEB); // ?? if (StringUtil.isNull(screenContext.getViewTitle()) == false) { if (StringUtil.isNull(screenContext.getLabelCd())) { screenContext.setViewTitle(MessageLabelUtil.getWordLabel(screenContext.getLabelCd(), screenContext.getLabelDiv(), bean.getMsgLocale())); } else { screenContext.setViewTitle(screenContext.getScreenName()); } } return screenContext; } }