KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > project > UnitTestForSourceQueryImpl


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
20 package org.netbeans.modules.java.project;
21
22 import java.net.MalformedURLException JavaDoc;
23 import java.net.URI JavaDoc;
24 import java.net.URISyntaxException JavaDoc;
25 import java.net.URL JavaDoc;
26 import org.netbeans.api.project.FileOwnerQuery;
27 import org.netbeans.api.project.Project;
28 import org.netbeans.spi.java.queries.UnitTestForSourceQueryImplementation;
29 import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation;
30 import org.openide.ErrorManager;
31 import org.openide.filesystems.FileObject;
32
33 /**
34  * Delegates {@link UnitTestForSourceQueryImplementation} to the project which
35  * owns the binary file.
36  */

37 @SuppressWarnings JavaDoc("deprecation")
38 public class UnitTestForSourceQueryImpl implements UnitTestForSourceQueryImplementation, MultipleRootsUnitTestForSourceQueryImplementation {
39     
40     /** Default constructor for lookup. */
41     public UnitTestForSourceQueryImpl() {
42     }
43     
44     public URL JavaDoc findUnitTest(FileObject source) {
45         Project project = FileOwnerQuery.getOwner(source);
46         if (project != null) {
47             UnitTestForSourceQueryImplementation query = project.getLookup().lookup(UnitTestForSourceQueryImplementation.class);
48             if (query != null) {
49                 return query.findUnitTest(source);
50             }
51         }
52         return null;
53     }
54
55     public URL JavaDoc[] findUnitTests(FileObject source) {
56         Project project = FileOwnerQuery.getOwner(source);
57         if (project != null) {
58             MultipleRootsUnitTestForSourceQueryImplementation query = project.getLookup().lookup(MultipleRootsUnitTestForSourceQueryImplementation.class);
59             if (query != null) {
60                 return query.findUnitTests(source);
61             }
62         }
63         return null;
64     }
65
66     public URL JavaDoc findSource(FileObject unitTest) {
67         Project project = FileOwnerQuery.getOwner(unitTest);
68         if (project != null) {
69             UnitTestForSourceQueryImplementation query = project.getLookup().lookup(UnitTestForSourceQueryImplementation.class);
70             if (query != null) {
71                 return query.findSource(unitTest);
72             }
73         }
74         return null;
75     }
76
77     public URL JavaDoc[] findSources(FileObject unitTest) {
78         Project project = FileOwnerQuery.getOwner(unitTest);
79         if (project != null) {
80             MultipleRootsUnitTestForSourceQueryImplementation query = project.getLookup().lookup(MultipleRootsUnitTestForSourceQueryImplementation.class);
81             if (query != null) {
82                 return query.findSources(unitTest);
83             }
84         }
85         return null;
86     }
87
88 }
89
Popular Tags