View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/common/src/java/org/astrogrid/community/common/ivorn/CommunityIvornFactory.java,v $</cvs:source>
3    * <cvs:author>$Author: dave $</cvs:author>
4    * <cvs:date>$Date: 2004/09/16 23:18:08 $</cvs:date>
5    * <cvs:version>$Revision: 1.8 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: CommunityIvornFactory.java,v $
9    *   Revision 1.8  2004/09/16 23:18:08  dave
10   *   Replaced debug logging in Community.
11   *   Added stream close() to FileStore.
12   *
13   *   Revision 1.7.82.1  2004/09/16 09:58:48  dave
14   *   Replaced debug with commons logging ....
15   *
16   *   Revision 1.7  2004/06/18 13:45:20  dave
17   *   Merged development branch, dave-dev-200406081614, into HEAD
18   *
19   *   Revision 1.6.32.2  2004/06/17 14:50:01  dave
20   *   Removed unused imports (PMD report).
21   *
22   *   Revision 1.6.32.1  2004/06/17 13:38:58  dave
23   *   Tidied up old CVS log entries
24   *
25   * </cvs:log>
26   *
27   */
28  package org.astrogrid.community.common.ivorn ;
29  
30  import org.apache.commons.logging.Log ;
31  import org.apache.commons.logging.LogFactory ;
32  
33  import org.astrogrid.store.Ivorn ;
34  import org.astrogrid.community.common.exception.CommunityIdentifierException ;
35  
36  /***
37   * A factory for generating Community related Ivorn identifiers.
38   * @todo Need better integration with the MockIvorn factory.
39   *
40   */
41  public class CommunityIvornFactory
42      {
43      /***
44       * Our debug logger.
45       *
46       */
47  	private static Log log = LogFactory.getLog(CommunityIvornFactory.class);
48  
49      /***
50       * Create a new ident.
51       * @param  community The Community ident, with no extra fields.
52       * @param  resource  The resource name.
53       * @return A new identifer.
54       * @throws CommunityIdentifierException if the community or resource identifiers are null.
55       *
56       */
57      protected static String createIdent(String community, String resource)
58          throws CommunityIdentifierException
59          {
60          return createIdent(
61          	community,
62          	resource,
63          	null,
64          	null,
65          	null
66          	) ;
67          }
68  
69      /***
70       * Create a Community ident.
71       * @param  community The Community ident, with no extra fields.
72       * @param  resource  The resource name.
73       * @param  path      The URI path, added after the resource.
74       * @return A new identifer.
75       * @throws CommunityIdentifierException if the community or resource identifiers are null.
76       *
77       */
78      protected static String createIdent(String community, String resource, String path)
79          throws CommunityIdentifierException
80          {
81          return createIdent(
82          	community,
83          	resource,
84          	path,
85          	null,
86          	null
87          	) ;
88          }
89  
90      /***
91       * Create a Community ident.
92       * @param  community The Community ident, with no extra fields.
93       * @param  resource  The resource name.
94       * @param  path      The URI path, added after the resource.
95       * @param  fragment  The URI fragment, added after the path.
96       * @return A new identifer.
97       * @throws CommunityIdentifierException if the community or resource identifiers are null.
98       *
99       */
100     protected static String createIdent(String community, String resource, String path, String fragment)
101         throws CommunityIdentifierException
102         {
103         return createIdent(
104         	community,
105         	resource,
106         	path,
107         	null,
108         	fragment
109         	) ;
110         }
111 
112     /***
113      * Create a Community ident.
114      * @param  community The Community ident, with no extra fields.
115      * @param  resource  The resource name.
116      * @param  path      The URI path, added after the resource.
117      * @param  query     The URI query string, added after the path.
118      * @param  fragment  The URI fragment, added after the query.
119      * @return A new identifer.
120      * @throws CommunityIdentifierException if the community or resource identifiers are null.
121      *
122      */
123     protected static String createIdent(String community, String resource, String path, String query, String fragment)
124         throws CommunityIdentifierException
125         {
126         log.debug("") ;
127         log.debug("----\"----") ;
128         log.debug("CommunityIvornFactory.createIdent()") ;
129         log.debug("  Community : " + community) ;
130         log.debug("  Resource  : " + resource) ;
131         log.debug("  Path      : " + path) ;
132         log.debug("  Query     : " + query) ;
133         log.debug("  Fragment  : " + fragment) ;
134         //
135         // Check for null params.
136         if (null == community)
137         	{
138         	throw new CommunityIdentifierException(
139         		"Null Community identifier"
140         		) ;
141         	}
142         if (null == resource)
143         	{
144         	throw new CommunityIdentifierException(
145         		"Null Resource identifier"
146         		) ;
147         	}
148         //
149         // Put it all together.
150         StringBuffer buffer = new StringBuffer() ;
151         //
152         // If the community identifier isn't an Ivorn yet.
153         if (false == community.startsWith(Ivorn.SCHEME))
154             {
155             buffer.append(Ivorn.SCHEME) ;
156             buffer.append("://") ;
157             }
158         buffer.append(community) ;
159         buffer.append("/") ;
160         buffer.append(resource) ;
161         if (null != path)
162             {
163             buffer.append("/") ;
164             buffer.append(path) ;
165             }
166         if (null != query)
167             {
168             buffer.append("?") ;
169             buffer.append(query) ;
170             }
171         if (null != fragment)
172             {
173             buffer.append("#") ;
174             buffer.append(fragment) ;
175             }
176         log.debug("  Result    : " + buffer.toString()) ;
177         //
178         // Return the new string.
179         return buffer.toString() ;
180         }
181     }