Hello wicket users
I creating a panel that display an image that is stored in a java
object as a byte array
public class OzImagePanel extends Panel {
private Image img;
private OzImage imgModel;
public OzImagePanel(final String id,FilePrx filePx)
{
super(id);
imgModel=new OzImage(filePx);
getApplication().getSharedResources().add("panelImg",imgModel);
add(img=new Image("img",new ResourceReference("panelImg")));
}
}
public class OzImage extends Resource {
private OzResourceStream resourceStream;
private Oz.Files.FilePrx filePx;
public OzImage(FilePrx filePx)
{
super();
this.filePx=filePx;
}
/* (non-Javadoc)
* @see wicket.Resource#getResourceStream()
*/
public IResourceStream getResourceStream() {
// TODO Auto-generated method stub
resourceStream=new OzResourceStream(filePx);
return resourceStream;
}
}
public class OzResourceStream implements IResourceStream{
private NodePrx fileNodePx;
public OzResourceStream(Oz.Files.NodePrx nodePx)
{
fileNodePx=nodePx;
}
public void close()
{
}
public String getContentType()
{
return fileNodePx.getContentType();
}
public InputStream getInputStream()
{
InputStream stream=null;
if(fileNodePx.ice_isA("::Oz::Files::File"))
{
int fileSize=0;
FilePrx
filePx=FilePrxHelper.uncheckedCast(fileNodePx);
byte fileBuffer[]=new
byte[(int)filePx.getSize()];
int chunks=(int)filePx.countChunks();
for(int a=0;a<chunks;++a)
{
byte
chunkBuffer[]=filePx.readChunk(a).read();
for(int b=0;b<chunkBuffer.length;++b)
{
fileBuffer[fileSize]=chunkBuffer[b];
fileSize++;
}
}
stream=new ByteArrayInputStream(fileBuffer);
}
return stream;
}
public long length()
{
return
FilePrxHelper.uncheckedCast(fileNodePx).getSize();
}
public Time lastModifiedTime()
{
return Time.now();
}
}
This code works as spected and the image is displayed OK the problem i
see is that if i create multipe OzImagePanel all objects use the Same
resource.
i think that the way to this works ok is create an unique id for each
resource and store it in an internal attribute of the panel
what you think about this?
any ideas to improve my code
thanks to all you
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user