KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > tutorial > application > Application


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

17
18 package tutorial.application;
19
20 import java.io.File JavaDoc;
21
22 import org.apache.avalon.framework.logger.AbstractLogEnabled;
23 import org.apache.avalon.framework.service.Serviceable;
24 import org.apache.avalon.framework.service.ServiceManager;
25 import org.apache.avalon.framework.service.ServiceException;
26 import org.apache.avalon.framework.activity.Disposable;
27
28 import tutorial.location.LocationService;
29 import tutorial.publisher.PublisherService;
30
31 /**
32  * PublisherComponent from Merlin's Composition Tutorial
33  *
34  * @avalon.component version="1.0" name="test"
35  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
36  */

37 public class Application extends AbstractLogEnabled implements Serviceable, Disposable
38 {
39
40    /**
41     * Servicing of the component by the container during
42     * which service dependencies declared under the component
43     * can be resolved using the supplied service manager. In this
44     * example the component uses a LocatorService service to log a
45     * message exposing a location.
46     *
47     * @param manager the service manager
48     * @avalon.dependency key="locator" type="tutorial.location.LocationService"
49     * @avalon.dependency key="publisher" type="tutorial.publisher.PublisherService"
50     */

51     public void service( ServiceManager manager ) throws ServiceException
52     {
53         getLogger().info( "servicing application" );
54
55         LocationService locator = (LocationService) manager.lookup( "locator" );
56         PublisherService publisher = (PublisherService) manager.lookup( "publisher" );
57
58         //
59
// get the location from the locator and publish
60
// it using the publisher
61
//
62

63         publisher.publish(
64             "\n******************"
65           + "\n* " + locator.getLocation()
66           + "\n******************");
67
68         getLogger().info( "done" );
69     }
70
71     public void dispose()
72     {
73         getLogger().info( "disposal" );
74     }
75 }
76
77
Popular Tags