Skip to content

Commit c109395

Browse files
author
jossonsmith
committed
Update Javadoc for net.sf.j2s.ajax
1 parent eb573ba commit c109395

File tree

7 files changed

+199
-5
lines changed

7 files changed

+199
-5
lines changed

sources/net.sf.j2s.ajax/ajaxcore/net/sf/j2s/ajax/AClass.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,36 @@
1414
package net.sf.j2s.ajax;
1515

1616
/**
17+
* This class is an asynchronous version of Class. It is designed for function
18+
* of Class#forName. While Class#forName will try to load class in synchronous
19+
* mode, this class AClass#load is trying to load class in asynchronous mode.
20+
* A callback object is provided for action to be executed after the class is
21+
* loaded.
22+
*
1723
* @author josson smith
1824
*
1925
* 2006-8-4
2026
*/
2127
public class AClass {
2228

2329
/**
30+
* AClass should NOT be instantialized outside package net.sf.j2s.ajax.
31+
* User should always use its static methods.
32+
*
2433
* @j2sIgnore
2534
*/
2635
protected AClass() {
2736
// prevent from instantialization
2837
}
2938

3039
/**
31-
* @param clazzName
32-
* @param afterLoaded
40+
* Load the class by the given class name and execute the given callback
41+
* after class is loaded.
42+
*
43+
* @param clazzName String given class name.
44+
* @param afterLoaded Runnable given callback. If this parameter is an
45+
* instance of <code>ARunnable</code>, the callback will receive the
46+
* loaded class automatically.
3347
*
3448
* @j2sNativeSrc
3549
* ClazzLoader.loadClass (clazzName, function () {

sources/net.sf.j2s.ajax/ajaxcore/net/sf/j2s/ajax/ARunnable.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,29 @@
1414
package net.sf.j2s.ajax;
1515

1616
/**
17+
* This abstract class provides a wrapper of interface Runnable to
18+
* give convenience for <code>AClass</code> or <code>ASWTClass</code>
19+
* to set and to get the class that is loaded.
20+
*
1721
* @author josson smith
1822
*
1923
* 2006-8-4
2024
*/
2125
public abstract class ARunnable implements Runnable {
2226
private Class clazz;
2327

28+
/**
29+
* Return the loaded class.
30+
* @return Class loaded class.
31+
*/
2432
public Class getClazz() {
2533
return clazz;
2634
}
2735

36+
/**
37+
* Set the loaded class
38+
* @param clazz Class class that is already loaded.
39+
*/
2840
public void setClazz(Class clazz) {
2941
this.clazz = clazz;
3042
}

sources/net.sf.j2s.ajax/ajaxcore/net/sf/j2s/ajax/HttpRequest.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
import org.w3c.dom.Document;
3131

3232
/**
33+
* This class is a Java implementation of browser's XMLHttpRequest object.
34+
* This class can be considered as a bridge of Java's AJAX programming and
35+
* JavaScript/Browser's AJAX programming.
36+
*
3337
* @author josson smith
3438
*
3539
* 2006-2-11
@@ -51,12 +55,26 @@ public final class HttpRequest {
5155
private Map headers = new HashMap();
5256
private String content;
5357

58+
/**
59+
* Return read state of XMLHttpRequest.
60+
* @return int ready state
61+
*/
5462
public int getReadyState() {
5563
return readyState;
5664
}
65+
/**
66+
* Return response raw text of XMLHttpRequest
67+
* @return String response text. May be null if the request is not sent
68+
* or an error happens.
69+
*/
5770
public String getResponseText() {
5871
return responseText;
5972
}
73+
/**
74+
* Return the parsed XML document of the response of XMLHttpRequest.
75+
* @return Document XML document. May be null if the response text is not
76+
* a valid XML document.
77+
*/
6078
public Document getResponseXML() {
6179
if (responseXML != null) {
6280
return responseXML;
@@ -75,21 +93,57 @@ public Document getResponseXML() {
7593
}
7694
return responseXML;
7795
}
96+
/**
97+
* Return respose code.
98+
* @return int response code. For more information please read about
99+
* HTTP protocol.
100+
*/
78101
public int getResponseCode() {
79102
return status;
80103
}
104+
/**
105+
* Register XMLHttpRequest callback.
106+
*
107+
* @param onreadystatechange IXHRCallback callback
108+
*/
81109
public void registerOnReadyStateChange(IXHRCallback onreadystatechange) {
82110
this.onreadystatechange = onreadystatechange;
83111
}
112+
/**
113+
* Set request header with given key and value.
114+
* @param key String request header keyword. For more information please
115+
* read about HTTP protocol.
116+
* @param value String request header value
117+
*/
84118
public void setRequestHeader(String key, String value) {
85119
headers.put(key, value);
86120
}
121+
/**
122+
* Get response header with given key.
123+
* @param key String header keyword. For more information please
124+
* read about HTTP protocol.
125+
* @return String the reponse header value.
126+
*/
87127
public String getResponseHeader(String key) {
88128
return connection.getHeaderField(key);
89129
}
130+
/**
131+
* Open connection for HTTP request with given method and URL
132+
* synchronously.
133+
*
134+
* @param method String "POST" or "GET" usually.
135+
* @param url String remote URL. Should always be absolute URL.
136+
*/
90137
public void open(String method, String url) {
91138
open(method, url, false);
92139
}
140+
/**
141+
* Open connection for HTTP request with given method, URL and mode.
142+
*
143+
* @param method String "POST" or "GET" usually.
144+
* @param url String remote URL. Should always be absolute URL.
145+
* @param async boolean whether send request asynchronously or not.
146+
*/
93147
public void open(String method, String url, boolean async) {
94148
this.asynchronous = async;
95149
this.method = method;
@@ -101,9 +155,17 @@ public void open(String method, String url, boolean async) {
101155
onreadystatechange.onLoading();
102156
}
103157
}
158+
159+
/**
160+
* Send the HTTP request without extra content.
161+
*/
104162
public void send() {
105163
send(null);
106164
}
165+
/**
166+
* Send the HTTP request with given content.
167+
* @param str String HTTP request content. May be null.
168+
*/
107169
public void send(String str) {
108170
content = str;
109171
if (asynchronous) {
@@ -116,6 +178,9 @@ public void run() {
116178
request();
117179
}
118180
}
181+
/*
182+
* Try setup the real connection and send the request over HTTP protocol.
183+
*/
119184
private void request() {
120185
try {
121186
connection = (HttpURLConnection) new URL(url).openConnection();

sources/net.sf.j2s.ajax/ajaxcore/net/sf/j2s/ajax/IXHRCallback.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,29 @@
1414
package net.sf.j2s.ajax;
1515

1616
/**
17+
* Interface of XMLHttpRequest callback.
18+
*
1719
* @author josson smith
1820
*
1921
* 2006-2-11
2022
*/
2123
public interface IXHRCallback {
2224
//public void onUninitialized();
25+
/**
26+
* Method will be called when XMLHttpRequest is loading.
27+
*/
2328
public void onLoading();
29+
/**
30+
* Method will be called when XMLHttpRequest already setup HTTP connection.
31+
*/
2432
public void onLoaded();
33+
/**
34+
* Method will be called when XMLHttpRequest is transforming request and
35+
* receiving response.
36+
*/
2537
public void onInteractive();
38+
/**
39+
* Method will be called when XMLHttpRequest receives all reponses.
40+
*/
2641
public void onComplete();
2742
}

sources/net.sf.j2s.ajax/ajaxcore/net/sf/j2s/ajax/XHRCallbackAdapter.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,38 @@
1414
package net.sf.j2s.ajax;
1515

1616
/**
17+
* This adapter provides a default implementation of IXHRCallback.
18+
*
1719
* @author josson smith
1820
*
1921
* 2006-2-11
2022
*/
2123
public class XHRCallbackAdapter implements IXHRCallback {
2224

25+
/**
26+
* Will be called when all responses are received.
27+
*/
2328
public void onComplete() {
2429

2530
}
2631

32+
/**
33+
* Will be called when the request is sending and the reponse comes.
34+
*/
2735
public void onInteractive() {
2836

2937
}
3038

39+
/**
40+
* Will be called when the HTTP connection is setup.
41+
*/
3142
public void onLoaded() {
3243

3344
}
3445

46+
/**
47+
* Will be called when <code>HttPRequest#open</code> is called.
48+
*/
3549
public void onLoading() {
3650

3751
}

sources/net.sf.j2s.ajax/ajaxswt/net/sf/j2s/ajax/ASWTClass.java

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,47 @@
1717
import org.eclipse.swt.widgets.Shell;
1818

1919
/**
20+
* This class is designed to load class asynchronously within the same thread
21+
* of given Shell or Display. Because executing callback after given class is
22+
* loaded will be in another thread scope of current Display. In order to
23+
* avoid nasty codes of such
24+
* <pre>
25+
Display.getDefault().asyncExec(new Runnable() {
26+
public void run() {
27+
//...
28+
}
29+
});
30+
* </pre>
31+
* This class ASWTClass is designed so developer won't need to code in such
32+
* nasty way. Just call <code>ASWTClass#swtLoad</code> with the same
33+
* parameter as <code>AClass#load</code>. Or call <code>ASWTClass#shellLoad</code>
34+
* or <code>ASWTClass#displayLoad</code> with extra Shell/Display argument.
35+
*
2036
* @author josson smith
2137
*
2238
* 2006-8-4
2339
*/
2440
public class ASWTClass extends AClass {
2541

2642
/**
43+
* ASWTClass should NOT be instantialized outside package net.sf.j2s.ajax.
44+
* User should always use its static methods.
45+
*
2746
* @j2sIgnore
2847
*/
2948
protected ASWTClass() {
3049
// prevent from instantialization
3150
}
3251

52+
/**
53+
* Load class by given class name and execute callback in the same thread
54+
* of default Display's thread.
55+
*
56+
* @param clazzName String given class name.
57+
* @param afterLoaded Runnable given callback. If this parameter is an
58+
* instance of <code>ARunnable</code>, the callback will receive the
59+
* loaded class automatically.
60+
*/
3361
public static void swtLoad(String clazzName, Runnable afterLoaded) {
3462
Display display = null;
3563
/**
@@ -46,9 +74,14 @@ public static void swtLoad(String clazzName, Runnable afterLoaded) {
4674

4775

4876
/**
49-
* @param display
50-
* @param clazzName
51-
* @param afterLoaded
77+
* Load class by given class name and execute callback in the same thread
78+
* of given Display's thread.
79+
*
80+
* @param display Display given display
81+
* @param clazzName String given class name.
82+
* @param afterLoaded Runnable given callback. If this parameter is an
83+
* instance of <code>ARunnable</code>, the callback will receive the
84+
* loaded class automatically.
5285
*
5386
* @j2sNativeSrc
5487
* ClazzLoader.loadClass (clazzName, function () {
@@ -86,9 +119,30 @@ public void run() {
86119
});
87120
}
88121

122+
/**
123+
* Load class asynchronously and execute callback in the same thread
124+
* of given Display's thread.
125+
*
126+
* @param display Display given display
127+
* @param clazzName String given class name.
128+
* @param afterLoaded Runnable given callback. If this parameter is an
129+
* instance of <code>ARunnable</code>, the callback will receive the
130+
* loaded class automatically.
131+
*/
89132
public static void displayLoad(Display display, final String clazzName, final Runnable afterLoaded) {
90133
objectLoad(display, clazzName, afterLoaded);
91134
}
135+
/**
136+
* Load class asynchronously and execute callback in the same thread of
137+
* given Shell's Display.
138+
*
139+
* @param shell Shell given shell
140+
* @param clazzName String given class name.
141+
* @param afterLoaded Runnable given callback. If this parameter is an
142+
* instance of <code>ARunnable</code>, the callback will receive the
143+
* loaded class automatically.
144+
*
145+
*/
92146
public static void shellLoad(Shell shell, String clazzName, Runnable afterLoaded) {
93147
objectLoad(shell.getDisplay(), clazzName, afterLoaded);
94148
}

0 commit comments

Comments
 (0)