class IdentityScriptValueGenerator extends AbstractValueGenerator<IdmIdentityDto> {

	@Override
	public IdmIdentityDto generate(IdmIdentityDto dto, IdmGenerateValueDto valueGenerator) {
		Assert.notNull(dto, "DTO is required.");
		Assert.notNull(valueGenerator, "Value generator is required.");
		//
		String scriptCode = getScriptCode(valueGenerator);
		Object returnValue = systemScriptEvaluator.evaluate(new AbstractScriptEvaluator.Builder()
				.setScriptCode(scriptCode)
				.addParameter(ENTITY_KEY, dto)
				.addParameter(VALUE_GENERATOR_KEY, valueGenerator));
		//
		if (returnValue == null || !(returnValue instanceof IdmIdentityDto)) {
			throw new ResultCodeException(CoreResultCode.GENERATOR_SCRIPT_RETURN_NULL_OR_BAD_DTO_TYPE,
					ImmutableMap.of(
							"scriptCode", scriptCode == null ? "null" : scriptCode,
							"returnedValue", returnValue == null ? "null" : returnValue));
		}
		//
		return (IdmIdentityDto) returnValue;

	}

}