Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8eb1e7e20ca6a630b7e7715bc72da116ba8bf4e2 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*******************************************************************************
 * Copyright (c) 2010, 2019 IBM Corporation and others.
 * 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.designtime.internal.view.model.jsp;

import java.io.IOException;
import java.io.Serializable;

import org.eclipse.jst.jsf.common.runtime.internal.view.model.common.AbstractTagAttribute;
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDAttributeDeclaration;

/**
 * Adapts a TLDAttributeDeclaration to the ITagAttribute interface.
 * 
 * @author cbateman
 *
 */
public class TLDTagAttribute extends AbstractTagAttribute
{

    /**
     * 
     */
    private static final long serialVersionUID = 4327701042556836452L;

    private final TLDAttributeData _tldData;

    /**
     * @param decl 
     */
    public TLDTagAttribute(final TLDAttributeDeclaration decl)
    {
        _tldData = new DocumentAttributeData(decl);
    }

    @Override
    public String getName()
    {
        return _tldData.getName();
    }

    @Override
    public String getDisplayName()
    {
        return _tldData.getDisplayName();
    }

    @Override
    public String getDescription() {
        return _tldData.getDescription();
    }

    @Override
    public String getTargetNamespace()
    {
        return _tldData.getTargetNamespace();
    }

    public boolean isRequired()
    {
        return _tldData.isRequired();
    }

    /**
     * Diagnostic only.  For testing only. Should never be exposed on ITagAttribute.
     * 
     * @return true if this instance wraps a SerializedTLDAttributeData (the
     * instance was created by readObject).  False if it is wrapping a 
     * TLDAttributeDeclaration.
     */
    public boolean hasBeenDeserialized()
    {
       return _tldData instanceof SerializedTLDAttributeData; 
    }
    @Override
    public String toString()
    {
        return String.format("Attribute: name=%s, displayName=%s, description=%s\n" //$NON-NLS-1$
                , getName(), getDisplayName(), getDescription());
    }

    private static class DocumentAttributeData extends TLDAttributeData
    {
        /**
         * 
         */
        private static final long serialVersionUID = -5974753636507938515L;
        private final TLDAttributeDeclaration       _decl;
        
        
        public DocumentAttributeData(TLDAttributeDeclaration decl)
        {
            super();
            _decl = decl;
        }

        private Object writeReplace()
        {
            return new SerializedTLDAttributeData(getName(), getDisplayName(), getDescription()
                    , getTargetNamespace(), isRequired());
        }

        @SuppressWarnings("unused")
        private void readObject(java.io.ObjectInputStream in)
                        throws IOException, ClassNotFoundException
        {
            throw new UnsupportedOperationException("This object should be serialized; writeReplace"); //$NON-NLS-1$
        }

        @Override
        public String getName()
        {
            return _decl.getAttrName();
        }

        @Override
        public String getTargetNamespace()
        {
            return null;
        }

        @Override
        public String getDescription()
        {
            return _decl.getDescription();
        }

        @Override
        public String getDisplayName()
        {
            return _decl.getAttrName();
        }

        @Override
        public boolean isRequired()
        {
            return _decl.isRequired();
        }

    }

    /**
     * @author cbateman
     *
     */
    private static class SerializedTLDAttributeData extends TLDAttributeData
    {
        /**
         * 
         */
        private static final long serialVersionUID = -1094006883222087189L;

        private final String _name;
        private final String _displayName;
        private final String _description;
        private final String _targetNamespace;
        private final boolean _isRequired;
        
        
        
        public SerializedTLDAttributeData(String name, String displayName,
                String description, String targetNamespace, boolean isRequired)
        {
            super();
            _name = name;
            _displayName = displayName;
            _description = description;
            _targetNamespace = targetNamespace;
            _isRequired = isRequired;
        }

        @Override
        public String getName()
        {
            return _name;
        }

        @Override
        public String getDisplayName()
        {
            return _displayName;
        }

        @Override
        public String getDescription()
        {
            return _description;
        }

        @Override
        public String getTargetNamespace()
        {
            return _targetNamespace;
        }

        @Override
        public boolean isRequired()
        {
            return _isRequired;
        }

    }

    private static abstract class TLDAttributeData implements Serializable
    {
        /**
         * 
         */
        private static final long serialVersionUID = 8376571212994363562L;
        public abstract String getName();
        public abstract String getDisplayName();
        public abstract String getDescription();
        public abstract String getTargetNamespace();
        public abstract boolean isRequired();
    }
}

Back to the top