/*
 * Copyright (c) 2016 Nova Ordis LLC
 *
 * Licensed 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 io.novaordis.playground.jee.servlet.session.applicaton;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

/**
 * An "application type" to experiment with.
 *
 * @author Ovidiu Feodorov <ovidiu@novaordis.com>
 * @since 6/12/16
 */
public class ApplicationType implements Serializable {

    // Constants -------------------------------------------------------------------------------------------------------

    private static final Logger log = LoggerFactory.getLogger(ApplicationType.class);

    //
    // this is the type's version. For more details @see Serializable
    //
    private static final long serialVersionUID = 1L;

    // Static ----------------------------------------------------------------------------------------------------------

    // Attributes ------------------------------------------------------------------------------------------------------

    private String state;

    // Constructors ----------------------------------------------------------------------------------------------------

    // Public ----------------------------------------------------------------------------------------------------------

    /**
     * Typed write.
     */
    public void write(String s) {

        log.info("write(" + s + ")");

        this.state = s;
    }

    /**
     * Typed read.
     */
    public String read() {

        log.info("read()");

        return state;
    }

    @Override
    public String toString() {

        return
                "ApplicationType[id=" + Integer.toHexString(System.identityHashCode(this)) +
                        "][version=" + serialVersionUID + "][state4=" + state + "]";
    }

    // Package protected -----------------------------------------------------------------------------------------------

    // Protected -------------------------------------------------------------------------------------------------------

    // Private ---------------------------------------------------------------------------------------------------------

    // Inner classes ---------------------------------------------------------------------------------------------------

}

@@ -746,16 +746,83 @@
 lizable;
+%0Aimport java.lang.reflect.Field;%0Aimport java.lang.reflect.Modifier;
 %0A%0A/**%0A *
@@ -1337,17 +1337,17 @@
 onUID = 
-1
+2
 L;%0A%0A    
@@ -1611,16 +1611,43 @@
 g state;
+%0A    private String state2;
 %0A%0A    //
@@ -2204,26 +2204,31 @@
     
-return%0A   
+String s = %22%22;%0A
         
     
@@ -2223,20 +2223,20 @@
         
-    
+s +=
  %22Applic
@@ -2308,29 +2308,22 @@
 )) +
-%0A            
+ %22%5D%22;%0A
         
     
@@ -2322,14 +2322,14 @@
     
-   
+s +=
  %22
-%5D
 %5Bver
@@ -2362,31 +2362,597 @@
 + %22%5D
-%5Bstate4=%22 + state + %22%5D%22
+%22;%0A%0A        // state%0A%0A        s += %22%5B%22;%0A%0A        boolean first = true;%0A%0A        for(Field f: this.getClass().getDeclaredFields()) %7B%0A%0A            if (Modifier.isStatic(f.getModifiers())) %7B%0A                continue;%0A            %7D%0A%0A            if (first) %7B%0A                first = false;%0A            %7D%0A            else %7B%0A                s += %22, %22;%0A            %7D%0A%0A            s += f.getName() + %22=%22;%0A%0A            try %7B%0A                s += f.get(this);%0A            %7D%0A            catch (Exception e) %7B%0A%0A                s += %22FAILURE%22;%0A            %7D%0A        %7D%0A        s += %22%5D%22;%0A%0A        return s
 ;%0A  

use reflection to describe ApplicationType instance state