1 19 20 package org.netbeans.modules.j2ee.deployment.impl; 21 22 import javax.enterprise.deploy.spi.Target ; 23 24 public class ServerString implements java.io.Serializable { 25 26 private final String plugin; 27 private final String instance; 28 private final String [] targets; 29 private final transient ServerInstance serverInstance; 30 private transient String [] theTargets; 31 private static final long serialVersionUID = 923457209372L; 32 33 public ServerString(String plugin, String instance, String [] targets) { 34 if (targets == null) 35 this.targets = new String [0]; 36 else 37 this.targets = targets; 38 this.plugin = plugin; this.instance = instance; this.serverInstance = null; 39 } 40 41 public ServerString(Server server) { 42 this.plugin = server.getShortName(); 43 this.instance = null; 44 this.targets = new String [0]; 45 this.serverInstance = null; 46 } 47 48 public ServerString(ServerInstance instance) { 49 assert instance != null; 50 this.plugin = instance.getServer().getShortName(); 51 this.instance = instance.getUrl(); 52 this.serverInstance = instance; 53 54 this.targets = null; 55 72 } 73 74 public ServerString(ServerTarget target) { 75 this.plugin = target.getInstance().getServer().getShortName(); 76 this.instance = target.getInstance().getUrl(); 77 this.targets = new String [] { target.getName() }; 78 this.serverInstance = null; 79 } 80 81 public ServerString(ServerInstance instance, String targetName) { 82 this.plugin = instance.getServer().getShortName(); 83 this.instance = instance.getUrl(); 84 this.serverInstance = instance; 85 if (targetName != null && ! "".equals(targetName.trim())) this.targets = new String [] { targetName }; 87 else 88 this.targets = null; 89 } 90 91 public String getPlugin() { 92 return plugin; 93 } 94 95 public String getUrl() { 96 return instance; 97 } 98 99 public String [] getTargets() { 100 return getTargets(false); 101 } 102 103 public String [] getTargets(boolean concrete) { 104 if (! concrete) { 105 if (targets == null) return new String [0]; 106 return targets; 107 } 108 109 if (targets != null && targets.length > 0) 110 return targets; 111 112 if (theTargets != null) 113 return theTargets; 114 115 ServerTarget[] serverTargets = getServerInstance().getTargets(); 116 theTargets = new String [serverTargets.length]; 117 for (int i=0; i<theTargets.length; i++) 118 theTargets[i] = serverTargets[i].getName(); 119 return theTargets; 120 } 121 122 public Server getServer() { 123 return ServerRegistry.getInstance().getServer(plugin); 124 } 125 126 public ServerInstance getServerInstance() { 127 if (serverInstance != null) 128 return serverInstance; 129 return ServerRegistry.getInstance().getServerInstance(instance); 130 } 131 132 public String toString() { 133 if (targets == null) return "Server " + plugin + " Instance " + instance + " Targets none"; return "Server " + plugin + " Instance " + instance + " Targets " + targets.length; } 136 137 public static ServerString fromTarget(ServerInstance instance, Target target) { 138 return new ServerString(new ServerTarget(instance, target)); 139 } 140 141 public Target [] toTargets() { 142 String [] targetNames = getTargets(true); 143 Target [] ret = new Target [targetNames.length]; 144 for (int i=0; i<targetNames.length; i++) 145 ret[i] = getServerInstance().getServerTarget(targetNames[i]).getTarget(); 146 return ret; 147 } 148 } 149 | Popular Tags |