Java Code Examples for org.osgl.util.E#invalidConfiguration()

The following examples show how to use org.osgl.util.E#invalidConfiguration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobAnnotationProcessor.java    From actframework with Apache License 2.0 6 votes vote down vote up
private String evaluateExpression(String expression, Class<? extends Annotation> annoClass) {
    String prefix = annoClass.getSimpleName();
    if (S.eq(FixedDelay.class.getName(), prefix)) {
        prefix = "fixed-delay";
    } else {
        prefix = prefix.toLowerCase();
    }
    String ret = expression.trim();
    if (ret.startsWith(prefix)) {
        ret = (String) app().config().get(expression);
        if (S.blank(ret)) {
            throw E.invalidConfiguration("Expression configuration not found: %s", expression);
        }
    }
    return ret;
}
 
Example 2
Source File: MailerConfig.java    From actframework with Apache License 2.0 6 votes vote down vote up
private String getPortConfig(Map<String, String> properties) {
    String port = getProperty(SMTP_PORT, properties);
    if (null == port) {
        if (!useSsl && !useTls) {
            port = "25";
        } else if (useSsl) {
            port = "465";
        } else {
            port = "587";
        }
        warn("No smtp.port found for mailer[%s] configuration will use the default number: ", id, port);
    } else {
        try {
            Integer.parseInt(port);
        } catch (Exception e) {
            throw E.invalidConfiguration("Invalid port configuration for mailer[%]: %s", id, port);
        }
    }
    return port;
}
 
Example 3
Source File: AutoConfigPlugin.java    From actframework with Apache License 2.0 6 votes vote down vote up
private void loadAutoConfig_(Field f, String ns) {
    String key = ns + "." + f.getName();
    Object val = conf.getIgnoreCase(key);
    if (null == val) {
        // try to change the "prefix.key_x_an_y" form to "prefix.key.x.an.y" form
        key = key.replace('_', '.');
        val = conf.getIgnoreCase(key);
        if (null == val) {
            return;
        }
    }
    BeanSpec spec = BeanSpec.of(f, injector);
    try {
        setField(f, null, key, val, spec);
    } catch (Exception e) {
        throw E.invalidConfiguration(e, "Error get configuration " + key + ": " + e.getMessage());
    }
}
 
Example 4
Source File: Module.java    From java-di with Apache License 2.0 5 votes vote down vote up
private void validate(Genie genie) {
    Map<Object, Binder> map = C.newMap();
    for (Binder<?> binder : binders) {
        Object spec = binder.beanSpec(genie);
        if (map.containsKey(spec)) {
            throw E.invalidConfiguration("Duplicate bean spec found: ", spec);
        }
        map.put(spec, binder);
    }
}
 
Example 5
Source File: JobTrigger.java    From actframework with Apache License 2.0 5 votes vote down vote up
static JobTrigger of(AppConfig config, Cron anno) {
    String v = anno.value();
    if (v.startsWith("cron.")) {
        v = (String) config.get(v);
    } else if (v.startsWith("${") && v.endsWith("}")) {
        v = v.substring(2, v.length() - 1);
        v = (String) config.get(v);
    }
    if (S.blank(v)) {
        throw E.invalidConfiguration("Cannot find configuration for cron: %s", anno.value());
    }
    return cron(v);
}
 
Example 6
Source File: JobTrigger.java    From actframework with Apache License 2.0 5 votes vote down vote up
static JobTrigger of(AppConfig config, FixedDelay anno) {
    String delay = anno.value();
    if (delay.startsWith("delay.")) {
        delay = (String) config.get(delay);
    } else if (delay.startsWith("${") && delay.endsWith("}")) {
        delay = delay.substring(2, delay.length() - 1);
        delay = (String) config.get(delay);
    }
    if (S.blank(delay)) {
        throw E.invalidConfiguration("Cannot find configuration for delay: %s", anno.value());
    }
    return fixedDelay(delay, anno.startImmediately());
}
 
Example 7
Source File: JobTrigger.java    From actframework with Apache License 2.0 5 votes vote down vote up
static JobTrigger of(AppConfig config, Every anno) {
    String duration = anno.value();
    if (duration.startsWith("every.")) {
        duration = (String) config.get(duration);
    } else if (duration.startsWith("${") && duration.endsWith("}")) {
        duration = duration.substring(2, duration.length() - 1);
        duration = (String) config.get(duration);
    }
    if (S.blank(duration)) {
        throw E.invalidConfiguration("Cannot find configuration for duration: %s", anno.value());
    }
    return every(duration, anno.startImmediately());
}
 
Example 8
Source File: MailerConfig.java    From actframework with Apache License 2.0 5 votes vote down vote up
private InternetAddress getFromConfig(Map<String, String> properties) {
    String s = getProperty(FROM, properties);
    if (null == s) {
        return null;
    }
    try {
        InternetAddress[] ia = InternetAddress.parse(s);
        if (null == ia || ia.length == 0) return null;
        return ia[0];
    } catch (AddressException e) {
        throw E.invalidConfiguration(e, "invalid mailer from address: %s", s);
    }

}
 
Example 9
Source File: CliDispatcher.java    From actframework with Apache License 2.0 5 votes vote down vote up
public CliDispatcher registerCommandHandler(String command, CommandMethodMetaInfo methodMetaInfo, CommanderClassMetaInfo classMetaInfo) {
    String sa[] = command.split(CommanderClassMetaInfo.NAME_SEPARATOR);
    for (String s : sa) {
        if (registry.containsKey(s)) {
            throw E.invalidConfiguration("Command %s already registered", command);
        }
        addToRegistry(s, new CliHandlerProxy(classMetaInfo, methodMetaInfo, app()));
        logger.debug("Command registered: %s", s);
    }
    return this;
}
 
Example 10
Source File: ActConfig.java    From actframework with Apache License 2.0 4 votes vote down vote up
private static void validateDir(File dir, String conf) {
    if (!dir.exists() || !dir.isDirectory() || !dir.canRead()) {
        E.invalidConfiguration("%s is not a valid directory: %s", conf, dir.getAbsolutePath());
    }
}