|
4 | 4 |
|
5 | 5 | **Nordstrom Java Utils** is a small collection of general-purpose utility classes with wide applicability.
|
6 | 6 |
|
| 7 | +## What You'll Find Here |
| 8 | + |
| 9 | +* [UncheckedThrow](#uncheckedthrow) provides a method that uses type erasure to enable you to throw checked exception as unchecked. |
| 10 | +* [DatabaseUtils](#databaseutils) provides facilities that enable you to define collections of database queries and stored procedures in an easy-to-execute format. |
| 11 | + * [Query Collections](#query-collections) are defined as Java enumerations that implement the `QueryAPI` interface |
| 12 | + * [Stored Procedure Collections](#stored-procedure-collections) are defined as Java enumerations that implement the `SProcAPI` interface |
| 13 | + * [Recommended Implementation Strategies](#recommended-implementation-strategies) to maximize usability and configurability |
| 14 | + * [Query Collection Example](#query-collection-example) |
| 15 | + * [Registering JDBC Providers](#registering-jdbc-providers) with the **ServiceLoader** facility of **DatabaseUtils** |
| 16 | +* [PathUtils](#pathutils) provides a method to acquire the next file path in sequence for the specified base name and extension in the indicated target folder. |
| 17 | +* [Params Interface](#params-interface) defines concise methods for the creation of named parameters and parameter maps. |
| 18 | +* [JarUtils](#jarutils) provides methods related to Java JAR files: |
| 19 | + * [Assembling a Classpath String](#assembling-a-classpath-string) |
| 20 | + * [Finding a JAR File Path](#finding-a-jar-file-path) |
| 21 | + * [Extracting the `Premain-Class` Attribute](#extracting-the-premain-class-attribute) |
| 22 | + |
7 | 23 | ## UncheckedThrow
|
8 | 24 |
|
9 | 25 | The **UncheckedThrow** class uses type erasure to enable client code to throw checked exceptions as unchecked. This allows methods to throw checked exceptions without requiring clients to handle or declare them. It should be used judiciously, as this exempts client code from handling or declaring exceptions created by their own actions. The target use case for this facility is to throw exceptions that were serialized in responses from a remote system. Although the compiler won't require clients of methods using this technique to handle or declare the suppressed exception, the JavaDoc for such methods should include a `@throws` declaration for implementers who might want to handle or declare it voluntarily.
|
10 | 26 |
|
11 |
| - |
12 | 27 | ```java
|
13 | 28 | ...
|
14 | 29 |
|
15 | 30 | String value;
|
16 | 31 | try {
|
17 | 32 | value = URLDecoder.decode(keyVal[1], "UTF-8");
|
18 | 33 | } catch (UnsupportedEncodingException e) {
|
19 |
| - throw UncheckedThrow.throwUnchecked(e); |
| 34 | + throw UncheckedThrow.throwUnchecked(e); |
20 | 35 | }
|
21 | 36 |
|
22 | 37 | ...
|
@@ -255,7 +270,7 @@ This sample provider configuration file will cause **DatabaseUtils** to load the
|
255 | 270 |
|
256 | 271 | ## PathUtils
|
257 | 272 |
|
258 |
| -The **PathUtils** `getNextPath` method provides a method to acquire the next file path in sequence for the specified base name and extension in the indicated target folder. If the target folder already contains at least one file that matches the specified base name and extension, the algorithm used to select the next path will always return a path whose index is one more than the highest index that currently exists. (If a single file with no index is found, its implied index is 0.) |
| 273 | +The **PathUtils** class provides a method to acquire the next file path in sequence for the specified base name and extension in the indicated target folder. If the target folder already contains at least one file that matches the specified base name and extension, the algorithm used to select the next path will always return a path whose index is one more than the highest index that currently exists. (If a single file with no index is found, its implied index is 0.) |
259 | 274 |
|
260 | 275 | ##### Example usage of `getNextPath`
|
261 | 276 |
|
@@ -342,3 +357,30 @@ public class ParamTest implements Params {
|
342 | 357 | ```
|
343 | 358 |
|
344 | 359 | This code uses a static import to eliminate redundant references to the **Params** interface. It also shows the unrestricted data types of parameter values. The use of **Optional** objects enables you to provide an indication that no value was returned without the risks associated with `null`.
|
| 360 | + |
| 361 | +## JarUtils |
| 362 | + |
| 363 | +The **JarUtils** class provides methods related to Java JAR files. |
| 364 | + |
| 365 | +* `getClasspath` assemble a classpath string from the specified array of dependencies. |
| 366 | +* `findJarPathFor` find the path to the JAR file from which the named class was loaded. |
| 367 | +* `getJarPremainClass` gets the 'Premain-Class' attribute from the indicated JAR file. |
| 368 | + |
| 369 | +The methods of this class provide critical services for the `Local Grid` feature of [**Selenium Foundation**](https://github.com/sbabcoc/Selenium-Foundation), handling the task of locating the JAR files that declare the classes required by the Java-based servers it launches. |
| 370 | + |
| 371 | +### Assembling a Classpath String |
| 372 | + |
| 373 | +The **`getClasspath`** method assembles a classpath string from the specified array of dependency contexts. This is useful for launching a Java sub-process, as it greatly simplifies the task of collecting the paths of JAR files that declare the classes required by your process. If any of the specified dependency contexts names the `premain` class of a Java agent, the string returned by this method will contain two records delimited by a `newline` character: |
| 374 | + |
| 375 | +* `0` - assembled classpath string |
| 376 | +* `1` - tab-delimited list of Java agent paths |
| 377 | + |
| 378 | +### Finding a JAR File Path |
| 379 | + |
| 380 | +The **`findJarPathFor`** method will find the absolute path to the JAR file from which the named class was loaded, provided the class has been loaded from a JAR file on the local file system. |
| 381 | + |
| 382 | +### Extracting the `Premain-Class` Attribute |
| 383 | + |
| 384 | +The **`getJarPremainClass`** method will extract the `Premain-Class` attribute from the manifest of the indicated JAR file. The value of this attribute specifies the name of a `Java agent` class declared by the JAR. |
| 385 | + |
| 386 | +> Written with [StackEdit](https://stackedit.io/). |
0 commit comments