KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > maven > plugin > jbi > IsDeployedTask


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.maven.plugin.jbi;
18
19 import org.apache.servicemix.jbi.framework.AdminCommandsServiceMBean;
20 import org.apache.servicemix.jbi.management.task.JbiTask;
21
22 public class IsDeployedTask extends JbiTask {
23
24     private static final String JavaDoc JBI_SHARED_LIBRARY = "jbi-shared-library";
25
26     private static final String JavaDoc JBI_COMPONENT = "jbi-component";
27
28     private static final String JavaDoc JBI_SERVICE_ASSEMBLY = "jbi-service-assembly";
29
30     private boolean deployed = false;
31
32     private String JavaDoc type;
33
34     private String JavaDoc name;
35
36     public boolean isDeployed() {
37         return deployed;
38     }
39
40     public void setDeployed(boolean deployed) {
41         this.deployed = deployed;
42     }
43
44     protected void doExecute(AdminCommandsServiceMBean acs) throws Exception JavaDoc {
45         if (JBI_SHARED_LIBRARY.equals(type)) {
46             String JavaDoc result = acs.listSharedLibraries(null, name);
47             setDeployed(isResultContaining(result, "shared-library", name));
48         } else if (JBI_SERVICE_ASSEMBLY.equals(type)) {
49             String JavaDoc result = acs.listServiceAssemblies(null, null, name);
50             setDeployed(result.contains("<service-assembly-info name='" + name
51                     + "'"));
52         }
53         if (JBI_COMPONENT.equals(type)) {
54             String JavaDoc result = acs.listComponents(false, false, false, null, null,
55                     null);
56             if (isResultContaining(result, "service-engine", name)
57                     || isResultContaining(result, "binding-component", name)) {
58                 setDeployed(true);
59             }
60         }
61     }
62
63     private boolean isResultContaining(String JavaDoc result, String JavaDoc type, String JavaDoc name) {
64         String JavaDoc componentLine = "<component-info type='" + type + "' name='"
65                 + name + "'";
66         return result.contains(componentLine);
67     }
68
69     public void setType(String JavaDoc type) {
70         this.type = type;
71     }
72
73     public void setName(String JavaDoc name) {
74         this.name = name;
75     }
76
77 }
78
Popular Tags