1 2 package SOFA.Util; 3 4 import java.net.InetAddress ; 5 import java.net.UnknownHostException ; 6 7 import org.omg.CosNaming.NameComponent ; 8 9 import SOFA.SOFAnode.Run.DeplDockRegistry.DeplDockRegistry; 10 import SOFA.SOFAnode.Run.DeplDockRegistry.DeplDockRegistryHelper; 11 import SOFA.SOFAnode.Run.DeplDockRegistry.NotFoundException; 12 13 14 15 19 public class SOFAURI { 20 21 22 public static class BadSOFAURIException extends cz.cuni.sofa.lib.SystemException { 23 public BadSOFAURIException() { 24 super(); 25 } 26 27 public BadSOFAURIException(String __reason) { 28 super(__reason); 29 } 30 31 public BadSOFAURIException(String __reason, Throwable __cause) { 32 super(__reason, __cause); 33 } 34 } 35 36 41 public static byte[] getReferenceToDeplDockFromSOFAURI(String sofaURI) throws BadSOFAURIException { 42 java.net.URI uri = null; 43 try { 44 uri = new java.net.URI (sofaURI); 45 } catch (java.net.URISyntaxException e) { 46 throw new BadSOFAURIException("URISynaxException: "+e.getMessage(), e); 47 } 48 if (uri.getScheme().compareTo("sofa") != 0) 49 throw new BadSOFAURIException("Bad scheme of the URI"); 50 String sofaNodeName = System.getProperty("sofa.nodename",""); 51 if (sofaNodeName.compareTo("")==0) { 52 try { 53 sofaNodeName = InetAddress.getLocalHost().getHostName(); 54 } catch (UnknownHostException e) {} 55 } 56 String host = uri.getHost(); 57 if (host.compareTo("local")==0 || host.compareTo(sofaNodeName)==0) 58 throw new BadSOFAURIException("Can't locate sofa node"); 59 String dockName = uri.getPath(); 60 if (dockName.lastIndexOf('/')!=0) 61 throw new BadSOFAURIException("Bad name of the depldock"); 62 dockName = dockName.substring(1); 63 64 SOFA.Util.CORBAAccess ca = new SOFA.Util.CORBAAccess(); 65 NameComponent nc = new NameComponent ("DeplDockRegistry", ""); 66 NameComponent path[] = {nc}; 67 DeplDockRegistry ddr = null; 68 try { 69 ddr = DeplDockRegistryHelper.narrow(SOFA.Util.CORBAAccess.ncRef.resolve(path)); 70 } catch (Exception e) { 71 throw new SOFA.SOFAnode.Run.SOFARuntimeException("Can't get DeplDock registry."); 72 } 73 74 byte[] serRef = null; 75 try { 76 serRef = ddr.lookup(dockName); 77 } catch (NotFoundException e) { 78 throw new BadSOFAURIException("No deployment dock with name \""+dockName+"\"."); 79 } 80 return serRef; 81 } 82 83 87 public static boolean isLocal(java.net.URI uri) { 88 if (uri.getScheme().compareTo("sofa") != 0) 89 return false; 90 if (uri.getHost().compareTo("local")!=0) 91 return false; 92 if (uri.getPath().compareTo("/local")!=0) 93 return false; 94 return true; 95 } 96 97 102 public static boolean isLocal(String uri) throws BadSOFAURIException { 103 java.net.URI u = null; 104 try { 105 u = new java.net.URI (uri); 106 } catch (java.net.URISyntaxException e) { 107 throw new BadSOFAURIException("URISynaxException: "+e.getMessage(), e); 108 } 109 return isLocal(u); 110 } 111 112 } 113 | Popular Tags |