KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > fortress > impl > handler > AbstractReleasableComponent


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
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package org.apache.avalon.fortress.impl.handler;
21
22 import org.apache.avalon.framework.service.ServiceException;
23
24 /**
25  * Base Implementation for a releasable component.
26  *
27  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
28  * @version CVS $Revision: 1.2 $ $Date: 2004/03/13 17:57:59 $
29  * @since 1.2
30  */

31 public class AbstractReleasableComponent implements ReleasableComponent
32 {
33     private boolean initialized = false;
34     
35     private ComponentHandler handler;
36     
37     public void initialize(ComponentHandler handler)
38     throws Exception JavaDoc
39     {
40         if ( this.initialized )
41         {
42             throw new ServiceException(this.toString(), "Handable component is already initialized.");
43         }
44         if ( handler == null )
45         {
46             throw new ServiceException(this.toString(), "Handler is required.");
47         }
48         this.handler = handler;
49         this.initialized = true;
50     }
51     
52     /* (non-Javadoc)
53      * @see org.apache.avalon.fortress.impl.handler.HandableComponent#put(java.lang.Object)
54      */

55     public void releaseOnComponentHandler( )
56     {
57         if ( this.initialized )
58         {
59             this.handler.put( this );
60         }
61     }
62 }
63
Popular Tags