Skip to content

Commit

Permalink
Add EL 6.0 resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
tandraschko committed Aug 13, 2024
1 parent c42067e commit 02eba71
Show file tree
Hide file tree
Showing 37 changed files with 93 additions and 694 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package org.apache.myfaces.component.validate;

import java.beans.FeatureDescriptor;
import java.util.Iterator;
import jakarta.el.ELContext;
import jakarta.el.ELResolver;

Expand Down Expand Up @@ -74,12 +72,6 @@ public boolean isReadOnly(final ELContext ctx, final Object base, final Object p
return resolver.isReadOnly(ctx, base, property);
}

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(final ELContext ctx, final Object base)
{
return resolver.getFeatureDescriptors(ctx, base);
}

@Override
public Class<?> getCommonPropertyType(final ELContext ctx, final Object base)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@
*/
package org.apache.myfaces.el;

import org.apache.myfaces.el.resolver.FlashELResolver;
import java.util.ArrayList;
import java.util.List;

import jakarta.el.ArrayELResolver;
import jakarta.el.BeanELResolver;
import jakarta.el.CompositeELResolver;
import jakarta.el.ELResolver;
import jakarta.el.ListELResolver;
import jakarta.el.MapELResolver;
import jakarta.el.OptionalELResolver;
import jakarta.el.RecordELResolver;
import jakarta.el.ResourceBundleELResolver;
import jakarta.el.StaticFieldELResolver;
import org.apache.myfaces.el.resolver.FlashELResolver;
import java.util.ArrayList;
import java.util.List;

import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.faces.component.UIInput;
import jakarta.faces.context.FacesContext;
Expand Down Expand Up @@ -126,7 +128,7 @@ public void build(FacesContext facesContext, CompositeELResolver compositeElReso

try
{
ELResolver streamElResolver = (ELResolver) runtimeConfig.getExpressionFactory().getStreamELResolver();
ELResolver streamElResolver = runtimeConfig.getExpressionFactory().getStreamELResolver();
if (streamElResolver != null)
{
list.add(streamElResolver);
Expand All @@ -149,6 +151,17 @@ public void build(FacesContext facesContext, CompositeELResolver compositeElReso
list.add(new MapELResolver());
list.add(new ListELResolver());
list.add(new ArrayELResolver());

try
{
list.add(new OptionalELResolver());
list.add(new RecordELResolver());
}
catch (Throwable ex)
{
LOG.log(Level.WARNING, "Could not add OptionalELResolver / RecordELResolver!", ex);
}

if (PropertyDescriptorUtils.isUseLambdaMetafactory(facesContext.getExternalContext()))
{
list.add(new LambdaBeanELResolver());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,25 @@
*/
package org.apache.myfaces.el.resolver;

import java.beans.BeanInfo;
import java.beans.FeatureDescriptor;
import java.beans.PropertyDescriptor;
import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;

import jakarta.el.ELContext;
import jakarta.el.ELResolver;
import jakarta.el.ValueExpression;
import jakarta.faces.component.UIComponent;
import jakarta.faces.context.FacesContext;
import jakarta.faces.el.CompositeComponentExpressionHolder;

import org.apache.myfaces.config.webparameters.MyfacesConfig;
import org.apache.myfaces.util.lang.ClassUtils;
import org.apache.myfaces.util.lang.StringUtils;
import org.apache.myfaces.view.facelets.tag.composite.CompositeComponentBeanInfo;

import java.beans.BeanInfo;
import java.beans.PropertyDescriptor;
import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;

/**
* Composite component attribute EL resolver. See Faces spec, section 5.6.2.2.
*/
Expand Down Expand Up @@ -67,13 +64,6 @@ public Class<?> getCommonPropertyType(ELContext context, Object base)
return String.class;
}

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base)
{
// Per the spec, do nothing.
return null;
}

@Override
public Class<?> getType(ELContext context, Object base, Object property)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package org.apache.myfaces.el.resolver;

import java.beans.FeatureDescriptor;
import java.util.Iterator;
import jakarta.el.ELContext;
import jakarta.el.ELResolver;

Expand All @@ -42,12 +40,6 @@ public <T extends Object> T convertToType(ELContext context, Object value, Class
return (T) value;
}

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base)
{
return null;
}

@Override
public Class<?> getType(ELContext context, Object base, Object property)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import jakarta.faces.context.ExternalContext;
import jakarta.faces.context.FacesContext;
import jakarta.faces.context.Flash;
import java.beans.FeatureDescriptor;
import java.util.ArrayList;
import java.util.Iterator;

/**
* Resolver for Flash object
Expand Down Expand Up @@ -285,44 +282,6 @@ else if (base instanceof Flash flash)
return null;
}

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base)
{
ArrayList<FeatureDescriptor> descriptors = new ArrayList<>(1);

descriptors.add(makeDescriptor(FLASH,
"Represents the current flash scope", Object.class));

if (base instanceof Flash flash)
{
Iterator itr = flash.keySet().iterator();
Object key;
FeatureDescriptor desc;
while (itr.hasNext())
{
key = itr.next();
desc = makeDescriptor(key.toString(), key.toString(), key.getClass());
descriptors.add(desc);
}
}
return descriptors.iterator();
}

protected FeatureDescriptor makeDescriptor(String name, String description,
Class<?> elResolverType)
{
FeatureDescriptor fd = new FeatureDescriptor();
fd.setValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
fd.setValue(ELResolver.TYPE, elResolverType);
fd.setName(name);
fd.setDisplayName(name);
fd.setShortDescription(description);
fd.setExpert(false);
fd.setHidden(false);
fd.setPreferred(true);
return fd;
}

@Override
public Class<?> getCommonPropertyType(ELContext context, Object base)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@
*/
package org.apache.myfaces.el.resolver;

import java.beans.FeatureDescriptor;
import static java.lang.String.format;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static java.util.logging.Level.FINE;
import java.util.logging.Logger;
import jakarta.el.ELContext;
import jakarta.el.ELException;
import jakarta.el.ELResolver;
Expand All @@ -42,6 +30,18 @@
import org.apache.myfaces.util.lang.ClassUtils;
import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;

import static java.lang.String.format;
import static java.util.logging.Level.FINE;

/**
*
*/
Expand Down Expand Up @@ -154,12 +154,6 @@ public boolean isReadOnly(final ELContext context, final Object base,
return false;
}

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(final ELContext context, final Object base)
{
return null;
}

@Override
public Class<?> getCommonPropertyType(final ELContext context, final Object base)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@
*/
package org.apache.myfaces.el.resolver;

import java.beans.FeatureDescriptor;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.ResourceBundle;
import jakarta.el.ELContext;
import jakarta.el.ELException;
import jakarta.el.ELResolver;
import jakarta.el.PropertyNotFoundException;
import jakarta.el.PropertyNotWritableException;
import jakarta.faces.application.Application;
import jakarta.faces.context.FacesContext;

import org.apache.myfaces.config.RuntimeConfig;

import java.util.ResourceBundle;

/**
* See Faces 1.2 spec section 5.6.1.4
*
Expand Down Expand Up @@ -166,26 +162,6 @@ public Class<?> getType(final ELContext context, final Object base, final Object
return null;
}

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(final ELContext context, final Object base)
{
if (base != null)
{
return null;
}

final Map<String, org.apache.myfaces.config.element.ResourceBundle> resourceBundles =
runtimeConfig(context).getResourceBundles();

final ArrayList<FeatureDescriptor> descriptors = new ArrayList<>(resourceBundles.size());
for (org.apache.myfaces.config.element.ResourceBundle resourceBundle : resourceBundles.values())
{
descriptors.add(makeDescriptor(resourceBundle));
}

return descriptors.iterator();
}

@Override
public Class<?> getCommonPropertyType(final ELContext context, final Object base)
{
Expand Down Expand Up @@ -228,17 +204,4 @@ protected RuntimeConfig runtimeConfig(ELContext context)
return runtimeConfig;
}

private static FeatureDescriptor makeDescriptor(org.apache.myfaces.config.element.ResourceBundle bundle)
{
final FeatureDescriptor fd = new FeatureDescriptor();
fd.setValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
fd.setName(bundle.getVar());
fd.setDisplayName(bundle.getDisplayName());
fd.setValue(ELResolver.TYPE, ResourceBundle.class);
fd.setShortDescription("");
fd.setExpert(false);
fd.setHidden(false);
fd.setPreferred(true);
return fd;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
*/
package org.apache.myfaces.el.resolver;

import java.beans.FeatureDescriptor;
import java.util.Iterator;

import jakarta.el.ELContext;
import jakarta.el.ELException;
import jakarta.el.ELResolver;
Expand All @@ -32,7 +29,6 @@
import org.apache.myfaces.renderkit.html.util.ResourceUtils;
import org.apache.myfaces.resource.ContractResource;
import org.apache.myfaces.resource.ResourceELUtils;

import org.apache.myfaces.view.facelets.el.CompositeComponentELUtils;

/**
Expand All @@ -58,13 +54,6 @@ public Class<?> getCommonPropertyType(final ELContext context,
return base == null ? Object.class : null;
}

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(
final ELContext context, final Object base)
{
return null;
}

@Override
public Class<?> getType(final ELContext context, final Object base,
final Object property)
Expand Down
Loading

0 comments on commit 02eba71

Please sign in to comment.