KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > samples > photos > PhotoRepository


1 /*
2
3   Copyright (C) AOPSYS (http://www.aopsys.com)
4
5   $licence$ */

6
7 package org.objectweb.jac.samples.photos;
8
9 import org.objectweb.jac.aspects.user.Profile;
10 import org.objectweb.jac.core.ObjectRepository;
11 import org.objectweb.jac.core.rtti.ClassRepository;
12 import java.util.Collection JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.Vector JavaDoc;
15 import java.util.Set JavaDoc;
16 import java.util.HashSet JavaDoc;
17 import java.util.List JavaDoc;
18
19 public class PhotoRepository
20 {
21
22    Set JavaDoc photos = new HashSet JavaDoc();
23
24    public PhotoRepository () {
25    }
26
27    /**
28     * Get the value of photos.
29     * @return value of photos.
30     */

31    public Set JavaDoc getPhotos() {
32       return photos;
33    }
34
35    /**
36     * Search for a photo with its title.
37     * @param title the title of the photo.
38     * @return photos found.
39     */

40    public List JavaDoc searchTitle(String JavaDoc title)
41    {
42       Iterator JavaDoc i = photos.iterator();
43       Vector JavaDoc result = new Vector JavaDoc();
44       while ( i.hasNext() ) {
45          Photo curphoto = (Photo)i.next();
46          if (curphoto.getTitle()!=null) {
47             if ( curphoto.getTitle().indexOf( title ) != -1 ) {
48                result.add ( curphoto );
49             }
50          }
51       }
52       /*
53       Photo[] res = new Photo[result.size()];
54       System.arraycopy(result.toArray(),0,res,0,result.size());
55       */

56       
57       return result;
58    }
59
60    /**
61     * Add a photo to photos
62     * @param photo the photo to add
63     */

64    public void addPhoto (Photo photo) {
65       photos.add(photo);
66    }
67
68    /**
69     * Remove a photo from photos
70     * @param photo the photo to remove
71     */

72    public void delPhoto(Photo photo) {
73       photos.remove(photo);
74    }
75
76    /**
77     * Remove all photos.
78     */

79    public void clearPhotos() {
80       photos.clear();
81    }
82
83    /**
84     * Filter out "owner" and "default" profile
85     */

86    public static Collection JavaDoc getProfiles(Object JavaDoc substance) {
87       Collection JavaDoc profiles =
88          ObjectRepository.getObjects(
89             ClassRepository.get().getClass(Profile.class));
90       Vector JavaDoc result = new Vector JavaDoc(profiles.size());
91       Iterator JavaDoc it=profiles.iterator();
92       while(it.hasNext()) {
93          Profile cur=(Profile)it.next();
94          if (!cur.getName().equals("owner") &&
95              !cur.getName().equals("default")) {
96             result.add(cur);
97          }
98       }
99       return result;
100    }
101
102    /*
103     * GUI methods
104     */

105
106    /*
107    public static Person selectionHandler(org.objectweb.jac.aspects.gui.SwingCustomizedGUI gui,
108                                          org.objectweb.jac.core.rtti.CollectionItem collection,
109                                          Photo photo) {
110       System.out.println("selectionHandler("+photo+")");
111       return photo.getAuthor();
112    }
113    */

114 }
115
116 // Local Variables: ***
117
// c-basic-offset:3 ***
118
// End: **
119

120
Popular Tags