author | ntoda |
Thu, 31 Jul 2014 17:01:24 -0700 | |
changeset 25799 | 1afc4675dc75 |
parent 25586 | cac6440168e2 |
child 26054 | 3d9f96f3d540 |
permissions | -rw-r--r-- |
25586
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
1 |
/* |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
3 |
* |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
4 |
* Redistribution and use in source and binary forms, with or without |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
5 |
* modification, are permitted provided that the following conditions |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
6 |
* are met: |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
7 |
* |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
8 |
* - Redistributions of source code must retain the above copyright |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
9 |
* notice, this list of conditions and the following disclaimer. |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
10 |
* |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
11 |
* - Redistributions in binary form must reproduce the above copyright |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
12 |
* notice, this list of conditions and the following disclaimer in the |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
13 |
* documentation and/or other materials provided with the distribution. |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
14 |
* |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
15 |
* - Neither the name of Oracle nor the names of its |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
16 |
* contributors may be used to endorse or promote products derived |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
17 |
* from this software without specific prior written permission. |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
18 |
* |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
19 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
20 |
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
21 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
22 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
23 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
24 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
25 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
26 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
27 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
28 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
29 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
30 |
*/ |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
31 |
|
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
32 |
if (arguments.length == 0) { |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
33 |
print("Usage: jjs ziplist <zip-file>"); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
34 |
exit(1); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
35 |
} |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
36 |
|
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
37 |
// list the content details of a .zip or .jar file |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
38 |
var file = arguments[0]; |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
39 |
|
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
40 |
// java classes used |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
41 |
var Attributes = Java.type("java.util.jar.Attributes"); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
42 |
var FileTime = Java.type("java.nio.file.attribute.FileTime"); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
43 |
var JarFile = Java.type("java.util.jar.JarFile"); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
44 |
var ZipEntry = Java.type("java.util.zip.ZipEntry"); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
45 |
var ZipFile = Java.type("java.util.zip.ZipFile"); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
46 |
|
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
47 |
var zf = file.endsWith(".jar")? new JarFile(file) : new ZipFile(file); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
48 |
|
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
49 |
var entries = zf.entries(); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
50 |
// make overall output a valid JSON |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
51 |
var zfObj = { |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
52 |
name: zf.name, |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
53 |
comment: zf.comment, |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
54 |
size: zf.size(), |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
55 |
entries: [] |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
56 |
}; |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
57 |
|
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
58 |
while (entries.hasMoreElements()) { |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
59 |
zfObj.entries.push(entries.nextElement()); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
60 |
} |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
61 |
|
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
62 |
print(JSON.stringify(zfObj, function (key, value) { |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
63 |
if (value instanceof ZipEntry) { |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
64 |
return Object.bindProperties({}, value); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
65 |
} else if (value instanceof FileTime) { |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
66 |
return value.toString(); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
67 |
} else if (value instanceof Attributes) { |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
68 |
var attrs = {}; |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
69 |
var itr = value.entrySet().iterator(); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
70 |
while (itr.hasNext()) { |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
71 |
var n = itr.next(); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
72 |
attrs[n.key] = String(n.value); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
73 |
} |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
74 |
return attrs; |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
75 |
} |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
76 |
|
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
77 |
return value; |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
78 |
}, ' ')); |
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
79 |
|
cac6440168e2
8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date
sundar
parents:
diff
changeset
|
80 |
zf.close(); |