/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package com.celements.pagetype.xobject;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.xwiki.component.annotation.Component;
import org.xwiki.component.annotation.Requirement;
import org.xwiki.context.Execution;

import com.celements.pagetype.IPageTypeConfig;
import com.celements.pagetype.IPageTypeProviderRole;
import com.celements.pagetype.PageTypeReference;
import com.celements.pagetype.cmd.GetPageTypesCommand;
import com.celements.pagetype.cmd.PageTypeCommand;
import com.xpn.xwiki.XWikiContext;

@Component("com.celements.XObjectPageTypeProvider")
public class XObjectPageTypeProvider implements IPageTypeProviderRole {

  GetPageTypesCommand getPageTypeCmd = new GetPageTypesCommand();
  PageTypeCommand pageTypeCmd = new PageTypeCommand();

  @Requirement
  Execution execution;

  private XWikiContext getContext() {
    return (XWikiContext) this.execution.getContext().getProperty("xwikicontext");
  }

  public IPageTypeConfig getPageTypeByReference(PageTypeReference pageTypeRef) {
    String pageTypeFN = pageTypeCmd.completePageTypeDocName(pageTypeRef.getConfigName());
    return getXObjectPTConfigForFN(pageTypeFN);
  }

  private XObjectPageTypeConfig getXObjectPTConfigForFN(String pageTypeFN) {
    return new XObjectPageTypeConfig(pageTypeFN);
  }

  public List<PageTypeReference> getPageTypes() {
    ArrayList<PageTypeReference> pageTypeList = new ArrayList<PageTypeReference>();
    Set<String> pageTypeSet = getPageTypeCmd.getAllXObjectPageTypes(getContext());
    for (String pageTypeFN : pageTypeSet) {
      XObjectPageTypeConfig xObjPT = getXObjectPTConfigForFN(pageTypeFN);
      pageTypeList.add(new PageTypeReference(xObjPT.getName(),
          "com.celements.XObjectPageTypeProvider", xObjPT.getCategories()));
    }
    return pageTypeList;
  }

}

@@ -998,24 +998,81 @@
 .util.Set;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import org.x
@@ -1104,24 +1104,24 @@
 .Component;%0A
-
 import org.x
@@ -1194,16 +1194,59 @@
 ecution;
+%0Aimport org.xwiki.context.ExecutionContext;
 %0A%0Aimport
@@ -1655,16 +1655,295 @@
 Role %7B%0A%0A
+  private static Logger LOGGER = LoggerFactory.getLogger(XObjectPageTypeProvider.class);%0A%0A  private String _CEL_XOBJ_GETALLPAGETYPES_COUNTER = %22celXObjectGetAllPageTypesCounter%22;%0A  private String _CEL_XOBJ_GETALLPAGETYPES_TOTALTIME =%0A      %22celXObjectGetAllPageTypesTotelTime%22;%0A%0A
   GetPag
@@ -2213,32 +2213,118 @@
 context%22);%0A  %7D%0A%0A
+  private ExecutionContext getExecContext() %7B%0A    return execution.getContext();%0A  %7D%0A%0A
   public IPageTy
@@ -2709,24 +2709,297 @@
 geTypes() %7B%0A
+    Integer count = 0;%0A    if (getExecContext().getProperty(_CEL_XOBJ_GETALLPAGETYPES_COUNTER) != null) %7B%0A      count = (Integer) getExecContext().getProperty(_CEL_XOBJ_GETALLPAGETYPES_COUNTER);%0A    %7D%0A    count = count++;%0A    long startMillis = System.currentTimeMillis();%0A
     ArrayLis
@@ -3334,16 +3334,16 @@
 Name(),%0A
-
         
@@ -3413,24 +3413,734 @@
 ()));%0A    %7D%0A
+    getExecContext().setProperty(_CEL_XOBJ_GETALLPAGETYPES_COUNTER, count);%0A    if (LOGGER.isInfoEnabled()) %7B%0A      long endMillis = System.currentTimeMillis();%0A      long timeUsed = endMillis - startMillis;%0A      Long totalTimeUsed = 0L;%0A      if (getExecContext().getProperty(_CEL_XOBJ_GETALLPAGETYPES_TOTALTIME) != null) %7B%0A        totalTimeUsed = (Long) getExecContext().getProperty(%0A            _CEL_XOBJ_GETALLPAGETYPES_TOTALTIME);%0A      %7D%0A      totalTimeUsed += timeUsed;%0A      getExecContext().setProperty(_CEL_XOBJ_GETALLPAGETYPES_TOTALTIME, totalTimeUsed);%0A      LOGGER.info(%22XOBJECT-getPageTypes %5B%22 + count + %22%5D: finished in %5B%22 + timeUsed%0A          + %22%5D, total time %5B%22 + totalTimeUsed + %22%5D.%22);%0A    %7D%0A
     return p

add performance messuring in XObjectPageTypeProvider