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 import java.util.Properties; 25 26 import org.apache.commons.configuration2.Configuration; 27 import org.apache.commons.configuration2.ConfigurationConverter; 28 29 /** 30 * This class is a generic implementation of <code>Service</code>. 31 * 32 * @author <a href="mailto:burton@apache.org">Kevin Burton</a> 33 * @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a> 34 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 35 * @version $Id$ 36 */ 37 public class BaseService 38 extends BaseInitable 39 implements Service 40 { 41 /** A reference to the ServiceBroker that instantiated this object. */ 42 protected ServiceBroker serviceBroker; 43 44 /** The configuration for this service */ 45 protected Configuration configuration; 46 47 /** The name of this Service. */ 48 protected String name; 49 50 /** 51 * Saves a reference to the ServiceBroker that instantiated this 52 * object, so that it can ask for its properties and access other 53 * Services. 54 * 55 * @param broker The ServiceBroker that instantiated this object. 56 */ 57 @Override 58 public void setServiceBroker(ServiceBroker broker) 59 { 60 this.serviceBroker = broker; 61 } 62 63 /** 64 * ServiceBroker uses this method to pass a Service its name. 65 * 66 * @param name The name of this Service. 67 */ 68 @Override 69 public void setName(String name) 70 { 71 this.name = name; 72 } 73 74 /** 75 * Returns the name of this service. 76 * 77 * @return The name of this Service. 78 */ 79 @Override 80 public String getName() 81 { 82 return name; 83 } 84 85 /** 86 * Returns a ServiceBroker reference. 87 * 88 * @return The ServiceBroker that instantiated this object. 89 */ 90 public ServiceBroker getServiceBroker() 91 { 92 return serviceBroker; 93 } 94 95 /** 96 * Returns the properties of this Service. 97 * 98 * @return The Properties of this Service. 99 */ 100 @Override 101 public Properties getProperties() 102 { 103 return ConfigurationConverter.getProperties(getConfiguration()); 104 } 105 106 /** 107 * Returns the configuration of this Service. 108 * 109 * @return The Configuration of this Service. 110 */ 111 @Override 112 public Configuration getConfiguration() 113 { 114 if (name == null) 115 { 116 return null; 117 } 118 119 if (configuration == null) 120 { 121 configuration = getServiceBroker().getConfiguration(name); 122 } 123 return configuration; 124 } 125 }