View Javadoc

1   /*
2    ORG Usurper is a random value object generator library 
3    Copyright (C) 2007  Pierre-Antoine Grégoire
4    
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9    
10   This library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14   
15   You should have received a copy of the GNU Lesser General Public
16   License along with this library; if not, write to the Free Software
17   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18   */
19  package org.org.usurper.utils;
20  
21  import java.util.SortedSet;
22  import java.util.TreeSet;
23  
24  import org.org.usurper.handlers.basic.AbstractSpecificPropertyHandler;
25  import org.org.usurper.model.PropertyTypeDefinition;
26  import org.org.usurper.setup.IUsurperGeneratorSetup;
27  /**
28   * This class is an UsurperGeneratorSetup utility class
29   * 
30   * @author pagregoire
31   */
32  public final class UsurperGeneratorSetupUtils {
33  
34      private UsurperGeneratorSetupUtils() {
35      }
36  
37      /**
38       * This method builds a String representation of an IUsurperGeneratorSetup instance.
39       * 
40       * @param usurperGeneratorSetup the usurper generator setup
41       * 
42       * @return the string
43       */
44      public static String buildStringRepresentation(IUsurperGeneratorSetup usurperGeneratorSetup) {
45          StringBuilder stringBuilder = new StringBuilder();
46          stringBuilder.append("--------------------------------------------\n");
47          stringBuilder.append("Usurper Generator setup:" + usurperGeneratorSetup.getClass().getName() + "\n");
48          stringBuilder.append("---------\n");
49          stringBuilder.append("Array handler: " + usurperGeneratorSetup.getArrayHandler().getClass().getName() + "\n");
50          stringBuilder.append("Enum handler: " + usurperGeneratorSetup.getEnumHandler().getClass().getName() + "\n");
51          stringBuilder.append("Count callback: " + usurperGeneratorSetup.getCountCallback().getClass().getName() + "\n");
52          stringBuilder.append("On missing handlers: " + usurperGeneratorSetup.getOnMissingHandlers().toString() + "\n");
53          stringBuilder.append("Property writing mechanism: " + usurperGeneratorSetup.getPropertyWritingMechanism().toString() + "\n");
54          stringBuilder.append("---------\n");
55          SortedSet<String> sortedSet = new TreeSet<String>();
56          for (PropertyTypeDefinition handledProperty : usurperGeneratorSetup.getPropertyTypeHandlersMap().keySet()) {
57              sortedSet.add(handledProperty + ": " + usurperGeneratorSetup.getPropertyTypeHandlersMap().get(handledProperty).getClass().getName() + "\n");
58          }
59          for (String message : sortedSet) {
60              stringBuilder.append(message);
61          }
62          stringBuilder.append("---------\n");
63          sortedSet = new TreeSet<String>();
64          for (AbstractSpecificPropertyHandler abstractSpecificPropertyHandler : usurperGeneratorSetup.getSpecificPropertyHandlersMap().values()) {
65              sortedSet.add(abstractSpecificPropertyHandler.getTargetProperty().getPropertyPathString() + ": " + abstractSpecificPropertyHandler.getClass().getName() + "\n");
66          }
67          for (String message : sortedSet) {
68              stringBuilder.append(message);
69          }
70          stringBuilder.append("--------------------------------------------\n");
71          return stringBuilder.toString();
72      }
73  
74  }