KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > loom > components > assembler > data > Component3


1 /*
2  * Copyright (C) The Loom Group. All rights reserved.
3  *
4  * This software is published under the terms of the Loom
5  * Software License version 1.1, a copy of which has been included
6  * with this distribution in the LICENSE.txt file.
7  */

8 package org.codehaus.loom.components.assembler.data;
9
10 import java.util.Arrays JavaDoc;
11 import org.apache.avalon.framework.service.ServiceException;
12 import org.apache.avalon.framework.service.ServiceManager;
13 import org.apache.avalon.framework.service.Serviceable;
14
15 /**
16  * A test component.
17  *
18  * @author Peter Donald
19  * @version $Revision: 1.2 $ $Date: 2004/05/01 12:48:35 $
20  * @dna.component
21  */

22 public class Component3
23     implements Serviceable
24 {
25     /**
26      * @dna.dependency type="Service1[]"
27      */

28     public void service( final ServiceManager manager )
29         throws ServiceException
30     {
31         final Service1[] services =
32             (Service1[])manager.lookup( Service1[].class.getName() );
33         System.out.println( "Passed the following services: " +
34                             Arrays.asList( services ) );
35         if( 3 != services.length )
36         {
37             final String JavaDoc message =
38                 "Expected to get 3 services but got " + services.length;
39             throw new ServiceException( Service1[].class.getName(), message );
40         }
41
42         checkEntry( services, 0 );
43         checkEntry( services, 1 );
44         checkEntry( services, 2 );
45     }
46
47     private void checkEntry( final Service1[] services, final int index )
48         throws ServiceException
49     {
50         if( null == services[ index ] )
51         {
52             final String JavaDoc message = "Expected non null service entry for " +
53                 index;
54             throw new ServiceException( Service1[].class.getName(), message );
55         }
56     }
57 }
58
Popular Tags