| | |
| | | * Portions Copyright 2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.admin.server; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import static org.opends.server.messages.MessageHandler.getMessage; |
| | | import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString; |
| | | |
| | | import java.lang.reflect.Method; |
| | |
| | | import org.opends.server.admin.Configuration; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.messages.AdminMessages; |
| | | import org.opends.messages.AdminMessages; |
| | | |
| | | import org.opends.server.types.ConfigChangeResult; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.ResultCode; |
| | |
| | | // Default result code. |
| | | ResultCode resultCode = ResultCode.SUCCESS; |
| | | boolean adminActionRequired = false; |
| | | ArrayList<String> messages = new ArrayList<String>(); |
| | | ArrayList<Message> messages = new ArrayList<Message>(); |
| | | |
| | | // We have committed to this change so always update the |
| | | // configuration. |
| | |
| | | // Notify that a new instance has been added. |
| | | doRegisterInstance(getImplementation(config)); |
| | | } catch (ConfigException e) { |
| | | messages.add(e.getMessage()); |
| | | messages.add(e.getMessageObject()); |
| | | resultCode = DirectoryServer.getServerErrorResultCode(); |
| | | } catch (InitializationException e) { |
| | | messages.add(e.getMessage()); |
| | | messages.add(e.getMessageObject()); |
| | | resultCode = DirectoryServer.getServerErrorResultCode(); |
| | | } |
| | | } else { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean isConfigurationAddAcceptable(C config, |
| | | List<String> unacceptableReasons) { |
| | | List<Message> unacceptableReasons) { |
| | | if (isEnabled(config)) { |
| | | // It's enabled so always validate the class. |
| | | return isJavaClassAcceptable(config, unacceptableReasons); |
| | |
| | | // Default result code. |
| | | ResultCode resultCode = ResultCode.SUCCESS; |
| | | boolean adminActionRequired = false; |
| | | ArrayList<String> messages = new ArrayList<String>(); |
| | | ArrayList<Message> messages = new ArrayList<Message>(); |
| | | |
| | | // We have committed to this change so always update the |
| | | // configuration. |
| | |
| | | // Notify that a new instance has been added. |
| | | doRegisterInstance(getImplementation(config)); |
| | | } catch (ConfigException e) { |
| | | messages.add(e.getMessage()); |
| | | messages.add(e.getMessageObject()); |
| | | resultCode = DirectoryServer.getServerErrorResultCode(); |
| | | } catch (InitializationException e) { |
| | | messages.add(e.getMessage()); |
| | | messages.add(e.getMessageObject()); |
| | | resultCode = DirectoryServer.getServerErrorResultCode(); |
| | | } |
| | | } else { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean isConfigurationChangeAcceptable(C config, |
| | | List<String> unacceptableReasons) { |
| | | List<Message> unacceptableReasons) { |
| | | if (isEnabled(config)) { |
| | | // It's enabled so always validate the class. |
| | | return isJavaClassAcceptable(config, unacceptableReasons); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean isConfigurationDeleteAcceptable(C config, |
| | | List<String> unacceptableReasons) { |
| | | List<Message> unacceptableReasons) { |
| | | if (isEnabled(getConfiguration())) { |
| | | return isDisableInstanceAcceptable(config, |
| | | unacceptableReasons); |
| | |
| | | * disabled or deleted. |
| | | */ |
| | | protected abstract boolean isDisableInstanceAcceptable(C config, |
| | | List<String> unacceptableReasons); |
| | | List<Message> unacceptableReasons); |
| | | |
| | | |
| | | |
| | |
| | | implClass = propertyDefinition.loadClass(className, theClass); |
| | | instance = implClass.newInstance(); |
| | | } catch (Exception e) { |
| | | int msgID = AdminMessages.MSGID_ADMIN_CANNOT_INSTANTIATE_CLASS; |
| | | String message = getMessage(msgID, String.valueOf(className), |
| | | String.valueOf(config.dn()), |
| | | stackTraceToSingleLineString(e)); |
| | | throw new ConfigException(msgID, message, e); |
| | | Message message = AdminMessages.ERR_ADMIN_CANNOT_INSTANTIATE_CLASS. |
| | | get(String.valueOf(className), String.valueOf(config.dn()), |
| | | stackTraceToSingleLineString(e)); |
| | | throw new ConfigException(message, e); |
| | | } |
| | | |
| | | // Perform the necessary initialization for the instance. |
| | |
| | | |
| | | method.invoke(instance, config); |
| | | } catch (Exception e) { |
| | | int msgID = AdminMessages.MSGID_ADMIN_CANNOT_INITIALIZE_COMPONENT; |
| | | String message = getMessage(msgID, String.valueOf(className), |
| | | String.valueOf(config.dn()), |
| | | stackTraceToSingleLineString(e)); |
| | | throw new ConfigException(msgID, message, e); |
| | | Message message = AdminMessages.ERR_ADMIN_CANNOT_INITIALIZE_COMPONENT. |
| | | get(String.valueOf(className), String.valueOf(config.dn()), |
| | | stackTraceToSingleLineString(e)); |
| | | throw new ConfigException(message, e); |
| | | } |
| | | |
| | | // The instance has been successfully initialized. |
| | |
| | | // Determines whether or not the new configuration's implementation |
| | | // class is acceptable. |
| | | private boolean isJavaClassAcceptable(C config, |
| | | List<String> unacceptableReasons) { |
| | | List<Message> unacceptableReasons) { |
| | | String className = getJavaImplementationClass(config); |
| | | |
| | | // Load the class and cast it to a T. |
| | |
| | | implClass = propertyDefinition.loadClass(className, theClass); |
| | | implClass.newInstance(); |
| | | } catch (Exception e) { |
| | | int msgID = AdminMessages.MSGID_ADMIN_CANNOT_INSTANTIATE_CLASS; |
| | | unacceptableReasons.add(getMessage(msgID, String |
| | | .valueOf(className), String.valueOf(config.dn()), |
| | | stackTraceToSingleLineString(e))); |
| | | unacceptableReasons.add( |
| | | AdminMessages.ERR_ADMIN_CANNOT_INSTANTIATE_CLASS.get( |
| | | String.valueOf(className), |
| | | String.valueOf(config.dn()), |
| | | stackTraceToSingleLineString(e))); |
| | | return false; |
| | | } |
| | | |
| | |
| | | implClass.getMethod(name, config.definition() |
| | | .getServerConfigurationClass()); |
| | | } catch (Exception e) { |
| | | int msgID = AdminMessages.MSGID_ADMIN_CANNOT_INITIALIZE_COMPONENT; |
| | | unacceptableReasons.add(getMessage(msgID, String |
| | | .valueOf(className), String.valueOf(config.dn()), |
| | | stackTraceToSingleLineString(e))); |
| | | unacceptableReasons.add( |
| | | AdminMessages.ERR_ADMIN_CANNOT_INITIALIZE_COMPONENT.get( |
| | | String.valueOf(className), String.valueOf(config.dn()), |
| | | stackTraceToSingleLineString(e))); |
| | | return false; |
| | | } |
| | | |