You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by lu...@apache.org on 2005/01/10 19:06:39 UTC

cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/resourcekind ResourceKindManager.java

luetzkendorf    2005/01/10 10:06:39

  Modified:    src/webdav/server/org/apache/slide/webdav/util/resourcekind
                        ResourceKindManager.java
  Log:
  improved configurability and logging
  
  Revision  Changes    Path
  1.4       +82 -43    jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/resourcekind/ResourceKindManager.java
  
  Index: ResourceKindManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/resourcekind/ResourceKindManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ResourceKindManager.java	3 Jan 2005 15:05:30 -0000	1.3
  +++ ResourceKindManager.java	10 Jan 2005 18:06:39 -0000	1.4
  @@ -32,18 +32,22 @@
   import javax.xml.parsers.SAXParser;
   import javax.xml.parsers.SAXParserFactory;
   
  +import org.apache.slide.common.Domain;
   import org.apache.slide.common.NamespaceAccessToken;
   import org.apache.slide.common.NamespaceConfig;
   import org.apache.slide.common.PropertyName;
   import org.apache.slide.content.NodeRevisionDescriptor;
   import org.apache.slide.content.NodeRevisionDescriptors;
  +import org.apache.slide.util.conf.Configurable;
   import org.apache.slide.util.conf.Configuration;
   import org.apache.slide.util.conf.ConfigurationElement;
   import org.apache.slide.util.conf.ConfigurationException;
   import org.apache.slide.util.conf.Populate;
  +import org.apache.slide.util.logger.Logger;
   import org.apache.slide.webdav.util.DeltavConstants;
   import org.apache.slide.webdav.util.UriHandler;
   import org.apache.slide.webdav.util.WebdavConstants;
  +import org.apache.slide.webdav.util.properties.ConfigurablePropertyComputer;
   import org.apache.slide.webdav.util.properties.PropertyComputer;
   import org.apache.slide.webdav.util.properties.PropertyDefaultProvider;
   import org.apache.slide.webdav.util.properties.PropertyValueValidator;
  @@ -57,6 +61,8 @@
    */
   public class ResourceKindManager
   {
  +    private static String LOG_CHANNEL = ResourceKindConfigurator.class.getName();
  +    
       public static Kind ACTIVITY = new Kind("Activity", ActivityImpl.getInstance());
       public static Kind BASELINE = new Kind("Baseline", BaselineImpl.getInstance());
       public static Kind CHECKED_IN_VERSION_CONTROLLED = new Kind("CheckedInVersionControlled", CheckedInVersionControlledImpl.getInstance());
  @@ -118,7 +124,8 @@
           else if( config.isPrincipal(resourcePath) ) {
               return PrincipalImpl.getInstance();
           }
  -        else if( nrd.propertyValueContains(WebdavConstants.PN_RESOURCETYPE, WebdavConstants.E_COLLECTION) ) {
  +        else if( nrd.propertyValueContains(WebdavConstants.PN_RESOURCETYPE, 
  +                WebdavConstants.E_COLLECTION) ) {
               return DeltavCompliantCollectionImpl.getInstance();
           }
           else {
  @@ -156,6 +163,15 @@
           resourceKind.instance.addSupportedMethod(methodName);
       }
       
  +    
  +    /**
  +     * Tests if the given property is protected at <em>any</em> resource kind.
  +     * @param name the properties name
  +     */
  +    static public boolean isProtectedProperty(PropertyName name) {
  +        return AbstractResourceKind.isGlobalProtectedProperty(name);
  +    }
  +    
       static void initFromDefaultConfig() {
           SAXParserFactory factory = SAXParserFactory.newInstance();
           factory.setNamespaceAware(false);
  @@ -183,7 +199,7 @@
           }
       }
       
  -    private static void initResourceKind(Configuration config) 
  +    static void initResourceKind(Configuration config) 
           throws ConfigurationException 
       {
           Kind kind = getKind(config.getAttribute("name"));
  @@ -192,7 +208,6 @@
               throw new ConfigurationException("Unknown resource kind name: " + config.getAttribute("name"), config);
           }
           
  -        System.out.println(kind);
           initProperties(config, kind);
           initReports(config, kind);
           initMethods(config, kind);
  @@ -214,33 +229,34 @@
                   
                   // TODO check features
                   
  -                System.out.print("\t" + name + ": ");
  -                String p = propConfig.getAttribute("computed", null);
  +                StringBuffer message = new StringBuffer();
  +                message.append(kind + " (property: " + name);
  +                String p = propConfig.getAttribute("computer", null);
                   if (p != null) {
                       // computed property
  -                    System.out.print("comupted " );
  -                    registerComputedProperty(kind, name, p);
  +                    message.append(" comupted" );
  +                    registerComputedProperty(kind, name, p, propConfig);
                   } 
                   p = propConfig.getAttribute("protected", "false");
                   if ("true".equals(p)) {
                       registerProtectedProperty(kind, name);
  -                    System.out.print("protected " );
  +                    message.append(" protected" );
                   }
                   
                   p = propConfig.getAttribute("validator", null);
                   if (p != null) {
                       registerPropertyValidator(kind, name, p);
  -                    System.out.print("validated " );
  +                    message.append(" validated" );
                   }
                   
                   p = propConfig.getAttribute("default", null);
                   if (p != null) {
  -                    System.out.print("default ");
  +                    message.append(" default");
                       registerDefault(kind, name, p);
                   } else {
                       try {
                           Configuration defaultValue = propConfig.getConfiguration("default-value");
  -                        System.out.print("default: " + defaultValue.getValue("") + " ");
  +                        message.append(" default:" + defaultValue.getValue(""));
                           registerDefault(kind, name, new SimpleDefaultProvider(
                                   name, defaultValue.getValue()));
                       } catch (ConfigurationException ex) {
  @@ -249,8 +265,11 @@
                   }
                   
                   // live property
  -                System.out.println("live ");
  +                message.append(" live");
                   registerLiveProperty(kind, name);
  +                
  +                message.append(")");
  +                log(message.toString());
               }
           }
       }
  @@ -265,7 +284,7 @@
                   
                   // TODO check features
                   registerReport(kind, repConfig.getAttribute("name"));
  -                System.out.println("\treport: " + repConfig.getAttribute("name"));
  +                log(kind + " (report: " + repConfig.getAttribute("name") + ")");
               }
           }
       }
  @@ -279,31 +298,46 @@
                   
                   // TODO check features
                   registerMethod(kind, methodConfig.getAttribute("name"));
  -                System.out.println("\tmethod: " + methodConfig.getAttribute("name"));
  +                log(kind + " (method: " + methodConfig.getAttribute("name") + ")");
               }
           }
       }
   
       private static void registerComputedProperty(Kind kind, PropertyName name, 
  -            String computerClass)
  +            String computerClass, Configuration propConfig)
       {
           try {
               Class cls = Class.forName(computerClass);
               PropertyComputer computer = (PropertyComputer)cls.newInstance();
  +            
  +            if (computer instanceof Configurable) {
  +                Configuration configuration = null;
  +                try {
  +                    configuration = propConfig.getConfiguration("computer-configuration");
  +                } catch (ConfigurationException e) {
  +                    // ignore; no configuration given, is OK too
  +                }
  +                if (configuration != null) {
  +                    ((Configurable)computer).configure(configuration);
  +                }
  +            }
  +            if (computer instanceof ConfigurablePropertyComputer) {
  +                ((ConfigurablePropertyComputer)computer).setPropertyName(name);
  +            }
  +            
               registerComputedProperty(kind, name, computer);
           } catch (ClassNotFoundException ex) {
  -            // TODO Auto-generated catch block
  -            ex.printStackTrace();
  +            error("Class " + computerClass + " for property not found!");
           } catch (InstantiationException ex) {
  -            // TODO Auto-generated catch block
  -            ex.printStackTrace();
  +            error("Object of class " + computerClass + 
  +                    " could not be instanciated!\n" + ex);
           } catch (IllegalAccessException ex) {
  -            // TODO Auto-generated catch block
  -            ex.printStackTrace();
  +            error("Object of class " + computerClass + 
  +                    " could not be instanciated!\n" + ex);
           } catch (ClassCastException ex) {
  -            // TODO Auto-generated catch block
  -            ex.printStackTrace();
  -        }
  +            error("Class " + computerClass + 
  +                    " does not implement PropertyComputer!");
  +        } 
       }
       private static void registerPropertyValidator(Kind kind, 
               PropertyName name, String validatorClass) {
  @@ -312,17 +346,16 @@
               PropertyValueValidator validator = (PropertyValueValidator)cls.newInstance();
               registerPropertyValidator(kind, name, validator);
           } catch (ClassNotFoundException ex) {
  -            // TODO Auto-generated catch block
  -            ex.printStackTrace();
  +            error("Class " + validatorClass + " for validator not found!");
           } catch (InstantiationException ex) {
  -            // TODO Auto-generated catch block
  -            ex.printStackTrace();
  +            error("Object of class " + validatorClass + 
  +                    " for validator could not be instanciated!\n" + ex);
           } catch (IllegalAccessException ex) {
  -            // TODO Auto-generated catch block
  -            ex.printStackTrace();
  +            error("Object of class " + validatorClass + 
  +                    " for validator could not be instanciated!\n" + ex);
           } catch (ClassCastException ex) {
  -            // TODO Auto-generated catch block
  -            ex.printStackTrace();
  +            error("Class " + validatorClass + 
  +                    " does not implement PropertyValueValidator!");
           }
       }
       private static void registerDefault(Kind kind, 
  @@ -332,20 +365,26 @@
               PropertyDefaultProvider provider = (PropertyDefaultProvider)cls.newInstance();
               registerDefault(kind, name, provider);
           } catch (ClassNotFoundException ex) {
  -            // TODO Auto-generated catch block
  -            ex.printStackTrace();
  +            error("Class " + defaultProviderClass + " for default not found!");
           } catch (InstantiationException ex) {
  -            // TODO Auto-generated catch block
  -            ex.printStackTrace();
  +            error("Object of class " + defaultProviderClass + 
  +                    " for default could not be instanciated!\n" + ex);
           } catch (IllegalAccessException ex) {
  -            // TODO Auto-generated catch block
  -            ex.printStackTrace();
  +            error("Object of class " + defaultProviderClass + 
  +                    " for default could not be instanciated!\n" + ex);
           } catch (ClassCastException ex) {
  -            // TODO Auto-generated catch block
  -            ex.printStackTrace();
  +            error("Object of class " + defaultProviderClass + 
  +                    " does not implement PropertyDefaultProvider!");
           }
       }
   
  +    private static void log(String msg) {
  +        Domain.log(msg, LOG_CHANNEL, Logger.DEBUG);
  +    }
  +    private static void error(String msg) {
  +        Domain.log(msg, LOG_CHANNEL, Logger.ERROR);
  +    }
  +    
       public static Kind getKind(String name) {
           return (Kind)Kind.kinds.get(name);
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org