You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by bl...@apache.org on 2001/02/17 20:09:13 UTC
cvs commit: xml-cocoon/src/org/apache/cocoon/components/store FilesystemStore.java
bloritsch 01/02/17 11:09:13
Modified: src/org/apache/cocoon/components/language/generator Tag:
xml-cocoon2 ProgramGeneratorImpl.java
src/org/apache/cocoon/components/store Tag: xml-cocoon2
FilesystemStore.java
Log:
Fix for REPOSITORY
Revision Changes Path
No revision
No revision
1.1.2.30 +82 -74 xml-cocoon/src/org/apache/cocoon/components/language/generator/Attic/ProgramGeneratorImpl.java
Index: ProgramGeneratorImpl.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/generator/Attic/ProgramGeneratorImpl.java,v
retrieving revision 1.1.2.29
retrieving revision 1.1.2.30
diff -u -r1.1.2.29 -r1.1.2.30
--- ProgramGeneratorImpl.java 2001/02/16 22:07:34 1.1.2.29
+++ ProgramGeneratorImpl.java 2001/02/17 19:09:10 1.1.2.30
@@ -45,7 +45,7 @@
/**
* The default implementation of <code>ProgramGenerator</code>
* @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
- * @version CVS $Revision: 1.1.2.29 $ $Date: 2001/02/16 22:07:34 $
+ * @version CVS $Revision: 1.1.2.30 $ $Date: 2001/02/17 19:09:10 $
*/
public class ProgramGeneratorImpl extends AbstractLoggable implements ProgramGenerator, Contextualizable, Composer, Configurable, ThreadSafe {
@@ -126,81 +126,89 @@
* @return The loaded program instance
* @exception Exception If an error occurs during generation or loading
*/
- public CompiledComponent load(File file, String markupLanguageName, String programmingLanguageName,
- EntityResolver resolver) throws Exception {
- // Get markup and programming languages
- MarkupLanguage markupLanguage = (MarkupLanguage)this.markupSelector.select(markupLanguageName);
- ProgrammingLanguage programmingLanguage =
- (ProgrammingLanguage)this.languageSelector.select(programmingLanguageName);
- programmingLanguage.setLanguageName(programmingLanguageName);
- // Create filesystem store
- // Set filenames
- String filename = IOUtils.getFullFilename(file);
- String normalizedName = IOUtils.normalizedFilename(filename);
- String sourceExtension = programmingLanguage.getSourceExtension();
- // Ensure no 2 requests for the same file overlap
- Class program = null;
- CompiledComponent programInstance = null;
+ public CompiledComponent load(File file,
+ String markupLanguageName,
+ String programmingLanguageName,
+ EntityResolver resolver)
+ throws Exception {
+ // Get markup and programming languages
+ MarkupLanguage markupLanguage = (MarkupLanguage)this.markupSelector.select(markupLanguageName);
+ ProgrammingLanguage programmingLanguage =
+ (ProgrammingLanguage)this.languageSelector.select(programmingLanguageName);
+
+ programmingLanguage.setLanguageName(programmingLanguageName);
+ // Create filesystem store
+ // Set filenames
+ String filename = IOUtils.getFullFilename(file);
+ String normalizedName = IOUtils.normalizedFilename(filename);
+ String sourceExtension = programmingLanguage.getSourceExtension();
+ // Ensure no 2 requests for the same file overlap
+ Class program = null;
+ CompiledComponent programInstance = null;
+
+ // Attempt to load program object from cache
+ try {
+ programInstance = (CompiledComponent) this.cache.select(normalizedName);
+ } catch (Exception e) {
+ getLogger().debug("The instance was not accessible, creating it now.", e);
+ }
- // Attempt to load program object from cache
+ if (programInstance == null) {
try {
- programInstance = (CompiledComponent) this.cache.select(filename);
- if (this.autoReload == false) return programInstance;
- } catch (Exception e) {
- getLogger().debug("The instance was not accessible, creating it now.");
- try {
- if (programInstance == null) {
- /*
- FIXME: Passing null as encoding may result in invalid
- recompilation under certain circumstances!
- */
-
- program = programmingLanguage.load(normalizedName, this.workDir, null);
- // Store loaded program in cache
- this.cache.addGenerator(filename, program);
- }
-
- programInstance = (CompiledComponent) this.cache.select(filename);
-
- } catch (LanguageException le) {
- getLogger().debug("Language Exception", le);
- }
-
- /*
- FIXME: It's the program (not the instance) that must
- be queried for changes!!!
- */
-
- if (programInstance != null && programInstance.modifiedSince(file.lastModified())) {
- // Unload program
- programmingLanguage.unload(program, normalizedName, this.workDir);
- // Invalidate previous program/instance pair
- program = null;
- programInstance = null;
- }
-
- if (program == null) {
- // Generate code
- String code = markupLanguage.generateCode(
- new InputSource(
- new FileReader(file)), normalizedName, programmingLanguage, resolver);
- String encoding = markupLanguage.getEncoding();
- // Format source code if applicable
- CodeFormatter codeFormatter = programmingLanguage.getCodeFormatter();
- if (codeFormatter != null) {
- code = codeFormatter.format(code, encoding);
- }
- // Store generated code
- String sourceFilename = filename + "." + sourceExtension;
- repository.store(sourceFilename, code);
- // [Compile]/Load generated program
- program = programmingLanguage.load(normalizedName, this.workDir, encoding);
- // Store generated program in cache
- this.cache.addGenerator(filename, program);
- }
- // Instantiate
- programInstance = (CompiledComponent) this.cache.select(filename);
+ /*
+ * FIXME: Passing null as encoding may result in invalid
+ * recompilation under certain circumstances!
+ */
+
+ program = programmingLanguage.load(normalizedName, this.workDir, null);
+ // Store loaded program in cache
+ this.cache.addGenerator(normalizedName, program);
+ } catch (LanguageException le) {
+ getLogger().debug("Language Exception", le);
+ }
+
+ try {
+ programInstance = (CompiledComponent) this.cache.select(normalizedName);
+ } catch (Exception cme) {
+ getLogger().debug("Can't load ServerPage", cme);
+ }
+ }
+
+ if (this.autoReload == false) return programInstance;
+
+ /*
+ * FIXME: It's the program (not the instance) that must
+ * be queried for changes!!!
+ */
+
+ if (programInstance != null && programInstance.modifiedSince(file.lastModified())) {
+ // Unload program
+ programmingLanguage.unload(program, normalizedName, this.workDir);
+ // Invalidate previous program/instance pair
+ program = null;
+ programInstance = null;
+ }
+
+ if (program == null) {
+ // Generate code
+ String code = markupLanguage.generateCode(
+ new InputSource(
+ new FileReader(file)), normalizedName, programmingLanguage, resolver);
+ String encoding = markupLanguage.getEncoding();
+ // Format source code if applicable
+ CodeFormatter codeFormatter = programmingLanguage.getCodeFormatter();
+ if (codeFormatter != null) {
+ code = codeFormatter.format(code, encoding);
}
- return programInstance;
+ // Store generated code
+ String sourceFilename = filename + "." + sourceExtension;
+ repository.store(sourceFilename, code);
+ // [Compile]/Load generated program
+ program = programmingLanguage.load(normalizedName, this.workDir, encoding);
+ // Store generated program in cache
+ this.cache.addGenerator(normalizedName, program);
+ }
+ // Instantiate
+ return (CompiledComponent) this.cache.select(normalizedName);
}
}
No revision
No revision
1.1.2.10 +11 -17 xml-cocoon/src/org/apache/cocoon/components/store/Attic/FilesystemStore.java
Index: FilesystemStore.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/store/Attic/FilesystemStore.java,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -u -r1.1.2.9 -r1.1.2.10
--- FilesystemStore.java 2001/02/16 15:38:30 1.1.2.9
+++ FilesystemStore.java 2001/02/17 19:09:12 1.1.2.10
@@ -5,29 +5,29 @@
import org.apache.cocoon.util.IOUtils;
-import org.apache.log.Logger;
-import org.apache.avalon.Loggable;
+import org.apache.avalon.AbstractLoggable;
import org.apache.avalon.ThreadSafe;
import java.io.IOException;
-public class FilesystemStore implements Store, ThreadSafe, Loggable {
+public class FilesystemStore extends AbstractLoggable implements Store, ThreadSafe {
/** The directory repository */
protected File directoryFile;
protected volatile String directoryPath;
- private Logger log;
-
/**
- * Constructor
+ * Sets the repository's location
*/
- public FilesystemStore(String directoryName) throws IOException {
- this(new File(directoryName));
+ public void setDirectory(String directory) throws IOException {
+ this.setDirectory(new File(directory));
}
- public FilesystemStore(File directoryFile) throws IOException {
- this.directoryFile = directoryFile;
+ /**
+ * Sets the repository's location
+ */
+ public void setDirectory(File directory) throws IOException {
+ this.directoryFile = directory;
/* Save directory path prefix */
this.directoryPath = IOUtils.getFullFilename(this.directoryFile);
@@ -56,12 +56,6 @@
}
}
- public void setLogger(Logger logger) {
- if (this.log == null) {
- this.log = logger;
- }
- }
-
/**
* Returns the repository's full pathname
*/
@@ -101,7 +95,7 @@
if (value == null) { /* Directory */
if (file.exists()) {
if (!file.delete()) { /* FAILURE */
- log.error("File cannot be deleted: " + file.toString());
+ getLogger().error("File cannot be deleted: " + file.toString());
return;
}
}