1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
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
144 StringBuffer buffer = new StringBuffer() ;
145
146
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
158 return buffer.toString() ;
159 }
160 }