masonjm     2004/12/15 08:26:52

  Modified:    src/share/org/apache/slide/common
                        NamespaceAccessTokenImpl.java
               src/share/org/apache/slide/macro MacroPropertyUpdater.java
  Added:       src/share/org/apache/slide/util NamespaceConfigUtil.java
  Log:
  Enhancement to allow the classes used to implement Content, Structure,
  Lock, Macro and Search to be specified in the namespace configuration.
  This makes it easier to extend functionality in the core.
  
  Revision  Changes    Path
  1.29      +21 -54    
jakarta-slide/src/share/org/apache/slide/common/NamespaceAccessTokenImpl.java
  
  Index: NamespaceAccessTokenImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/common/NamespaceAccessTokenImpl.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- NamespaceAccessTokenImpl.java     5 Aug 2004 15:42:32 -0000       1.28
  +++ NamespaceAccessTokenImpl.java     15 Dec 2004 16:26:51 -0000      1.29
  @@ -37,22 +37,15 @@
   import javax.xml.parsers.SAXParserFactory;
   
   import org.apache.slide.content.Content;
  -import org.apache.slide.content.ContentImpl;
   import org.apache.slide.event.EventDispatcher;
   import org.apache.slide.event.TransactionEvent;
   import org.apache.slide.event.VetoException;
   import org.apache.slide.lock.Lock;
  -import org.apache.slide.lock.LockImpl;
   import org.apache.slide.macro.Macro;
  -import org.apache.slide.macro.MacroImpl;
   import org.apache.slide.search.Search;
  -import org.apache.slide.search.SearchImpl;
  -import org.apache.slide.security.ACLSecurityImpl;
   import org.apache.slide.security.Security;
  -import org.apache.slide.security.SecurityImpl;
  -import org.apache.slide.security.SecurityImplAllGrant;
   import org.apache.slide.structure.Structure;
  -import org.apache.slide.structure.StructureImpl;
  +import org.apache.slide.util.NamespaceConfigUtil;
   import org.apache.slide.util.conf.Configuration;
   import org.apache.slide.util.conf.ConfigurationElement;
   import org.apache.slide.util.conf.ConfigurationException;
  @@ -72,10 +65,6 @@
       
       // ------------------------------------------------------------ 
Constructor
       
  -    private static String ACL_SEMANTICS                 = "acl_semantics";
  -    private static String ALL_GRANT_BEFORE_DENY           = 
"all-grant-before-any-deny";
  -    private static String LEGACY_ALL_GRANT_BEFORE_DENY    = 
"legacy-all-grant-before-any-deny";
  -    
       /**
        * Constructor.
        *
  @@ -83,44 +72,22 @@
        */
       NamespaceAccessTokenImpl(Namespace namespace) {
           this.namespace = namespace;
  -        NamespaceConfig config = namespace.getConfig();
  -        if (config != null) {
  -            String acl_semantics = config.getParameter(ACL_SEMANTICS);
  -            if ((acl_semantics != null) && 
(acl_semantics.equals(LEGACY_ALL_GRANT_BEFORE_DENY ))) {
  -                securityHelper = new SecurityImpl(namespace, 
namespace.getConfig());
  -            } else if((acl_semantics != null) && 
(acl_semantics.equals(ALL_GRANT_BEFORE_DENY ))) {
  -                securityHelper = new SecurityImplAllGrant(namespace, 
namespace.getConfig());
  -            } else if (acl_semantics != null) {
  -                try {
  -                    securityHelper = (Security) 
Class.forName(acl_semantics).newInstance();
  -                    if (securityHelper != null) {
  -                        securityHelper.init(namespace, 
namespace.getConfig());
  -                    }
  -                }catch (Exception e) {
  -                    e.printStackTrace();
  -                }
  -            }
  -        }
  -        if (securityHelper == null) {
  -            securityHelper = new ACLSecurityImpl(namespace, 
namespace.getConfig());
  -        }
  -        
  -        lockHelper =
  -            new LockImpl(namespace, namespace.getConfig(), securityHelper);
  -        
  -        structureHelper =
  -            new StructureImpl(namespace, namespace.getConfig(),
  -                              securityHelper, lockHelper);
  -        contentHelper =
  -            new ContentImpl(namespace, namespace.getConfig(), securityHelper,
  -                            structureHelper, lockHelper);
  -        searchHelper =
  -            new SearchImpl (namespace, namespace.getConfig(),
  -                            structureHelper, contentHelper);
  -        
  -        macroHelper =
  -            new MacroImpl(namespace, namespace.getConfig(), securityHelper,
  -                          contentHelper, structureHelper, lockHelper);
  +        
  +        securityHelper = 
NamespaceConfigUtil.getSecurityImplementation(namespace);
  +        
  +        lockHelper = NamespaceConfigUtil.getLockImplementation(namespace, 
securityHelper);
  +        
  +        structureHelper = NamespaceConfigUtil.getStructureImplementation(
  +                namespace, securityHelper, lockHelper);
  +        
  +        contentHelper = NamespaceConfigUtil.getContentImplementation(
  +                namespace, securityHelper, structureHelper, lockHelper);
  +        
  +        searchHelper = NamespaceConfigUtil.getSearchImplementation(
  +                namespace, structureHelper, contentHelper);
  +        
  +        macroHelper = NamespaceConfigUtil.getMacroImplementation(
  +                namespace, securityHelper, contentHelper, structureHelper, 
lockHelper);
       }
       
       
  
  
  
  1.1                  
jakarta-slide/src/share/org/apache/slide/util/NamespaceConfigUtil.java
  
  Index: NamespaceConfigUtil.java
  ===================================================================
  /*
   *  Copyright 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.slide.util;
  
  import org.apache.slide.common.Namespace;
  import org.apache.slide.common.NamespaceConfig;
  import org.apache.slide.content.Content;
  import org.apache.slide.content.ContentImpl;
  import org.apache.slide.lock.Lock;
  import org.apache.slide.lock.LockImpl;
  import org.apache.slide.macro.Macro;
  import org.apache.slide.macro.MacroImpl;
  import org.apache.slide.search.Search;
  import org.apache.slide.search.SearchImpl;
  import org.apache.slide.security.ACLSecurityImpl;
  import org.apache.slide.security.Security;
  import org.apache.slide.security.SecurityImpl;
  import org.apache.slide.security.SecurityImplAllGrant;
  import org.apache.slide.structure.Structure;
  import org.apache.slide.structure.StructureImpl;
  import org.apache.slide.util.logger.Logger;
  
  /**
   * Static methods to aid in accessing a [EMAIL PROTECTED] NamespaceConfig}
   */
  public class NamespaceConfigUtil {
      
      private static final String LOG_CHANNEL = 
NamespaceConfigUtil.class.toString();
      
      // Parameter names from Domain configuration file
      private static String ACL_SEMANTICS                  = "acl_semantics";
      private static String ALL_GRANT_BEFORE_DENY          = 
"all-grant-before-any-deny";
      private static String LEGACY_ALL_GRANT_BEFORE_DENY   = 
"legacy-all-grant-before-any-deny";
      
      private static String LOCK_IMPLEMENTATION_PARAM      = 
"lock-implementation-class";
      private static String STRUCTURE_IMPLEMENTATION_PARAM = 
"structure-implementation-class";
      private static String CONTENT_IMPLEMENTATION_PARAM   = 
"content-implementation-class";
      private static String SEARCH_IMPLEMENTATION_PARAM    = 
"search-implementation-class";
      private static String MACRO_IMPLEMENTATION_PARAM     = 
"macro-implementation-class";
      
      /**
       * NamespaceConfigUtil cannot be instantiated.
       */
      private NamespaceConfigUtil() {}
      
      /**
       * Returns a new instance of the [EMAIL PROTECTED] Security} 
implementation for the given [EMAIL PROTECTED] Namespace}.
       * 
       * @param namespace the [EMAIL PROTECTED] Namespace} to interogate
       * @return the [EMAIL PROTECTED] Security} implementation for the 
namespace
       */
      public static Security getSecurityImplementation(Namespace namespace) {
          Security securityHelper = null;
          NamespaceConfig config = namespace.getConfig();
          if (config != null) {
              String acl_semantics = config.getParameter(ACL_SEMANTICS);
              if ((acl_semantics != null) && 
(acl_semantics.equals(LEGACY_ALL_GRANT_BEFORE_DENY ))) {
                  securityHelper = new SecurityImpl(namespace, 
namespace.getConfig());
              } else if((acl_semantics != null) && 
(acl_semantics.equals(ALL_GRANT_BEFORE_DENY ))) {
                  securityHelper = new SecurityImplAllGrant(namespace, 
namespace.getConfig());
              } else if (acl_semantics != null) {
                  try {
                      securityHelper = (Security) 
Class.forName(acl_semantics).newInstance();
                      if (securityHelper != null) {
                          securityHelper.init(namespace, namespace.getConfig());
                      }
                  }catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          }
          // Default implementation
          if (securityHelper == null) {
              securityHelper = new ACLSecurityImpl(namespace, 
namespace.getConfig());
          }
          return securityHelper;
      }
      
      /**
       * Returns a new instance of the [EMAIL PROTECTED] Lock} implementation 
for the given [EMAIL PROTECTED] Namespace}.
       * 
       * @param namespace the [EMAIL PROTECTED] Namespace} to interogate
       * @return the [EMAIL PROTECTED] Lock} implementation for the namespace
       */
      public static Lock getLockImplementation(Namespace namespace) {
          return getLockImplementation(namespace, 
getSecurityImplementation(namespace));
      }
  
      /**
       * Returns a new instance of the [EMAIL PROTECTED] Lock} implementation 
for the given [EMAIL PROTECTED] Namespace}.
       * 
       * @param namespace the [EMAIL PROTECTED] Namespace} to interogate
       * @param security the [EMAIL PROTECTED] Security} implementation used to 
initialize the [EMAIL PROTECTED] Lock}
       * @return the [EMAIL PROTECTED] Lock} implementation for the namespace
       */
      public static Lock getLockImplementation(Namespace namespace, Security 
security) {
          Lock lockHelper = null;
          NamespaceConfig config = namespace.getConfig();
          if (config != null) {
              String lockImplemenation = 
config.getParameter(LOCK_IMPLEMENTATION_PARAM);
              if (lockImplemenation != null) {
                  try {
                      lockHelper = (Lock) Class.forName(
                              lockImplemenation).getConstructor(
                                      new Class[] {
                                              namespace.getClass(),
                                              config.getClass(),
                                              Security.class}
                                      ).newInstance(
                                              new Object[] {
                                                      namespace,
                                                      config,
                                                      security});
                  } catch (Exception e) {
                      namespace.getLogger().log(
                              "Cannot create Lock instance of type: " + 
lockImplemenation,
                              e, LOG_CHANNEL, Logger.ERROR);
                  }
              }
          }
          // Default implementation
          if (lockHelper == null) {
              lockHelper = new LockImpl(namespace, namespace.getConfig(), 
security);
          }
          return lockHelper;
      }
      
      /**
       * Returns a new instance of the [EMAIL PROTECTED] Structure} 
implementation for the given [EMAIL PROTECTED] Namespace}.
       * 
       * @param namespace the [EMAIL PROTECTED] Namespace} to interogate
       * @return the [EMAIL PROTECTED] Structure} implementation for the 
namespace
       */
      public static Structure getStructureImplementation(Namespace namespace) {
          Security security = getSecurityImplementation(namespace);
          Lock lock = getLockImplementation(namespace, security);
          return getStructureImplementation(namespace, security, lock);
      }
  
      /**
       * Returns a new instance of the [EMAIL PROTECTED] Structure} 
implementation for the given [EMAIL PROTECTED] Namespace}.
       * 
       * @param namespace the [EMAIL PROTECTED] Namespace} to interogate
       * @param security the [EMAIL PROTECTED] Security} implementation used to 
initialize the [EMAIL PROTECTED] Structure}
       * @param lock the [EMAIL PROTECTED] Lock} implementation used to 
initialize the [EMAIL PROTECTED] Structure}
       * @return the [EMAIL PROTECTED] Structure} implementation for the 
namespace
       */
      public static Structure getStructureImplementation(Namespace namespace, 
Security security, Lock lock) {
          Structure structureHelper = null;
          NamespaceConfig config = namespace.getConfig();
          if (config != null) {
              String structureImplemenation = 
config.getParameter(STRUCTURE_IMPLEMENTATION_PARAM);
              if (structureImplemenation != null) {
                  try {
                      structureHelper = (Structure) Class.forName(
                              structureImplemenation).getConstructor(
                                      new Class[] {
                                              namespace.getClass(),
                                              config.getClass(),
                                              Security.class,
                                              Lock.class}
                                      ).newInstance(
                                              new Object[] {
                                                      namespace,
                                                      config,
                                                      security,
                                                      lock});
                  } catch (Exception e) {
                      namespace.getLogger().log(
                              "Cannot create Structure instance of type: " + 
structureImplemenation,
                              e, LOG_CHANNEL, Logger.ERROR);
                  }
              }
          }
          // Default implementation
          if (structureHelper == null) {
              structureHelper = new StructureImpl(namespace, 
namespace.getConfig(), security, lock);
          }
          return structureHelper;
      }
      
      /**
       * Returns a new instance of the [EMAIL PROTECTED] Content} 
implementation for the given [EMAIL PROTECTED] Namespace}.
       * 
       * @param namespace the [EMAIL PROTECTED] Namespace} to interogate
       * @return the [EMAIL PROTECTED] Content} implementation for the namespace
       */
      public static Content getContentImplementation(Namespace namespace) {
          Security security = getSecurityImplementation(namespace);
          Lock lock = getLockImplementation(namespace, security);
          Structure structure = getStructureImplementation(namespace, security, 
lock);
          return getContentImplementation(namespace, security, structure, lock);
      }
  
      /**
       * Returns a new instance of the [EMAIL PROTECTED] Content} 
implementation for the given [EMAIL PROTECTED] Namespace}.
       * 
       * @param namespace the [EMAIL PROTECTED] Namespace} to interogate
       * @param security the [EMAIL PROTECTED] Security} implementation used to 
initialize the [EMAIL PROTECTED] Content}
       * @param structure the [EMAIL PROTECTED] Structure} implementation used 
to initialize the [EMAIL PROTECTED] Content}
       * @param lock the [EMAIL PROTECTED] Lock} implementation used to 
initialize the [EMAIL PROTECTED] Content}
       * @return the [EMAIL PROTECTED] Content} implementation for the namespace
       */
      public static Content getContentImplementation(Namespace namespace, 
Security security, Structure structure, Lock lock) {
          Content contentHelper = null;
          NamespaceConfig config = namespace.getConfig();
          if (config != null) {
              String contentImplemenation = 
config.getParameter(CONTENT_IMPLEMENTATION_PARAM);
              if (contentImplemenation != null) {
                  try {
                      contentHelper = (Content) Class.forName(
                              contentImplemenation).getConstructor(
                                      new Class[] {
                                              namespace.getClass(),
                                              config.getClass(),
                                              Security.class,
                                              Structure.class,
                                              Lock.class}
                                      ).newInstance(
                                              new Object[] {
                                                      namespace,
                                                      config,
                                                      security,
                                                      structure,
                                                      lock});
                  } catch (Exception e) {
                      namespace.getLogger().log(
                              "Cannot create Content instance of type: " + 
contentImplemenation,
                              e, LOG_CHANNEL, Logger.ERROR);
                  }
              }
          }
          // Default implementation
          if (contentHelper == null) {
              contentHelper = new ContentImpl(namespace, namespace.getConfig(), 
security, structure, lock);
          }
          return contentHelper;
      }
      
      /**
       * Returns a new instance of the [EMAIL PROTECTED] Search} implementation 
for the given [EMAIL PROTECTED] Namespace}.
       * 
       * @param namespace the [EMAIL PROTECTED] Namespace} to interogate
       * @return the [EMAIL PROTECTED] Search} implementation for the namespace
       */
      public static Search getSearchImplementation(Namespace namespace) {
          Security security = getSecurityImplementation(namespace);
          Lock lock = getLockImplementation(namespace, security);
          Structure structure = getStructureImplementation(namespace, security, 
lock);
          Content content = getContentImplementation(namespace, security, 
structure, lock);
          return getSearchImplementation(namespace, structure, content);
      }
  
      /**
       * Returns a new instance of the [EMAIL PROTECTED] Search} implementation 
for the given [EMAIL PROTECTED] Namespace}.
       * 
       * @param namespace the [EMAIL PROTECTED] Namespace} to interogate
       * @param structure the [EMAIL PROTECTED] Structure} implementation used 
to initialize the [EMAIL PROTECTED] Search}
       * @param content the [EMAIL PROTECTED] Content} implementation used to 
initialize the [EMAIL PROTECTED] Search}
       * @return the [EMAIL PROTECTED] Search} implementation for the namespace
       */
      public static Search getSearchImplementation(Namespace namespace, 
Structure structure, Content content) {
          Search searchHelper = null;
          NamespaceConfig config = namespace.getConfig();
          if (config != null) {
              String searchImplemenation = 
config.getParameter(SEARCH_IMPLEMENTATION_PARAM);
              if (searchImplemenation != null) {
                  try {
                      searchHelper = (Search) Class.forName(
                              searchImplemenation).getConstructor(
                                      new Class[] {
                                              namespace.getClass(),
                                              config.getClass(),
                                              Structure.class,
                                              Content.class}
                                      ).newInstance(
                                              new Object[] {
                                                      namespace,
                                                      config,
                                                      structure,
                                                      content});
                  } catch (Exception e) {
                      namespace.getLogger().log(
                              "Cannot create Search instance of type: " + 
searchImplemenation,
                              e, LOG_CHANNEL, Logger.ERROR);
                  }
              }
          }
          // Default implementation
          if (searchHelper == null) {
              searchHelper = new SearchImpl(namespace, namespace.getConfig(), 
structure, content);
          }
          return searchHelper;
      }
      
      /**
       * Returns a new instance of the [EMAIL PROTECTED] Macro} implementation 
for the given [EMAIL PROTECTED] Namespace}.
       * 
       * @param namespace the [EMAIL PROTECTED] Namespace} to interogate
       * @return the [EMAIL PROTECTED] Macro} implementation for the namespace
       */
      public static Macro getMacroImplementation(Namespace namespace) {
          Security security = getSecurityImplementation(namespace);
          Lock lock = getLockImplementation(namespace, security);
          Structure structure = getStructureImplementation(namespace, security, 
lock);
          Content content = getContentImplementation(namespace, security, 
structure, lock);
          return getMacroImplementation(namespace, security, content, 
structure, lock);
      }
  
      /**
       * Returns a new instance of the [EMAIL PROTECTED] Macro} implementation 
for the given [EMAIL PROTECTED] Namespace}.
       * 
       * @param namespace the [EMAIL PROTECTED] Namespace} to interogate
       * @param security the [EMAIL PROTECTED] Security} implementation used to 
initialize the [EMAIL PROTECTED] Macro}
       * @param content the [EMAIL PROTECTED] Content} implementation used to 
initialize the [EMAIL PROTECTED] Macro}
       * @param structure the [EMAIL PROTECTED] Structure} implementation used 
to initialize the [EMAIL PROTECTED] Macro}
       * @param lock the [EMAIL PROTECTED] Lock} implementation used to 
initialize the [EMAIL PROTECTED] Macro}
       * @return the [EMAIL PROTECTED] Macro} implementation for the namespace
       */
      public static Macro getMacroImplementation(Namespace namespace, Security 
security, Content content, Structure structure, Lock lock) {
          Macro macroHelper = null;
          NamespaceConfig config = namespace.getConfig();
          if (config != null) {
              String macroImplemenation = 
config.getParameter(MACRO_IMPLEMENTATION_PARAM);
              if (macroImplemenation != null) {
                  try {
                      macroHelper = (Macro) Class.forName(
                              macroImplemenation).getConstructor(
                                      new Class[] {
                                              namespace.getClass(),
                                              config.getClass(),
                                              Security.class,
                                              Content.class,
                                              Structure.class,
                                              Lock.class}
                                      ).newInstance(
                                              new Object[] {
                                                      namespace,
                                                      config,
                                                      security,
                                                      content,
                                                      structure,
                                                      lock});
                  } catch (Exception e) {
                      namespace.getLogger().log(
                              "Cannot create Macro instance of type: " + 
macroImplemenation,
                              e, LOG_CHANNEL, Logger.ERROR);
                  }
              }
          }
          // Default implementation
          if (macroHelper == null) {
              macroHelper = new MacroImpl(namespace, namespace.getConfig(), 
security, content, structure, lock);
          }
          return macroHelper;
      }
  
  }
  
  
  
  1.8       +18 -22    
jakarta-slide/src/share/org/apache/slide/macro/MacroPropertyUpdater.java
  
  Index: MacroPropertyUpdater.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/macro/MacroPropertyUpdater.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- MacroPropertyUpdater.java 19 Oct 2004 11:30:08 -0000      1.7
  +++ MacroPropertyUpdater.java 15 Dec 2004 16:26:51 -0000      1.8
  @@ -25,19 +25,16 @@
   import org.apache.slide.common.Domain;
   import org.apache.slide.common.Uri;
   import org.apache.slide.content.Content;
  -import org.apache.slide.content.ContentImpl;
   import org.apache.slide.content.NodeRevisionDescriptor;
   import org.apache.slide.content.NodeRevisionDescriptors;
   import org.apache.slide.event.MacroEvent;
   import org.apache.slide.event.MacroListener;
   import org.apache.slide.event.VetoException;
   import org.apache.slide.lock.Lock;
  -import org.apache.slide.lock.LockImpl;
  -import org.apache.slide.security.ACLSecurityImpl;
   import org.apache.slide.security.Security;
   import org.apache.slide.structure.Structure;
  -import org.apache.slide.structure.StructureImpl;
   import org.apache.slide.structure.SubjectNode;
  +import org.apache.slide.util.NamespaceConfigUtil;
   import org.apache.slide.util.conf.Configurable;
   import org.apache.slide.util.conf.Configuration;
   import org.apache.slide.util.conf.ConfigurationException;
  @@ -212,21 +209,20 @@
     }
   
     private Content getContentHelper(MacroEvent event) {
  -     Security security = new ACLSecurityImpl(event.getNamespace(),
  -                                             
event.getNamespace().getConfig());
  -     Lock lock = new LockImpl(event.getNamespace(),
  -                              event.getNamespace().getConfig(),
  -                              security);
  -     Structure structure = new StructureImpl(event.getNamespace(),
  -                              event.getNamespace().getConfig(),
  -                              security,
  -                              lock);
  -     Content helper = new ContentImpl(
  -           event.getNamespace(),
  -           event.getNamespace().getConfig(),
  -           security,
  -           structure,
  -           lock);
  +     Security security = NamespaceConfigUtil.getSecurityImplementation(
  +             event.getNamespace());
  +     Lock lock = NamespaceConfigUtil.getLockImplementation(
  +             event.getNamespace(),
  +             security);
  +     Structure structure = NamespaceConfigUtil.getStructureImplementation(
  +             event.getNamespace(),
  +             security,
  +             lock);     
  +     Content helper = NamespaceConfigUtil.getContentImplementation(
  +             event.getNamespace(),
  +             security,
  +             structure,
  +             lock);
        return helper;
     }
   }
  
  
  

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

Reply via email to