/** * Assert this instance is attached to a HTTP servlet request. * * @throws BugError if this instance is not attached. * @see #attached */ private void assertAttached() { if (!attached) { throw new BugError("Attempt to use request context outside HTTP request thread."); } } }
/** * Get named child string value or null if child not found or it has no value. * * @param name name of the child to retrieve value from. * @return named child string value, possible null. */ public String getChildValue(String name) { Config child = getChild(name); return child != null ? child.getValue() : null; }
/** * Construct a looper instance operating in <code>continuous</code> modes. {@link Looper#loop()} implementation should * wait for some IO events or explicit sleep to avoid abusing the thread. */ protected AbstractLooper() { this.thread = new LooperThread(this); }
/** * Return instance type loaded from class descriptor, <code>type</code> attribute. If type is not defined uses * {@link InstanceType#POJO} as default value. * * @param descriptor managed class descriptor. * @return loaded instance type. * @throws ConfigException if there is no {@link InstanceFactory} registered for loaded instance type. */ private InstanceType loadInstanceType(Config descriptor) throws ConfigException { InstanceType instanceType = descriptor.getAttribute("type", InstanceType.class, InstanceType.POJO); if (!container.hasInstanceFactory(instanceType)) { throw new ConfigException("Not registered managed instance type value |%s|. See class descriptor |%s|.", instanceType, descriptor); } return instanceType; }
@Override public Config build() throws ConfigException { Config config = new Config("i18n-repository"); config.setProperty("multi-locale", multiLocale); config.setProperty("base-dir", baseDir); config.setProperty("sub-path", subpath); config.setProperty("files-pattern", filesPattern); return config; } }
@Override public void run() { try { onPreExecute(); Value value = execute(); onPostExecute(value); } catch (Throwable throwable) { onThrowable(throwable); } } });
/** * Get configuration object property value or default value if there is no property with requested name. * * @param name property name, * @param defaultValue default value. * @return configuration object property value or given default value. * @throws IllegalArgumentException if <code>name</code> argument is null or empty. */ public String getProperty(String name, String defaultValue) { String value = getProperty(name); return value != null ? value : defaultValue; }
/** * Test constructor creates and empty configuration object with given name. * * @param configName configuration object name. */ protected TinyConfigBuilder(String configName) { config = new Config(configName); }
/** * Stop looper thread. This pre-destroy hook just stops this looper thread. Subclass may need to defined specific * clean-up logic. It can override this hook but should explicitly invoke super. Otherwise looper thread is not * stopped and runs indefinitely. * * @throws Exception exceptions from application defined clean-up logic are bubbled up. */ @Override public void preDestroy() throws Exception { thread.stop(); } }
/** Dump configuration object tree to standard out, for debugging purposes. */ public void dump() { print(this, 0); }
/** * Start looper thread. This post-construct hook just starts this looper thread. Subclass may need to add application * specific initialization and override this method but should explicitly invoke super. Otherwise looper thread is not * started. * * @throws Exception exceptions from application defined post-construct logic are bubbled up. */ @Override public void postConstruct() throws Exception { thread.start(); }
/** * Task returned value handler. This hook is executed after task logic execution and its default action is to delegate * {@link #callback}, of course if one supplied to constructor. * * @param value value returned by task logic. */ protected void onPostExecute(Value value) { if (callback != null) { callback.handle(value); } }
@Override public ArgumentPartReader getArgumentPartReader(String contentType, Type parameterType) { ArgumentsReader reader = getArgumentsReader(contentType, parameterType); if (!(reader instanceof ArgumentPartReader)) { throw new IllegalArgumentException("Invalid content type for mixed part. Content type |%s| not supported.", contentType); } return (ArgumentPartReader) reader; }
@Override public String getRequestPath() { if (!remotelyAccessible) { throw new BugError("Attempt to retrieve request URI path from local managed method |%s|.", this); } return requestPath; }
/** * Load remote class URL from class descriptor, <code>url</code> attribute. This getter does not perform URL validation; it * returns URL value as declared by attribute. * * @param descriptor class descriptor. * @return remote class URL value. * @throws ConfigException if instance type is {@link InstanceType#REMOTE} and <code>url</code> attribute is missing. */ private String loadImplementationURL(Config descriptor) throws ConfigException { String implementationURL = descriptor.getAttribute("url"); if (instanceType.equals(InstanceType.REMOTE) && implementationURL == null) { throw new ConfigException("Remote managed class requires <url> attribute. See class descriptor |%s|.", descriptor); } return implementationURL; }
/** * Get configuration object property converter to requested type or null if there is no property with given name. * * @param name property name. * @param type type to convert property value to. * @param <T> value type. * @return newly created value object or null. * @throws IllegalArgumentException if <code>name</code> argument is null or empty. * @throws IllegalArgumentException if <code>type</code> argument is null. * @throws ConverterException if there is no converter registered for value type or value parse fails. */ public <T> T getProperty(String name, Class<T> type) { return getProperty(name, type, null); }
@Override public Class<?> getInterfaceClass() { if (interfaceClasses.length > 1) { throw new BugError("Attempt to treat multiple interfaces as a single one."); } return interfaceClasses[0]; }
/** * Return instance scope loaded from class descriptor, <code>scope</code> attribute. If scope is not defined use * {@link InstanceScope#APPLICATION} as default value. * * @param descriptor managed class descriptor. * @return loaded instance scope. * @throws ConfigException if there is no {@link ScopeFactory} registered for loaded instance scope. */ private InstanceScope loadInstanceScope(Config descriptor) throws ConfigException { InstanceScope instanceScope = descriptor.getAttribute("scope", InstanceScope.class, InstanceScope.APPLICATION); if (!container.hasScopeFactory(instanceScope)) { throw new ConfigException("Not registered managed instance scope value |%s|. See class descriptor |%s|.", instanceScope, descriptor); } return instanceScope; }
@Override public String getRequestPath() { if (!remotelyAccessible) { throw new BugError("Attempt to retrive request URI path for local managed class |%s|.", this); } return requestPath; }
@Override public String handle(String variableName) { String property = System.getProperty(variableName); if(property == null) { throw new BugError("Missing system property |%s|. String |%s| variable injection aborted.", variableName, string); } return property; } });