Skip to content

Commit 9e296d4

Browse files
committed
0.8.13 (2023-02-26)
+ [Added unsafe loading for factory type](fugerit-org/fj-doc#31)
1 parent 5f778df commit 9e296d4

File tree

10 files changed

+132
-7
lines changed

10 files changed

+132
-7
lines changed

docgen/parameters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"title" : "Jupiter (Fugerit Core A.P.I.)",
33
"name": "Jupiter",
44
"version" : "0.8.12",
5-
"date" : "28/01/2023",
5+
"date" : "26/02/2023",
66
"organization" : {
77
"name" : "Fugerit Org",
88
"url" : "https://www.fugerit.org"

docgen/release-notes.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
0.8.12 (2023-01-28)
1+
0.8.13 (2023-02-26)
2+
------------------
3+
+ [Added unsafe loading for factory type](https://github.com/fugerit-org/fj-doc/issues/31)
4+
5+
0.8.12 (2023-01-28)
26
------------------
37
+ fix to jvfs copy (files with no null input streams were not copied)
48

fj-core-jvfs/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-lib</artifactId>
10-
<version>0.8.12</version>
10+
<version>0.8.13</version>
1111
</parent>
1212

1313
<name>fj-core-jvfs</name>

fj-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-lib</artifactId>
10-
<version>0.8.12</version>
10+
<version>0.8.13</version>
1111
</parent>
1212

1313
<name>fj-core</name>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.fugerit.java.core.cfg.helpers;
2+
3+
import org.fugerit.java.core.cfg.ConfigException;
4+
import org.fugerit.java.core.lang.helpers.BooleanUtils;
5+
import org.fugerit.java.core.lang.helpers.StringUtils;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
public class UnsafeHelper {
10+
11+
private UnsafeHelper() {}
12+
13+
private final static Logger logger = LoggerFactory.getLogger( UnsafeHelper.class );
14+
15+
public static final String UNSAFE_TRUE = BooleanUtils.BOOLEAN_TRUE;
16+
public static final String UNSAFE_FALSE = BooleanUtils.BOOLEAN_FALSE;
17+
18+
public static final String UNSAFE_MODE_LOG_TRACE = "log-trace";
19+
public static final String UNSAFE_MODE_LOG_MESSAGE = "log-message";
20+
public static final String UNSAFE_MODE_DEFAULT = UNSAFE_MODE_LOG_MESSAGE;
21+
22+
public static void handleUnsafe( Exception e, String unsafe ) throws ConfigException {
23+
handleUnsafe(e, unsafe, null);
24+
}
25+
26+
public static void handleUnsafe( Exception e, String unsafe, String unsafeMode ) throws ConfigException {
27+
handleUnsafe(logger, e, unsafe, unsafeMode);
28+
}
29+
30+
public static void handleUnsafe( Logger l, Exception e, String unsafe, String unsafeMode ) throws ConfigException {
31+
unsafeMode = StringUtils.valueWithDefault( unsafeMode , UNSAFE_MODE_DEFAULT );
32+
boolean unsafeHandle = BooleanUtils.isTrue( unsafe );
33+
String message = "Error handling unsafe seciont "+e;
34+
if ( unsafeHandle ) {
35+
if ( UNSAFE_MODE_LOG_TRACE.equalsIgnoreCase( unsafeMode ) ) {
36+
l.warn( message, e );
37+
} else {
38+
l.warn( message+" [trace suppressed, set unsafe-mode='log-trace' to show]" );
39+
}
40+
} else {
41+
ConfigException cf = null;
42+
if ( e instanceof ConfigException ) {
43+
cf = (ConfigException)e;
44+
} else {
45+
cf = new ConfigException( message, e );
46+
}
47+
throw cf;
48+
}
49+
}
50+
51+
}

fj-core/src/main/java/org/fugerit/java/core/cfg/xml/FactoryCatalog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.w3c.dom.Element;
55

66
public class FactoryCatalog extends CustomListCatalogConfig<FactoryType, ListMapConfig<FactoryType>> {
7-
7+
88
/**
99
* Default configuration element for a data list
1010
*/

fj-core/src/main/java/org/fugerit/java/core/cfg/xml/FactoryType.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
public class FactoryType extends BasicIdConfigType {
66

7+
@Override
8+
public String toString() {
9+
return "FactoryType [type=" + type + ", info=" + info + ", unsafe=" + unsafe + ", element=" + element + "]";
10+
}
11+
712
/**
813
*
914
*/
@@ -12,6 +17,10 @@ public class FactoryType extends BasicIdConfigType {
1217
private String type;
1318

1419
private String info;
20+
21+
private String unsafe;
22+
23+
private String unsafeMode;
1524

1625
public String getType() {
1726
return type;
@@ -29,6 +38,22 @@ public void setInfo(String info) {
2938
this.info = info;
3039
}
3140

41+
public String getUnsafe() {
42+
return unsafe;
43+
}
44+
45+
public void setUnsafe(String unsafe) {
46+
this.unsafe = unsafe;
47+
}
48+
49+
public String getUnsafeMode() {
50+
return unsafeMode;
51+
}
52+
53+
public void setUnsafeMode(String unsafeMode) {
54+
this.unsafeMode = unsafeMode;
55+
}
56+
3257
private Element element;
3358

3459
public Element getElement() {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.fugerit.java.core.cfg.xml;
2+
3+
import java.io.Serializable;
4+
5+
import org.fugerit.java.core.cfg.ConfigException;
6+
import org.fugerit.java.core.cfg.ConfigurableObject;
7+
import org.fugerit.java.core.cfg.helpers.UnsafeHelper;
8+
import org.fugerit.java.core.lang.helpers.ClassHelper;
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
12+
public class FactoryTypeHelper<T> implements Serializable {
13+
14+
/**
15+
*
16+
*/
17+
private static final long serialVersionUID = 6578485338271471032L;
18+
19+
private static Logger logger = LoggerFactory.getLogger( FactoryTypeHelper.class );
20+
21+
private FactoryTypeHelper() {
22+
23+
}
24+
25+
@SuppressWarnings("unchecked")
26+
public T createHelper( FactoryType factoryType ) throws ConfigException {
27+
logger.info( "factoryType : {} , resultType : {}" );
28+
T res = null;
29+
try {
30+
res = (T)ClassHelper.newInstance( factoryType.getType() );
31+
if ( res instanceof ConfigurableObject && factoryType.getElement() != null ) {
32+
logger.info( "ConfigurableObject -> try configure()" );
33+
((ConfigurableObject)res).configure( factoryType.getElement());
34+
}
35+
} catch (Exception | NoClassDefFoundError e) {
36+
UnsafeHelper.handleUnsafe( new ConfigException( "Type cannot be loaded : "+e, e ), factoryType.getUnsafe(), factoryType.getUnsafeMode() );
37+
}
38+
return res;
39+
}
40+
41+
public static <T> FactoryTypeHelper<T> newInstance( Class<? extends T> ct ) {
42+
return new FactoryTypeHelper<T>();
43+
}
44+
45+
}

fj-tool/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-lib</artifactId>
10-
<version>0.8.12</version>
10+
<version>0.8.13</version>
1111
</parent>
1212

1313
<name>fj-tool</name>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<relativePath></relativePath>
1212
</parent>
1313

14-
<version>0.8.12</version>
14+
<version>0.8.13</version>
1515
<packaging>pom</packaging>
1616

1717
<name>fj-lib</name>

0 commit comments

Comments
 (0)