Lines 34-41
Link Here
|
34 |
import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler; |
34 |
import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler; |
35 |
import org.openide.modules.InstalledFileLocator; |
35 |
import org.openide.modules.InstalledFileLocator; |
36 |
|
36 |
|
37 |
//import java.util.logging.*; |
|
|
38 |
|
39 |
public final class ServerRegistry implements java.io.Serializable { |
37 |
public final class ServerRegistry implements java.io.Serializable { |
40 |
|
38 |
|
41 |
public static final String DIR_INSTALLED_SERVERS = "/J2EE/InstalledServers"; //NOI18N |
39 |
public static final String DIR_INSTALLED_SERVERS = "/J2EE/InstalledServers"; //NOI18N |
Lines 43-50
Link Here
|
43 |
public static final String URL_ATTR = InstanceProperties.URL_ATTR; |
41 |
public static final String URL_ATTR = InstanceProperties.URL_ATTR; |
44 |
public static final String USERNAME_ATTR = InstanceProperties.USERNAME_ATTR; |
42 |
public static final String USERNAME_ATTR = InstanceProperties.USERNAME_ATTR; |
45 |
public static final String PASSWORD_ATTR = InstanceProperties.PASSWORD_ATTR; |
43 |
public static final String PASSWORD_ATTR = InstanceProperties.PASSWORD_ATTR; |
46 |
public static final String FILE_DEFAULT_INSTANCE = "DefaultInstance.settings"; //NOI18N |
|
|
47 |
public static final String J2EE_DEFAULT_SERVER = "j2ee.defaultServer"; //NOI18N |
48 |
public static final String TARGETNAME_ATTR = "targetName"; //NOI18N |
44 |
public static final String TARGETNAME_ATTR = "targetName"; //NOI18N |
49 |
public static final String SERVER_NAME = "serverName"; //NOI18N |
45 |
public static final String SERVER_NAME = "serverName"; //NOI18N |
50 |
private static ServerRegistry instance = null; |
46 |
private static ServerRegistry instance = null; |
Lines 224-243
Link Here
|
224 |
if (url == null) |
220 |
if (url == null) |
225 |
return; |
221 |
return; |
226 |
|
222 |
|
227 |
// Make sure defaultInstance cache is reset |
|
|
228 |
ServerString def = getDefaultInstance(); |
229 |
if (url.equals(def.getUrl())) { |
230 |
defaultInstance = null; |
231 |
} |
232 |
|
233 |
ServerInstance instance = (ServerInstance) instancesMap().remove(url); |
223 |
ServerInstance instance = (ServerInstance) instancesMap().remove(url); |
234 |
if (instance != null) { |
224 |
if (instance != null) { |
235 |
fireInstanceListeners(url, false); |
225 |
fireInstanceListeners(url, false); |
236 |
removeInstanceFromFile(url); |
226 |
removeInstanceFromFile(url); |
237 |
} |
227 |
} |
238 |
ServerString newinst = getDefaultInstance(false); |
|
|
239 |
fireDefaultInstance(def != null ? def.getUrl() : null, |
240 |
newinst != null ? newinst.getUrl() : null); |
241 |
} |
228 |
} |
242 |
|
229 |
|
243 |
public ServerInstance[] getServerInstances() { |
230 |
public ServerInstance[] getServerInstances() { |
Lines 430-516
Link Here
|
430 |
} |
417 |
} |
431 |
} |
418 |
} |
432 |
|
419 |
|
433 |
private void fireDefaultInstance(String oldInstance, String newInstance) { |
|
|
434 |
InstanceListener[] instListeners = getInstanceListeners(); |
435 |
for(int i = 0; i < instListeners.length; i++) { |
436 |
instListeners[i].changeDefaultInstance(oldInstance, newInstance); |
437 |
} |
438 |
} |
439 |
|
440 |
public void setDefaultInstance(ServerString instance) { |
441 |
if (instance != null && instance.equals(defaultInstance)) { |
442 |
return; |
443 |
} |
444 |
|
445 |
if (instance == null) { |
446 |
removeDefaultInstanceFile(); |
447 |
ServerString oldValue = defaultInstance; |
448 |
defaultInstance = null; |
449 |
fireDefaultInstance(oldValue != null ? oldValue.getUrl() : null, null); |
450 |
} else { |
451 |
if (ServerStringConverter.writeServerInstance(instance, DIR_INSTALLED_SERVERS, FILE_DEFAULT_INSTANCE)) { |
452 |
ServerString oldValue = defaultInstance; |
453 |
defaultInstance = instance; |
454 |
fireDefaultInstance(oldValue != null ? oldValue.getUrl() : null, |
455 |
instance != null ? instance.getUrl() : null); |
456 |
} |
457 |
} |
458 |
} |
459 |
|
460 |
static private void removeDefaultInstanceFile() { |
461 |
FileLock lock = null; |
462 |
Writer writer = null; |
463 |
try { |
464 |
String pathName = DIR_INSTALLED_SERVERS + "/" + FILE_DEFAULT_INSTANCE; // NOI18N |
465 |
FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource(pathName); |
466 |
if (fo != null) |
467 |
fo.delete(); |
468 |
} catch(Exception ioe) { |
469 |
org.openide.ErrorManager.getDefault().notify(org.openide.ErrorManager.WARNING, ioe); |
470 |
} |
471 |
} |
472 |
|
473 |
private ServerString getInstallerDefaultPlugin() { |
474 |
File propFile = InstalledFileLocator.getDefault ().locate ("config/install.properties", null, false); // NOI18N |
475 |
Properties installProp = readProperties(propFile); //NOI18N |
476 |
|
477 |
String j2eeDefaultServerFileName = installProp.getProperty(J2EE_DEFAULT_SERVER); |
478 |
if (j2eeDefaultServerFileName == null) |
479 |
return null; |
480 |
|
481 |
File serverFile = InstalledFileLocator.getDefault ().locate (j2eeDefaultServerFileName, null, false); |
482 |
Properties defaultServerProp = readProperties(serverFile); |
483 |
String serverName = defaultServerProp.getProperty(SERVER_NAME); |
484 |
String url = defaultServerProp.getProperty(URL_ATTR); |
485 |
String user = defaultServerProp.getProperty(USERNAME_ATTR); |
486 |
String password = defaultServerProp.getProperty(PASSWORD_ATTR); |
487 |
String targetName = defaultServerProp.getProperty(TARGETNAME_ATTR); |
488 |
|
489 |
try { |
490 |
if (url != null) { |
491 |
InstanceProperties instProp = InstanceProperties.getInstanceProperties(url); |
492 |
if (instProp == null) |
493 |
instProp = InstanceProperties.createInstanceProperties(url, user, password); |
494 |
instProp.setProperties(defaultServerProp); |
495 |
|
496 |
ServerInstance inst = getServerInstance(url); |
497 |
if (inst != null) |
498 |
return new ServerString(inst, targetName); |
499 |
|
500 |
} else if (serverName != null) { |
501 |
Server server = getServer(serverName); |
502 |
if (server != null) { |
503 |
ServerInstance[] instances = server.getInstances(); |
504 |
if (instances.length > 1) |
505 |
return new ServerString(instances[0]); |
506 |
} |
507 |
} |
508 |
} catch (Exception e) { |
509 |
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); |
510 |
} |
511 |
return null; |
512 |
} |
513 |
|
514 |
static private Properties readProperties(File propFile) { |
420 |
static private Properties readProperties(File propFile) { |
515 |
Properties prop = new Properties(); |
421 |
Properties prop = new Properties(); |
516 |
try { |
422 |
try { |
Lines 522-555
Link Here
|
522 |
return prop; |
428 |
return prop; |
523 |
} |
429 |
} |
524 |
|
430 |
|
525 |
public ServerString getDefaultInstance() { |
|
|
526 |
return getDefaultInstance(true); |
527 |
} |
528 |
|
529 |
public ServerString getDefaultInstance(boolean readFromFile) { |
530 |
if (defaultInstance != null) |
531 |
return defaultInstance; |
532 |
|
533 |
if (readFromFile) { |
534 |
defaultInstance = ServerStringConverter.readServerInstance(DIR_INSTALLED_SERVERS, FILE_DEFAULT_INSTANCE); |
535 |
|
536 |
if (defaultInstance == null) { |
537 |
defaultInstance = getInstallerDefaultPlugin(); |
538 |
} |
539 |
|
540 |
} |
541 |
|
542 |
if (defaultInstance == null) { |
543 |
ServerInstance[] instances = getServerInstances(); |
544 |
if (instances != null && instances.length > 0) { |
545 |
defaultInstance = new ServerString(instances[0]); |
546 |
} |
547 |
} |
548 |
|
549 |
setDefaultInstance(defaultInstance); |
550 |
return defaultInstance; |
551 |
} |
552 |
|
553 |
public interface PluginListener { |
431 |
public interface PluginListener { |
554 |
|
432 |
|
555 |
public void serverAdded(Server name); |
433 |
public void serverAdded(Server name); |
Lines 586-601
Link Here
|
586 |
initConfigNamesByType(); |
464 |
initConfigNamesByType(); |
587 |
Set configNames = (Set) configNamesByType.get(type); |
465 |
Set configNames = (Set) configNamesByType.get(type); |
588 |
return (configNames != null && configNames.contains(name)); |
466 |
return (configNames != null && configNames.contains(name)); |
589 |
} |
|
|
590 |
|
591 |
public ServerInstance getInstanceOrDefault(String uri) { |
592 |
ServerInstance instance = getServerInstance(uri); |
593 |
if (instance == null) { |
594 |
instance = getDefaultInstance().getServerInstance(); |
595 |
} |
596 |
if (instance != null) |
597 |
return instance; |
598 |
throw new RuntimeException(NbBundle.getMessage(ServerRegistry.class, "MSG_NoServerInstances", uri)); |
599 |
} |
467 |
} |
600 |
|
468 |
|
601 |
/** Return profiler if any is registered in the IDE, null otherwise. */ |
469 |
/** Return profiler if any is registered in the IDE, null otherwise. */ |