Author: pete.muir(a)jboss.org
Date: 2008-10-22 09:32:24 -0400 (Wed, 22 Oct 2008)
New Revision: 9379
Added:
trunk/src/main/org/jboss/seam/deployment/AbstractClassDeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/ClassDeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/ClassDeploymentMetadata.java
trunk/src/main/org/jboss/seam/deployment/ClassDescriptor.java
trunk/src/main/org/jboss/seam/deployment/DeploymentMetadata.java
trunk/src/main/org/jboss/seam/deployment/DotComponentDotXmlDeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/FileDescriptor.java
Removed:
trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/PatternDeploymentHandler.java
Modified:
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/binding/lacewiki/PluginDeploymentHandler.java
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/binding/lacewiki/PluginI18NDeploymentHandler.java
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/upload/importers/metamodel/ImporterRegistry.java
trunk/examples/wiki/src/main/org/jboss/seam/wiki/preferences/metamodel/PreferenceRegistry.java
trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/AnnotationDeploymentHelper.java
trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/XmlDeploymentHandler.java
trunk/src/main/org/jboss/seam/bpm/Jbpm.java
trunk/src/main/org/jboss/seam/bpm/PageflowDeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/AbstractDeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/AbstractScanner.java
trunk/src/main/org/jboss/seam/deployment/AnnotationDeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/ComponentDeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/ComponentsXmlDeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/DeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java
trunk/src/main/org/jboss/seam/deployment/DotPageDotXmlDeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/GroovyDeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/GroovyHotDeploymentStrategy.java
trunk/src/main/org/jboss/seam/deployment/HotDeploymentStrategy.java
trunk/src/main/org/jboss/seam/deployment/NamespaceDeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/StandardDeploymentStrategy.java
trunk/src/main/org/jboss/seam/deployment/URLScanner.java
trunk/src/main/org/jboss/seam/deployment/WarRootDeploymentStrategy.java
trunk/src/main/org/jboss/seam/init/Initialization.java
trunk/src/main/org/jboss/seam/navigation/Pages.java
trunk/src/resteasy/org/jboss/seam/resteasy/ResteasyBootstrap.java
Log:
JBSEAM-3276
Modified:
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/binding/lacewiki/PluginDeploymentHandler.java
===================================================================
---
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/binding/lacewiki/PluginDeploymentHandler.java 2008-10-22
13:26:57 UTC (rev 9378)
+++
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/binding/lacewiki/PluginDeploymentHandler.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -7,8 +7,8 @@
package org.jboss.seam.wiki.core.plugin.binding.lacewiki;
import org.jboss.seam.Component;
+import org.jboss.seam.deployment.DeploymentStrategy;
import org.jboss.seam.wiki.util.XmlDeploymentHandler;
-import org.jboss.seam.deployment.DeploymentStrategy;
/**
* Detects all *.plugin.xml files and offers Dom4J elements.
Modified:
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/binding/lacewiki/PluginI18NDeploymentHandler.java
===================================================================
---
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/binding/lacewiki/PluginI18NDeploymentHandler.java 2008-10-22
13:26:57 UTC (rev 9378)
+++
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/binding/lacewiki/PluginI18NDeploymentHandler.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -6,15 +6,20 @@
*/
package org.jboss.seam.wiki.core.plugin.binding.lacewiki;
-import org.jboss.seam.wiki.util.PatternDeploymentHandler;
import org.jboss.seam.wiki.core.plugin.metamodel.Plugin;
import org.jboss.seam.wiki.core.exception.InvalidWikiConfigurationException;
-import org.jboss.seam.core.ResourceLoader;
+import org.jboss.seam.deployment.AbstractDeploymentHandler;
+import org.jboss.seam.deployment.DeploymentMetadata;
import org.jboss.seam.deployment.DeploymentStrategy;
+import org.jboss.seam.deployment.FileDescriptor;
import org.jboss.seam.Component;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* Finds (during startup scanning) all plugin messages files, using the pattern
@@ -27,29 +32,52 @@
*
* @author Christian Bauer
*/
-public class PluginI18NDeploymentHandler extends PatternDeploymentHandler {
+public class PluginI18NDeploymentHandler extends AbstractDeploymentHandler {
public static final String NAME = "pluginI18NDeploymentHandler";
public static final String MESSAGES_PATTERN =
"^([a-zA-Z0-9/]+)"+Plugin.PACKAGE_I18N_MESSAGES+"_("+Plugin.KEY_PATTERN+")_([a-zA-Z_]+)\\.properties$";
- public String getPattern() {
- return MESSAGES_PATTERN;
+ private static DeploymentMetadata deploymentMetadata = new DeploymentMetadata()
+ {
+
+ public String getFileNameSuffix()
+ {
+ return ".properties";
+ }
+
+ };
+
+ private Pattern compiledPattern;
+
+ public PluginI18NDeploymentHandler()
+ {
+ compiledPattern = Pattern.compile(MESSAGES_PATTERN);
}
+
+ @Override
+ public void postProcess(ClassLoader classLoader) {
+ for (FileDescriptor fileDescriptor : getResources())
+ {
+ Matcher matcher = compiledPattern.matcher(fileDescriptor.getName());
+ if (matcher.matches()) {
+ String[] groups = new String[matcher.groupCount()];
+ for (int i = 0; i < groups.length; i++) {
+ groups[i] = matcher.group(i+1);
+ }
+ if (groups == null || groups.length != 3) {
+ throw new InvalidWikiConfigurationException("Deployment of i18n
properties failed");
+ }
+ String packageName = groups[0];
+ String pluginKey = groups[1];
+ String locale = groups[2]; // Don't really need it here
- public void handleMatch(String s, ClassLoader classLoader, String... matchedGroups)
{
- if (matchedGroups == null || matchedGroups.length != 3) {
- throw new InvalidWikiConfigurationException("Deployment of i18n
properties failed");
+ if (packageName.endsWith(Plugin.PACKAGE_I18N+"/")) {
+ String bundleName = packageName.replaceAll("/",
".") + "messages_" + pluginKey;
+ getMessageBundleNames().add(bundleName);
+ }
+ }
}
-
- String packageName = matchedGroups[0];
- String pluginKey = matchedGroups[1];
- String locale = matchedGroups[2]; // Don't really need it here
-
- if (packageName.endsWith(Plugin.PACKAGE_I18N+"/")) {
- String bundleName = packageName.replaceAll("/", ".") +
"messages_" + pluginKey;
- getMessageBundleNames().add(bundleName);
- }
}
public String getName() {
@@ -66,5 +94,10 @@
DeploymentStrategy deployment = (DeploymentStrategy)
Component.getInstance("deploymentStrategy");
return (PluginI18NDeploymentHandler)
deployment.getDeploymentHandlers().get(NAME);
}
+
+ public DeploymentMetadata getMetadata()
+ {
+ return deploymentMetadata;
+ }
}
Modified:
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/upload/importers/metamodel/ImporterRegistry.java
===================================================================
---
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/upload/importers/metamodel/ImporterRegistry.java 2008-10-22
13:26:57 UTC (rev 9378)
+++
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/upload/importers/metamodel/ImporterRegistry.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -29,7 +29,7 @@
log.debug("initializing upload importer registry");
- Set<Class<Object>> importerClasses =
AnnotationDeploymentHelper.getAnnotatedClasses(UploadImporter.class);
+ Set<Class<?>> importerClasses =
AnnotationDeploymentHelper.getAnnotatedClasses(UploadImporter.class);
if (importerClasses == null) return;
for (Class<?> importerClass : importerClasses) {
Modified:
trunk/examples/wiki/src/main/org/jboss/seam/wiki/preferences/metamodel/PreferenceRegistry.java
===================================================================
---
trunk/examples/wiki/src/main/org/jboss/seam/wiki/preferences/metamodel/PreferenceRegistry.java 2008-10-22
13:26:57 UTC (rev 9378)
+++
trunk/examples/wiki/src/main/org/jboss/seam/wiki/preferences/metamodel/PreferenceRegistry.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -34,7 +34,7 @@
public void startup() {
log.debug("initializing preferences registry");
- Set<Class<Object>> preferencesClasses =
AnnotationDeploymentHelper.getAnnotatedClasses(Preferences.class);
+ Set<Class<?>> preferencesClasses =
AnnotationDeploymentHelper.getAnnotatedClasses(Preferences.class);
if (preferencesClasses == null)
throw new RuntimeException("No preference entities found, add
@Preferences annotation to META-INF/seam-deployment.properties");
Modified:
trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/AnnotationDeploymentHelper.java
===================================================================
---
trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/AnnotationDeploymentHelper.java 2008-10-22
13:26:57 UTC (rev 9378)
+++
trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/AnnotationDeploymentHelper.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -22,14 +22,14 @@
*/
public class AnnotationDeploymentHelper {
- public static Set<Class<Object>> getAnnotatedClasses(String
annotationFQN) {
+ public static Set<Class<?>> getAnnotatedClasses(String annotationFQN) {
DeploymentStrategy deployment = (DeploymentStrategy)
Component.getInstance("deploymentStrategy");
AnnotationDeploymentHandler handler =
(AnnotationDeploymentHandler)deployment.getDeploymentHandlers().get(AnnotationDeploymentHandler.NAME);
- return handler.getClasses().get(annotationFQN);
+ return handler.getClassMap().get(annotationFQN);
}
- public static Set<Class<Object>> getAnnotatedClasses(Class
annotationType) {
+ public static Set<Class<?>> getAnnotatedClasses(Class annotationType) {
return getAnnotatedClasses(annotationType.getName());
}
Deleted:
trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/PatternDeploymentHandler.java
===================================================================
---
trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/PatternDeploymentHandler.java 2008-10-22
13:26:57 UTC (rev 9378)
+++
trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/PatternDeploymentHandler.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -1,40 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-package org.jboss.seam.wiki.util;
-
-import org.jboss.seam.deployment.DeploymentHandler;
-
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-
-/**
- * @author Christian Bauer
- */
-public abstract class PatternDeploymentHandler implements DeploymentHandler {
-
- protected Pattern compiledPattern;
-
- protected PatternDeploymentHandler() {
- compiledPattern = Pattern.compile(getPattern());
- }
-
- public void handle(String s, ClassLoader classLoader) {
- Matcher matcher = compiledPattern.matcher(s);
- if (matcher.matches()) {
- String[] groups = new String[matcher.groupCount()];
- for (int i = 0; i < groups.length; i++) {
- groups[i] = matcher.group(i+1);
- }
- handleMatch(s, classLoader, groups);
- }
- }
-
- public abstract String getPattern();
-
- public abstract void handleMatch(String s, ClassLoader classLoader, String...
matchedGroups);
-
-}
Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/XmlDeploymentHandler.java
===================================================================
---
trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/XmlDeploymentHandler.java 2008-10-22
13:26:57 UTC (rev 9378)
+++
trunk/examples/wiki/src/main/org/jboss/seam/wiki/util/XmlDeploymentHandler.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -9,10 +9,11 @@
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
-import org.jboss.seam.deployment.DeploymentHandler;
+import org.jboss.seam.deployment.AbstractDeploymentHandler;
+import org.jboss.seam.deployment.DeploymentMetadata;
+import org.jboss.seam.deployment.FileDescriptor;
import org.jboss.seam.util.DTDEntityResolver;
-import java.io.InputStream;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
@@ -28,16 +29,26 @@
*
* @author Christian Bauer
*/
-public abstract class XmlDeploymentHandler implements DeploymentHandler {
+public abstract class XmlDeploymentHandler extends AbstractDeploymentHandler {
- Map<String, InputStream> files = new HashMap<String, InputStream>();
Map<String, Element> elements;
-
- public void handle(String s, ClassLoader classLoader) {
- if (s.endsWith(getExtension())) {
- files.put(s, classLoader.getResourceAsStream(s));
- }
+
+ private DeploymentMetadata deploymentMetadata;
+
+ public XmlDeploymentHandler()
+ {
+ deploymentMetadata = new DeploymentMetadata() {
+
+ public String getFileNameSuffix() {
+ return ".plugin.xml";
+ }
+
+ };
}
+
+ public DeploymentMetadata getMetadata() {
+ return deploymentMetadata;
+ }
public abstract String getExtension();
@@ -49,7 +60,7 @@
// Lazy access to streams
if (elements == null) {
elements = new HashMap<String, Element>();
- for (Map.Entry<String, InputStream> fileInputStream : files.entrySet())
{
+ for (FileDescriptor fileDescriptor : getResources()) {
try {
SAXReader saxReader = new SAXReader();
saxReader.setMergeAdjacentText(true);
@@ -60,7 +71,7 @@
saxReader.setFeature("http://apache.org/xml/features/validation/sche...;
}
- elements.put(fileInputStream.getKey(),
saxReader.read(fileInputStream.getValue()).getRootElement());
+ elements.put(fileDescriptor.getName(),
saxReader.read(fileDescriptor.getUrl().openStream()).getRootElement());
} catch (DocumentException dex) {
Throwable nested = dex.getNestedException();
@@ -68,7 +79,7 @@
if (nested instanceof FileNotFoundException) {
throw new RuntimeException(
"Can't find schema/DTD reference for file:
"
- + fileInputStream.getKey() + "': "
+ + fileDescriptor.getName() + "': "
+ nested.getMessage(), dex
);
} else if (nested instanceof UnknownHostException) {
@@ -79,9 +90,9 @@
);
}
}
- throw new RuntimeException("Could not parse XML file: " +
fileInputStream.getKey() ,dex);
+ throw new RuntimeException("Could not parse XML file: " +
fileDescriptor.getName() ,dex);
} catch (Exception ex) {
- throw new RuntimeException("Could not parse XML file: " +
fileInputStream.getKey() ,ex);
+ throw new RuntimeException("Could not parse XML file: " +
fileDescriptor.getName() ,ex);
}
}
}
Modified: trunk/src/main/org/jboss/seam/bpm/Jbpm.java
===================================================================
--- trunk/src/main/org/jboss/seam/bpm/Jbpm.java 2008-10-22 13:26:57 UTC (rev 9378)
+++ trunk/src/main/org/jboss/seam/bpm/Jbpm.java 2008-10-22 13:32:24 UTC (rev 9379)
@@ -31,6 +31,7 @@
import org.jboss.seam.core.Init;
import org.jboss.seam.core.ResourceLoader;
import org.jboss.seam.deployment.DeploymentStrategy;
+import org.jboss.seam.deployment.FileDescriptor;
import org.jboss.seam.deployment.StandardDeploymentStrategy;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
@@ -267,7 +268,10 @@
mergedPageflowDefinitions.addAll(Arrays.asList(pageflowDefinitions));
}
- mergedPageflowDefinitions.addAll(((PageflowDeploymentHandler) ((DeploymentStrategy)
Contexts.getEventContext().get(StandardDeploymentStrategy.NAME)).getDeploymentHandlers().get(PageflowDeploymentHandler.NAME)).getPageflowDefinitions());
+ for (FileDescriptor fileDescriptor : ((PageflowDeploymentHandler)
((DeploymentStrategy)
Contexts.getEventContext().get(StandardDeploymentStrategy.NAME)).getDeploymentHandlers().get(PageflowDeploymentHandler.NAME)).getResources())
+ {
+ mergedPageflowDefinitions.add(fileDescriptor.getName());
+ }
for (String pageflow: mergedPageflowDefinitions)
{
Modified: trunk/src/main/org/jboss/seam/bpm/PageflowDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/bpm/PageflowDeploymentHandler.java 2008-10-22 13:26:57
UTC (rev 9378)
+++ trunk/src/main/org/jboss/seam/bpm/PageflowDeploymentHandler.java 2008-10-22 13:32:24
UTC (rev 9379)
@@ -1,13 +1,15 @@
package org.jboss.seam.bpm;
+import java.io.IOException;
import java.io.InputStream;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.jboss.seam.deployment.AbstractDeploymentHandler;
+import org.jboss.seam.deployment.DeploymentMetadata;
+import org.jboss.seam.deployment.FileDescriptor;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
import org.jboss.seam.util.Resources;
@@ -16,45 +18,64 @@
public class PageflowDeploymentHandler extends AbstractDeploymentHandler
{
+
+ private static DeploymentMetadata NAMESPACE_METADATA = new DeploymentMetadata()
+ {
+ public String getFileNameSuffix()
+ {
+ return ".jpdl.xml";
+ }
+
+ };
+
private static LogProvider log =
Logging.getLogProvider(PageflowDeploymentHandler.class);
public static final String NAME =
"org.jboss.seam.bpm.PageflowDeploymentHandler";
-
- private Set<String> pageflowDefinitions;
- public PageflowDeploymentHandler()
- {
- pageflowDefinitions = new HashSet<String>();
- }
-
public String getName()
{
return NAME;
}
- public void handle(String name, ClassLoader classLoader)
+ @Override
+ public void postProcess(ClassLoader classLoader)
{
- if (name.endsWith(".jpdl.xml")) {
- InputStream inputStream = Resources.getResourceAsStream(name, null);
- try {
- Element root = XML.getRootElementSafely(inputStream);
- if ("pageflow-definition".equals(root.getName()))
+ Set<FileDescriptor> files = new HashSet<FileDescriptor>();
+ for (FileDescriptor fileDescriptor : getResources())
+ {
+ try
+ {
+ InputStream inputStream = fileDescriptor.getUrl().openStream();
+ try
{
- pageflowDefinitions.add(name);
+
+ Element root = XML.getRootElementSafely(inputStream);
+ if ("pageflow-definition".equals(root.getName()))
+ {
+ files.add(fileDescriptor);
+ }
}
- } catch (DocumentException e) {
- log.debug("Unable to parse " + name, e);
- } finally {
- Resources.closeStream(inputStream);
+ catch (DocumentException e)
+ {
+ log.debug("Unable to parse " + fileDescriptor.getName(), e);
+ }
+ finally
+ {
+ Resources.closeStream(inputStream);
+ }
+ } catch (IOException e)
+ {
+ log.trace("Error loading " + fileDescriptor.getName());
}
}
+ setResources(files);
}
- public Set<String> getPageflowDefinitions()
+ public DeploymentMetadata getMetadata()
{
- return Collections.unmodifiableSet(pageflowDefinitions);
+ return NAMESPACE_METADATA;
}
}
Added: trunk/src/main/org/jboss/seam/deployment/AbstractClassDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/AbstractClassDeploymentHandler.java
(rev 0)
+++
trunk/src/main/org/jboss/seam/deployment/AbstractClassDeploymentHandler.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -0,0 +1,27 @@
+package org.jboss.seam.deployment;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public abstract class AbstractClassDeploymentHandler extends AbstractDeploymentHandler
+ implements ClassDeploymentHandler
+{
+
+ private Set<ClassDescriptor> classes;
+
+ public AbstractClassDeploymentHandler()
+ {
+ classes = new HashSet<ClassDescriptor>();
+ }
+
+ public Set<ClassDescriptor> getClasses()
+ {
+ return classes;
+ }
+
+ public void setClasses(Set<ClassDescriptor> classes)
+ {
+ this.classes = classes;
+ }
+
+}
Property changes on:
trunk/src/main/org/jboss/seam/deployment/AbstractClassDeploymentHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/main/org/jboss/seam/deployment/AbstractDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/AbstractDeploymentHandler.java 2008-10-22
13:26:57 UTC (rev 9378)
+++ trunk/src/main/org/jboss/seam/deployment/AbstractDeploymentHandler.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -1,14 +1,8 @@
package org.jboss.seam.deployment;
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
-import javassist.bytecode.AnnotationsAttribute;
-import javassist.bytecode.ClassFile;
-import javassist.bytecode.annotation.MemberValue;
-
/**
* Abstract base class for {@link DeploymentHandler} providing common functionality
*
@@ -17,86 +11,30 @@
*/
public abstract class AbstractDeploymentHandler implements DeploymentHandler
{
- /**
- * Convert a path to a class file to a class name
- */
- protected static String filenameToClassname(String filename)
- {
- return filename.substring( 0, filename.lastIndexOf(".class") )
- .replace('/', '.').replace('\\', '.');
- }
- /**
- * Get a Javassist {@link ClassFile} for a given class name from the classLoader
- */
- protected ClassFile getClassFile(String name, ClassLoader classLoader) throws
IOException
+ private Set<FileDescriptor> resources;
+
+ public AbstractDeploymentHandler()
{
- if (name == null)
- {
- throw new NullPointerException("name cannot be null");
- }
- InputStream stream = classLoader.getResourceAsStream(name);
- if (stream == null)
- {
- throw new IllegalStateException("Cannot load " + name + " from
" + classLoader + " (using getResourceAsStream() returned null)");
- }
- DataInputStream dstream = new DataInputStream(stream);
+ resources = new HashSet<FileDescriptor>();
+ }
- try
- {
- return new ClassFile(dstream);
- }
- finally
- {
- dstream.close();
- stream.close();
- }
+ @Override
+ public String toString()
+ {
+ return getName();
}
- /**
- * Check if the Javassist {@link ClassFile} has the specfied annotation
- */
- protected boolean hasAnnotation(ClassFile classFile, Class<? extends Annotation>
annotationType)
- {
- AnnotationsAttribute visible = (AnnotationsAttribute) classFile.getAttribute(
AnnotationsAttribute.visibleTag );
- if ( visible != null )
- {
- return visible.getAnnotation( annotationType.getName() ) != null;
- }
- return false;
+ public void setResources(Set<FileDescriptor> resources)
+ {
+ this.resources = resources;
}
- /**
- * Get the value of the annotation on the Javassist {@link ClassFile}, or null
- * if the class doesn't have that annotation
- */
- protected String getAnnotationValue(ClassFile classFile, Class<? extends
Annotation> annotationType, String memberName)
- {
- AnnotationsAttribute visible = (AnnotationsAttribute) classFile.getAttribute(
AnnotationsAttribute.visibleTag );
- if ( visible != null )
- {
- javassist.bytecode.annotation.Annotation annotation = visible.getAnnotation(
annotationType.getName() );
- if (annotation==null)
- {
- return null;
- }
- else
- {
- MemberValue memberValue = annotation.getMemberValue(memberName);
- return memberValue==null ? null : memberValue.toString(); //TODO: toString()
here is probably Bad ;-)
- }
- }
- else
- {
- return null;
- }
+ public Set<FileDescriptor> getResources()
+ {
+ return resources;
}
-
- @Override
- public String toString()
- {
- return getName();
- }
-
+ public void postProcess(ClassLoader classLoader) {}
+
}
Modified: trunk/src/main/org/jboss/seam/deployment/AbstractScanner.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/AbstractScanner.java 2008-10-22 13:26:57 UTC
(rev 9378)
+++ trunk/src/main/org/jboss/seam/deployment/AbstractScanner.java 2008-10-22 13:32:24 UTC
(rev 9379)
@@ -1,5 +1,13 @@
package org.jboss.seam.deployment;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javassist.bytecode.AnnotationsAttribute;
import javassist.bytecode.ClassFile;
import org.jboss.seam.log.LogProvider;
@@ -14,6 +22,95 @@
public abstract class AbstractScanner implements Scanner
{
+ private static class Handler
+ {
+
+ // Cache descriptors for performance
+ private ClassFile classFile;
+ private ClassDescriptor classDescriptor;
+ private FileDescriptor fileDescriptor;
+
+ private Set<Entry<String, DeploymentHandler>> deploymentHandlers;
+ private ClassLoader classLoader;
+ private String name;
+
+ public Handler(String name, Set<Entry<String, DeploymentHandler>>
deploymentHandlers, ClassLoader classLoader)
+ {
+ this.deploymentHandlers = deploymentHandlers;
+ this.name = name;
+ this.classLoader = classLoader;
+ }
+
+ protected void handle(DeploymentHandler deploymentHandler)
+ {
+ if (deploymentHandler instanceof ClassDeploymentHandler)
+ {
+ if (name.endsWith(".class"))
+ {
+ ClassDeploymentHandler classDeploymentHandler = (ClassDeploymentHandler)
deploymentHandler;
+ if (hasAnnotations(getClassFile(),
classDeploymentHandler.getMetadata().getClassAnnotatedWith()))
+ {
+ log.trace("adding class to deployable list " + name + "
for deployment handler " + deploymentHandler.getName());
+ if (getClassDescriptor().getClazz() != null)
+ {
+ classDeploymentHandler.getClasses().add(getClassDescriptor());
+ }
+ }
+ }
+ }
+ else
+ {
+ if (name.endsWith(deploymentHandler.getMetadata().getFileNameSuffix()))
+ {
+ deploymentHandler.getResources().add(getFileDescriptor());
+ }
+ }
+ }
+
+ protected void handle()
+ {
+ log.trace("found " + name);
+ for (Entry<String, DeploymentHandler> entry: deploymentHandlers)
+ {
+ handle(entry.getValue());
+ }
+ }
+
+ private ClassFile getClassFile()
+ {
+ if (classFile == null)
+ {
+ try
+ {
+ classFile = loadClassFile(name, classLoader);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Error loading class file " + name,
e);
+ }
+ }
+ return classFile;
+ }
+
+ private ClassDescriptor getClassDescriptor()
+ {
+ if (classDescriptor == null)
+ {
+ classDescriptor = new ClassDescriptor(name, classLoader);
+ }
+ return classDescriptor;
+ }
+
+ private FileDescriptor getFileDescriptor()
+ {
+ if (fileDescriptor == null)
+ {
+ fileDescriptor = new FileDescriptor(name, classLoader);
+ }
+ return fileDescriptor;
+ }
+ }
+
private static final LogProvider log = Logging.getLogProvider(Scanner.class);
private DeploymentStrategy deploymentStrategy;
@@ -24,12 +121,52 @@
ClassFile.class.getPackage(); //to force loading of javassist, throwing an
exception if it is missing
}
- protected final void handleItem(String name)
+ protected static boolean hasAnnotations(ClassFile classFile, Set<Class<? extends
Annotation>> annotationTypes)
{
- log.trace("found " + name);
- getDeploymentStrategy().handle(name);
+ if (annotationTypes.size() > 0)
+ {
+ AnnotationsAttribute visible = (AnnotationsAttribute) classFile.getAttribute(
AnnotationsAttribute.visibleTag );
+ if ( visible != null )
+ {
+ for (Class<? extends Annotation> annotationType : annotationTypes)
+ {
+ if (visible.getAnnotation(annotationType.getName()) != null)
+ {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
}
+ /**
+ * Get a Javassist {@link ClassFile} for a given class name from the classLoader
+ */
+ protected static ClassFile loadClassFile(String name, ClassLoader classLoader) throws
IOException
+ {
+ if (name == null)
+ {
+ throw new NullPointerException("name cannot be null");
+ }
+ InputStream stream = classLoader.getResourceAsStream(name);
+ if (stream == null)
+ {
+ throw new IllegalStateException("Cannot load " + name + " from
" + classLoader + " (using getResourceAsStream() returned null)");
+ }
+ DataInputStream dstream = new DataInputStream(stream);
+
+ try
+ {
+ return new ClassFile(dstream);
+ }
+ finally
+ {
+ dstream.close();
+ stream.close();
+ }
+ }
+
public DeploymentStrategy getDeploymentStrategy()
{
return deploymentStrategy;
@@ -39,5 +176,10 @@
{
return Long.MAX_VALUE;
}
+
+ protected void handleItem(String name)
+ {
+ new Handler(name, deploymentStrategy.getDeploymentHandlers().entrySet(),
deploymentStrategy.getClassLoader()).handle();
+ }
}
Modified: trunk/src/main/org/jboss/seam/deployment/AnnotationDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/AnnotationDeploymentHandler.java 2008-10-22
13:26:57 UTC (rev 9378)
+++ trunk/src/main/org/jboss/seam/deployment/AnnotationDeploymentHandler.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -1,6 +1,5 @@
package org.jboss.seam.deployment;
-import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.HashMap;
@@ -9,13 +8,34 @@
import java.util.Map;
import java.util.Set;
-import javassist.bytecode.ClassFile;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
-public class AnnotationDeploymentHandler extends AbstractDeploymentHandler
+public class AnnotationDeploymentHandler extends AbstractClassDeploymentHandler
{
+ private class AnnotationDeploymentHandlerMetadata implements ClassDeploymentMetadata
+ {
+
+ private Set<Class<? extends Annotation>> annotations;
+
+ public AnnotationDeploymentHandlerMetadata(Set<Class<? extends
Annotation>> annotations)
+ {
+ this.annotations = annotations;
+ }
+
+ public Set<Class<? extends Annotation>> getClassAnnotatedWith()
+ {
+ return annotations;
+ }
+
+ public String getFileNameSuffix()
+ {
+ return null;
+ }
+
+ }
+
/**
* Name under which this {@link DeploymentHandler} is registered
*/
@@ -23,14 +43,16 @@
public static final String ANNOTATIONS_KEY =
"org.jboss.seam.deployment.annotationTypes";
- private Map<String, Set<Class<Object>>> classes;
+ private static final LogProvider log =
Logging.getLogProvider(AnnotationDeploymentHandler.class);
+
+ private ClassDeploymentMetadata metadata;
+
+ private Map<String, Set<Class<?>>> classes;
private Set<Class<? extends Annotation>> annotations;
- private static final LogProvider log =
Logging.getLogProvider(AnnotationDeploymentHandler.class);
-
public AnnotationDeploymentHandler(List<String> annotationTypes, ClassLoader
classLoader)
{
- annotations = new HashSet<Class<? extends Annotation>>();
+ this.annotations = new HashSet<Class<? extends Annotation>>();
for (String classname: annotationTypes)
{
try
@@ -50,18 +72,13 @@
log.warn("could not load annotation class (not an annotation): " +
classname, cce);
}
}
-
- classes = new HashMap<String, Set<Class<Object>>>();
- for (Class annotation: annotations)
- {
- classes.put(annotation.getName(), new HashSet<Class<Object>>());
- }
+ metadata = new AnnotationDeploymentHandlerMetadata(annotations);
}
/**
* Get annotated classes
*/
- public Map<String, Set<Class<Object>>> getClasses()
+ public Map<String, Set<Class<?>>> getClassMap()
{
return Collections.unmodifiableMap(classes);
}
@@ -72,45 +89,29 @@
return NAME;
}
- public void handle(String name, ClassLoader classLoader)
+ public ClassDeploymentMetadata getMetadata()
{
- if (name.endsWith(".class"))
+ return metadata;
+ }
+
+ @Override
+ public void postProcess(ClassLoader classLoader)
+ {
+ classes = new HashMap<String, Set<Class<?>>>();
+ for (Class<? extends Annotation> annotationType: annotations)
{
- String classname = filenameToClassname(name);
- try
+ classes.put(annotationType.getName(), new HashSet<Class<?>>());
+ }
+ for (ClassDescriptor classDescriptor : getClasses())
+ {
+ for (Annotation annotation: classDescriptor.getClazz().getAnnotations())
{
- ClassFile classFile = getClassFile(name, classLoader);
- Class clazz = null;
- for (Class<? extends Annotation> annotationType: annotations)
+ if (classes.containsKey(annotation.annotationType().getName()))
{
- if (hasAnnotation(classFile, annotationType))
- {
- log.trace("found class annotated with " + annotationType +
": " + name);
- if (clazz == null)
- {
- try
- {
- clazz = classLoader.loadClass(classname);
- }
- catch (ClassNotFoundException cnfe)
- {
- log.debug("could not load class: " + classname, cnfe);
- }
- catch (NoClassDefFoundError ncdfe)
- {
- log.debug("could not load class (missing dependency): "
+ classname, ncdfe);
- }
- }
- classes.get(annotationType.getName()).add( clazz );
- }
+
classes.get(annotation.annotationType().getName()).add(classDescriptor.getClazz());
}
}
- catch (IOException ioe)
- {
- log.debug("could not load classfile: " + classname, ioe);
- }
}
-
}
}
Added: trunk/src/main/org/jboss/seam/deployment/ClassDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/ClassDeploymentHandler.java
(rev 0)
+++ trunk/src/main/org/jboss/seam/deployment/ClassDeploymentHandler.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -0,0 +1,13 @@
+package org.jboss.seam.deployment;
+
+import java.util.Set;
+
+public interface ClassDeploymentHandler extends DeploymentHandler {
+
+ public ClassDeploymentMetadata getMetadata();
+
+ public Set<ClassDescriptor> getClasses();
+
+ public void setClasses(Set<ClassDescriptor> classes);
+
+}
Property changes on: trunk/src/main/org/jboss/seam/deployment/ClassDeploymentHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/src/main/org/jboss/seam/deployment/ClassDeploymentMetadata.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/ClassDeploymentMetadata.java
(rev 0)
+++ trunk/src/main/org/jboss/seam/deployment/ClassDeploymentMetadata.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -0,0 +1,17 @@
+package org.jboss.seam.deployment;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+public interface ClassDeploymentMetadata extends DeploymentMetadata
+{
+
+ /**
+ * An array of class annotations this deployment handler is interested in
+ *
+ * All classes with any of these annotations should be considered part of the
+ * match
+ */
+ public Set<Class<? extends Annotation>> getClassAnnotatedWith();
+
+}
Property changes on:
trunk/src/main/org/jboss/seam/deployment/ClassDeploymentMetadata.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/src/main/org/jboss/seam/deployment/ClassDescriptor.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/ClassDescriptor.java
(rev 0)
+++ trunk/src/main/org/jboss/seam/deployment/ClassDescriptor.java 2008-10-22 13:32:24 UTC
(rev 9379)
@@ -0,0 +1,80 @@
+package org.jboss.seam.deployment;
+
+import java.net.URL;
+
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+
+public class ClassDescriptor extends FileDescriptor
+{
+
+ private static LogProvider log = Logging.getLogProvider(ClassDescriptor.class);
+
+ private Class<?> clazz;
+
+ public ClassDescriptor(String name, URL url, Class<?> clazz)
+ {
+ super(name, url);
+ this.clazz = clazz;
+ }
+
+ public ClassDescriptor(String name, ClassLoader classLoader)
+ {
+ super(name, classLoader);
+ String classname = filenameToClassname(name);
+ log.trace("Trying to load class " + classname);
+ try
+ {
+ clazz = classLoader.loadClass(classname);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ log.info("could not load class: " + classname, cnfe);
+ }
+ catch (NoClassDefFoundError ncdfe)
+ {
+ log.debug("could not load class (missing dependency): " + classname,
ncdfe);
+ }
+ }
+
+ public Class<?> getClazz()
+ {
+ return clazz;
+ }
+
+ @Override
+ public String toString()
+ {
+ return clazz.getName();
+ }
+
+ /**
+ * Convert a path to a class file to a class name
+ */
+ protected static String filenameToClassname(String filename)
+ {
+ return filename.substring( 0, filename.lastIndexOf(".class") )
+ .replace('/', '.').replace('\\', '.');
+ }
+
+ @Override
+ public boolean equals(Object other)
+ {
+ if (other instanceof ClassDescriptor)
+ {
+ ClassDescriptor that = (ClassDescriptor) other;
+ return this.getClazz().equals(that.getClazz());
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return getClazz().hashCode();
+ }
+
+}
Property changes on: trunk/src/main/org/jboss/seam/deployment/ClassDescriptor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/main/org/jboss/seam/deployment/ComponentDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/ComponentDeploymentHandler.java 2008-10-22
13:26:57 UTC (rev 9378)
+++ trunk/src/main/org/jboss/seam/deployment/ComponentDeploymentHandler.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -1,16 +1,12 @@
package org.jboss.seam.deployment;
-import java.io.IOException;
-import java.util.Collections;
+import java.lang.annotation.Annotation;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
-import javassist.bytecode.ClassFile;
-
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
/**
* The {@link ComponentDeploymentHandler} process Seam's component annotated
@@ -19,73 +15,60 @@
* @author Pete Muir
*
*/
-public class ComponentDeploymentHandler extends AbstractDeploymentHandler
+public class ComponentDeploymentHandler extends AbstractClassDeploymentHandler
{
+
+ private static Set<Class<? extends Annotation>> ANNOTATION_TYPES = new
HashSet<Class<? extends Annotation>>(Arrays.asList(Name.class));
+
+ public static ClassDeploymentMetadata NAME_ANNOTATED_CLASS_METADATA = new
ClassDeploymentMetadata()
+ {
+
+ public Set<Class<? extends Annotation>> getClassAnnotatedWith()
+ {
+ return ANNOTATION_TYPES;
+ }
+
+ public String getFileNameSuffix()
+ {
+ return null;
+ }
+
+ };
+
/**
* Name under which this {@link DeploymentHandler} is registered
*/
public static final String NAME =
"org.jboss.seam.deployment.ComponentDeploymentHandler";
- private static final LogProvider log =
Logging.getLogProvider(ComponentDeploymentHandler.class);
-
- protected Set<Class<Object>> classes;
-
- public ComponentDeploymentHandler()
+ public String getName()
{
- classes = new HashSet<Class<Object>>();
+ return NAME;
}
- /**
- * Get annotated Seam components
- */
- public Set<Class<Object>> getClasses()
+ public ClassDeploymentMetadata getMetadata()
{
- return Collections.unmodifiableSet(classes);
+ return NAME_ANNOTATED_CLASS_METADATA;
}
-
- /**
- * @see DeploymentHandler#handle(String, ClassLoader)
- */
- public void handle(String name, ClassLoader classLoader)
+
+ @Override
+ public void postProcess(ClassLoader classLoader)
{
- if (name.endsWith(".class"))
+ Set<ClassDescriptor> classes = new HashSet<ClassDescriptor>();
+ for (ClassDescriptor classDescriptor : getClasses())
{
- String classname = filenameToClassname(name);
- String filename = componentFilename(name);
- try
+ if (classDescriptor.getClazz().isAnnotationPresent(Install.class))
{
- ClassFile classFile = getClassFile(name, classLoader);
- boolean installable = ( hasAnnotation(classFile, Name.class) ||
classLoader.getResources(filename).hasMoreElements() )
- && !"false".equals( getAnnotationValue(classFile,
Install.class, "value") );
- if (installable)
+ if (classDescriptor.getClazz().getAnnotation(Install.class).value())
{
- log.trace("found component class: " + name);
- classes.add( (Class<Object>) classLoader.loadClass(classname) );
+ classes.add(classDescriptor);
}
}
- catch (ClassNotFoundException cnfe)
+ else
{
- log.debug("could not load class: " + classname, cnfe);
+ classes.add(classDescriptor);
}
- catch (NoClassDefFoundError ncdfe)
- {
- log.debug("could not load class (missing dependency): " +
classname, ncdfe);
- }
- catch (IOException ioe)
- {
- log.debug("could not load classfile: " + classname, ioe);
- }
- }
+ }
+ setClasses(classes);
}
-
- private static String componentFilename(String name)
- {
- return name.substring( 0, name.lastIndexOf(".class") ) +
".component.xml";
- }
- public String getName()
- {
- return NAME;
- }
-
}
Modified: trunk/src/main/org/jboss/seam/deployment/ComponentsXmlDeploymentHandler.java
===================================================================
---
trunk/src/main/org/jboss/seam/deployment/ComponentsXmlDeploymentHandler.java 2008-10-22
13:26:57 UTC (rev 9378)
+++
trunk/src/main/org/jboss/seam/deployment/ComponentsXmlDeploymentHandler.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -1,8 +1,8 @@
package org.jboss.seam.deployment;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import java.util.regex.Pattern;
/**
* The {@link ComponentsXmlDeploymentHandler} components.xml and .component.xml files
@@ -12,45 +12,48 @@
*/
public class ComponentsXmlDeploymentHandler extends AbstractDeploymentHandler
{
+
+ private Pattern INF_PATTERN =
Pattern.compile("(WEB-INF/components.xml$)|(META-INF/components.xml$)");
+
+ private static DeploymentMetadata COMPONENTSXML_SUFFIX_FILE_METADATA = new
DeploymentMetadata()
+ {
+
+ public String getFileNameSuffix()
+ {
+ return "components.xml";
+ }
+
+ };
+
/**
* Name under which this {@link DeploymentHandler} is registered
*/
public static final String NAME =
"org.jboss.seam.deployment.ComponentsXmlDeploymentHandler";
-
- private Set<String> resources;
- public ComponentsXmlDeploymentHandler()
+ public String getName()
{
- resources = new HashSet<String>();
+ return NAME;
}
- /**
- * Get paths to components.xml files
- */
- public Set<String> getResources()
+ public DeploymentMetadata getMetadata()
{
- return Collections.unmodifiableSet(resources);
+ return COMPONENTSXML_SUFFIX_FILE_METADATA;
}
-
- /**
- * @see DeploymentHandler#handle(String, ClassLoader)
- */
- public void handle(String name, ClassLoader classLoader)
+
+ @Override
+ public void postProcess(ClassLoader classLoader)
{
- if (name.endsWith(".component.xml") ||
name.endsWith("/components.xml"))
+ Set<FileDescriptor> resources = new HashSet<FileDescriptor>();
+ for (FileDescriptor fileDescriptor : getResources())
{
- // we want to skip over known meta-directories since Seam will auto-load these
without a scan
- if (!name.startsWith("WEB-INF/") &&
!name.startsWith("META-INF/"))
- {
- resources.add(name);
- }
+ // we want to skip over known meta-directories since Seam will auto-load these
without a scan
+ String path = fileDescriptor.getName();
+ if (!INF_PATTERN.matcher(path).matches())
+ {
+ resources.add(fileDescriptor);
+ }
}
-
+ setResources(resources);
}
- public String getName()
- {
- return NAME;
- }
-
}
Modified: trunk/src/main/org/jboss/seam/deployment/DeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/DeploymentHandler.java 2008-10-22 13:26:57
UTC (rev 9378)
+++ trunk/src/main/org/jboss/seam/deployment/DeploymentHandler.java 2008-10-22 13:32:24
UTC (rev 9379)
@@ -1,5 +1,7 @@
package org.jboss.seam.deployment;
+import java.util.Set;
+
/**
* A deployment handler is responsible for processing found resources
*
@@ -11,16 +13,24 @@
*/
public interface DeploymentHandler
{
- /**
- * Handle a resource
- * @param name The path to the resource
- * @param classLoader The ClassLoader on which the resource was found
- */
- public void handle(String name, ClassLoader classLoader);
/**
* A key used to identify the deployment handler
*/
public String getName();
+ /**
+ * Get DeploymentHandlerMetadata for resources this deployment handler is
+ * interested in processing.
+ *
+ * If a deployment handler is interested in a number of files it should
+ * define multiple pieces of metadata
+ */
+ public DeploymentMetadata getMetadata();
+
+ public void postProcess(ClassLoader classLoader);
+
+ public Set<FileDescriptor> getResources();
+
+ public void setResources(Set<FileDescriptor> resources);
}
Added: trunk/src/main/org/jboss/seam/deployment/DeploymentMetadata.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/DeploymentMetadata.java
(rev 0)
+++ trunk/src/main/org/jboss/seam/deployment/DeploymentMetadata.java 2008-10-22 13:32:24
UTC (rev 9379)
@@ -0,0 +1,18 @@
+package org.jboss.seam.deployment;
+
+/**
+ * Metadata about resources the deployment handler is interested in
+ *
+ * @author pmuir
+ *
+ */
+public interface DeploymentMetadata
+{
+
+ /**
+ * A file name suffixes that this deployment handler is interested in
+ */
+ public String getFileNameSuffix();
+
+}
+
Property changes on: trunk/src/main/org/jboss/seam/deployment/DeploymentMetadata.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java 2008-10-22 13:26:57
UTC (rev 9378)
+++ trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java 2008-10-22 13:32:24
UTC (rev 9379)
@@ -7,6 +7,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
@@ -39,10 +40,6 @@
*/
public static final String SCANNERS_KEY =
"org.jboss.seam.deployment.scanners";
-
-
-
-
/**
* Do the scan for resources
*
@@ -92,19 +89,6 @@
}
protected abstract String getDeploymentHandlersKey();
-
- /**
- * Handle a resource using any registered {@link DeploymentHandler}s
- *
- * @param name Path to a resource to handle
- */
- public void handle(String name)
- {
- for (String key: getDeploymentHandlers().keySet())
- {
- getDeploymentHandlers().get(key).handle(name, getClassLoader());
- }
- }
private void initScanner()
{
@@ -229,4 +213,12 @@
return getScanner().getTimestamp();
}
+ protected void postScan()
+ {
+ for (Entry<String, DeploymentHandler> entry :
getDeploymentHandlers().entrySet())
+ {
+ entry.getValue().postProcess(getClassLoader());
+ }
+ }
+
}
Added: trunk/src/main/org/jboss/seam/deployment/DotComponentDotXmlDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/DotComponentDotXmlDeploymentHandler.java
(rev 0)
+++
trunk/src/main/org/jboss/seam/deployment/DotComponentDotXmlDeploymentHandler.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -0,0 +1,37 @@
+package org.jboss.seam.deployment;
+
+/**
+ * The {@link DotComponentDotXmlDeploymentHandler} .component.xml files
+ *
+ * @author Pete Muir
+ *
+ */
+public class DotComponentDotXmlDeploymentHandler extends AbstractDeploymentHandler
+{
+
+ private static DeploymentMetadata DOTCOMPONENTDOTXML_SUFFIX_FILE_METADATA = new
DeploymentMetadata()
+ {
+
+ public String getFileNameSuffix()
+ {
+ return ".component.xml";
+ }
+
+ };
+
+ /**
+ * Name under which this {@link DeploymentHandler} is registered
+ */
+ public static final String NAME =
"org.jboss.seam.deployment.DotComponentDotXmlDeploymentHandler";
+
+ public String getName()
+ {
+ return NAME;
+ }
+
+ public DeploymentMetadata getMetadata()
+ {
+ return DOTCOMPONENTDOTXML_SUFFIX_FILE_METADATA;
+ }
+
+}
Property changes on:
trunk/src/main/org/jboss/seam/deployment/DotComponentDotXmlDeploymentHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/main/org/jboss/seam/deployment/DotPageDotXmlDeploymentHandler.java
===================================================================
---
trunk/src/main/org/jboss/seam/deployment/DotPageDotXmlDeploymentHandler.java 2008-10-22
13:26:57 UTC (rev 9378)
+++
trunk/src/main/org/jboss/seam/deployment/DotPageDotXmlDeploymentHandler.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -1,9 +1,5 @@
package org.jboss.seam.deployment;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
import org.jboss.seam.contexts.Contexts;
/**
@@ -14,37 +10,22 @@
*/
public class DotPageDotXmlDeploymentHandler extends AbstractDeploymentHandler
{
- /**
- * Name under which this {@link DeploymentHandler} is registered
- */
- public static final String NAME =
"org.jboss.seam.deployment.DotPageDotXmlDeploymentHandler";
-
- private Set<String> files;
- public DotPageDotXmlDeploymentHandler()
+ private static DeploymentMetadata DOTPAGEDOTXML_SUFFIX_FILE_METADATA = new
DeploymentMetadata()
{
- files = new HashSet<String>();
- }
- /**
- * Get annotated Seam components
- */
- public Set<String> getFiles()
- {
- return Collections.unmodifiableSet(files);
- }
-
- /**
- * @see DeploymentHandler#handle(String, ClassLoader)
- */
- public void handle(String name, ClassLoader classLoader)
- {
- if (name.endsWith(".page.xml"))
+ public String getFileNameSuffix()
{
- files.add(name);
+ return ".page.xml";
}
- }
+
+ };
+ /**
+ * Name under which this {@link DeploymentHandler} is registered
+ */
+ public static final String NAME =
"org.jboss.seam.deployment.DotPageDotXmlDeploymentHandler";
+
public String getName()
{
return NAME;
@@ -70,5 +51,10 @@
throw new IllegalStateException("Event context not active");
}
}
+
+ public DeploymentMetadata getMetadata()
+ {
+ return DOTPAGEDOTXML_SUFFIX_FILE_METADATA;
+ }
}
Added: trunk/src/main/org/jboss/seam/deployment/FileDescriptor.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/FileDescriptor.java
(rev 0)
+++ trunk/src/main/org/jboss/seam/deployment/FileDescriptor.java 2008-10-22 13:32:24 UTC
(rev 9379)
@@ -0,0 +1,59 @@
+package org.jboss.seam.deployment;
+
+import java.net.URL;
+
+public class FileDescriptor
+{
+
+ private String name;
+ private URL url;
+
+ public FileDescriptor(String name, URL url)
+ {
+ this.name = name;
+ this.url = url;
+ }
+
+ public FileDescriptor(String name, ClassLoader classLoader)
+ {
+ this.name = name;
+ this.url = classLoader.getResource(name);
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public URL getUrl()
+ {
+ return url;
+ }
+
+ @Override
+ public String toString()
+ {
+ return url.getPath();
+ }
+
+ @Override
+ public boolean equals(Object other)
+ {
+ if (other instanceof FileDescriptor)
+ {
+ FileDescriptor that = (FileDescriptor) other;
+ return this.getUrl().equals(that.getUrl());
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return getUrl().hashCode();
+ }
+
+}
Property changes on: trunk/src/main/org/jboss/seam/deployment/FileDescriptor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/main/org/jboss/seam/deployment/GroovyDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/GroovyDeploymentHandler.java 2008-10-22
13:26:57 UTC (rev 9378)
+++ trunk/src/main/org/jboss/seam/deployment/GroovyDeploymentHandler.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -6,7 +6,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -25,13 +24,32 @@
public class GroovyDeploymentHandler extends AbstractDeploymentHandler
{
+ private class GroovyDeploymentHandlerMetadata implements DeploymentMetadata
+ {
+
+ private String groovyExtension;
+
+ public GroovyDeploymentHandlerMetadata(String groovyExtension)
+ {
+ this.groovyExtension = groovyExtension;
+ }
+
+ public String getFileNameSuffix()
+ {
+ return groovyExtension;
+ }
+
+ }
+
+ private DeploymentMetadata metadata;
+
private static final LogProvider log =
Logging.getLogProvider(GroovyDeploymentHandler.class);
public static final String NAME =
"org.jboss.seam.deployment.GroovyDeploymentHandler";
private final String groovyFileExtension;
- private Set<Class<Object>> classes;
+ private Set<ClassDescriptor> classes;
/**
*
@@ -40,28 +58,30 @@
public GroovyDeploymentHandler(String groovyFileExtension)
{
this.groovyFileExtension = groovyFileExtension;
- this.classes = new HashSet<Class<Object>>();
+ this.classes = new HashSet<ClassDescriptor>();
+ this.metadata = new GroovyDeploymentHandlerMetadata(groovyFileExtension);
}
/**
* Get all the Groovy Seam Components this handler has handled
*/
- public Set<Class<Object>> getClasses()
+ public Set<ClassDescriptor> getClasses()
{
- return Collections.unmodifiableSet(classes);
+ return classes;
}
-
- public void handle(String name, ClassLoader classLoader)
+
+ @Override
+ public void postProcess(ClassLoader classLoader)
{
- if (name.endsWith(groovyFileExtension))
+ for (FileDescriptor fileDescriptor : getResources())
{
- log.debug("Found a groovy file: " + name);
- String classname = filenameToGroovyname(name);
- String filename = groovyComponentFilename(name);
+ log.debug("Found a groovy file: " + fileDescriptor.getName());
+ String classname = filenameToGroovyname(fileDescriptor.getName());
+ String filename = groovyComponentFilename(fileDescriptor.getName());
BufferedReader buffReader = null;
try
{
- InputStream stream = classLoader.getResourceAsStream(name);
+ InputStream stream =
classLoader.getResourceAsStream(fileDescriptor.getName());
//TODO is BufferedInputStream necessary?
buffReader = new BufferedReader(new InputStreamReader(stream));
String line = buffReader.readLine();
@@ -70,7 +90,7 @@
if (line.indexOf("@Name") != -1 || line.indexOf("@" +
Name.class.getName()) != -1)
{
//possibly a Seam component
- log.debug("Groovy file possibly a Seam component: " + name);
+ log.debug("Groovy file possibly a Seam component: " +
fileDescriptor.getName());
Class<Object> groovyClass = (Class<Object>)
classLoader.loadClass(classname);
Install install = groovyClass.getAnnotation(Install.class);
boolean installable = ( install == null || install.value() )
@@ -78,8 +98,8 @@
|| classLoader.getResources(filename).hasMoreElements() );
if (installable)
{
- log.debug("found groovy component class: " + name);
- classes.add(groovyClass);
+ log.debug("found groovy component class: " +
fileDescriptor.getName());
+ classes.add(new ClassDescriptor(fileDescriptor.getName(),
fileDescriptor.getUrl(), groovyClass));
}
break;
}
@@ -120,9 +140,10 @@
}
}
}
-
}
+
+
private String filenameToGroovyname(String filename)
{
return filename.substring(0, filename.lastIndexOf(groovyFileExtension))
@@ -139,4 +160,9 @@
return NAME;
}
+ public DeploymentMetadata getMetadata()
+ {
+ return metadata;
+ }
+
}
Modified: trunk/src/main/org/jboss/seam/deployment/GroovyHotDeploymentStrategy.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/GroovyHotDeploymentStrategy.java 2008-10-22
13:26:57 UTC (rev 9378)
+++ trunk/src/main/org/jboss/seam/deployment/GroovyHotDeploymentStrategy.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -68,9 +68,9 @@
}
@Override
- public Set<Class<Object>> getScannedComponentClasses()
+ public Set<ClassDescriptor> getScannedComponentClasses()
{
- Set<Class<Object>> set = new HashSet<Class<Object>>();
+ Set<ClassDescriptor> set = new HashSet<ClassDescriptor>();
set.addAll(super.getScannedComponentClasses());
set.addAll(groovyDeploymentHandler.getClasses());
return Collections.unmodifiableSet(set);
Modified: trunk/src/main/org/jboss/seam/deployment/HotDeploymentStrategy.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/HotDeploymentStrategy.java 2008-10-22
13:26:57 UTC (rev 9378)
+++ trunk/src/main/org/jboss/seam/deployment/HotDeploymentStrategy.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -5,6 +5,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
+import java.util.Collections;
import java.util.Map;
import java.util.Set;
@@ -154,21 +155,21 @@
/**
* Get all Components which the strategy has scanned and handled
*/
- public Set<Class<Object>> getScannedComponentClasses()
+ public Set<ClassDescriptor> getScannedComponentClasses()
{
- return componentDeploymentHandler.getClasses();
+ return Collections.unmodifiableSet(componentDeploymentHandler.getClasses());
}
- public Map<String, Set<Class<Object>>> getAnnotatedClasses()
+ public Map<String, Set<Class<?>>> getAnnotatedClasses()
{
- return annotationDeploymentHandler.getClasses();
+ return Collections.unmodifiableMap(annotationDeploymentHandler.getClassMap());
}
@Override
public void scan()
{
getScanner().scanDirectories(getFiles().toArray(new File[0]));
-
+ postScan();
}
public static HotDeploymentStrategy instance()
Modified: trunk/src/main/org/jboss/seam/deployment/NamespaceDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/NamespaceDeploymentHandler.java 2008-10-22
13:26:57 UTC (rev 9378)
+++ trunk/src/main/org/jboss/seam/deployment/NamespaceDeploymentHandler.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -17,6 +17,16 @@
public class NamespaceDeploymentHandler extends AbstractDeploymentHandler
{
+ private static DeploymentMetadata NAMESPACE_METADATA = new DeploymentMetadata()
+ {
+
+ public String getFileNameSuffix()
+ {
+ return "/package-info.class";
+ }
+
+ };
+
public static final String NAME =
"org.jboss.seam.deployment.NamespaceDeploymentHandler";
private static final LogProvider log =
Logging.getLogProvider(NamespaceDeploymentHandler.class);
@@ -36,30 +46,33 @@
return Collections.unmodifiableSet(packages);
}
- public void handle(String name, ClassLoader classLoader)
+ @Override
+ public void postProcess(ClassLoader classLoader)
{
- if ( name.endsWith("/package-info.class") )
- {
- String packageName = filenameToPackageName(name);
- Package pkg = getPackage(packageName, classLoader);
- if (pkg == null)
- {
- log.warn("Cannot load package Dinfo for " + packageName);
- }
- else
- {
- if (pkg.getAnnotation(Namespace.class) != null)
- {
- packages.add(pkg);
- }
- }
- }
+ for (FileDescriptor fileDescriptor : getResources())
+ {
+ String packageName = filenameToPackageName(fileDescriptor.getName());
+ Package pkg = getPackage(packageName, classLoader);
+ if (pkg == null)
+ {
+ log.warn("Cannot load package Dinfo for " + packageName);
+ }
+ else
+ {
+ if (pkg.getAnnotation(Namespace.class) != null)
+ {
+ packages.add(pkg);
+ }
+ }
+ }
+
+
}
private static String filenameToPackageName(String filename)
{
- return filename.substring(0,
filename.lastIndexOf("/package-info.class"))
- .replace('/', '.').replace('\\', '.');
+ return filename.substring(0,
filename.lastIndexOf("/package-info.class"))
+ .replace('/', '.').replace('\\', '.');
}
private static Package getPackage(String name, ClassLoader classLoader)
@@ -79,5 +92,10 @@
{
return NAME;
}
+
+ public DeploymentMetadata getMetadata()
+ {
+ return NAMESPACE_METADATA;
+ }
}
Modified: trunk/src/main/org/jboss/seam/deployment/StandardDeploymentStrategy.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/StandardDeploymentStrategy.java 2008-10-22
13:26:57 UTC (rev 9378)
+++ trunk/src/main/org/jboss/seam/deployment/StandardDeploymentStrategy.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -1,6 +1,8 @@
package org.jboss.seam.deployment;
import java.io.File;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -41,6 +43,7 @@
private ComponentsXmlDeploymentHandler componentsXmlDeploymentHandler;
private NamespaceDeploymentHandler namespaceDeploymentHandler;
private AnnotationDeploymentHandler annotationDeploymentHandler;
+ private DotComponentDotXmlDeploymentHandler dotComponentDotXmlDeploymentHandler;
/**
* @param classLoader The classloader used to load and handle resources
@@ -52,6 +55,8 @@
getDeploymentHandlers().put(ComponentDeploymentHandler.NAME,
componentDeploymentHandler);
componentsXmlDeploymentHandler = new ComponentsXmlDeploymentHandler();
getDeploymentHandlers().put(ComponentsXmlDeploymentHandler.NAME,
componentsXmlDeploymentHandler);
+ dotComponentDotXmlDeploymentHandler = new DotComponentDotXmlDeploymentHandler();
+ getDeploymentHandlers().put(DotComponentDotXmlDeploymentHandler.NAME,
dotComponentDotXmlDeploymentHandler);
namespaceDeploymentHandler = new NamespaceDeploymentHandler();
getDeploymentHandlers().put(NamespaceDeploymentHandler.NAME,
namespaceDeploymentHandler);
annotationDeploymentHandler = new AnnotationDeploymentHandler(new
SeamDeploymentProperties(classLoader).getPropertyValues(AnnotationDeploymentHandler.ANNOTATIONS_KEY),
classLoader);
@@ -71,19 +76,22 @@
}
/**
- * Get all scanned and handled annotated components known to this strategy
+ * Get all annotated components known to this strategy
*/
- public Set<Class<Object>> getScannedComponentClasses()
+ public Set<ClassDescriptor> getAnnotatedComponents()
{
- return componentDeploymentHandler.getClasses();
+ return Collections.unmodifiableSet(componentDeploymentHandler.getClasses());
}
/**
- * Get all scanned and handled components.xml files
+ * Get all XML defined (throught components.xml and component.xml) components
*/
- public Set<String> getScannedComponentResources()
+ public Set<FileDescriptor> getXmlComponents()
{
- return componentsXmlDeploymentHandler.getResources();
+ Set<FileDescriptor> fileDescriptors = new HashSet<FileDescriptor>();
+ fileDescriptors.addAll(componentsXmlDeploymentHandler.getResources());
+ fileDescriptors.addAll(dotComponentDotXmlDeploymentHandler.getResources());
+ return Collections.unmodifiableSet(fileDescriptors);
}
/**
@@ -91,12 +99,12 @@
*/
public Set<Package> getScannedNamespaces()
{
- return namespaceDeploymentHandler.getPackages();
+ return Collections.unmodifiableSet(namespaceDeploymentHandler.getPackages());
}
- public Map<String, Set<Class<Object>>> getAnnotatedClasses()
+ public Map<String, Set<Class<?>>> getAnnotatedClasses()
{
- return annotationDeploymentHandler.getClasses();
+ return Collections.unmodifiableMap(annotationDeploymentHandler.getClassMap());
}
@Override
@@ -104,6 +112,7 @@
{
getScanner().scanResources(RESOURCE_NAMES);
getScanner().scanDirectories(getFiles().toArray(new File[0]));
+ postScan();
}
public static StandardDeploymentStrategy instance()
Modified: trunk/src/main/org/jboss/seam/deployment/URLScanner.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/URLScanner.java 2008-10-22 13:26:57 UTC (rev
9378)
+++ trunk/src/main/org/jboss/seam/deployment/URLScanner.java 2008-10-22 13:32:24 UTC (rev
9379)
@@ -90,7 +90,7 @@
{
try
{
- log.debug("scanning: " + urlPath);
+ log.trace("scanning: " + urlPath);
File file = new File(urlPath);
if ( file.isDirectory() )
{
@@ -112,7 +112,7 @@
{
try
{
- log.debug("archive: " + file);
+ log.trace("archive: " + file);
touchTimestamp(file);
ZipFile zip = new ZipFile(file);
Enumeration<? extends ZipEntry> entries = zip.entries();
@@ -131,7 +131,7 @@
private void handleDirectory(File file, String path)
{
- log.debug("directory: " + file);
+ log.trace("directory: " + file);
for ( File child: file.listFiles() )
{
String newPath = path==null ? child.getName() : path + '/' +
child.getName();
Modified: trunk/src/main/org/jboss/seam/deployment/WarRootDeploymentStrategy.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/WarRootDeploymentStrategy.java 2008-10-22
13:26:57 UTC (rev 9378)
+++ trunk/src/main/org/jboss/seam/deployment/WarRootDeploymentStrategy.java 2008-10-22
13:32:24 UTC (rev 9379)
@@ -56,25 +56,17 @@
{
return HANDLERS_KEY;
}
-
- @Override
- public void handle(String name)
- {
- if (!(name.startsWith("WEB-INF") ||
name.startsWith("/WEB-INF")))
- {
- super.handle(name);
- }
- }
@Override
public void scan()
{
getScanner().scanDirectories(warRoot);
+ postScan();
}
- public Set<String> getDotPageDotXmlFileNames()
+ public Set<FileDescriptor> getDotPageDotXmlFileNames()
{
- return dotPageDotXmlDeploymentHandler.getFiles();
+ return dotPageDotXmlDeploymentHandler.getResources();
}
}
Modified: trunk/src/main/org/jboss/seam/init/Initialization.java
===================================================================
--- trunk/src/main/org/jboss/seam/init/Initialization.java 2008-10-22 13:26:57 UTC (rev
9378)
+++ trunk/src/main/org/jboss/seam/init/Initialization.java 2008-10-22 13:32:24 UTC (rev
9379)
@@ -47,6 +47,8 @@
import org.jboss.seam.contexts.ServletLifecycle;
import org.jboss.seam.core.Expressions;
import org.jboss.seam.core.Init;
+import org.jboss.seam.deployment.ClassDescriptor;
+import org.jboss.seam.deployment.FileDescriptor;
import org.jboss.seam.deployment.HotDeploymentStrategy;
import org.jboss.seam.deployment.SeamDeploymentProperties;
import org.jboss.seam.deployment.StandardDeploymentStrategy;
@@ -792,8 +794,9 @@
private void installHotDeployableComponents()
{
- for (Class<Object> scannedClass:
hotDeploymentStrategy.getScannedComponentClasses() )
+ for (ClassDescriptor classDescriptor:
hotDeploymentStrategy.getScannedComponentClasses() )
{
+ Class<?> scannedClass = classDescriptor.getClazz();
installScannedComponentAndRoles(scannedClass);
}
}
@@ -869,15 +872,15 @@
private void scanForComponents()
{
- for ( Class<Object> scannedClass:
standardDeploymentStrategy.getScannedComponentClasses() )
+ for ( ClassDescriptor classDescriptor :
standardDeploymentStrategy.getAnnotatedComponents() )
{
- installScannedComponentAndRoles(scannedClass);
+ Class<?> scannedClass = classDescriptor.getClazz();
+ installScannedComponentAndRoles(scannedClass);
}
-
- for ( String name: standardDeploymentStrategy.getScannedComponentResources() )
+ for ( FileDescriptor fileDescriptor : standardDeploymentStrategy.getXmlComponents()
)
{
- installComponentsFromDescriptor( name,
standardDeploymentStrategy.getClassLoader() );
+ installComponentsFromDescriptor( fileDescriptor,
standardDeploymentStrategy.getClassLoader() );
}
}
@@ -890,10 +893,18 @@
return descriptor.substring(0,pos).replace('/',
'.').replace('\\', '.');
}
- private void installComponentsFromDescriptor(String fileName, ClassLoader loader)
+ private void installComponentsFromDescriptor(FileDescriptor fileDescriptor,
ClassLoader loader)
{
//note: this is correct, we do not need to scan other classloaders!
- InputStream stream = loader.getResourceAsStream(fileName);
+ InputStream stream = null;
+ try
+ {
+ stream = fileDescriptor.getUrl().openStream();
+ }
+ catch (IOException e)
+ {
+ // No-op
+ }
if (stream != null)
{
try
@@ -908,18 +919,18 @@
{
installComponentFromXmlElement(root,
root.attributeValue("name"),
- classFilenameFromDescriptor(fileName),
+ classFilenameFromDescriptor(fileDescriptor.getName()),
replacements);
}
} catch (Exception e) {
- throw new RuntimeException("error while reading " + fileName, e);
+ throw new RuntimeException("error while reading " +
fileDescriptor.getName(), e);
} finally {
Resources.closeStream(stream);
}
}
}
- private void installScannedComponentAndRoles(Class<Object> scannedClass)
+ private void installScannedComponentAndRoles(Class<?> scannedClass)
{
try {
if ( scannedClass.isAnnotationPresent(Name.class) )
@@ -943,7 +954,7 @@
}
}
- private void installRole(Class<Object> scannedClass, Role role)
+ private void installRole(Class<?> scannedClass, Role role)
{
ScopeType scope = Seam.getComponentRoleScope(scannedClass, role);
addComponentDescriptor( new ComponentDescriptor( role.name(), scannedClass, scope )
);
Modified: trunk/src/main/org/jboss/seam/navigation/Pages.java
===================================================================
--- trunk/src/main/org/jboss/seam/navigation/Pages.java 2008-10-22 13:26:57 UTC (rev
9378)
+++ trunk/src/main/org/jboss/seam/navigation/Pages.java 2008-10-22 13:32:24 UTC (rev
9379)
@@ -2,6 +2,7 @@
import static org.jboss.seam.annotations.Install.BUILT_IN;
+import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
@@ -10,7 +11,6 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
@@ -49,6 +49,7 @@
import org.jboss.seam.core.Expressions.MethodExpression;
import org.jboss.seam.core.Expressions.ValueExpression;
import org.jboss.seam.deployment.DotPageDotXmlDeploymentHandler;
+import org.jboss.seam.deployment.FileDescriptor;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.faces.Validation;
import org.jboss.seam.international.StatusMessage;
@@ -106,7 +107,7 @@
{
if (DotPageDotXmlDeploymentHandler.instance() != null)
{
- initialize(DotPageDotXmlDeploymentHandler.instance().getFiles());
+ initialize(DotPageDotXmlDeploymentHandler.instance().getResources());
}
else
{
@@ -121,7 +122,7 @@
initialize(null);
}
- public void initialize(Set<String> fileNames)
+ public void initialize(Set<FileDescriptor> fileNames)
{
pagesByViewId = Collections.synchronizedMap(new HashMap<String, Page>());
pageStacksByViewId = Collections.synchronizedMap(new HashMap<String,
List<Page>>());
@@ -149,27 +150,23 @@
}
}
- private void parsePages(Set<String> ...fileNames)
+ private void parsePages(Set<FileDescriptor> files)
{
- Set<String> mergedFileNames = new HashSet<String>();
- for (Set<String> f : fileNames)
+ for (FileDescriptor file : files)
{
- mergedFileNames.addAll(f);
- }
- for (String fileName: mergedFileNames)
- {
- if (!fileName.startsWith("/"))
+ String fileName = file.getName();
+ String viewId = "/" +
fileName.substring(0,fileName.length()-".page.xml".length()) +
".xhtml"; // needs more here
+
+ InputStream stream = null;
+ try
{
- fileName = "/" + fileName;
+ stream = file.getUrl().openStream();
}
- String viewId =
fileName.substring(0,fileName.length()-".page.xml".length()) +
".xhtml"; // needs more here
-
- InputStream stream = ResourceLoader.instance().getResourceAsStream(fileName);
- if (stream==null)
+ catch (IOException exception)
{
- log.info("no pages.xml file found: " + fileName);
+ // No-op
}
- else
+ if (stream != null)
{
log.debug("reading pages.xml file: " + fileName);
try {
Modified: trunk/src/resteasy/org/jboss/seam/resteasy/ResteasyBootstrap.java
===================================================================
--- trunk/src/resteasy/org/jboss/seam/resteasy/ResteasyBootstrap.java 2008-10-22 13:26:57
UTC (rev 9378)
+++ trunk/src/resteasy/org/jboss/seam/resteasy/ResteasyBootstrap.java 2008-10-22 13:32:24
UTC (rev 9379)
@@ -38,8 +38,8 @@
{
log.info("deploying Resteasy providers and resources");
- Collection<Class<java.lang.Object>> annotatedProviderClasses = null;
- Collection<Class<java.lang.Object>> annotatedResourceClasses = null;
+ Collection<Class<?>> annotatedProviderClasses = null;
+ Collection<Class<?>> annotatedResourceClasses = null;
if (applicationConfig.isScanProviders() || applicationConfig.isScanResources())
{
log.debug("scanning all classes for JAX-RS annotations");
@@ -48,8 +48,8 @@
AnnotationDeploymentHandler handler =
(AnnotationDeploymentHandler)
deployment.getDeploymentHandlers().get(AnnotationDeploymentHandler.NAME);
- annotatedProviderClasses =
handler.getClasses().get(javax.ws.rs.ext.Provider.class.getName());
- annotatedResourceClasses =
handler.getClasses().get(javax.ws.rs.Path.class.getName());
+ annotatedProviderClasses =
handler.getClassMap().get(javax.ws.rs.ext.Provider.class.getName());
+ annotatedResourceClasses =
handler.getClassMap().get(javax.ws.rs.Path.class.getName());
}
log.debug("finding all Seam component classes");