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 queries within the Replication API.
25   * 
26   * @author <a href="mailto:tcunning@apache.org">Tom Cunningham</a>
27   */
28  public enum ReplicationQuery implements UDDIQuery {
29      GET_CHANGERECORDS("get_changeRecords"),
30      NOTIFY_CHANGERECORDSAVAILABLE("notify_changeRecordsAvailable"),
31      DO_PING("do_ping"),
32      GET_HIGHWATERMARKS("get_highWaterMarks"),
33      TRANSFER_CUSTODY("transfer_custody");
34      
35      private String _query;
36      private static Hashtable<String, ReplicationQuery> _replicationQueries = null;
37      
38      ReplicationQuery(final String query) {
39          _query = query;
40      }
41      
42      public String getQuery() {
43          return _query;
44      }
45      
46      public synchronized static void initReplicationQueries () {
47              if (_replicationQueries == null) {
48                  _replicationQueries = new Hashtable();
49  
50                  _replicationQueries.put(ReplicationQuery.GET_CHANGERECORDS.getQuery(), ReplicationQuery.GET_CHANGERECORDS);
51                  _replicationQueries.put(ReplicationQuery.NOTIFY_CHANGERECORDSAVAILABLE.getQuery(), ReplicationQuery.NOTIFY_CHANGERECORDSAVAILABLE);
52                  _replicationQueries.put(ReplicationQuery.DO_PING.getQuery(), ReplicationQuery.DO_PING);
53                  _replicationQueries.put(ReplicationQuery.GET_HIGHWATERMARKS.getQuery(), ReplicationQuery.GET_HIGHWATERMARKS);
54                  _replicationQueries.put(ReplicationQuery.TRANSFER_CUSTODY.getQuery(), ReplicationQuery.TRANSFER_CUSTODY);
55              }
56      }
57  
58      public static List<String> getQueries() {
59          if (_replicationQueries == null) {
60              initReplicationQueries();
61          }
62          
63          List list = new ArrayList<String>(_replicationQueries.keySet());
64          return list;
65      }
66      
67      /**
68       * this doesn't appear to be used anywhere and will be removed in a future version
69       * @param query
70       * @return
71       * @deprecated
72       */
73      public static ReplicationQuery fromQuery(final String query) {
74          if (_replicationQueries == null) {
75              initReplicationQueries();
76          }
77          
78          if (_replicationQueries.contains(query)) {
79              return _replicationQueries.get(query);
80          } else {
81              throw new IllegalArgumentException("Unrecognized query " + query);
82          }        
83  
84      }
85  }