- DamoManager singleton 메서드 추가 및 README 예제 갱신
- 기존 생성자 방식 유지 - 점진적 singleton 전환 가능
This commit is contained in:
@@ -117,17 +117,24 @@ WAS 기동 시 콘솔(`catalina.out` 또는 stderr)에 다음과 같은 배너
|
||||
```java
|
||||
import com.eactive.ext.djb.DamoManager;
|
||||
|
||||
DamoManager damo = new DamoManager(); // 클래스 로딩 시점에 모드 감지
|
||||
// 기존 방식 유지
|
||||
DamoManager damo1 = new DamoManager();
|
||||
|
||||
String cipher = damo.encrypt("hello"); // Base64 cipher text
|
||||
String plain = damo.decrypt(cipher); // → "hello"
|
||||
String h256 = damo.hash(DamoManager.SHA256, "password"); // SHA-256 base64
|
||||
String h512 = damo.hash(DamoManager.SHA512, "password"); // SHA-512 base64
|
||||
// singleton 필요 시
|
||||
DamoManager damo2 = DamoManager.getInstance();
|
||||
|
||||
boolean fake = damo.isFakeMode(); // 디버깅 / 분기용
|
||||
int rc = damo.getReturnCode(); // 0: 성공, -1: 실패
|
||||
String cipher = damo2.encrypt("hello"); // Base64 cipher text
|
||||
String plain = damo2.decrypt(cipher); // -> "hello"
|
||||
String h256 = damo2.hash(DamoManager.SHA256, "password"); // SHA-256 base64
|
||||
String h512 = damo2.hash(DamoManager.SHA512, "password"); // SHA-512 base64
|
||||
|
||||
boolean fake = damo2.isFakeMode(); // 디버깅 / 분기용
|
||||
int rc = damo2.getReturnCode(); // 0: 성공, -1: 실패
|
||||
```
|
||||
|
||||
`new DamoManager()` 와 `DamoManager.getInstance()` 를 함께 지원하므로,
|
||||
기존 호출 코드를 변경하지 않고도 singleton 접근 방식으로 점진 전환할 수 있다.
|
||||
|
||||
| 메서드 | 운영 동작 | Fake 동작 |
|
||||
|---|---|---|
|
||||
| `String encrypt(String plain)` | `ScpEncB64(INI_FILE, "KEY1", plain, "UTF-8")` | `Base64.encode(plain.getBytes("UTF-8"))` |
|
||||
@@ -146,6 +153,7 @@ int rc = damo.getReturnCode(); // 0: 성공, -1:
|
||||
- `Base64Encode(byte[])`, `Base64Decode(String)`
|
||||
- `byteToHex(byte[])`, `byteArrayToHex(byte[])`
|
||||
- `checkHangul(char)`
|
||||
- `getInstance()` (singleton 인스턴스 접근)
|
||||
- `getReturnCode()`, `getRevision()`
|
||||
|
||||
## 검증
|
||||
|
||||
@@ -63,6 +63,13 @@ public class DamoManager {
|
||||
private int nReturn;
|
||||
private final RealBridge bridge;
|
||||
|
||||
/**
|
||||
* 기존 생성자 사용은 유지하면서, 공용 singleton 인스턴스가 필요한 경우 사용.
|
||||
*/
|
||||
public static DamoManager getInstance() {
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public DamoManager() {
|
||||
if (REAL_MODE) {
|
||||
this.bridge = new RealBridge();
|
||||
@@ -78,6 +85,10 @@ public class DamoManager {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class SingletonHolder {
|
||||
private static final DamoManager INSTANCE = new DamoManager();
|
||||
}
|
||||
|
||||
public String getRevision() {
|
||||
return this.szRevision;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user