private boolean isJavaClassAcceptable( LogRotationPolicyCfg config, List<Message> unacceptableReasons) { String className = config.getJavaClass(); LogRotationPolicyCfgDefn d = LogRotationPolicyCfgDefn.getInstance(); ClassPropertyDefinition pd = d.getJavaClassPropertyDefinition(); // Load the class and cast it to a RotationPolicy. Class<? extends RotationPolicy> theClass; try { theClass = pd.loadClass(className, RotationPolicy.class); theClass.newInstance(); } catch (Exception e) { Message message = ERR_CONFIG_ROTATION_POLICY_INVALID_CLASS.get( className, config.dn().toString(), String.valueOf(e)); unacceptableReasons.add(message); return false; } // Check that the implementation class implements the correct interface. try { // Determine the initialization method to use: it must take a // single parameter which is the exact type of the configuration // object. theClass.getMethod("initializeLogRotationPolicy", config.configurationClass()); } catch (Exception e) { Message message = ERR_CONFIG_ROTATION_POLICY_INVALID_CLASS.get( className, config.dn().toString(), String.valueOf(e)); unacceptableReasons.add(message); return false; } // The class is valid as far as we can tell. return true; }
private RotationPolicy getRotationPolicy(LogRotationPolicyCfg config) throws ConfigException { String className = config.getJavaClass(); LogRotationPolicyCfgDefn d = LogRotationPolicyCfgDefn.getInstance(); ClassPropertyDefinition pd = d.getJavaClassPropertyDefinition(); // Load the class and cast it to a RotationPolicy. Class<? extends RotationPolicy> theClass; RotationPolicy rotationPolicy; try { theClass = pd.loadClass(className, RotationPolicy.class); rotationPolicy = theClass.newInstance(); // Determine the initialization method to use: it must take a // single parameter which is the exact type of the configuration // object. Method method = theClass.getMethod("initializeLogRotationPolicy", config.configurationClass()); method.invoke(rotationPolicy, config); } catch (InvocationTargetException ite) { // Rethrow the exceptions thrown be the invoked method. Throwable e = ite.getTargetException(); Message message = ERR_CONFIG_ROTATION_POLICY_INVALID_CLASS.get( className, config.dn().toString(), stackTraceToSingleLineString(e)); throw new ConfigException(message, e); } catch (Exception e) { Message message = ERR_CONFIG_ROTATION_POLICY_INVALID_CLASS.get( className, config.dn().toString(), String.valueOf(e)); throw new ConfigException(message, e); } // The connection handler has been successfully initialized. return rotationPolicy; }
/** {@inheritDoc} */ public ConfigChangeResult applyConfigurationChange(LogRotationPolicyCfg configuration) { // Default result code. ResultCode resultCode = ResultCode.SUCCESS; boolean adminActionRequired = false; ArrayList<Message> messages = new ArrayList<Message>(); RotationPolicy policy = DirectoryServer.getRotationPolicy(configuration.dn()); String className = configuration.getJavaClass(); if (!className.equals(policy.getClass().getName())) { adminActionRequired = true; } return new ConfigChangeResult(resultCode, adminActionRequired, messages); }