This project has retired. For details please refer to its Attic page.
UddiSubscriptionManagement xref
View Javadoc
1   /*
2    * Copyright 2014 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  package org.apache.juddi.v3.client.cli;
17  
18  import java.util.List;
19  import org.apache.juddi.jaxb.PrintUDDI;
20  import org.apache.juddi.v3.client.config.UDDIClerk;
21  import org.apache.juddi.v3.client.config.UDDIClient;
22  import org.apache.juddi.v3.client.transport.Transport;
23  import org.uddi.sub_v3.DeleteSubscription;
24  import org.uddi.sub_v3.Subscription;
25  import org.uddi.v3_service.UDDISubscriptionPortType;
26  
27  /**
28   *
29   * @author Alex O'Ree
30   */
31  public class UddiSubscriptionManagement {
32  
33          private UDDISubscriptionPortType uddiSubscriptionService = null;
34  
35          private UDDIClerk clerk = null;
36          private UDDIClient client = null;
37  
38          public UddiSubscriptionManagement() {
39                  try {
40                          // create a manager and read the config in the archive; 
41                          // you can use your config file name
42                          client = new UDDIClient("META-INF/simple-publish-uddi.xml");
43                          clerk = client.getClerk("default");
44                          Transport transport = client.getTransport();
45                          // Now you create a reference to the UDDI API
46                        
47                          uddiSubscriptionService = transport.getUDDISubscriptionService();
48                  } catch (Exception e) {
49                          e.printStackTrace();
50                  }
51          }
52          
53           public UddiSubscriptionManagement(Transport transport) {
54                  try {
55                         
56                          // Now you create a reference to the UDDI API
57                        
58                          uddiSubscriptionService = transport.getUDDISubscriptionService();
59                  } catch (Exception e) {
60                          e.printStackTrace();
61                  }
62          }
63  
64          public static void main(String args[]) throws Exception {
65                  UddiSubscriptionManagement sp = new UddiSubscriptionManagement();
66                  sp.printSubscriptions(null);
67          }
68  
69          public void printSubscriptions(String authtoken) throws Exception {
70  
71                  if (authtoken == null) {
72                          authtoken = clerk.getAuthToken();
73                  }
74                  List<Subscription> subscriptions = uddiSubscriptionService.getSubscriptions(authtoken);
75                  System.out.println(subscriptions.size() + " subscriptions found");
76                  for (int i = 0; i < subscriptions.size(); i++) {
77                          System.out.println("_____________________________________");
78                          
79                          System.out.println(p.print(subscriptions.get(i)));
80                  }
81          }
82  
83          public void deleteSubscription(String authtoken, String key) throws Exception {
84  
85                  if (authtoken == null) {
86                          authtoken = clerk.getAuthToken();
87                  }
88                  if (key == null) {
89                          System.out.println("No key specified!");
90                          return;
91                  }
92                  DeleteSubscription ds = new DeleteSubscription();
93                  ds.setAuthInfo(authtoken);
94                  ds.getSubscriptionKey().add(key);
95                  uddiSubscriptionService.deleteSubscription(ds);
96                  System.out.println("Deleted!");
97  
98          }
99  
100         public void deleteAllSubscriptions(String authtoken) throws Exception {
101 
102                 if (authtoken == null) {
103                         authtoken = clerk.getAuthToken();
104                 }
105                 List<Subscription> subscriptions = uddiSubscriptionService.getSubscriptions(authtoken);
106                 System.out.println(subscriptions.size() + " subscriptions found");
107                 for (int i = 0; i < subscriptions.size(); i++) {
108                         System.out.println("_____________________________________");
109                         System.out.println(subscriptions.get(i).getSubscriptionKey());
110                         DeleteSubscription ds = new DeleteSubscription();
111                         ds.setAuthInfo(authtoken);
112                         ds.getSubscriptionKey().add(subscriptions.get(i).getSubscriptionKey());
113                         uddiSubscriptionService.deleteSubscription(ds);
114                         System.out.println("Deleted!");
115                 }
116 
117         }
118 
119         PrintUDDI<Subscription> p = new PrintUDDI<Subscription>();
120 
121 }