just before adding authorization service.
[photos] / src / main / java / org / wamblee / photos / model / filesystem / FindByIdCallback.java
1 /*
2  * Copyright 2005 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */ 
16 package org.wamblee.photos.model.filesystem;
17
18 import java.io.File;
19 import java.io.IOException;
20 import java.util.List;
21
22 import org.wamblee.cache.Cache;
23 import org.wamblee.photos.model.PhotoEntry;
24
25 /**
26  * Callback interface used to find a photo entry by id. 
27  */
28 class FindByIdCallback implements EntryFoundCallback {
29     /**
30      * Id of the entry to look for. 
31      */
32         private String _id;
33     
34     /**
35      * Search result or null if not found yet.  
36      */
37         private PhotoEntry _entry;
38     
39     /**
40      * Cache to use. 
41      */
42     private Cache _cache; 
43         
44     /**
45      * Constructs the callback. 
46      * @param aId Photo entry id to look for. 
47      */
48         public FindByIdCallback(String aId, Cache aCache) {
49                 _id = aId;    
50                 _entry = null; 
51         _cache = aCache; 
52         }
53     
54     /**
55      * Gets the entry that was found. 
56      * @return Photo entry or null if not found. 
57      */
58         public PhotoEntry getEntry() {
59                 return _entry;    
60         }
61     
62     /*
63      *  (non-Javadoc)
64      * @see org.wamblee.photos.model.file.EntryFoundCallback#photoFound(java.io.File, java.io.File, java.lang.String)
65      */
66         public boolean photoFound(List<PhotoEntry> aEntries, File aThumbnail, File aPhoto, String aPath) {
67                 if ( FileSystemPhoto.getId(aPath).equals(_id)) {
68                         _entry = new FileSystemPhoto(aThumbnail, aPhoto, aPath);
69                         return false; 
70                 }
71                 return true; // continue search.
72         }
73         
74     /*
75      *  (non-Javadoc)
76      * @see org.wamblee.photos.model.file.EntryFoundCallback#albumFound(java.io.File, java.lang.String)
77      */
78         public boolean albumFound(List<PhotoEntry> aEntries, File aAlbum, String aPath) throws IOException {
79                 FileSystemAlbum albumEntry = new FileSystemAlbum(aAlbum, aPath, _cache); 
80                 if ( aAlbum.getName().equals(_id)) {
81                         _entry = albumEntry; 
82                         return false; 
83                 }
84                 return albumEntry.traverse(albumEntry.getPath(), aEntries, aAlbum, this); // continue search.
85         }
86 }