-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
105 changed files
with
1,378 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
eclipse/bundles/org.openntf.xsp.jakarta.el/res/META-INF/services/com.ibm.xsp.Library
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
....openntf.xsp.jakarta.el/src/org/openntf/xsp/jakarta/el/impl/RecordPropertyELResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package org.openntf.xsp.jakarta.el.impl; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
import java.util.Objects; | ||
|
||
import jakarta.el.BeanELResolver; | ||
import jakarta.el.ELContext; | ||
import jakarta.el.ELResolver; | ||
import jakarta.el.PropertyNotWritableException; | ||
|
||
public class RecordPropertyELResolver extends ELResolver { | ||
|
||
private final BeanELResolver delegate = new BeanELResolver(); | ||
|
||
@SuppressWarnings({"removal", "deprecation"}) | ||
@Override | ||
public Object getValue(ELContext context, Object base, Object property) { | ||
if(base == null) { | ||
return null; | ||
} | ||
if(!base.getClass().isRecord()) { | ||
return null; | ||
} | ||
|
||
Objects.requireNonNull(property); | ||
Object result = AccessController.doPrivileged((PrivilegedAction<Object>)() -> { | ||
try { | ||
Method m = base.getClass().getMethod(property.toString()); | ||
context.setPropertyResolved(true); | ||
return m.invoke(base); | ||
} catch (NoSuchMethodException e) { | ||
return null; | ||
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
|
||
// Handle custom methods like normal beans | ||
if(!context.isPropertyResolved()) { | ||
return delegate.getValue(context, base, property); | ||
} else { | ||
return result; | ||
} | ||
} | ||
|
||
@SuppressWarnings({"removal", "deprecation"}) | ||
@Override | ||
public Class<?> getType(ELContext context, Object base, Object property) { | ||
Objects.requireNonNull(base); | ||
if(!base.getClass().isRecord()) { | ||
return null; | ||
} | ||
|
||
Objects.requireNonNull(property); | ||
Class<?> result = AccessController.doPrivileged((PrivilegedAction<Class<?>>)() -> { | ||
try { | ||
Method m = base.getClass().getMethod(property.toString()); | ||
context.setPropertyResolved(true); | ||
return m.getReturnType(); | ||
} catch (NoSuchMethodException e) { | ||
return null; | ||
} catch (SecurityException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
|
||
// Handle custom methods like normal beans | ||
if(!context.isPropertyResolved()) { | ||
return delegate.getType(context, base, property); | ||
} else { | ||
return result; | ||
} | ||
} | ||
|
||
@Override | ||
public void setValue(ELContext context, Object base, Object property, Object value) { | ||
throw new PropertyNotWritableException("Cannot write a property on a record"); | ||
} | ||
|
||
@Override | ||
public boolean isReadOnly(ELContext context, Object base, Object property) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Class<?> getCommonPropertyType(ELContext context, Object base) { | ||
if (base == null) { | ||
return null; | ||
} | ||
|
||
return Object.class; | ||
} | ||
|
||
} |
121 changes: 121 additions & 0 deletions
121
...rg.openntf.xsp.jakarta.el/src/org/openntf/xsp/jakarta/el/impl/RecordPropertyResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package org.openntf.xsp.jakarta.el.impl; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import javax.faces.el.EvaluationException; | ||
import javax.faces.el.PropertyNotFoundException; | ||
import javax.faces.el.PropertyResolver; | ||
|
||
import com.ibm.xsp.el.PropertyResolverImpl; | ||
|
||
/** | ||
* @since 3.1.0 | ||
*/ | ||
public class RecordPropertyResolver extends PropertyResolver { | ||
public static final RecordPropertyResolver INSTANCE = new RecordPropertyResolver(); | ||
private final PropertyResolverImpl delegate = new PropertyResolverImpl(); | ||
|
||
@SuppressWarnings({"removal", "deprecation"}) | ||
@Override | ||
public Object getValue(Object base, Object property) | ||
throws EvaluationException, PropertyNotFoundException { | ||
if(base == null) { | ||
return null; | ||
} | ||
if(!base.getClass().isRecord()) { | ||
return null; | ||
} | ||
|
||
Objects.requireNonNull(property); | ||
AtomicBoolean resolved = new AtomicBoolean(false); | ||
Object result = AccessController.doPrivileged((PrivilegedAction<Object>)() -> { | ||
try { | ||
Method m = base.getClass().getMethod(property.toString()); | ||
resolved.set(true); | ||
return m.invoke(base); | ||
} catch (NoSuchMethodException e) { | ||
return null; | ||
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
|
||
// Handle custom methods like normal beans | ||
if(!resolved.get()) { | ||
return delegate.getValue(base, property); | ||
} else { | ||
return result; | ||
} | ||
} | ||
|
||
@Override | ||
public Object getValue(Object base, int index) throws EvaluationException, PropertyNotFoundException { | ||
throw new PropertyNotFoundException(); | ||
} | ||
|
||
@Override | ||
public void setValue(Object base, Object property, Object value) | ||
throws EvaluationException, PropertyNotFoundException { | ||
throw new EvaluationException("Cannot set values on records"); | ||
} | ||
|
||
@Override | ||
public void setValue(Object base, int index, Object value) | ||
throws EvaluationException, PropertyNotFoundException { | ||
throw new PropertyNotFoundException(); | ||
} | ||
|
||
@Override | ||
public boolean isReadOnly(Object base, Object property) | ||
throws EvaluationException, PropertyNotFoundException { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isReadOnly(Object base, int index) throws EvaluationException, PropertyNotFoundException { | ||
return true; | ||
} | ||
|
||
@SuppressWarnings({"removal", "deprecation", "rawtypes"}) | ||
@Override | ||
public Class getType(Object base, Object property) | ||
throws EvaluationException, PropertyNotFoundException { | ||
Objects.requireNonNull(base); | ||
if(!base.getClass().isRecord()) { | ||
return null; | ||
} | ||
|
||
Objects.requireNonNull(property); | ||
AtomicBoolean resolved = new AtomicBoolean(false); | ||
Class<?> result = AccessController.doPrivileged((PrivilegedAction<Class<?>>)() -> { | ||
try { | ||
Method m = base.getClass().getMethod(property.toString()); | ||
resolved.set(true); | ||
return m.getReturnType(); | ||
} catch (NoSuchMethodException e) { | ||
return null; | ||
} catch (SecurityException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
|
||
// Handle custom methods like normal beans | ||
if(!resolved.get()) { | ||
return delegate.getType(base, property); | ||
} else { | ||
return result; | ||
} | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
@Override | ||
public Class getType(Object base, int index) throws EvaluationException, PropertyNotFoundException { | ||
throw new PropertyNotFoundException(); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...ntf.xsp.jakarta.el/src/org/openntf/xsp/jakarta/el/impl/RecordPropertyResolverFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.openntf.xsp.jakarta.el.impl; | ||
|
||
import javax.faces.el.PropertyResolver; | ||
|
||
import com.ibm.xsp.el.PropertyResolverFactory; | ||
|
||
/** | ||
* @since 3.1.0 | ||
*/ | ||
public class RecordPropertyResolverFactory implements PropertyResolverFactory { | ||
public static final RecordPropertyResolverFactory INSTANCE = new RecordPropertyResolverFactory(); | ||
|
||
@Override | ||
public PropertyResolver getPropertyResolver(Object base) { | ||
if(base != null && base.getClass().isRecord()) { | ||
return RecordPropertyResolver.INSTANCE; | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.