[Minor] Throw exception if policy is missing proper constructor
This commit is contained in:
parent
b8e2c40df3
commit
abf508cc6b
|
@ -37,17 +37,17 @@ import li.strolch.utils.helper.XmlHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* This is the default Strolch {@link PolicyHandler} which implements {@link PolicyDefVisitor}. This
|
* This is the default Strolch {@link PolicyHandler} which implements {@link PolicyDefVisitor}. This {@link
|
||||||
* {@link PolicyHandler} parses a policy configuration file to handle the look-up of {@link KeyPolicyDef}
|
* PolicyHandler} parses a policy configuration file to handle the look-up of {@link KeyPolicyDef}
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* This {@link StrolchComponent} uses two configuration properties:
|
* This {@link StrolchComponent} uses two configuration properties:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@link #PROP_READ_POLICY_FILE} - Default is false. If false then no configuration file is read. Useful if all
|
* <li>{@link #PROP_READ_POLICY_FILE} - Default is false. If false then no configuration file is
|
||||||
* policy definitions are {@link JavaPolicyDef}</li>
|
* read. Useful if all policy definitions are {@link JavaPolicyDef}</li>
|
||||||
* <li>{@link #PROP_POLICY_CONFIG} - Default is {@link #DEF_STROLCH_POLICIES_XML}. If {@link #PROP_READ_POLICY_FILE} is
|
* <li>{@link #PROP_POLICY_CONFIG} - Default is {@link #DEF_STROLCH_POLICIES_XML}. If {@link
|
||||||
* true, then this property is used to determine which configuration file to parse for the policy key mappings for
|
* #PROP_READ_POLICY_FILE} is true, then this property is used to determine which configuration file to parse for the
|
||||||
* {@link KeyPolicyDef}</li>
|
* policy key mappings for {@link KeyPolicyDef}</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
@ -84,10 +84,12 @@ public class DefaultPolicyHandler extends StrolchComponent implements PolicyHand
|
||||||
|
|
||||||
Class<T> clazz = policyDef.accept(this);
|
Class<T> clazz = policyDef.accept(this);
|
||||||
Constructor<T> constructor = clazz.getConstructor(ComponentContainer.class, StrolchTransaction.class);
|
Constructor<T> constructor = clazz.getConstructor(ComponentContainer.class, StrolchTransaction.class);
|
||||||
|
if (constructor == null)
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Class" + clazz.getName() + " is missing constructor (ComponentContainer, StrolchTransaction)");
|
||||||
return constructor.newInstance(getContainer(), tx);
|
return constructor.newInstance(getContainer(), tx);
|
||||||
|
|
||||||
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
|
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | ClassNotFoundException e) {
|
||||||
| IllegalArgumentException | InvocationTargetException | ClassNotFoundException e) {
|
|
||||||
throw new StrolchPolicyException(
|
throw new StrolchPolicyException(
|
||||||
MessageFormat.format("Failed to instantiate policy {0} due to {1}", policyDef, e.getMessage()), e);
|
MessageFormat.format("Failed to instantiate policy {0} due to {1}", policyDef, e.getMessage()), e);
|
||||||
}
|
}
|
||||||
|
@ -146,9 +148,10 @@ public class DefaultPolicyHandler extends StrolchComponent implements PolicyHand
|
||||||
|
|
||||||
// assert API is a Policy
|
// assert API is a Policy
|
||||||
if (!StrolchPolicy.class.isAssignableFrom(implClass)) {
|
if (!StrolchPolicy.class.isAssignableFrom(implClass)) {
|
||||||
throw new StrolchPolicyException("Invalid " + StrolchPolicyFileParser.POLICY
|
throw new StrolchPolicyException(
|
||||||
+ " configuration for Type=" + type + " Key=" + key + " as " + className
|
"Invalid " + StrolchPolicyFileParser.POLICY + " configuration for Type=" + type
|
||||||
+ " is not a " + StrolchPolicy.class.getName());
|
+ " Key=" + key + " as " + className + " is not a " + StrolchPolicy.class
|
||||||
|
.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!apiClass.isAssignableFrom(implClass)) {
|
if (!apiClass.isAssignableFrom(implClass)) {
|
||||||
|
@ -162,13 +165,15 @@ public class DefaultPolicyHandler extends StrolchComponent implements PolicyHand
|
||||||
this.classByTypeMap.addElement(type, key, (Class<? extends StrolchPolicy>) implClass);
|
this.classByTypeMap.addElement(type, key, (Class<? extends StrolchPolicy>) implClass);
|
||||||
|
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new StrolchPolicyException("Invalid " + StrolchPolicyFileParser.POLICY
|
throw new StrolchPolicyException(
|
||||||
+ " configuration for Type=" + type + " Key=" + key + " due to " + e.getMessage(), e);
|
"Invalid " + StrolchPolicyFileParser.POLICY + " configuration for Type=" + type
|
||||||
|
+ " Key=" + key + " due to " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new StrolchPolicyException("Invalid " + StrolchPolicyFileParser.POLICY_TYPE
|
throw new StrolchPolicyException(
|
||||||
+ " configuration for Type=" + type + " due to " + e.getMessage(), e);
|
"Invalid " + StrolchPolicyFileParser.POLICY_TYPE + " configuration for Type=" + type
|
||||||
|
+ " due to " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue