Skip to main content
summaryrefslogtreecommitdiffstats
blob: 557e5c9acab8b1ce074f5ff2058fc3e95090d8c1 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*******************************************************************************
 * 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 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 *     Oracle Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.common.runtime.internal.model.decorator;

import org.eclipse.jst.jsf.common.runtime.internal.model.types.ClassTypeInfo;

/**
 * Type information about a converter.
 * 
 * @author cbateman
 * 
 */
public class ConverterTypeInfo extends ClassTypeInfo
{
    /**
     * serializable id
     */
    private static final long serialVersionUID = -7238952424045449907L;
    private static final String[]  NO_FOR_CLASS = new  String[0];
    private final String        _converterId;
    private final String[]      _forClasses;

    /**
     * For unknown converters, use the UNKNOWN constant.
     * 
     * @param className
     * @param converterId
     * @throws java.lang.IllegalArgumentException
     *             if both className and converterId are null.
     * 
     */
    public ConverterTypeInfo(String className, String converterId)
    {
        super(className, new String[0], new String[0]);
        if (className == null && converterId == null)
        {
            throw new IllegalArgumentException(
                    "converterClass and converterId must not both be null.  For unknown validator use the UNKNOWN constant"); //$NON-NLS-1$
        }

        _converterId = converterId;
        _forClasses = NO_FOR_CLASS;
    }

    /**
     * For unknown converters, use the UNKNOWN constant.
     * 
     * @param className
     * @param superClasses 
     * @param interfaces 
     * @param converterId
     * @param forClass 
     * @throws java.lang.IllegalArgumentException
     *             if both className and converterId are null.
     * 
     */
    public ConverterTypeInfo(String className, String[] superClasses,
            String[] interfaces, String converterId, String[] forClass)
    {
        super(className, superClasses, interfaces);
        if (className == null && converterId == null)
        {
            throw new IllegalArgumentException(
                    "converterClass and converterId must not both be null.  For unknown validator use the UNKNOWN constant"); //$NON-NLS-1$
        }

        _converterId = converterId;
        if (forClass == null)
        {
            _forClasses = NO_FOR_CLASS;
        }
        else
        {
            _forClasses = forClass;
        }
    }

    /**
     * Use when the converter's information unknown such as occurs when using
     * the f:converter tag.
     */
    public static final ConverterTypeInfo UNKNOWN = new ConverterTypeInfo(
            (Object) null);

    /**
     * A private constructor used to create the UNRESOLVED constant. We use an
     * Object arg here (which is discarded) rather than using the zero-arg
     * constructor so as not mess up anything like Serializable that may depend
     * on how zero-arg constructors are defined.
     * 
     * @param unresolved
     */
    private ConverterTypeInfo(Object unresolved)
    {
        super(null, new String[0], new String[0]);
        _converterId = null;
        _forClasses = NO_FOR_CLASS;
    }

    /**
     * @return the converter's id.
     */
    public final String getConverterId()
    {
        return _converterId;
    }

    /**
     * @return a copy of the listof classes that this type converters to.  May
     * be empty.  Never null.
     */
    public final String[] getForClass()
    {
        final String[]  returnArray = new String[_forClasses.length];
        System.arraycopy(_forClasses, 0, returnArray, 0, _forClasses.length);
        return returnArray;
    }

    public String toString()
    {
        String toString = ""; //$NON-NLS-1$

        if (_forClasses.length  > 0)
        {
            toString = "For-Classes: ["; //$NON-NLS-1$
            for (int i = 0; i < _forClasses.length; i++)
            {
                toString += _forClasses[i];
                if (i < _forClasses.length-1)
                {
                    toString += ", "; //$NON-NLS-1$
                }
            }
            toString += "], "; //$NON-NLS-1$
        }
        return toString + "Converter Type Info: type = " + _converterId + ", "+super.toString(); //$NON-NLS-1$ //$NON-NLS-2$
    }
}

Back to the top