View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/filestore/common/src/java/org/astrogrid/filestore/common/ivorn/FileStoreIvornFactory.java,v $</cvs:source>
3    * <cvs:author>$Author: dave $</cvs:author>
4    * <cvs:date>$Date: 2004/09/17 06:57:10 $</cvs:date>
5    * <cvs:version>$Revision: 1.4 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: FileStoreIvornFactory.java,v $
9    *   Revision 1.4  2004/09/17 06:57:10  dave
10   *   Added commons logging to FileStore.
11   *   Updated logging properties in Community.
12   *   Fixed bug in AGINAB deployment.
13   *   Removed MySpace tests with hard coded grendel address.
14   *
15   *   Revision 1.3.32.1  2004/09/17 01:08:36  dave
16   *   Updated debug to use commons logging API ....
17   *
18   *   Revision 1.3  2004/08/18 19:00:01  dave
19   *   Myspace manager modified to use remote filestore.
20   *   Tested before checkin - integration tests at 91%.
21   *
22   *   Revision 1.2.10.2  2004/08/02 14:54:15  dave
23   *   Trying to get integration tests to run
24   *
25   *   Revision 1.2.10.1  2004/07/28 03:00:17  dave
26   *   Refactored resolver constructors and added mock ivorn
27   *
28   *   Revision 1.2  2004/07/23 09:11:16  dave
29   *   Merged development branch, dave-dev-200407221513, into HEAD
30   *
31   *   Revision 1.1.2.1  2004/07/23 02:10:58  dave
32   *   Added IvornFactory and IvornParser
33   *
34   * </cvs:log>
35   *
36   */
37  package org.astrogrid.filestore.common.ivorn ;
38  
39  import org.apache.commons.logging.Log ;
40  import org.apache.commons.logging.LogFactory ;
41  
42  import org.astrogrid.store.Ivorn ;
43  import org.astrogrid.filestore.common.exception.FileStoreIdentifierException ;
44  
45  import java.net.URISyntaxException ;
46  
47  /***
48   * A factory for generating filestore related Ivorn identifiers.
49   *
50   */
51  public class FileStoreIvornFactory
52      {
53      /***
54       * Our debug logger.
55       *
56       */
57      private static Log log = LogFactory.getLog(FileStoreIvornFactory.class);
58  
59      /***
60       * Create a filestore ivorn.
61       * @param  service The filestore service identifier.
62       * @param  resource  The resource identifier.
63       * @return A new ivorn.
64       * @throws FileStoreIdentifierException if the filestore or resource identifiers are invalid or null.
65       *
66       */
67      public static Ivorn createIvorn(String service, String resource)
68          throws FileStoreIdentifierException
69  		{
70  		try {
71  			return new Ivorn(
72  				createIdent(
73  					service,
74  					resource
75  					)
76  				) ;
77  			}
78  		catch (URISyntaxException ouch)
79  			{
80  			throw new FileStoreIdentifierException(
81  				ouch
82  				) ;
83  			}
84  		}
85  
86      /***
87       * Create a mock filestore ivorn.
88       * @param  resource  The resource identifier.
89       * @return A new mock ivorn.
90       * @throws FileStoreIdentifierException if the filestore or resource identifiers are null.
91       *
92       */
93      public static Ivorn createMock(String resource)
94          throws FileStoreIdentifierException
95  		{
96  		try {
97  			return new Ivorn(
98  				createIdent(
99  					FileStoreIvornParser.MOCK_SERVICE_IDENT,
100 					resource
101 					)
102 				) ;
103 			}
104 		catch (URISyntaxException ouch)
105 			{
106 			throw new FileStoreIdentifierException(
107 				ouch
108 				) ;
109 			}
110 		}
111 
112     /***
113      * Create a filestore ident.
114      * @param  service The filestore service identifier.
115      * @param  resource  The resource identifier.
116      * @return A new identifer.
117      * @throws FileStoreIdentifierException if the filestore or resource identifiers are null.
118      *
119      */
120     public static String createIdent(String service, String resource)
121         throws FileStoreIdentifierException
122         {
123         log.debug("") ;
124         log.debug("----\"----") ;
125         log.debug("FilestoreIvornFactory.createIdent()") ;
126         log.debug("  Service  : " + service) ;
127         log.debug("  Resource : " + resource) ;
128         //
129         // Check for null params.
130         if (null == service)
131         	{
132         	throw new FileStoreIdentifierException(
133         		"Null service identifier"
134         		) ;
135         	}
136         if (null == resource)
137         	{
138         	throw new FileStoreIdentifierException(
139         		"Null resource identifier"
140         		) ;
141         	}
142         //
143         // Put it all together.
144         StringBuffer buffer = new StringBuffer() ;
145         //
146         // If the service identifier isn't an Ivorn yet.
147         if (false == service.startsWith(Ivorn.SCHEME))
148             {
149             buffer.append(Ivorn.SCHEME) ;
150             buffer.append("://") ;
151             }
152         buffer.append(service) ;
153         buffer.append("#") ;
154         buffer.append(resource) ;
155         log.debug("  Result   : " + buffer.toString()) ;
156         //
157         // Return the new string.
158         return buffer.toString() ;
159         }
160     }