KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > plugin > packaging > MavenRepository


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

17 package org.apache.geronimo.plugin.packaging;
18
19 import java.io.File JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.net.MalformedURLException JavaDoc;
22 import java.net.URI JavaDoc;
23 import java.net.URL JavaDoc;
24
25 import org.apache.geronimo.gbean.GBeanInfo;
26 import org.apache.geronimo.gbean.GBeanInfoBuilder;
27 import org.apache.geronimo.kernel.repository.Repository;
28
29 /**
30  * Implementation of Repository that maps to the local Maven repository.
31  *
32  * @version $Rev: 158417 $ $Date: 2005-03-20 23:25:45 -0800 (Sun, 20 Mar 2005) $
33  */

34 public class MavenRepository implements Repository {
35     private final URI JavaDoc root;
36
37     public MavenRepository(File JavaDoc root) {
38         this.root = root.toURI();
39     }
40
41     public boolean hasURI(URI JavaDoc uri) {
42         uri = root.resolve(uri);
43         if ("file".equals(uri.getScheme())) {
44             return new File JavaDoc(uri).canRead();
45         } else {
46             try {
47                 uri.toURL().openStream().close();
48                 return true;
49             } catch (IOException JavaDoc e) {
50                 return false;
51             }
52         }
53     }
54
55     public URL JavaDoc getURL(URI JavaDoc uri) throws MalformedURLException JavaDoc {
56         uri = root.resolve(uri);
57         return uri.toURL();
58     }
59
60     public static final GBeanInfo GBEAN_INFO;
61
62     public static GBeanInfo getGBeanInfo() {
63         return GBEAN_INFO;
64     }
65
66     static {
67         GBeanInfoBuilder builder = new GBeanInfoBuilder(MavenRepository.class);
68         builder.addInterface(Repository.class);
69         builder.addAttribute("root", File JavaDoc.class, true);
70         builder.setConstructor(new String JavaDoc[]{"root"});
71         GBEAN_INFO = builder.getBeanInfo();
72     }
73 }
74
Popular Tags