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

The following examples show how to use org.osgl.util.E#illegalStateIf() . 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: Tags.java    From actframework with Apache License 2.0 6 votes vote down vote up
@Override
public String apply() throws NotAppliedException, $.Break {
    ActContext context = ActContext.Base.currentContext();
    E.illegalStateIf(null == context, "Cannot get full action path reference outside of act context");
    /*
     * try to determine if the template is free or bounded template
     */
    if (context.templatePathIsImplicit()) {
        return context.methodPath();
    } else {
        String path = context.templatePath();
        path = org.osgl.util.S.beforeLast(path, ".");
        if (!isTemplateBounded(path, context.methodPath())) {
            return context.methodPath();
        }
        return path.replace('/', '.');
    }
}
 
Example 2
Source File: ActError.java    From actframework with Apache License 2.0 6 votes vote down vote up
public static SourceInfo loadSourceInfo(StackTraceElement[] stackTraceElements, Class<? extends ActError> errClz) {
    E.illegalStateIf(Act.isProd());
    DevModeClassLoader cl = (DevModeClassLoader) App.instance().classLoader();
    String errClzName = errClz.getName();
    for (StackTraceElement stackTraceElement : stackTraceElements) {
        int line = stackTraceElement.getLineNumber();
        if (line <= 0) {
            continue;
        }
        String className = stackTraceElement.getClassName();
        if (S.eq(className, errClzName)) {
            continue;
        }
        Source source = cl.source(className);
        if (null == source) {
            continue;
        }
        return new SourceInfoImpl(source, line);
    }
    return null;
}
 
Example 3
Source File: ReflectedInvokerHelper.java    From actframework with Apache License 2.0 6 votes vote down vote up
public static Annotation[][] requestHandlerMethodParamAnnotations(Method method) {
    if (!ApiManager.inProgress() && null == ActionContext.current()) {
        return method.getParameterAnnotations();
    }
    Annotation[][] paramAnnotations = requestHandlerMethodParamAnnotationCache.get(method);
    if (null == paramAnnotations) {
        boolean searchForOverwrittenMethod = false;
        RoutedContext ctx = RoutedContext.Current.get();
        if (null != ctx) {
            searchForOverwrittenMethod = RouteSource.ACTION_ANNOTATION == ctx.routeSource() && !hasActionAnnotation(method);
        } else {
            E.illegalStateIf(null == JobContext.current(), "Unable to detected current RoutedContext");
        }
        if (searchForOverwrittenMethod) {
            Method overwrittenMethod = overwrittenMethodOf(method);
            paramAnnotations = overwrittenMethod == method ? method.getParameterAnnotations() : requestHandlerMethodParamAnnotations(overwrittenMethod);
        } else {
            paramAnnotations = method.getParameterAnnotations();
        }
        requestHandlerMethodParamAnnotationCache.put(method, paramAnnotations);
    }
    return paramAnnotations;
}
 
Example 4
Source File: JobMethodMetaInfo.java    From actframework with Apache License 2.0 5 votes vote down vote up
public List<JobMethodMetaInfo> extendedJobMethodMetaInfoList(App app) {
    E.illegalStateIf(!classInfo().isAbstract(), "this job method meta info is not abstract");
    final List<JobMethodMetaInfo> list = new ArrayList<>();
    final JobClassMetaInfo clsInfo = classInfo();
    String clsName = clsInfo.className();
    ClassNode node = app.classLoader().classInfoRepository().node(clsName);
    if (null == node) {
        return list;
    }
    final JobMethodMetaInfo me = this;
    node.visitTree(new $.Visitor<ClassNode>() {
        @Override
        public void visit(ClassNode classNode) throws $.Break {
            if (!classNode.isAbstract() && classNode.isPublic()) {
                JobClassMetaInfo subClsInfo = new JobClassMetaInfo().className(classNode.name());
                JobMethodMetaInfo subMethodInfo = new JobMethodMetaInfo(subClsInfo, JobMethodMetaInfo.this);
                if (me.isStatic()) {
                    subMethodInfo.invokeStaticMethod();
                } else {
                    subMethodInfo.invokeInstanceMethod();
                }
                subMethodInfo.name(me.name());
                subMethodInfo.returnType(me.returnType());
                list.add(subMethodInfo);
            }
        }
    });
    return list;
}
 
Example 5
Source File: ReflectedJobInvoker.java    From actframework with Apache License 2.0 5 votes vote down vote up
private Object[] params(Object job, JobContext ctx) {
    if (null != paramValueLoaderService) {
        return paramValueLoaderService.loadMethodParams(job, method, ctx);
    }
    E.illegalStateIf(paramTypes().length > 0, "Cannot invoke job with parameters before app fully started");
    return new Object[0];
}
 
Example 6
Source File: ActProvider.java    From actframework with Apache License 2.0 5 votes vote down vote up
private Class<T> exploreTypeInfo() {
    List<Type> types = Generics.typeParamImplementations(getClass(), ActProvider.class);
    int sz = types.size();
    E.illegalStateIf(1 != sz, "generic type number not match");
    Type type = types.get(0);
    E.illegalArgumentIf(!(type instanceof Class), "generic type is not a class: %s", type);
    return (Class) type;
}
 
Example 7
Source File: SenderMethodMetaInfo.java    From actframework with Apache License 2.0 5 votes vote down vote up
public SenderMethodMetaInfo addLocal(LocalVariableMetaInfo local) {
    Label start = local.start();
    Map<Integer, LocalVariableMetaInfo> m = locals.get(start);
    if (null == m) {
        m = new HashMap<>();
        locals.put(start, m);
    }
    int index = local.index();
    E.illegalStateIf(m.containsKey(index), "Local variable index conflict");
    m.put(local.index(), local);
    return this;
}
 
Example 8
Source File: HeaderValueLoader.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
public Object get() {
    if (ApiManager.inProgress()) {
        return null;
    }
    ActionContext ctx = ActionContext.current();
    E.illegalStateIf(null == ctx, "Not in request handling context");
    return $.convert(ctx.req().header(headerName)).to(targetType);
}
 
Example 9
Source File: EndpointTester.java    From actframework with Apache License 2.0 5 votes vote down vote up
protected Request.Builder req()  {
    if (null == req) {
        E.illegalStateIf(null == reqBuilder, "Please make sure url(String, Object...) method called first");
        req = reqBuilder.build();
    }
    return req;
}
 
Example 10
Source File: ActError.java    From actframework with Apache License 2.0 5 votes vote down vote up
private static SourceInfo loadSourceInfo(String className, String elementName, boolean isMethod, Integer lineNo) {
    E.illegalStateIf(Act.isProd());
    DevModeClassLoader cl = (DevModeClassLoader) App.instance().classLoader();
    Source source = cl.source(className);
    if (null == source) {
        return null;
    }
    List<String> lines = source.lines();
    Line candidate = null;
    String pattern = isMethod ?
            S.concat("^\\s*.*", elementName, "\\s*\\(.*") :
            S.concat("^\\s*.*", elementName, "[^\\(\\{]*");
    if (null != lineNo) {
        return new SourceInfoImpl(source, lineNo);
    }
    for (int i = 0; i < lines.size(); ++i) {
        String line = lines.get(i);
        if (line.matches(pattern)) {
            candidate = new Line(line, i + 1);
            if (candidate.forSure) {
                return new SourceInfoImpl(source, candidate.no);
            }
        }
    }
    if (null != candidate) {
        return new SourceInfoImpl(source, candidate.no);
    }
    return new SourceInfoImpl(source, 1);
}
 
Example 11
Source File: ByteCodeVisitor.java    From actframework with Apache License 2.0 5 votes vote down vote up
public ByteCodeVisitor commitDownstream() {
    if (null == _cv && null != cv && cv instanceof ByteCodeVisitor) {
        ((ByteCodeVisitor) cv).commitDownstream();
        return this;
    }
    E.illegalStateIf(null == _cv || null != cv);
    cv = _cv.get();
    return this;
}
 
Example 12
Source File: YamlLoader.java    From actframework with Apache License 2.0 5 votes vote down vote up
protected File getFile(String name) {
    App app = Act.app();
    if (null == app) {
        // must doing unit testing
        return null;
    }
    E.illegalStateIf(null == app, "App instance not found");
    // try new location first
    File file = app.testResource(patchResourceName(name));
    if (file.exists()) {
        return file;
    }
    file = app.resource(patchResourceNameWithLegacyFixtureFolder(name));
    return file.exists() ? file : null;
}
 
Example 13
Source File: GenieInjector.java    From actframework with Apache License 2.0 4 votes vote down vote up
public void addModule(Object module) {
    E.illegalStateIf(null != genie);
    modules.add(module);
}
 
Example 14
Source File: Gh1016.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public String get() {
    ActionContext context = ActionContext.current();
    E.illegalStateIf(null == context);
    return context.req().ip();
}
 
Example 15
Source File: ByteCodeVisitor.java    From actframework with Apache License 2.0 4 votes vote down vote up
public ByteCodeVisitor setDownstream(ClassVisitor cv) {
    E.illegalStateIf(null != this.cv);
    this.cv = cv;
    return this;
}
 
Example 16
Source File: EntityClassMetaInfo.java    From actframework with Apache License 2.0 4 votes vote down vote up
void createdByField(EntityFieldMetaInfo fieldInfo) {
    E.illegalStateIf(null != createdByField, "createdBy field already set");
    this.createdByField = $.requireNotNull(fieldInfo);
}
 
Example 17
Source File: EntityClassMetaInfo.java    From actframework with Apache License 2.0 4 votes vote down vote up
void createdAtField(EntityFieldMetaInfo fieldInfo) {
    E.illegalStateIf(null != createdAtField, "createdAt field already set");
    this.createdAtField = $.requireNotNull(fieldInfo);
}
 
Example 18
Source File: PasswordMetaInfo.java    From actframework with Apache License 2.0 4 votes vote down vote up
public String singlePasswordFieldName() {
    E.illegalStateIf(!isSinglePasswordProvider());
    return passwordFields.keySet().iterator().next();
}
 
Example 19
Source File: WebSocketConnectionListener.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public void onClose(WebSocketContext context) {
    E.illegalStateIf(null == realListener);
    realListener.onClose(context);
}
 
Example 20
Source File: WebSocketConnectionListener.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public void onConnect(WebSocketContext context) {
    E.illegalStateIf(null == realListener);
    realListener.onConnect(context);
}