Hello! I want to write a new Jini attribute, I have followed all the instructions in the Core Jini book, I have compiled the code from the book , I even have a Bean for my new attribute, but when I want my client to search based on this new attribute, it doesn't work!!! I would really appreciate if someone would help me. My attribute is called Photo, and it is supposed to give the client information about an image:
Photo(String city, String format, String color, String size, String dimensions)
The service browser that comes with Jini shows my new attribute, but it does now show it's parameters (they appear all "null") it just shows the standard ones like "Name" and "Location". It looks like this on the attribute window of the Jini browser:
Name [net.jini.lookup.entry.Name(name=Photo archive of mexican colonial cities)] Photo [Photo(city=null,format=null,color=null,size=null,dimensions=null)] Comment [net.jini.lookup.entry.Comment(comment=Gif/jpeg images of Mexico City and Guanajuato)] Location [net.jini.lookup.entry.Location(floor=2,room=20,building=Public Library, Mexico D.F.)]
Does anybody know why this is happening? And why my client doesn't do the searching based on the attribute?
I have this on the client code:
public void discovered(DiscoveryEvent evt) {
ServiceRegistrar[] registrars = evt.getRegistrars(); Class [] classes = new Class[] {Images.class};
Entry[] attr = new Entry[1]; attr[0] = new Photo("Mexico DF", "jpeg", "color", "11886 bytes", "180 x 200 pixels");
ServiceTemplate template = new ServiceTemplate(null, classes, attr);
for (int n = 0; n < registrars.length; n++) { System.out.println("\nService Found..."); ServiceRegistrar registrar = registrars[n]; ServiceMatches matches; try { matches = registrar.lookup(template, 10); } catch(java.rmi.RemoteException e) { e.printStackTrace(); continue; } for (int m = 0; m < matches.items.length; m++) ...
Location ltn = new Location("2", "20", "Public Library, Mexico D.F."); Comment comment = new Comment("Gif/jpeg images of Mexico City and Guanajuato"); Name name = new Name("Photo archive of mexican colonial cities");
Photo photo1 = new Photo("Mexico DF", "jpeg", "color", "11886 bytes", "180 x 200 pixeles"); Photo photo2 = new Photo("Mexico DF", "jpeg", "color", "12717 bytes", "180 x 203 pixeles"); Photo photo3 = new Photo("Mexico DF", "jpeg", "color", "14518 bytes", "444 x 292 pixeles"); Photo photo4 = new Photo("Mexico DF", "jpeg", "color", "37993 bytes", "480 x 360 pixeles"); Photo photo5 = new Photo("Mexico DF", "jpeg", "color", "19013 bytes", "267 x 400 pixeles");
They should be public - if they're not, they won't be serialized and transferred. To be a valid field in the Entry implementation, the attribute field must be public.
> Can you post the code for Photo itself? > > Are the attributes public or private? > > They should be public - if they're not, they won't be > serialized and transferred. To be a valid field in the > Entry implementation, the attribute field must be public.
Hello Dan, thank you very much for your reply, I had already started to give up on the problem, I hadn't logged in for a while. Here is the code for Photo, all the attributes are public:
import net.jini.entry.AbstractEntry;
public class Photo extends AbstractEntry {
public String city; public String format; public String color; public String size; public String dimensions;
public Photo() { city = new String(); format = new String(); color = new String(); size = new String(); dimensions = new String();
}
public Photo(String city, String format, String color, String size, String dimensions) { city = new String(); format = new String(); color = new String(); size = new String(); dimensions = new String(); }
Well I don't know much about Jini, but I do know Java, and it looks to me like this in the constructor code is wrong:
public Photo(String city, String format, String color,
String size, String dimensions) {
city = new String();
format = new String();
color = new String();
size = new String();
dimensions = new String();
}
I think what it should do is set the instance variables to the values passed in, not to new String(). Unless Jini is supposed to be doing something tricky with the values and the public instance variables after the constructor is called, then I would expected them all to be the null String, as returned by your test.
> Well I don't know much about Jini, but I do know Java, and > it looks to me like this in the constructor code is > wrong: > >
> public Photo(String city, String format, String
> ring color,
> String size, String dimensions) {
> city = new String();
> format = new String();
> color = new String();
> size = new String();
> dimensions = new String();
> }
>
> I think what it should do is set the instance variables to > the values passed in, not to new String(). Unless Jini is > supposed to be doing something tricky with the values and > the public instance variables after the constructor is > called, then I would expected them all to be the null > String, as returned by your test.
Hello Steve, thank you very much for your reply, I was wondering how the constructor would actually look like, 'cause I've been trying to fix it but it's still working the same.
Hello Steve, thank you very much for your reply, I was wondering how the constructor would actually look like, 'cause I've been trying to fix it but it's still working the same.
Okay, well the constructor is certainly not right but that doesn't explain why the ServiceBrowser shows nulls for each field. Even with the faulty constructor we should be seeing empty strings not nulls, I think.
As a test, rather than extend AbstractEntry, implement net.jini.core.entry.Entry and add a toString method like:
<pre> public String toString() { return city + format + color + size + dimensions; }
And let's see what you get in the browser then.....