cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r158097 - in cocoon/branches/BRANCH_2_1_X/src: blocks/forms/java/org/apache/cocoon/forms/DefaultCacheManager.java java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java
Date Fri, 18 Mar 2005 16:53:17 GMT
Author: vgritsenko
Date: Fri Mar 18 08:53:15 2005
New Revision: 158097

URL: http://svn.apache.org/viewcvs?view=rev&rev=158097
Log:
Use SourceValidity constants

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/DefaultCacheManager.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/DefaultCacheManager.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/DefaultCacheManager.java?view=diff&r1=158096&r2=158097
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/DefaultCacheManager.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/DefaultCacheManager.java
Fri Mar 18 08:53:15 2005
@@ -1,12 +1,12 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ * Copyright 1999-2005 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.
@@ -33,13 +33,13 @@
 
 /**
  * Component implementing the {@link CacheManager} role.
- * 
+ *
  * @version $Id$
  */
-public class DefaultCacheManager 
-  extends AbstractLogEnabled 
+public class DefaultCacheManager
+  extends AbstractLogEnabled
   implements CacheManager, ThreadSafe, Serviceable, Disposable, Configurable, Component {
-      
+
     protected ServiceManager manager;
     protected Configuration configuration;
     protected FastHashMap cache = new FastHashMap();
@@ -61,29 +61,30 @@
 
         // If source is not valid then remove object from cache and return null
         if (newValidity == null) {
-            cache.remove(key);
+            this.cache.remove(key);
             return null;
         }
 
         // If object is not in cache then return null
-        Object[] objectAndValidity = (Object[])cache.get(key);
-        if (objectAndValidity == null)
+        Object[] objectAndValidity = (Object[]) this.cache.get(key);
+        if (objectAndValidity == null) {
             return null;
+        }
 
-       // Check stored validity against current source validity
-        SourceValidity storedValidity = (SourceValidity)objectAndValidity[1];
+        // Check stored validity against current source validity
+        SourceValidity storedValidity = (SourceValidity) objectAndValidity[1];
         int valid = storedValidity.isValid();
         boolean isValid;
-        if (valid == 0) {
+        if (valid == SourceValidity.UNKNOWN) {
             valid = storedValidity.isValid(newValidity);
-            isValid = (valid == 1);
+            isValid = (valid == SourceValidity.VALID);
         } else {
-            isValid = (valid == 1);
+            isValid = (valid == SourceValidity.VALID);
         }
 
         // If stored object is not valid then remove object from cache and return null
         if (!isValid) {
-            cache.remove(key);
+            this.cache.remove(key);
             return null;
         }
 

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java?view=diff&r1=158096&r2=158097
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
Fri Mar 18 08:53:15 2005
@@ -491,23 +491,23 @@
                 while (responseIsValid && i < fromCacheValidityObjects.length)
{
                     boolean isValid = false;
 
-                    // BH check if validities[i] is null, may happen
-                    // if exception was thrown due to malformed content
+                    // BH Check if validities[i] is null, may happen
+                    //    if exception was thrown due to malformed content
                     SourceValidity validity = fromCacheValidityObjects[i];
-                    int valid = validity != null ? validity.isValid() : -1;
-                    if (valid == 0) { // don't know if valid, make second test
-
-                        validity = this.getValidityForInternalPipeline(i);
+                    int valid = validity == null ? SourceValidity.INVALID : validity.isValid();
+                    if (valid == SourceValidity.UNKNOWN) {
+                        // Don't know if valid, make second test
+                        validity = getValidityForInternalPipeline(i);
                         if (validity != null) {
-                            valid = fromCacheValidityObjects[i].isValid( validity );
-                            if (valid == 0) {
+                            valid = fromCacheValidityObjects[i].isValid(validity);
+                            if (valid == SourceValidity.UNKNOWN) {
                                 validity = null;
                             } else {
-                                isValid = (valid == 1);
+                                isValid = (valid == SourceValidity.VALID);
                             }
                         }
                     } else {
-                        isValid = (valid == 1);
+                        isValid = (valid == SourceValidity.VALID);
                     }
 
                     if (!isValid) {
@@ -564,7 +564,7 @@
                         this.cacheCompleteResponse = false;
                     } else {
                         // the entry is invalid, remove it
-                        this.cache.remove( this.fromCacheKey );
+                        this.cache.remove(this.fromCacheKey);
                     }
 
                     // try a shorter key
@@ -686,7 +686,7 @@
                     SourceValidity[] validities = cachedObject.getValidityObjects();
                     if (validities == null || validities.length != 1) {
                         // to avoid getting here again and again, we delete it
-                        this.cache.remove( pcKey );
+                        this.cache.remove(pcKey);
                         if (getLogger().isDebugEnabled()) {
                             getLogger().debug("Cached response for '" + environment.getURI()
+
                                               "' using key: " + pcKey + " is invalid.");
@@ -694,31 +694,31 @@
                         this.cachedResponse = null;
                     } else {
                         SourceValidity cachedValidity = validities[0];
-                        int result = cachedValidity.isValid();
-                        boolean valid = false;
-                        if ( result == 0 ) {
+                        boolean isValid = false;
+                        int valid = cachedValidity.isValid();
+                        if (valid == SourceValidity.UNKNOWN) {
                             // get reader validity and compare
                             if (isCacheableProcessingComponent) {
-                                readerValidity = ((CacheableProcessingComponent)super.reader).getValidity();
+                                readerValidity = ((CacheableProcessingComponent) super.reader).getValidity();
                             } else {
-                                CacheValidity cv = ((Cacheable)super.reader).generateValidity();
+                                CacheValidity cv = ((Cacheable) super.reader).generateValidity();
                                 if (cv != null) {
-                                    readerValidity = CacheValidityToSourceValidity.createValidity(
cv );
+                                    readerValidity = CacheValidityToSourceValidity.createValidity(cv);
                                 }
                             }
                             if (readerValidity != null) {
-                                result = cachedValidity.isValid(readerValidity);
-                                if ( result == 0 ) {
+                                valid = cachedValidity.isValid(readerValidity);
+                                if (valid == SourceValidity.UNKNOWN) {
                                     readerValidity = null;
                                 } else {
-                                    valid = (result == 1);
+                                    isValid = (valid == SourceValidity.VALID);
                                 }
                             }
                         } else {
-                            valid = (result > 0);
+                            isValid = (valid == SourceValidity.VALID);
                         }
 
-                        if (valid) {
+                        if (isValid) {
                             if (getLogger().isDebugEnabled()) {
                                 getLogger().debug("processReader: using valid cached content
for '" +
                                                   environment.getURI() + "'.");
@@ -726,10 +726,10 @@
                             byte[] response = cachedObject.getResponse();
                             if (response.length > 0) {
                                 usedCache = true;
-                                if ( cachedObject.getContentType() != null ) {
+                                if (cachedObject.getContentType() != null) {
                                     environment.setContentType(cachedObject.getContentType());
                                 } else {
-                                    this.setMimeTypeForReader(environment);
+                                    setMimeTypeForReader(environment);
                                 }
                                 outputStream = environment.getOutputStream(0);
                                 environment.setContentLength(response.length);

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java?view=diff&r1=158096&r2=158097
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java
Fri Mar 18 08:53:15 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 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.
@@ -28,7 +28,7 @@
  * <p>An aggregated {@link SourceValidity} for multiple sources.</p>
  *
  * @author <a href="http://www.apache.org/~sylvain">Sylvain Wallez</a>
- * @version CVS $Id$
+ * @version $Id$
  */
 public class MultiSourceValidity extends AbstractAggregatedValidity
                                  implements SourceValidity {
@@ -160,7 +160,7 @@
 
             /* Check the validity status */
             SourceValidity validity = (SourceValidity) validities.get(i);
-            switch(validity.isValid()) {
+            switch (validity.isValid()) {
 
                 /* The current source is valid: just continue to next source */
                 case SourceValidity.VALID:
@@ -173,24 +173,30 @@
                 /* The source validity is not known: check with the new source */
                 case SourceValidity.UNKNOWN:
                     /* We have no resolver: definitely don't know */
-                    if (resolver == null) return 0;
+                    if (resolver == null) {
+                        return SourceValidity.UNKNOWN;
+                    }
 
                     /* Check the new source by asking to the resolver */
                     Source newSrc = null;
                     int newValidity = SourceValidity.INVALID;
                     try {
-                        newSrc = resolver.resolveURI((String) uris.get(i));
+                        newSrc = resolver.resolveURI((String) this.uris.get(i));
                         newValidity = validity.isValid(newSrc.getValidity());
                     } catch(IOException ioe) {
                         /* Swallow the IOException, but set the new validity */
                         newValidity = SourceValidity.INVALID;
                     } finally {
                         /* Make sure that the source is released */
-                        if (newSrc != null) resolver.release(newSrc);
+                        if (newSrc != null) {
+                            resolver.release(newSrc);
+                        }
                     }
 
                     /* If the source is still valid, go to the next one */
-                    if (newValidity == SourceValidity.VALID) break;
+                    if (newValidity == SourceValidity.VALID) {
+                        break;
+                    }
 
                     /* The source is not valid (or unknown), we invalidate the lot */
                     return SourceValidity.INVALID;
@@ -202,6 +208,6 @@
         }
 
         /* All items checked successfully */
-        return 1;
+        return SourceValidity.VALID;
     }
 }



Mime
View raw message