All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.managedbean.ftlh Maven / Gradle / Ivy

package ${package};

import java.lang.annotation.Annotation;
import java.util.function.Supplier;
import java.util.Set;
import java.util.HashSet;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Provider;

import io.crysknife.client.BeanManager;
import io.crysknife.client.Reflect;
import io.crysknife.client.SyncBeanDef;
import io.crysknife.client.InstanceFactory;
import io.crysknife.client.internal.InstanceImpl;
import io.crysknife.client.internal.ManagedInstanceImpl;
import io.crysknife.client.internal.BeanFactory;
import io.crysknife.client.internal.proxy.OnFieldAccessed;
import io.crysknife.client.internal.QualifierUtil;

<#if !jre>
import io.crysknife.client.internal.proxy.Interceptor;
import io.crysknife.client.internal.proxy.OnFieldAccessed;
import io.crysknife.client.Reflect;


<#list imports as import>
import ${import};


@SuppressWarnings({"unchecked", "rawtypes"})
public class ${clazz}_Factory extends <#if isProxy>ProxyBeanFactory<${bean}> {

    <#list fields as call>
    ${call?no_esc}
    

    <#list deps as dep>
    private final Supplier> ${dep.fieldName} = ${dep.call?no_esc};
    

    @Override()
    public ${bean} createInstance() {
        Set deps = new HashSet<>();
    <#if !jre>
        <#if isDependent>
        final Interceptor interceptor = new Interceptor(new ${bean}(<#if constructorParams??>${constructorParams?no_esc}));
        <#else>
        <#if isProxy>
        final Interceptor interceptor = new Interceptor(new Proxy${bean}());
        <#else>
        if (this.instance != null) {
            return (${bean}) instance;
        }
        final Interceptor interceptor = new Interceptor(new ${bean}(<#if constructorParams??>${constructorParams?no_esc}));
        
    
        <#if isDependent>${bean} instance = interceptor.getProxy();
        <#list fieldInterceptors as call>
        ${call?no_esc};
        
    <#else>

  <#if isDependent>
      ${bean} instance = new ${bean}(<#if constructorParams??>${constructorParams?no_esc});
  <#else>
    <#if isProxy>
        instance = new Proxy${bean}();
    <#else>
        if (this.instance != null) {
          return (${bean}) instance;
        }
        instance = new ${bean}(<#if constructorParams??>${constructorParams?no_esc});
    
  

        addDependencyConstructor(instance, deps);
        deps.clear();
    <#list doCreateInstance as call>
        ${call?no_esc};
    
        return (${bean}) instance;
    }

    @Override()
    public void doInitInstance(${bean} instance) {
<#list doInitInstance as call>
        ${call?no_esc}

<#list postConstruct as call>
    ${call?no_esc}

    }
<#if isDependent>
    @Override()
    public ${bean} getInstance() {
        ${bean} instance = createInstanceInternal();
        initInstance(instance);
        return instance;
    }
<#else>
    @Override()
    public ${bean} getInstance() {
        <#if isProxy>
        if (instance == null) {
          createInstance();
          initDelegate();
        }
        <#else>
        if (instance != null) {
            return (${bean}) instance;
        }
        ${bean} instance = createInstanceInternal();
        initInstance(instance);
        
        return instance;
    }



<#if preDestroy??>
    @Override()
    protected void onDestroy(${bean} instance) {
    <#list preDestroy as call>
        ${call?no_esc}
    
    }


    public ${clazz}_Factory(BeanManager beanManager) {
        super(beanManager);
        <#list factoryConstructor as call>
        ${call?no_esc}
        
    }

<#if !jre>
    <#if privateMethods?? && privateMethods?size != 0>
    @JsType(isNative=true, namespace="${package}", name="${bean}")
    public static class ${bean}Proxy {
        <#list privateMethods as mangle>
            @JsProperty(name="${mangle}")
            public Function ${mangle};
        
    }
    




}