Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
      Copyright (c) 2014 zuendorf
   
      Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
      and associated documentation files (the "Software"), to deal in the Software without restriction, 
      including without limitation the rights to use, copy, modify, merge, publish, distribute, 
      sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
      furnished to do so, subject to the following conditions:
   
     The above copyright notice and this permission notice shall be included in all copies or 
     substantial portions of the Software.
  
     The Software shall be used for Good, not Evil.
  
     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   */
  
  package org.sdmlib.storyboards;
  
  import java.io.File;
  import java.util.Arrays;
  import java.util.Date;
  
  import  org.junit.Assert;
  import org.sdmlib.CGUtil;
  
  
  public class Storyboard implements PropertyChangeInterface
  {
     public static final String PROPERTY_STEPDONECOUNTER = "stepDoneCounter";
     public static final String PROPERTY_STEPCOUNTER = "stepCounter";
     public static final String PROPERTY_MODELROOTDIR = "modelRootDir";
     public static final String PROPERTY_ROOTDIR = "rootDir";
     public static final String PROPERTY_WALL = "wall";
     public static final String PROPERTY_STORYBOARDSTEPS = "storyboardSteps";
  
     public static final String MODELING = "modeling";
     public static final String ACTIVE = "active";
     public static final String DONE = "done";
     public static final String IMPLEMENTATION = "implementation";
     public static final String BACKLOG = "backlog";
  
     private String name = "";
     private GuiAdapter adapter;
     private String javaTestFileName = "";
     private JsonArray largestJsonArray = null;
     private Object largestRoot = null;
     private String kanbanWorkFlow = null;
     private String projectName = null;
     private int stepDoneCounter;
     private String sprintName = null;
     private int stepCounter;
     private String modelRootDir = null;
     private String rootDir = null;
  //   private StoryboardWall wall = null;
    private StoryboardStepSet storyboardSteps = null;
    private int codeStartLineNumber = -1;
    private JsonIdMap jsonIdMap = null;
    private LinkedHashMap<StringStringiconMap = new LinkedHashMap<StringString>();
 
    public Storyboard withJsonIdMap(JsonIdMap jsonIdMap)
    {
       this. = jsonIdMap;
       return this;
    }
 
    public GuiAdapter getAdapter()
    {
       if ( == null)
       {
           = GraphFactory.getAdapter();
       }
       return ;
    }
 
    public Storyboard withAdapter(GuiAdapter adapter)
    {
       this. = adapter;
       return this;
    }
 
    public String getName()
    {
       return ;
    }
 
    public void setName(String name)
    {
       this. = name;
    }
 
    public Storyboard withName(String name)
    {
       setName(name);
       return this;
    }
 
    public String findRootDir()
    {
       if ( == null)
       {
          this. = "src";
 
          Exception e = new RuntimeException();
 
          StackTraceElement[] stackTrace = e.getStackTrace();
          StackTraceElement callEntry = stackTrace[1];
 
          // find first method outside Storyboard
          int i = 1;
 
          while (true)
          {
             callEntry = stackTrace[i];
 
             if (callEntry.getClassName().equals(Storyboard.class.getName()))
             {
                i++;
                continue;
             }
             else
             {
                break;
             }
          }
 
           = callEntry.getClassName().replaceAll("\\.""/") + ".java";
 
          // search for a subdirectory containing the javaTestFile of the
          // execution directory and search for the subdi
          File projectDir = new File(".");
          searchDirectoryTree(projectDir);
 
       }
 
       return this.;
    }
 
    private boolean searchDirectoryTree(File projectDir)
    {
       for (File subDir : projectDir.listFiles())
       {
          if (subDir.isDirectory())
          {
             String subPath = subDir.getPath();
             if (new File(subPath + "/" + ).exists())
             {
                // got it
                this. = subDir.getPath().replaceAll("\\\\""/");
                 = "../" +  + "/" + ;
 
                return true;
             }
             else
             {
                boolean done = searchDirectoryTree(subDir);
                if (done)
                   return true;
             }
          }
       }
 
       return false;
    }
 
    public Storyboard()
    {
       findRootDir();
 
       Exception e = new RuntimeException();
       StackTraceElement[] stackTrace = e.getStackTrace();
       StackTraceElement callEntry = stackTrace[1];
 
       String methodName = stackTrace[1].getMethodName();
 
       if (methodName.startsWith("test"))
       {
          methodName = methodName.substring(4);
       }
 
       setName(methodName);
 
       this.addToSteps();
    }
 
    private void addToSteps(String text)
    {
       StoryboardStep storyStep = new StoryboardStep().withText(text);
       this.addToStoryboardSteps(storyStep);
    }
 
    // private String rootDir = null;
 
    public Storyboard(String rootDir)
    {
       if (rootDir == null)
       {
          // do nothing just for getSendableInstance
          return;
       }
 
       this. = rootDir;
 
       Exception e = new RuntimeException();
 
       StackTraceElement[] stackTrace = e.getStackTrace();
       StackTraceElement callEntry = stackTrace[1];
        = "../" + rootDir + "/" + callEntry.getClassName().replaceAll("\\.""/") + ".java";
 
       String methodName = stackTrace[1].getMethodName();
 
       if (methodName.startsWith("test"))
       {
          methodName = methodName.substring(4);
       }
 
       setName(methodName);
 
       this.addToSteps();
 
    }
 
    public Storyboard(String rootDirString name)
    {
       this. = rootDir;
       setName(name);
 
       this.addToSteps(name);
 
       Exception e = new RuntimeException();
 
       StackTraceElement[] stackTrace = e.getStackTrace();
       StackTraceElement callEntry = stackTrace[1];
        = "../" + rootDir + "/" + callEntry.getClassName().replaceAll("\\.""/") + ".java";
    }
 
    public void dumpHTML(KanbanEntry kanbanBoard)
    {
       // get kanbanEntry
       KanbanEntry kanbanEntry = kanbanBoard.findOldEntry(this.getName());
 
       if (kanbanEntry == null)
       {
          Date today = new Date(System.currentTimeMillis());
          SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss z");
 
          String todayString = dateFormat.format(today);
          kanbanEntry = new KanbanEntry()
             .withName(this.getName())
             .withPhase()
             .withParent(kanbanBoard)
             .withLogEntries(
                new LogEntryStoryBoard()
                   .withDate(todayString)
                   .withPhase()
                   .withDeveloper(System.getProperty("user.name"))
                   .withHoursRemainingInTotal(0.0));
       }
 
       if (kanbanEntry.getPhase() == null)
       {
          kanbanEntry.setPhase(.);
       }
 
       if (this. != null)
       {
          kanbanEntry.setPhases(this.);
 
          KanbanEntry parent = kanbanEntry.getParent();
 
          while (parent != null)
          {
             parent.setPhases(this.);
             parent = parent.getParent();
          }
       }
 
       if (this. != null)
       {
          kanbanBoard.setName();
       }
 
       if ( != null)
       {
          KanbanEntry sprintEntry = kanbanBoard.findOrCreate();
          kanbanEntry.setParent(sprintEntry);
 
          if (sprintEntry.getParent() == null)
          {
             sprintEntry.setParent(kanbanBoard);
          }
 
          if (sprintEntry.getPhase() == null)
          {
             sprintEntry.setPhase();
          }
       }
 
       // reuse old logentries to keep kanban.json stable
       double remainingTime = 0.0;
       double hoursSpend = 0.0;
       Iterator<LogEntryStoryBoardoldLogEntriesIter = kanbanEntry.getLogEntries()
          .clone().iterator();
       Date latestEntryTime = null;
 
       for (LogEntryStoryBoard newEntry : .values())
       {
          if (latestEntryTime == null)
          {
             latestEntryTime = newEntry.getParsedDate();
             remainingTime = newEntry.getHoursRemainingInTotal();
          }
          else if (latestEntryTime.compareTo(newEntry.getParsedDate()) < 0)
          {
             latestEntryTime = newEntry.getParsedDate();
             remainingTime = newEntry.getHoursRemainingInTotal();
          }
 
          hoursSpend += newEntry.getHoursSpend();
 
          if (oldLogEntriesIter.hasNext())
          {
             LogEntryStoryBoard oldEntry = oldLogEntriesIter.next();
             oldEntry.withDeveloper(newEntry.getDeveloper())
                .withDate(newEntry.getDate())
                .withHoursRemainingInTotal(newEntry.getHoursRemainingInTotal())
                .withHoursSpend(newEntry.getHoursSpend())
                .withPhase(newEntry.getPhase());
          }
          else
          {
             // out of old entries, just add new entry
             kanbanEntry.addToLogEntries(newEntry);
          }
       }
 
       kanbanEntry.setHoursRemaining(remainingTime);
 
       // remove obsolet oldLogEntries
       while (oldLogEntriesIter.hasNext())
       {
          LogEntryStoryBoard oldEntry = oldLogEntriesIter.next();
          kanbanEntry.removeFromLogEntries(oldEntry);
       }
 
       // generate the html text
       String htmlText = "<!DOCTYPE html>\n"
          + "<html>\n" +
             "<head>" +
             "<meta charset=\"utf-8\">\n" +
             "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n" +
             "<link href=\"includes/diagramstyle.css\" rel=\"stylesheet\" type=\"text/css\">\n" +
             "\n" +
             "<script src=\"includes/dagre.min.js\"></script>\n" +
             "<script src=\"includes/drawer.js\"></script>\n" +
             "<script src=\"includes/graph.js\"></script>\n" +
             "</head>" +
             "<body>\n" +
             "<p>Storyboard <a href='testfilename' type='text/x-java'>storyboardName</a></p>\n" +
             "$text\n" +
             "</body>\n" +
             "</html>\n";
 
       String storyboardName = this.getName();
 
       htmlText = htmlText.replaceFirst("storyboardName"storyboardName);
       htmlText = htmlText.replaceFirst("testfilename");
       kanbanEntry.setName(storyboardName);
 
       String shortFileName = "" + storyboardName + ".html";
       String pathname = "doc/" + shortFileName;
 
       StringBuffer text = new StringBuffer();
 
       for (StoryboardStep step : this.getStoryboardSteps())
       {
          String content = step.getText();
 
          if (content.startsWith("<"))
          {
             // already html
             text.append(content);
          }
          else if (content.startsWith("screendump="))
          {
             String[] split = content.split("=");
             content = split.clone()[1];
             String imgText = "<img src='" + content + "' />\n";
 
             text.append(imgText);
          }
          else
          {
             text.append("<p>" + content + "</p>\n");
          }
       } // for
 
       int pos = htmlText.indexOf("$text");
 
       htmlText = htmlText.substring(0, pos)
          + text.toString()
          + htmlText.substring(pos + "$text".length());
 
       writeToFile(shortFileNamehtmlText);
 
    }
 
    private void writeToFile(String imgNameString fileText)
    {
       try
       {
          if (imgName.startsWith("<"))
          {
             ..println("Ups, invalid file name: " + imgName);
             return;
          }
 
          File oldFile = new File("doc/" + imgName);
 
          if (oldFile.exists())
          {
             // load old file content and compare with new fileText, if no
             // change, do not write
 
             BufferedReader in = new BufferedReader(new FileReader(oldFile));
             StringBuilder oldFileText = new StringBuilder();
 
             String line = in.readLine();
             while (line != null)
             {
                oldFileText.append(line).append("\n");
                line = in.readLine();
             }
 
             String oldFileString = oldFileText.toString().trim();
 
             fileText = fileText.replaceAll("\\r""");
 
             int oldStringLength = oldFileString.length();
             int newStringLength = fileText.length();
 
             // for (int i = 0; i < Math.min(oldStringLength, newStringLength);
             // i++)
             // {
             // if (oldFileString.charAt(i) != fileText.charAt(i))
             // {
             // System.out.println("Found diff");
             // }
             // }
 
             if (oldFileString.equals(fileText.trim()))
             {
                // do not write file, no change
                return;
             }
          }
 
          BufferedWriter out = new BufferedWriter(new FileWriter("doc/" + imgName));
 
          out.write(fileText);
          out.close();
       }
       catch (IOException e)
       {
          // e.printStackTrace();
       }
    }
 
    // private int stepCounter = 0;
 
    public Storyboard addStep(String txt)
    {
       if ( == 0)
       {
          this.add("Start: " + txt);
          this.setStepCounter(this.getStepCounter() + 1);
       }
       else
       {
          StringBuilder buf = new StringBuilder("<p><a name = 'step_stepCounter'>Step stepCounter: text</a></p>");
          CGUtil.replaceAll(buf,
             "stepCounter""" + ,
             "text"txt);
          this.add(buf.toString());
          this.setStepCounter(this.getStepCounter() + 1);
       }
       return this;
    }
 
    public void add(String string)
    {
       this.addToSteps(string);
       synchronized (this)
       {
          this.notifyAll();
       }
    }
 
    public void addText(String string)
    {
       this.add(string);
    }
 
    public Storyboard withMap(JsonIdMap map)
    {
       this. = map;
       return this;
    }
 
    public void coverage4GeneratedModelCode(Object root)
    {
       if (root == null)
       {
          return;
       }
 
       // derive creator class from root and create idMap
       String className = root.getClass().getName();
       String packageName = CGUtil.packageName(className) + ".util";
       className = packageName + ".CreatorCreator";
 
       Object idMap = null;
       try
       {
          if ( == null)
          {
             Class<?> creatorClass = Class.forName(className);
             Method method = creatorClass.getDeclaredMethod("createIdMap"String.class);
 
             idMap = method.invoke(null"debug");
 
              = (JsonIdMapidMap;
          }
 
          if ( == null)
          {
              = .toJsonArray(root);
          }
 
          JsonIdMap copyMap = (JsonIdMapnew JsonIdMap().withCreator();
 
          copyMap.decode();
 
          coverSetAndPOClasses(copyMap);
 
          coverSeldomModelMethods(copyMap);
 
       }
       catch (Exception e)
       {
          // cannot find creator creator class, sorry.
          e.printStackTrace();
       }
    }
 
          InvocationTargetException
    {
       LinkedHashSet<StringhandledClassesNames = new LinkedHashSet<String>();
 
       LinkedHashSet<StringkeySet = new LinkedHashSet<String>();
       keySet.addAll(copyMap.keySet());
       // loop through objects
       for (String key : keySet)
       {
          try
          {
             Object object = keySet;
 
             // that class is already handled?
             String className = object.getClass().getName();
 
             if (handledClassesNames.contains(className))
             {
                continue;
             }
 
             handledClassesNames.add(className);
 
             // call toString
             object.toString();
 
             Class<? extends ObjectobjectClass = object.getClass();
 
             try
             {
                Method addPropertyChangeListenerMetod = objectClass.getMethod("addPropertyChangeListener",
                   PropertyChangeListener.class);
                addPropertyChangeListenerMetod.invoke(objectnew Object[]
                { null });
             }
             catch (Exception e)
             {
                // dont worry
             }
 
             // call createXY methods (some of them are not used in practice, e.g
             // student.createUniversity())
             for (Method m : objectClass.getMethods())
             {
                String methodName = m.getName();
                if (methodName.startsWith("create") && m.getParameterTypes().length == 0)
                {
                   try
                   {
                      m.invoke(object);
                   }
                   catch (Exception e)
                   {
                   }
                }
 
                if (methodName.startsWith("get") && methodName.endsWith("Transitive"))
                {
                   try
                   {
                      m.invoke(object);
                   }
                   catch (Exception e)
                   {
                   }
                }
             }
 
             Method removeMethod = objectClass.getMethod("removeYou");
 
             removeMethod.invoke(object);
          }
          catch (Exception x)
          {
             // dont worry
          }
 
       }
    }
 
    public void coverSetAndPOClasses(JsonIdMap copyMap)
    {
       // loop through objects in jsonIdMap, pack them into set, read and write
       // all attributes
       LinkedHashSet<StringkeySet = new LinkedHashSet<String>();
       keySet.addAll(copyMap.keySet());
       for (String key : keySet)
       {
          Object object = copyMap.getObject(key);
 
          SendableEntityCreator creatorClass = copyMap.getCreatorClass(object);
 
          String className = object.getClass().getName();
          String packageName = CGUtil.packageName(className) + ".util";
          String setClassName = packageName + "." + CGUtil.shortClassName(className) + "Set";
 
          try
          {
             Class<?> setClass = Class.forName(setClassName);
             Object setObject = setClass.newInstance();
 
             if (setObject instanceof ModelSet)
             {
                // cover ModelSet methods
                String entryType = ((ModelSetsetObject).getEntryType();
             }
 
             // add entry
             Method withMethod = setClass.getMethod("with"new Class[]
             { Object.class });
             withMethod.invoke(setObjectobject);
             withMethod.invoke(setObjectsetObject);
 
             PatternObject patternObject = null;
             Class patternObjectClass = null;
             Method hasPOMethod = null;
             try
             {
                hasPOMethod = setClass.getMethod("has" + CGUtil.shortClassName(className) + "PO");
                patternObject = (PatternObjecthasPOMethod.invoke(setObject);
 
                patternObjectClass = patternObject.getClass();
 
                // call allMatches
                Method allMatchesMethod = patternObjectClass.getMethod("allMatches");
                allMatchesMethod.invoke(patternObject);
 
                // Method poConstructor =
                // patternObjectClass.getMethod(CGUtil.shortClassName(patternObjectClass.getName()));
                // poConstructor.invoke(null);
 
             }
             catch (Exception e)
             {
                // e.printStackTrace();
             }
 
             // toString
             String text = setObject.toString();
 
             // loop through attributes
             for (String attrName : creatorClass.getProperties())
             {
                try
                {
                   // call getter
                   Method getMethod = setClass.getMethod("get" + StrUtil.upFirstChar(attrName));
 
                   Object value = getMethod.invoke(setObject);
                   Object setValue = null;
                   // get direct value
                   if (value instanceof Collection)
                   {
                      setValue = value;
                      value = ((Collection<?>) value).iterator().next();
                   }
 
                   Class<?> valueClass = value.getClass();
 
                   if (value instanceof Integer)
                   {
                      valueClass = int.class;
                   }
                   else if (value instanceof Double)
                   {
                      valueClass = double.class;
                   }
                   else if (value instanceof Long)
                   {
                      valueClass = long.class;
                   }
                   else if (value instanceof Float)
                   {
                      valueClass = float.class;
                   }
                   else if (value instanceof Boolean)
                   {
                      valueClass = boolean.class;
                   }
 
                   // call setter
                   Method setMethod = setClass.getMethod("with" + StrUtil.upFirstChar(attrName), valueClass);
                   setMethod.invoke(setObjectvalue);
 
                   try
                   {
                      Method unsetMethod = setClass.getMethod("without" + StrUtil.upFirstChar(attrName), valueClass);
                      unsetMethod.invoke(setObjectvalue);
                   }
                   catch (Exception e)
                   {
                   }
 
                   try
                   {
                      Method hasMethod = setClass.getMethod("has" + StrUtil.upFirstChar(attrName), valueClass);
                      hasMethod.invoke(setObjectvalue);
 
                      hasMethod = setClass.getMethod("has" + StrUtil.upFirstChar(attrName), valueClassvalueClass);
                      hasMethod.invoke(setObjectvaluevalue);
                   }
                   catch (Exception e)
                   {
                   }
 
                   try
                   {
                      Method hasMethod = setClass.getMethod("has" + StrUtil.upFirstChar(attrName), Object.class);
                      hasMethod.invoke(setObjectvalue);
                      if (setValue != null)
                      {
                         hasMethod.invoke(setObjectsetValue);
                      }
                   }
                   catch (Exception e)
                   {
                   }
 
                   // also cover creatorclass set method
                   creatorClass.setValue(objectattrNamevalue"");
                   creatorClass.setValue(objectattrNamevalue.);
 
                   patternObject = (PatternObjecthasPOMethod.invoke(setObject);
 
                   if (patternObject != null)
                   {
                      // cover attr methods for pattern object
                      try
                      {
                         // getName
                         getMethod = patternObjectClass.getMethod("get" + StrUtil.upFirstChar(attrName));
                         getMethod.invoke(patternObject);
                      }
                      catch (Exception e)
                      {
                      }
                      try
                      {
                         // createName
                         withMethod = patternObjectClass.getMethod("with" + StrUtil.upFirstChar(attrName), valueClass);
                         withMethod.invoke(patternObjectvalue);
                      }
                      catch (Exception e)
                      {
                      }
                      try
                      {
                         // createName
                         Method createMethod = patternObjectClass.getMethod("create" + StrUtil.upFirstChar(attrName),
                            valueClass);
                         createMethod.invoke(patternObjectvalue);
                      }
                      catch (Exception e)
                      {
                      }
                      try
                      {
                         Method hasMethod = patternObjectClass.getMethod("has" + StrUtil.upFirstChar(attrName),
                            valueClass);
                         hasMethod.invoke(patternObjectvalue);
                      }
                      catch (Exception e)
                      {
                      }
                      try
                      {
                         Method hasMethod = patternObjectClass.getMethod("has" + StrUtil.upFirstChar(attrName),
                            valueClassvalueClass);
                         hasMethod.invoke(patternObjectvaluevalue);
                      }
                      catch (Exception e)
                      {
                      }
                      try
                      {
                         Method hasMethod = patternObjectClass.getMethod("has" + StrUtil.upFirstChar(attrName));
                         hasMethod.invoke(patternObject);
                      }
                      catch (Exception e)
                      {
                      }
                      try
                      {
                         Method method = patternObjectClass.getMethod("create" + StrUtil.upFirstChar(attrName));
                         method.invoke(patternObject);
                      }
                      catch (Exception e)
                      {
                      }
                      try
                      {
                         String poClassName = CGUtil.helperClassName(valueClass.getName(), "PO");
                         SendableEntityCreator poCreator = copyMap.getCreator(poClassNametrue);
                         Object po = poCreator.getSendableInstance(false);
                         try
                         {
                            Method method = patternObjectClass.getMethod("has" + StrUtil.upFirstChar(attrName),
                               po.getClass());
                            method.invoke(patternObjectpo);
                         }
                         catch (Exception e)
                         {
                         }
                         try
                         {
                            Method method = patternObjectClass.getMethod("with" + StrUtil.upFirstChar(attrName),
                               po.getClass());
                            method.invoke(patternObjectpo);
                         }
                         catch (Exception e)
                         {
                         }
                         try
                         {
                            Method method = patternObjectClass.getMethod("without" + StrUtil.upFirstChar(attrName),
                               po.getClass());
                            method.invoke(patternObjectpo);
                         }
                         catch (Exception e)
                         {
                         }
                         try
                         {
                            Method method = patternObjectClass.getMethod("create" + StrUtil.upFirstChar(attrName),
                               po.getClass());
                            method.invoke(patternObjectpo);
                         }
                         catch (Exception e)
                         {
                         }
                      }
                      catch (Exception e)
                      {
                      }
 
                   }
 
                }
                catch (Exception e)
                {
                   // no problem, go on with next attr
                }
             }
 
             // del entry
             Method withoutMethod = setClass.getMethod("without"object.getClass());
             withoutMethod.invoke(setObjectobject);
 
             creatorClass.getValue(object"foo.bar");
 
             ((EntityFactorycreatorClass).removeObject(object);
          }
          catch (Exception e)
          {
             // no problem, just lower coverage
             // e.printStackTrace();
          }
       }
 
    }
 
    public void addClassDiagram(ClassModel model)
    {
       String diagName = this.getName() + "ClassDiagram" + this.getStoryboardSteps().size();
       diagName = model.dumpClassDiagram(diagName);
       this.add(diagName);
    }
 
    public void addClassDiagram(ClassModel modelString rootDir)
    {
       String diagName = this.getName() + "ClassDiagram" + this.getStoryboardSteps().size();
       diagName = model.dumpClassDiagram(diagName);
       this.addSVGImage(diagName);
    }
 
    public void addObjectDiagramWith(Object... elems)
    {
       ArrayList<ObjecttempElems = new ArrayList<Object>(Arrays.asList((Object[]) elems));
       tempElems.add(true);
       Object[] moreElems = tempElems.toArray();
       addObjectDiagram(moreElems);
    }
 
    public void addObjectDiagram(Object... elems)
    {
       String objectName;
       String objectIcon;
       Object object;
       Object root = null;
       LinkedHashSet<ObjectexplicitElems = new LinkedHashSet<Object>();
       boolean restrictToExplicitElems = false;
 
       // go through all diagram elems
       int i = 0;
 
       while (i < elems.length)
       {
         objectName = null;
         objectIcon = null;
         object = null;
         while (i < elems.length && elems[iinstanceof String)
         {
            String txt = (Stringelems[i];
            String suffix = CGUtil.shortClassName(txt);
            if (txt.indexOf('.') >= 0 && "png gif tif".indexOf(suffix) >= 0)
            {
               // it is a file name
               objectIcon = txt;
            }
            else
            {
               // name for an object
               objectName = (Stringelems[i];
            }
            i++;
         }
         if (!(i < elems.length))
         {
            // ups no object for this name.
            break;
         }
         object = elems[i];
         i++;
         if (object == null)
         {
            continue;
         }
         if (object.equals(true))
         {
            restrictToExplicitElems = true;
            continue;
         }
         if (object.getClass().isPrimitive())
         {
            // not an object
            continue;
         }
         if (object instanceof Collection)
         {
            explicitElems.addAll((Collection<?>) object);
            Collection<?> coll = (Collection<?>) object;
            if (!coll.isEmpty())
            {
               object = coll.iterator().next();
            }
            else
            {
               continue;
            }
         }
         else
         {
            // plain object
            explicitElems.add(object);
         }
         if (root == null)
         {
            root = object;
         }
         // do we have a JsonIdMap?
         if ( == null)
         {
             = (JsonIdMapnew GenericIdMap().withSessionId(null);
            .getLogger().withError(false);
            // try to infer creator class
            String className = object.getClass().getName();
            String creatorClassName = CGUtil.helperClassName(className"Creator");
            try
            {
               Class<?> creatorClass = this.getClass().getClassLoader().loadClass(creatorClassName);
               Method createIdMapMethod = creatorClass.getDeclaredMethod("createIdMap"String.class);
                = (JsonIdMapcreateIdMapMethod.invoke(nullnew Object[0]);
               .getLogger().withError(false);
            }
            catch (Exception e)
            {
               // did not work, thus generic must be enough
            }
         }
         SendableEntityCreator objectCreator = .getCreatorClass(object);
         if (objectCreator == null || objectCreator instanceof GenericCreator)
         {
            String className = object.getClass().getName();
            String packageName = CGUtil.packageName(className) + ".util";
            className = CGUtil.helperClassName(className"Creator");
            Object idMap = null;
            try
            {
               Class<?> creatorClass = Class.forName(className);
               Method method = creatorClass.getDeclaredMethod("createIdMap"String.class);
               idMap = method.invoke(null"debug");
               .withCreator((((JsonIdMapidMap)));
            }
            catch (Exception e)
            {
               // cannot find creator creator class, use generic idMap instead;
               ..println("Could not find creator class for " + className);
               e.printStackTrace();
            }
         }
         // add to jsonIdMap
         if (objectName != null)
         {
            .put(objectNameobject);
         }
         else
         {
            objectName = .getId(object);
         }
         if (objectIcon != null)
         {
            .put(objectNameobjectIcon);
         }
      }
      // all names collected, dump it
      if (restrictToExplicitElems)
      {
         RestrictToFilter jsonFilter = new RestrictToFilter(explicitElems);
         addObjectDiagram(explicitElemsjsonFilter);
      }
      else
      {