You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2016/09/15 18:09:26 UTC
svn commit: r1760967 [1/2] - in /myfaces/trinidad/branches/trinidad-2.0.x:
./ trinidad-assembly/ trinidad-examples/
trinidad-examples/trinidad-example-assembly/ trinidad-impl/
trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/co...
Author: lu4242
Date: Thu Sep 15 18:09:25 2016
New Revision: 1760967
URL: http://svn.apache.org/viewvc?rev=1760967&view=rev
Log:
Standardize state saving
Added:
myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassLoaderUtils.java (with props)
myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassUtils.java (with props)
myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/MyFacesObjectInputStream.java (with props)
myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/StateUtils.java (with props)
myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/serial/
myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/serial/DefaultSerialFactory.java (with props)
myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/serial/SerialFactory.java (with props)
Modified:
myfaces/trinidad/branches/trinidad-2.0.x/pom.xml
myfaces/trinidad/branches/trinidad-2.0.x/trinidad-assembly/pom.xml
myfaces/trinidad/branches/trinidad-2.0.x/trinidad-examples/pom.xml
myfaces/trinidad/branches/trinidad-2.0.x/trinidad-examples/trinidad-example-assembly/pom.xml
myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/pom.xml
myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreResponseStateManager.java
Modified: myfaces/trinidad/branches/trinidad-2.0.x/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/pom.xml?rev=1760967&r1=1760966&r2=1760967&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/pom.xml (original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/pom.xml Thu Sep 15 18:09:25 2016
@@ -26,10 +26,10 @@ Build:
mvn3 clean install
Prepare Release
- mvn3 release:prepare
+ mvn3 release:prepare -DprepareRelease=true
Perform Release
- mvn3 release:perform
+ mvn3 release:perform -DperformRelease=true
Change Version Number (http://maven.apache.org/plugins/maven-release-plugin/examples/update-versions.html)
mvn3 release:update-versions
@@ -45,13 +45,13 @@ Create A Branch (http://maven.apache.org
<name>Apache MyFaces Trinidad 2.0</name>
<description>Apache MyFaces Trinidad for JSF 2.0</description>
- <url>http://myfaces.apache.org/trinidad/trinidad-1_2</url>
+ <url>http://myfaces.apache.org/trinidad/trinidad-2_0</url>
<inceptionYear>2001</inceptionYear>
<parent>
<groupId>org.apache.myfaces</groupId>
<artifactId>myfaces</artifactId>
- <version>11</version>
+ <version>16</version>
</parent>
<groupId>org.apache.myfaces.trinidad</groupId>
@@ -73,6 +73,8 @@ Create A Branch (http://maven.apache.org
<portlet-bridge.version>2.0.0</portlet-bridge.version>
<commons-lang.version>2.4</commons-lang.version>
<commons-io.version>2.0</commons-io.version>
+ <commons-codec.version>1.3</commons-codec.version>
+
<pluto-embedded.version>1.0.1</pluto-embedded.version>
<!-- Testing -->
@@ -94,7 +96,18 @@ Create A Branch (http://maven.apache.org
<!-- Other -->
<jdev.release>11.1.1.0.0</jdev.release>
- <myfaces-builder-annotations.version>1.0.8</myfaces-builder-annotations.version>
+ <myfaces-builder-annotations.version>1.0.9</myfaces-builder-annotations.version>
+
+ <!-- Site deployment -->
+ <siteModule.path>trinidad-2.0</siteModule.path>
+ <site.mainDirectory>${user.home}/myfaces-site/checkout</site.mainDirectory>
+ <siteContent.path>${user.home}/myfaces-site/site/${siteModule.path}</siteContent.path>
+ <!-- it's a default location for performance reason (not checkout the content all the time)
+ you can override this value in your settings. -->
+ <scmCheckout.path>\${site.mainDirectory}/${siteModule.path}</scmCheckout.path>
+ <siteDeploy.url>file://${user.home}/myfaces-site/site/${siteModule.path}</siteDeploy.url>
+ <siteScmPublish.url>scm:svn:https://svn.apache.org/repos/asf/myfaces/site/publish/</siteScmPublish.url>
+
</properties>
<issueManagement>
@@ -170,7 +183,8 @@ Create A Branch (http://maven.apache.org
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/myfaces/trinidad/branches/trinidad-2.0.x</developerConnection>
<url>http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x</url>
</scm>
-
+
+ <!--
<distributionManagement>
<site>
<id>apache-site</id>
@@ -178,6 +192,14 @@ Create A Branch (http://maven.apache.org
<url>scp://minotaur.apache.org/www/myfaces.apache.org/trinidad</url>
</site>
</distributionManagement>
+ -->
+ <distributionManagement>
+ <site>
+ <id>myfaces-local-staging</id>
+ <name>Apache Website</name>
+ <url>scp://localhost/${user.home}/myfaces-site/${siteModule.path}</url>
+ </site>
+ </distributionManagement>
<dependencyManagement>
<dependencies>
@@ -273,6 +295,12 @@ Create A Branch (http://maven.apache.org
</dependency>
<dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>${commons-codec.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.myfaces.buildtools</groupId>
<artifactId>myfaces-builder-annotations</artifactId>
<version>${myfaces-builder-annotations.version}</version>
@@ -355,11 +383,21 @@ Create A Branch (http://maven.apache.org
</modules>
<build>
+
+ <!-- Since Maven 3.0, this is required to add scpexe as protocol for deploy. -->
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-ssh-external</artifactId>
+ <version>1.0-beta-7</version>
+ </extension>
+ </extensions>
+
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-site-plugin</artifactId>
- <version>3.0</version>
+ <version>3.3</version>
<inherited>true</inherited>
<dependencies>
<dependency>
@@ -369,6 +407,8 @@ Create A Branch (http://maven.apache.org
</dependency>
</dependencies>
<configuration>
+ <stagingRepositoryId>myfaces-local-staging</stagingRepositoryId>
+ <stagingSiteURL>${siteDeploy.url}</stagingSiteURL>
<outputEncoding>UTF-8</outputEncoding>
<reportPlugins>
<!--plugin>
@@ -410,6 +450,7 @@ Create A Branch (http://maven.apache.org
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
+ <version>2.17</version>
<inherited>true</inherited>
<configuration>
<parallel>true</parallel>
@@ -581,6 +622,24 @@ Create A Branch (http://maven.apache.org
<version>2.8</version>
</plugin>
+ <!-- Begin dependency fix for .md5 and .sha1 -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <version>2.5.3</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-gpg-plugin</artifactId>
+ <version>1.6</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ </plugin>
+ <!-- End -->
+
</plugins>
</pluginManagement>
@@ -699,6 +758,19 @@ Create A Branch (http://maven.apache.org
</excludes>
</configuration>
</plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-scm-publish-plugin</artifactId>
+ <version>1.0-beta-2</version>
+ <configuration>
+ <pubScmUrl>${siteScmPublish.url}</pubScmUrl>
+ <tryUpdate>true</tryUpdate>
+ <checkoutDirectory>${scmCheckout.path}</checkoutDirectory>
+ <content>\${siteContent.path}</content>
+ </configuration>
+ </plugin>
+
</plugins>
</build>
@@ -761,6 +833,7 @@ Create A Branch (http://maven.apache.org
NOTE that for the maven lifecycle invoked by the release plugin, -Papache-release will
be added automatically because of the config in apache-parent-7.
-->
+ <!--
<profile>
<id>apache-release</id>
@@ -784,6 +857,51 @@ Create A Branch (http://maven.apache.org
</plugins>
</build>
</profile>
+ -->
+
+ <profile>
+ <id>prepare-release</id>
+ <activation>
+ <property>
+ <name>prepareRelease</name>
+ </property>
+ </activation>
+ <modules>
+ <module>trinidad-assembly</module>
+ </modules>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-release-plugin</artifactId>
+ <configuration>
+ <arguments>-DprepareRelease</arguments>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>perform-release</id>
+ <activation>
+ <property>
+ <name>performRelease</name>
+ <value>true</value>
+ </property>
+ </activation>
+ <modules>
+ <module>trinidad-assembly</module>
+ </modules>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-release-plugin</artifactId>
+ <configuration>
+ <arguments>-Papache-release -DperformRelease</arguments>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
<profile>
<id>enableRat</id>
Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-assembly/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-assembly/pom.xml?rev=1760967&r1=1760966&r2=1760967&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-assembly/pom.xml (original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-assembly/pom.xml Thu Sep 15 18:09:25 2016
@@ -94,7 +94,6 @@
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
- <version>2.2</version>
<executions>
<execution>
<id>make_assembly_trinidad</id>
@@ -102,8 +101,11 @@
<descriptors>
<descriptor>src/main/assembly/dep.xml</descriptor>
</descriptors>
- <appendAssemblyId>true</appendAssemblyId> <!-- adds "-bin" and "-src" -->
+ <finalName>trinidad-assembly-${project.version}-dist</finalName>
+ <appendAssemblyId>false</appendAssemblyId> <!-- adds "-bin" and "-src" -->
<tarLongFileMode>gnu</tarLongFileMode>
+ <outputDirectory>target/assembly/out</outputDirectory>
+ <workDirectory>target/assembly/work</workDirectory>
</configuration>
<phase>package</phase>
<goals>
@@ -112,6 +114,35 @@
</execution>
</executions>
</plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.5</version>
+ <executions>
+ <execution>
+ <id>attach-artifacts</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attach-artifact</goal>
+ </goals>
+ <configuration>
+ <artifacts>
+ <artifact>
+ <file>target/assembly/out/trinidad-assembly-${project.version}-dist.zip</file>
+ <type>zip</type>
+ <classifier>dist</classifier>
+ </artifact>
+ <artifact>
+ <file>target/assembly/out/trinidad-assembly-${project.version}-dist.tar.gz</file>
+ <type>tar.gz</type>
+ <classifier>dist</classifier>
+ </artifact>
+ </artifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-examples/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-examples/pom.xml?rev=1760967&r1=1760966&r2=1760967&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-examples/pom.xml (original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-examples/pom.xml Thu Sep 15 18:09:25 2016
@@ -121,12 +121,58 @@
NOTE: the apache-release profile is invoked on any execution of the maven-release-plugin
as per the apache-10 common ancestor file.
-->
+ <!--
<profile>
<id>apache-release</id>
<modules>
<module>trinidad-example-assembly</module>
</modules>
</profile>
+ -->
+ <profile>
+ <id>prepare-release</id>
+ <activation>
+ <property>
+ <name>prepareRelease</name>
+ </property>
+ </activation>
+ <modules>
+ <module>trinidad-example-assembly</module>
+ </modules>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-release-plugin</artifactId>
+ <configuration>
+ <arguments>-DprepareRelease</arguments>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>perform-release</id>
+ <activation>
+ <property>
+ <name>performRelease</name>
+ <value>true</value>
+ </property>
+ </activation>
+ <modules>
+ <module>trinidad-example-assembly</module>
+ </modules>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-release-plugin</artifactId>
+ <configuration>
+ <arguments>-Papache-release -DperformRelease</arguments>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
<!--
This profile activates MyFaces as the release to use for these demos. By default
Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-examples/trinidad-example-assembly/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-examples/trinidad-example-assembly/pom.xml?rev=1760967&r1=1760966&r2=1760967&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-examples/trinidad-example-assembly/pom.xml (original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-examples/trinidad-example-assembly/pom.xml Thu Sep 15 18:09:25 2016
@@ -28,6 +28,7 @@
<groupId>org.apache.myfaces.trinidad</groupId>
<artifactId>trinidad</artifactId>
<version>2.0.2-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>trinidad-example-assembly</artifactId>
@@ -111,6 +112,35 @@
</execution>
</executions>
</plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.5</version>
+ <executions>
+ <execution>
+ <id>attach-artifacts</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attach-artifact</goal>
+ </goals>
+ <configuration>
+ <artifacts>
+ <artifact>
+ <file>target/trinidad-example-assembly-${project.version}-example.zip</file>
+ <type>zip</type>
+ <classifier>example</classifier>
+ </artifact>
+ <artifact>
+ <file>target/trinidad-example-assembly-${project.version}-example.tar.gz</file>
+ <type>tar.gz</type>
+ <classifier>example</classifier>
+ </artifact>
+ </artifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/pom.xml?rev=1760967&r1=1760966&r2=1760967&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/pom.xml (original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/pom.xml Thu Sep 15 18:09:25 2016
@@ -86,6 +86,12 @@
<groupId>org.apache.myfaces.trinidad</groupId>
<artifactId>trinidad-api</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <scope>compile</scope>
+ </dependency>
<!--dependency>
<groupId>com.sun.facelets</groupId>
Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreResponseStateManager.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreResponseStateManager.java?rev=1760967&r1=1760966&r2=1760967&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreResponseStateManager.java (original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreResponseStateManager.java Thu Sep 15 18:09:25 2016
@@ -18,20 +18,9 @@
*/
package org.apache.myfaces.trinidadinternal.renderkit.core;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamClass;
-import java.io.OptionalDataException;
-import java.io.StringReader;
-import java.io.StringWriter;
import java.util.Map;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.GZIPOutputStream;
import javax.faces.FacesException;
import javax.faces.application.StateManager;
@@ -41,11 +30,8 @@ import javax.faces.context.ResponseWrite
import javax.faces.render.ResponseStateManager;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
-import org.apache.myfaces.trinidad.util.Base64InputStream;
-import org.apache.myfaces.trinidad.util.Base64OutputStream;
-import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
import org.apache.myfaces.trinidadinternal.application.StateManagerImpl;
-import org.apache.myfaces.trinidadinternal.util.ObjectInputStreamResolveClass;
+import org.apache.myfaces.trinidadinternal.util.StateUtils;
/**
* ResponseStateManager implementation for the Core RenderKit.
@@ -94,7 +80,7 @@ public class CoreResponseStateManager ex
// out twice
// rw.writeAttribute("id", VIEW_STATE_PARAM, null);
- String s = encodeSerializedViewAsString(serializedView);
+ String s = encodeSerializedViewAsString(context, serializedView);
rw.writeAttribute("value", s, null);
rw.endElement("input");
@@ -111,13 +97,16 @@ public class CoreResponseStateManager ex
}
- protected String encodeSerializedViewAsString(
+ protected String encodeSerializedViewAsString(FacesContext context,
StateManager.SerializedView serializedView) throws IOException
{
if ((serializedView.getState() == null) &&
(serializedView.getStructure() instanceof String))
- return _TOKEN_PREFIX + serializedView.getStructure();
+ return _TOKEN_PREFIX + StateUtils.construct(serializedView.getStructure(), context.getExternalContext());
+ return StateUtils.construct(
+ new Object[]{serializedView.getStructure(),serializedView.getState()}, context.getExternalContext());
+ /*
StringWriter sw = new StringWriter();
BufferedWriter bw = new BufferedWriter(sw);
Base64OutputStream b64_out = new Base64OutputStream(bw);
@@ -136,7 +125,7 @@ public class CoreResponseStateManager ex
String retVal = sw.toString();
assert(!retVal.startsWith(_TOKEN_PREFIX));
- return retVal;
+ return retVal;*/
}
@Override
@@ -166,7 +155,7 @@ public class CoreResponseStateManager ex
StateManager.SerializedView serializedView = _getSerializedView(context, state);
try
{
- return encodeSerializedViewAsString(serializedView);
+ return encodeSerializedViewAsString(context, serializedView);
}
catch (IOException e)
{
@@ -271,13 +260,15 @@ public class CoreResponseStateManager ex
if (tokenString != null)
{
- view = new Object[]{tokenString, null};
+ view = new Object[]{StateUtils.reconstruct(tokenString, context.getExternalContext()), null};
}
// Nope, let's look for a regular state field
else
{
if (stateString != null)
{
+ view = (Object[]) StateUtils.reconstruct(stateString, context.getExternalContext());
+ /*
StringReader sr = new StringReader(stateString);
BufferedReader br = new BufferedReader(sr);
Base64InputStream b64_in = new Base64InputStream(br);
@@ -305,6 +296,7 @@ public class CoreResponseStateManager ex
{
_LOG.severe(ioe);
}
+ */
}
}
Added: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassLoaderUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassLoaderUtils.java?rev=1760967&view=auto
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassLoaderUtils.java (added)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassLoaderUtils.java Thu Sep 15 18:09:25 2016
@@ -0,0 +1,394 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.myfaces.trinidadinternal.util;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.IOException;
+
+import java.io.InputStreamReader;
+
+import java.net.URL;
+
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.FacesException;
+
+/**
+ * Utility methods for accessing classes and resources using an appropriate
+ * class loader.
+ *
+ * @version $Revision$ $Date$
+ */
+public final class ClassLoaderUtils
+{
+ // Utility class only, no instances
+ private ClassLoaderUtils()
+ {
+ }
+
+ /**
+ * Loads the class with the specified name. For Java 2 callers, the
+ * current thread's context class loader is preferred, falling back on the
+ * system class loader of the caller when the current thread's context is not
+ * set, or the caller is pre Java 2.
+ *
+ * @param name the name of the class
+ * @return the resulting <code>Class</code> object
+ * @exception ClassNotFoundException if the class was not found
+ */
+ public static Class<?> loadClass(
+ String name) throws ClassNotFoundException
+ {
+ return loadClass(name, null);
+ }
+
+ /**
+ * Locates the resource with the specified name. For Java 2 callers, the
+ * current thread's context class loader is preferred, falling back on the
+ * system class loader of the caller when the current thread's context is not
+ * set, or the caller is pre Java 2.
+ *
+ * @param name the name of the resource
+ * @return the resulting <code>URL</code> object
+ */
+ public static URL getResource(
+ String name)
+ {
+ return getResource(name, null);
+ }
+
+ /**
+ * Locates the stream resource with the specified name. For Java 2 callers,
+ * the current thread's context class loader is preferred, falling back on
+ * the system class loader of the caller when the current thread's context is
+ * not set, or the caller is pre Java 2.
+ *
+ * @param name the name of the resource
+ * @return the resulting <code>InputStream</code> object
+ */
+ public static InputStream getResourceAsStream(
+ String name)
+ {
+ return getResourceAsStream(name, null);
+ }
+
+ /**
+ * Loads the class with the specified name. For Java 2 callers, the
+ * current thread's context class loader is preferred, falling back on the
+ * class loader of the caller when the current thread's context is not set,
+ * or the caller is pre Java 2. If the callerClassLoader is null, then
+ * fall back on the system class loader.
+ *
+ * @param name the name of the class
+ * @param callerClassLoader the calling class loader context
+ * @return the resulting <code>Class</code> object
+ * @exception ClassNotFoundException if the class was not found
+ */
+ public static Class<?> loadClass(
+ String name,
+ ClassLoader callerClassLoader) throws ClassNotFoundException
+ {
+ Class<?> clazz = null;
+
+ try
+ {
+ ClassLoader loader = getContextClassLoader();
+
+ if (loader != null)
+ {
+ clazz = loader.loadClass(name);
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ // treat as though loader not set
+ }
+
+ if (clazz == null)
+ {
+ if (callerClassLoader != null)
+ {
+ clazz = callerClassLoader.loadClass(name);
+ }
+ else
+ {
+ clazz = Class.forName(name);
+ }
+ }
+
+ return clazz;
+ }
+
+ /**
+ * Locates the resource with the specified name. For Java 2 callers, the
+ * current thread's context class loader is preferred, falling back on the
+ * class loader of the caller when the current thread's context is not set,
+ * or the caller is pre Java 2. If the callerClassLoader is null, then
+ * fall back on the system class loader.
+ *
+ * @param name the name of the resource
+ * @param callerClassLoader the calling class loader context
+ * @return the resulting <code>URL</code> object
+ */
+ public static URL getResource(
+ String name,
+ ClassLoader callerClassLoader)
+ {
+ _checkResourceName(name);
+
+ URL url = null;
+
+ ClassLoader loader = getContextClassLoader();
+
+ if (loader != null)
+ {
+ url = loader.getResource(name);
+ }
+
+ if (url == null)
+ {
+ if (callerClassLoader != null)
+ {
+ url = callerClassLoader.getResource(name);
+ }
+ else
+ {
+ url = ClassLoader.getSystemResource(name);
+ }
+ }
+
+ return url;
+ }
+
+ /**
+ * Locates the resource stream with the specified name. For Java 2 callers,
+ * the current thread's context class loader is preferred, falling back on
+ * the class loader of the caller when the current thread's context is not
+ * set, or the caller is pre Java 2. If the callerClassLoader is null, then
+ * fall back on the system class loader.
+ *
+ * @param name the name of the resource
+ * @param callerClassLoader the calling class loader context
+ * @return the resulting <code>InputStream</code> object
+ */
+ public static InputStream getResourceAsStream(
+ String name,
+ ClassLoader callerClassLoader)
+ {
+ _checkResourceName(name);
+
+ InputStream stream = null;
+
+ ClassLoader loader = getContextClassLoader();
+
+ if (loader != null)
+ {
+ stream = loader.getResourceAsStream(name);
+ }
+
+ if (stream == null)
+ {
+ if (callerClassLoader != null)
+ {
+ stream = callerClassLoader.getResourceAsStream(name);
+ }
+ else
+ {
+ stream = ClassLoader.getSystemResourceAsStream(name);
+ }
+ }
+
+ return stream;
+ }
+
+ /**
+ * Dynamically accesses the current context class loader.
+ * Includes a check for priviledges against java2 security
+ * to ensure no security related exceptions are encountered.
+ * Returns null if there is no per-thread context class loader.
+ */
+ public static ClassLoader getContextClassLoader()
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ ClassLoader cl = AccessController.doPrivileged(new PrivilegedExceptionAction<ClassLoader>()
+ {
+ public ClassLoader run() throws PrivilegedActionException
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ return cl;
+ }
+ catch (PrivilegedActionException pae)
+ {
+ throw new FacesException(pae);
+ }
+ }
+ else
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ }
+
+ /**
+ * Instantiate a service from a file in /META-INF/services.
+ * <P>
+ * The following is an excerpt from the JAR File specification:
+ * A service provider identifies itself by placing a provider-configuration file
+ * in the resource directory META-INF/services.
+ * The file's name should consist of the fully-qualified name of the abstract service class.
+ * The file should contain a newline-separated list of unique concrete provider-class names.
+ * Space and tab characters, as well as blank lines, are ignored. The comment character is '#' (0x23);
+ * on each line all characters following the first comment character are ignored.
+ * The file must be encoded in UTF-8.
+ *
+ * @param service the classname of the abstract service class.
+ * eg: javax.servlet.Filter
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> List<T> getServices(String service)
+ {
+ String serviceUri ="META-INF/services/" + service;
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Enumeration<URL> urls = loader.getResources(serviceUri);
+ if (urls.hasMoreElements())
+ {
+ List<T> services = new ArrayList<T>(1);
+ Set<String> keys = new HashSet<String>(20);
+ do
+ {
+ URL url = urls.nextElement();
+
+ if (_LOG.isLoggable(Level.FINEST))
+ {
+ _LOG.finest("Processing: " + url);
+ }
+ try
+ {
+ BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
+ try
+ {
+ while(true)
+ {
+ String line = in.readLine();
+ if (line == null)
+ {
+ break;
+ }
+
+ String className = _parseLine(line);
+
+ if(className!=null && keys.add(className))
+ {
+ T instance = (T) _getClass(loader, className);
+ services.add(instance);
+ }
+ }
+ }
+ finally
+ {
+ in.close();
+ }
+ }
+ catch (Exception e)
+ {
+ if (_LOG.isLoggable(Level.WARNING))
+ {
+ _LOG.log(Level.WARNING, "Error parsing URL: " + url, e);
+ }
+ }
+ }
+ while(urls.hasMoreElements());
+
+ if (services.size() == 1)
+ {
+ return Collections.singletonList(services.get(0));
+ }
+
+ return Collections.unmodifiableList(services);
+ }
+ }
+ catch (IOException e)
+ {
+ if (_LOG.isLoggable(Level.SEVERE))
+ {
+ _LOG.log(Level.SEVERE, "Error loading Resource: " + serviceUri, e);
+ }
+ }
+
+ return Collections.emptyList();
+ }
+
+ private static String _parseLine(String line)
+ {
+ // Eliminate any comments
+ int hashIndex = line.indexOf('#');
+ if (hashIndex >= 0)
+ {
+ line = line.substring(0, hashIndex);
+ }
+
+ // and any whitespace
+ line = line.trim();
+ if (line.length() > 0)
+ {
+ return line;
+ }
+
+ return null;
+ }
+
+ private static Object _getClass(ClassLoader loader, String className)
+ throws ClassNotFoundException, InstantiationException,
+ IllegalAccessException
+ {
+ Class<?> clazz = loader.loadClass(className);
+ return clazz.newInstance();
+ }
+
+ private static void _checkResourceName(String name)
+ {
+ if ((name != null) && name.startsWith("/"))
+ {
+ if (_LOG.isLoggable(Level.WARNING))
+ {
+ _LOG.log(Level.WARNING, "Resource name not portable: " +name);
+ }
+ }
+ }
+
+ private static final Logger _LOG = Logger.getLogger(ClassLoaderUtils.class.getName());
+}
Propchange: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassLoaderUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassLoaderUtils.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassUtils.java?rev=1760967&view=auto
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassUtils.java (added)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassUtils.java Thu Sep 15 18:09:25 2016
@@ -0,0 +1,661 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.myfaces.trinidadinternal.util;
+
+import javax.el.ExpressionFactory;
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+public final class ClassUtils
+{
+ //~ Static fields/initializers -----------------------------------------------------------------
+
+ //private static final Log log = LogFactory.getLog(ClassUtils.class);
+ private static final Logger log = Logger.getLogger(ClassUtils.class.getName());
+
+ public static final Class BOOLEAN_ARRAY_CLASS = boolean[].class;
+ public static final Class BYTE_ARRAY_CLASS = byte[].class;
+ public static final Class CHAR_ARRAY_CLASS = char[].class;
+ public static final Class SHORT_ARRAY_CLASS = short[].class;
+ public static final Class INT_ARRAY_CLASS = int[].class;
+ public static final Class LONG_ARRAY_CLASS = long[].class;
+ public static final Class FLOAT_ARRAY_CLASS = float[].class;
+ public static final Class DOUBLE_ARRAY_CLASS = double[].class;
+ public static final Class OBJECT_ARRAY_CLASS = Object[].class;
+ public static final Class BOOLEAN_OBJECT_ARRAY_CLASS = Boolean[].class;
+ public static final Class BYTE_OBJECT_ARRAY_CLASS = Byte[].class;
+ public static final Class CHARACTER_OBJECT_ARRAY_CLASS = Character[].class;
+ public static final Class SHORT_OBJECT_ARRAY_CLASS = Short[].class;
+ public static final Class INTEGER_OBJECT_ARRAY_CLASS = Integer[].class;
+ public static final Class LONG_OBJECT_ARRAY_CLASS = Long[].class;
+ public static final Class FLOAT_OBJECT_ARRAY_CLASS = Float[].class;
+ public static final Class DOUBLE_OBJECT_ARRAY_CLASS = Double[].class;
+ public static final Class STRING_OBJECT_ARRAY_CLASS = String[].class;
+
+ //public static ClassLoaderExtension [] classLoadingExtensions = new ClassLoaderExtension[0];
+
+
+
+ public static final Map COMMON_TYPES = new HashMap(64);
+ static
+ {
+ COMMON_TYPES.put("byte", Byte.TYPE);
+ COMMON_TYPES.put("char", Character.TYPE);
+ COMMON_TYPES.put("double", Double.TYPE);
+ COMMON_TYPES.put("float", Float.TYPE);
+ COMMON_TYPES.put("int", Integer.TYPE);
+ COMMON_TYPES.put("long", Long.TYPE);
+ COMMON_TYPES.put("short", Short.TYPE);
+ COMMON_TYPES.put("boolean", Boolean.TYPE);
+ COMMON_TYPES.put("void", Void.TYPE);
+ COMMON_TYPES.put("java.lang.Object", Object.class);
+ COMMON_TYPES.put("java.lang.Boolean", Boolean.class);
+ COMMON_TYPES.put("java.lang.Byte", Byte.class);
+ COMMON_TYPES.put("java.lang.Character", Character.class);
+ COMMON_TYPES.put("java.lang.Short", Short.class);
+ COMMON_TYPES.put("java.lang.Integer", Integer.class);
+ COMMON_TYPES.put("java.lang.Long", Long.class);
+ COMMON_TYPES.put("java.lang.Float", Float.class);
+ COMMON_TYPES.put("java.lang.Double", Double.class);
+ COMMON_TYPES.put("java.lang.String", String.class);
+
+ COMMON_TYPES.put("byte[]", BYTE_ARRAY_CLASS);
+ COMMON_TYPES.put("char[]", CHAR_ARRAY_CLASS);
+ COMMON_TYPES.put("double[]", DOUBLE_ARRAY_CLASS);
+ COMMON_TYPES.put("float[]", FLOAT_ARRAY_CLASS);
+ COMMON_TYPES.put("int[]", INT_ARRAY_CLASS);
+ COMMON_TYPES.put("long[]", LONG_ARRAY_CLASS);
+ COMMON_TYPES.put("short[]", SHORT_ARRAY_CLASS);
+ COMMON_TYPES.put("boolean[]", BOOLEAN_ARRAY_CLASS);
+ COMMON_TYPES.put("java.lang.Object[]", OBJECT_ARRAY_CLASS);
+ COMMON_TYPES.put("java.lang.Boolean[]", BOOLEAN_OBJECT_ARRAY_CLASS);
+ COMMON_TYPES.put("java.lang.Byte[]", BYTE_OBJECT_ARRAY_CLASS);
+ COMMON_TYPES.put("java.lang.Character[]", CHARACTER_OBJECT_ARRAY_CLASS);
+ COMMON_TYPES.put("java.lang.Short[]", SHORT_OBJECT_ARRAY_CLASS);
+ COMMON_TYPES.put("java.lang.Integer[]", INTEGER_OBJECT_ARRAY_CLASS);
+ COMMON_TYPES.put("java.lang.Long[]", LONG_OBJECT_ARRAY_CLASS);
+ COMMON_TYPES.put("java.lang.Float[]", FLOAT_OBJECT_ARRAY_CLASS);
+ COMMON_TYPES.put("java.lang.Double[]", DOUBLE_OBJECT_ARRAY_CLASS);
+ COMMON_TYPES.put("java.lang.String[]", STRING_OBJECT_ARRAY_CLASS);
+ // array of void is not a valid type
+ }
+
+ /** utility class, do not instantiate */
+ private ClassUtils()
+ {
+ // utility class, disable instantiation
+ }
+
+ //~ Methods ------------------------------------------------------------------------------------
+
+ /*
+ public synchronized static void addClassLoadingExtension(ClassLoaderExtension extension, boolean top)
+ {
+ /**
+ * now at the first look this looks somewhat strange
+ * but to get the best performance access we assign new native
+ * arrays to our static variable
+ *
+ * we have to synchronized nevertheless because if two threads try to register
+ * loaders at the same time none of them should get lost
+ */
+ /*
+ ClassLoaderExtension [] retVal = new ClassLoaderExtension[classLoadingExtensions.length+1];
+ ArrayList extensions = new ArrayList(classLoadingExtensions.length+1);
+
+ if(!top)
+ {
+ extensions.addAll(Arrays.asList(classLoadingExtensions));
+ }
+ extensions.add(extension);
+ if(top)
+ {
+ extensions.addAll(Arrays.asList(classLoadingExtensions));
+ }
+
+ classLoadingExtensions = (ClassLoaderExtension []) extensions.toArray(retVal);
+ }*/
+
+ /**
+ * Tries a Class.loadClass with the context class loader of the current thread first and
+ * automatically falls back to the ClassUtils class loader (i.e. the loader of the
+ * myfaces.jar lib) if necessary.
+ *
+ * @param type fully qualified name of a non-primitive non-array class
+ * @return the corresponding Class
+ * @throws NullPointerException if type is null
+ * @throws ClassNotFoundException
+ */
+ public static Class classForName(String type)
+ throws ClassNotFoundException
+ {
+ //we now assign the array to safekeep the reference on
+ // the local variable stack, that way
+ //we can avoid synchronisation calls
+ /*
+ ClassLoaderExtension [] loaderPlugins = classLoadingExtensions;
+
+ int plugins = loaderPlugins.length;
+ for(int cnt = 0; cnt < loaderPlugins.length; cnt ++)
+ {
+ ClassLoaderExtension extension = loaderPlugins[cnt];
+ Class retVal = extension.forName(type);
+ if(retVal != null)
+ {
+ return retVal;
+ }
+ }
+ */
+
+ if (type == null)
+ {
+ throw new NullPointerException("type");
+ }
+ try
+ {
+ // Try WebApp ClassLoader first
+ return Class.forName(type,
+ false, // do not initialize for faster startup
+ getContextClassLoader());
+ }
+ catch (ClassNotFoundException ignore)
+ {
+ // fallback: Try ClassLoader for ClassUtils (i.e. the myfaces.jar lib)
+ return Class.forName(type,
+ false, // do not initialize for faster startup
+ ClassUtils.class.getClassLoader());
+ }
+ }
+
+
+ /**
+ * Same as {@link #classForName(String)}, but throws a RuntimeException
+ * (FacesException) instead of a ClassNotFoundException.
+ *
+ * @return the corresponding Class
+ * @throws NullPointerException if type is null
+ * @throws FacesException if class not found
+ */
+ public static Class simpleClassForName(String type)
+ {
+ try
+ {
+ return classForName(type);
+ }
+ catch (ClassNotFoundException e)
+ {
+ log.log(Level.SEVERE, "Class " + type + " not found", e);
+ throw new FacesException(e);
+ }
+ }
+
+
+ /**
+ * Similar as {@link #classForName(String)}, but also supports primitive types
+ * and arrays as specified for the JavaType element in the JavaServer Faces Config DTD.
+ *
+ * @param type fully qualified class name or name of a primitive type, both optionally
+ * followed by "[]" to indicate an array type
+ * @return the corresponding Class
+ * @throws NullPointerException if type is null
+ * @throws ClassNotFoundException
+ */
+ public static Class javaTypeToClass(String type)
+ throws ClassNotFoundException
+ {
+ if (type == null)
+ {
+ throw new NullPointerException("type");
+ }
+
+ // try common types and arrays of common types first
+ Class clazz = (Class) COMMON_TYPES.get(type);
+ if (clazz != null)
+ {
+ return clazz;
+ }
+
+ int len = type.length();
+ if (len > 2 && type.charAt(len - 1) == ']' && type.charAt(len - 2) == '[')
+ {
+ String componentType = type.substring(0, len - 2);
+ Class componentTypeClass = classForName(componentType);
+ return Array.newInstance(componentTypeClass, 0).getClass();
+ }
+
+ return classForName(type);
+
+ }
+
+ /**
+ * This method is similar to shared ClassUtils.javaTypeToClass,
+ * but the default package for the type is java.lang
+ *
+ * @param type
+ * @return
+ * @throws ClassNotFoundException
+ */
+ public static Class javaDefaultTypeToClass(String type)
+ throws ClassNotFoundException
+ {
+ if (type == null)
+ {
+ throw new NullPointerException("type");
+ }
+
+ // try common types and arrays of common types first
+ Class clazz = (Class) ClassUtils.COMMON_TYPES.get(type);
+ if (clazz != null)
+ {
+ return clazz;
+ }
+
+ int len = type.length();
+ if (len > 2 && type.charAt(len - 1) == ']' && type.charAt(len - 2) == '[')
+ {
+ String componentType = type.substring(0, len - 2);
+ Class componentTypeClass = ClassUtils.classForName(componentType);
+ return Array.newInstance(componentTypeClass, 0).getClass();
+ }
+
+ if (type.indexOf('.') == -1)
+ {
+ type = "java.lang." + type;
+ }
+ return ClassUtils.classForName(type);
+ }
+
+ /**
+ * Same as {@link #javaTypeToClass(String)}, but throws a RuntimeException
+ * (FacesException) instead of a ClassNotFoundException.
+ *
+ * @return the corresponding Class
+ * @throws NullPointerException if type is null
+ * @throws FacesException if class not found
+ */
+ public static Class simpleJavaTypeToClass(String type)
+ {
+ try
+ {
+ return javaTypeToClass(type);
+ }
+ catch (ClassNotFoundException e)
+ {
+ log.log(Level.SEVERE, "Class " + type + " not found", e);
+ throw new FacesException(e);
+ }
+ }
+
+ public static URL getResource(String resource)
+ {
+ URL url = getContextClassLoader().getResource(resource);
+ if (url == null)
+ {
+ url = ClassUtils.class.getClassLoader().getResource(resource);
+ }
+ return url;
+ }
+
+ public static InputStream getResourceAsStream(String resource)
+ {
+ InputStream stream = getContextClassLoader()
+ .getResourceAsStream(resource);
+ if (stream == null)
+ {
+ // fallback
+ stream = ClassUtils.class.getClassLoader().getResourceAsStream(resource);
+ }
+ return stream;
+ }
+
+ /**
+ * @param resource Name of resource(s) to find in classpath
+ * @param defaultObject The default object to use to determine the class loader
+ * (if none associated with current thread.)
+ * @return Iterator over URL Objects
+ */
+ public static Iterator getResources(String resource, Object defaultObject)
+ {
+ try
+ {
+ Enumeration resources = getCurrentLoader(defaultObject).getResources(resource);
+ List lst = new ArrayList();
+ while (resources.hasMoreElements())
+ {
+ lst.add(resources.nextElement());
+ }
+ return lst.iterator();
+ }
+ catch (IOException e)
+ {
+ log.log(Level.SEVERE, e.getMessage(), e);
+ throw new FacesException(e);
+ }
+ }
+
+
+ public static Object newInstance(String type)
+ throws FacesException
+ {
+ if (type == null)
+ {
+ return null;
+ }
+ return newInstance(simpleClassForName(type));
+ }
+
+ public static Object newInstance(String type, Class expectedType) throws FacesException
+ {
+ return newInstance(type, expectedType == null ? null : new Class[] {expectedType});
+ }
+
+ public static Object newInstance(String type, Class[] expectedTypes)
+ {
+ if (type == null)
+ {
+ return null;
+ }
+
+ Class clazzForName = simpleClassForName(type);
+
+ if(expectedTypes != null)
+ {
+ for (int i = 0, size = expectedTypes.length; i < size; i++)
+ {
+ if (!expectedTypes[i].isAssignableFrom(clazzForName))
+ {
+ throw new FacesException("'" + type + "' does not implement expected type '" + expectedTypes[i]
+ + "'");
+ }
+ }
+ }
+
+ return newInstance(clazzForName);
+ }
+
+ public static <T> T newInstance(Class<T> clazz)
+ throws FacesException
+ {
+ try
+ {
+ return clazz.newInstance();
+ }
+ catch(NoClassDefFoundError e)
+ {
+ log.log(Level.SEVERE, "Class : "+clazz.getName()+" not found.",e);
+ throw new FacesException(e);
+ }
+ catch (InstantiationException e)
+ {
+ log.log(Level.SEVERE, e.getMessage(), e);
+ throw new FacesException(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ log.log(Level.SEVERE, e.getMessage(), e);
+ throw new FacesException(e);
+ }
+ }
+
+ public static <T> T newInstance(Class<T> clazz,
+ Class<?>[] constructorArgClasses,
+ Object... constructorArgs) throws NoSuchMethodException
+ {
+ if (constructorArgs.length == 0)
+ {
+ // no args given - use normal newInstance()
+ return newInstance(clazz);
+ }
+
+ // try to get a fitting constructor (throws NoSuchMethodException)
+ Constructor constructor = clazz.getConstructor(constructorArgClasses);
+
+ try
+ {
+ // actually create instance
+ return (T) constructor.newInstance(constructorArgs);
+ }
+ catch (Exception e)
+ {
+ throw new FacesException(e);
+ }
+ }
+
+ public static Object convertToType(Object value, Class desiredClass)
+ {
+ if (value == null)
+ {
+ return null;
+ }
+
+ try
+ {
+ ExpressionFactory expFactory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
+ return expFactory.coerceToType(value, desiredClass);
+ }
+ catch (Exception e)
+ {
+ String message = "Cannot coerce " + value.getClass().getName()
+ + " to " + desiredClass.getName();
+ log.log(Level.SEVERE, message, e);
+ throw new FacesException(message, e);
+ }
+ }
+
+ /**
+ * Gets the ClassLoader associated with the current thread. Returns the class loader associated with
+ * the specified default object if no context loader is associated with the current thread.
+ *
+ * @param defaultObject The default object to use to determine the class loader
+ * (if none associated with current thread.)
+ * @return ClassLoader
+ */
+ protected static ClassLoader getCurrentLoader(Object defaultObject)
+ {
+ ClassLoader loader = getContextClassLoader();
+ if(loader == null)
+ {
+ loader = defaultObject.getClass().getClassLoader();
+ }
+ return loader;
+ }
+
+ /**
+ * Gets the ClassLoader associated with the current thread. Includes a check for priviledges
+ * against java2 security to ensure no security related exceptions are encountered.
+ *
+ * @since 3.0.6
+ * @return ClassLoader
+ */
+ public static ClassLoader getContextClassLoader()
+ {
+ // call into the same method on ClassLoaderUtils. no need for duplicate code maintenance.
+ return ClassLoaderUtils.getContextClassLoader();
+ }
+
+ /**
+ * Creates ApplicationObjects like NavigationHandler or StateManager and creates
+ * the right wrapping chain of the ApplicationObjects known as the decorator pattern.
+ * @param <T>
+ * @param interfaceClass The class from which the implementation has to inherit from.
+ * @param classNamesIterator All the class names of the actual ApplicationObject implementations
+ * from the faces-config.xml.
+ * @param defaultObject The default implementation for the given ApplicationObject.
+ * @return
+ */
+ public static <T> T buildApplicationObject(Class<T> interfaceClass,
+ Collection<String> classNamesIterator, T defaultObject)
+ {
+ return buildApplicationObject(interfaceClass, null, null, classNamesIterator, defaultObject);
+ }
+
+ /**
+ * Creates ApplicationObjects like NavigationHandler or StateManager and creates
+ * the right wrapping chain of the ApplicationObjects known as the decorator pattern.
+ * @param <T>
+ * @param interfaceClass The class from which the implementation has to inherit from.
+ * @param extendedInterfaceClass A subclass of interfaceClass which specifies a more
+ * detailed implementation.
+ * @param extendedInterfaceWrapperClass A wrapper class for the case that you have an ApplicationObject
+ * which only implements the interfaceClass but not the
+ * extendedInterfaceClass.
+ * @param classNamesIterator All the class names of the actual ApplicationObject implementations
+ * from the faces-config.xml.
+ * @param defaultObject The default implementation for the given ApplicationObject.
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> T buildApplicationObject(Class<T> interfaceClass, Class<? extends T> extendedInterfaceClass,
+ Class<? extends T> extendedInterfaceWrapperClass,
+ Collection<String> classNamesIterator, T defaultObject)
+ {
+ T current = defaultObject;
+
+
+ for (String implClassName : classNamesIterator)
+ {
+ Class<? extends T> implClass = ClassUtils.simpleClassForName(implClassName);
+
+ // check, if class is of expected interface type
+ if (!interfaceClass.isAssignableFrom(implClass))
+ {
+ throw new IllegalArgumentException("Class " + implClassName + " is no " + interfaceClass.getName());
+ }
+
+ if (current == null)
+ {
+ // nothing to decorate
+ current = (T) ClassUtils.newInstance(implClass);
+ }
+ else
+ {
+ // let's check if class supports the decorator pattern
+ T newCurrent = null;
+ try
+ {
+ Constructor<? extends T> delegationConstructor = null;
+
+ // first, if there is a extendedInterfaceClass,
+ // try to find a constructor that uses that
+ if (extendedInterfaceClass != null
+ && extendedInterfaceClass.isAssignableFrom(current.getClass()))
+ {
+ try
+ {
+ delegationConstructor =
+ implClass.getConstructor(new Class[] {extendedInterfaceClass});
+ }
+ catch (NoSuchMethodException mnfe)
+ {
+ // just eat it
+ }
+ }
+ if (delegationConstructor == null)
+ {
+ // try to find the constructor with the "normal" interfaceClass
+ delegationConstructor =
+ implClass.getConstructor(new Class[] {interfaceClass});
+ }
+ // impl class supports decorator pattern at this point
+ try
+ {
+ // create new decorator wrapping current
+ newCurrent = delegationConstructor.newInstance(new Object[] { current });
+ }
+ catch (InstantiationException e)
+ {
+ log.log(Level.SEVERE, e.getMessage(), e);
+ throw new FacesException(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ log.log(Level.SEVERE, e.getMessage(), e);
+ throw new FacesException(e);
+ }
+ catch (InvocationTargetException e)
+ {
+ log.log(Level.SEVERE, e.getMessage(), e);
+ throw new FacesException(e);
+ }
+ }
+ catch (NoSuchMethodException e)
+ {
+ // no decorator pattern support
+ newCurrent = (T) ClassUtils.newInstance(implClass);
+ }
+
+ // now we have a new current object (newCurrent)
+ // --> find out if it is assignable from extendedInterfaceClass
+ // and if not, wrap it in a backwards compatible wrapper (if available)
+ if (extendedInterfaceWrapperClass != null
+ && !extendedInterfaceClass.isAssignableFrom(newCurrent.getClass()))
+ {
+ try
+ {
+ Constructor<? extends T> wrapperConstructor
+ = extendedInterfaceWrapperClass.getConstructor(
+ new Class[] {interfaceClass, extendedInterfaceClass});
+ newCurrent = wrapperConstructor.newInstance(new Object[] {newCurrent, current});
+ }
+ catch (NoSuchMethodException e)
+ {
+ log.log(Level.SEVERE, e.getMessage(), e);
+ throw new FacesException(e);
+ }
+ catch (InstantiationException e)
+ {
+ log.log(Level.SEVERE, e.getMessage(), e);
+ throw new FacesException(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ log.log(Level.SEVERE, e.getMessage(), e);
+ throw new FacesException(e);
+ }
+ catch (InvocationTargetException e)
+ {
+ log.log(Level.SEVERE, e.getMessage(), e);
+ throw new FacesException(e);
+ }
+ }
+
+ current = newCurrent;
+ }
+ }
+
+ return current;
+ }
+}
Propchange: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassUtils.java
------------------------------------------------------------------------------
cvs2svn:cvs-rev = 1.11
Propchange: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassUtils.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ClassUtils.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/MyFacesObjectInputStream.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/MyFacesObjectInputStream.java?rev=1760967&view=auto
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/MyFacesObjectInputStream.java (added)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/MyFacesObjectInputStream.java Thu Sep 15 18:09:25 2016
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.myfaces.trinidadinternal.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+import java.lang.reflect.Proxy;
+
+/**
+ * Tried to deploy v0.4.2 on JBoss 3.2.1 and had a classloading problem again.
+ * The problem seemed to be with JspInfo, line 98. We are using an
+ * ObjectInputStream Class, which then cannot find the classes to deserialize
+ * the input stream. The solution appears to be to subclass ObjectInputStream
+ * (eg. CustomInputStream), and specify a different class-loading mechanism.
+ */
+public class MyFacesObjectInputStream
+ extends ObjectInputStream
+{
+ public MyFacesObjectInputStream(InputStream in) throws IOException
+ {
+ super(in);
+ }
+
+ protected Class resolveClass(ObjectStreamClass desc)
+ throws ClassNotFoundException, IOException
+ {
+ try
+ {
+ return ClassUtils.classForName(desc.getName());
+ }
+ catch (ClassNotFoundException e)
+ {
+ return super.resolveClass(desc);
+ }
+ }
+
+ protected Class resolveProxyClass(String[] interfaces)
+ throws IOException, ClassNotFoundException
+ {
+ // Only option that would match the current code would be to
+ // expand ClassLoaderExtension to handle 'getProxyClass', which
+ // would break all existing ClassLoaderExtension implementations
+ Class[] cinterfaces = new Class[interfaces.length];
+ for (int i = 0; i < interfaces.length; i++)
+ {
+ cinterfaces[i] = ClassUtils.classForName(interfaces[i]);
+ }
+
+ try
+ {
+ // Try WebApp ClassLoader first
+ return Proxy.getProxyClass(ClassUtils.getContextClassLoader(), cinterfaces);
+ }
+ catch (Exception ex)
+ {
+ // fallback: Try ClassLoader for MyFacesObjectInputStream (i.e. the myfaces.jar lib)
+ try
+ {
+ return Proxy.getProxyClass(
+ MyFacesObjectInputStream.class.getClassLoader(), cinterfaces);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new ClassNotFoundException(e.toString(), e);
+ }
+ }
+ }
+}
Propchange: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/MyFacesObjectInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/MyFacesObjectInputStream.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL