taylor      2004/09/17 13:02:03

  Added:       components/locator/src/java/org/apache/jetspeed/profiler/impl
                        JetspeedProfiledPageContext.java
                        ProfileLocatorControl.java
                        ProfileLocatorPropertyImpl.java
                        JetspeedProfileLocator.java
                        ProfileFallbackIterator.java
  Log:
  decoupled profiler from page manager, moving profile locator into locator package
  implementationby Randy Watler
  
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.1                  
jakarta-jetspeed-2/components/locator/src/java/org/apache/jetspeed/profiler/impl/JetspeedProfiledPageContext.java
  
  Index: JetspeedProfiledPageContext.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.profiler.impl;
  
  import org.apache.jetspeed.om.folder.Folder;
  import org.apache.jetspeed.om.page.Page;
  import org.apache.jetspeed.page.document.NodeSet;
  import org.apache.jetspeed.profiler.ProfileLocator;
  import org.apache.jetspeed.profiler.ProfiledPageContext;
  import org.apache.jetspeed.profiler.Profiler;
  
  /**
   * JetspeedProfiledPageContext
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Randy Watler</a>
   * @version $Id: JetspeedProfiledPageContext.java,v 1.1 2004/09/17 20:02:03 taylor 
Exp $
   */
  public class JetspeedProfiledPageContext implements ProfiledPageContext
  {    
      private ProfileLocator locator;
      private Page page;
      private Folder folder;
      private NodeSet siblingPages;
      private Folder parentFolder;
      private NodeSet siblingFolders;
      private NodeSet rootLinks;
  
      public void init(Profiler profiler, ProfileLocator locator)
      {
          // save profiled context supplied by profiler
          this.locator = locator;
      }
  
      public ProfileLocator getLocator()
      {
          return locator;
      }
  
      public Page getPage()
      {
          return page;
      }
  
      public void setPage(Page page)
      {
          this.page = page;
      }
  
      public Folder getFolder()
      {
          return folder;
      }
  
      public void setFolder(Folder folder)
      {
          this.folder = folder;
      }
  
      public NodeSet getSiblingPages()
      {
          return siblingPages;
      }
  
      public void setSiblingPages(NodeSet pages)
      {
          this.siblingPages = pages;
      }
  
      public Folder getParentFolder()
      {
          return parentFolder;
      }
  
      public void setParentFolder(Folder folder)
      {
          this.parentFolder = folder;
      }
  
      public NodeSet getSiblingFolders()
      {
          return siblingFolders;
      }
  
      public void setSiblingFolders(NodeSet folders)
      {
          this.siblingFolders = folders;
      }
  
      public NodeSet getRootLinks()
      {
          return rootLinks;
      }
  
      public void setRootLinks(NodeSet links)
      {
          this.rootLinks = links;
      }
  }
  
  
  
  1.1                  
jakarta-jetspeed-2/components/locator/src/java/org/apache/jetspeed/profiler/impl/ProfileLocatorControl.java
  
  Index: ProfileLocatorControl.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.profiler.impl;
  
  import java.util.List;
  
  import org.apache.jetspeed.profiler.ProfileLocator;
  
  /**
   * ProfileLocatorControl
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: ProfileLocatorControl.java,v 1.1 2004/09/17 20:02:03 taylor Exp $
   */
  public interface ProfileLocatorControl extends ProfileLocator
  {
      List getElements();
  }
  
  
  
  1.1                  
jakarta-jetspeed-2/components/locator/src/java/org/apache/jetspeed/profiler/impl/ProfileLocatorPropertyImpl.java
  
  Index: ProfileLocatorPropertyImpl.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.profiler.impl;
  
  import org.apache.jetspeed.profiler.ProfileLocatorProperty;
  import org.apache.jetspeed.profiler.rules.ProfilingRule;
  import org.apache.jetspeed.profiler.rules.RuleCriterion;
  
  /**
   * ProfileLocatorElement
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: ProfileLocatorPropertyImpl.java,v 1.1 2004/09/17 20:02:03 taylor 
Exp $
   */
  public class ProfileLocatorPropertyImpl implements ProfileLocatorProperty
  {
      private String name;
      private String value;
      private String type;
      private int fallbackType;
      private boolean isControl;
          
      public ProfileLocatorPropertyImpl(RuleCriterion criterion, boolean isControl, 
String value)
      {
          this.name = criterion.getName();
          this.value = value;
          this.type = criterion.getType();
          this.fallbackType = criterion.getFallbackType();
          this.isControl = isControl;
      }
      
      public ProfileLocatorPropertyImpl(String name, boolean isControl, String value)
      {
          this.name = name;
          this.value = value;
          this.type = ProfilingRule.STANDARD;
          this.fallbackType = RuleCriterion.FALLBACK_CONTINUE;
          this.isControl = isControl;
      }
  
      /**
       * @return
       */
      public String getValue()
      {
          return value;
      }
  
      /**
       * @param string
       */
      public void setValue(String value)
      {
          this.value = value;
      }
  
  
      /**
       * @return
       */
      public int getFallbackType()
      {
          return fallbackType;
      }
  
      /**
       * @return
       */
      public String getName()
      {
          return name;
      }
  
      /**
       * @return
       */
      public String getType()
      {
          return type;
      }
  
      /**
       * @param i
       */
      public void setFallbackType(int i)
      {
          fallbackType = i;
      }
  
      /**
       * @param string
       */
      public void setName(String string)
      {
          name = string;
      }
  
      /**
       * @param string
       */
      public void setType(String string)
      {
          type = string;
      }
  
      /**
       * @return control classification flag
       */
      public boolean isControl()
      {
          return isControl;
      }
  
  }
  
  
  
  1.1                  
jakarta-jetspeed-2/components/locator/src/java/org/apache/jetspeed/profiler/impl/JetspeedProfileLocator.java
  
  Index: JetspeedProfileLocator.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.profiler.impl;
  
  import java.util.Iterator;
  import java.util.LinkedList;
  import java.util.List;
  import java.util.ListIterator;
  import java.util.StringTokenizer;
  
  import org.apache.jetspeed.profiler.ProfiledPageContext;
  import org.apache.jetspeed.profiler.ProfileLocator;
  import org.apache.jetspeed.profiler.ProfileLocatorProperty;
  import org.apache.jetspeed.profiler.Profiler;
  import org.apache.jetspeed.profiler.rules.RuleCriterion;
  
  /**
   * ProfileLocatorImpl
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: JetspeedProfileLocator.java,v 1.1 2004/09/17 20:02:03 taylor Exp $
   */
  public class JetspeedProfileLocator implements ProfileLocatorControl
  {    
      private LinkedList elements = new LinkedList();
      private Profiler profiler;
      private String requestPath;
  
      public List getElements()
      {
          return elements;
      }
  
      public void init(Profiler profiler, String requestPath)
      {
          this.profiler = profiler;
          if (requestPath != null)
              if (requestPath.indexOf("/") != -1)
                  this.requestPath = requestPath;
              else
                  this.requestPath = "/" + requestPath;
          else
              this.requestPath = "/";
      }
  
      public Iterator iterator()
      {    
          return new ProfileFallbackIterator(this);
      }
      
      public String getValue(String name)
      {
          Iterator iter = elements.iterator();
          while (iter.hasNext())
          {
              ProfileLocatorPropertyImpl element = 
(ProfileLocatorPropertyImpl)iter.next();
              String elementName = element.getName();
              if (elementName != null && elementName.equals(name))
              {
                  return element.getValue();
              }
          }
          return null;
      }
  
      public boolean isControl(String name)
      {
          Iterator iter = elements.iterator();
          while (iter.hasNext())
          {
              ProfileLocatorPropertyImpl element = 
(ProfileLocatorPropertyImpl)iter.next();
              String elementName = element.getName();
              if (elementName != null && elementName.equals(name))
              {
                  return element.isControl();
              }
          }
          return false;
      }
      
      public void add(RuleCriterion criterion, boolean isControl, String value)
      {
          elements.add(new ProfileLocatorPropertyImpl(criterion, isControl, value));
      }
  
      public void add(String name, boolean isControl, String value)
      {
          elements.add(new ProfileLocatorPropertyImpl(name, isControl, value));
      }
      
      public void add(String name, String value)
      {
          add(name, true, value);
      }
      
      public void createFromLocatorPath(String path)
      {
          elements.clear();
          StringTokenizer tokenizer = new StringTokenizer(path, 
ProfileLocator.PATH_SEPARATOR);
          while (tokenizer.hasMoreTokens())
          {
              String name = (String)tokenizer.nextToken();
              if (tokenizer.hasMoreTokens())
              {
                  String value = tokenizer.nextToken();
                  this.add(name, true, value);
              }
          }        
      }
                      
      public String getLocatorPath()
      {
          StringBuffer key = new StringBuffer();
          ListIterator it = elements.listIterator();
          while (it.hasNext())
          {
              ProfileLocatorPropertyImpl element = 
(ProfileLocatorPropertyImpl)it.next();
              key.append(element.getName());
              key.append(ProfileLocator.PATH_SEPARATOR);
              key.append(element.getValue());
              if (it.hasNext())
              {
                  key.append(ProfileLocator.PATH_SEPARATOR);
              }
          }
          return key.toString();
      }
          
      public String getLocatorPath(ProfileLocatorProperty [] properties)
      {
          StringBuffer key = new StringBuffer();
          if (properties != null)
              for (int i = 0; (i < properties.length); i++)
              {
                  if (i > 0)
                      key.append(ProfileLocator.PATH_SEPARATOR);
                  key.append(properties[i].getName());
                  key.append(ProfileLocator.PATH_SEPARATOR);
                  key.append(properties[i].getValue());
              }
          return key.toString();
      }
  
      public String toString()
      {
          return getRequestPath() + ProfileLocator.PATH_SEPARATOR + getLocatorPath();
      }
          
      public String getRequestPath()
      {
          return requestPath;
      }
  
      public ProfiledPageContext createProfiledPageContext()
      {
          if (profiler != null)
              return profiler.createProfiledPageContext(this);
          return null;
      }
  }
  
  
  
  1.1                  
jakarta-jetspeed-2/components/locator/src/java/org/apache/jetspeed/profiler/impl/ProfileFallbackIterator.java
  
  Index: ProfileFallbackIterator.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.profiler.impl;
  
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.jetspeed.profiler.ProfileLocator;
  import org.apache.jetspeed.profiler.ProfileLocatorProperty;
  import org.apache.jetspeed.profiler.rules.RuleCriterion;
  
  /**
   * ProfileFallbackIterator
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: ProfileFallbackIterator.java,v 1.1 2004/09/17 20:02:03 taylor Exp $
   */
  public class ProfileFallbackIterator implements Iterator
  {
      private ProfileLocatorControl locator;
      private int last = 0;
      private int state = RuleCriterion.FALLBACK_CONTINUE;     
      private ProfileFallbackIterator()
      {
      }
      
      public ProfileFallbackIterator(ProfileLocatorControl locator)
      {
          this.locator = locator;
          last = locator.getElements().size() - 1;
      }
      
      /* (non-Javadoc)
       * @see java.util.Iterator#remove()
       */
      public void remove()
      {
          // TODO Auto-generated method stub
      }
      
      /* (non-Javadoc)
       * @see java.util.Iterator#hasNext()
       */
      public boolean hasNext()
      {
          boolean hasNext = false;
          
          List elements = locator.getElements();
          
          if (last < 0 || last >= elements.size())
          {
              state = RuleCriterion.FALLBACK_STOP;
              return false;
          }
          
          if (state == RuleCriterion.FALLBACK_STOP)
          {
              hasNext = false;
          }        
          else if (state == RuleCriterion.FALLBACK_CONTINUE ||
                   state == RuleCriterion.FALLBACK_LOOP)
          {
              hasNext = true;
          }
          
          ProfileLocatorPropertyImpl element = 
(ProfileLocatorPropertyImpl)elements.get(last);
          state = element.getFallbackType();
                  
          return hasNext;
      }
      
      /* (non-Javadoc)
       * @see java.util.Iterator#next()
       */
      public Object next()
      {
          ProfileLocatorProperty [] properties = null;
  
          if (last >= 0)
          {
              List elements = locator.getElements();
              properties = new ProfileLocatorProperty[last+1];
              Iterator it = elements.listIterator();
              for (int count = 0; (count <= last) && it.hasNext(); count++)
                  properties[count] = (ProfileLocatorProperty)it.next();
              last--;
          }
  
          return properties;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to