1 19 20 21 26 27 package org.netbeans.modules.j2ee.deployment.impl; 28 29 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 30 import org.openide.filesystems.FileObject; 31 import org.openide.util.NbBundle; 32 import java.beans.PropertyChangeEvent ; 33 import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; 34 35 39 public class InstancePropertiesImpl extends InstanceProperties implements InstanceListener { 40 private final String url; 41 private transient FileObject fo; 42 43 44 public InstancePropertiesImpl(ServerInstance instance) { 45 this(instance.getUrl()); 46 } 47 48 49 public InstancePropertiesImpl(String url) { 50 this.url = url; 51 } 52 53 private FileObject getFO() { 54 if (fo == null) { 55 ServerInstance instance = ServerRegistry.getInstance().getServerInstance(url); 56 if (instance == null) 57 throw new IllegalStateException ( 58 (NbBundle.getMessage(InstancePropertiesImpl.class, "MSG_InstanceNotExists", url))); fo = ServerRegistry.getInstance().getInstanceFileObject(url); 60 if (fo == null) 61 throw new IllegalStateException ( 62 (NbBundle.getMessage(InstancePropertiesImpl.class, "MSG_InstanceNotExists", url))); 64 } 65 return fo; 66 } 67 68 public void instanceRemoved(String instance) { 70 if (instance != null && url.equals(instance)) 71 fo = null; 72 } 73 public void instanceAdded(String instance) {} 74 public void changeDefaultInstance(String oldInstance, String newInstance){ 75 } 76 77 public String getProperty(String propname) throws IllegalStateException { 78 Object propValue = getFO().getAttribute(propname); 79 return propValue == null ? null : propValue.toString(); 80 } 81 82 public java.util.Enumeration propertyNames() throws IllegalStateException { 83 return getFO().getAttributes(); 84 } 85 86 public void setProperty(String propname, String value) throws IllegalStateException { 87 try { 88 String oldValue = getProperty(propname); 89 getFO().setAttribute(propname, value); 90 firePropertyChange(new PropertyChangeEvent (this, propname, oldValue, value)); 91 } catch (java.io.IOException ioe) { 92 throw (IllegalStateException ) org.openide.ErrorManager.getDefault().annotate( 93 new IllegalStateException (NbBundle.getMessage(InstancePropertiesImpl.class, "MSG_InstanceNotExists", url)),ioe); 94 } 95 } 96 97 public void setProperties(java.util.Properties props) throws IllegalStateException { 98 java.util.Enumeration propNames = props.propertyNames(); 99 while (propNames.hasMoreElements()) { 100 String propName = (String ) propNames.nextElement(); 101 String propValue = props.getProperty(propName); 102 setProperty(propName, propValue); 103 } 104 } 105 106 public javax.enterprise.deploy.spi.DeploymentManager getDeploymentManager() { 107 ServerRegistry registry = ServerRegistry.getInstance(); 108 ServerInstance inst = registry.getServerInstance(url); 109 return inst.getDeploymentManager(); 110 } 111 112 public javax.enterprise.deploy.spi.Target getDefaultTarget() { 113 ServerRegistry registry = ServerRegistry.getInstance(); 114 ServerString ss = registry.getDefaultInstance(); 115 javax.enterprise.deploy.spi.Target [] targets = ss.toTargets(); 116 if (targets != null && targets.length > 0) 117 return targets[0]; 118 return null; 119 } 120 121 public void setAsDefaultServer(String targetName) { 122 ServerRegistry registry = ServerRegistry.getInstance(); 123 ServerInstance inst = registry.getServerInstance(url); 124 ServerString server = new ServerString(inst, targetName); 125 registry.setDefaultInstance(server); 126 } 127 128 public boolean isDefaultInstance() { 129 ServerRegistry registry = ServerRegistry.getInstance(); 130 ServerString ss = registry.getDefaultInstance(); 131 return ss.getUrl().equals(url); 132 } 133 134 public void refreshServerInstance() { 135 ServerRegistry registry = ServerRegistry.getInstance(); 136 ServerInstance inst = registry.getServerInstance(url); 137 if (inst != null) { 138 inst.refresh(); 139 } 140 } 141 } 142 | Popular Tags |