📄 remotesessionimpl.java
字号:
package org.rapla.server.internal;
import java.util.HashMap;
import org.apache.avalon.framework.logger.Logger;
import org.rapla.entities.User;
import org.rapla.facade.RaplaComponent;
import org.rapla.framework.RaplaContext;
import org.rapla.framework.RaplaException;
import org.rapla.server.RaplaRemoteServiceFactory;
import org.rapla.server.RemoteSession;
import org.rapla.storage.StorageOperator;
/** Implementation of RemoteStorage as a RemoteService
* @see org.rapla.server.RemoteStorage
* @see org.rapla.components.rpc.RemoteServiceDispatcher
*
*/
public class RemoteSessionImpl extends RaplaComponent implements RemoteSession {
/**
*
*/
String username;
HashMap remoteServiceMap = new HashMap();
Logger logger;
StorageOperator operator;
long serverStartTime;
public RemoteSessionImpl(RaplaContext context, String clientName, long serverStartTime) throws RaplaException {
super( context );
this.serverStartTime = serverStartTime;
operator = (StorageOperator)context.lookup(StorageOperator.ROLE);
logger = super.getLogger().getChildLogger(clientName);
}
public Logger getLogger() {
return logger;
}
public RaplaContext getContext() {
return super.getContext();
}
Object lookupService( String name) throws RaplaException {
Object serviceSession =remoteServiceMap.get( name);
if ( serviceSession != null) {
return serviceSession;
}
RaplaRemoteServiceFactory service = (RaplaRemoteServiceFactory)getContext().lookup( RaplaRemoteServiceFactory.ROLE + "/" + name);
if ( service == null)
throw new RaplaException( "Can't find Remoteservice for Role " + name);
serviceSession = service.createRemoteService( this);
remoteServiceMap.put( name, serviceSession);
return serviceSession;
}
String getUsername() {
return username;
}
public User getUser() throws RaplaException {
String username = getUsername();
if (username == null)
throw new IllegalStateException("No username found in session.");
User user = this.operator.getUser(username);
if (user == null)
throw new RaplaException("No user found for username: " + username);
return user;
}
public boolean isAuthentified() {
return getUsername() != null;
}
public void setUsername( String username )
{
this.username = username;
}
public long getServerStartTime()
{
return serverStartTime;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -