1 package org.apache.turbine.services; 2 3 4 /* 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file 9 * to you under the Apache License, Version 2.0 (the 10 * "License"); you may not use this file except in compliance 11 * with the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, 16 * software distributed under the License is distributed on an 17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 * KIND, either express or implied. See the License for the 19 * specific language governing permissions and limitations 20 * under the License. 21 */ 22 23 24 /** 25 * This class provides a generic implementation of 26 * <code>Initable</code>. This implementation, that other 27 * <code>Initables</code> are welcome to extend, contains facilities 28 * to maintain internal state. 29 * 30 * @author <a href="mailto:burton@apache.org">Kevin Burton</a> 31 * @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a> 32 * @version $Id: BaseInitable.java 1078552 2011-03-06 19:58:46Z tv $ 33 */ 34 public class BaseInitable 35 implements Initable 36 { 37 /** InitableBroker that instantiatd this class. */ 38 protected InitableBroker initableBroker; 39 40 /** Initialization status of this class. */ 41 protected boolean isInitialized = false; 42 43 /** 44 * Default constructor of BaseInitable. 45 * 46 * This constructor does nothing. Your own constructurs should be 47 * modest in allocating memory and other resources, leaving this 48 * to the <code>init()</code> method. 49 */ 50 public BaseInitable() 51 { 52 // empty 53 } 54 55 /** 56 * Saves InitableBroker reference for later use. 57 * 58 * @param broker The InitableBroker that instantiated this object. 59 */ 60 public void setInitableBroker(InitableBroker broker) 61 { 62 this.initableBroker = broker; 63 } 64 65 /** 66 * Returns an InitableBroker reference. 67 * 68 * @return The InitableBroker that instantiated this object. 69 */ 70 public InitableBroker getInitableBroker() 71 { 72 return initableBroker; 73 } 74 75 /** 76 * Performs early initialization. Used in a manner similar to a ctor. 77 * 78 * BaseInitable doesn't need early initialization, therefore it 79 * ignores all objects passed to it and performs no initialization 80 * activities. 81 * 82 * @param data An Object to use for initialization activities. 83 * @exception InitializationException Initialization of this 84 * class was not successful. 85 */ 86 public void init(Object data) throws InitializationException 87 { 88 // empty 89 } 90 91 /** 92 * Performs late initializtion. Called when the Service is requested 93 * for the first time (if not already completely initialized by the 94 * early initializer). 95 * 96 * Late intialization of a BaseInitable is alwas successful. 97 * 98 * @exception InitializationException Initialization of this 99 * class was not successful. 100 */ 101 public void init() throws InitializationException 102 { 103 // empty 104 } 105 106 /** 107 * Returns an Initable to uninitialized state. 108 * 109 * Calls setInit(false) to mark that we are no longer in initialized 110 * state. 111 */ 112 public void shutdown() 113 { 114 setInit(false); 115 } 116 117 /** 118 * Returns initialization status. 119 * 120 * @return True if the initable is initialized. 121 */ 122 public boolean getInit() 123 { 124 return isInitialized; 125 } 126 127 /** 128 * Sets initailization status. 129 * 130 * @param value The new initialization status. 131 */ 132 protected void setInit(boolean value) 133 { 134 this.isInitialized = value; 135 } 136 }