1 23 24 package com.sun.enterprise.deployment.deploy.shared; 25 26 import java.io.IOException ; 27 import java.net.URI ; 28 import java.net.MalformedURLException ; 29 import java.io.File ; 30 31 38 public class ArchiveFactory implements AbstractArchiveFactory { 39 40 41 public ArchiveFactory() { 42 } 43 44 45 public AbstractArchive createArchive(String path) throws java.io.IOException { 46 try { 47 51 return createArchive(prepareArchiveURI(path)); 52 } catch(java.net.URISyntaxException e) { 53 return null; 54 } 55 } 56 57 public AbstractArchive openArchive(String path) throws java.io.IOException { 58 try { 59 return openArchive(prepareArchiveURI(path)); 60 } catch(java.net.URISyntaxException e) { 61 return null; 62 } 63 } 64 65 71 public AbstractArchive createArchive(URI path) throws IOException { 72 73 String protocol = path.getScheme(); 74 if (protocol.equals("file")) { 75 FileArchive output = new FileArchive(); 76 output.create(path.getPath()); 77 return output; 78 } else 79 if (protocol.equals("jar")) { 80 OutputJarArchive ja = new OutputJarArchive(); 81 ja.create(path.getPath()); 82 return ja; 83 } else 84 throw new MalformedURLException ("Protocol not supported : " + protocol); 85 } 86 87 94 public AbstractArchive openArchive(URI path) throws IOException { 95 96 String protocol = path.getScheme(); 97 if (protocol.equals("file")) { 98 FileArchive input = new FileArchive(); 99 input.open(path.getPath()); 100 return input; 101 } else 102 if (protocol.equals("jar")) { 103 InputJarArchive ja = new InputJarArchive(); 104 ja.open(path.getPath()); 105 return ja; 106 } else 107 112 throw new MalformedURLException ("Protocol not supported : " + protocol); 113 } 114 115 124 static java.net.URI prepareArchiveURI(String path) throws java.net.URISyntaxException , java.io.UnsupportedEncodingException , java.io.IOException { 125 126 File archiveFile = new File (path); 127 URI archiveURI = archiveFile.toURI(); 128 String scheme = (archiveFile.isDirectory() ? "file" : "jar"); 129 URI answer = new URI (scheme, null , archiveURI.getPath(), null , null ); 130 return answer; 131 } 132 } 133 | Popular Tags |