Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3f06d6d5b5f49a8110835afaa2cdffc087689899 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*******************************************************************************
 * Copyright (c) 2001, 2008 Oracle Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Oracle Corporation - initial API and implementation
 *******************************************************************************/
package instrument;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.util.Iterator;

import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.component.UIOutput;

import org.eclipse.jst.jsf.common.runtime.internal.debug.JSFMonitorMessage;
import org.eclipse.jst.jsf.common.runtime.internal.model.component.ComponentFactory;
import org.eclipse.jst.jsf.common.runtime.internal.model.component.ComponentInfo;
import org.eclipse.jst.jsf.common.runtime.internal.model.component.FacetInfo;
import org.eclipse.jst.jsf.common.runtime.internal.model.component.UIInputInfo;
import org.eclipse.jst.jsf.common.runtime.internal.model.component.UIOutputInfo;

public class MyMonitorMessageFactory 
{
    public static JSFMonitorMessage  createJSFMonitorMessage(InputStream inStream) throws IOException, ClassCastException, ClassNotFoundException
    {
        ObjectInputStream objectStream = new ObjectInputStream(inStream);
        Object nextObject = objectStream.readObject();
        return (JSFMonitorMessage) nextObject;
    }
   
    static ComponentInfo buildComponentTree(UIComponent component, boolean isFacet)
    {
        final ComponentInfo componentInfo = getComponentData(component, isFacet);
        
        for (Iterator it = component.getChildren().iterator(); it.hasNext();)
        {
            UIComponent child = (UIComponent) it.next();
            componentInfo.getChildren().add(buildComponentTree(child, false));
        }

        for (Iterator it = component.getFacets().values().iterator(); it.hasNext();)
        {
            UIComponent facet = (UIComponent) it.next();
            componentInfo.getChildren().add(buildComponentTree(facet, true));
        }
        
        return componentInfo;
    }
    
    private static ComponentInfo getComponentData(final UIComponent component, boolean isFacet)
    {
        if (isFacet)
        {
            return calculateFacetInfo(component);
        }
        else if (component instanceof UIInput)
        {
            return calculateUIInput((UIInput)component);
        }
        else if (component instanceof UIOutput)
        {
            return calculateUIOutput((UIOutput)component);
        }
        
        // default; just make a component
        return calculateComponentInfo(component);
    }

    private static ComponentInfo calculateComponentInfo(UIComponent component)
    {
        final String id = component.getId();
        final String parentId = component.getParent() == null ? null : component.getParent().getId();
        final String componentFamily = component.getFamily();
        final String renderFamily = component.getRendererType();
        final String componentType = null;
        final String componentClass = component.getClass().getCanonicalName();
        
        return ComponentFactory.createComponentInfo
            (id, parentId, componentFamily, renderFamily, componentType, componentClass);
    }
    
    private static FacetInfo calculateFacetInfo(UIComponent component)
    {
        final String id = component.getId();
        final String parentId = component.getParent() == null ? null : component.getParent().getId();
        final String componentFamily = component.getFamily();
        final String renderFamily = component.getRendererType();
        final String componentType = null;
        final String componentClass = component.getClass().getCanonicalName();

        return ComponentFactory.createFacetInfo
            (id, parentId, componentFamily, renderFamily, componentType, componentClass);
    }
    
    private static UIInputInfo calculateUIInput(UIInput  uiInput)
    {
        final String id = uiInput.getId();
        final String parentId = uiInput.getParent() == null ? null : uiInput.getParent().getId();
        final String componentFamily = uiInput.getFamily();
        final String renderFamily = uiInput.getRendererType();
        final String componentType = null;
        final String componentClass = uiInput.getClass().getCanonicalName();
        final String isValid = Boolean.toString(uiInput.isValid());
        final String isImmediate = Boolean.toString(uiInput.isImmediate());
        final String isRequired = Boolean.toString(uiInput.isRequired());
        final String isRendered = Boolean.toString(uiInput.isRendered());

        return ComponentFactory.createUIInputInfo
            (id, parentId, componentFamily, renderFamily, isValid, isImmediate, isRequired, isRendered, componentType, componentClass);
    }

    private static UIOutputInfo calculateUIOutput(UIOutput uiOutput)
    {
        final String id = uiOutput.getId();
        final String parentId = uiOutput.getParent() == null ? null : uiOutput.getParent().getId();
        final String componentFamily = uiOutput.getFamily();
        final String renderFamily = uiOutput.getRendererType();
        final String componentType = null;
        final String componentClass = uiOutput.getClass().getCanonicalName();
        final String isRendered = Boolean.toString(uiOutput.isRendered());

        return ComponentFactory.createUIOutputInfo
            (id, parentId, componentFamily, renderFamily, isRendered, componentType, componentClass);
    }
}

Back to the top