Java Code Examples for org.osgl.util.E#unexpectedIf()
The following examples show how to use
org.osgl.util.E#unexpectedIf() .
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: StringValueResolverManager.java From actframework with Apache License 2.0 | 6 votes |
public <T> StringValueResolver<T> arrayResolver(final Class<T> targetType, final char separator) { final Class<?> componentType = targetType.getComponentType(); E.unexpectedIf(null == componentType, "specified target type is not array type: " + targetType); final StringValueResolver elementResolver = resolver(componentType); return new StringValueResolver<T>(targetType) { @Override public T resolve(String value) { List list = new ArrayList(); List<String> parts = S.fastSplit(value, String.valueOf(separator)); for (String part : parts) { list.add(elementResolver.resolve(part)); } T array = (T) Array.newInstance(componentType, list.size()); return (T)list.toArray((Object[])array); } }; }
Example 2
Source File: ConfigResourceLoader.java From actframework with Apache License 2.0 | 6 votes |
@Override protected void initialized() { String path = (String) options.get("value"); E.unexpectedIf(S.blank(path), "resource path not specified"); while (path.startsWith("/")) { path = path.substring(1); } if (path.startsWith("config/")) { path = path.substring(7); } resource = ResourceLoader._load(profileConfig(path), spec, hint, true); if (null == resource) { resource = ResourceLoader._load(commonConfig(path), spec, hint, true); } if (null == resource) { resource = ResourceLoader._load(confConfig(path), spec, hint, true); } if (null == resource) { resource = ResourceLoader._load(path, spec, hint, true); } if (null == resource && !ignoreResourceNotFound) { LOGGER.warn("config resource not found: %s", path); } }
Example 3
Source File: Interaction.java From actframework with Apache License 2.0 | 6 votes |
@Override public void validate(TestSession session) throws UnexpectedException { E.unexpectedIf(null == request, "request spec not specified in interaction[%s]", this); //E.unexpectedIf(null == response, "response spec not specified"); act.metric.Timer timer = metric.startTimer("validate"); try { request.resolveParent(session.requestTemplateManager); request.validate(this); if (null != response) { response.validate(this); } reset(); } finally { timer.stop(); } }
Example 4
Source File: ImplicitVariableProvider.java From actframework with Apache License 2.0 | 5 votes |
private void initLoaders(App app) { java.lang.reflect.Type[] types = method.getGenericParameterTypes(); int len = types.length; ParamValueLoader[] loaders = new ParamValueLoader[len]; if (0 < len) { GenieInjector injector = app.injector(); Annotation[][] annos = method.getParameterAnnotations(); for (int i = 0; i < len; ++i) { java.lang.reflect.Type type = types[i]; Annotation[] aa = annos[i]; BeanSpec spec = BeanSpec.of(type, aa, injector); E.unexpectedIf(!injector.isProvided(spec), ""); loaders[i] = ProvidedValueLoader.get(spec, injector); if (spec.isInstanceOf(ActionContext.class) || requireAction(type)) { supportAction = true; } else if (spec.isInstanceOf(MailerContext.class)) { supportMailer = true; } } } if (!supportAction && !supportMailer) { supportAction = true; supportMailer = true; } this.loaders = loaders; this.paramLen = len; }
Example 5
Source File: HelpPage.java From actframework with Apache License 2.0 | 5 votes |
private Map<String, String> getCmdParamInfo(CliHandlerProxy proxy, Set<String> multiLinesParams) { CommandExecutor executor = proxy.executor(); Class<?> host = $.getProperty(executor, "commanderClass"); Method method = $.getProperty(executor, "method"); Map<String, String> map = new TreeMap<>(); Class<?>[] paramTypes = method.getParameterTypes(); Annotation[][] paramAnns = method.getParameterAnnotations(); for (int i = 0; i < paramTypes.length; ++i) { Class<?> pt = paramTypes[i]; Named named = _getAnno(paramAnns, i, Named.class); E.unexpectedIf(null == named, "Cannot find name of the param: %s.%s(%s|%s)", host.getSimpleName(), method.getName(), i, pt.getSimpleName()); String pn = named.value(); if (null != _getAnno(paramAnns, i, MultiLines.class)) { multiLinesParams.add(pn); } Required required = _getAnno(paramAnns, i, Required.class); if (null != required) { map.put(pn, helpOf(required)); } else { act.cli.Optional optional = _getAnno(paramAnns, i, act.cli.Optional.class); if (null != optional) { String help = helpOf(optional); map.put(pn, help); } else { map.put(pn, "no help"); } } } return map; }
Example 6
Source File: AppBuilder.java From actframework with Apache License 2.0 | 5 votes |
private File verifyDir(File dir, String label, boolean create) { if (create && !dir.exists()) { E.unexpectedIf(!dir.mkdirs(), "Cannot create %s dir %s for %s", dir, label, app); return dir; } E.unexpectedIf(!dir.isDirectory(), "%s %s is not a directory", label, dir); E.unexpectedIf(!dir.canRead(), "Cannot read %s dir %s", label, dir); E.unexpectedIf(!dir.canWrite(), "Cannot write %s dir %s", label, dir); return dir; }
Example 7
Source File: HeaderValueLoader.java From actframework with Apache License 2.0 | 5 votes |
@Override public void init(Map<String, Object> map, BeanSpec beanSpec) { this.headerName = (String) map.get("value"); if (S.blank(headerName)) { this.headerName = beanSpec.name(); } E.unexpectedIf(S.blank(headerName), "header name not found"); this.headerName = Keyword.of(this.headerName).httpHeader(); this.targetType = beanSpec.rawType(); }
Example 8
Source File: SessionValueLoader.java From actframework with Apache License 2.0 | 5 votes |
@Override public void init(Map<String, Object> map, BeanSpec beanSpec) { this.sessionKey = (String) map.get("value"); if (S.blank(this.sessionKey)) { this.sessionKey = beanSpec.name(); } E.unexpectedIf(S.blank(this.sessionKey), "session key not found"); this.targetType = beanSpec.rawType(); }
Example 9
Source File: NamedLogicRegister.java From actframework with Apache License 2.0 | 5 votes |
void register(Keyword keyword, NamedLogic logic, boolean force) { Class<? extends NamedLogic> type = logic.type(); Map<Keyword, NamedLogic> lookup = registry.get(type); if (null == lookup) { lookup = new HashMap<>(); registry.put(type, lookup); } NamedLogic existing = lookup.put(keyword, logic); E.unexpectedIf(!force && null != existing && logic != existing, "Keyword already used: " + keyword.hyphenated()); }
Example 10
Source File: ImplicitVariableProvider.java From actframework with Apache License 2.0 | 4 votes |
private void register(Meta meta, App app) { Class<?> cls = app.classForName(meta.className); Method method = findMethod(cls, meta.methodName); E.unexpectedIf(null == method, "Unable to find method %s", meta); register(meta, cls, method, app); }
Example 11
Source File: BootstrapClassLoaderTestRunner.java From actframework with Apache License 2.0 | 4 votes |
private static File ensureDir(File root, String dir) { File file = new File(root, dir); E.unexpectedIf(!file.exists() && !file.mkdirs(), "Cannot create act dir: %s", file.getAbsolutePath()); return file; }
Example 12
Source File: JavaNames.java From actframework with Apache License 2.0 | 3 votes |
/** * Returns package name of a class * * @param clazz * the class * @return * the package name of the class */ public static String packageNameOf(Class<?> clazz) { String name = clazz.getName(); int pos = name.lastIndexOf('.'); E.unexpectedIf(pos < 0, "Class does not have package: " + name); return name.substring(0, pos); }