@Override public void config(Config config) { log.trace("config(Config.Element)"); period = config.getAttribute("period", int.class, 0); }
/** * Get attribute value or given default value if there is no attribute with requested name. If given default value is * null and attribute is not found this method still returns null, that is, requested default value. * * @param name attribute name. * @param defaultValue default value, null or empty accepted. * @return attribute value or default value. * @throws IllegalArgumentException if <code>name</code> argument is null or empty. */ public String getAttribute(String name, String defaultValue) { Params.notNullOrEmpty(name, "Attribute name"); return getAttribute(name, String.class, defaultValue); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * Get attribute value converted to requested type or null if there is no attribute with requested name. * * @param name attribute name, * @param type type to converter attribute value to. * @param <T> type to convert attribute value. * @return newly created value object or null if named attribute not found. * @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 getAttribute(String name, Class<T> type) { Params.notNullOrEmpty(name, "Attribute name"); Params.notNull(type, "Attribute type"); return getAttribute(name, type, null); }
/** * Initialize instance fields from managed class configuration object. * * @param managedClass managed class, * @param instance instance of managed class. * @throws ConverterException if configured value cannot be converted to field type. * @throws BugError if attempt to assign instance field to not POJO type. */ @Override public void postProcessInstance(ManagedClassSPI managedClass, Object instance) { Config config = managedClass.getConfig(); if (config == null) { return; } List<Config> fields = config.findChildren("instance-field"); if (!fields.isEmpty() && !InstanceType.POJO.equals(managedClass.getInstanceType())) { throw new BugError("Cannot assign instance field on non %s type.", InstanceType.POJO); } for (Config field : fields) { Classes.setFieldValue(instance, field.getAttribute("name"), field.getAttribute("value")); } } }
String fieldName = config.getAttribute("name"); if (fieldName == null) { throw new ConfigException("Missing <name> attribute from static field initialization |%s|.", config.getParent()); Object value = config.getAttribute("value", field.getType()); log.debug("Intialize static field |%s#%s| |%s|", implementationClass, fieldName, value); Classes.setFieldValue(null, field, config.getAttribute("value", field.getType()));
interfaceNames.add(descriptor.getAttribute("interface")); } else { for (int i = 0; i < descriptor.getChildrenCount(); ++i) { String interfaceName = descriptor.getChild(i).getAttribute("name"); if (interfaceName == null) { throw new ConfigException("Missing <name> attribute from interface declaration. See class descriptor |%s|.", descriptor);
String className = el.getAttribute("class"); Class<?> valueType = Classes.forOptionalName(className); if (valueType == null) { String converterName = el.getAttribute("converter"); Class<? extends Converter> converterClass = Classes.forOptionalName(converterName); if (converterClass == null) {
if (!classDescriptor.hasChildren()) { if (!classDescriptor.hasAttribute("interface")) { classDescriptor.setAttribute("interface", classDescriptor.getAttribute("class")); String interfaceClass = classDescriptor.getAttribute("interface"); for (int i = 0; i < classDescriptors.size(); ++i) { if (classDescriptors.get(i).hasAttribute("interface", interfaceClass)) {
String pojoClassName = pojoClassElement.getAttribute("class"); if (pojoClassName == null) { throw new ConfigException("Invalid POJO class element. Missing <class> attribute."); String fieldName = staticElement.getAttribute("name"); if (fieldName == null) { throw new ConfigException("Missing <name> attribute from static field initialization |%s|.", configSection); Object value = staticElement.getAttribute("value", staticField.getType()); log.debug("Intialize static field |%s#%s| |%s|", pojoClassName, fieldName, value); Classes.setFieldValue(null, staticField, value);
String implementationName = descriptor.getAttribute("class"); if (implementationName == null) { if (instanceType.requiresImplementation()) {
String className = repositorySection.getAttribute("class", DEF_IMPLEMENTATION); Class<?> implementation = Classes.forOptionalName(className); if (implementation == null) { String repositoryPath = repositorySection.getAttribute("path"); if (repositoryPath == null) { throw new ConfigException("Invalid views repository configuration. Missing <path> attribute."); String filesPattern = repositorySection.getAttribute("files-pattern"); if (filesPattern == null) { throw new ConfigException("Invalid views repository configuration. Missing <files-pattern> attribute.");