View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/filestore/client/src/java/org/astrogrid/filestore/resolver/FileStoreDelegateResolverMock.java,v $</cvs:source>
3    * <cvs:author>$Author: jdt $</cvs:author>
4    * <cvs:date>$Date: 2004/11/25 00:19:21 $</cvs:date>
5    * <cvs:version>$Revision: 1.2 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: FileStoreDelegateResolverMock.java,v $
9    *   Revision 1.2  2004/11/25 00:19:21  jdt
10   *   Merge from dave-dev-200410061224-200411221626
11   *
12   *   Revision 1.1.2.4  2004/11/09 17:41:36  dave
13   *   Added file:// URL handling to allow server URLs to be tested.
14   *   Added importInit and exportInit to server implementation.
15   *   Moved remaining tests out of extended test abd removed it.
16   *
17   *   Revision 1.1.2.3  2004/11/04 02:33:03  dave
18   *   Refactored mock delegate and config to make it easier to test filemanager with multiple filstores.
19   *
20   *   Revision 1.1.2.2  2004/10/21 21:00:13  dave
21   *   Added mock://xyz URL handler to enable testing of transfer.
22   *   Implemented importInit to the mock service and created transfer tests.
23   *
24   *   Revision 1.1.2.1  2004/10/19 14:56:15  dave
25   *   Refactored config and resolver to enable multiple instances of mock implementation.
26   *   Required to implement handling of multiple FileStore(s) in FileManager.
27   *
28   * </cvs:log>
29   *
30   */
31  package org.astrogrid.filestore.resolver ;
32  
33  import org.apache.commons.logging.Log ;
34  import org.apache.commons.logging.LogFactory ;
35  
36  import java.net.URL ;
37  
38  import java.util.Map ;
39  import java.util.HashMap ;
40  
41  import org.astrogrid.store.Ivorn ;
42  
43  import org.astrogrid.registry.client.query.RegistryService ;
44  
45  import org.astrogrid.filestore.common.FileStore ;
46  import org.astrogrid.filestore.common.ivorn.FileStoreIvornParser ;
47  import org.astrogrid.filestore.client.FileStoreDelegate ;
48  import org.astrogrid.filestore.client.FileStoreSoapDelegate ;
49  import org.astrogrid.filestore.client.FileStoreMockDelegate ;
50  import org.astrogrid.filestore.common.exception.FileStoreIdentifierException ;
51  import org.astrogrid.filestore.common.exception.FileStoreServiceException ;
52  
53  /***
54   * A resolver for mock filestores.
55   *
56   */
57  public class FileStoreDelegateResolverMock
58  	implements FileStoreDelegateResolver
59      {
60      /***
61       * Our debug logger.
62       *
63       */
64      private static Log log = LogFactory.getLog(FileStoreDelegateResolverMock.class);
65  
66      /***
67       * Public constructor.
68       *
69       */
70      public FileStoreDelegateResolverMock()
71          {
72          }
73  
74  	/***
75  	 * Our internal map of services.
76  	 *
77  	 */
78  	private Map map = new HashMap() ;
79  
80  	/***
81  	 * Register a new filestore.
82  	 *
83  	 */
84  	public void register(FileStoreDelegate store)
85  		throws FileStoreServiceException
86  		{
87  		map.put(
88  			store.identifier(),
89  			store
90  			);
91  		}
92  
93      /***
94       * Resolve an Ivorn into a delegate.
95       * @param ivorn An Ivorn containing a filestore identifier.
96       * @return A FileStoreDelegate for the service.
97       * @throws FileStoreIdentifierException If the identifier is not valid.
98       * @throws FileStoreResolverException If unable to resolve the identifier.
99       *
100      */
101     public FileStoreDelegate resolve(Ivorn ivorn)
102         throws FileStoreIdentifierException, FileStoreResolverException
103         {
104         log.debug("") ;
105         log.debug("----\"----") ;
106         log.debug("FileStoreDelegateResolverMock.resolve()") ;
107         log.debug("  Ivorn : " + ivorn) ;
108 		//
109 		// Parse the ivorn.
110 		String ident = new FileStoreIvornParser(
111 			ivorn
112 			).getServiceIdent() ;
113 		//
114 		// Lookup the filestore in our map.
115 		if (map.containsKey(ident))
116 			{
117 			return (FileStoreDelegate) map.get(ident) ;
118 			}
119 		else {
120 			throw new FileStoreResolverException(
121 				"FileStore not found"
122 				) ;
123 			}
124         }
125     }
126