- PR -

「メソッド CmSessionById.putValue(String, Object) は HttpSession からの使用すべきでないメソッドをオ

1
投稿者投稿内容
lrabby
会議室デビュー日: 2004/02/25
投稿数: 16
投稿日時: 2004-03-01 15:16
いつもお世話になっております。李軍峰と申します。

javaのクラスを作成する時に、以下のコンパイルエラーが出ます。

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
メソッド CmSessionById.putValue(String, Object) は
HttpSession からの使用すべきでないメソッドをオーバーライド
します。
CmSessionMng.java BizFirm/java/nnes/cm 行 272
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

また、作成したクラスは、以下のとおりです。

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
package cm;

import java.util.*;
import javax.servlet.http.*;

public class CmSessionMng {

public static final int USE_HTTPSESSION = 1;
public static final int USE_SESSIONID = 2;
public static final int USE_COOKIE = 3;

private static String strSessionTag="__ID__";

private static int m_nSessionType = USE_HTTPSESSION;

private static Hashtable m_hashSessions = new Hashtable();

public CmSessionMng() {
}

public void setSessionTag(String strTag)
{
strSessionTag = strTag;
}

public String getSessionTag()
{
return(strSessionTag);
}

public static void setSessionType(int nSessionType) {
m_nSessionType = nSessionType;
}

public static int getSessionType(){
return( m_nSessionType );
}

public static synchronized void removeSession(String strSessionId) {
m_hashSessions.remove(strSessionId);
}

public static HttpSession getSession(HttpServletRequest req, String strSessionId)
throws CmBaseException
{
HttpSession session = null;

if (m_nSessionType == USE_HTTPSESSION) {
session = req.getSession();
}
else if (m_nSessionType == USE_SESSIONID) {
checkSessions();

if ((strSessionId == null)
|| ((session = (HttpSession) m_hashSessions.get(strSessionId)) == null)) {
session = new CmSessionById();
m_hashSessions.put(session.getId(), session);
} else {
CmSessionTime st = (CmSessionTime) session;
st.setLastAccessTime();
}
}

return(session);
}

private static void checkSessions() {
Enumeration enum = m_hashSessions.elements();
CmSessionTime st;
Date now = new Date();

if (enum == null) {
return;
}

try {
while((st = (CmSessionTime) enum.nextElement()) != null) {
if (st.isTimeOut(now)) {
HttpSession session = (HttpSession) st;
m_hashSessions.remove(session.getId());
}
}
} catch (NoSuchElementException e) {
return;
}

}
}

interface CmSessionTime {
public boolean isTimeOut(Date now);
public void setLastAccessTime();
}

class CmSessionById implements HttpSession, CmSessionTime {
private static final int PWD_MAXSIZE = 16;
private static final int PWD_MINSIZE = 8;
private static final int PRINTABLE_CODE_SIZE = 0x7a-0x30;
private static final int PRINTABLE_CODE_START = 0x30;

private Hashtable m_hashAttribute = new Hashtable();
private String strSessionId;
private long lMaxInactiveInterval = 3600 * 1000;
private Date createDate = null;
private Date lastDate = null;

public CmSessionById()
throws CmBaseException
{
strSessionId = generateSessionId();
lastDate = createDate = new Date();
}

public boolean isTimeOut(Date now)
{

long d = now.getTime() - lastDate.getTime();

if (d > lMaxInactiveInterval) {
return(true);
}

return(false);
}

public void setLastAccessTime()
{
lastDate = new Date();
}

public void invalidate() {
CmSessionMng.removeSession(strSessionId);
}

public String getId() {
return(strSessionId);
}

public long getCreationTime()
throws IllegalStateException
{
if (createDate == null) {
throw new IllegalStateException("Not Set CreateTime");
}
return(createDate.getTime());
}

public long getLastAccessedTime()
{
if (lastDate == null) {
return(0);
}
return(lastDate.getTime());
}

public void setMaxInactiveInterval(int seconds)
{
lMaxInactiveInterval = seconds * 1000;
}

public int getMaxInactiveInterval()
{

return((int)(lMaxInactiveInterval/1000));
}

public boolean isNew()
throws IllegalStateException
{
boolean bStatus = false;

if (lastDate == createDate) {
bStatus = true;
}

return(bStatus);
}

public Enumeration getAttributeNames()
throws IllegalStateException
{
return(m_hashAttribute.keys());
}

public Object getAttribute(String name)
throws IllegalStateException
{
if (name == null) {
throw new IllegalStateException("getAttribute Invalid args");
}
return(m_hashAttribute.get(name));
}

public void removeAttribute(String name)
throws IllegalStateException
{
if (name == null) {
throw new IllegalStateException("removeAttribute Invalid args");
}

Object obj = m_hashAttribute.remove(name);

if (obj == null) {
throw new IllegalStateException("Can't Find Attribute");
}
}

public void setAttribute(String name, Object value)
throws IllegalStateException
{
if ((name == null) || (value == null)) {
throw new IllegalStateException("setAttribute Invalid args");
}
m_hashAttribute.put(name, value);
}

public void putValue(String name, Object value)
{
if ((name == null) || (value == null)) {
return;
}
m_hashAttribute.put(name, value);
}

public Object getValue(String name)
{
return(m_hashAttribute.get(name));
}

public void removeValue(String name)
{
m_hashAttribute.remove(name);
}

public String getValueNames() []
{
return(null);
}

public HttpSessionContext getSessionContext()
{
return(null);
}

/**
* Generate session Id <BR>
* @return value of session Id
* @exception
* @see CmSession#strSessionId
* @author
*/
public String generateSessionId()
throws CmBaseException
{

String strValue = "";

try{
int nStrLen; //.セッションID長
int nRandomData; //.乱数データ
Date dateObj = null; //.Dateオブジェクト
Random generator = null; //.Randomオブジェクト
byte bSessionId[] = new byte[PWD_MAXSIZE]; //.セッションID

/* Randomクラス生成 */
dateObj = new Date();
generator = new Random( dateObj.getTime() );

/* セッションID長を取得 */
nStrLen = PWD_MINSIZE + generator.nextInt(PWD_MAXSIZE - PWD_MINSIZE);

/* 乱数データを一文字一文字入念につくる */
for (int i = 0; i < nStrLen; i++){
nRandomData = generator.nextInt(128) % PRINTABLE_CODE_SIZE
+ PRINTABLE_CODE_START;
bSessionId[i] = (byte)nRandomData;
}

/* 乱数データセッションIDをString型に変換 */
strValue = new String(bSessionId, 0, nStrLen);
}
catch(Exception e){
throw new CmBaseException(CmBaseException.EGEN_SESSIONID);
}

return(strValue);
}
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

どなたか解決方法をご存知の方、ご教授お願いいたします。

以上、よろしくお願いいたします。
maru
ぬし
会議室デビュー日: 2003/01/27
投稿数: 412
投稿日時: 2004-03-01 15:23
>メソッド CmSessionById.putValue(String, Object) は
>HttpSession からの使用すべきでないメソッドをオーバーライド
>します。
>CmSessionMng.java BizFirm/java/nnes/cm 行 272
このエラーメッセージから何を検討されましたか?
なぜこのようなコンパイルエラーがでるのかはご存知ですか?

http://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?topic=9712&forum=12
でもそうですが、一度Javaの基本からきちんと勉強されてはいかがでしょうか?
大きなプログラムではなく、小さなプログラムから。なぜ、コンパイルエラーがでるのか?
Javaというプログラミング言語だけでなくオブジェクト指向も含めて。

このレベルの問題でつまずいて、その都度ソースを貼り付けてご教示願いますでは、
なかなかご自身の作業も理解度も進みませんよ


[ メッセージ編集済み 編集者: maru 編集日時 2004-03-01 15:29 ]
1

スキルアップ/キャリアアップ(JOB@IT)