PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/projects/jtopen-7.8/src/com/ibm/as400/resource/RJavaProgram.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 1012 lines | 392 code | 181 blank | 439 comment | 36 complexity | fc1ffe9228211678c94ff4dfb7f21776 MD5 | raw file
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // JTOpen (IBM Toolbox for Java - OSS version)
  4. //
  5. // Filename: RJavaProgram.java
  6. //
  7. // The source code contained herein is licensed under the IBM Public License
  8. // Version 1.0, which has been approved by the Open Source Initiative.
  9. // Copyright (C) 1997-2004 International Business Machines Corporation and
  10. // others. All rights reserved.
  11. //
  12. ///////////////////////////////////////////////////////////////////////////////
  13. package com.ibm.as400.resource;
  14. import com.ibm.as400.access.AS400;
  15. import com.ibm.as400.access.ExtendedIllegalStateException;
  16. import com.ibm.as400.access.CommandCall;
  17. import com.ibm.as400.access.IFSFile;
  18. import com.ibm.as400.access.Trace;
  19. import com.ibm.as400.data.PcmlException;
  20. import com.ibm.as400.data.ProgramCallDocument;
  21. import java.beans.PropertyVetoException;
  22. import java.util.Date;
  23. /**
  24. Represents a Java program on the system. This is supported
  25. only when connecting to systems running OS/400 V5R1, and is not supported beyond IBM i 7.1.
  26. <p>
  27. In the context of this discussion, a "Java program" is the IBM i executable object that is created when the CRTJVAPGM (Create Java Program) CL command is run against a class, JAR, or ZIP file.
  28. <a name="attributeIDs"><p>The following attribute IDs are supported:
  29. <ul>
  30. <li>{@link #CLASSES_WITHOUT_CURRENT_JAVA_PROGRAMS CLASSES_WITHOUT_CURRENT_JAVA_PROGRAMS}
  31. <li>{@link #CLASSES_WITH_CURRENT_JAVA_PROGRAMS CLASSES_WITH_CURRENT_JAVA_PROGRAMS}
  32. <li>{@link #CLASSES_WITH_ERRORS CLASSES_WITH_ERRORS}
  33. <li>{@link #ENABLE_PERFORMANCE_COLLECTION ENABLE_PERFORMANCE_COLLECTION}
  34. <li>{@link #FILE_CHANGE FILE_CHANGE}
  35. <li>{@link #JAVA_PROGRAMS JAVA_PROGRAMS}
  36. <li>{@link #JAVA_PROGRAM_CREATION JAVA_PROGRAM_CREATION}
  37. <li>{@link #JAVA_PROGRAM_SIZE JAVA_PROGRAM_SIZE}
  38. <li>{@link #LICENSED_INTERNAL_CODE_OPTIONS LICENSED_INTERNAL_CODE_OPTIONS}
  39. <li>{@link #OPTIMIZATION OPTIMIZATION}
  40. <li>{@link #OWNER OWNER}
  41. <li>{@link #PROFILING_DATA PROFILING_DATA}
  42. <li>{@link #RELEASE_PROGRAM_CREATED_FOR RELEASE_PROGRAM_CREATED_FOR}
  43. <li>{@link #TOTAL_CLASSES_IN_SOURCE TOTAL_CLASSES_IN_SOURCE}
  44. <li>{@link #USE_ADOPTED_AUTHORITY USE_ADOPTED_AUTHORITY}
  45. <li>{@link #USER_PROFILE USER_PROFILE}
  46. </ul>
  47. </a>
  48. <p>Use any of these attribute IDs with
  49. {@link com.ibm.as400.resource.ChangeableResource#getAttributeValue getAttributeValue()}
  50. and {@link com.ibm.as400.resource.ChangeableResource#setAttributeValue setAttributeValue()}
  51. to access the attribute values for an RJavaProgram.
  52. <blockquote><pre>
  53. // Create an RJavaProgram object to refer to a specific Java program.
  54. AS400 system = new AS400("MYSYSTEM", "MYUSERID", "MYPASSWORD");
  55. RJavaProgram javaProgram = new RJavaProgram(system, "/home/mydir/HelloWorld.class");
  56. <br>
  57. // Get the optimization.
  58. Integer optimization = (Integer)javaProgram.getAttributeValue(RJavaProgram.OPTIMIZATION);
  59. <br>
  60. // Set the enable peformance collection attribute value to full.
  61. javaProgram.setAttributeValue(RJavaProgram.ENABLE_PERFORMANCE_COLLECTION, RJavaProgram.ENABLE_PERFORMANCE_COLLECTION_FULL);
  62. <br>
  63. // Commit the attribute change.
  64. javaProgram.commitAttributeChanges();
  65. </pre></blockquote>
  66. @deprecated Use
  67. {@link com.ibm.as400.access.JavaProgram JavaProgram} instead, as this package may be removed in the future.
  68. **/
  69. public class RJavaProgram
  70. extends ChangeableResource
  71. {
  72. static final long serialVersionUID = 4L;
  73. //-----------------------------------------------------------------------------------------
  74. // Presentation.
  75. //-----------------------------------------------------------------------------------------
  76. private static PresentationLoader presentationLoader_ = new PresentationLoader("com.ibm.as400.resource.ResourceMRI");
  77. private static final String ICON_BASE_NAME_ = "RJavaProgram";
  78. private static final String PRESENTATION_KEY_ = "JAVA_PROGRAM";
  79. //-----------------------------------------------------------------------------------------
  80. // Attribute values.
  81. //-----------------------------------------------------------------------------------------
  82. /**
  83. Attribute value for yes.
  84. **/
  85. public static final String YES = "*YES";
  86. /**
  87. Attribute value for no.
  88. **/
  89. public static final String NO = "*NO";
  90. //-----------------------------------------------------------------------------------------
  91. // Attribute IDs.
  92. //
  93. // * If you add an attribute here, make sure and add it to the class javadoc.
  94. //-----------------------------------------------------------------------------------------
  95. // Private data.
  96. static ResourceMetaDataTable attributes_ = new ResourceMetaDataTable(presentationLoader_, PRESENTATION_KEY_);
  97. private static ProgramMap getterMap_ = new ProgramMap();
  98. private static CommandMap setterMap_ = new CommandMap();
  99. private static final String CRTJVAPGM_ = "CRTJVAPGM";
  100. private static final String CHGJVAPGM_ = "CHGJVAPGM";
  101. private static final String PATH_PARAMETER_ = "CLSF";
  102. private static final String QJVAMAT_ = "qjvamat";
  103. /**
  104. Attribute ID for total classes in source. This identifies a read-only
  105. Integer attribute, which represents the total number of classes located
  106. within the ZIP or JAR file.
  107. **/
  108. public static final String TOTAL_CLASSES_IN_SOURCE = "TOTAL_CLASSES_IN_SOURCE"; // @B1A
  109. static {
  110. try {
  111. attributes_.add(TOTAL_CLASSES_IN_SOURCE, Integer.class, true);
  112. getterMap_.add(TOTAL_CLASSES_IN_SOURCE, QJVAMAT_, "receiverVariable.numberOfTotalClassesInSource");
  113. }
  114. catch (Exception found) { found.printStackTrace(); }
  115. }
  116. /**
  117. Attribute ID for classes with errors. This identifies a read-only
  118. Integer attribute, which represents the number of classes in the
  119. file that contain errors.
  120. **/
  121. public static final String CLASSES_WITH_ERRORS = "CLASSES_WITH_ERRORS"; // @B1A
  122. static {
  123. try {
  124. attributes_.add(CLASSES_WITH_ERRORS, Integer.class, true);
  125. getterMap_.add(CLASSES_WITH_ERRORS, QJVAMAT_, "receiverVariable.numberOfClassesWithErrors");
  126. }
  127. catch (Exception found) { found.printStackTrace(); }
  128. }
  129. /**
  130. Attribute ID for classes with current Java programs. This identifies
  131. a read-only Integer attribute, which represents the number of classes
  132. in the file which have current Java programs.
  133. **/
  134. public static final String CLASSES_WITH_CURRENT_JAVA_PROGRAMS = "CLASSES_WITH_CURRENT_JAVA_PROGRAMS";
  135. static {
  136. attributes_.add(CLASSES_WITH_CURRENT_JAVA_PROGRAMS, Integer.class, true);
  137. getterMap_.add(CLASSES_WITH_CURRENT_JAVA_PROGRAMS, QJVAMAT_, "receiverVariable.numberOfClassesWithCurrentJavaPrograms");
  138. }
  139. /**
  140. Attribute ID for classes without current Java programs. This identifies
  141. a read-only Integer attribute, which represents the number of classes
  142. in the file which do not have current Java programs.
  143. **/
  144. public static final String CLASSES_WITHOUT_CURRENT_JAVA_PROGRAMS = "CLASSES_WITHOUT_CURRENT_JAVA_PROGRAMS";
  145. static {
  146. attributes_.add(CLASSES_WITHOUT_CURRENT_JAVA_PROGRAMS, Integer.class, true);
  147. getterMap_.add(CLASSES_WITHOUT_CURRENT_JAVA_PROGRAMS, QJVAMAT_, "receiverVariable.numberOfClassesWithoutCurrentJavaPrograms");
  148. }
  149. /**
  150. Attribute ID for enable performance collection. This identifies a
  151. String attribute, which represents the level of performance data
  152. collection allowed for this Java program. Possible
  153. values are:
  154. <ul>
  155. <li>{@link #ENABLE_PERFORMANCE_COLLECTION_NONE ENABLE_PERFORMANCE_COLLECTION_NONE}
  156. - No performance collection is enabled for this Java program.
  157. <li>{@link #ENABLE_PERFORMANCE_COLLECTION_ENTRY_EXIT ENABLE_PERFORMANCE_COLLECTION_ENTRY_EXIT}
  158. - This gives the entry/exit information on all the procedures of the Java
  159. program (including those that are leaf procedures). This includes the
  160. PEP routine. This is useful in capturing information on all procedures.
  161. <li>{@link #ENABLE_PERFORMANCE_COLLECTION_FULL ENABLE_PERFORMANCE_COLLECTION_FULL}
  162. - This gives the entry/exit information on all procedures of the Java
  163. program (including those that are leaf procedures) and precall and postcall
  164. hooks around calls to other procedures. This is useful in capturing
  165. information on all procedures.
  166. </ul>
  167. **/
  168. public static final String ENABLE_PERFORMANCE_COLLECTION = "ENABLE_PERFORMANCE_COLLECTION";
  169. /**
  170. Attribute value indicating that no performance collection is enabled for this Java program.
  171. @see #ENABLE_PERFORMANCE_COLLECTION
  172. **/
  173. public static final String ENABLE_PERFORMANCE_COLLECTION_NONE = "*NONE";
  174. /**
  175. Attribute value indicating that the entry/exit information on all the procedures of the Java
  176. program (including those that are leaf procedures) is given. This includes the
  177. PEP routine. This is useful in capturing information on all procedures.
  178. @see #ENABLE_PERFORMANCE_COLLECTION
  179. **/
  180. public static final String ENABLE_PERFORMANCE_COLLECTION_ENTRY_EXIT = "*ENTRYEXIT";
  181. /**
  182. Attribute value indicating that the entry/exit information on all procedures of the Java
  183. program (including those that are leaf procedures) and precall and postcall
  184. hooks around calls to other procedures is given. This is useful in capturing
  185. information on all procedures.
  186. @see #ENABLE_PERFORMANCE_COLLECTION
  187. **/
  188. public static final String ENABLE_PERFORMANCE_COLLECTION_FULL = "*FULL";
  189. static {
  190. attributes_.add(ENABLE_PERFORMANCE_COLLECTION, String.class, false,
  191. new Object[] {ENABLE_PERFORMANCE_COLLECTION_NONE,
  192. ENABLE_PERFORMANCE_COLLECTION_ENTRY_EXIT,
  193. ENABLE_PERFORMANCE_COLLECTION_FULL }, null, true);
  194. getterMap_.add(ENABLE_PERFORMANCE_COLLECTION, QJVAMAT_, "receiverVariable.performanceCollectionEnabledFlag",
  195. new EnablePerformanceCollectionValueMap_());
  196. setterMap_.add(ENABLE_PERFORMANCE_COLLECTION, CHGJVAPGM_, "ENBPFRCOL");
  197. }
  198. private static class EnablePerformanceCollectionValueMap_ extends AbstractValueMap
  199. {
  200. public Object ptol(Object physicalValue)
  201. {
  202. if (physicalValue.equals("11"))
  203. return ENABLE_PERFORMANCE_COLLECTION_FULL;
  204. else if (physicalValue.equals("10"))
  205. return ENABLE_PERFORMANCE_COLLECTION_ENTRY_EXIT;
  206. else
  207. return ENABLE_PERFORMANCE_COLLECTION_NONE;
  208. }
  209. }
  210. /**
  211. Attribute ID for profiling data. This identifies a
  212. String attribute, which indicates if the Java program is
  213. collecting profiling data. Possible values are:
  214. <ul>
  215. <li>{@link #PROFILING_DATA_NOCOLLECTION PROFILING_DATA_NOCOLLECTION}
  216. - No profiling data collection is enabled for this Java program.
  217. <li>{@link #PROFILING_DATA_COLLECTION PROFILING_DATA_COLLECTION}
  218. - Profiling data collection is enabled for this Java program. This
  219. enablement can only occur if the optimization of the Java program is
  220. 30 or higher. Also, collection does not occur until the profiling
  221. data is applied.
  222. <li>{@link #PROFILING_DATA_APPLY PROFILING_DATA_APPLY}
  223. - Profiling data collection is applied for this Java program.
  224. <li>{@link #PROFILING_DATA_CLEAR PROFILING_DATA_CLEAR}
  225. - All profiling data that has been collected for this Java program is to
  226. be cleared.
  227. </ul>
  228. **/
  229. public static final String PROFILING_DATA = "PROFILING_DATA"; // @B1A
  230. /**
  231. Attribute value indicating that no profiling data collection is enabled for this Java program.
  232. @see #PROFILING_DATA
  233. **/
  234. public static final String PROFILING_DATA_NOCOLLECTION = "*NOCOL"; // @B1A
  235. /**
  236. Attribute value indicating that profiling data collection is enabled for this Java program.
  237. This enablement can only occur if the optimization of the Java program is 30 or higher.
  238. Also, collection does not occur until the profiling data is applied.
  239. @see #PROFILING_DATA
  240. **/
  241. public static final String PROFILING_DATA_COLLECTION = "*COL"; // @B1A
  242. /**
  243. Attribute value indicating that profiling data collection is applied for this Java program.
  244. @see #PROFILING_DATA
  245. **/
  246. public static final String PROFILING_DATA_APPLY = "*APY"; // @B1A
  247. /**
  248. Attribute value indicating that all profiling data that has been collected
  249. for this Java program is to be cleared.
  250. @see #PROFILING_DATA
  251. **/
  252. public static final String PROFILING_DATA_CLEAR = "*CLR"; // @B1A
  253. static { // @B1A
  254. attributes_.add(PROFILING_DATA, String.class, false,
  255. new Object[] {PROFILING_DATA_NOCOLLECTION,
  256. PROFILING_DATA_COLLECTION,
  257. PROFILING_DATA_CLEAR,
  258. PROFILING_DATA_APPLY }, null, true);
  259. getterMap_.add(PROFILING_DATA, QJVAMAT_, "receiverVariable.profilingDataStatus",
  260. new ProfilingDataValueMap_());
  261. setterMap_.add(PROFILING_DATA, CHGJVAPGM_, "PRFDTA");
  262. }
  263. private static class ProfilingDataValueMap_ extends AbstractValueMap // @B1A
  264. {
  265. public Object ptol(Object physicalValue)
  266. {
  267. if (physicalValue.equals("2"))
  268. return PROFILING_DATA_APPLY;
  269. else if (physicalValue.equals("1"))
  270. return PROFILING_DATA_COLLECTION;
  271. else
  272. return PROFILING_DATA_NOCOLLECTION;
  273. }
  274. }
  275. /**
  276. Attribute ID for file change. This identifies a read-only
  277. Date attribute, which represents the date and time when the file
  278. was last changed. The Date value is converted using the default Java locale.
  279. **/
  280. public static final String FILE_CHANGE = "FILE_CHANGE";
  281. static {
  282. attributes_.add(FILE_CHANGE, Date.class, true);
  283. getterMap_.add(FILE_CHANGE, QJVAMAT_, "receiverVariable.fileChangeModifyDateAndTime", new DateValueMap(DateValueMap.FORMAT_13));
  284. }
  285. /**
  286. Attribute ID for Java programs. This identifies a read-only
  287. Integer attribute, which represents the number of Java
  288. programs associated with the file.
  289. **/
  290. public static final String JAVA_PROGRAMS = "JAVA_PROGRAMS";
  291. static {
  292. attributes_.add(JAVA_PROGRAMS, Integer.class, true);
  293. getterMap_.add(JAVA_PROGRAMS, QJVAMAT_, "receiverVariable.numberOfJavaProgramsAttached");
  294. }
  295. /**
  296. Attribute ID for Java program creation. This identifies a read-only
  297. Date attribute, which represents the date and time when the Java
  298. program was created. If this is a zip or jar file, this is the
  299. date and time when the first Java program was attached to the file.
  300. If this is class file, this is the date and time when the Java
  301. program was created. The Date value is converted using the default Java locale.
  302. **/
  303. public static final String JAVA_PROGRAM_CREATION = "JAVA_PROGRAM_CREATION";
  304. static {
  305. attributes_.add(JAVA_PROGRAM_CREATION, Date.class, true);
  306. getterMap_.add(JAVA_PROGRAM_CREATION, QJVAMAT_, "receiverVariable.javaProgramCreationDateAndTime", new DateValueMap(DateValueMap.FORMAT_13));
  307. }
  308. /**
  309. Attribute ID for Java program size. This identifies
  310. a read-only Long attribute, which represents the size, in kilobytes,
  311. of the Java programs that are attached to the file.
  312. **/
  313. public static final String JAVA_PROGRAM_SIZE = "JAVA_PROGRAM_SIZE";
  314. static {
  315. attributes_.add(JAVA_PROGRAM_SIZE, Long.class, true);
  316. getterMap_.add(JAVA_PROGRAM_SIZE, QJVAMAT_, "receiverVariable.sizeOfJavaProgramsAttached", new JavaProgramSizeValueMap_());
  317. }
  318. private static class JavaProgramSizeValueMap_ extends AbstractValueMap
  319. {
  320. public Object ptol(Object physicalValue)
  321. {
  322. if (physicalValue instanceof Integer)
  323. return new Long((long)((Integer)physicalValue).intValue());
  324. else
  325. return physicalValue;
  326. }
  327. }
  328. /**
  329. Attribute ID for licensed internal code options. This identifies
  330. a String attribute, which represents the selected licensed
  331. internal code (LIC) compile-time options that are used when
  332. the Java program was created.
  333. **/
  334. public static final String LICENSED_INTERNAL_CODE_OPTIONS = "LICENSED_INTERNAL_CODE_OPTIONS";
  335. static {
  336. attributes_.add(LICENSED_INTERNAL_CODE_OPTIONS, String.class, false);
  337. getterMap_.add(LICENSED_INTERNAL_CODE_OPTIONS, QJVAMAT_, "receiverVariable.LICOptions");
  338. setterMap_.add(LICENSED_INTERNAL_CODE_OPTIONS, CHGJVAPGM_, "LICOPT", new QuoteValueMap());
  339. }
  340. /**
  341. Attribute ID for optimization. This identifies an Integer attribute,
  342. which represents the optimization level of the Java program. Possible
  343. values are:
  344. <ul>
  345. <li>{@link #OPTIMIZATION_INTERPRET OPTIMIZATION_INTERPRET}
  346. - The Java program is not optimized. When invoked, the Java program
  347. interprets the class file byte codes. Variables can be displayed and
  348. modified while debugging.
  349. <li>{@link #OPTIMIZATION_10 OPTIMIZATION_10}
  350. - The Java program contains a compiled version of the class file byte codes
  351. but has only minimal additional compiler optimization. Variables can be
  352. displayed and modified while debugging.
  353. <li>{@link #OPTIMIZATION_20 OPTIMIZATION_20}
  354. - The Java program contains a compiled version of the class file byte codes
  355. and has some additional compiler optimization. Variables can be displayed
  356. but not modified while debugging.
  357. <li>{@link #OPTIMIZATION_30 OPTIMIZATION_30}
  358. - The Java program contains a compiled version of the class file byte codes
  359. and has more compiler optimization than optimization level 20. During a
  360. debug session, user variables cannot be changed, but can be displayed.
  361. The presented values may not be the current values of the variables.
  362. <li>{@link #OPTIMIZATION_40 OPTIMIZATION_40}
  363. - The Java program contains a compiled version of the class file byte codes
  364. and has more compiler optimization than optimization level 30. All call and
  365. instruction tracing is disabled.
  366. </ul>
  367. **/
  368. public static final String OPTIMIZATION = "OPTIMIZATION";
  369. /**
  370. Attribute value indicating that the Java program is not optimized. When invoked,
  371. the Java program interprets the class file byte codes. Variables can be displayed and
  372. modified while debugging.
  373. @see #OPTIMIZATION
  374. **/
  375. public static final Integer OPTIMIZATION_INTERPRET = new Integer(-1);
  376. private static final String OPTIMIZATION_INTERPRET_PHYSICAL = "*INTERPRET";
  377. /**
  378. Attribute value indicating that the Java program contains a compiled version
  379. of the class file byte codes but has only minimal additional compiler optimization.
  380. Variables can be displayed and modified while debugging.
  381. @see #OPTIMIZATION
  382. **/
  383. public static final Integer OPTIMIZATION_10 = new Integer(10);
  384. /**
  385. Attribute value indicating that the Java program contains a compiled version
  386. of the class file byte codes and has some additional compiler optimization.
  387. Variables can be displayed but not modified while debugging.
  388. @see #OPTIMIZATION
  389. **/
  390. public static final Integer OPTIMIZATION_20 = new Integer(20);
  391. /**
  392. Attribute value indicating that the Java program contains a compiled version
  393. of the class file byte codes and has more compiler optimization than optimization
  394. level 20. During a debug session, user variables cannot be changed, but can be
  395. displayed. The presented values may not be the current values of the variables.
  396. @see #OPTIMIZATION
  397. **/
  398. public static final Integer OPTIMIZATION_30 = new Integer(30);
  399. /**
  400. Attribute value indicating that the Java program contains a compiled version
  401. of the class file byte codes and has more compiler optimization than optimization
  402. level 30. All call and instruction tracing is disabled.
  403. @see #OPTIMIZATION
  404. **/
  405. public static final Integer OPTIMIZATION_40 = new Integer(40);
  406. static {
  407. attributes_.add(OPTIMIZATION, Integer.class, false,
  408. new Object[] {OPTIMIZATION_INTERPRET,
  409. OPTIMIZATION_10,
  410. OPTIMIZATION_20,
  411. OPTIMIZATION_30,
  412. OPTIMIZATION_40 }, null, true);
  413. OptimizationValueMap_ valueMap = new OptimizationValueMap_();
  414. getterMap_.add(OPTIMIZATION, QJVAMAT_, "receiverVariable.optimizationLevel", valueMap);
  415. setterMap_.add(OPTIMIZATION, CHGJVAPGM_, "OPTIMIZE", valueMap);
  416. }
  417. private static class OptimizationValueMap_ extends AbstractValueMap
  418. {
  419. public Object ptol(Object physicalValue)
  420. {
  421. if (((Integer)physicalValue).intValue() == 0)
  422. return OPTIMIZATION_INTERPRET;
  423. else
  424. return physicalValue;
  425. }
  426. public Object ltop(Object logicalValue)
  427. {
  428. if (logicalValue.equals(OPTIMIZATION_INTERPRET))
  429. return OPTIMIZATION_INTERPRET_PHYSICAL;
  430. else
  431. return logicalValue.toString();
  432. }
  433. }
  434. /**
  435. Attribute ID for owner. This identifies a read-only
  436. String attribute, which represents the owner of the
  437. Java program.
  438. **/
  439. public static final String OWNER = "OWNER";
  440. static {
  441. attributes_.add(OWNER, String.class, true);
  442. getterMap_.add(OWNER, QJVAMAT_, "receiverVariable.fileOwnerName");
  443. }
  444. /**
  445. Attribute ID for release program created for. This identifies
  446. a read-only String attribute, which represents the release of the
  447. operating system for which the object was created.
  448. **/
  449. public static final String RELEASE_PROGRAM_CREATED_FOR = "RELEASE_PROGRAM_CREATED_FOR";
  450. static {
  451. attributes_.add(RELEASE_PROGRAM_CREATED_FOR, String.class, true);
  452. getterMap_.add(RELEASE_PROGRAM_CREATED_FOR, QJVAMAT_, "receiverVariable.javaProgramVersion", new ReleaseProgramCreatedForValueMap_());
  453. }
  454. private static class ReleaseProgramCreatedForValueMap_ extends AbstractValueMap
  455. {
  456. public Object ptol(Object physicalValue)
  457. {
  458. byte[] asBytes = (byte[])physicalValue;
  459. StringBuffer buffer = new StringBuffer("V");
  460. buffer.append(asBytes[0]);
  461. buffer.append("R");
  462. buffer.append(asBytes[1] >> 4);
  463. buffer.append("M");
  464. buffer.append(asBytes[1] & 0x0F);
  465. return buffer.toString();
  466. }
  467. }
  468. /**
  469. Attribute ID for use adopted authority. This identifies a read-only
  470. String attribute, which indicates if the Java programs use adopted authority
  471. from previous call levels in the stack. Possible values are:
  472. <ul>
  473. <li>{@link #YES YES}
  474. <li>{@link #YES NO}
  475. </ul>
  476. **/
  477. public static final String USE_ADOPTED_AUTHORITY = "USE_ADOPTED_AUTHORITY";
  478. static {
  479. attributes_.add(USE_ADOPTED_AUTHORITY, String.class, true,
  480. new Object[] {YES, NO } ,null, true);
  481. getterMap_.add(USE_ADOPTED_AUTHORITY, QJVAMAT_, "receiverVariable.useAdoptedAuthority", new UseAdoptedAuthorityValueMap_());
  482. }
  483. private static class UseAdoptedAuthorityValueMap_ extends AbstractValueMap
  484. {
  485. public Object ptol(Object physicalValue)
  486. {
  487. return (physicalValue.equals("1") ? YES : NO);
  488. }
  489. }
  490. /**
  491. Attribute ID for user profile. This identifies a read-only
  492. String attribute, which represents who the authority checking
  493. that was done while this program is running should include.
  494. Possible values are:
  495. <ul>
  496. <li>{@link #USER_PROFILE_USER USER_PROFILE_USER}
  497. - Indicates that the authority checking that was done while
  498. this program is running should include only the user
  499. who is running the program.
  500. <li>{@link #USER_PROFILE_OWNER USER_PROFILE_OWNER}
  501. - Indicates that the authority checking that was done while
  502. this program is running should include both the use
  503. who is running the program and the program owner.
  504. </ul>
  505. **/
  506. public static final String USER_PROFILE = "USER_PROFILE";
  507. /**
  508. Attribute value indicating that the authority checking that was done while
  509. this program is running should include only the user who is running the program.
  510. @see #USER_PROFILE
  511. **/
  512. public static final String USER_PROFILE_USER = "*USER";
  513. /**
  514. Attribute value indicating that the authority checking that was done while
  515. this program is running should include both the use who is running the program
  516. and the program owner.
  517. @see #USER_PROFILE
  518. **/
  519. public static final String USER_PROFILE_OWNER = "*OWNER";
  520. static {
  521. attributes_.add(USER_PROFILE, String.class, true,
  522. new Object[] {USER_PROFILE_USER, USER_PROFILE_OWNER } ,null, true);
  523. getterMap_.add(USER_PROFILE, QJVAMAT_, "receiverVariable.adoptedAuthorityProfile", new UserProfileValueMap_());
  524. }
  525. private static class UserProfileValueMap_ extends AbstractValueMap
  526. {
  527. public Object ptol(Object physicalValue)
  528. {
  529. return (physicalValue.equals("1") ? USER_PROFILE_OWNER : USER_PROFILE_USER);
  530. }
  531. }
  532. //-----------------------------------------------------------------------------------------
  533. // PCML document initialization.
  534. //-----------------------------------------------------------------------------------------
  535. private static final String DOCUMENT_NAME_ = "com.ibm.as400.resource.RJavaProgram";
  536. private static ProgramCallDocument staticDocument_ = null;
  537. static {
  538. // Create a static version of the PCML document, then clone it for each document.
  539. // This will improve performance, since we will only have to deserialize the PCML
  540. // object once.
  541. try {
  542. staticDocument_ = new ProgramCallDocument();
  543. staticDocument_.setDocument(DOCUMENT_NAME_);
  544. }
  545. catch(PcmlException e) {
  546. if (Trace.isTraceOn())
  547. Trace.log(Trace.ERROR, "Error instantiating ProgramCallDocument", e);
  548. }
  549. }
  550. //-----------------------------------------------------------------------------------------
  551. // Private data.
  552. //-----------------------------------------------------------------------------------------
  553. private String path_ = null;
  554. private ProgramAttributeGetter attributeGetter_ = null;
  555. private CommandAttributeSetter attributeSetter_ = null;
  556. private ProgramCallDocument document_ = null;
  557. //-----------------------------------------------------------------------------------------
  558. // Constructors.
  559. //-----------------------------------------------------------------------------------------
  560. /**
  561. Constructs an RJavaProgram object.
  562. **/
  563. public RJavaProgram()
  564. {
  565. super(presentationLoader_.getPresentationWithIcon(PRESENTATION_KEY_, ICON_BASE_NAME_), null, attributes_);
  566. }
  567. /**
  568. Constructs an RJavaProgram object.
  569. @param system The system.
  570. @param path The path. This can be any class, jar, or zip file.
  571. **/
  572. public RJavaProgram(AS400 system, String path)
  573. {
  574. this();
  575. try {
  576. setSystem(system);
  577. setPath(path);
  578. }
  579. catch(PropertyVetoException e) {
  580. // Ignore.
  581. }
  582. }
  583. private void checkVRM()
  584. throws ResourceException
  585. {
  586. try
  587. {
  588. // See if the system VRM is higher than IBM i 7.1.
  589. if (getSystem() != null && getSystem().getVRM() > 0x00070100) {
  590. Trace.log(Trace.ERROR, "RJavaProgram is not supported beyond IBM i 7.1.");
  591. throw new ResourceException(ResourceException.OPERATION_NOT_SUPPORTED);
  592. }
  593. }
  594. catch (ResourceException e) { throw e; }
  595. catch (Exception e) {
  596. if (Trace.isTraceOn())
  597. Trace.log(Trace.ERROR, "Error when checking system VRM.", e);
  598. throw new ResourceException(e);
  599. }
  600. }
  601. /**
  602. Commits the specified attribute changes.
  603. @exception ResourceException If an error occurs.
  604. **/
  605. protected void commitAttributeChanges(Object[] attributeIDs, Object[] values)
  606. throws ResourceException
  607. {
  608. checkVRM();
  609. super.commitAttributeChanges(attributeIDs, values);
  610. // Establish the connection if needed.
  611. if (! isConnectionEstablished())
  612. establishConnection();
  613. attributeSetter_.setValues(attributeIDs, values);
  614. }
  615. /**
  616. Computes the resource key.
  617. @param system The system.
  618. @param path The path.
  619. **/
  620. static Object computeResourceKey(AS400 system, String path)
  621. {
  622. StringBuffer buffer = new StringBuffer();
  623. buffer.append(RJavaProgram.class);
  624. buffer.append(':');
  625. buffer.append(system.getSystemName());
  626. buffer.append(':');
  627. buffer.append(system.getUserId());
  628. buffer.append(':');
  629. buffer.append(path);
  630. return buffer.toString();
  631. }
  632. /**
  633. Deletes the Java program. This does not delete the class, jar, or zip file.
  634. @exception ResourceException If an error occurs.
  635. **/
  636. public void delete()
  637. throws ResourceException
  638. {
  639. checkVRM();
  640. // Establish the connection if needed.
  641. if (!isConnectionEstablished())
  642. establishConnection();
  643. StringBuffer buffer = new StringBuffer("DLTJVAPGM CLSF('");
  644. buffer.append(path_);
  645. buffer.append("')");
  646. try {
  647. fireBusy();
  648. CommandCall dltjvapgm = new CommandCall(getSystem(), buffer.toString());
  649. if (dltjvapgm.run() == false)
  650. throw new ResourceException(dltjvapgm.getMessageList());
  651. }
  652. catch (Exception e) {
  653. if (Trace.isTraceOn())
  654. Trace.log(Trace.ERROR, "Error when deleting a Java program", e);
  655. throw new ResourceException(e);
  656. }
  657. finally {
  658. fireIdle();
  659. }
  660. }
  661. /**
  662. Establishes the connection to the system.
  663. <p>The method is called by the resource framework automatically
  664. when the connection needs to be established.
  665. @exception ResourceException If an error occurs.
  666. **/
  667. protected void establishConnection()
  668. throws ResourceException
  669. {
  670. // Call the superclass.
  671. super.establishConnection();
  672. // Validate if we can establish the connection.
  673. if (path_ == null)
  674. throw new ExtendedIllegalStateException("path", ExtendedIllegalStateException.PROPERTY_NOT_SET);
  675. // Initialize the PCML document.
  676. document_ = (ProgramCallDocument)staticDocument_.clone();
  677. AS400 system = getSystem();
  678. try {
  679. document_.setSystem(system);
  680. document_.setIntValue("qjvamat.lengthOfPathName", path_.length());
  681. document_.setValue("qjvamat.pathName", path_);
  682. }
  683. catch(PcmlException e) {
  684. if (Trace.isTraceOn())
  685. Trace.log(Trace.ERROR, "Error setting PCML document values", e);
  686. }
  687. // Initialize the attribute getter.
  688. attributeGetter_ = new ProgramAttributeGetter(system, document_, getterMap_);
  689. // Initialize the attribute setter.
  690. attributeSetter_ = new CommandAttributeSetter(system, setterMap_);
  691. attributeSetter_.setParameterValue(CHGJVAPGM_, PATH_PARAMETER_, '\'' + path_ + '\'');
  692. }
  693. /**
  694. Freezes any property changes. After this is called, property
  695. changes should not be made. Properties are not the same thing
  696. as attributes. Properties are basic pieces of information
  697. which must be set to make the object usable, such as the system
  698. and path.
  699. <p>The method is called by the resource framework automatically
  700. when the properties need to be frozen.
  701. @exception ResourceException If an error occurs.
  702. **/
  703. protected void freezeProperties()
  704. throws ResourceException
  705. {
  706. // Call the superclass.
  707. super.freezeProperties();
  708. // Validate if we can establish the connection.
  709. if (path_ == null)
  710. throw new ExtendedIllegalStateException("path", ExtendedIllegalStateException.PROPERTY_NOT_SET);
  711. // Update the presentation.
  712. Presentation presentation = getPresentation();
  713. IFSFile f = new IFSFile(getSystem(), path_);
  714. presentation.setName(f.getName());
  715. presentation.setFullName(f.getPath());
  716. // Update the resource key.
  717. if (getResourceKey() == null)
  718. setResourceKey(computeResourceKey(getSystem(), path_));
  719. }
  720. /**
  721. Returns the unchanged value of an attribute. If the attribute
  722. value has a uncommitted change, this returns the unchanged value.
  723. If the attribute value does not have a uncommitted change, this
  724. returns the same value as <b>getAttributeValue()</b>.
  725. @param attributeID Identifies the attribute.
  726. @return The attribute value, or null if the attribute
  727. value is not available.
  728. @exception ResourceException If an error occurs.
  729. **/
  730. public Object getAttributeUnchangedValue(Object attributeID)
  731. throws ResourceException
  732. {
  733. checkVRM();
  734. Object value = super.getAttributeUnchangedValue(attributeID);
  735. if (value == null) {
  736. // Establish the connection if needed.
  737. if (! isConnectionEstablished())
  738. establishConnection();
  739. value = attributeGetter_.getValue(attributeID);
  740. /* @A1D
  741. // Check to see if the Java program exists (the API will not result
  742. // in an exception in this case).
  743. try {
  744. if (document_.getIntValue("qjvalibjvm.receiverVariable.bytesAvailable") == 0)
  745. throw new ResourceException(ResourceException.ATTRIBUTES_NOT_RETURNED);
  746. }
  747. catch(PcmlException e) {
  748. throw new ResourceException(e);
  749. }
  750. */
  751. }
  752. return value;
  753. }
  754. /**
  755. Returns the path.
  756. @return The path.
  757. **/
  758. public String getPath()
  759. {
  760. return path_;
  761. }
  762. /**
  763. Refreshes the values for all attributes. This does not cancel
  764. uncommitted changes. This method fires an attributeValuesRefreshed()
  765. ResourceEvent.
  766. @exception ResourceException If an error occurs.
  767. **/
  768. public void refreshAttributeValues()
  769. throws ResourceException
  770. {
  771. checkVRM();
  772. super.refreshAttributeValues();
  773. if (attributeGetter_ != null)
  774. attributeGetter_.clearBuffer();
  775. }
  776. /**
  777. Sets the path. This does not change the Java program
  778. on the system. Instead, it changes the Java program
  779. that this object references.
  780. @param path The path. This can be any class, jar, or zip file.
  781. **/
  782. public void setPath(String path)
  783. {
  784. if (path == null)
  785. throw new NullPointerException("path");
  786. if (arePropertiesFrozen())
  787. throw new ExtendedIllegalStateException("propertiesFrozen", ExtendedIllegalStateException.PROPERTY_NOT_CHANGED);
  788. String oldValue = path_;
  789. path_ = path;
  790. firePropertyChange("path", oldValue, path_);
  791. }
  792. /**
  793. Returns the path.
  794. @return The path.
  795. **/
  796. public String toString()
  797. {
  798. return (path_ == null) ? "" : path_;
  799. }
  800. }