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

The following examples show how to use org.osgl.util.E#illegalArgumentIf() . 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: RequestHandlerProxy.java    From actframework with Apache License 2.0 6 votes vote down vote up
@Inject
public RequestHandlerProxy(final String actionMethodName, final App app) {
    int pos = actionMethodName.lastIndexOf('.');
    final String ERR = "Invalid controller action: %s";
    E.illegalArgumentIf(pos < 0, ERR, actionMethodName);
    controllerClassName = actionMethodName.substring(0, pos);
    E.illegalArgumentIf(S.isEmpty(controllerClassName), ERR, actionMethodName);
    this.actionMethodName = actionMethodName.substring(pos + 1);
    E.illegalArgumentIf(S.isEmpty(this.actionMethodName), ERR, actionMethodName);
    this.actionPath = actionMethodName;
    if (app.classLoader() != null) {
        cache = app.config().cacheService(CACHE_NAME);
    } else {
        app.jobManager().on(SysEventId.CLASS_LOADER_INITIALIZED, "RequestHandlerProxy[" + actionMethodName + "]:setCache", new Runnable() {
            @Override
            public void run() {
                cache = app.config().cacheService(CACHE_NAME);
            }
        });
    }
    this.app = app;
    this.appInterceptor = app.interceptorManager();
}
 
Example 2
Source File: OptionAnnoInfoBase.java    From actframework with Apache License 2.0 6 votes vote down vote up
public OptionAnnoInfoBase spec(String[] specs) {
    E.illegalArgumentIf(null == specs || specs.length == 0);
    lead1 = specs[0];
    if (specs.length > 1) {
        lead2 = specs[1];
    } else {
        String[] sa = lead1.split("[,;\\s]+");
        if (sa.length > 2) {
            throw E.unexpected("Option cannot have more than two leads");
        }
        if (sa.length > 1) {
            lead1 = sa[0];
            lead2 = sa[1];
        }
    }
    Help.updateMaxWidth(leads().length());
    return this;
}
 
Example 3
Source File: ActErrorResult.java    From actframework with Apache License 2.0 6 votes vote down vote up
@Deprecated
public static Result of(int statusCode) {
    E.illegalArgumentIf(statusCode < 400);
    switch (statusCode) {
        case 400:
            return ActBadRequest.create();
        case 401:
            return ActUnauthorized.create();
        case 403:
            return ActForbidden.create();
        case 404:
            return ActNotFound.create();
        case 405:
            return ActMethodNotAllowed.create();
        case 409:
            return ActConflict.create();
        case 501:
            return ActNotImplemented.create();
        default:
            if (Act.isDev()) {
                return new ActErrorResult(new RuntimeException());
            } else {
                return new ErrorResult(H.Status.of(statusCode));
            }
    }
}
 
Example 4
Source File: EntityId.java    From actframework with Apache License 2.0 6 votes vote down vote up
@Override
public void init(Object param) {
    Class type = null;
    try {
        type = Act.classForName(S.string(param));
    } catch (Exception e) {
        throw new IllegalArgumentException("Class name expected. Found: " + param);
    }
    App app = Act.app();
    EntityFieldMetaInfo fieldMetaInfo = null;
    for (EntityMetaInfoRepo repo : app.entityMetaInfoRepo().allRepos()) {
        EntityClassMetaInfo metaInfo = repo.classMetaInfo(type);
        if (null != metaInfo) {
            fieldMetaInfo = metaInfo.idField();
        }
    }
    E.illegalArgumentIf(null == fieldMetaInfo, "Cannot find ID field of class: " + type);
    String fieldName = fieldMetaInfo.fieldName();
    idFieldClass = $.fieldOf(type, fieldName).getType();
    isPrimitive = $.isPrimitiveType(idFieldClass);
}
 
Example 5
Source File: Tags.java    From actframework with Apache License 2.0 6 votes vote down vote up
@Override
protected void call(__ParameterList params, __Body body) {
    int paramSize = params.size();
    E.illegalArgumentIf(paramSize < 1);
    String msg = params.get(0).value.toString();
    Object[] args;
    if (paramSize > 1) {
        args = new Object[paramSize - 1];
        for (int i = 1; i < paramSize; ++i) {
            args[i - 1] = params.get(i).value;
        }
    } else {
        args = new Object[0];
    }
    p(I18n.i18n(act_messages.class, msg, args));
}
 
Example 6
Source File: CommandLineParser.java    From actframework with Apache License 2.0 6 votes vote down vote up
public CommandLineParser(String line) {
    E.illegalArgumentIf(S.blank(line));
    raw = line.trim();
    options = new HashMap<>();
    List<String> sl = new ArrayList<>();
    Pattern ptn = choosePattern(raw);
    Matcher m = ptn.matcher(raw);
    while (m.find()) {
        String s = m.group(1);
        if (ptn == P_QUOTATION) {
            s = S.strip(s, "\"", "\"");
        } else {
            s = S.strip(s, "\'", "\'");
        }
        sl.add(s);
    }
    parse(sl);
}
 
Example 7
Source File: ActErrorResult.java    From actframework with Apache License 2.0 5 votes vote down vote up
public static ErrorResult of(H.Status status) {
    E.illegalArgumentIf(!status.isClientError() && !status.isServerError());
    if (Act.isDev()) {
        return new ActErrorResult(status);
    } else {
        return ErrorResult.of(status);
    }
}
 
Example 8
Source File: StringValueResolverValueLoaderBase.java    From actframework with Apache License 2.0 5 votes vote down vote up
public StringValueResolverValueLoaderBase(ParamKey key, DefaultValue def, BeanSpec spec, boolean simpleKeyOnly) {
    E.illegalArgumentIf(simpleKeyOnly && !key.isSimple());
    this.paramSpec = spec;
    this.param = spec.getAnnotation(Param.class);
    this.paramKey = key;
    this.defSpec = def;
    this.resolverManager = Act.app().resolverManager();
    this.injector = Act.app().injector();
    this.requireRuntimeType = !(spec.type() instanceof Class);
    this.stringValueResolver = this.requireRuntimeType ? null : lookupResolver(spec, spec.rawType());
    this.defVal = this.requireRuntimeType ? null : null != def ? this.stringValueResolver.resolve(def.value()) : defVal(param, spec.rawType());
}
 
Example 9
Source File: StringValueResolverValueLoaderBase.java    From actframework with Apache License 2.0 5 votes vote down vote up
protected StringValueResolverValueLoaderBase(ParamKey key, DefaultValue def, StringValueResolver resolver, BeanSpec paramSpec, boolean simpleKeyOnly) {
    E.illegalArgumentIf(simpleKeyOnly && !key.isSimple());
    this.paramSpec = paramSpec;
    this.param = paramSpec.getAnnotation(Param.class);
    this.paramKey = key;
    this.defSpec = def;
    this.resolverManager = Act.app().resolverManager();
    this.injector = Act.app().injector();
    this.requireRuntimeType = false;
    this.stringValueResolver = resolver;
    this.defVal = null != def ? this.stringValueResolver.resolve(def.value()) : defVal(param, paramSpec.rawType());
}
 
Example 10
Source File: Tags.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
protected void call(__ParameterList params, __Body body) {
    int paramSize = params.size();
    E.illegalArgumentIf(paramSize < 1);
    String field = params.get(0).value.toString();
    ConstraintViolation violation = ActContext.Base.currentContext().violation(field);
    if (null != violation) {
        p(violation.getMessage());
    }
}
 
Example 11
Source File: ThrottleFilter.java    From actframework with Apache License 2.0 5 votes vote down vote up
public ThrottleFilter(int throttle, boolean expireScale) {
    E.illegalArgumentIf(throttle < 1);
    this.throttle = throttle;
    this.expireScale = expireScale;
    final App app = Act.app();
    app.jobManager().on(SysEventId.CLASS_LOADER_INITIALIZED, "ThrottleFilter:initCache", new Runnable() {
        @Override
        public void run() {
            cache = app.cache(CACHE_NAME);
        }
    }, true);
}
 
Example 12
Source File: Tags.java    From actframework with Apache License 2.0 5 votes vote down vote up
private String inferFullPath(String actionPath) {
    E.illegalArgumentIf(S.empty(actionPath), "action path expected");
    if (actionPath.contains("/") || (!actionPath.contains(".") && !actionPath.contains("("))) {
        // this is a URL path, not action path
        return actionPath;
    }
    if (actionPath.contains("(")) {
        actionPath = org.osgl.util.S.beforeFirst(actionPath, "(");
    }
    return Router.inferFullActionPath(actionPath, INFER_REFERENCE_PROVIDER);
}
 
Example 13
Source File: JobTrigger.java    From actframework with Apache License 2.0 4 votes vote down vote up
_Periodical(long seconds, boolean startImmediately) {
    super(false);
    E.illegalArgumentIf(seconds < 1, "delay duration cannot be zero or negative");
    this.seconds = seconds;
    this.startImmediately = startImmediately;
}
 
Example 14
Source File: JobTrigger.java    From actframework with Apache License 2.0 4 votes vote down vote up
static JobTrigger of(AppConfig config, InvokeBefore anno) {
    String id = anno.value();
    E.illegalArgumentIf(S.blank(id), "associate job ID cannot be empty");
    return new _Before(id);
}
 
Example 15
Source File: NewInstanceTest.java    From java-tool with Apache License 2.0 4 votes vote down vote up
public Foo(int i) throws IllegalArgumentException {
    E.illegalArgumentIf(i < 0);
}
 
Example 16
Source File: ParamAnnoInfoTraitBase.java    From actframework with Apache License 2.0 4 votes vote down vote up
protected ParamAnnoInfoTraitBase(int index) {
    E.illegalArgumentIf(index < 0);
    this.index = index;
}
 
Example 17
Source File: ParamKey.java    From actframework with Apache License 2.0 4 votes vote down vote up
static ParamKey of(String[] seq) {
    E.illegalArgumentIf(seq.length == 0);
    return new ParamKey(seq);
}
 
Example 18
Source File: CORS.java    From actframework with Apache License 2.0 4 votes vote down vote up
private Spec(Collection<H.Method> methodSet) {
    E.illegalArgumentIf(methodSet.isEmpty());
    methods = S.join(", ", C.list(methodSet).map($.F.<H.Method>asString()));
    effective = true;
}
 
Example 19
Source File: JobTrigger.java    From actframework with Apache License 2.0 4 votes vote down vote up
_AssociatedTo(String targetId) {
    super(null);
    E.illegalArgumentIf(S.blank(targetId), "associate job ID expected");
    this.targetId = targetId;
}
 
Example 20
Source File: VarDef.java    From actframework with Apache License 2.0 2 votes vote down vote up
/**
 * Construct an implicit variable by name and type
 *
 * @param name the name of the variable. Could be referenced in
 *             view template to get the variable
 * @param type the type of the variable. Some view solution e.g.
 *             Rythm needs to explicitly declare the template
 *             arguments. And type information is used by those
 *             static template engines
 */
protected VarDef(String name, Class<?> type) {
    E.illegalArgumentIf(S.blank(name), "VarDef name cannot be empty");
    this.name = name;
    this.type = type.getCanonicalName().replace('$', '.');
}