001    /*
002     * CDDL HEADER START
003     *
004     * The contents of this file are subject to the terms of the
005     * Common Development and Distribution License, Version 1.0 only
006     * (the "License").  You may not use this file except in compliance
007     * with the License.
008     *
009     * You can obtain a copy of the license at
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.tools.dsconfig;
028    
029    
030    
031    import static org.opends.messages.DSConfigMessages.*;
032    
033    import org.opends.messages.Message;
034    import org.opends.server.admin.AbstractManagedObjectDefinition;
035    import org.opends.server.admin.DefaultBehaviorException;
036    import org.opends.server.admin.IllegalPropertyValueException;
037    import org.opends.server.admin.IllegalPropertyValueStringException;
038    import org.opends.server.admin.ManagedObjectDefinition;
039    import org.opends.server.admin.PropertyDefinition;
040    import org.opends.server.admin.PropertyDefinitionUsageBuilder;
041    import org.opends.server.admin.PropertyException;
042    import org.opends.server.admin.PropertyIsMandatoryException;
043    import org.opends.server.admin.PropertyIsReadOnlyException;
044    import org.opends.server.admin.PropertyIsSingleValuedException;
045    import org.opends.server.admin.RelationDefinition;
046    import org.opends.server.admin.client.IllegalManagedObjectNameException;
047    import org.opends.server.admin.client.ManagedObjectDecodingException;
048    import org.opends.server.admin.client.MissingMandatoryPropertiesException;
049    import org.opends.server.admin.client.OperationRejectedException;
050    import org.opends.server.util.args.Argument;
051    import org.opends.server.util.args.ArgumentException;
052    import org.opends.server.util.cli.CLIException;
053    import org.opends.server.util.cli.ConsoleApplication;
054    import org.opends.server.util.table.TableBuilder;
055    import org.opends.server.util.table.TextTablePrinter;
056    
057    
058    
059    /**
060     * A utility class for converting various admin exception types into
061     * argument exceptions.
062     */
063    public final class ArgumentExceptionFactory {
064    
065      /**
066       * Creates a CLI exception from an illegal managed object name
067       * exception.
068       *
069       * @param e
070       *          The illegal managed object name exception.
071       * @param d
072       *          The managed object definition.
073       * @return Returns a CLI exception.
074       */
075      public static CLIException adaptIllegalManagedObjectNameException(
076          IllegalManagedObjectNameException e,
077          AbstractManagedObjectDefinition<?, ?> d) {
078        String illegalName = e.getIllegalName();
079        PropertyDefinition<?> pd = e.getNamingPropertyDefinition();
080    
081        if (illegalName.length() == 0) {
082          Message message =
083              ERR_DSCFG_ERROR_ILLEGAL_NAME_EMPTY.get(d.getUserFriendlyPluralName());
084          return new CLIException(message);
085        } else if (illegalName.trim().length() == 0) {
086          Message message =
087              ERR_DSCFG_ERROR_ILLEGAL_NAME_BLANK.get(d.getUserFriendlyPluralName());
088          return new CLIException(message);
089        } else if (pd != null) {
090          try {
091            pd.decodeValue(illegalName);
092          } catch (IllegalPropertyValueStringException e1) {
093            PropertyDefinitionUsageBuilder b = new PropertyDefinitionUsageBuilder(
094                true);
095            Message syntax = b.getUsage(pd);
096    
097            Message message = ERR_DSCFG_ERROR_ILLEGAL_NAME_SYNTAX.get(
098                illegalName, d.getUserFriendlyName(), syntax);
099            return new CLIException(message);
100          }
101        }
102    
103        Message message = ERR_DSCFG_ERROR_ILLEGAL_NAME_UNKNOWN.get(
104            illegalName, d.getUserFriendlyName());
105        return new CLIException(message);
106      }
107    
108    
109    
110      /**
111       * Creates an argument exception from a property exception.
112       *
113       * @param e
114       *          The property exception.
115       * @param d
116       *          The managed object definition.
117       * @return Returns an argument exception.
118       */
119      public static ArgumentException adaptPropertyException(PropertyException e,
120          AbstractManagedObjectDefinition<?, ?> d) {
121        if (e instanceof IllegalPropertyValueException) {
122          IllegalPropertyValueException pe = (IllegalPropertyValueException) e;
123          return adapt(d, pe);
124        } else if (e instanceof IllegalPropertyValueStringException) {
125          IllegalPropertyValueStringException pe =
126            (IllegalPropertyValueStringException) e;
127          return adapt(d, pe);
128        } else if (e instanceof PropertyIsMandatoryException) {
129          PropertyIsMandatoryException pe = (PropertyIsMandatoryException) e;
130          return adapt(d, pe);
131        } else if (e instanceof PropertyIsSingleValuedException) {
132          PropertyIsSingleValuedException pe = (PropertyIsSingleValuedException) e;
133          return adapt(d, pe);
134        } else if (e instanceof PropertyIsReadOnlyException) {
135          PropertyIsReadOnlyException pe = (PropertyIsReadOnlyException) e;
136          return adapt(d, pe);
137        } else if (e instanceof DefaultBehaviorException) {
138          DefaultBehaviorException pe = (DefaultBehaviorException) e;
139          return adapt(d, pe);
140        } else {
141          Message message = ERR_DSCFG_ERROR_PROPERTY_UNKNOWN_ERROR.
142              get(d.getUserFriendlyName(), e.getPropertyDefinition().getName(),
143                  e.getMessage());
144          return new ArgumentException(message);
145        }
146      }
147    
148    
149    
150      /**
151       * Displays a table listing reasons why a managed object could not
152       * be decoded successfully.
153       *
154       * @param app
155       *          The console application.
156       * @param e
157       *          The managed object decoding exception.
158       */
159      public static void displayManagedObjectDecodingException(
160          ConsoleApplication app, ManagedObjectDecodingException e) {
161        AbstractManagedObjectDefinition<?, ?> d = e.getPartialManagedObject()
162            .getManagedObjectDefinition();
163        Message ufn = d.getUserFriendlyName();
164        Message msg;
165        if (e.getCauses().size() == 1) {
166          msg = ERR_GET_HEADING_MODE_SINGLE.get(ufn);
167        } else {
168          msg = ERR_GET_HEADING_MODE_PLURAL.get(ufn);
169        }
170    
171        app.println(msg);
172        app.println();
173        TableBuilder builder = new TableBuilder();
174        for (PropertyException pe : e.getCauses()) {
175          ArgumentException ae = adaptPropertyException(pe, d);
176          builder.startRow();
177          builder.appendCell("*");
178          builder.appendCell(ae.getMessage());
179        }
180    
181        TextTablePrinter printer = new TextTablePrinter(app.getErrorStream());
182        printer.setDisplayHeadings(false);
183        printer.setColumnWidth(1, 0);
184        printer.setIndentWidth(4);
185        builder.print(printer);
186      }
187    
188    
189    
190      /**
191       * Displays a table listing missing mandatory properties.
192       *
193       * @param app
194       *          The console application.
195       * @param e
196       *          The missing mandatory property exception.
197       */
198      public static void displayMissingMandatoryPropertyException(
199          ConsoleApplication app, MissingMandatoryPropertiesException e) {
200        Message ufn = e.getUserFriendlyName();
201        Message msg;
202        if (e.isCreate()) {
203          if (e.getCauses().size() == 1) {
204            msg = ERR_CREATE_HEADING_MMPE_SINGLE.get(ufn);
205          } else {
206            msg = ERR_CREATE_HEADING_MMPE_PLURAL.get(ufn);
207          }
208        } else {
209          if (e.getCauses().size() == 1) {
210            msg = ERR_MODIFY_HEADING_MMPE_SINGLE.get(ufn);
211          } else {
212            msg = ERR_MODIFY_HEADING_MMPE_PLURAL.get(ufn);
213          }
214        }
215    
216        app.println(msg);
217        app.println();
218        TableBuilder builder = new TableBuilder();
219        builder.addSortKey(0);
220        builder.appendHeading(INFO_DSCFG_HEADING_PROPERTY_NAME.get());
221        builder.appendHeading(INFO_DSCFG_HEADING_PROPERTY_SYNTAX.get());
222    
223        PropertyDefinitionUsageBuilder b = new PropertyDefinitionUsageBuilder(true);
224        for (PropertyIsMandatoryException pe : e.getCauses()) {
225          PropertyDefinition<?> pd = pe.getPropertyDefinition();
226          builder.startRow();
227          builder.appendCell(pd.getName());
228          builder.appendCell(b.getUsage(pd));
229        }
230    
231        TextTablePrinter printer = new TextTablePrinter(app.getErrorStream());
232        printer.setDisplayHeadings(true);
233        printer.setColumnWidth(1, 0);
234        printer.setIndentWidth(4);
235        builder.print(printer);
236      }
237    
238    
239    
240      /**
241       * Displays a table listing the reasons why an operation was
242       * rejected.
243       *
244       * @param app
245       *          The console application.
246       * @param e
247       *          The operation rejected exception.
248       */
249      public static void displayOperationRejectedException(ConsoleApplication app,
250          OperationRejectedException e) {
251        Message ufn = e.getUserFriendlyName();
252        Message msg;
253        switch (e.getOperationType()) {
254        case CREATE:
255          if (e.getMessages().size() == 1) {
256            msg = ERR_DSCFG_ERROR_CREATE_ORE_SINGLE.get(ufn);
257          } else {
258            msg = ERR_DSCFG_ERROR_CREATE_ORE_PLURAL.get(ufn);
259          }
260          break;
261        case DELETE:
262          if (e.getMessages().size() == 1) {
263            msg = ERR_DSCFG_ERROR_DELETE_ORE_SINGLE.get(ufn);
264          } else {
265            msg = ERR_DSCFG_ERROR_DELETE_ORE_PLURAL.get(ufn);
266          }
267          break;
268        default:
269          if (e.getMessages().size() == 1) {
270            msg = ERR_DSCFG_ERROR_MODIFY_ORE_SINGLE.get(ufn);
271          } else {
272            msg = ERR_DSCFG_ERROR_MODIFY_ORE_PLURAL.get(ufn);
273          }
274          break;
275        }
276    
277        app.println(msg);
278        app.println();
279        TableBuilder builder = new TableBuilder();
280        for (Message reason : e.getMessages()) {
281          builder.startRow();
282          builder.appendCell("*");
283          builder.appendCell(reason);
284        }
285        TextTablePrinter printer = new TextTablePrinter(app.getErrorStream());
286        printer.setDisplayHeadings(false);
287        printer.setColumnWidth(1, 0);
288        printer.setIndentWidth(4);
289        builder.print(printer);
290      }
291    
292    
293    
294      /**
295       * Creates an argument exception which should be used when a
296       * property modification argument is incompatible with a previous
297       * modification argument.
298       *
299       * @param arg
300       *          The incompatible argument.
301       * @return Returns an argument exception.
302       */
303      public static ArgumentException incompatiblePropertyModification(String arg) {
304        Message msg = ERR_DSCFG_ERROR_INCOMPATIBLE_PROPERTY_MOD.get(arg);
305        return new ArgumentException(msg);
306      }
307    
308    
309    
310      /**
311       * Creates an argument exception which should be used when the
312       * client has not specified a bind password.
313       *
314       * @param bindDN
315       *          The name of the user requiring a password.
316       * @return Returns an argument exception.
317       */
318      public static ArgumentException missingBindPassword(String bindDN) {
319        Message msg = ERR_DSCFG_ERROR_NO_PASSWORD.get(bindDN);
320        return new ArgumentException(msg);
321      }
322    
323    
324    
325      /**
326       * Creates an argument exception which should be used when an
327       * argument, which is mandatory when the application is
328       * non-interactive, has not been specified.
329       *
330       * @param arg
331       *          The missing argument.
332       * @return Returns an argument exception.
333       */
334      public static ArgumentException missingMandatoryNonInteractiveArgument(
335          Argument arg) {
336        Message msg = ERR_DSCFG_ERROR_MISSING_NON_INTERACTIVE_ARG.get(
337            arg.getLongIdentifier());
338        return new ArgumentException(msg);
339      }
340    
341    
342    
343      /**
344       * Creates an argument exception which should be used when a
345       * property value argument is invalid because it does not a property
346       * name.
347       *
348       * @param arg
349       *          The argument having the missing property name.
350       * @return Returns an argument exception.
351       */
352      public static ArgumentException missingNameInPropertyArgument(String arg) {
353        Message msg = ERR_DSCFG_ERROR_NO_NAME_IN_PROPERTY_VALUE.get(arg);
354        return new ArgumentException(msg);
355      }
356    
357    
358    
359      /**
360       * Creates an argument exception which should be used when a
361       * property modification argument is invalid because it does not a
362       * property name.
363       *
364       * @param arg
365       *          The argument having the missing property name.
366       * @return Returns an argument exception.
367       */
368      public static ArgumentException missingNameInPropertyModification(
369          String arg) {
370        Message msg = ERR_DSCFG_ERROR_NO_NAME_IN_PROPERTY_MOD.get(arg);
371        return new ArgumentException(msg);
372      }
373    
374    
375    
376      /**
377       * Creates an argument exception which should be used when a
378       * property value argument is invalid because it does not contain a
379       * separator between the property name and its value.
380       *
381       * @param arg
382       *          The argument having a missing separator.
383       * @return Returns an argument exception.
384       */
385      public static ArgumentException missingSeparatorInPropertyArgument(
386          String arg) {
387        Message msg = ERR_DSCFG_ERROR_NO_SEPARATOR_IN_PROPERTY_VALUE.get(arg);
388        return new ArgumentException(msg);
389      }
390    
391    
392    
393      /**
394       * Creates an argument exception which should be used when a
395       * property modification argument is invalid because it does not
396       * contain a separator between the property name and its value.
397       *
398       * @param arg
399       *          The argument having a missing separator.
400       * @return Returns an argument exception.
401       */
402      public static ArgumentException missingSeparatorInPropertyModification(
403          String arg) {
404        Message msg = ERR_DSCFG_ERROR_NO_SEPARATOR_IN_PROPERTY_MOD.get(arg);
405        return new ArgumentException(msg);
406      }
407    
408    
409    
410      /**
411       * Creates an argument exception which should be used when a
412       * property value argument is invalid because it does not a property
413       * value.
414       *
415       * @param arg
416       *          The argument having the missing property value.
417       * @return Returns an argument exception.
418       */
419      public static ArgumentException missingValueInPropertyArgument(String arg) {
420        Message msg = ERR_DSCFG_ERROR_NO_VALUE_IN_PROPERTY_VALUE.get(arg);
421        return new ArgumentException(msg);
422      }
423    
424    
425    
426      /**
427       * Creates an argument exception which should be used when a
428       * property modification argument is invalid because it does not a
429       * property value.
430       *
431       * @param arg
432       *          The argument having the missing property value.
433       * @return Returns an argument exception.
434       */
435      public static ArgumentException missingValueInPropertyModification(
436          String arg) {
437        Message msg = ERR_DSCFG_ERROR_NO_NAME_IN_PROPERTY_MOD.get(arg);
438        return new ArgumentException(msg);
439      }
440    
441    
442    
443      /**
444       * Creates an argument exception which should be used when the
445       * connection parameters could not be read from the standard input.
446       *
447       * @param cause
448       *          The reason why the connection parameters could not be
449       *          read.
450       * @return Returns an argument exception.
451       */
452      public static ArgumentException unableToReadConnectionParameters(
453          Exception cause) {
454        Message message = ERR_DSCFG_ERROR_CANNOT_READ_CONNECTION_PARAMETERS
455            .get(cause.getMessage());
456        return new ArgumentException(message, cause);
457      }
458    
459    
460    
461      /**
462       * Creates an argument exception which should be used when the bind
463       * password could not be read from the standard input because the
464       * application is non-interactive.
465       *
466       * @return Returns an argument exception.
467       */
468      public static ArgumentException unableToReadBindPasswordInteractively() {
469        Message message = ERR_DSCFG_ERROR_BIND_PASSWORD_NONINTERACTIVE.get();
470        return new ArgumentException(message);
471      }
472    
473    
474    
475      /**
476       * Creates an argument exception which should be used when an
477       * attempt is made to reset a mandatory property that does not have
478       * any default values.
479       *
480       * @param d
481       *          The managed object definition.
482       * @param name
483       *          The name of the mandatory property.
484       * @param setOption
485       *          The name of the option which should be used to set the
486       *          property's values.
487       * @return Returns an argument exception.
488       */
489      public static ArgumentException unableToResetMandatoryProperty(
490          AbstractManagedObjectDefinition<?, ?> d, String name, String setOption) {
491        Message message = ERR_DSCFG_ERROR_UNABLE_TO_RESET_MANDATORY_PROPERTY.get(
492            d.getUserFriendlyPluralName(), name, setOption);
493        return new ArgumentException(message);
494      }
495    
496    
497    
498      /**
499       * Creates an argument exception which should be used when an
500       * attempt is made to set the naming property for a managed object
501       * during creation.
502       *
503       * @param d
504       *          The managed object definition.
505       * @param pd
506       *          The naming property definition.
507       * @return Returns an argument exception.
508       */
509      public static ArgumentException unableToSetNamingProperty(
510          AbstractManagedObjectDefinition<?, ?> d, PropertyDefinition<?> pd) {
511        Message message = ERR_DSCFG_ERROR_UNABLE_TO_SET_NAMING_PROPERTY.get(
512            pd.getName(), d.getUserFriendlyName());
513        return new ArgumentException(message);
514      }
515    
516    
517    
518      /**
519       * Creates an argument exception which should be used when a
520       * component category argument is not recognized.
521       *
522       * @param categoryName
523       *          The unrecognized component category.
524       * @return Returns an argument exception.
525       */
526      public static ArgumentException unknownCategory(String categoryName) {
527        Message msg = ERR_DSCFG_ERROR_CATEGORY_UNRECOGNIZED.get(categoryName);
528        return new ArgumentException(msg);
529      }
530    
531    
532    
533      /**
534       * Creates an argument exception which should be used when a
535       * property name is not recognized.
536       *
537       * @param d
538       *          The managed object definition.
539       * @param name
540       *          The unrecognized property name.
541       * @return Returns an argument exception.
542       */
543      public static ArgumentException unknownProperty(
544          AbstractManagedObjectDefinition<?, ?> d, String name) {
545        Message message = ERR_DSCFG_ERROR_PROPERTY_UNRECOGNIZED.get(
546            name, d.getUserFriendlyPluralName());
547        return new ArgumentException(message);
548      }
549    
550    
551    
552      /**
553       * Creates an argument exception which should be used when a
554       * property name is not recognized.
555       *
556       * @param name
557       *          The unrecognized property name.
558       * @return Returns an argument exception.
559       */
560      public static ArgumentException unknownProperty(String name) {
561        Message message = ERR_DSCFG_ERROR_PROPERTY_UNRECOGNIZED_NO_DEFN.get(name);
562        return new ArgumentException(message);
563      }
564    
565    
566    
567      /**
568       * Creates an argument exception which should be used when a
569       * sub-type argument in a create-xxx sub-command is not recognized.
570       *
571       * @param r
572       *          The relation definition.
573       * @param typeName
574       *          The unrecognized property sub-type.
575       * @param typeUsage
576       *          A usage string describing the allowed sub-types.
577       * @return Returns an argument exception.
578       */
579      public static ArgumentException unknownSubType(RelationDefinition<?, ?> r,
580          String typeName, String typeUsage) {
581        Message msg = ERR_DSCFG_ERROR_SUB_TYPE_UNRECOGNIZED.get(
582            typeName, r.getUserFriendlyName(), typeUsage);
583        return new ArgumentException(msg);
584      }
585    
586    
587      /**
588       * Creates an argument exception which should be used when a managed
589       * object type argument is not associated with a category.
590       *
591       * @param categoryName
592       *          The component category.
593       * @param typeName
594       *          The unrecognized component type.
595       * @return Returns an argument exception.
596       */
597      public static ArgumentException unknownTypeForCategory(String typeName,
598          String categoryName) {
599        Message msg =
600            ERR_DSCFG_ERROR_CATEGORY_TYPE_UNRECOGNIZED.get(typeName, categoryName);
601        return new ArgumentException(msg);
602      }
603    
604    
605    
606      /**
607       * Creates a CLI exception which should be used when a managed
608       * object is retrieved but does not have the correct type
609       * appropriate for the associated sub-command.
610       *
611       * @param r
612       *          The relation definition.
613       * @param d
614       *          The definition of the managed object that was retrieved.
615       *
616       * @param subcommandName the sub-command name.
617       * @return Returns a CLI exception.
618       */
619      public static CLIException wrongManagedObjectType(RelationDefinition<?, ?> r,
620          ManagedObjectDefinition<?, ?> d, String subcommandName) {
621        Message msg = ERR_DSCFG_ERROR_TYPE_UNRECOGNIZED_FOR_SUBCOMMAND.get(
622            d.getUserFriendlyName(), subcommandName);
623        return new CLIException(msg);
624      }
625    
626    
627    
628      /**
629       * Creates an argument exception from a default behavior exception.
630       *
631       * @param d
632       *          The managed object definition.
633       * @param e
634       *          The default behavior exception.
635       * @return Returns an argument exception.
636       */
637      private static ArgumentException adapt(
638          AbstractManagedObjectDefinition<?, ?> d, DefaultBehaviorException e) {
639        Message message = ERR_DSCFG_ERROR_PROPERTY_DEFAULT_BEHAVIOR.
640            get(d.getUserFriendlyName(), e.getPropertyDefinition().getName(),
641                e.getMessage());
642        return new ArgumentException(message);
643      }
644    
645    
646    
647      /**
648       * Creates an argument exception from an illegal property value
649       * exception.
650       *
651       * @param d
652       *          The managed object definition.
653       * @param e
654       *          The illegal property value exception.
655       * @return Returns an argument exception.
656       */
657      private static ArgumentException adapt(
658          AbstractManagedObjectDefinition<?, ?> d,
659          IllegalPropertyValueException e) {
660        PropertyDefinitionUsageBuilder b = new PropertyDefinitionUsageBuilder(true);
661        Message syntax = b.getUsage(e.getPropertyDefinition());
662    
663        if (syntax.length() > 20) {
664          // syntax =
665          // INFO_DSCFG_DESCRIPTION_PROPERTY_SYNTAX_HELP.get();
666        }
667    
668        Message message = ERR_DSCFG_ERROR_PROPERTY_INVALID_VALUE.
669            get(String.valueOf(e.getIllegalValue()), d.getUserFriendlyName(),
670                e.getPropertyDefinition().getName(), syntax);
671        return new ArgumentException(message);
672      }
673    
674    
675    
676      /**
677       * Creates an argument exception from an illegal property string
678       * value exception.
679       *
680       * @param d
681       *          The managed object definition.
682       * @param e
683       *          The illegal property string value exception.
684       * @return Returns an argument exception.
685       */
686      private static ArgumentException adapt(
687          AbstractManagedObjectDefinition<?, ?> d,
688          IllegalPropertyValueStringException e) {
689        PropertyDefinitionUsageBuilder b = new PropertyDefinitionUsageBuilder(true);
690        Message syntax = b.getUsage(e.getPropertyDefinition());
691    
692        if (syntax.length() > 20) {
693          // syntax =
694          // INFO_DSCFG_DESCRIPTION_PROPERTY_SYNTAX_HELP.get();
695        }
696    
697        Message message = ERR_DSCFG_ERROR_PROPERTY_INVALID_VALUE.
698            get(String.valueOf(e.getIllegalValueString()), d.getUserFriendlyName(),
699                e.getPropertyDefinition().getName(), syntax);
700        return new ArgumentException(message);
701      }
702    
703    
704    
705      /**
706       * Creates an argument exception from a property is mandatory
707       * exception.
708       *
709       * @param d
710       *          The managed object definition.
711       * @param e
712       *          The property is mandatory exception.
713       * @return Returns an argument exception.
714       */
715      private static ArgumentException adapt(
716          AbstractManagedObjectDefinition<?, ?> d,
717          PropertyIsMandatoryException e) {
718        Message message = ERR_DSCFG_ERROR_PROPERTY_MANDATORY.get(
719            d.getUserFriendlyName(), e.getPropertyDefinition().getName());
720        return new ArgumentException(message);
721      }
722    
723    
724    
725      /**
726       * Creates an argument exception from a property is read-only
727       * exception.
728       *
729       * @param d
730       *          The managed object definition.
731       * @param e
732       *          The property is read-only exception.
733       * @return Returns an argument exception.
734       */
735      private static ArgumentException adapt(
736          AbstractManagedObjectDefinition<?, ?> d,
737          PropertyIsReadOnlyException e) {
738        Message message = ERR_DSCFG_ERROR_PROPERTY_READ_ONLY.get(
739            d.getUserFriendlyName(), e.getPropertyDefinition().getName());
740        return new ArgumentException(message);
741      }
742    
743    
744    
745      /**
746       * Creates an argument exception from a property is single-valued
747       * exception.
748       *
749       * @param d
750       *          The managed object definition.
751       * @param e
752       *          The property is single-valued exception.
753       * @return Returns an argument exception.
754       */
755      private static ArgumentException adapt(
756          AbstractManagedObjectDefinition<?, ?> d,
757          PropertyIsSingleValuedException e) {
758        Message message = ERR_DSCFG_ERROR_PROPERTY_SINGLE_VALUED.get(
759            d.getUserFriendlyName(), e.getPropertyDefinition().getName());
760        return new ArgumentException(message);
761      }
762    
763    
764    
765      // Prevent instantiation.
766      private ArgumentExceptionFactory() {
767        // No implementation required.
768      }
769    }