1 17 package org.apache.geronimo.plugin.packaging; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.net.MalformedURLException ; 22 import java.net.URI ; 23 import java.net.URL ; 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 34 public class MavenRepository implements Repository { 35 private final URI root; 36 37 public MavenRepository(File root) { 38 this.root = root.toURI(); 39 } 40 41 public boolean hasURI(URI uri) { 42 uri = root.resolve(uri); 43 if ("file".equals(uri.getScheme())) { 44 return new File (uri).canRead(); 45 } else { 46 try { 47 uri.toURL().openStream().close(); 48 return true; 49 } catch (IOException e) { 50 return false; 51 } 52 } 53 } 54 55 public URL getURL(URI uri) throws MalformedURLException { 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 .class, true); 70 builder.setConstructor(new String []{"root"}); 71 GBEAN_INFO = builder.getBeanInfo(); 72 } 73 } 74 | Popular Tags |