KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > bpe > BPESpringComponent


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.bpe;
18
19 import java.io.File JavaDoc;
20
21 import org.apache.servicemix.common.BaseLifeCycle;
22 import org.apache.servicemix.common.ServiceUnit;
23 import org.springframework.core.io.Resource;
24
25 /**
26  *
27  * @author gnodet
28  * @version $Revision: 376451 $
29  * @org.apache.xbean.XBean element="component"
30  * description="A BPE component"
31  */

32 public class BPESpringComponent extends BPEComponent {
33
34     private String JavaDoc name;
35     private Resource bpelResource;
36     
37     /* (non-Javadoc)
38      * @see org.servicemix.common.BaseComponent#createLifeCycle()
39      */

40     protected BaseLifeCycle createLifeCycle() {
41         return new LifeCycle();
42     }
43
44     public class LifeCycle extends BPELifeCycle {
45
46         protected ServiceUnit su;
47         
48         public LifeCycle() {
49             super(BPESpringComponent.this);
50         }
51         
52         /* (non-Javadoc)
53          * @see org.servicemix.common.BaseLifeCycle#doInit()
54          */

55         protected void doInit() throws Exception JavaDoc {
56             super.doInit();
57             if (bpelResource == null) {
58                 throw new IllegalArgumentException JavaDoc("bpelResource must be configured");
59             }
60             File JavaDoc bpelFile = bpelResource.getFile();
61             String JavaDoc fileName = bpelFile.getName();
62             if (!fileName.endsWith(".bpel")) {
63                 throw new IllegalArgumentException JavaDoc("bpelResource must resolve to a .bpel file");
64             }
65             if (name == null) {
66                 name = fileName.substring(0, fileName.length() - 5);
67             }
68             su = new BPEDeployer(BPESpringComponent.this).deploy(name, bpelFile.getParent());
69             getRegistry().registerServiceUnit(su);
70         }
71
72         /* (non-Javadoc)
73          * @see org.servicemix.common.BaseLifeCycle#doStart()
74          */

75         protected void doStart() throws Exception JavaDoc {
76             super.doStart();
77             su.start();
78         }
79         
80         /* (non-Javadoc)
81          * @see org.servicemix.common.BaseLifeCycle#doStop()
82          */

83         protected void doStop() throws Exception JavaDoc {
84             su.stop();
85             super.doStop();
86         }
87         
88         /* (non-Javadoc)
89          * @see org.servicemix.common.BaseLifeCycle#doShutDown()
90          */

91         protected void doShutDown() throws Exception JavaDoc {
92             su.shutDown();
93             super.doShutDown();
94         }
95     }
96
97     /**
98      * @return Returns the bpelResource.
99      */

100     public Resource getBpelResource() {
101         return bpelResource;
102     }
103
104     /**
105      * @param bpelResource The bpelResource to set.
106      */

107     public void setBpelResource(Resource bpelResource) {
108         this.bpelResource = bpelResource;
109     }
110
111     /**
112      * @return Returns the name.
113      */

114     public String JavaDoc getName() {
115         return name;
116     }
117
118     /**
119      * @param name The name to set.
120      */

121     public void setName(String JavaDoc name) {
122         this.name = name;
123     }
124
125 }
126
Popular Tags