1 19 20 package org.netbeans.modules.j2ee.sun.share.configbean; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 25 import javax.enterprise.deploy.model.DDBean ; 26 import javax.enterprise.deploy.model.DDBeanRoot ; 27 import javax.enterprise.deploy.spi.DeploymentConfiguration ; 28 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 29 30 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 31 import org.netbeans.modules.j2ee.sun.dd.api.DDProvider; 32 import org.netbeans.modules.j2ee.sun.dd.api.app.SunApplication; 33 import org.netbeans.modules.j2ee.sun.dd.api.app.Web; 34 35 36 41 public class WebAppRef extends BaseModuleRef { 42 43 46 47 49 public WebAppRef() { 50 } 51 52 protected void init(DDBean dDBean, Base parent) throws ConfigurationException { 53 super.init(dDBean, parent); 54 55 contextRootDD = getNameDD("context-root"); 56 loadFromPlanFile(getConfig()); 57 } 58 59 62 protected void initModuleUri(DDBean dDBean) { 63 DDBean [] uriBeans = dDBean.getChildBean("web-uri"); 64 if(uriBeans.length > 0) { 65 setModuleUri(uriBeans[0]); 66 } else { 67 setModuleUri(null); 68 } 69 } 70 71 75 public String getTitleFragment() { 76 return bundle.getString("LBL_WebTitleFragment"); } 78 79 82 83 85 88 89 90 92 93 private DDBean contextRootDD = null; 94 private String contextRoot; 95 96 100 public String getWebUri() { 101 return getModuleUri(); 102 } 103 104 108 public String getContextRoot() { 109 String result = null; 110 111 114 if(contextRoot == null || contextRoot.length() == 0 && contextRootDD != null) { 115 result = contextRootDD.getText(); 116 } else { 117 result = contextRoot; 118 } 119 120 return result; 121 } 122 123 127 public void setContextRoot(String newContextRoot) throws java.beans.PropertyVetoException { 128 if (newContextRoot!=null){ 129 newContextRoot = newContextRoot.replace (' ', '_'); } 131 if (newContextRoot!=null){ try{ 133 String result=""; 134 String s[] = newContextRoot.split("/"); 135 for (int i=0;i<s.length;i++){ 136 result=result+java.net.URLEncoder.encode(s[i], "UTF-8"); 137 if (i!=s.length -1) 138 result=result+"/"; 139 } 140 newContextRoot= result; 141 } 142 catch (Exception e){ 143 144 } 145 } 146 String oldContextRoot = contextRoot; 147 getVCS().fireVetoableChange("contextRoot", oldContextRoot, newContextRoot); 148 contextRoot = newContextRoot; 149 getPCS().firePropertyChange("contextRoot", oldContextRoot, contextRoot); 150 } 151 152 153 public String getHelpId() { 154 return "AS_CFG_WebAppRef"; } 156 157 158 161 Collection getSnippets() { 162 Collection snippets = new ArrayList (); 163 Snippet snipOne = new DefaultSnippet() { 164 165 public CommonDDBean getDDSnippet() { 166 Web web = getConfig().getStorageFactory().createWeb(); 167 168 web.setWebUri(getWebUri()); 169 web.setContextRoot(getContextRoot()); 170 171 return web; 172 } 173 174 public boolean hasDDSnippet() { 175 if(Utils.notEmpty(contextRoot)) { 176 return true; 177 } 178 179 return false; 180 } 181 182 public String getPropertyName() { 183 return SunApplication.WEB; 184 } 185 }; 186 187 snippets.add(snipOne); 188 return snippets; 189 } 190 191 private class WebAppRefFinder implements ConfigFinder { 192 public Object find(Object obj) { 193 Web result = null; 194 String webUri = getWebUri(); 195 196 if(obj instanceof SunApplication && webUri != null) { 197 SunApplication sa = (SunApplication) obj; 198 Web [] webModules = sa.getWeb(); 199 200 for(int i = 0; i < webModules.length; i++) { 201 if(webUri.compareTo(webModules[i].getWebUri()) == 0) { 202 result = webModules[i]; 203 break; 204 } 205 } 206 } 207 208 return result; 209 } 210 } 211 212 boolean loadFromPlanFile(SunONEDeploymentConfiguration config) { 213 String uriText = getUriText(); 214 215 Web beanGraph = (Web) config.getBeans( 216 uriText, constructFileName(), getParser(), new WebAppRefFinder()); 217 218 clearProperties(); 219 220 if(beanGraph != null) { 221 String cr = beanGraph.getContextRoot(); 222 if(Utils.notEmpty(cr) && cr.compareTo(getContextRoot()) != 0) { 223 contextRoot = cr; 224 } 225 } else { 226 setDefaultProperties(); 227 } 228 229 return (beanGraph != null); 230 } 231 232 protected void clearProperties() { 233 contextRoot = null; 234 } 235 236 protected void setDefaultProperties() { 237 } 239 } 240 | Popular Tags |