package org.jboss.webbeans.util;

import java.lang.annotation.Annotation;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jboss.webbeans.bean.EnterpriseBean;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.contexts.ApplicationContext;
import org.jboss.webbeans.ejb.EjbMetaData;
import org.jboss.webbeans.test.beans.Chicken;
import org.jboss.webbeans.test.ejb.model.valid.Laika;

/**
 * Utility class to produce friendly names e.g. for debugging
 * 
 * @author Pete Muir
 * 
 */
public class Names
{

   private static Pattern CAPITAL_LETTERS = Pattern.compile("\\p{Upper}{1}\\p{Lower}*");

   public static String scopeTypeToString(Class<? extends Annotation> scopeType)
   {
      String scopeName = scopeType.getSimpleName();
      Matcher matcher = CAPITAL_LETTERS.matcher(scopeName);
      StringBuilder result = new StringBuilder();
      while (matcher.find())
      {
         result.append(matcher.group().toLowerCase() + " ");
      }
      return result.toString();
   }

   public static String ejbTypeFromMetaData(EjbMetaData<?> ejbMetaData)
   {
      if (ejbMetaData.isMessageDriven())
      {
         return "message driven";
      }
      else if (ejbMetaData.isSingleton())
      {
         return "singleton";
      }
      else if (ejbMetaData.isStateful())
      {
         return "stateful";
      }
      else if (ejbMetaData.isStateless())
      {
         return "stateless";
      }
      return "unknown";
   }

   public static int count(Iterable<?> iterable)
   {
      int count = 0;
      for (Iterator<?> i = iterable.iterator(); i.hasNext();)
      {
         count++;
      }
      return count;
   }

}

@@ -189,267 +189,22 @@
 ans.
-bean.EnterpriseBean;%0Aimport org.jboss.webbeans.bean.SimpleBean;%0Aimport org.jboss.webbeans.contexts.ApplicationContext;%0Aimport org.jboss.webbeans.ejb.EjbMetaData;%0Aimport org.jboss.webbeans.test.beans.Chicken;%0Aimport org.jboss.webbeans.test.ejb.model.valid.Laik
+ejb.EjbMetaDat
 a;%0A%0A

fix broken build