Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f202b1fa2c61b468f04811cb815a5353f37e3c17 (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
/*******************************************************************************
 * Copyright (c) 2008 Oracle Corporation.
 * 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:
 *    Cameron Bateman - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.facelet.core.internal.registry;

import java.util.Iterator;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.emf.common.util.EList;
import org.eclipse.jst.jsf.common.dom.TagIdentifier;
import org.eclipse.jst.jsf.common.runtime.internal.model.component.ComponentTypeInfo;
import org.eclipse.jst.jsf.common.runtime.internal.model.decorator.ConverterTypeInfo;
import org.eclipse.jst.jsf.common.runtime.internal.model.decorator.ValidatorTypeInfo;
import org.eclipse.jst.jsf.common.runtime.internal.model.types.TypeInfo;
import org.eclipse.jst.jsf.common.runtime.internal.view.model.common.IHandlerTagElement.TagHandlerType;
import org.eclipse.jst.jsf.common.runtime.internal.view.model.common.ITagElement;
import org.eclipse.jst.jsf.core.internal.tld.TagIdentifierFactory;
import org.eclipse.jst.jsf.designtime.internal.Messages;
import org.eclipse.jst.jsf.designtime.internal.view.mapping.ViewMetadataLoader;
import org.eclipse.jst.jsf.designtime.internal.view.mapping.ViewMetadataMapper;
import org.eclipse.jst.jsf.designtime.internal.view.mapping.viewmapping.TagMapping;
import org.eclipse.jst.jsf.designtime.internal.view.mapping.viewmapping.TagToViewObjectMapping;
import org.eclipse.jst.jsf.designtime.internal.view.model.jsp.AbstractTagResolvingStrategy;
import org.eclipse.jst.jsf.designtime.internal.view.model.jsp.DefaultTagTypeInfo;
import org.eclipse.jst.jsf.facelet.core.internal.cm.FaceletDocumentFactory;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib.FaceletTaglibTagAttribute;
import org.eclipse.jst.jsf.facelet.core.internal.tagmodel.ComponentTag;
import org.eclipse.jst.jsf.facelet.core.internal.tagmodel.ConverterTag;
import org.eclipse.jst.jsf.facelet.core.internal.tagmodel.HandlerTag;
import org.eclipse.jst.jsf.facelet.core.internal.tagmodel.NoArchetypeFaceletTag;
import org.eclipse.jst.jsf.facelet.core.internal.tagmodel.ValidatorTag;
import org.osgi.framework.Version;

/**
 * Resolves facelet tags from JSF framework metadata.
 * 
 * @author cbateman
 *
 */
public class FaceletMetaResolvingStrategy
        extends
        AbstractTagResolvingStrategy<IFaceletTagResolvingStrategy.TLDWrapper, String>
        implements IFaceletTagResolvingStrategy
{

    /**
     * strategy id
     */
    public final static String           ID           = "org.eclipse.jst.jsf.facelet.metadata.FaceletMetaResolvingStrategy"; //$NON-NLS-1$
    /**
     * displayable nameb
     */
    public final static String           DISPLAY_NAME = Messages.DefaultJSPTagResolver_DisplayName;

    private final ViewMetadataLoader     _loader;
    private final ViewMetadataMapper     _mapper;
    private final FaceletDocumentFactory _factory;

    /**
     * @param project
     * @param factory 
     */
    public FaceletMetaResolvingStrategy(final IProject project,
            final FaceletDocumentFactory factory)
    {
        _factory = factory;
        _loader = new ViewMetadataLoader(project);
        _mapper = new ViewMetadataMapper();
    }

    @Override
    public ITagElement resolve(
            final IFaceletTagResolvingStrategy.TLDWrapper elementDecl)
    {
        final String uri = elementDecl.getUri();
        final String tagName = elementDecl.getTagDefn().getTagName();
        final TagIdentifier tagId = TagIdentifierFactory.createJSPTagWrapper(
                uri, tagName);
        final TagMapping mapping = _loader.getTagToViewMapping(tagId);

        TypeInfo elementType = null;
        if (mapping != null)
        {
            elementType = findTypeInfo(mapping, "1.1", null); //$NON-NLS-1$
        }
        final List<FaceletTaglibTagAttribute>  attributes = 
            elementDecl.getTagDefn().getAttribute();
        if (elementType instanceof ComponentTypeInfo)
        {
            return new ComponentTag(uri, tagName,
                    (ComponentTypeInfo) elementType, null, _factory,
                    new MetadataAttributeAdvisor(tagId, _loader, attributes));
        }
        else if (elementType instanceof ConverterTypeInfo)
        {
            return new ConverterTag(uri, tagName,
                    (ConverterTypeInfo) elementType, null, _factory,
                    new MetadataAttributeAdvisor(tagId, _loader, attributes));
        }
        else if (elementType instanceof ValidatorTypeInfo)
        {
            return new ValidatorTag(uri, tagName,
                    (ValidatorTypeInfo) elementType, null, _factory,
                    new MetadataAttributeAdvisor(tagId, _loader, attributes));
        }
        else if (elementType instanceof TagHandlerType)
        {
            return new HandlerTag(uri, tagName,
                    (TagHandlerType) elementType, null, _factory,
                    new MetadataAttributeAdvisor(
                            tagId, _loader, attributes));
        }
        else if (DefaultTagTypeInfo.isDefaultLib(tagId.getUri()))
        {
            return new NoArchetypeFaceletTag(uri, tagName, _factory, new MetadataAttributeAdvisor(tagId, _loader, attributes));
        }

        // not found
        return null;
    }

    private TypeInfo findTypeInfo(final TagMapping mapping,
            final String jsfVersion, final String libVersion)
    {
        final EList list = mapping.getVersionedTagToViewMappings();

        FIND_BY_VERSION: for (final Iterator<?> it = list.iterator(); it
                .hasNext();)
        {
            Object obj = it.next();

            if (obj instanceof TagToViewObjectMapping)
            {
                final TagToViewObjectMapping viewMapping = (TagToViewObjectMapping) obj;

                final String minJsfVersionString = viewMapping
                        .getMinJSFVersion();
                if (minJsfVersionString != null)
                {
                    try
                    {
                        final Version version = new Version(jsfVersion);
                        final Version minVersion = Version
                                .parseVersion(minJsfVersionString);

                        if (version.compareTo(minVersion) < 0)
                        {
                            // my version is less than the minimum specified
                            // by this meta-data
                            continue FIND_BY_VERSION;
                        }
                    }
                    catch (final IllegalArgumentException iae)
                    {
                        continue FIND_BY_VERSION;
                    }
                }
                final String minLibVersionString = viewMapping
                        .getMinLibraryVersion();
                if (libVersion != null && minLibVersionString != null)
                {
                    try
                    {
                        final Version version = new Version(libVersion);
                        final Version minLibVersion = Version
                                .parseVersion(minLibVersionString);

                        if (version.compareTo(minLibVersion) < 0)
                        {
                            // my lib version is less than the minimum specified
                            // by the meta-data
                            continue FIND_BY_VERSION;
                        }
                    }
                    catch (IllegalArgumentException iae)
                    {
                        continue FIND_BY_VERSION;
                    }
                }
                return _mapper.mapToFrameworkData(viewMapping.getTypeInfo());
            }
        }
        return null;
    }

    @Override
    public String getId()
    {
        return ID;
    }

    public String getDisplayName()
    {
        return DISPLAY_NAME;
    }

}

Back to the top