Class PrototypeFactory


  • public class PrototypeFactory
    extends java.lang.Object
    Factory implementation that creates a new instance each time based on a prototype.
    Since:
    Commons Collections 3.0
    Version:
    $Revision: 1713849 $ $Date: 2015-11-11 15:21:37 +0100 (Wed, 11 Nov 2015) $
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private PrototypeFactory()
      Constructor that performs no validation.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Factory getInstance​(java.lang.Object prototype)
      Factory method that performs validation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PrototypeFactory

        private PrototypeFactory()
        Constructor that performs no validation. Use getInstance if you want that.
    • Method Detail

      • getInstance

        public static Factory getInstance​(java.lang.Object prototype)
        Factory method that performs validation.

        Creates a Factory that will return a clone of the same prototype object each time the factory is used. The prototype will be cloned using one of these techniques (in order):

        • public clone method
        • public copy constructor
        • serialization clone

            WARNING: from v3.2.2 onwards this method will return a Factory that will throw an UnsupportedOperationException when trying to serialize or de-serialize it to prevent potential remote code execution exploits.

            In order to re-enable serialization support the following system property can be used (via -Dproperty=true):

             org.apache.commons.collections.enableUnsafeSerialization
             
        Parameters:
        prototype - the object to clone each time in the factory
        Returns:
        the prototype factory
        Throws:
        java.lang.IllegalArgumentException - if the prototype is null
        java.lang.IllegalArgumentException - if the prototype cannot be cloned