public void writeClassBegin()

in maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/AbstractComponentGenerator.java [69:246]


  public void writeClassBegin(
      PrettyWriter out,
      String className,
      String superclassName,
      ComponentBean component,
      SourceTemplate template,
      boolean createSuperclass)
  {
    if (className == null)
      throw new NullPointerException();
    
    out.println("/**");

    // TODO: restore description (needs escaping?)
//    String description = component.getDescription();
//    if (description != null)
//    {
//      out.println(" *");
//      out.println(" * " + convertMultilineComment(description));
//    }

    String longDescription = component.getLongDescription();
    if (longDescription != null)
    {
      out.println(" *");
      out.println(" * " + convertMultilineComment(longDescription));
    }

    if (component.hasEvents(true))
    {
      // the events javadoc
      out.println(" *");
      out.println(" * <h4>Events:</h4>");
      out.println(" * <table border=\"1\" width=\"100%\" cellpadding=\"3\" summary=\"\">");
      out.println(" * <tr bgcolor=\"#CCCCFF\" class=\"TableHeadingColor\">");
      out.println(" * <th align=\"left\">Type</th>");
      out.println(" * <th align=\"left\">Phases</th>");
      out.println(" * <th align=\"left\">Description</th>");
      out.println(" * </tr>");
      Iterator<EventRefBean> events = component.events(true);
      while (events.hasNext())
      {
        EventRefBean eventRef = events.next();
        EventBean event = eventRef.resolveEventType();
        if (event != null)
        {
          String eventClass = event.getEventClass();
          String[] eventPhases = eventRef.getEventDeliveryPhases();
          String eventDescription = event.getDescription();
          out.println(" * <tr class=\"TableRowColor\">");
          out.println(" * <td valign=\"top\"><code>" + eventClass + "</code></td>");
          out.print(" * <td valign=\"top\" nowrap>");
          if (eventPhases != null)
          {
            for (int i = 0; i < eventPhases.length; i++)
            {
              if (i > 0)
                out.print("<br>");
              out.print(eventPhases[i]);
            }
          }
          out.println("</td>");
          out.println(" * <td valign=\"top\">" + eventDescription + "</td>");
          out.println(" * </tr>");
        }
      }
      out.println(" * </table>");
    }

    if (!component.hasChildren())
    {
      out.println(" * <p>");
      out.println(" * It does not support any children.");
    }

    String deprecatedMessage = component.getDeprecated();
    if (deprecatedMessage != null)
    {
      out.println(" * @deprecated " + convertMultilineComment(deprecatedMessage));
    }
    out.println(" */");

    if (deprecatedMessage != null)
    {
      out.println("@Deprecated");
    }

    // TODO: eliminate <mfp:component-class-modifier> metadata
    int modifiers = component.getComponentClassModifiers();
    
    // make abstract superclass classes abstract and package private
    if (createSuperclass)
    {
      // we would really like to make this package private, but because of a bug in the Java
      // Introspection code, a get on a final method of a public class inherited from a
      // package private class actually refers to the package private class.  The result
      // is that invoking it blows up.  Therefore, instead of making the class package private,
      // we have to make it public. GRRR.
    
      // remove all of the access modifiers to make this package private
      modifiers &= ~(Modifier.PRIVATE | Modifier.PROTECTED); // Modifier.PUBLIC
      
      // force abstract on as well as public, due to stupid bug
      modifiers |= Modifier.ABSTRACT | Modifier.PUBLIC;
    }
    else
    {
      // if no modifier is specified, default to public
      if ((modifiers & (Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED)) == 0)
      {
        modifiers |= Modifier.PUBLIC;
      }
    }
    
    String classStart = Modifier.toString(modifiers);
    // TODO: use canonical ordering
    classStart = classStart.replaceAll("public abstract", "abstract public");
    out.println(classStart + " class " + className +
        " extends " + superclassName);

    Set<String> interfaces = new HashSet<String>();
    if (template != null)
      interfaces.addAll(template.getImplements());

    if (component.isNamingContainer())
      interfaces.add("javax.faces.component.NamingContainer");

    if (component.isClientBehaviorHolder())
      interfaces.add("javax.faces.component.behavior.ClientBehaviorHolder");

    Iterator<EventRefBean> events = component.events();
    while (events.hasNext())
    {
      EventRefBean eventRef = events.next();
      EventBean event = eventRef.resolveEventType();
      if (event != null)
      {
        if (!eventRef.isIgnoreSourceInterface())
        {
          String source = event.getEventSourceInterface();
          if (source != null)
            interfaces.add(Util.getClassFromFullClass(source));
        }
      }
    }

    if (!interfaces.isEmpty())
    {
      Set<String> implementsSet = new HashSet<String>();
      for (Iterator iter = interfaces.iterator(); iter.hasNext();)
      {
        String fcqn = (String) iter.next();
        implementsSet.add(Util.getClassFromFullClass(fcqn));
      }

      // implements clause spans multiple lines
      char[] indent = new char[classStart.length() +
          " class ".length() +
          className.length() + 1];
      Arrays.fill(indent, ' ');
      out.print(indent);
      out.print("implements ");
      for (Iterator iter = implementsSet.iterator(); iter.hasNext();)
      {
        out.print((String) iter.next());
        if (iter.hasNext())
        {
          out.println(",");
          out.print(indent);
          out.print("           ");  // same length as "implements "
        }
      }
      out.println();
    }

    out.println("{");
    out.indent();
  }