[webbeans-commits] Webbeans SVN: r1666 - in extensions/trunk: se and 23 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Mon Feb 23 19:11:39 EST 2009
Author: peteroyle
Date: 2009-02-23 19:11:39 -0500 (Mon, 23 Feb 2009)
New Revision: 1666
Added:
extensions/trunk/se/
extensions/trunk/se/nbactions.xml
extensions/trunk/se/pom.xml
extensions/trunk/se/src/
extensions/trunk/se/src/etc/
extensions/trunk/se/src/etc/header.txt
extensions/trunk/se/src/main/
extensions/trunk/se/src/main/java/
extensions/trunk/se/src/main/java/org/
extensions/trunk/se/src/main/java/org/jboss/
extensions/trunk/se/src/main/java/org/jboss/webbeans/
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/StartMain.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/beans/
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/beans/ParametersFactory.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/bindings/
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/bindings/Parameters.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/bindings/ParametersBinding.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/EmptyEjbDiscovery.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/UnsupportedEjbResolver.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/UnsupportedNaming.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/WebBeansBootstrap.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/bootstrap/
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/AbstractClassDeploymentHandler.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/AbstractDeploymentHandler.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/AbstractScanner.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/ClassDeploymentHandler.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/ClassDeploymentMetadata.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/ClassDescriptor.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/DeploymentHandler.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/DeploymentMetadata.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/DeploymentStrategy.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/FileDescriptor.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/Scanner.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/SimpleWebBeansDeploymentHandler.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/StandardDeploymentStrategy.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/URLScanner.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/WebBeansDeploymentProperties.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/WebBeansXmlDeploymentHandler.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/discovery/
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/discovery/WebBeanDiscoveryException.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/discovery/WebBeanDiscoveryImpl.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/Setup.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/Shutdown.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/Start.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/exception/
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/resources/
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/resources/DefaultResourceLoader.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/util/
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/util/EnumerationEnumeration.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/lifecycle/
extensions/trunk/se/src/main/java/org/jboss/webbeans/lifecycle/ApplicationLifecycle.java
extensions/trunk/se/src/main/resources/
extensions/trunk/se/src/main/resources/beans.xml
extensions/trunk/se/src/main/resources/log4j.properties
extensions/trunk/se/src/test/
extensions/trunk/se/src/test/java/
extensions/trunk/se/src/test/java/com/
extensions/trunk/se/src/test/java/com/screamingcoder/
extensions/trunk/se/src/test/java/com/screamingcoder/plebeians/
Log:
initial checkin of webbeans se module
Added: extensions/trunk/se/nbactions.xml
===================================================================
--- extensions/trunk/se/nbactions.xml (rev 0)
+++ extensions/trunk/se/nbactions.xml 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ JBoss, Home of Professional Open Source
+ Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ by the @authors tag. See the copyright.txt in the distribution for a
+ full listing of individual contributors.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+--><actions>
+ <action>
+ <actionName>CUSTOM-Jalopy Format</actionName>
+ <displayName>Jalopy Format</displayName>
+ <goals>
+ <goal>jalopy:format</goal>
+ </goals>
+ </action>
+ <action>
+ <actionName>CUSTOM-License Format</actionName>
+ <displayName>License Format</displayName>
+ <goals>
+ <goal>license:format</goal>
+ </goals>
+ </action>
+ </actions>
Added: extensions/trunk/se/pom.xml
===================================================================
--- extensions/trunk/se/pom.xml (rev 0)
+++ extensions/trunk/se/pom.xml 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.webbeans</groupId>
+ <artifactId>se-module</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>Web Beans SE Module</name>
+ <url>http://maven.apache.org</url>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jalopy-maven-plugin</artifactId>
+ <version>1.0-alpha-1</version>
+ <!-- This wipes out UNDO in IDEs. Run manually instead.
+ <executions>
+ <execution>
+ <phase>compile</phase>
+ <goals>
+ <goal>format</goal>
+ </goals>
+ </execution>
+ </executions>
+ -->
+ </plugin>
+ <plugin>
+ <groupId>com.google.code.maven-license-plugin</groupId>
+ <artifactId>maven-license-plugin</artifactId>
+ <version>1.4.0</version>
+ <configuration>
+ <basedir>${basedir}</basedir>
+ <header>${basedir}/src/etc/header.txt</header>
+ <quiet>false</quiet>
+ <failIfMissing>true</failIfMissing>
+ <aggregate>false</aggregate>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>compile</phase>
+ <goals>
+ <goal>format</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>repository.jboss.org</id>
+ <name>JBoss Repository</name>
+ <url>http://repository.jboss.org/maven2</url>
+ <releases>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>snapshots.jboss.org</id>
+ <name>JBoss Snapshots Repository</name>
+ <url>http://snapshots.jboss.org/maven2</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <updatePolicy>always</updatePolicy>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>repository.codehaus.org</id>
+ <name>Codehaus Repository</name>
+ <url>http://repository.codehaus.org</url>
+ </repository>
+ </repositories>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.jboss.webbeans</groupId>
+ <artifactId>webbeans-ri-spi</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <!-- TODO (PR): remove this dependency -->
+ <dependency>
+ <groupId>org.jboss.webbeans</groupId>
+ <artifactId>webbeans-ri</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
+ <version>1.0.1B</version>
+ </dependency>
+ </dependencies>
+
+</project>
Added: extensions/trunk/se/src/etc/header.txt
===================================================================
--- extensions/trunk/se/src/etc/header.txt (rev 0)
+++ extensions/trunk/se/src/etc/header.txt 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,14 @@
+JBoss, Home of Professional Open Source
+Copyright 2008, Red Hat Middleware LLC, and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+http://www.apache.org/licenses/LICENSE-2.0
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/StartMain.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/StartMain.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/StartMain.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,102 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se;
+
+import org.jboss.webbeans.context.beanmap.SimpleBeanMap;
+import org.jboss.webbeans.environment.se.boot.WebBeansBootstrap;
+import org.jboss.webbeans.lifecycle.ApplicationLifecycle;
+
+/**
+ * This is the main class that should always be called from the command
+ * line for a WebBEans SE app. Something like:
+ * <code>
+ * java -jar MyApp.jar org.jboss.webbeans.environment.se.StarMain arguments
+ * </code>
+ * @author Peter Royle
+ */
+public class StartMain
+{
+
+ String[] args;
+
+ public StartMain( String[] commandLineArgs )
+ {
+ this.args = commandLineArgs;
+ }
+
+ public void go()
+ {
+ WebBeansBootstrap webBeansBootstrap = new WebBeansBootstrap( args );
+
+ webBeansBootstrap.initialize();
+
+ ApplicationLifecycle lifecycle = ApplicationLifecycle.instance();
+ lifecycle.initialize();
+ final SimpleBeanMap appBeanMap = new SimpleBeanMap();
+ lifecycle.beginApplication( "TODO: application id?", appBeanMap );
+
+ webBeansBootstrap.boot();
+
+ lifecycle.endApplication( "TODO: application id?", appBeanMap );
+
+ }
+
+ /**
+ * The main method called from the command line. This little puppy
+ * will get the ball rolling.
+ * @param args the command line arguments
+ */
+ public static void main( String[] args )
+ {
+ new StartMain( args ).go();
+ }
+ /**
+ * When an exception happens in your main app, you don't want
+ * the manager to come down in a screaming heap. Well, not all the time.
+ * Sometimes you just want to exit gently. This method will detect such
+ * times and behave appropriately.
+ * @param e
+ */
+// private void handleException( Throwable e )
+// {
+// // check for a 'special' root cause
+// boolean dealtWith = false;
+// Throwable cause = e.getCause();
+//
+// while (cause != null)
+// {
+// if (cause instanceof CleanShutdownException)
+// {
+// // This is a request to shut down silently, so swollow it.
+// // Hoewver, if there's a message, then print it to stdout
+// if (cause.getMessage() != null)
+// {
+// System.out.println( cause.getMessage() );
+// }
+//
+// dealtWith = true;
+// }
+//
+// cause = cause.getCause();
+// }
+//
+// if (!dealtWith)
+// {
+// e.printStackTrace();
+// }
+// }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/beans/ParametersFactory.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/beans/ParametersFactory.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/beans/ParametersFactory.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,59 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.beans;
+
+import org.jboss.webbeans.environment.se.bindings.Parameters;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import javax.context.ApplicationScoped;
+import javax.inject.Produces;
+
+/**
+ * The simple bean that will hold the command line arguments
+ * and make them available by injection (using the @Parameters binding).
+ * It's initialised by the StartMain class before your main app is
+ * initialised.
+ * @author Peter Royle
+ */
+ at ApplicationScoped
+public class ParametersFactory
+{
+ private String[] args;
+
+ /**
+ * Producer method for the injectible command line args.
+ * @return The command line arguments.
+ */
+ @Produces
+ @Parameters
+ public ArrayList<String> getArgs( )
+ {
+ // TODO (PR): is there an unmodifiable, serializable List?
+ return new ArrayList( Arrays.asList( this.args ) );
+ }
+
+ /**
+ * StartMain passes in the command line args here.
+ * @param args The command line arguments.
+ */
+ public void setArgs( String[] args )
+ {
+ this.args = args;
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/bindings/Parameters.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/bindings/Parameters.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/bindings/Parameters.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,38 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.bindings;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.BindingType;
+
+/**
+ *
+ * @author Peter Royle
+ */
+ at BindingType
+ at Retention( RetentionPolicy.RUNTIME )
+ at Target( {ElementType.PARAMETER,
+ ElementType.METHOD,
+ ElementType.FIELD
+} )
+public @interface Parameters
+{
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/bindings/ParametersBinding.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/bindings/ParametersBinding.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/bindings/ParametersBinding.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,29 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.bindings;
+
+import javax.inject.AnnotationLiteral;
+
+/**
+ *
+ * @author Peter Royle
+ */
+public class ParametersBinding
+ extends AnnotationLiteral<Parameters>
+ implements Parameters
+{
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/EmptyEjbDiscovery.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/EmptyEjbDiscovery.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/EmptyEjbDiscovery.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,41 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.boot;
+
+import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
+import org.jboss.webbeans.ejb.spi.EjbDescriptor;
+
+import java.util.Collections;
+
+/**
+ *
+ * @author JBoss.org, modifications by Peter Royle
+ */
+public class EmptyEjbDiscovery
+ implements EjbDiscovery
+{
+
+ public Iterable<EjbDescriptor<?>> discoverEjbs()
+ {
+ return Collections.EMPTY_SET;
+ }
+
+ protected static Iterable<Class<?>> discoverEjbs( Iterable<Class<?>> webBeanClasses )
+ {
+ return Collections.EMPTY_SET;
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/UnsupportedEjbResolver.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/UnsupportedEjbResolver.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/UnsupportedEjbResolver.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,67 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.boot;
+
+import org.jboss.webbeans.ejb.spi.EjbResolver;
+import org.jboss.webbeans.resources.spi.NamingContext;
+
+import java.lang.annotation.Annotation;
+
+import javax.inject.manager.InjectionPoint;
+
+/**
+ * EjbResolver which does nothing, since we are not interested in EJB
+ * integration.
+ * @author Peter Royle
+ */
+public class UnsupportedEjbResolver
+ implements EjbResolver
+{
+ public UnsupportedEjbResolver( )
+ {
+ }
+
+ public Class<?extends Annotation> getEJBAnnotation( )
+ {
+ return null;
+ }
+
+ public Class<?extends Annotation> getPersistenceContextAnnotation( )
+ {
+ return null;
+ }
+
+ public Class<?extends Annotation> getResourceAnnotation( )
+ {
+ return null;
+ }
+
+ public Object resolveEjb( InjectionPoint injectionPoint, NamingContext naming )
+ {
+ throw new UnsupportedOperationException( "Not supported in SE environment." );
+ }
+
+ public Object resolvePersistenceContext( InjectionPoint injectionPoint, NamingContext naming )
+ {
+ throw new UnsupportedOperationException( "Not supported in SE environment." );
+ }
+
+ public Object resolveResource( InjectionPoint injectionPoint, NamingContext naming )
+ {
+ throw new UnsupportedOperationException( "Not supported yet in SE environment." );
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/UnsupportedNaming.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/UnsupportedNaming.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/UnsupportedNaming.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,39 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.boot;
+
+import org.jboss.webbeans.resources.spi.NamingContext;
+
+/**
+ *
+ * @author Peter Royle
+ */
+public class UnsupportedNaming
+ implements NamingContext
+{
+
+ public void bind( String name, Object value )
+ {
+ throw new UnsupportedOperationException( "Not supported in SE environment." );
+ }
+
+ public <T> T lookup( String name, Class<? extends T> expectedType )
+ {
+ throw new UnsupportedOperationException( "Not supported in SE environment." );
+ }
+
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/WebBeansBootstrap.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/WebBeansBootstrap.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/boot/WebBeansBootstrap.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,148 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.boot;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+import javax.inject.manager.Manager;
+import javax.transaction.Transaction;
+import org.jboss.webbeans.BeanValidator;
+import org.jboss.webbeans.CurrentManager;
+import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.bean.standard.InjectionPointBean;
+import org.jboss.webbeans.bean.standard.ManagerBean;
+import org.jboss.webbeans.bootstrap.BeanDeployer;
+import org.jboss.webbeans.bootstrap.BeansXmlParser;
+import org.jboss.webbeans.bootstrap.api.helpers.AbstractBootstrap;
+import org.jboss.webbeans.environment.se.beans.ParametersFactory;
+import org.jboss.webbeans.environment.se.discovery.WebBeanDiscoveryImpl;
+import org.jboss.webbeans.environment.se.resources.DefaultResourceLoader;
+import org.jboss.webbeans.literal.DeployedLiteral;
+import org.jboss.webbeans.literal.InitializedLiteral;
+import org.jboss.webbeans.log.Log;
+import org.jboss.webbeans.log.Logging;
+
+/**
+ * Bootstrap class for for WebBeans in SE environment. Provides no JNDI binding.
+ *
+ * @author Peter Royle
+ */
+public class WebBeansBootstrap extends AbstractBootstrap
+{
+
+ Log log = Logging.getLog( WebBeansBootstrap.class );
+ String[] commandLineArgs;
+ private ManagerImpl manager;
+
+ public WebBeansBootstrap( String[] commandLineArgs )
+ {
+ setResourceLoader( new DefaultResourceLoader() );
+ setEjbResolver( new UnsupportedEjbResolver() );
+ setEjbDiscovery( new EmptyEjbDiscovery() );
+ setNamingContext( new UnsupportedNaming() );
+ setWebBeanDiscovery( new WebBeanDiscoveryImpl() );
+ this.commandLineArgs = commandLineArgs;
+
+ }
+
+ @Override
+ public void initialize()
+ {
+
+ if (getResourceLoader() == null)
+ {
+ throw new IllegalStateException( "ResourceLoader not set" );
+ }
+ if (getNamingContext() == null)
+ {
+ throw new IllegalStateException( "NamingContext is not set" );
+ }
+ if (getEjbResolver() == null)
+ {
+ throw new IllegalStateException( "EjbResolver is not set" );
+ }
+ this.manager = new ManagerImpl( getNamingContext(), getEjbResolver(), getResourceLoader() );
+ CurrentManager.setRootManager( manager );
+
+ }
+
+ @Override
+ public Manager getManager()
+ {
+ return manager;
+ }
+
+ @Override
+ public void boot()
+ {
+ synchronized (this)
+ {
+ log.info( "Starting Web Beans RI (SE environment) " );
+ if (manager == null)
+ {
+ throw new IllegalStateException( "Manager has not been initialized" );
+ }
+ if (getWebBeanDiscovery() == null)
+ {
+ throw new IllegalStateException( "WebBeanDiscovery not set" );
+ }
+ if (getEjbDiscovery() == null)
+ {
+ throw new IllegalStateException( "EjbDiscovery is not set" );
+ }
+ if (getResourceLoader() == null)
+ {
+ throw new IllegalStateException( "ResourceLoader not set" );
+ }
+ BeansXmlParser parser = new BeansXmlParser( getResourceLoader(), getWebBeanDiscovery().discoverWebBeansXml() );
+ parser.parse();
+ List<Class<? extends Annotation>> enabledDeploymentTypes = parser.getEnabledDeploymentTypes();
+ if (enabledDeploymentTypes != null)
+ {
+ manager.setEnabledDeploymentTypes( enabledDeploymentTypes );
+ }
+ registerBeans( getWebBeanDiscovery().discoverWebBeanClasses() );
+
+ // grab the ParametersFactory and inject the given commandline arguments
+ ParametersFactory paramsFactory =
+ (ParametersFactory) CurrentManager.rootManager().getInstanceByType( ParametersFactory.class );
+ paramsFactory.setArgs( this.commandLineArgs );
+
+ manager.fireEvent( manager, new InitializedLiteral() );
+ log.info( "Web Beans initialized. Validating beans." );
+ manager.getResolver().resolveInjectionPoints();
+ new BeanValidator( manager ).validate();
+ manager.fireEvent( manager, new DeployedLiteral() );
+ }
+ }
+
+ /**
+ * Register the bean with the getManager(), including any standard (built in)
+ * beans
+ *
+ * @param classes The classes to register as Web Beans
+ */
+ protected void registerBeans( Iterable<Class<?>> classes )
+ {
+ BeanDeployer beanDeployer = new BeanDeployer( manager );
+ beanDeployer.addClasses( classes );
+ beanDeployer.addBean( ManagerBean.of( manager ) );
+ beanDeployer.addBean( InjectionPointBean.of( manager ) );
+ beanDeployer.addClass( Transaction.class );
+ beanDeployer.deploy();
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/AbstractClassDeploymentHandler.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/AbstractClassDeploymentHandler.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/AbstractClassDeploymentHandler.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,42 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.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;
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/AbstractDeploymentHandler.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/AbstractDeploymentHandler.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/AbstractDeploymentHandler.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,57 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.deployment;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Abstract base class for {@link DeploymentHandler} providing common functionality
+ *
+ * @author Pete Muir
+ *
+ */
+public abstract class AbstractDeploymentHandler
+ implements DeploymentHandler
+{
+ private Set<FileDescriptor> resources;
+
+ public AbstractDeploymentHandler( )
+ {
+ resources = new HashSet<FileDescriptor>( );
+ }
+
+ @Override
+ public String toString( )
+ {
+ return getName( );
+ }
+
+ public void setResources( Set<FileDescriptor> resources )
+ {
+ this.resources = resources;
+ }
+
+ public Set<FileDescriptor> getResources( )
+ {
+ return resources;
+ }
+
+ public void postProcess( ClassLoader classLoader )
+ {
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/AbstractScanner.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/AbstractScanner.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/AbstractScanner.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,284 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.deployment;
+
+import org.jboss.webbeans.environment.se.discovery.WebBeanDiscoveryException;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import javassist.bytecode.AnnotationsAttribute;
+import javassist.bytecode.ClassFile;
+
+/**
+ * Abstract base class for {@link Scanner} providing common functionality
+ *
+ * This class provides file-system orientated scanning
+ *
+ * @author Pete Muir
+ *
+ */
+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<FileDescriptor> fileDescriptors;
+ 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;
+ }
+
+ /**
+ * Return true if the file was handled (false if it was ignored)
+ */
+ protected boolean handle( DeploymentHandler deploymentHandler )
+ {
+ boolean handled = false;
+
+ if ( deploymentHandler instanceof ClassDeploymentHandler )
+ {
+ if ( name.endsWith( ".class" ) )
+ {
+ ClassDeploymentHandler classDeploymentHandler = (ClassDeploymentHandler) deploymentHandler;
+
+ if ( hasAnnotations( getClassFile( ),
+ classDeploymentHandler.getMetadata( ).getClassAnnotatedWith( ) ) )
+ {
+ if ( getClassDescriptor( ).getClazz( ) != null )
+ {
+ log.trace( "adding class to deployable list " + name + " for deployment handler " +
+ deploymentHandler.getName( ) );
+ classDeploymentHandler.getClasses( ).add( getClassDescriptor( ) );
+ handled = true;
+ } else
+ {
+ log.info( "skipping class " + name +
+ " because it cannot be loaded (may reference a type which is not available on the classpath)" );
+ }
+ }
+ }
+ } else
+ {
+ if ( name.endsWith( deploymentHandler.getMetadata( ).getFileNameSuffix( ) ) )
+ {
+ deploymentHandler.getResources( ).addAll( getAllFileDescriptors( ) );
+ handled = true;
+ }
+ }
+
+ return handled;
+ }
+
+ protected boolean handle( )
+ {
+ log.trace( "found " + name );
+
+ boolean handled = false;
+
+ for ( Entry<String, DeploymentHandler> entry : deploymentHandlers )
+ {
+ if ( handle( entry.getValue( ) ) )
+ {
+ handled = true;
+ }
+ }
+
+ return handled;
+ }
+
+ 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 Set<FileDescriptor> getAllFileDescriptors( )
+ {
+ if ( fileDescriptors == null )
+ {
+ try
+ {
+ Enumeration<URL> allUrls = classLoader.getResources( name );
+ Set<FileDescriptor> fileDescSet = new HashSet<FileDescriptor>( );
+
+ while ( allUrls.hasMoreElements( ) )
+ {
+ fileDescSet.add( new FileDescriptor(
+ name,
+ allUrls.nextElement( ) ) );
+ }
+
+ this.fileDescriptors = fileDescSet;
+ } catch ( IOException ex )
+ {
+ throw new WebBeanDiscoveryException( "Error loading all classpath urls for file " + name, ex );
+ }
+ }
+
+ return fileDescriptors;
+ }
+ }
+
+ private static final LogProvider log = Logging.getLogProvider( Scanner.class );
+ private DeploymentStrategy deploymentStrategy;
+
+ public AbstractScanner( DeploymentStrategy deploymentStrategy )
+ {
+ this.deploymentStrategy = deploymentStrategy;
+ ClassFile.class.getPackage( ); //to force loading of javassist, throwing an exception if it is missing
+ }
+
+ protected AbstractScanner( )
+ {
+ }
+
+ protected static boolean hasAnnotations( ClassFile classFile, Set<Class<?extends Annotation>> annotationTypes )
+ {
+ 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;
+ }
+ }
+ }
+ } else
+ {
+ // If no annotations were specified, don't filter on annotations
+ // (note that this differs to the semantics used in Seam, where nothing would be matched)
+ 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;
+ }
+
+ public long getTimestamp( )
+ {
+ return Long.MAX_VALUE;
+ }
+
+ protected void handleItem( String name )
+ {
+ handle( name );
+ }
+
+ protected boolean handle( String name )
+ {
+ return new Handler( name,
+ deploymentStrategy.getDeploymentHandlers( ).entrySet( ),
+ deploymentStrategy.getClassLoader( ) ).handle( );
+ }
+
+ public void scanDirectories( File[] directories, File[] excludedDirectories )
+ {
+ scanDirectories( directories );
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/ClassDeploymentHandler.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/ClassDeploymentHandler.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/ClassDeploymentHandler.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,29 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.deployment;
+
+import java.util.Set;
+
+public interface ClassDeploymentHandler
+ extends DeploymentHandler
+{
+ public ClassDeploymentMetadata getMetadata( );
+
+ public Set<ClassDescriptor> getClasses( );
+
+ public void setClasses( Set<ClassDescriptor> classes );
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/ClassDeploymentMetadata.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/ClassDeploymentMetadata.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/ClassDeploymentMetadata.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,35 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.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
+ *
+ * If this set is empty then all classes will be matched, whether they
+ * have annotations or not.
+ */
+ public Set<Class<?extends Annotation>> getClassAnnotatedWith( );
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/ClassDescriptor.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/ClassDescriptor.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/ClassDescriptor.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,101 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.deployment;
+
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+
+import java.net.URL;
+
+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 );
+ // IBM JVM will throw a TypeNotPresentException if any annotation on the class is not on
+ // the classpath, rendering the class virtually unusable (given Seam's heavy use of annotations)
+ clazz.getAnnotations( );
+ } catch ( ClassNotFoundException cnfe )
+ {
+ log.info( "could not load class: " + classname, cnfe );
+ } catch ( NoClassDefFoundError ncdfe )
+ {
+ log.debug( "could not load class (missing dependency): " + classname, ncdfe );
+ } catch ( TypeNotPresentException tnpe )
+ {
+ clazz = null;
+ log.debug( "could not load class (annotation missing dependency): " + classname, tnpe );
+ }
+ }
+
+ public Class<?> getClazz( )
+ {
+ return clazz;
+ }
+
+ @Override
+ public String toString( )
+ {
+ return clazz.getName( );
+ }
+
+ /**
+ * Convert a path to a class file to a class name
+ */
+ public 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( );
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/DeploymentHandler.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/DeploymentHandler.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/DeploymentHandler.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,51 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.deployment;
+
+import java.util.Set;
+
+/**
+ * A deployment handler is responsible for processing found resources
+ *
+ * All deployment handlers should specify a unique name under which they
+ * will be registered with the {@link DeploymentStrategy}
+ *
+ * @author Pete Muir
+ *
+ */
+public interface DeploymentHandler
+{
+ /**
+ * 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: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/DeploymentMetadata.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/DeploymentMetadata.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/DeploymentMetadata.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,32 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.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( );
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/DeploymentStrategy.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/DeploymentStrategy.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/DeploymentStrategy.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,242 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.deployment;
+
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+
+import java.io.File;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * A {@link DeploymentStrategy} coordinates the deployment of resources for a
+ * Web Beans SE application.
+ *
+ * @author Pete Muir
+ *
+ */
+public abstract class DeploymentStrategy
+{
+ private static final LogProvider log = Logging.getLogProvider( DeploymentStrategy.class );
+ private Scanner scanner;
+ private List<File> files = new ArrayList<File>( );
+ private Map<String, DeploymentHandler> deploymentHandlers;
+
+ /**
+ * The key under which to list possible scanners. System properties take
+ * precedence over /META-INF/seam-scanner.properties. Entries will be tried
+ * in sequential order until a Scanner can be loaded.
+ *
+ * This can be specified as a System property or in
+ * /META-INF/seam-deployment.properties
+ */
+ public static final String SCANNERS_KEY = "org.jboss.webbeans.environment.se.deployment.scanners";
+
+ /**
+ * Do the scan for resources
+ *
+ * Should only be called by Seam
+ *
+ */
+ public abstract void scan( );
+
+ /**
+ * Get the scanner being used
+ *
+ */
+ protected Scanner getScanner( )
+ {
+ if ( scanner == null )
+ {
+ initScanner( );
+ }
+
+ return scanner;
+ }
+
+ /**
+ * Get the classloader to use
+ */
+ public abstract ClassLoader getClassLoader( );
+
+ /**
+ * Get (or modify) any registered {@link DeploymentHandler}s
+ *
+ * Implementations of {@link DeploymentStrategy} may add default
+ * {@link DeploymentHandler}s
+ */
+ public Map<String, DeploymentHandler> getDeploymentHandlers( )
+ {
+ if ( deploymentHandlers == null )
+ {
+ initDeploymentHandlers( );
+ }
+
+ return this.deploymentHandlers;
+ }
+
+ private void initDeploymentHandlers( )
+ {
+ this.deploymentHandlers = new HashMap<String, DeploymentHandler>( );
+
+ List<String> deploymentHandlersClassNames =
+ new WebBeansDeploymentProperties( getClassLoader( ) ).getPropertyValues( getDeploymentHandlersKey( ) );
+ addHandlers( deploymentHandlersClassNames );
+ }
+
+ protected abstract String getDeploymentHandlersKey( );
+
+ protected void initScanner( )
+ {
+ List<String> scanners =
+ new WebBeansDeploymentProperties( getClassLoader( ) ).getPropertyValues( SCANNERS_KEY );
+
+ for ( String className : scanners )
+ {
+ Scanner scanner = instantiateScanner( className );
+
+ if ( scanner != null )
+ {
+ log.debug( "Using " + scanner.toString( ) );
+ this.scanner = scanner;
+
+ return;
+ }
+ }
+
+ log.debug( "Using default URLScanner" );
+ this.scanner = new URLScanner( this );
+ }
+
+ private Scanner instantiateScanner( String className )
+ {
+ try
+ {
+ Class<Scanner> scannerClass = (Class<Scanner>) getClassLoader( ).loadClass( className );
+ Constructor<Scanner> constructor = scannerClass.getConstructor( new Class[] { DeploymentStrategy.class } );
+
+ return constructor.newInstance( new Object[] { this } );
+ } catch ( ClassNotFoundException e )
+ {
+ log.trace( "Unable to use " + className + " as scanner (class not found)", e );
+ } catch ( NoClassDefFoundError e )
+ {
+ log.trace( "Unable to use " + className + " as scanner (dependency not found)", e );
+ } catch ( ClassCastException e )
+ {
+ log.trace( "Unable to use " + className +
+ " as scanner (class does not implement org.jboss.seam.deployment.Scanner)" );
+ } catch ( InstantiationException e )
+ {
+ log.trace( "Unable to instantiate scanner " + className, e );
+ } catch ( IllegalAccessException e )
+ {
+ log.trace( "Unable to instantiate scanner " + className, e );
+ } catch ( SecurityException e )
+ {
+ log.trace( className + " must declare public " + className +
+ "( ClassLoader classLoader, String ... resourceNames )", e );
+ } catch ( NoSuchMethodException e )
+ {
+ log.trace( className + " must declare public " + className +
+ "( ClassLoader classLoader, String ... resourceNames )", e );
+ } catch ( IllegalArgumentException e )
+ {
+ log.trace( className + " must declare public " + className +
+ "( ClassLoader classLoader, String ... resourceNames )", e );
+ } catch ( InvocationTargetException e )
+ {
+ log.trace( className + " must declare public " + className +
+ "( ClassLoader classLoader, String ... resourceNames )", e );
+ }
+
+ return null;
+ }
+
+ private void addHandlers( List<String> handlers )
+ {
+ for ( String handler : handlers )
+ {
+ addHandler( handler );
+ }
+ }
+
+ private void addHandler( String className )
+ {
+ DeploymentHandler deploymentHandler = instantiateDeploymentHandler( className );
+
+ if ( deploymentHandler != null )
+ {
+ log.debug( "Adding " + deploymentHandler + " as a deployment handler" );
+ deploymentHandlers.put( deploymentHandler.getName( ),
+ deploymentHandler );
+ }
+ }
+
+ private DeploymentHandler instantiateDeploymentHandler( String className )
+ {
+ try
+ {
+ Class<DeploymentHandler> clazz = (Class<DeploymentHandler>) getClassLoader( ).loadClass( className );
+
+ return clazz.newInstance( );
+ } catch ( ClassNotFoundException e )
+ {
+ log.trace( "Unable to use " + className + " as a deployment handler (class not found)", e );
+ } catch ( NoClassDefFoundError e )
+ {
+ log.trace( "Unable to use " + className + " as a deployment handler (dependency not found)", e );
+ } catch ( InstantiationException e )
+ {
+ log.trace( "Unable to instantiate deployment handler " + className, e );
+ } catch ( IllegalAccessException e )
+ {
+ log.trace( "Unable to instantiate deployment handler " + className, e );
+ }
+
+ return null;
+ }
+
+ public List<File> getFiles( )
+ {
+ return files;
+ }
+
+ public void setFiles( List<File> files )
+ {
+ this.files = files;
+ }
+
+ public long getTimestamp( )
+ {
+ return getScanner( ).getTimestamp( );
+ }
+
+ protected void postScan( )
+ {
+ for ( Entry<String, DeploymentHandler> entry : getDeploymentHandlers( ).entrySet( ) )
+ {
+ entry.getValue( ).postProcess( getClassLoader( ) );
+ }
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/FileDescriptor.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/FileDescriptor.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/FileDescriptor.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,85 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.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;
+
+ if ( name == null )
+ {
+ throw new NullPointerException( "Name cannot be null, loading from " + classLoader );
+ }
+
+ this.url = classLoader.getResource( name );
+
+ if ( this.url == null )
+ {
+ throw new NullPointerException( "Cannot find URL from classLoader for " + name + ", loading from " +
+ classLoader );
+ }
+ }
+
+ 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( );
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/Scanner.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/Scanner.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/Scanner.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,59 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.deployment;
+
+import java.io.File;
+
+/**
+ * The Scanner is used to find resources to be processed by Seam
+ *
+ * The processing is done by {@link DeploymentHandler}s
+ *
+ * @author Pete Muir
+ *
+ */
+public interface Scanner
+{
+ /**
+ * Recursively scan directories, skipping directories in the exclusion list.
+ *
+ * @param directories An array of the roots of the directory trees to scan
+ */
+ public void scanDirectories( File[] directories );
+
+ /**
+ * Recursively scan directories, skipping directories in the exclusion list.
+ *
+ * @param directories An array of the roots of the directory trees to scan
+ * @param excludedDirectories Directories to skip over during the recursive scan
+ */
+ public void scanDirectories( File[] directories, File[] excludedDirectories );
+
+ /**
+ * Scan for structures which contain any of the given resources in their root
+ *
+ * @param resources The resources to scan for
+ */
+ public void scanResources( String[] resources );
+
+ /**
+ * Get the deployment strategy this scanner is used by
+ */
+ public DeploymentStrategy getDeploymentStrategy( );
+
+ public long getTimestamp( );
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/SimpleWebBeansDeploymentHandler.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/SimpleWebBeansDeploymentHandler.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/SimpleWebBeansDeploymentHandler.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,62 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.deployment;
+
+import java.lang.annotation.Annotation;
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * The {@link SimpleWebBeansDeploymentHandler} processes all classes found in a
+ * Web Beans archive/folder.
+ *
+ * @author Pete Muir
+ * @author Peter Royle
+ *
+ */
+public class SimpleWebBeansDeploymentHandler
+ extends AbstractClassDeploymentHandler
+{
+ public static ClassDeploymentMetadata NAME_ANNOTATED_CLASS_METADATA =
+ new ClassDeploymentMetadata( )
+ {
+ public Set<Class<?extends Annotation>> getClassAnnotatedWith( )
+ {
+ return Collections.EMPTY_SET;
+ }
+
+ public String getFileNameSuffix( )
+ {
+ return null;
+ }
+ };
+
+ /**
+ * Name under which this {@link DeploymentHandler} is registered
+ */
+ public static final String NAME = "org.jboss.webbeans.environment.se.deployment.SimpleWebBeansDeploymentHandler";
+
+ public String getName( )
+ {
+ return NAME;
+ }
+
+ public ClassDeploymentMetadata getMetadata( )
+ {
+ return NAME_ANNOTATED_CLASS_METADATA;
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/StandardDeploymentStrategy.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/StandardDeploymentStrategy.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/StandardDeploymentStrategy.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,117 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.deployment;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * The standard deployment strategy used with Seam, deploys non-hot-deployable
+ * Seam components and namespaces
+ *
+ * @author Pete Muir
+ *
+ */
+public class StandardDeploymentStrategy
+ extends DeploymentStrategy
+{
+ private ClassLoader classLoader;
+
+ /**
+ * The files used to identify a Seam archive
+ */
+ public static final String[] RESOURCE_NAMES = { "beans.xml" };
+
+ /**
+ * The contextual variable name this deployment strategy is made available at
+ * during Seam startup.
+ */
+ public static final String NAME = "deploymentStrategy";
+
+ /**
+ * The key under which to list extra deployment handlers.
+ *
+ * This can be specified as a System property or in
+ * /META-INF/seam-deployment.properties
+ */
+ public static final String HANDLERS_KEY = "org.jboss.webbeans.environment.se.deployment.deploymentHandlers";
+ private SimpleWebBeansDeploymentHandler simpleWebBeansDeploymentHandler;
+ private WebBeansXmlDeploymentHandler webBeansXmlDeploymentHandler;
+
+ /**
+ * @param classLoader The classloader used to load and handle resources
+ */
+ public StandardDeploymentStrategy( ClassLoader classLoader )
+ {
+ this.classLoader = Thread.currentThread( ).getContextClassLoader( );
+ simpleWebBeansDeploymentHandler = new SimpleWebBeansDeploymentHandler( );
+ getDeploymentHandlers( ).put( SimpleWebBeansDeploymentHandler.NAME, simpleWebBeansDeploymentHandler );
+ webBeansXmlDeploymentHandler = new WebBeansXmlDeploymentHandler( );
+ getDeploymentHandlers( ).put( WebBeansXmlDeploymentHandler.NAME, webBeansXmlDeploymentHandler );
+ }
+
+ @Override
+ public ClassLoader getClassLoader( )
+ {
+ return classLoader;
+ }
+
+ @Override
+ protected String getDeploymentHandlersKey( )
+ {
+ return HANDLERS_KEY;
+ }
+
+ /**
+ * Get all annotated components known to this strategy
+ */
+ public Set<ClassDescriptor> getSimpleWebBeans( )
+ {
+ return Collections.unmodifiableSet( simpleWebBeansDeploymentHandler.getClasses( ) );
+ }
+
+ /**
+ * Get all beans.xml locations
+ */
+ public Set<FileDescriptor> getWebBeansXMLs( )
+ {
+ Set<FileDescriptor> fileDescriptors = new HashSet<FileDescriptor>( );
+ fileDescriptors.addAll( webBeansXmlDeploymentHandler.getResources( ) );
+
+ return Collections.unmodifiableSet( fileDescriptors );
+ }
+
+ @Override
+ public void scan( )
+ {
+ getScanner( ).scanResources( RESOURCE_NAMES );
+ getScanner( ).scanDirectories( getFiles( ).toArray( new File[0] ) );
+ postScan( );
+ }
+
+ // TODO (PR): what's the equivalent for Web Beans?
+// public static StandardDeploymentStrategy instance()
+// {
+// if (Contexts.getEventContext().isSet(NAME))
+// {
+// return (StandardDeploymentStrategy) Contexts.getEventContext().get(NAME);
+// }
+// return null;
+// }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/URLScanner.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/URLScanner.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/URLScanner.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,217 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.deployment;
+
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.URLDecoder;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+
+/**
+ * Implementation of {@link Scanner} which can scan a {@link URLClassLoader}
+ *
+ * @author Thomas Heute
+ * @author Gavin King
+ * @author Norman Richards
+ * @author Pete Muir
+ *
+ */
+public class URLScanner
+ extends AbstractScanner
+{
+ private static final LogProvider log = Logging.getLogProvider( URLScanner.class );
+ private long timestamp;
+
+ public URLScanner( DeploymentStrategy deploymentStrategy )
+ {
+ super( deploymentStrategy );
+ }
+
+ public void scanDirectories( File[] directories )
+ {
+ scanDirectories( directories,
+ new File[0] );
+ }
+
+ @Override
+ public void scanDirectories( File[] directories, File[] excludedDirectories )
+ {
+ for ( File directory : directories )
+ {
+ handleDirectory( directory, null, excludedDirectories );
+ }
+ }
+
+ public void scanResources( String[] resources )
+ {
+ Set<String> paths = new HashSet<String>( );
+
+ for ( String resourceName : resources )
+ {
+ try
+ {
+ Enumeration<URL> urlEnum = getDeploymentStrategy( ).getClassLoader( ).getResources( resourceName );
+
+ while ( urlEnum.hasMoreElements( ) )
+ {
+ String urlPath = urlEnum.nextElement( ).getFile( );
+ urlPath = URLDecoder.decode( urlPath, "UTF-8" );
+
+ if ( urlPath.startsWith( "file:" ) )
+ {
+ urlPath = urlPath.substring( 5 );
+ }
+
+ if ( urlPath.indexOf( '!' ) > 0 )
+ {
+ urlPath =
+ urlPath.substring( 0,
+ urlPath.indexOf( '!' ) );
+ } else
+ {
+ File dirOrArchive = new File( urlPath );
+
+ if ( ( resourceName != null ) && ( resourceName.lastIndexOf( '/' ) > 0 ) )
+ {
+ //for META-INF/components.xml
+ dirOrArchive = dirOrArchive.getParentFile( );
+ }
+
+ urlPath = dirOrArchive.getParent( );
+ }
+
+ paths.add( urlPath );
+ }
+ } catch ( IOException ioe )
+ {
+ log.warn( "could not read: " + resourceName, ioe );
+ }
+ }
+
+ handle( paths );
+ }
+
+ protected void handle( Set<String> paths )
+ {
+ for ( String urlPath : paths )
+ {
+ try
+ {
+ log.trace( "scanning: " + urlPath );
+
+ File file = new File( urlPath );
+
+ if ( file.isDirectory( ) )
+ {
+ handleDirectory( file, null );
+ } else
+ {
+ handleArchiveByFile( file );
+ }
+ } catch ( IOException ioe )
+ {
+ log.warn( "could not read entries", ioe );
+ }
+ }
+ }
+
+ private void handleArchiveByFile( File file )
+ throws IOException
+ {
+ try
+ {
+ log.trace( "archive: " + file );
+ touchTimestamp( file );
+
+ ZipFile zip = new ZipFile( file );
+ Enumeration<?extends ZipEntry> entries = zip.entries( );
+
+ while ( entries.hasMoreElements( ) )
+ {
+ ZipEntry entry = entries.nextElement( );
+ String name = entry.getName( );
+ handle( name );
+ }
+ } catch ( ZipException e )
+ {
+ throw new RuntimeException( "Error handling file " + file, e );
+ }
+ }
+
+ private void handleDirectory( File file, String path )
+ {
+ handleDirectory( file,
+ path,
+ new File[0] );
+ }
+
+ private void handleDirectory( File file, String path, File[] excludedDirectories )
+ {
+ for ( File excludedDirectory : excludedDirectories )
+ {
+ if ( file.equals( excludedDirectory ) )
+ {
+ log.trace( "skipping excluded directory: " + file );
+
+ return;
+ }
+ }
+
+ log.trace( "handling directory: " + file );
+
+ for ( File child : file.listFiles( ) )
+ {
+ String newPath = ( path == null ) ? child.getName( ) : ( path + '/' + child.getName( ) );
+
+ if ( child.isDirectory( ) )
+ {
+ handleDirectory( child, newPath, excludedDirectories );
+ } else
+ {
+ if ( handle( newPath ) )
+ {
+ // only try to update the timestamp on this scanner if the file was actually handled
+ touchTimestamp( child );
+ }
+ }
+ }
+ }
+
+ private void touchTimestamp( File file )
+ {
+ if ( file.lastModified( ) > timestamp )
+ {
+ timestamp = file.lastModified( );
+ }
+ }
+
+ @Override
+ public long getTimestamp( )
+ {
+ return timestamp;
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/WebBeansDeploymentProperties.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/WebBeansDeploymentProperties.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/WebBeansDeploymentProperties.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,136 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.deployment;
+
+import org.jboss.webbeans.environment.se.util.EnumerationEnumeration;
+import static org.jboss.webbeans.util.Strings.split;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Properties;
+
+public class WebBeansDeploymentProperties
+{
+ private ClassLoader classLoader;
+ private Enumeration<URL> urlEnum;
+
+ public WebBeansDeploymentProperties( ClassLoader classLoader )
+ {
+ this.classLoader = classLoader;
+ }
+
+ /**
+ * The resource bundle used to control Seam deployment
+ */
+ public static final String RESOURCE_BUNDLE = "META-INF/seam-deployment.properties";
+
+ // All resource bundles to use, including legacy names
+ private static final String[] RESOURCE_BUNDLES = { RESOURCE_BUNDLE, "META-INF/seam-scanner.properties" };
+
+ /**
+ * Get a list of possible values for a given key.
+ *
+ * First, System properties are tried, followed by the specified resource
+ * bundle (first in classpath only).
+ *
+ * Colon (:) deliminated lists are split out.
+ *
+ */
+ public List<String> getPropertyValues( String key )
+ {
+ List<String> values = new ArrayList<String>( );
+ addPropertiesFromSystem( key, values );
+ addPropertiesFromResourceBundle( key, values );
+
+ return values;
+ }
+
+ private void addPropertiesFromSystem( String key, List<String> values )
+ {
+ addProperty( key,
+ System.getProperty( key ),
+ values );
+ }
+
+ private void addPropertiesFromResourceBundle( String key, List<String> values )
+ {
+ try
+ {
+ while ( getResources( ).hasMoreElements( ) )
+ {
+ URL url = getResources( ).nextElement( );
+ Properties properties = new Properties( );
+ InputStream propertyStream = url.openStream( );
+
+ try
+ {
+ properties.load( propertyStream );
+ addProperty( key,
+ properties.getProperty( key ),
+ values );
+ } finally
+ {
+ if ( propertyStream != null )
+ {
+ propertyStream.close( );
+ }
+ }
+ }
+ } catch ( IOException e )
+ {
+ // No - op, file is optional
+ }
+ }
+
+ /*
+ * Add the property to the set of properties only if it hasn't already been added
+ */
+ private void addProperty( String key, String value, List<String> values )
+ {
+ if ( value != null )
+ {
+ String[] properties = split( value, ":" );
+
+ for ( String property : properties )
+ {
+ values.add( property );
+ }
+ }
+ }
+
+ private Enumeration<URL> getResources( )
+ throws IOException
+ {
+ if ( urlEnum == null )
+ {
+ Enumeration<URL>[] enumerations = new Enumeration[RESOURCE_BUNDLES.length];
+
+ for ( int i = 0; i < RESOURCE_BUNDLES.length; i++ )
+ {
+ enumerations[i] = classLoader.getResources( RESOURCE_BUNDLES[i] );
+ }
+
+ urlEnum = new EnumerationEnumeration<URL>( enumerations );
+ }
+
+ return urlEnum;
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/WebBeansXmlDeploymentHandler.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/WebBeansXmlDeploymentHandler.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/deployment/WebBeansXmlDeploymentHandler.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,52 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.deployment;
+
+
+/**
+ * The {@link WebBeansXmlDeploymentHandler} beans.xml files
+ *
+ * @author Pete Muir
+ *
+ */
+public class WebBeansXmlDeploymentHandler
+ extends AbstractDeploymentHandler
+{
+ private static DeploymentMetadata WEBBEANSXML_SUFFIX_FILE_METADATA =
+ new DeploymentMetadata( )
+ {
+ public String getFileNameSuffix( )
+ {
+ return "beans.xml";
+ }
+ };
+
+ /**
+ * Name under which this {@link DeploymentHandler} is registered
+ */
+ public static final String NAME = "org.jboss.webbeans.environment.se.deployment.WebBeansXmlDeploymentHandler";
+
+ public String getName( )
+ {
+ return NAME;
+ }
+
+ public DeploymentMetadata getMetadata( )
+ {
+ return WEBBEANSXML_SUFFIX_FILE_METADATA;
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/discovery/WebBeanDiscoveryException.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/discovery/WebBeanDiscoveryException.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/discovery/WebBeanDiscoveryException.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,42 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.discovery;
+
+
+/**
+ * Thrown if there's an error during Web Bean discoery that will stop the
+ * manager from starting up.
+ * @author Peter Royle
+ */
+public class WebBeanDiscoveryException
+ extends RuntimeException
+{
+ public WebBeanDiscoveryException( Throwable cause )
+ {
+ super( cause );
+ }
+
+ public WebBeanDiscoveryException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public WebBeanDiscoveryException( String message )
+ {
+ super( message );
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/discovery/WebBeanDiscoveryImpl.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/discovery/WebBeanDiscoveryImpl.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/discovery/WebBeanDiscoveryImpl.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,88 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.discovery;
+
+import org.apache.log4j.Logger;
+
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
+import org.jboss.webbeans.ejb.spi.EjbDescriptor;
+import org.jboss.webbeans.environment.se.deployment.ClassDescriptor;
+import org.jboss.webbeans.environment.se.deployment.FileDescriptor;
+import org.jboss.webbeans.environment.se.deployment.StandardDeploymentStrategy;
+
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * The means by which Web Beans are discovered on the classpath. This will only
+ * discover simple web beans - there is no EJB/Servlet/JPA integration.
+ * @author Peter Royle.
+ * Adapted from org.jboss.webbeans.integration.jbossas.WebBeansDiscoveryImpl (author unknown)
+ */
+public class WebBeanDiscoveryImpl
+ implements WebBeanDiscovery
+{
+ private Set<Class<?>> wbClasses = new HashSet<Class<?>>( );
+ private Set<URL> wbUrls = new HashSet<URL>( );
+ private StandardDeploymentStrategy deploymentStrategy;
+
+ // The log provider
+ private static Logger log = Logger.getLogger( WebBeanDiscoveryImpl.class.getName( ) );
+
+ public WebBeanDiscoveryImpl( )
+ {
+ deploymentStrategy = new StandardDeploymentStrategy( Thread.currentThread( ).getContextClassLoader( ) );
+ deploymentStrategy.scan( );
+
+ findWebBeansXmlUrls( );
+ findWebBeansAnnotatedClasses( );
+ }
+
+ public Iterable<EjbDescriptor<?>> discoverEjbs( )
+ {
+ return new HashSet<EjbDescriptor<?>>( );
+ }
+
+ public Iterable<Class<?>> discoverWebBeanClasses( )
+ {
+ return wbClasses;
+ }
+
+ public Iterable<URL> discoverWebBeansXml( )
+ {
+ return wbUrls;
+ }
+
+ private void findWebBeansAnnotatedClasses( )
+ throws WebBeanDiscoveryException
+ {
+ for ( ClassDescriptor classDesc : deploymentStrategy.getSimpleWebBeans( ) )
+ {
+ final Class<?> clazz = classDesc.getClazz( );
+ wbClasses.add( clazz );
+ }
+ }
+
+ private void findWebBeansXmlUrls( )
+ {
+ for ( FileDescriptor fileDesc : deploymentStrategy.getWebBeansXMLs( ) )
+ {
+ wbUrls.add( fileDesc.getUrl( ) );
+ }
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/Setup.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/Setup.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/Setup.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,30 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.events;
+
+
+/**
+ * The event which is fired after the manager initialises but before the
+ * "Start" event is fired (causing the application to begin).
+ * Applications may observe this event in order to perform any additional setup
+ * necessary, however it is most useful for setup required to make injection
+ * of certain custom beans possible - for example: setting up custom contexts.
+ * @author Peter Royle
+ */
+public class Setup
+{
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/Shutdown.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/Shutdown.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/Shutdown.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,30 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.events;
+
+/**
+ * Fired by webbeans SE before shutting down. Applications and modules should
+ * release resources cleanly in response to this event.
+ * @author Peter Royle
+ */
+public class Shutdown
+{
+
+ public Shutdown()
+ {
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/Start.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/Start.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/Start.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,28 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.events;
+
+
+/**
+ * The event which is fired after the manager initialises and is ready for the
+ * application to start. Applications should provide a method which observes
+ * this event as a means of starting the application.
+ * @author Peter Royle
+ */
+public class Start
+{
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/resources/DefaultResourceLoader.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/resources/DefaultResourceLoader.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/resources/DefaultResourceLoader.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.resources;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+import org.jboss.webbeans.resources.spi.ResourceLoadingException;
+import org.jboss.webbeans.util.EnumerationIterable;
+
+/**
+ * A simple resource loader.
+ *
+ * Uses {@link DefaultResourceLoader}'s classloader if the Thread Context
+ * Classloader isn't available
+ *
+ * @author Pete Muir
+ *
+ */
+public class DefaultResourceLoader implements ResourceLoader
+{
+
+ public Class<?> classForName(String name)
+ {
+
+ try
+ {
+ if (Thread.currentThread().getContextClassLoader() != null)
+ {
+ return Thread.currentThread().getContextClassLoader().loadClass(name);
+ }
+ else
+ {
+ return Class.forName(name);
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ catch (NoClassDefFoundError e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ }
+
+ public URL getResource(String name)
+ {
+ if (Thread.currentThread().getContextClassLoader() != null)
+ {
+ return Thread.currentThread().getContextClassLoader().getResource(name);
+ }
+ else
+ {
+ return getClass().getResource(name);
+ }
+ }
+
+ public Iterable<URL> getResources(String name)
+ {
+ try
+ {
+ if (Thread.currentThread().getContextClassLoader() != null)
+ {
+ return new EnumerationIterable<URL>(Thread.currentThread().getContextClassLoader().getResources(name));
+ }
+ else
+ {
+ return new EnumerationIterable<URL>(getClass().getClassLoader().getResources(name));
+ }
+ }
+ catch (IOException e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ }
+
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/util/EnumerationEnumeration.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/util/EnumerationEnumeration.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/util/EnumerationEnumeration.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,85 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.util;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+
+public class EnumerationEnumeration<T>
+ implements Enumeration<T>
+{
+ private Enumeration<T>[] enumerations;
+ private int loc = 0;
+
+ public EnumerationEnumeration( Enumeration<T>[] enumerations )
+ {
+ this.enumerations = enumerations;
+ }
+
+ public boolean hasMoreElements( )
+ {
+ for ( int i = loc; i < enumerations.length; i++ )
+ {
+ if ( enumerations[i].hasMoreElements( ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public T nextElement( )
+ {
+ while ( isCurrentEnumerationAvailable( ) )
+ {
+ if ( currentHasMoreElements( ) )
+ {
+ return currentNextElement( );
+ } else
+ {
+ nextEnumeration( );
+ }
+ }
+
+ throw new NoSuchElementException( );
+ }
+
+ private void nextEnumeration( )
+ {
+ loc++;
+ }
+
+ /*private boolean isNextEnumerationAvailable()
+ {
+ return loc < enumerations.length-1;
+ }*/
+ private boolean isCurrentEnumerationAvailable( )
+ {
+ return loc < enumerations.length;
+ }
+
+ private T currentNextElement( )
+ {
+ return enumerations[loc].nextElement( );
+ }
+
+ private boolean currentHasMoreElements( )
+ {
+ return enumerations[loc].hasMoreElements( );
+ }
+}
Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/lifecycle/ApplicationLifecycle.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/lifecycle/ApplicationLifecycle.java (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/lifecycle/ApplicationLifecycle.java 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,85 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.lifecycle;
+
+import org.jboss.webbeans.CurrentManager;
+import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.context.ApplicationContext;
+import org.jboss.webbeans.context.DependentContext;
+import org.jboss.webbeans.context.beanmap.BeanMap;
+import org.jboss.webbeans.environment.se.events.Shutdown;
+import org.jboss.webbeans.log.Log;
+import org.jboss.webbeans.log.Logging;
+
+/**
+ * Implements the lifecycle methods for a WebBeans SE application.
+ * @author Peter Royle
+ */
+public class ApplicationLifecycle
+{
+
+ private static ApplicationLifecycle instance;
+ Log log = Logging.getLog( ApplicationLifecycle.class );
+
+
+ static
+ {
+ instance = new ApplicationLifecycle();
+ }
+
+ public static ApplicationLifecycle instance()
+ {
+ return instance;
+ }
+
+ public void initialize()
+ {
+ ManagerImpl manager = CurrentManager.rootManager();
+ if (manager == null)
+ {
+ throw new IllegalStateException( "Manager has not been initialized, " +
+ "check that Bootstrap.initialize() has run" );
+ }
+ manager.addContext( DependentContext.create() );
+ manager.addContext( ApplicationContext.create() );
+ }
+
+ public void beginApplication( String id, BeanMap applicationBeanMap )
+ {
+ log.trace( "Starting application " + id );
+ ApplicationContext.INSTANCE.setBeanMap( applicationBeanMap );
+ ApplicationContext.INSTANCE.setActive( true );
+ // TODO (PR): I have no idea if this is OK??? The WB spec says that the
+ // dependant scoe is only active when the manager is doing its work.
+ // This leaves it open for the whole duration. I guess that's about
+ // right since the main bean is in the dependant scope?
+ DependentContext.INSTANCE.setActive( true );
+ }
+
+ public void endApplication( String id, BeanMap applicationBeanMap )
+ {
+ log.trace( "Ending application " + id );
+
+ // Give apps and modules a chance to shutdown cleanly
+ CurrentManager.rootManager().fireEvent( new Shutdown() );
+
+ ApplicationContext.INSTANCE.destroy();
+ ApplicationContext.INSTANCE.setActive( false );
+ ApplicationContext.INSTANCE.setBeanMap( null );
+
+ }
+}
Added: extensions/trunk/se/src/main/resources/beans.xml
===================================================================
--- extensions/trunk/se/src/main/resources/beans.xml (rev 0)
+++ extensions/trunk/se/src/main/resources/beans.xml 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,19 @@
+<!--
+
+ JBoss, Home of Professional Open Source
+ Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ by the @authors tag. See the copyright.txt in the distribution for a
+ full listing of individual contributors.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<beans></beans>
Added: extensions/trunk/se/src/main/resources/log4j.properties
===================================================================
--- extensions/trunk/se/src/main/resources/log4j.properties (rev 0)
+++ extensions/trunk/se/src/main/resources/log4j.properties 2009-02-24 00:11:39 UTC (rev 1666)
@@ -0,0 +1,25 @@
+#
+# JBoss, Home of Professional Open Source
+# Copyright 2008, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Set root logger level to DEBUG and its only appender to A1.
+log4j.rootLogger=TRACE, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
More information about the weld-commits
mailing list