PageRenderTime 49ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/projects/netbeans-7.3/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/wsclient/AppClientProjectWebServicesClientSupport.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 908 lines | 672 code | 98 blank | 138 comment | 132 complexity | 7ff7535e6be647917a12e58350e2b947 MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * Contributor(s):
  28. *
  29. * The Original Software is NetBeans. The Initial Developer of the Original
  30. * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
  31. * Microsystems, Inc. All Rights Reserved.
  32. *
  33. * If you wish your version of this file to be governed by only the CDDL
  34. * or only the GPL Version 2, indicate your decision by adding
  35. * "[Contributor] elects to include this software in this distribution
  36. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  37. * single choice of license, a recipient has the option to distribute
  38. * your version of this file under either the CDDL, the GPL Version 2 or
  39. * to extend the choice of license to its licensees as provided above.
  40. * However, if you add GPL Version 2 code and therefore, elected the GPL
  41. * Version 2 license, then the option applies only if the new code is
  42. * made subject to such option by the copyright holder.
  43. */
  44. package org.netbeans.modules.j2ee.clientproject.wsclient;
  45. import org.netbeans.modules.j2ee.dd.api.client.AppClient;
  46. import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException;
  47. import org.openide.util.Mutex.Action;
  48. import static org.netbeans.modules.websvc.api.client.WebServicesClientConstants.*;
  49. import java.io.IOException;
  50. import java.net.InetAddress;
  51. import java.net.URI;
  52. import java.net.URISyntaxException;
  53. import java.net.UnknownHostException;
  54. import java.util.ArrayList;
  55. import java.util.Arrays;
  56. import java.util.HashSet;
  57. import java.util.Iterator;
  58. import java.util.List;
  59. import java.util.Set;
  60. import java.util.logging.Level;
  61. import java.util.logging.Logger;
  62. import org.netbeans.api.j2ee.core.Profile;
  63. import org.netbeans.api.project.Project;
  64. import org.netbeans.api.project.ProjectManager;
  65. import org.netbeans.api.project.ui.OpenProjects;
  66. import org.netbeans.modules.j2ee.clientproject.AppClientProject;
  67. import org.netbeans.modules.j2ee.clientproject.AppClientProjectType;
  68. import org.netbeans.modules.j2ee.clientproject.AppClientProvider;
  69. import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties;
  70. import org.netbeans.modules.j2ee.dd.api.client.DDProvider;
  71. import org.netbeans.modules.j2ee.dd.api.common.NameAlreadyUsedException;
  72. import org.netbeans.modules.j2ee.dd.api.common.PortComponentRef;
  73. import org.netbeans.modules.j2ee.dd.api.common.RootInterface;
  74. import org.netbeans.modules.j2ee.dd.api.common.ServiceRef;
  75. import org.netbeans.modules.websvc.api.client.ClientStubDescriptor;
  76. import org.netbeans.modules.websvc.api.client.WsCompileClientEditorSupport;
  77. import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportImpl;
  78. import org.netbeans.spi.project.support.ant.AntProjectHelper;
  79. import org.netbeans.spi.project.support.ant.EditableProperties;
  80. import org.netbeans.spi.project.support.ant.PropertyUtils;
  81. import org.netbeans.spi.project.support.ant.ReferenceHelper;
  82. import org.openide.DialogDisplayer;
  83. import org.openide.NotifyDescriptor;
  84. import org.openide.filesystems.FileObject;
  85. import org.openide.filesystems.FileUtil;
  86. import org.openide.util.NbBundle;
  87. import org.w3c.dom.Document;
  88. import org.w3c.dom.Element;
  89. import org.w3c.dom.Node;
  90. import org.w3c.dom.NodeList;
  91. /**
  92. * Implementation of WebServicesSupportImpl and WebServicesClientSupportImpl.
  93. *
  94. * @author rico
  95. */
  96. public class AppClientProjectWebServicesClientSupport implements WebServicesClientSupportImpl{
  97. private final AppClientProject project;
  98. private final AntProjectHelper helper;
  99. private final ReferenceHelper referenceHelper;
  100. private String proxyHost,proxyPort;
  101. public static final String WSDL_FOLDER = "wsdl"; //NOI18N
  102. /** Creates a new instance of J2SEProjectWebServicesSupport */
  103. public AppClientProjectWebServicesClientSupport(AppClientProject project, AntProjectHelper helper, ReferenceHelper referenceHelper) {
  104. this.project = project;
  105. this.helper = helper;
  106. this.referenceHelper = referenceHelper;
  107. }
  108. public AntProjectHelper getAntProjectHelper() {
  109. return helper;
  110. }
  111. public ReferenceHelper getReferenceHelper(){
  112. return referenceHelper;
  113. }
  114. // Implementation of WebServiceClientSupportImpl
  115. public void addServiceClient(String serviceName, String packageName, String sourceUrl, FileObject configFile, ClientStubDescriptor stubDescriptor) {
  116. this.addServiceClient(serviceName, packageName, sourceUrl, configFile, stubDescriptor, null);
  117. }
  118. // Implementation of WebServiceClientSupportImpl
  119. public void addServiceClient(final String serviceName, final String packageName, final String sourceUrl, final FileObject configFile, final ClientStubDescriptor stubDescriptor, final String[] wscompileFeatures) {
  120. // It seems like it ought to be implemented via the AuxiliaryConfiguration interface.
  121. boolean needToSave = ProjectManager.mutex().writeAccess(new Action<Boolean>() {
  122. public Boolean run() {
  123. boolean needsSave = false;
  124. boolean modifiedProjectProperties = false;
  125. boolean modifiedPrivateProperties = false;
  126. /** Locate root of web service client node structure in project,xml, creating it
  127. * if it's not found.
  128. */
  129. Element data = helper.getPrimaryConfigurationData(true);
  130. Document doc = data.getOwnerDocument();
  131. NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS);
  132. Element clientElements = null;
  133. if(nodes.getLength() == 0) {
  134. // 'needsSave' deliberately left false here because this is a trival change
  135. // that only should be saved if additional changes are also made below.
  136. clientElements = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENTS);
  137. NodeList srcRoots = data.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "source-roots"); // NOI18N
  138. assert srcRoots.getLength() == 1 : "Invalid project.xml."; // NOI18N
  139. data.insertBefore(clientElements, srcRoots.item(0));
  140. } else {
  141. clientElements = (Element) nodes.item(0);
  142. }
  143. /** Make sure this service is not already registered in project.xml
  144. */
  145. boolean serviceAlreadyAdded = false;
  146. NodeList clientNameList = clientElements.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME);
  147. for(int i = 0; i < clientNameList.getLength(); i++ ) {
  148. Element clientNameElement = (Element) clientNameList.item(i);
  149. NodeList nl = clientNameElement.getChildNodes();
  150. if(nl.getLength() >= 1) {
  151. Node n = nl.item(0);
  152. if(n.getNodeType() == Node.TEXT_NODE) {
  153. if(serviceName.equalsIgnoreCase(n.getNodeValue())) {
  154. serviceAlreadyAdded = true;
  155. // !PW FIXME should force stub type to match value passed in
  156. // in case someone is overwriting a current service with a different
  157. // stub type.
  158. }
  159. }
  160. }
  161. }
  162. /** Add entry for the client to project.xml and regenerate build-impl.xml.
  163. */
  164. if(!serviceAlreadyAdded) {
  165. Element clientElement = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT);
  166. clientElements.appendChild(clientElement);
  167. Element clientElementName = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME);
  168. clientElement.appendChild(clientElementName);
  169. clientElementName.appendChild(doc.createTextNode(serviceName));
  170. Element clientElementStubType = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_STUB_TYPE);
  171. clientElement.appendChild(clientElementStubType);
  172. clientElementStubType.appendChild(doc.createTextNode(stubDescriptor.getName()));
  173. Element clientElementSourceUrl = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL);
  174. clientElement.appendChild(clientElementSourceUrl);
  175. clientElementSourceUrl.appendChild(doc.createTextNode(sourceUrl));
  176. helper.putPrimaryConfigurationData(data, true);
  177. needsSave = true;
  178. }
  179. EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
  180. EditableProperties privateProperties = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
  181. // Add property for wscompile features
  182. {
  183. String featurePropertyName = "wscompile.client." + serviceName + ".features"; // NOI18N
  184. String defaultFeatures = "wsi, strict"; // NOI18N -- defaults if stub descriptor is bad type (should never happen?)
  185. if(stubDescriptor instanceof JAXRPCClientStubDescriptor) {
  186. JAXRPCClientStubDescriptor stubDesc = (JAXRPCClientStubDescriptor) stubDescriptor;
  187. if (wscompileFeatures!=null) {
  188. stubDesc.setDefaultFeatures(wscompileFeatures);
  189. }
  190. defaultFeatures = stubDesc.getDefaultFeaturesAsArgument();
  191. } else {
  192. // !PW FIXME wrong stub type -- log error message.
  193. }
  194. String oldFeatures = projectProperties.getProperty(featurePropertyName);
  195. if(!defaultFeatures.equals(oldFeatures)) {
  196. projectProperties.put(featurePropertyName, defaultFeatures);
  197. modifiedProjectProperties = true;
  198. }
  199. }
  200. // Add package name property
  201. {
  202. String packagePropertyName = "wscompile.client." + serviceName + ".package"; // NOI18N
  203. String oldPackageName = projectProperties.getProperty(packagePropertyName);
  204. if(!packageName.equals(oldPackageName)) {
  205. projectProperties.put(packagePropertyName, packageName);
  206. modifiedProjectProperties = true;
  207. }
  208. }
  209. // Add http.proxyHost, http.proxyPort and http.nonProxyHosts JVM options
  210. // create wscompile:httpproxy property
  211. if (proxyHost!=null && proxyHost.length()>0) {
  212. boolean modif = addJVMProxyOptions(projectProperties,proxyHost,proxyPort);
  213. if (modif) {
  214. modifiedProjectProperties = true;
  215. }
  216. String proxyProperty = "wscompile.client." + serviceName + ".proxy"; // NOI18N
  217. String oldProxyProperty = privateProperties.getProperty(proxyProperty);
  218. if(!proxyProperty.equals(oldProxyProperty)) {
  219. privateProperties.put(proxyProperty, proxyHost+':'+(proxyPort==null?"8080":proxyPort)); //NOI18N
  220. modifiedPrivateProperties = true;
  221. }
  222. }
  223. if(modifiedProjectProperties) {
  224. helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties);
  225. needsSave = true;
  226. }
  227. if(modifiedPrivateProperties) {
  228. helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProperties);
  229. needsSave = true;
  230. }
  231. // Update wscompile related properties. boolean return indicates whether
  232. // any changes were made.
  233. if(updateWsCompileProperties(serviceName)) {
  234. needsSave = true;
  235. }
  236. return needsSave;
  237. }
  238. });
  239. // !PW Lastly, save the project if we actually made any changes to any
  240. // properties or the build script.
  241. if(needToSave) {
  242. try {
  243. ProjectManager.getDefault().saveProject(project);
  244. } catch(IOException ex) {
  245. NotifyDescriptor desc = new NotifyDescriptor.Message(
  246. NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"MSG_ErrorSavingOnWSClientAdd", serviceName, ex.getMessage()), // NOI18N
  247. NotifyDescriptor.ERROR_MESSAGE);
  248. DialogDisplayer.getDefault().notify(desc);
  249. }
  250. }
  251. }
  252. public void addInfrastructure(String implBeanClass, FileObject pkg) {
  253. //nothing to do here, there are no infrastructure elements
  254. }
  255. public FileObject getDeploymentDescriptor() {
  256. FileObject webInfFo = project.getAPICar().getMetaInf();
  257. if (webInfFo==null) {
  258. if (isProjectOpened()) {
  259. DialogDisplayer.getDefault().notify(
  260. new NotifyDescriptor.Message(NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"MSG_WebInfCorrupted"), // NOI18N
  261. NotifyDescriptor.ERROR_MESSAGE));
  262. }
  263. return null;
  264. }
  265. return webInfFo.getFileObject(AppClientProvider.FILE_DD);
  266. }
  267. private FileObject getFileObject(String propname) {
  268. String prop = helper.getStandardPropertyEvaluator().getProperty(propname);
  269. if (prop != null) {
  270. return helper.resolveFileObject(prop);
  271. } else {
  272. return null;
  273. }
  274. }
  275. private boolean updateWsCompileProperties(String serviceName) {
  276. /** Ensure wscompile.classpath and wscompile.tools.classpath are
  277. * properly defined.
  278. *
  279. * wscompile.classpath goes in project properties and includes
  280. * jaxrpc and qname right now.
  281. *
  282. * wscompile.tools.classpath is for tools.jar which is needed when
  283. * running under the Sun JDK to invoke javac. It is placed in
  284. * user.properties so that if we compute it incorrectly (say on a mac)
  285. * the user can change it and we will not blow away the change.
  286. * Hopefully we can do this better for release.
  287. */
  288. boolean globalPropertiesChanged = false;
  289. EditableProperties globalProperties = PropertyUtils.getGlobalProperties();
  290. if(globalProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) {
  291. globalProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); // NOI18N
  292. try {
  293. PropertyUtils.putGlobalProperties(globalProperties);
  294. } catch(IOException ex) {
  295. NotifyDescriptor desc = new NotifyDescriptor.Message(
  296. NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"MSG_ErrorSavingGlobalProperties", serviceName, ex.getMessage()), // NOI18N
  297. NotifyDescriptor.ERROR_MESSAGE);
  298. DialogDisplayer.getDefault().notify(desc);
  299. }
  300. globalPropertiesChanged = true;
  301. }
  302. boolean projectPropertiesChanged = false;
  303. EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
  304. { // Block that adjusts wscompile.client.classpath as necessary.
  305. Set<String> wscJars = new HashSet<String>();
  306. boolean newWscJars = false;
  307. String wscClientClasspath = projectProperties.getProperty(WSCOMPILE_CLASSPATH);
  308. if(wscClientClasspath != null) {
  309. String [] libs = PropertyUtils.tokenizePath(wscClientClasspath);
  310. for(int i = 0; i < libs.length; i++) {
  311. wscJars.add(libs[i]);
  312. }
  313. }
  314. for(int i = 0; i < WSCOMPILE_JARS.length; i++) {
  315. if(!wscJars.contains(WSCOMPILE_JARS[i])) {
  316. wscJars.add(WSCOMPILE_JARS[i]);
  317. newWscJars = true;
  318. }
  319. }
  320. if(newWscJars) {
  321. StringBuffer newClasspathBuf = new StringBuffer(256);
  322. for(Iterator iter = wscJars.iterator(); iter.hasNext(); ) {
  323. newClasspathBuf.append(iter.next().toString());
  324. if(iter.hasNext()) {
  325. newClasspathBuf.append(':');
  326. }
  327. }
  328. projectProperties.put(WSCOMPILE_CLASSPATH, newClasspathBuf.toString());
  329. projectPropertiesChanged = true;
  330. }
  331. }
  332. // set tools.jar property if not set
  333. if(projectProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) {
  334. projectProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); // NOI18N
  335. projectPropertiesChanged = true;
  336. }
  337. if(projectPropertiesChanged) {
  338. helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties);
  339. }
  340. return globalPropertiesChanged || projectPropertiesChanged;
  341. }
  342. public void removeServiceClient(final String serviceName) {
  343. // 2. Remove service from project.xml
  344. // Side effect: Regenerate build-impl.xsl
  345. // Optional - if last service, remove properties we generated.
  346. boolean needToSave = ProjectManager.mutex().writeAccess(new Action<Boolean>() {
  347. public Boolean run() {
  348. boolean needsSave = false;
  349. boolean needsSave1 = false;
  350. /** Remove properties from project.properties
  351. */
  352. String featureProperty = "wscompile.client." + serviceName + ".features"; // NOI18N
  353. String packageProperty = "wscompile.client." + serviceName + ".package"; // NOI18N
  354. String proxyProperty = "wscompile.client." + serviceName + ".proxy"; //NOI18N
  355. EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
  356. EditableProperties ep1 = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
  357. if(ep.getProperty(featureProperty) != null) {
  358. ep.remove(featureProperty);
  359. needsSave = true;
  360. }
  361. if(ep.getProperty(packageProperty) != null) {
  362. ep.remove(packageProperty);
  363. needsSave = true;
  364. }
  365. if(ep1.getProperty(proxyProperty) != null) {
  366. ep1.remove(proxyProperty);
  367. needsSave1 = true;
  368. }
  369. if(needsSave) {
  370. helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
  371. }
  372. if(needsSave1) {
  373. helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep1);
  374. }
  375. /** Locate root of web service client node structure in project,xml
  376. */
  377. Element data = helper.getPrimaryConfigurationData(true);
  378. NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS);
  379. Element clientElements = null;
  380. /* If there is a root, get all the names of the child services and search
  381. * for the one we want to remove.
  382. */
  383. if(nodes.getLength() >= 1) {
  384. clientElements = (Element) nodes.item(0);
  385. NodeList clientNameList = clientElements.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME);
  386. for(int i = 0; i < clientNameList.getLength(); i++ ) {
  387. Element clientNameElement = (Element) clientNameList.item(i);
  388. NodeList nl = clientNameElement.getChildNodes();
  389. if(nl.getLength() == 1) {
  390. Node n = nl.item(0);
  391. if(n.getNodeType() == Node.TEXT_NODE) {
  392. if(serviceName.equalsIgnoreCase(n.getNodeValue())) {
  393. // Found it! Now remove it.
  394. Node serviceNode = clientNameElement.getParentNode();
  395. clientElements.removeChild(serviceNode);
  396. helper.putPrimaryConfigurationData(data, true);
  397. needsSave = true;
  398. }
  399. }
  400. }
  401. }
  402. }
  403. return needsSave || needsSave1;
  404. }
  405. });
  406. // !PW Lastly, save the project if we actually made any changes to any
  407. // properties or the build script.
  408. if(needToSave) {
  409. try {
  410. ProjectManager.getDefault().saveProject(project);
  411. } catch(IOException ex) {
  412. NotifyDescriptor desc = new NotifyDescriptor.Message(
  413. NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"MSG_ErrorSavingOnWSClientRemove", serviceName, ex.getMessage()), // NOI18N
  414. NotifyDescriptor.ERROR_MESSAGE);
  415. DialogDisplayer.getDefault().notify(desc);
  416. }
  417. }
  418. removeServiceRef(serviceName);
  419. }
  420. private void removeServiceRef(String serviceName) {
  421. FileObject ddFO = getDeploymentDescriptor();
  422. // If we get null for the deployment descriptor, ignore this step.
  423. if (ddFO != null) {
  424. String wsdlLocation = "META-INF/wsdl/"+serviceName+".wsdl"; //NOI18N;
  425. try {
  426. AppClient appClient = DDProvider.getDefault().getDDRoot(ddFO);
  427. ServiceRef serviceRef = null;
  428. for (ServiceRef ref:appClient.getServiceRef()) {
  429. URI wsdl = ref.getWsdlFile();
  430. if (wsdlLocation.equals(ref.getWsdlFile().getPath())) {
  431. serviceRef = ref;
  432. }
  433. }
  434. if (serviceRef != null) {
  435. appClient.removeServiceRef(serviceRef);
  436. appClient.write(ddFO);
  437. }
  438. } catch (IOException ex) {
  439. Logger.getLogger("global").log(Level.INFO, null, ex); //NOI18N;
  440. } catch (VersionNotSupportedException ex) {
  441. // for old versions of DD
  442. Logger.getLogger("global").log(Level.INFO, null, ex); //NOI18N;
  443. }
  444. }
  445. }
  446. public FileObject getWsdlFolder(boolean create) throws IOException {
  447. String metaInfStr = helper.getStandardPropertyEvaluator().getProperty(AppClientProjectProperties.META_INF);
  448. String wsdlFolderStr = metaInfStr + '/' + WSDL_FOLDER; // NOI18N
  449. FileObject wsdlFolder = project.getProjectDirectory().getFileObject(wsdlFolderStr);
  450. if (wsdlFolder == null && create) {
  451. wsdlFolder = FileUtil.createFolder(project.getProjectDirectory(), wsdlFolderStr);
  452. }
  453. return wsdlFolder;
  454. }
  455. public List<ClientStubDescriptor> getStubDescriptors() {
  456. ArrayList<ClientStubDescriptor> stubs = new ArrayList<ClientStubDescriptor>(2);
  457. Profile version = project.getCarModule().getJ2eeProfile();
  458. if (Profile.J2EE_14.equals(version)) {
  459. stubs.add(jsr109ClientStub);
  460. }
  461. stubs.add(jaxrpcClientStub);
  462. return stubs;
  463. }
  464. private boolean isProjectOpened() {
  465. Project[] projects = OpenProjects.getDefault().getOpenProjects();
  466. for (int i = 0; i < projects.length; i++) {
  467. if (projects[i].equals(project)) {
  468. return true;
  469. }
  470. }
  471. return false;
  472. }
  473. /** !PW This method is exposed in the client support API. Though it's
  474. * implementation makes more sense here than anywhere else, perhaps this
  475. * and the other project.xml/project.properties related methods in this
  476. * object should be refactored into another object that this one delegates
  477. * to. That way, this method would be directly available within the web
  478. * web module, as it is needed, and remain missing from the API (where it
  479. * probably does not belong at this time.
  480. */
  481. private static final String [] WSCOMPILE_CLIENT_FEATURES = {
  482. "datahandleronly", // - portable // NOI18N
  483. // "documentliteral", // SEI ONLY
  484. // "rpcliteral", // SEI ONLY
  485. "explicitcontext", // NOI18N
  486. // "infix:<name>", // difficult to implement.
  487. "jaxbenumtype", // NOI18N
  488. "nodatabinding", // - portable // NOI18N
  489. "noencodedtypes", // NOI18N
  490. "nomultirefs", // NOI18N
  491. "norpcstructures", // - portable // NOI18N
  492. "novalidation", // - portable // NOI18N
  493. "resolveidref", // NOI18N
  494. "searchschema", // - portable // NOI18N
  495. "serializeinterfaces", // NOI18N
  496. "strict", // - portable // NOI18N
  497. // "useonewayoperations", // SEI ONLY
  498. "wsi", // - portable // NOI18N
  499. "unwrap",// - portable // NOI18N
  500. "donotoverride", // - portable // NOI18N
  501. "donotunwrap", // - portable // NOI18N
  502. };
  503. private static final List allClientFeatures = Arrays.asList(WSCOMPILE_CLIENT_FEATURES);
  504. private static final String [] WSCOMPILE_KEY_CLIENT_FEATURES = {
  505. "wsi", // NOI18N
  506. "strict", // NOI18N
  507. "norpcstructures", // NOI18N
  508. "unwrap", // NOI18N
  509. "donotunwrap", // NOI18N
  510. "donotoverride", // NOI18N
  511. "datahandleronly", // NOI18N
  512. "nodatabinding", // NOI18N
  513. "novalidation", // NOI18N
  514. "searchschema", // NOI18N
  515. };
  516. private static final List importantClientFeatures = Arrays.asList(WSCOMPILE_KEY_CLIENT_FEATURES);
  517. public List<WsCompileClientEditorSupport.ServiceSettings> getServiceClients() {
  518. List<WsCompileClientEditorSupport.ServiceSettings> serviceNames = new ArrayList<WsCompileClientEditorSupport.ServiceSettings>();
  519. Element data = helper.getPrimaryConfigurationData(true);
  520. NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS);
  521. EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
  522. if(nodes.getLength() != 0) {
  523. Element clientElements = (Element) nodes.item(0);
  524. NodeList clientNameList = clientElements.getElementsByTagNameNS(
  525. AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME);
  526. for(int i = 0; i < clientNameList.getLength(); i++ ) {
  527. Element clientNameElement = (Element) clientNameList.item(i);
  528. NodeList nl = clientNameElement.getChildNodes();
  529. if(nl.getLength() == 1) {
  530. Node n = nl.item(0);
  531. if(n.getNodeType() == Node.TEXT_NODE) {
  532. String serviceName = n.getNodeValue();
  533. String currentFeatures = projectProperties.getProperty("wscompile.client." + serviceName + ".features");
  534. if(currentFeatures == null) {
  535. // !PW should probably retrieve default features for stub type.
  536. // For now, this will work because this is the same value we'd get doing that.
  537. //
  538. // Defaults if we can't find any feature property for this client
  539. // Mostly for upgrading EA1, EA2 projects which did not have
  540. // this property, but also useful if the user deletes it from
  541. // project.properties.
  542. currentFeatures = "wsi, strict"; // NOI18N
  543. }
  544. boolean propVerbose = "true".equalsIgnoreCase( //NOI18N
  545. projectProperties.getProperty("wscompile.client." + serviceName + ".verbose")); //NOI18N
  546. boolean propDebug = "true".equalsIgnoreCase( //NOI18N
  547. projectProperties.getProperty("wscompile.client." + serviceName + ".debug")); //NOI18N
  548. boolean propPrintStackTrace = "true".equalsIgnoreCase( //NOI18N
  549. projectProperties.getProperty("wscompile.client." + serviceName + ".xPrintStackTrace")); //NOI18N
  550. boolean propExtensible = "true".equalsIgnoreCase( //NOI18N
  551. projectProperties.getProperty("wscompile.client." + serviceName + ".xSerializable")); //NOI18N
  552. boolean propOptimize = "true".equalsIgnoreCase( //NOI18N
  553. projectProperties.getProperty("wscompile.client." + serviceName + ".optimize")); //NOI18N
  554. boolean[] options = new boolean[] { //NOI18N
  555. propVerbose,propDebug,propPrintStackTrace,propExtensible,propOptimize
  556. };
  557. ClientStubDescriptor stubType = getClientStubDescriptor(clientNameElement.getParentNode());
  558. WsCompileClientEditorSupport.ServiceSettings settings = new WsCompileClientEditorSupport.ServiceSettings(
  559. serviceName, stubType, options, currentFeatures, allClientFeatures, importantClientFeatures);
  560. serviceNames.add(settings);
  561. } else {
  562. // !PW FIXME node is wrong type?! - log message or trace?
  563. }
  564. } else {
  565. // !PW FIXME no name for this service entry - notify user
  566. }
  567. }
  568. }
  569. return serviceNames;
  570. }
  571. private ClientStubDescriptor getClientStubDescriptor(Node parentNode) {
  572. ClientStubDescriptor result = null;
  573. if(parentNode instanceof Element) {
  574. Element parentElement = (Element) parentNode;
  575. NodeList clientNameList = parentElement.getElementsByTagNameNS(
  576. AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_STUB_TYPE);
  577. if(clientNameList.getLength() == 1) {
  578. Element clientStubElement = (Element) clientNameList.item(0);
  579. NodeList nl = clientStubElement.getChildNodes();
  580. if(nl.getLength() == 1) {
  581. Node n = nl.item(0);
  582. if(n.getNodeType() == Node.TEXT_NODE) {
  583. String stubName = n.getNodeValue();
  584. if(ClientStubDescriptor.JSR109_CLIENT_STUB.equals(stubName)) {
  585. result = jsr109ClientStub;
  586. } else if(ClientStubDescriptor.JAXRPC_CLIENT_STUB.equals(stubName)) {
  587. result = jaxrpcClientStub;
  588. }
  589. }
  590. }
  591. }
  592. }
  593. return result;
  594. }
  595. public String getWsdlSource(String serviceName) {
  596. Element data = helper.getPrimaryConfigurationData(true);
  597. String wsdlSource = null;
  598. Element clientElement = getWebServiceClientNode(data, serviceName);
  599. if(clientElement != null) {
  600. NodeList fromWsdlList = clientElement.getElementsByTagNameNS(
  601. AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL);
  602. if(fromWsdlList.getLength() == 1) {
  603. Element fromWsdlElement = (Element) fromWsdlList.item(0);
  604. NodeList nl = fromWsdlElement.getChildNodes();
  605. if(nl.getLength() == 1) {
  606. Node n = nl.item(0);
  607. if(n.getNodeType() == Node.TEXT_NODE) {
  608. wsdlSource = n.getNodeValue();
  609. }
  610. }
  611. }
  612. }
  613. return wsdlSource;
  614. }
  615. public void setWsdlSource(String serviceName, String wsdlSource) {
  616. Element data = helper.getPrimaryConfigurationData(true);
  617. Document doc = data.getOwnerDocument();
  618. boolean needsSave = false;
  619. Element clientElement = getWebServiceClientNode(data, serviceName);
  620. if(clientElement != null) {
  621. NodeList fromWsdlList = clientElement.getElementsByTagNameNS(
  622. AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL);
  623. if(fromWsdlList.getLength() > 0) {
  624. Element fromWsdlElement = (Element) fromWsdlList.item(0);
  625. NodeList nl = fromWsdlElement.getChildNodes();
  626. if(nl.getLength() > 0) {
  627. Node n = nl.item(0);
  628. n.setNodeValue(wsdlSource);
  629. } else {
  630. fromWsdlElement.appendChild(doc.createTextNode(wsdlSource));
  631. }
  632. } else {
  633. Element clientElementSourceUrl = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL);
  634. clientElement.appendChild(clientElementSourceUrl);
  635. clientElementSourceUrl.appendChild(doc.createTextNode(wsdlSource));
  636. }
  637. needsSave = true;
  638. }
  639. // !PW Save the project if we were able to make the change.
  640. if(needsSave) {
  641. try {
  642. ProjectManager.getDefault().saveProject(project);
  643. } catch(IOException ex) {
  644. NotifyDescriptor desc = new NotifyDescriptor.Message(
  645. NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"MSG_ErrorSavingOnWSClientAdd", serviceName, ex.getMessage()), // NOI18N
  646. NotifyDescriptor.ERROR_MESSAGE);
  647. DialogDisplayer.getDefault().notify(desc);
  648. }
  649. }
  650. }
  651. private Element getWebServiceClientNode(Element data, String serviceName) {
  652. Element clientElement = null;
  653. NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS);
  654. if(nodes.getLength() != 0) {
  655. Element clientElements = (Element) nodes.item(0);
  656. NodeList clientNameList = clientElements.getElementsByTagNameNS(
  657. AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME);
  658. for(int i = 0; i < clientNameList.getLength(); i++ ) {
  659. Element clientNameElement = (Element) clientNameList.item(i);
  660. NodeList nl = clientNameElement.getChildNodes();
  661. if(nl.getLength() == 1) {
  662. Node n = nl.item(0);
  663. if(n.getNodeType() == Node.TEXT_NODE) {
  664. String name = n.getNodeValue();
  665. if(serviceName.equals(name)) {
  666. Node node = clientNameElement.getParentNode();
  667. clientElement = (node instanceof Element) ? (Element) node : null;
  668. break;
  669. }
  670. } else {
  671. // !PW FIXME node is wrong type?! - log message or trace?
  672. }
  673. }
  674. }
  675. }
  676. return clientElement;
  677. }
  678. // Client stub descriptors
  679. private static final JAXRPCClientStubDescriptor jsr109ClientStub = new JAXRPCClientStubDescriptor(
  680. ClientStubDescriptor.JSR109_CLIENT_STUB,
  681. NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"LBL_JSR109ClientStub"),
  682. new String [] { "wsi", "strict" }); // NOI18N
  683. private static final JAXRPCClientStubDescriptor jaxrpcClientStub = new JAXRPCClientStubDescriptor(
  684. ClientStubDescriptor.JAXRPC_CLIENT_STUB,
  685. NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"LBL_JAXRPCStaticClientStub"),
  686. new String [] { "wsi", "strict" }); // NOI18N
  687. public void addServiceClientReference(String serviceName, String fqServiceName, String relativeWsdlPath, String relativeMappingPath, String[] portSEIInfo) {
  688. FileObject ddFO = getDeploymentDescriptor();
  689. // If we get null for the deployment descriptor, ignore this step.
  690. if (ddFO != null) {
  691. try {
  692. RootInterface rootDD = DDProvider.getDefault().getDDRoot(ddFO);
  693. ServiceRef serviceRef = (ServiceRef) rootDD.findBeanByName("ServiceRef", "ServiceRefName", serviceName); // NOI18N
  694. if(serviceRef == null) {
  695. serviceRef = (ServiceRef) rootDD.addBean("ServiceRef", // NOI18N
  696. new String [] { /* property list */
  697. "ServiceRefName", // NOI18N
  698. "ServiceInterface", // NOI18N
  699. "WsdlFile", // NOI18N
  700. "JaxrpcMappingFile" // NOI18N
  701. },
  702. new String [] { /* property values */
  703. // service name
  704. serviceName,
  705. // interface package . service name
  706. fqServiceName,
  707. // web doc base / wsdl folder / wsdl file name
  708. relativeWsdlPath,
  709. // web doc base / mapping file name
  710. relativeMappingPath
  711. },
  712. "ServiceRefName"); // NOI18N
  713. } else {
  714. serviceRef.setServiceInterface(fqServiceName);
  715. serviceRef.setWsdlFile(new URI(relativeWsdlPath));
  716. serviceRef.setJaxrpcMappingFile(relativeMappingPath);
  717. }
  718. PortComponentRef [] portRefArray = new PortComponentRef [portSEIInfo.length];
  719. for (int pi = 0; pi < portRefArray.length; pi++) {
  720. portRefArray[pi] = (PortComponentRef) serviceRef.createBean("PortComponentRef"); // NOI18N
  721. portRefArray[pi].setServiceEndpointInterface(portSEIInfo[pi]); // NOI18N
  722. }
  723. serviceRef.setPortComponentRef(portRefArray);
  724. rootDD.write(ddFO);
  725. } catch (IOException ex) {
  726. // Strange thing happen
  727. Logger.getLogger("global").log(Level.INFO, null, ex);
  728. } catch (NameAlreadyUsedException ex) {
  729. // Should never happen because we look for it by name first.
  730. Logger.getLogger("global").log(Level.INFO, null, ex);
  731. } catch (URISyntaxException ex) {
  732. // Programmer error - validation of input data should ensure this never happens.
  733. Logger.getLogger("global").log(Level.INFO, null, ex);
  734. } catch (ClassNotFoundException ex) {
  735. // Programmer error - mistyped object name.
  736. Logger.getLogger("global").log(Level.INFO, null, ex);
  737. }
  738. }
  739. }
  740. /** Stub descriptor for services and clients supported by this project type.
  741. */
  742. private static class JAXRPCClientStubDescriptor extends ClientStubDescriptor {
  743. private String [] defaultFeatures;
  744. public JAXRPCClientStubDescriptor(String name, String displayName, String [] defaultFeatures) {
  745. super(name, displayName);
  746. this.defaultFeatures = defaultFeatures;
  747. }
  748. public String [] getDefaultFeatures() {
  749. return defaultFeatures;
  750. }
  751. public String getDefaultFeaturesAsArgument() {
  752. StringBuffer buf = new StringBuffer(defaultFeatures.length*32);
  753. for(int i = 0; i < defaultFeatures.length; i++) {
  754. if(i > 0) {
  755. buf.append(','); // NOI18N
  756. }
  757. buf.append(defaultFeatures[i]);
  758. }
  759. return buf.toString();
  760. }
  761. void setDefaultFeatures(String[] defaultFeatures) {
  762. this.defaultFeatures=defaultFeatures;
  763. }
  764. }
  765. public void setProxyJVMOptions(String proxyHost, String proxyPort) {
  766. this.proxyHost=proxyHost;
  767. this.proxyPort=proxyPort;
  768. }
  769. private static final String PROXY_HOST_OPTION="-Dhttp.proxyHost"; //NOI18N
  770. private static final String PROXY_PORT_OPTION="-Dhttp.proxyPort"; //NOI18N
  771. private static final String NON_PROXY_HOSTS_OPTION="-Dhttp.nonProxyHosts"; //NOI18N
  772. private boolean addJVMProxyOptions(EditableProperties prop, String proxyHost, String proxyPort) {
  773. String jvmOptions = prop.getProperty(AppClientProjectProperties.RUN_JVM_ARGS);
  774. boolean modif=false;
  775. String localHosts = "localhost"; //NOI18N
  776. try {
  777. localHosts = InetAddress.getLocalHost().getCanonicalHostName();
  778. } catch (UnknownHostException ex) {}
  779. if (!"localhost".equals(localHosts)) {
  780. localHosts='\"'+localHosts+"|localhost\""; //NOI18N
  781. }
  782. if (jvmOptions==null || jvmOptions.length()==0) {
  783. jvmOptions = PROXY_HOST_OPTION+'='+proxyHost+
  784. ' '+PROXY_PORT_OPTION+'='+proxyPort+
  785. ' '+NON_PROXY_HOSTS_OPTION+'='+localHosts;
  786. modif=true;
  787. } else {
  788. if (jvmOptions.indexOf(PROXY_HOST_OPTION)<0) {
  789. jvmOptions+=' '+PROXY_HOST_OPTION+'='+proxyHost;
  790. modif=true;
  791. }
  792. if (jvmOptions.indexOf(PROXY_PORT_OPTION)<0) {
  793. jvmOptions+=' '+PROXY_PORT_OPTION+'='+proxyPort;
  794. modif=true;
  795. }
  796. if (jvmOptions.indexOf(NON_PROXY_HOSTS_OPTION)<0) {
  797. jvmOptions+=' '+NON_PROXY_HOSTS_OPTION+'='+localHosts;
  798. modif=true;
  799. }
  800. }
  801. if (modif) {
  802. prop.setProperty(AppClientProjectProperties.RUN_JVM_ARGS,jvmOptions);
  803. }
  804. return modif;
  805. }
  806. public String getServiceRefName(String serviceName) {
  807. //noop
  808. return null;
  809. }
  810. }