You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bs...@apache.org on 2011/10/25 20:23:02 UTC

svn commit: r1188848 - in /myfaces/trinidad/branches/jwaldman-offline-mode-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit: ClassRendererInstantiator.java NeedsPostConstructionInitialization.java

Author: bsullivan
Date: Tue Oct 25 18:23:01 2011
New Revision: 1188848

URL: http://svn.apache.org/viewvc?rev=1188848&view=rev
Log:
Support two-phase construction of Renderers to avoid problems calling virtual functions from constructors

Added:
    myfaces/trinidad/branches/jwaldman-offline-mode-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/NeedsPostConstructionInitialization.java   (with props)
Modified:
    myfaces/trinidad/branches/jwaldman-offline-mode-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/ClassRendererInstantiator.java

Modified: myfaces/trinidad/branches/jwaldman-offline-mode-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/ClassRendererInstantiator.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman-offline-mode-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/ClassRendererInstantiator.java?rev=1188848&r1=1188847&r2=1188848&view=diff
==============================================================================
--- myfaces/trinidad/branches/jwaldman-offline-mode-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/ClassRendererInstantiator.java (original)
+++ myfaces/trinidad/branches/jwaldman-offline-mode-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/ClassRendererInstantiator.java Tue Oct 25 18:23:01 2011
@@ -46,7 +46,15 @@ class ClassRendererInstantiator implemen
     try
     {
       Class<?> classInstance = ClassLoaderUtils.loadClass(_className);
-      return (Renderer) classInstance.newInstance();
+      Renderer renderer = (Renderer) classInstance.newInstance();
+      
+      // if the Renderer needs two-phase construction, call it
+      if (renderer instanceof NeedsPostConstructionInitialization)
+      {
+        renderer = ((NeedsPostConstructionInitialization<Renderer>)renderer).initialize();
+      }
+      
+      return renderer;
     }
     catch (ClassNotFoundException cnfe)
     {

Added: myfaces/trinidad/branches/jwaldman-offline-mode-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/NeedsPostConstructionInitialization.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jwaldman-offline-mode-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/NeedsPostConstructionInitialization.java?rev=1188848&view=auto
==============================================================================
--- myfaces/trinidad/branches/jwaldman-offline-mode-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/NeedsPostConstructionInitialization.java (added)
+++ myfaces/trinidad/branches/jwaldman-offline-mode-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/NeedsPostConstructionInitialization.java Tue Oct 25 18:23:01 2011
@@ -0,0 +1,30 @@
+/*
+ *  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.renderkit;
+
+/**
+ * Interface implemented by Renderers that need an extra
+ * Instantiation step after the Renderer class is created.
+ * Use of this interface avoids problems with calling
+ * virtual methods from constructors.
+ */
+public interface NeedsPostConstructionInitialization<T>
+{
+  public T initialize();
+}

Propchange: myfaces/trinidad/branches/jwaldman-offline-mode-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/NeedsPostConstructionInitialization.java
------------------------------------------------------------------------------
    svn:eol-style = native