KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > mdr > test > MDRTestLookup


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.mdr.test;
20
21 import org.openide.util.*;
22 import org.netbeans.mdr.NBMDRManagerImpl;
23 import org.netbeans.lib.jmi.xmi.*;
24 import org.netbeans.lib.jmi.mapping.JMIMapperImpl;
25
26 import java.util.*;
27
28 /**
29  *
30  * @author mmatula
31  * @version
32  */

33 public class MDRTestLookup extends Lookup {
34
35     private ArrayList instances = null;
36
37     /** Creates new RepositoryLookup */
38     public MDRTestLookup() {
39     }
40
41     public Object JavaDoc lookup(Class JavaDoc cls) {
42         if (instances == null) {
43             instances = new ArrayList();
44             instances.add(new NBMDRManagerImpl());
45             instances.add(new XMISaxReaderImpl());
46             instances.add(new JMIMapperImpl());
47             instances.add(new XMIWriterImpl());
48         }
49         for (Iterator it = instances.iterator(); it.hasNext();) {
50             Object JavaDoc instance = it.next();
51             if (cls.isAssignableFrom(instance.getClass())) {
52                 return instance;
53             }
54         }
55         return null;
56     }
57     
58     public Lookup.Result lookup(Lookup.Template template) {
59         return new Result(lookup(template.getType()));
60     }
61     
62     private static class Result extends Lookup.Result {
63         private final ArrayList result = new ArrayList();
64         
65         public Result(Object JavaDoc o) {
66             if (o != null) result.add(o);
67         }
68         
69         /** Registers a listener that is invoked when there is a possible
70          * change in this result.
71          *
72          * @param l the listener to add
73          */

74         public void addLookupListener(LookupListener l) {
75             // this lookup never changes so nothing need to be registered
76
}
77         
78         /** Get all instances in the result.
79          * @return collection of all instances
80          */

81         public java.util.Collection JavaDoc allInstances() {
82             return result;
83         }
84         
85         /** Unregisters a listener previously added.
86          * @param l the listener to remove
87          */

88         public void removeLookupListener(LookupListener l) {
89             // nothing was registered
90
}
91     }
92 }
93
Popular Tags