📄 remotestorageimpl.java
字号:
ArrayList completeList = new ArrayList();
completeList.add( entity );
Iterator it = entity.getSubEntities();
while (it.hasNext()) {
completeList.add( it.next() );
}
List list = makeTransactionSafe( completeList );
getLogger().debug("Get entity " + entity);
return list;
}
}
public List getReservations(Date start,Date end) throws RaplaException
{
checkAuthentified();
User user = null;
this.getLogger().debug ("A RemoteServer wants to reservations from ." + start + " to " + end);
synchronized (operator.getLock())
{
ArrayList completeList = new ArrayList();
List reservations = operator.getReservations(user, start, end );
completeList.addAll(reservations);
Iterator it = reservations.iterator();
while (it.hasNext()) {
Iterator it2 = ((RefEntity)it.next()).getSubEntities();
while (it2.hasNext()) {
completeList.add( it2.next() );
}
}
List list = makeTransactionSafe( completeList );
getLogger().debug("Get reservations " + start + " " + end + ": "
+ reservations.size() + "," + list.size());
return list;
}
}
public RaplaContext getContext() throws RaplaException {
return session.getContext();
}
public void restartServer() throws RaplaException {
checkAuthentified();
if (!getSessionUser().isAdmin())
throw new RaplaSecurityException("Only admins can restart the server");
((ShutdownService) getContext().lookup(ShutdownService.ROLE)).shutdown(null, true);
}
public long getServerTime() throws RaplaException {
return System.currentTimeMillis();
}
public void dispatch(UpdateEvent evt)
throws RaplaException {
checkAuthentified();
try {
User user;
if ( evt.getUserId() != null)
{
user = (User) operator.resolveId(evt.getUserId());
}
else
{
user = session.getUser();
}
synchronized (operator.getLock())
{
EntityResolver resolver = operator.createEntityResolver(evt.getStoreObjects()
,operator.getCache());
Iterator it = evt.getStoreObjects().iterator();
while (it.hasNext()) {
SimpleEntity entity = (SimpleEntity) it.next();
if (getLogger().isDebugEnabled())
getLogger().debug("Contextualizing " + entity);
entity.resolveEntities( resolver);
}
it = evt.getRemoveObjects().iterator();
while (it.hasNext()) {
SimpleEntity entity = (SimpleEntity) it.next();
entity.resolveEntities( resolver);
}
it = evt.getStoreObjects().iterator();
while (it.hasNext()) {
SimpleEntity entity = (SimpleEntity) it.next();
security.checkWritePermissions(user,entity);
}
it = evt.getRemoveObjects().iterator();
while (it.hasNext()) {
SimpleEntity entity = (SimpleEntity) it.next();
security.checkWritePermissions(user,entity);
}
if (this.getLogger().isDebugEnabled())
this.getLogger().debug("Dispatching changes to " + operator.getClass());
operator.dispatch(evt);
if (this.getLogger().isDebugEnabled())
this.getLogger().debug("Changes dispatched returning result.");
}
} catch (DependencyException ex) {
throw ex;
} catch (RaplaException ex) {
this.getLogger().error(ex.getMessage(),ex);
throw ex;
} catch (Exception ex) {
this.getLogger().error(ex.getMessage(),ex);
throw new RaplaException(ex);
}
}
public Object createIdentifier(RaplaType raplaType) throws RaplaException {
checkAuthentified();
synchronized (operator.getLock())
{
//User user =
getSessionUser(); //check if authenified
return operator.createIdentifier(raplaType);
}
}
public void authenticate(String username,
String password) throws RaplaException
{
synchronized (operator.getLock())
{
getSessionUser(); //check if authenified
server.authenticate( username, password );
}
}
public boolean canChangePassword() throws RaplaException {
checkAuthentified();
synchronized (operator.getLock())
{
return !authenticationStore && operator.canChangePassword();
}
}
public void changePassword(String username
,char[] oldPassword
,char[] newPassword
) throws RaplaException
{
checkAuthentified();
if ( authenticationStore ) {
throw new RaplaException("Rapla can't change your password. "
+ "Authentication is done via plugin." );
}
synchronized (operator.getLock()) {
User sessionUser = getSessionUser();
if (!sessionUser.isAdmin()) {
operator.authenticate(username,new String(oldPassword));
}
User user = operator.getUser(username);
operator.changePassword(user,oldPassword,newPassword);
}
}
static public UpdateEvent createUpdateEvent( RaplaContext context,String xml, LocalCache cache ) throws RaplaException
{
EntityStore store = new EntityStore( cache, cache.getSuperCategory());
RaplaContext inputContext = new IOContext().createInputContext(context,store,new IdTable());
Logger logger = (Logger)context.lookup( Logger.class.getName());
RaplaInput xmlAdapter = new RaplaInput( logger.getChildLogger("reading"));
RaplaMainReader contentHandler = new RaplaMainReader( inputContext);
try
{
xmlAdapter.read(new StringReader( xml), contentHandler, false);
}
catch (IOException e)
{
throw new RaplaException(e);
}
UpdateEvent event = new UpdateEvent();
event.setRepositoryVersion(store.getRepositoryVersion());
for (Iterator it = store.getList().iterator();it.hasNext();)
{
RefEntity object = (RefEntity)it.next();
event.putStore( object);
}
for (Iterator it = store.getRemoveIds().iterator();it.hasNext();)
{
Object id = (Object)it.next();
RefEntity entity = (RefEntity)cache.get( id );
if ( entity != null)
{
event.putRemove( entity);
}
}
return event;
}
static public String createUpdateEvent( RaplaContext context, LocalCache cache,UpdateEvent evt) throws RaplaException, IOException
{
RaplaDefaultContext ioContext = new IOContext().createOutputContext( context, cache, true, true);
StringWriter stringWriter = new StringWriter( );
RaplaMainWriter writer = new RaplaMainWriter(ioContext);
BufferedWriter buf = new BufferedWriter(stringWriter);
writer.setWriter( buf);
writer.printList( evt.getStoreObjects(),evt.getRemoveObjects(), evt.getRepositoryVersion());
buf.flush();
String xml = stringWriter.toString();
return xml;
}
private static List makeTransactionSafe(List objectList) {
List saveList = new ArrayList();
Iterator it = objectList.iterator();
while (it.hasNext()) {
saveList.add(((Mementable)it.next()).clone());
}
return saveList;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -