Class JvmClassInitializer

java.lang.Object
org.daiitech.naftah.builtin.lang.JvmClassInitializer
All Implemented Interfaces:
Serializable, JvmExecutable

public final class JvmClassInitializer extends Object implements Serializable, JvmExecutable
Represents a Java class Constructor that can be invoked dynamically.

This class serves as a reflective wrapper around a Constructor<?>, storing metadata about its declaring class, parameter types, and whether it is invocable. It also provides serialization support, automatically restoring the transient Constructor instance upon deserialization by matching parameter types.

Arabic terminology:

  • المنشئ — Constructor
  • المُعدّلات — Modifiers
  • المعاملات — Parameters

Author:
Chakib Daii
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • clazz

      private final Class<?> clazz
      The class declaring this constructor.
    • qualifiedName

      private final String qualifiedName
      The fully qualified signature identifying this constructor.
    • constructorParameterTypes

      private final Class<?>[] constructorParameterTypes
      The parameter types accepted by this constructor.
    • isInvocable

      private final boolean isInvocable
      Whether this constructor is invocable (accessible and valid).
    • constructor

      private transient Constructor<?> constructor
      The reflected constructor instance (transient for serialization).
  • Constructor Details

    • JvmClassInitializer

      public JvmClassInitializer(String qualifiedName, Class<?> clazz, Constructor<?> constructor, boolean isInvocable)
      Creates a new JvmClassInitializer wrapper.
      Parameters:
      qualifiedName - the fully qualified constructor signature
      clazz - the class declaring the constructor
      constructor - the reflected constructor instance
      isInvocable - whether the constructor can be invoked
  • Method Details

    • of

      public static JvmClassInitializer of(String qualifiedName, Class<?> clazz, Constructor<?> constructor)
      Factory method for creating a JvmClassInitializer instance.
      Parameters:
      qualifiedName - the fully qualified constructor signature
      clazz - the declaring class
      constructor - the reflected constructor
      Returns:
      a new JvmClassInitializer instance
    • getClazz

      public Class<?> getClazz()
      Gets the class declaring the method.
      Returns:
      the class declaring this constructor
    • getQualifiedName

      public String getQualifiedName()
      Gets the class qualified name.
      Returns:
      the fully qualified name of this constructor
    • getConstructor

      public Constructor<?> getConstructor()
      Gets the class constructor.
      Returns:
      the reflected Constructor instance
    • isInvocable

      public boolean isInvocable()
      Checks if the method is invocable.
      Returns:
      true if this constructor can be invoked, otherwise false
    • getConstructorParameterTypes

      public Class<?>[] getConstructorParameterTypes()
      Returns the parameter types accepted by this constructor.
      Returns:
      an array of Class objects representing the constructor's parameter types
    • getExecutable

      public Executable getExecutable()
      Returns the underlying reflective Executable instance represented by this object.

      This may correspond to a Java method, constructor, or other callable element recognized by the JVM.

      Specified by:
      getExecutable in interface JvmExecutable
      Returns:
      the associated Executable instance
    • writeObject

      private void writeObject(ObjectOutputStream oos) throws IOException
      Custom serialization logic for writing non-transient fields.
      Parameters:
      oos - the object output stream
      Throws:
      IOException - if an I/O error occurs
    • readObject

      private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException
      Custom deserialization logic for restoring the transient Constructor.

      After reading object data, this method searches the declaring class for a constructor with matching parameter types and restores it.

      Parameters:
      ois - the object input stream
      Throws:
      IOException - if an I/O error occurs
      ClassNotFoundException - if a class cannot be found during deserialization
    • toString

      public String toString()
      Returns a concise Arabic-labeled string representation of this constructor.

      Format: <منشئ qualifiedName>

      Overrides:
      toString in class Object
      Returns:
      a short string identifying this constructor
    • toDetailedString

      public String toDetailedString()
      Returns a detailed, Arabic-formatted string representation of this constructor, including its class, parameters, modifiers, and annotations.

      Example output:

       تفاصيل المنشئ:
       - الاسم المؤهل: com.example.MyClass - كوم:إِكْزامْبِل:ماي_كْلاس
       - المعاملات:
       - java.lang.String - جافا:لانغ:سترينج
       - المُعدّلات: public - بَبْلِكْ
       - التعليقات التوضيحية:
       - @java.lang.Deprecated - جافا:لانغ:دِبْرِكَيْتِدْ
       
      Returns:
      an Arabic, multi-line description of the constructor’s metadata