[Minor] Some code cleanup for JDK 9
This commit is contained in:
parent
2cb799dfb4
commit
84d3ca4666
|
@ -32,7 +32,7 @@ public abstract class BooleanSelector<T extends StrolchElement> implements Selec
|
||||||
this.selectors = new ArrayList<>(1);
|
this.selectors = new ArrayList<>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BooleanSelector(Selector<T>... selector) {
|
public BooleanSelector(Selector<T> selector) {
|
||||||
this.selectors = Arrays.asList(selector);
|
this.selectors = Arrays.asList(selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class NotSelector<T extends StrolchElement> extends BooleanSelector<T> {
|
||||||
/**
|
/**
|
||||||
* @param selector
|
* @param selector
|
||||||
*/
|
*/
|
||||||
public NotSelector(Selector<T> selector) {
|
NotSelector(Selector<T> selector) {
|
||||||
super(selector);
|
super(selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,15 +32,6 @@ public class OrSelector<T extends StrolchElement> extends BooleanSelector<T> {
|
||||||
super(selectors);
|
super(selectors);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
|
||||||
public OrSelector(Selector<T>... selector) {
|
|
||||||
super(selector);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrSelector(Selector<T> leftHandSide, Selector<T> rightHandSide) {
|
|
||||||
super(leftHandSide, rightHandSide);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OrSelector<T> with(Selector<T> selector) {
|
public OrSelector<T> with(Selector<T> selector) {
|
||||||
super.with(selector);
|
super.with(selector);
|
||||||
|
|
|
@ -1847,7 +1847,7 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
||||||
PrivilegePolicy policy;
|
PrivilegePolicy policy;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
policy = policyClazz.newInstance();
|
policy = policyClazz.getConstructor().newInstance();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String msg = "The class for the policy with the name {0} does not exist!{1}"; //$NON-NLS-1$
|
String msg = "The class for the policy with the name {0} does not exist!{1}"; //$NON-NLS-1$
|
||||||
msg = MessageFormat.format(msg, policyName, policyName);
|
msg = MessageFormat.format(msg, policyName, policyName);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.privilege.model.internal;
|
package li.strolch.privilege.model.internal;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -117,11 +118,12 @@ public class PrivilegeContainerModel {
|
||||||
// load class and try to create a new instance
|
// load class and try to create a new instance
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Class<PrivilegePolicy> clazz = (Class<PrivilegePolicy>) Class.forName(policyClassName);
|
Class<PrivilegePolicy> clazz = (Class<PrivilegePolicy>) Class.forName(policyClassName);
|
||||||
clazz.newInstance();
|
|
||||||
|
clazz.getConstructor().newInstance();
|
||||||
|
|
||||||
this.policies.put(privilegeName, clazz);
|
this.policies.put(privilegeName, clazz);
|
||||||
|
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException | InvocationTargetException e) {
|
||||||
String msg = "Configured Privilege Policy {0} with class {1} could not be instantiated."; //$NON-NLS-1$
|
String msg = "Configured Privilege Policy {0} with class {1} could not be instantiated."; //$NON-NLS-1$
|
||||||
msg = MessageFormat.format(msg, privilegeName, policyClassName);
|
msg = MessageFormat.format(msg, privilegeName, policyClassName);
|
||||||
throw new PrivilegeException(msg, e);
|
throw new PrivilegeException(msg, e);
|
||||||
|
@ -133,6 +135,10 @@ public class PrivilegeContainerModel {
|
||||||
String msg = "Configured Privilege Policy {0} with class {1} does not exist."; //$NON-NLS-1$
|
String msg = "Configured Privilege Policy {0} with class {1} does not exist."; //$NON-NLS-1$
|
||||||
msg = MessageFormat.format(msg, privilegeName, policyClassName);
|
msg = MessageFormat.format(msg, privilegeName, policyClassName);
|
||||||
throw new PrivilegeException(msg, e);
|
throw new PrivilegeException(msg, e);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
String msg = "Configured Privilege Policy {0} with class {1} has missing parameterless constructor"; //$NON-NLS-1$
|
||||||
|
msg = MessageFormat.format(msg, privilegeName, policyClassName);
|
||||||
|
throw new PrivilegeException(msg, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@ package li.strolch.service.test;
|
||||||
import static li.strolch.testbase.runtime.RuntimeMock.assertServiceResult;
|
import static li.strolch.testbase.runtime.RuntimeMock.assertServiceResult;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
|
|
||||||
|
@ -91,10 +93,11 @@ public abstract class AbstractRealmServiceTest {
|
||||||
if (!Driver.isRegistered())
|
if (!Driver.isRegistered())
|
||||||
Driver.register();
|
Driver.register();
|
||||||
|
|
||||||
Version dbVersion = DbSchemaVersionCheck.getExpectedDbVersion(PostgreSqlPersistenceHandler.SCRIPT_PREFIX,
|
Version dbVersion = DbSchemaVersionCheck
|
||||||
PostgreSqlPersistenceHandler.class);
|
.getExpectedDbVersion(PostgreSqlPersistenceHandler.SCRIPT_PREFIX, PostgreSqlPersistenceHandler.class);
|
||||||
String sql = DbSchemaVersionCheck.getSql(PostgreSqlPersistenceHandler.SCRIPT_PREFIX,
|
String sql = DbSchemaVersionCheck
|
||||||
PostgreSqlPersistenceHandler.class, dbVersion, "drop"); //$NON-NLS-1$
|
.getSql(PostgreSqlPersistenceHandler.SCRIPT_PREFIX, PostgreSqlPersistenceHandler.class, dbVersion,
|
||||||
|
"drop"); //$NON-NLS-1$
|
||||||
try (Connection connection = DriverManager.getConnection(dbUrl, dbUsername, dbPassword)) {
|
try (Connection connection = DriverManager.getConnection(dbUrl, dbUsername, dbPassword)) {
|
||||||
connection.prepareStatement(sql).execute();
|
connection.prepareStatement(sql).execute();
|
||||||
}
|
}
|
||||||
|
@ -156,10 +159,11 @@ public abstract class AbstractRealmServiceTest {
|
||||||
Class<? extends Service<T, U>> svcClass, Class<?> expectedServiceResultType, T arg, Runner before,
|
Class<? extends Service<T, U>> svcClass, Class<?> expectedServiceResultType, T arg, Runner before,
|
||||||
Runner validator, Runner after) {
|
Runner validator, Runner after) {
|
||||||
try {
|
try {
|
||||||
runTransient(svcClass.newInstance(), expectedServiceResultType, arg, before, validator, after);
|
Constructor<? extends Service<T, U>> constructor = svcClass.getConstructor();
|
||||||
runCached(svcClass.newInstance(), expectedServiceResultType, arg, before, validator, after);
|
runTransient(constructor.newInstance(), expectedServiceResultType, arg, before, validator, after);
|
||||||
runTransactional(svcClass.newInstance(), expectedServiceResultType, arg, before, validator, after);
|
runCached(constructor.newInstance(), expectedServiceResultType, arg, before, validator, after);
|
||||||
} catch (InstantiationException | IllegalAccessException e) {
|
runTransactional(constructor.newInstance(), expectedServiceResultType, arg, before, validator, after);
|
||||||
|
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
|
||||||
throw new RuntimeException("Failed to instantiate class " + svcClass.getName() + ": " + e.getMessage(), e);
|
throw new RuntimeException("Failed to instantiate class " + svcClass.getName() + ": " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue