accountserviceshell.java

来自「非常有影响的 j道 论 坛 源码 国外很有明的专家编写的 ....对java爱好」· Java 代码 · 共 116 行

JAVA
116
字号
/*
 * Copyright 2007 the original author or jdon.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package com.jdon.jivejdon.service.imp.account;

import com.jdon.annotation.intercept.SessionContextAcceptable;
import com.jdon.annotation.intercept.Stateful;
import com.jdon.container.visitor.data.SessionContext;
import com.jdon.controller.events.EventModel;
import com.jdon.jivejdon.Constants;
import com.jdon.jivejdon.auth.ResourceAuthorization;
import com.jdon.jivejdon.dao.AccountDao;
import com.jdon.jivejdon.dao.SequenceDao;
import com.jdon.jivejdon.dao.util.OldUpdateNewUtil;
import com.jdon.jivejdon.model.Account;
import com.jdon.jivejdon.service.util.JtaTransactionUtil;
import com.jdon.jivejdon.service.util.SessionContextUtil;
import com.jdon.util.Debug;

@Stateful
public  class AccountServiceShell extends AccountServiceImp  {
	private final static String module = AccountServiceShell.class.getName();

	protected SessionContextUtil sessionContextUtil;

	protected SessionContext sessionContext;

	protected ResourceAuthorization resourceAuthorization;
	
	//this is stateful one user has one instance
	protected Account account;

	public AccountServiceShell(AccountDao accountDao, SequenceDao sequenceDao, SessionContextUtil sessionContextUtil, JtaTransactionUtil jtaTransactionUtil,
			ResourceAuthorization resourceAuthorization, OldUpdateNewUtil oldUpdateNewUtil,  EmailHelper emailHelper) {
		super(accountDao, sequenceDao, jtaTransactionUtil, oldUpdateNewUtil, emailHelper);
		this.sessionContextUtil = sessionContextUtil;
		this.resourceAuthorization = resourceAuthorization;

	}

	public Account getloginAccount() {
		if (account == null)
			account = sessionContextUtil.getLoginAccount(sessionContext);
		return account;
	}

	public Account getAccountByName(String username) {
		Account account = getloginAccount();
		if (resourceAuthorization.isAdmin(account))// if now is Admin
			return super.getAccountByName(username);
		else
			return account;

	}

	public void updateAccount(EventModel em) {
		Debug.logVerbose("enter updateAccount", module);
		Account accountInput = (Account) em.getModelIF();
		try {
			Account account = getloginAccount();
			if (account == null) {
				Debug.logError("this user not login", module);
				return;
			}
			if (resourceAuthorization.isOwner(account, accountInput)) {
				super.updateAccount(accountInput);
			}
		} catch (Exception daoe) {
			Debug.logError(" updateAccount error : " + daoe, module);
			em.setErrors(Constants.ERRORS);
		}
	}

	public void deleteAccount(EventModel em) {
		Account accountInput = (Account) em.getModelIF();
		try {
			Account account = getloginAccount();
			if (resourceAuthorization.isOwner(account, accountInput)) {
				super.deleteAccount(accountInput);
			}
		} catch (Exception e) {
			em.setErrors(Constants.ERRORS);
		}
	}


	/**
	 * @return Returns the sessionContext.
	 */
	public SessionContext getSessionContext() {
		return sessionContext;
	}

	/**
	 * @param sessionContext The sessionContext to set.
	 */
	@SessionContextAcceptable
	public void setSessionContext(SessionContext sessionContext) {
		this.sessionContext = sessionContext;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?