FilePresenter Proxy management.

This commit is contained in:
Christian P. MOMON 2010-08-08 00:25:02 +02:00
parent ecf3786506
commit 69f1edfc94
2 changed files with 258 additions and 0 deletions

View file

@ -0,0 +1,184 @@
/*
* Copyright 2009 Christian Momon, All rights reserved.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.xid;
import java.util.Vector;
/**
*
*/
public class FilePresenters extends Vector<FilePresenter>
{
private static final long serialVersionUID = 7058868685681354293L;
static protected org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (FilePresenters.class);
/**
*
*/
public FilePresenters ()
{
super ();
}
/**
*
*/
public FilePresenters (FilePresenters source)
{
super ();
for (FilePresenter presenter : source)
{
this.add(presenter);
}
}
/**
*
*/
public boolean exists (String source)
{
boolean result;
if (this.getBySource(source) == null)
{
result = false;
}
else
{
result = true;
}
//
return(result);
}
/**
*
*/
public FilePresenter getByIndex (int id)
{
FilePresenter result;
result = this.get(id);
//
return(result);
}
/**
*
*/
public FilePresenter getBySource (String source)
{
FilePresenter result;
if (source == null)
{
result = null;
}
else
{
result = null;
boolean ended = false;
int presenterIndex = 0;
while (!ended)
{
if (presenterIndex < this.size())
{
FilePresenter presenter = this.get(presenterIndex);
if (presenter.source().equals(source))
{
result = presenter;
ended = true;
}
else
{
presenterIndex += 1;
}
}
else
{
ended = true;
result = null;
}
}
}
//
return(result);
}
/**
*
*/
public int getIndexOf (String source)
{
int result;
if (source == null)
{
result = -1;
}
else
{
result = -1;
boolean ended = false;
int presenterIndex = 0;
while (!ended)
{
if (presenterIndex < this.size())
{
FilePresenter presenter = this.get(presenterIndex);
if (presenter.source().equals(source))
{
result = presenterIndex;
ended = true;
}
else
{
presenterIndex += 1;
}
}
else
{
ended = true;
result = -1;
}
}
}
//
return(result);
}
/**
*
*/
public String toString()
{
String result;
result = "";
//
return(result);
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -0,0 +1,74 @@
package fr.devinsy.xid;
import java.io.File;
import java.text.*;
import java.util.*;
/**
*
*/
public class FilePresentersProxy
{
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (FilePresentersProxy.class);
private static FilePresentersProxy instance = null;
protected FilePresenters presenters = null;
/**
*
*/
protected FilePresentersProxy () throws Exception
{
this.presenters = new FilePresenters();
}
/**
*
*/
public static FilePresentersProxy instance () throws Exception
{
FilePresentersProxy result;
if (FilePresentersProxy.instance == null)
{
instance = new FilePresentersProxy ();
}
result = instance;
//
return (result);
}
/**
*
*/
public FilePresenter getBySource(String source) throws Exception
{
FilePresenter result;
if (source == null)
{
result = null;
}
else
{
result = this.presenters.getBySource(source);
if (result == null)
{
result = new FilePresenter(source);
this.presenters.add(result);
}
}
//
return (result);
}
}
// ////////////////////////////////////////////////////////////////////////