View Javadoc
1   /*
2    * Copyright 2001-2008 The Apache Software Foundation.
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   */
17  package org.apache.juddi.api.util;
18  
19  import java.util.ArrayList;
20  import java.util.Hashtable;
21  import java.util.List;
22  
23  /**
24   * Enum to represent the methods within the Security API.
25   * 
26   * @author <a href="mailto:tcunning@apache.org">Tom Cunningham</a>
27   */
28  public enum SecurityQuery implements UDDIQuery {
29      GET_AUTHTOKEN("get_authToken"),
30      DISCARD_AUTHTOKEN("discard_authToken");
31      
32      private String _query;
33      private static Hashtable<String, SecurityQuery> _securityQueries = null;
34      
35      SecurityQuery(final String query) {
36          _query = query;
37      }
38      
39      public String getQuery() {
40          return _query;
41      }
42      
43      public synchronized static void initSecurityQueries () {
44              if (_securityQueries == null) {
45                  _securityQueries = new Hashtable();
46  
47                  _securityQueries.put(SecurityQuery.GET_AUTHTOKEN.getQuery(), SecurityQuery.GET_AUTHTOKEN);
48                  _securityQueries.put(SecurityQuery.DISCARD_AUTHTOKEN.getQuery(), SecurityQuery.DISCARD_AUTHTOKEN);
49              }
50      }
51  
52      public static List<String> getQueries() {
53          if (_securityQueries == null) {
54              initSecurityQueries();
55          }
56          
57          List list = new ArrayList<String>(_securityQueries.keySet());
58          return list;
59      }
60      
61      /**
62       * this doesn't appear to be used anywhere and will be removed in a future version
63       * @param query
64       * @return
65       * @deprecated
66       */
67      public static SecurityQuery fromQuery(final String query) {
68          if (_securityQueries == null) {
69              initSecurityQueries();
70          }
71          
72          if (_securityQueries.contains(query)) {
73              return _securityQueries.get(query);
74          } else {
75              throw new IllegalArgumentException("Unrecognized query " + query);
76          }       
77      }
78  }