Java Doc for SelfModifier.java in  » Installer » IzPack » com » izforge » izpack » uninstaller » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Installer » IzPack » com.izforge.izpack.uninstaller 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.izforge.izpack.uninstaller.SelfModifier

SelfModifier
public class SelfModifier (Code)
Allows an application to modify the jar file from which it came, including outright deletion. The jar file of an app is usually locked when java is run so this is normally not possible.

Create a SelfModifier with a target method, then invoke the SelfModifier with arguments to be passed to the target method. The jar file containing the target method's class (obtained by reflection) will be extracted to a temporary directory, and a new java process will be spawned to invoke the target method. The original jar file may now be modified.

If the constructor or invoke() methods fail, it is generally because secondary java processes could not be started. Requirements

  • The target method, and all it's required classes must be in a jar file.
  • The Self Modifier, and its inner classes must also be in the jar file.
There are three system processes (or "phases") involved, the first invoked by the user, the second and third by the SelfModifier.

Phase 1:

  1. Program is launched, SelfModifier is created, invoke(String[]) is called
  2. A temporary directory (or "sandbox") is created in the default temp directory, and the jar file contents ar extracted into it
  3. Phase 2 is spawned using the sandbox as it's classpath, SelfModifier as the main class, the arguments to "invoke(String[])" as the main arguments, and the SelfModifier system properties set.
  4. Immidiately exit so the system unlocks the jar file
Phase 2:
  1. Initializes from system properties.
  2. Spawn phase 3 exactly as phase 2 except the self.modifier.phase system properties set to 3.
  3. Wait for phase 3 to die
  4. Delete the temporary sandbox
Phase 3:
  1. Initializes from system properties.
  2. Redirect std err stream to the log
  3. Invoke the target method with arguments we were given
  4. The target method is expected to call exit(), or to not start any looping threads (e.g. AWT thread). In other words, the target is the new "main" method.
SelfModifier system properties used to pass information between processes.
Constant System property description
BASE_KEY self.mod.jar base path to log file and sandbox dir
JAR_KEY self.mod.class path to original jar file
CLASS_KEY self.mod.method class of target method
METHOD_KEY self.mod.phase name of method to be invoked in sandbox
PHASE_KEY self.mod.base phase of operation to run

author:
   Chadwick McHenry
version:
   1.0

Inner Class :public static class StreamProxy extends Thread

Field Summary
final public static  StringBASE_KEY
     System property name of base for log and sandbox of secondary processes.
final public static  StringCLASS_KEY
     System property name of class declaring target method.
final public static  StringJAR_KEY
     System property name of original jar file containing application.
final public static  StringMETHOD_KEY
     System property name of target method to invoke in secondary process.
final public static  StringPHASE_KEY
     System property name of phase (1, 2, or 3) indicator.
 PrintStreamlog
    

Constructor Summary
public  SelfModifier(Method method)
     Creates a SelfModifier which will invoke the target method in a separate process from which it may modify it's own jar file. The target method must be public, static, and take a single array of strings as its only parameter.

Method Summary
public static  booleandeleteTree(File file)
     Recursively delete a file structure.
public static  FilefindJarFile(Class<MultiVolumeInstaller> clazz)
     Retrieve the jar file the specified class was loaded from.
public static  StringfromURI(String uri)
     Constructs a file path from a file: URI.

Will be an absolute path if the given URI is absolute.

Swallows '%' that are not followed by two characters, doesn't deal with non-ASCII characters.


Parameters:
  uri - the URI designating a file in the local filesystem.
public  voidinvoke(String[] args)
     Invoke the target method in a separate process from which it may modify it's own jar file. This method does not normally return.
public static  voidmain(String[] args)
    
public static  voidtest(String[] args)
    

Field Detail
BASE_KEY
final public static String BASE_KEY(Code)
System property name of base for log and sandbox of secondary processes.



CLASS_KEY
final public static String CLASS_KEY(Code)
System property name of class declaring target method.



JAR_KEY
final public static String JAR_KEY(Code)
System property name of original jar file containing application.



METHOD_KEY
final public static String METHOD_KEY(Code)
System property name of target method to invoke in secondary process.



PHASE_KEY
final public static String PHASE_KEY(Code)
System property name of phase (1, 2, or 3) indicator.



log
PrintStream log(Code)
--------------------------------------------------------------------- Logging ---------------------------------------------------------------------




Constructor Detail
SelfModifier
public SelfModifier(Method method) throws IOException(Code)
Creates a SelfModifier which will invoke the target method in a separate process from which it may modify it's own jar file. The target method must be public, static, and take a single array of strings as its only parameter. The class which declares the method must also be public. Reflection is used to ensure this.
Parameters:
  method - a public, static method that accepts a String array as it's only parameter. Anyreturn value is ignored.
throws:
  NullPointerException - if method is null
throws:
  IllegalArgumentException - if method is not public, static, and take aString array as it's only argument, or of it's declaring class is not public.
throws:
  IllegalStateException - if process was not invoked from a jar file, or an IOExceptioinoccured while accessing it
throws:
  IOException - if java is unable to be executed as a separte process
throws:
  SecurityException - if access to the method, or creation of a subprocess is denied




Method Detail
deleteTree
public static boolean deleteTree(File file)(Code)
Recursively delete a file structure.



findJarFile
public static File findJarFile(Class<MultiVolumeInstaller> clazz)(Code)
Retrieve the jar file the specified class was loaded from. null if file was not loaded from a jar file
throws:
  SecurityException - if access to is denied by SecurityManager



fromURI
public static String fromURI(String uri)(Code)
Constructs a file path from a file: URI.

Will be an absolute path if the given URI is absolute.

Swallows '%' that are not followed by two characters, doesn't deal with non-ASCII characters.


Parameters:
  uri - the URI designating a file in the local filesystem. the local file system path for the file.



invoke
public void invoke(String[] args) throws IOException(Code)
Invoke the target method in a separate process from which it may modify it's own jar file. This method does not normally return. After spawning the secondary process, the current process must die before the jar file is unlocked, therefore calling this method is akin to calling System.exit(int) .

The contents of the current jar file are extracted copied to a 'sandbox' directory from which the method is invoked. The path to the original jar file is placed in the system property SelfModifier.JAR_KEY .


Parameters:
  args - arguments to pass to the target method. May be empty or null to indicate noarguments.
throws:
  IOException - for lots of things
throws:
  IllegalStateException - if method's class was not loaded from a jar




main
public static void main(String[] args)(Code)



test
public static void test(String[] args)(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.