This commit is contained in:
2024-11-30 19:03:49 +08:00
commit 1e6763c160
3806 changed files with 737676 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @since Common Annotations 1.0
*/
@Documented
@Target({ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR,
ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.METHOD,
ElementType.PACKAGE, ElementType.PARAMETER, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
public @interface Generated {
public String[] value();
public String date() default "";
public String comments() default "";
}

View File

@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @since Common Annotations 1.1
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ManagedBean {
String value() default "";
}

View File

@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @since Common Annotations 1.0
*/
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface PostConstruct {
// No attributes
}

View File

@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @since Common Annotations 1.0
*/
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface PreDestroy {
// No attributes
}

View File

@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @since Common Annotations 1.2
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Priority {
int value();
}

View File

@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @since Common Annotations 1.0
*/
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Resource {
public enum AuthenticationType {
CONTAINER,
APPLICATION
}
public String name() default "";
/**
* Uses generics since Common Annotations 1.2.
*
* @return The type for instances of this resource
*/
public Class<?> type() default Object.class;
public AuthenticationType authenticationType() default AuthenticationType.CONTAINER;
public boolean shareable() default true;
public String description() default "";
public String mappedName() default "";
/**
* @since Common Annotations 1.1
*
* @return The name of the entry, if any, to use for this resource
*/
public String lookup() default "";
}

View File

@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @since Common Annotations 1.0
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Resources {
public Resource[] value();
}

View File

@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.annotation.security;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @since Common Annotations 1.0
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface DeclareRoles {
public String[] value();
}

View File

@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.annotation.security;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @since Common Annotations 1.0
*/
@Documented
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface DenyAll {
// No attributes
}

View File

@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.annotation.security;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @since Common Annotations 1.0
*/
@Documented
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface PermitAll {
// No attributes
}

View File

@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.annotation.security;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @since Common Annotations 1.0
*/
@Documented
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface RolesAllowed {
public String[] value();
}

View File

@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.annotation.security;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @since Common Annotations 1.0
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface RunAs {
public String value();
}

View File

@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.annotation.sql;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @since Common Annotations 1.1
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface DataSourceDefinition {
String className();
String name();
String description() default "";
String url() default "";
String user() default "";
String password() default "";
String databaseName() default "";
int portNumber() default -1;
String serverName() default "localhost";
int isolationLevel() default -1;
boolean transactional() default true;
int initialPoolSize() default -1;
int maxPoolSize() default -1;
int minPoolSize() default -1;
int maxIdleTime() default -1;
int maxStatements() default -1;
String[] properties() default {};
int loginTimeout() default 0;
}

View File

@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.annotation.sql;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @since Common Annotations 1.1
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface DataSourceDefinitions {
DataSourceDefinition[] value();
}

37
java/javax/ejb/EJB.java Normal file
View File

@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.ejb;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD, ElementType.TYPE, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface EJB {
String name() default "";
String description() default "";
@SuppressWarnings("rawtypes") // Can't use Class<?> because API needs to match specification
Class beanInterface() default java.lang.Object.class;
String beanName() default "";
String mappedName() default "";
String lookup() default "";
}

31
java/javax/ejb/EJBs.java Normal file
View File

@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.ejb;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface EJBs {
EJB[] value();
}

View File

@@ -0,0 +1,150 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.beans.FeatureDescriptor;
import java.lang.reflect.Array;
import java.util.Iterator;
import java.util.Objects;
public class ArrayELResolver extends ELResolver {
private final boolean readOnly;
public ArrayELResolver() {
this.readOnly = false;
}
public ArrayELResolver(boolean readOnly) {
this.readOnly = readOnly;
}
@Override
public Class<?> getType(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base != null && base.getClass().isArray()) {
context.setPropertyResolved(base, property);
try {
int idx = coerce(property);
checkBounds(base, idx);
} catch (IllegalArgumentException e) {
// ignore
}
return base.getClass().getComponentType();
}
return null;
}
@Override
public Object getValue(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base != null && base.getClass().isArray()) {
context.setPropertyResolved(base, property);
int idx = coerce(property);
if (idx < 0 || idx >= Array.getLength(base)) {
return null;
}
return Array.get(base, idx);
}
return null;
}
@Override
public void setValue(ELContext context, Object base, Object property,
Object value) {
Objects.requireNonNull(context);
if (base != null && base.getClass().isArray()) {
context.setPropertyResolved(base, property);
if (this.readOnly) {
throw new PropertyNotWritableException(Util.message(context,
"resolverNotWriteable", base.getClass().getName()));
}
int idx = coerce(property);
checkBounds(base, idx);
if (value != null && !Util.isAssignableFrom(value.getClass(),
base.getClass().getComponentType())) {
throw new ClassCastException(Util.message(context,
"objectNotAssignable", value.getClass().getName(),
base.getClass().getComponentType().getName()));
}
Array.set(base, idx, value);
}
}
@Override
public boolean isReadOnly(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base != null && base.getClass().isArray()) {
context.setPropertyResolved(base, property);
try {
int idx = coerce(property);
checkBounds(base, idx);
} catch (IllegalArgumentException e) {
// ignore
}
}
return this.readOnly;
}
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
return null;
}
@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
if (base != null && base.getClass().isArray()) {
return Integer.class;
}
return null;
}
private static final void checkBounds(Object base, int idx) {
if (idx < 0 || idx >= Array.getLength(base)) {
throw new PropertyNotFoundException(
new ArrayIndexOutOfBoundsException(idx).getMessage());
}
}
private static final int coerce(Object property) {
if (property instanceof Number) {
return ((Number) property).intValue();
}
if (property instanceof Character) {
return ((Character) property).charValue();
}
if (property instanceof Boolean) {
return ((Boolean) property).booleanValue() ? 1 : 0;
}
if (property instanceof String) {
return Integer.parseInt((String) property);
}
throw new IllegalArgumentException(property != null ?
property.toString() : "null");
}
}

View File

@@ -0,0 +1,372 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.beans.BeanInfo;
import java.beans.FeatureDescriptor;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
public class BeanELResolver extends ELResolver {
private static final int CACHE_SIZE;
private static final String CACHE_SIZE_PROP =
"org.apache.el.BeanELResolver.CACHE_SIZE";
static {
String cacheSizeStr;
if (System.getSecurityManager() == null) {
cacheSizeStr = System.getProperty(CACHE_SIZE_PROP, "1000");
} else {
cacheSizeStr = AccessController.doPrivileged(
new PrivilegedAction<String>() {
@Override
public String run() {
return System.getProperty(CACHE_SIZE_PROP, "1000");
}
});
}
CACHE_SIZE = Integer.parseInt(cacheSizeStr);
}
private final boolean readOnly;
private final ConcurrentCache<String, BeanProperties> cache =
new ConcurrentCache<>(CACHE_SIZE);
public BeanELResolver() {
this.readOnly = false;
}
public BeanELResolver(boolean readOnly) {
this.readOnly = readOnly;
}
@Override
public Class<?> getType(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base == null || property == null) {
return null;
}
context.setPropertyResolved(base, property);
return this.property(context, base, property).getPropertyType();
}
@Override
public Object getValue(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base == null || property == null) {
return null;
}
context.setPropertyResolved(base, property);
Method m = this.property(context, base, property).read(context, base);
try {
return m.invoke(base, (Object[]) null);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
Util.handleThrowable(cause);
throw new ELException(Util.message(context, "propertyReadError",
base.getClass().getName(), property.toString()), cause);
} catch (Exception e) {
throw new ELException(e);
}
}
@Override
public void setValue(ELContext context, Object base, Object property,
Object value) {
Objects.requireNonNull(context);
if (base == null || property == null) {
return;
}
context.setPropertyResolved(base, property);
if (this.readOnly) {
throw new PropertyNotWritableException(Util.message(context,
"resolverNotWriteable", base.getClass().getName()));
}
Method m = this.property(context, base, property).write(context, base);
try {
m.invoke(base, value);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
Util.handleThrowable(cause);
throw new ELException(Util.message(context, "propertyWriteError",
base.getClass().getName(), property.toString()), cause);
} catch (Exception e) {
throw new ELException(e);
}
}
/**
* @since EL 2.2
*/
@Override
public Object invoke(ELContext context, Object base, Object method,
Class<?>[] paramTypes, Object[] params) {
Objects.requireNonNull(context);
if (base == null || method == null) {
return null;
}
ExpressionFactory factory = ELManager.getExpressionFactory();
String methodName = (String) factory.coerceToType(method, String.class);
// Find the matching method
Method matchingMethod =
Util.findMethod(base.getClass(), base, methodName, paramTypes, params);
Object[] parameters = Util.buildParameters(
matchingMethod.getParameterTypes(), matchingMethod.isVarArgs(),
params);
Object result = null;
try {
result = matchingMethod.invoke(base, parameters);
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new ELException(e);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
Util.handleThrowable(cause);
throw new ELException(cause);
}
context.setPropertyResolved(base, method);
return result;
}
@Override
public boolean isReadOnly(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base == null || property == null) {
return false;
}
context.setPropertyResolved(base, property);
return this.readOnly || this.property(context, base, property).isReadOnly(base);
}
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
if (base == null) {
return null;
}
try {
BeanInfo info = Introspector.getBeanInfo(base.getClass());
PropertyDescriptor[] pds = info.getPropertyDescriptors();
for (int i = 0; i < pds.length; i++) {
pds[i].setValue(RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
pds[i].setValue(TYPE, pds[i].getPropertyType());
}
return Arrays.asList((FeatureDescriptor[]) pds).iterator();
} catch (IntrospectionException e) {
//
}
return null;
}
@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
if (base != null) {
return Object.class;
}
return null;
}
static final class BeanProperties {
private final Map<String, BeanProperty> properties;
private final Class<?> type;
public BeanProperties(Class<?> type) throws ELException {
this.type = type;
this.properties = new HashMap<>();
try {
BeanInfo info = Introspector.getBeanInfo(this.type);
PropertyDescriptor[] pds = info.getPropertyDescriptors();
for (PropertyDescriptor pd: pds) {
this.properties.put(pd.getName(), new BeanProperty(type, pd));
}
if (System.getSecurityManager() != null) {
// When running with SecurityManager, some classes may be
// not accessible, but have accessible interfaces.
populateFromInterfaces(type);
}
} catch (IntrospectionException ie) {
throw new ELException(ie);
}
}
private void populateFromInterfaces(Class<?> aClass) throws IntrospectionException {
Class<?> interfaces[] = aClass.getInterfaces();
if (interfaces.length > 0) {
for (Class<?> ifs : interfaces) {
BeanInfo info = Introspector.getBeanInfo(ifs);
PropertyDescriptor[] pds = info.getPropertyDescriptors();
for (PropertyDescriptor pd : pds) {
if (!this.properties.containsKey(pd.getName())) {
this.properties.put(pd.getName(), new BeanProperty(
this.type, pd));
}
}
populateFromInterfaces(ifs);
}
}
Class<?> superclass = aClass.getSuperclass();
if (superclass != null) {
populateFromInterfaces(superclass);
}
}
private BeanProperty get(ELContext ctx, String name) {
BeanProperty property = this.properties.get(name);
if (property == null) {
throw new PropertyNotFoundException(Util.message(ctx,
"propertyNotFound", type.getName(), name));
}
return property;
}
private Class<?> getType() {
return type;
}
}
static final class BeanProperty {
private final Class<?> type;
private final Class<?> owner;
private final PropertyDescriptor descriptor;
private Method read;
private Method write;
public BeanProperty(Class<?> owner, PropertyDescriptor descriptor) {
this.owner = owner;
this.descriptor = descriptor;
this.type = descriptor.getPropertyType();
}
public Class<?> getPropertyType() {
return this.type;
}
public boolean isReadOnly(Object base) {
return this.write == null &&
(null == (this.write = Util.getMethod(this.owner, base, descriptor.getWriteMethod())));
}
private Method write(ELContext ctx, Object base) {
if (this.write == null) {
this.write = Util.getMethod(this.owner, base, descriptor.getWriteMethod());
if (this.write == null) {
throw new PropertyNotWritableException(Util.message(ctx,
"propertyNotWritable", new Object[] {
owner.getName(), descriptor.getName() }));
}
}
return this.write;
}
private Method read(ELContext ctx, Object base) {
if (this.read == null) {
this.read = Util.getMethod(this.owner, base, descriptor.getReadMethod());
if (this.read == null) {
throw new PropertyNotFoundException(Util.message(ctx,
"propertyNotReadable", new Object[] {
owner.getName(), descriptor.getName() }));
}
}
return this.read;
}
}
private final BeanProperty property(ELContext ctx, Object base,
Object property) {
Class<?> type = base.getClass();
String prop = property.toString();
BeanProperties props = this.cache.get(type.getName());
if (props == null || type != props.getType()) {
props = new BeanProperties(type);
this.cache.put(type.getName(), props);
}
return props.get(ctx, prop);
}
private static final class ConcurrentCache<K,V> {
private final int size;
private final Map<K,V> eden;
private final Map<K,V> longterm;
public ConcurrentCache(int size) {
this.size = size;
this.eden = new ConcurrentHashMap<>(size);
this.longterm = new WeakHashMap<>(size);
}
public V get(K key) {
V value = this.eden.get(key);
if (value == null) {
synchronized (longterm) {
value = this.longterm.get(key);
}
if (value != null) {
this.eden.put(key, value);
}
}
return value;
}
public void put(K key, V value) {
if (this.eden.size() >= this.size) {
synchronized (longterm) {
this.longterm.putAll(this.eden);
}
this.eden.clear();
}
this.eden.put(key, value);
}
}
}

View File

@@ -0,0 +1,155 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.beans.FeatureDescriptor;
import java.util.Iterator;
import java.util.Objects;
/**
* @since EL 3.0
*/
public class BeanNameELResolver extends ELResolver {
private final BeanNameResolver beanNameResolver;
public BeanNameELResolver(BeanNameResolver beanNameResolver) {
this.beanNameResolver = beanNameResolver;
}
@Override
public Object getValue(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base != null || !(property instanceof String)) {
return null;
}
String beanName = (String) property;
if (beanNameResolver.isNameResolved(beanName)) {
try {
Object result = beanNameResolver.getBean(beanName);
context.setPropertyResolved(base, property);
return result;
} catch (Throwable t) {
Util.handleThrowable(t);
throw new ELException(t);
}
}
return null;
}
@Override
public void setValue(ELContext context, Object base, Object property,
Object value) {
Objects.requireNonNull(context);
if (base != null || !(property instanceof String)) {
return;
}
String beanName = (String) property;
boolean isResolved = context.isPropertyResolved();
boolean isReadOnly;
try {
isReadOnly = isReadOnly(context, base, property);
} catch (Throwable t) {
Util.handleThrowable(t);
throw new ELException(t);
} finally {
context.setPropertyResolved(isResolved);
}
if (isReadOnly) {
throw new PropertyNotWritableException(Util.message(context,
"beanNameELResolver.beanReadOnly", beanName));
}
if (beanNameResolver.isNameResolved(beanName) ||
beanNameResolver.canCreateBean(beanName)) {
try {
beanNameResolver.setBeanValue(beanName, value);
context.setPropertyResolved(base, property);
} catch (Throwable t) {
Util.handleThrowable(t);
throw new ELException(t);
}
}
}
@Override
public Class<?> getType(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base != null || !(property instanceof String)) {
return null;
}
String beanName = (String) property;
try {
if (beanNameResolver.isNameResolved(beanName)) {
Class<?> result = beanNameResolver.getBean(beanName).getClass();
context.setPropertyResolved(base, property);
return result;
}
} catch (Throwable t) {
Util.handleThrowable(t);
throw new ELException(t);
}
return null;
}
@Override
public boolean isReadOnly(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base != null || !(property instanceof String)) {
// Return value undefined
return false;
}
String beanName = (String) property;
if (beanNameResolver.isNameResolved(beanName)) {
boolean result;
try {
result = beanNameResolver.isReadOnly(beanName);
} catch (Throwable t) {
Util.handleThrowable(t);
throw new ELException(t);
}
context.setPropertyResolved(base, property);
return result;
}
// Return value undefined
return false;
}
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
Object base) {
return null;
}
@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
return String.class;
}
}

View File

@@ -0,0 +1,91 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
/**
* Base implementation that provides a minimal default implementation that is
* intended to be extended by application developers.
*
* @since EL 3.0
*/
public abstract class BeanNameResolver {
/**
* Can this resolver resolve the given bean name?
*
* @param beanName The bean name to resolve
*
* @return This default implementation always returns <code>false</code>
*/
public boolean isNameResolved(String beanName) {
return false;
}
/**
* Returns the named bean.
*
* @param beanName The bean name to return
*
* @return This default implementation always returns <code>null</code>
*/
public Object getBean(String beanName) {
return null;
}
/**
* Sets a value of a bean of the given name. If the named bean does not
* exist and {@link #canCreateBean} returns <code>true</code> then a bean
* is created with the given value.
*
* @param beanName The name of the bean to be set/create
* @param value The value of the bean to set/create
*
* @throws PropertyNotWritableException if the bean is read only
*/
public void setBeanValue(String beanName, Object value)
throws PropertyNotWritableException {
throw new PropertyNotWritableException();
}
/**
* Is the named bean read-only?
*
* @param beanName The name of the bean of interest
*
* @return <code>true</code> if the bean is read only, otherwise
* <code>false</code>
*/
public boolean isReadOnly(String beanName) {
return true;
}
/**
* Is it permitted to create a bean of the given name?
*
* @param beanName The name of the bean of interest
*
* @return <code>true</code> if the bean may be created, otherwise
* <code>false</code>
*/
public boolean canCreateBean(String beanName) {
return false;
}
}

View File

@@ -0,0 +1,233 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.beans.FeatureDescriptor;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
public class CompositeELResolver extends ELResolver {
private static final Class<?> SCOPED_ATTRIBUTE_EL_RESOLVER;
static {
Class<?> clazz = null;
try {
clazz = Class.forName("javax.servlet.jsp.el.ScopedAttributeELResolver");
} catch (ClassNotFoundException e) {
// Ignore. This is expected if using the EL stand-alone
}
SCOPED_ATTRIBUTE_EL_RESOLVER = clazz;
}
private int size;
private ELResolver[] resolvers;
public CompositeELResolver() {
this.size = 0;
this.resolvers = new ELResolver[8];
}
public void add(ELResolver elResolver) {
Objects.requireNonNull(elResolver);
if (this.size >= this.resolvers.length) {
ELResolver[] nr = new ELResolver[this.size * 2];
System.arraycopy(this.resolvers, 0, nr, 0, this.size);
this.resolvers = nr;
}
this.resolvers[this.size++] = elResolver;
}
@Override
public Object getValue(ELContext context, Object base, Object property) {
context.setPropertyResolved(false);
int sz = this.size;
for (int i = 0; i < sz; i++) {
Object result = this.resolvers[i].getValue(context, base, property);
if (context.isPropertyResolved()) {
return result;
}
}
return null;
}
/**
* @since EL 2.2
*/
@Override
public Object invoke(ELContext context, Object base, Object method,
Class<?>[] paramTypes, Object[] params) {
context.setPropertyResolved(false);
int sz = this.size;
for (int i = 0; i < sz; i++) {
Object obj = this.resolvers[i].invoke(context, base, method, paramTypes, params);
if (context.isPropertyResolved()) {
return obj;
}
}
return null;
}
@Override
public Class<?> getType(ELContext context, Object base, Object property) {
context.setPropertyResolved(false);
int sz = this.size;
for (int i = 0; i < sz; i++) {
Class<?> type = this.resolvers[i].getType(context, base, property);
if (context.isPropertyResolved()) {
if (SCOPED_ATTRIBUTE_EL_RESOLVER != null &&
SCOPED_ATTRIBUTE_EL_RESOLVER.isAssignableFrom(resolvers[i].getClass())) {
// Special case since
// javax.servlet.jsp.el.ScopedAttributeELResolver will
// always return Object.class for type
Object value = resolvers[i].getValue(context, base, property);
if (value != null) {
return value.getClass();
}
}
return type;
}
}
return null;
}
@Override
public void setValue(ELContext context, Object base, Object property, Object value) {
context.setPropertyResolved(false);
int sz = this.size;
for (int i = 0; i < sz; i++) {
this.resolvers[i].setValue(context, base, property, value);
if (context.isPropertyResolved()) {
return;
}
}
}
@Override
public boolean isReadOnly(ELContext context, Object base, Object property) {
context.setPropertyResolved(false);
int sz = this.size;
for (int i = 0; i < sz; i++) {
boolean readOnly = this.resolvers[i].isReadOnly(context, base, property);
if (context.isPropertyResolved()) {
return readOnly;
}
}
return false;
}
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
return new FeatureIterator(context, base, this.resolvers, this.size);
}
@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
Class<?> commonType = null;
int sz = this.size;
for (int i = 0; i < sz; i++) {
Class<?> type = this.resolvers[i].getCommonPropertyType(context, base);
if (type != null && (commonType == null || commonType.isAssignableFrom(type))) {
commonType = type;
}
}
return commonType;
}
@Override
public Object convertToType(ELContext context, Object obj, Class<?> type) {
context.setPropertyResolved(false);
int sz = this.size;
for (int i = 0; i < sz; i++) {
Object result = this.resolvers[i].convertToType(context, obj, type);
if (context.isPropertyResolved()) {
return result;
}
}
return null;
}
private static final class FeatureIterator implements Iterator<FeatureDescriptor> {
private final ELContext context;
private final Object base;
private final ELResolver[] resolvers;
private final int size;
private Iterator<FeatureDescriptor> itr;
private int idx;
private FeatureDescriptor next;
public FeatureIterator(ELContext context, Object base, ELResolver[] resolvers, int size) {
this.context = context;
this.base = base;
this.resolvers = resolvers;
this.size = size;
this.idx = 0;
this.guaranteeIterator();
}
private void guaranteeIterator() {
while (this.itr == null && this.idx < this.size) {
this.itr = this.resolvers[this.idx].getFeatureDescriptors(this.context, this.base);
this.idx++;
}
}
@Override
public boolean hasNext() {
if (this.next != null)
return true;
if (this.itr != null) {
while (this.next == null && itr.hasNext()) {
this.next = itr.next();
}
} else {
return false;
}
if (this.next == null) {
this.itr = null;
this.guaranteeIterator();
}
return hasNext();
}
@Override
public FeatureDescriptor next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
FeatureDescriptor result = this.next;
this.next = null;
return result;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
}

View File

@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
/**
* @since EL 3.0
*/
public class ELClass {
private final Class<?> clazz;
public ELClass(Class<?> clazz) {
this.clazz = clazz;
}
public Class<?> getKlass() {
return clazz;
}
}

View File

@@ -0,0 +1,306 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
public abstract class ELContext {
private Locale locale;
private Map<Class<?>, Object> map;
private boolean resolved;
private ImportHandler importHandler = null;
private List<EvaluationListener> listeners = new ArrayList<>();
private Deque<Map<String,Object>> lambdaArguments = new LinkedList<>();
public ELContext() {
this.resolved = false;
}
public void setPropertyResolved(boolean resolved) {
this.resolved = resolved;
}
/**
* Mark the given property as resolved and notify any interested listeners.
*
* @param base The base object on which the property was found
* @param property The property that was resolved
*
* @since EL 3.0
*/
public void setPropertyResolved(Object base, Object property) {
setPropertyResolved(true);
notifyPropertyResolved(base, property);
}
public boolean isPropertyResolved() {
return this.resolved;
}
// Can't use Class<?> because API needs to match specification
/**
* Add an object to this EL context under the given key.
*
* @param key The key under which to store the object
* @param contextObject The object to add
*
* @throws NullPointerException
* If the supplied key or context is <code>null</code>
*/
public void putContext(@SuppressWarnings("rawtypes") Class key,
Object contextObject) {
Objects.requireNonNull(key);
Objects.requireNonNull(contextObject);
if (this.map == null) {
this.map = new HashMap<>();
}
this.map.put(key, contextObject);
}
// Can't use Class<?> because API needs to match specification
/**
* Obtain the context object for the given key.
*
* @param key The key of the required context object
*
* @return The value of the context object associated with the given key
*
* @throws NullPointerException
* If the supplied key is <code>null</code>
*/
public Object getContext(@SuppressWarnings("rawtypes") Class key) {
Objects.requireNonNull(key);
if (this.map == null) {
return null;
}
return this.map.get(key);
}
public abstract ELResolver getELResolver();
/**
* Obtain the ImportHandler for this ELContext, creating one if necessary.
* This method is not thread-safe.
*
* @return the ImportHandler for this ELContext.
*
* @since EL 3.0
*/
public ImportHandler getImportHandler() {
if (importHandler == null) {
importHandler = new ImportHandler();
}
return importHandler;
}
public abstract FunctionMapper getFunctionMapper();
public Locale getLocale() {
return this.locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
}
public abstract VariableMapper getVariableMapper();
/**
* Register an EvaluationListener with this ELContext.
*
* @param listener The EvaluationListener to register
*
* @since EL 3.0
*/
public void addEvaluationListener(EvaluationListener listener) {
listeners.add(listener);
}
/**
* Obtain the list of registered EvaluationListeners.
*
* @return A list of the EvaluationListener registered with this ELContext
*
* @since EL 3.0
*/
public List<EvaluationListener> getEvaluationListeners() {
return listeners;
}
/**
* Notify interested listeners that an expression will be evaluated.
*
* @param expression The expression that will be evaluated
*
* @since EL 3.0
*/
public void notifyBeforeEvaluation(String expression) {
for (EvaluationListener listener : listeners) {
try {
listener.beforeEvaluation(this, expression);
} catch (Throwable t) {
Util.handleThrowable(t);
// Ignore - no option to log
}
}
}
/**
* Notify interested listeners that an expression has been evaluated.
*
* @param expression The expression that was evaluated
*
* @since EL 3.0
*/
public void notifyAfterEvaluation(String expression) {
for (EvaluationListener listener : listeners) {
try {
listener.afterEvaluation(this, expression);
} catch (Throwable t) {
Util.handleThrowable(t);
// Ignore - no option to log
}
}
}
/**
* Notify interested listeners that a property has been resolved.
*
* @param base The object on which the property was resolved
* @param property The property that was resolved
*
* @since EL 3.0
*/
public void notifyPropertyResolved(Object base, Object property) {
for (EvaluationListener listener : listeners) {
try {
listener.propertyResolved(this, base, property);
} catch (Throwable t) {
Util.handleThrowable(t);
// Ignore - no option to log
}
}
}
/**
* Determine if the specified name is recognised as the name of a lambda
* argument.
*
* @param name The name of the lambda argument
*
* @return <code>true</code> if the name is recognised as the name of a
* lambda argument, otherwise <code>false</code>
*
* @since EL 3.0
*/
public boolean isLambdaArgument(String name) {
for (Map<String,Object> arguments : lambdaArguments) {
if (arguments.containsKey(name)) {
return true;
}
}
return false;
}
/**
* Obtain the value of the lambda argument with the given name.
*
* @param name The name of the lambda argument
*
* @return The value of the specified argument
*
* @since EL 3.0
*/
public Object getLambdaArgument(String name) {
for (Map<String,Object> arguments : lambdaArguments) {
Object result = arguments.get(name);
if (result != null) {
return result;
}
}
return null;
}
/**
* Called when starting to evaluate a lambda expression so that the
* arguments are available to the EL context during evaluation.
*
* @param arguments The arguments in scope for the current lambda
* expression.
* @since EL 3.0
*/
public void enterLambdaScope(Map<String,Object> arguments) {
lambdaArguments.push(arguments);
}
/**
* Called after evaluating a lambda expression to signal that the arguments
* are no longer required.
*
* @since EL 3.0
*/
public void exitLambdaScope() {
lambdaArguments.pop();
}
/**
* Coerce the supplied object to the requested type.
*
* @param obj The object to be coerced
* @param type The type to which the object should be coerced
*
* @return An instance of the requested type.
*
* @throws ELException
* If the conversion fails
*
* @since EL 3.0
*/
public Object convertToType(Object obj, Class<?> type) {
boolean originalResolved = isPropertyResolved();
setPropertyResolved(false);
try {
ELResolver resolver = getELResolver();
if (resolver != null) {
Object result = resolver.convertToType(this, obj, type);
if (isPropertyResolved()) {
return result;
}
}
} finally {
setPropertyResolved(originalResolved);
}
return ELManager.getExpressionFactory().coerceToType(obj, type);
}
}

View File

@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.util.EventObject;
public class ELContextEvent extends EventObject {
private static final long serialVersionUID = 1255131906285426769L;
/**
* @param source The EL context that was the source of this event
*/
public ELContextEvent(ELContext source) {
super(source);
}
public ELContext getELContext() {
return (ELContext) this.getSource();
}
}

View File

@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
/**
* @author Jacob Hookom [jacob/hookom.net]
*
*/
public interface ELContextListener extends java.util.EventListener {
public void contextCreated(ELContextEvent event);
}

View File

@@ -0,0 +1,68 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
/**
* Represents any of the exception conditions that can arise during expression
* evaluation.
*
* @since 2.1
*/
public class ELException extends RuntimeException {
private static final long serialVersionUID = -6228042809457459161L;
/**
* Creates an ELException with no detail message
*/
public ELException() {
super();
}
/**
* Creates an ELException with the provided detail message.
*
* @param message
* the detail message
*/
public ELException(String message) {
super(message);
}
/**
* Creates an ELException with the given cause
*
* @param cause
* the originating cause of this exception
*/
public ELException(Throwable cause) {
super(cause);
}
/**
* Creates an ELException with the given detail message and root cause.
*
* @param message
* the detail message
* @param cause
* the originating cause of this exception
*/
public ELException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -0,0 +1,90 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.lang.reflect.Method;
import java.util.Map;
/**
* @since EL 3.0
*/
public class ELManager {
private StandardELContext context = null;
public static ExpressionFactory getExpressionFactory() {
return Util.getExpressionFactory();
}
public StandardELContext getELContext() {
if (context == null) {
context = new StandardELContext(getExpressionFactory());
}
return context;
}
public ELContext setELContext(ELContext context) {
StandardELContext oldContext = this.context;
this.context = new StandardELContext(context);
return oldContext;
}
public void addBeanNameResolver(BeanNameResolver beanNameResolver) {
getELContext().addELResolver(new BeanNameELResolver(beanNameResolver));
}
public void addELResolver(ELResolver resolver) {
getELContext().addELResolver(resolver);
}
public void mapFunction(String prefix, String function, Method method) {
getELContext().getFunctionMapper().mapFunction(
prefix, function, method);
}
public void setVariable(String variable, ValueExpression expression) {
getELContext().getVariableMapper().setVariable(variable, expression);
}
public void importStatic(String staticMemberName)
throws javax.el.ELException {
getELContext().getImportHandler().importStatic(staticMemberName);
}
public void importClass(String className) throws javax.el.ELException {
getELContext().getImportHandler().importClass(className);
}
public void importPackage(String packageName) {
getELContext().getImportHandler().importPackage(packageName);
}
public Object defineBean(String name, Object bean) {
Map<String,Object> localBeans = getELContext().getLocalBeans();
if (bean == null) {
return localBeans.remove(name);
} else {
return localBeans.put(name, bean);
}
}
public void addEvaluationListener(EvaluationListener listener) {
getELContext().addEvaluationListener(listener);
}
}

View File

@@ -0,0 +1,362 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashSet;
import java.util.Set;
/**
* @since EL 3.0
*/
public class ELProcessor {
private static final Set<String> PRIMITIVES = new HashSet<>();
static {
PRIMITIVES.add("boolean");
PRIMITIVES.add("byte");
PRIMITIVES.add("char");
PRIMITIVES.add("double");
PRIMITIVES.add("float");
PRIMITIVES.add("int");
PRIMITIVES.add("long");
PRIMITIVES.add("short");
}
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private final ELManager manager = new ELManager();
private final ELContext context = manager.getELContext();
private final ExpressionFactory factory = ELManager.getExpressionFactory();
public ELManager getELManager() {
return manager;
}
public Object eval(String expression) {
return getValue(expression, Object.class);
}
public Object getValue(String expression, Class<?> expectedType) {
ValueExpression ve = factory.createValueExpression(
context, bracket(expression), expectedType);
return ve.getValue(context);
}
public void setValue(String expression, Object value) {
ValueExpression ve = factory.createValueExpression(
context, bracket(expression), Object.class);
ve.setValue(context, value);
}
public void setVariable(String variable, String expression) {
if (expression == null) {
manager.setVariable(variable, null);
} else {
ValueExpression ve = factory.createValueExpression(
context, bracket(expression), Object.class);
manager.setVariable(variable, ve);
}
}
public void defineFunction(String prefix, String function, String className,
String methodName) throws ClassNotFoundException,
NoSuchMethodException {
if (prefix == null || function == null || className == null ||
methodName == null) {
throw new NullPointerException(Util.message(
context, "elProcessor.defineFunctionNullParams"));
}
// Check the imports
Class<?> clazz = context.getImportHandler().resolveClass(className);
if (clazz == null) {
clazz = Class.forName(className, true, Util.getContextClassLoader());
}
if (!Modifier.isPublic(clazz.getModifiers())) {
throw new ClassNotFoundException(Util.message(context,
"elProcessor.defineFunctionInvalidClass", className));
}
MethodSignature sig =
new MethodSignature(context, methodName, className);
if (function.length() == 0) {
function = sig.getName();
}
// Only returns public methods. Java 9+ access is checked below.
Method methods[] = clazz.getMethods();
JreCompat jreCompat = JreCompat.getInstance();
for (Method method : methods) {
if (!Modifier.isStatic(method.getModifiers())) {
continue;
}
if (!jreCompat.canAcccess(null, method)) {
continue;
}
if (method.getName().equals(sig.getName())) {
if (sig.getParamTypeNames() == null) {
// Only a name provided, no signature so map the first
// method declared
manager.mapFunction(prefix, function, method);
return;
}
if (sig.getParamTypeNames().length != method.getParameterTypes().length) {
continue;
}
if (sig.getParamTypeNames().length == 0) {
manager.mapFunction(prefix, function, method);
return;
} else {
Class<?>[] types = method.getParameterTypes();
String[] typeNames = sig.getParamTypeNames();
if (types.length == typeNames.length) {
boolean match = true;
for (int i = 0; i < types.length; i++) {
if (i == types.length -1 && method.isVarArgs()) {
String typeName = typeNames[i];
if (typeName.endsWith("...")) {
typeName = typeName.substring(0, typeName.length() - 3);
if (!typeName.equals(types[i].getName())) {
match = false;
}
} else {
match = false;
}
} else if (!types[i].getName().equals(typeNames[i])) {
match = false;
break;
}
}
if (match) {
manager.mapFunction(prefix, function, method);
return;
}
}
}
}
}
throw new NoSuchMethodException(Util.message(context,
"elProcessor.defineFunctionNoMethod", methodName, className));
}
/**
* Map a method to a function name.
*
* @param prefix Function prefix
* @param function Function name
* @param method Method
*
* @throws NullPointerException
* If any of the arguments are null
* @throws NoSuchMethodException
* If the method is not static
*/
public void defineFunction(String prefix, String function, Method method)
throws java.lang.NoSuchMethodException {
if (prefix == null || function == null || method == null) {
throw new NullPointerException(Util.message(
context, "elProcessor.defineFunctionNullParams"));
}
int modifiers = method.getModifiers();
// Check for static, public method and module access for Java 9+
JreCompat jreCompat = JreCompat.getInstance();
if (!Modifier.isStatic(modifiers) || !jreCompat.canAcccess(null, method)) {
throw new NoSuchMethodException(Util.message(context,
"elProcessor.defineFunctionInvalidMethod", method.getName(),
method.getDeclaringClass().getName()));
}
manager.mapFunction(prefix, function, method);
}
public void defineBean(String name, Object bean) {
manager.defineBean(name, bean);
}
private static String bracket(String expression) {
return "${" + expression + "}";
}
private static class MethodSignature {
private final String name;
private final String[] parameterTypeNames;
public MethodSignature(ELContext context, String methodName,
String className) throws NoSuchMethodException {
int paramIndex = methodName.indexOf('(');
if (paramIndex == -1) {
name = methodName.trim();
parameterTypeNames = null;
} else {
String returnTypeAndName = methodName.substring(0, paramIndex).trim();
// Assume that the return type and the name are separated by
// whitespace. Given the use of trim() above, there should only
// be one sequence of whitespace characters.
int wsPos = -1;
for (int i = 0; i < returnTypeAndName.length(); i++) {
if (Character.isWhitespace(returnTypeAndName.charAt(i))) {
wsPos = i;
break;
}
}
if (wsPos == -1) {
throw new NoSuchMethodException();
}
name = returnTypeAndName.substring(wsPos).trim();
String paramString = methodName.substring(paramIndex).trim();
// We know the params start with '(', check they end with ')'
if (!paramString.endsWith(")")) {
throw new NoSuchMethodException(Util.message(context,
"elProcessor.defineFunctionInvalidParameterList",
paramString, methodName, className));
}
// Trim '(' and ')'
paramString = paramString.substring(1, paramString.length() - 1).trim();
if (paramString.length() == 0) {
parameterTypeNames = EMPTY_STRING_ARRAY;
} else {
parameterTypeNames = paramString.split(",");
ImportHandler importHandler = context.getImportHandler();
for (int i = 0; i < parameterTypeNames.length; i++) {
String parameterTypeName = parameterTypeNames[i].trim();
int dimension = 0;
int bracketPos = parameterTypeName.indexOf('[');
if (bracketPos > -1) {
String parameterTypeNameOnly =
parameterTypeName.substring(0, bracketPos).trim();
while (bracketPos > -1) {
dimension++;
bracketPos = parameterTypeName.indexOf('[', bracketPos+ 1);
}
parameterTypeName = parameterTypeNameOnly;
}
boolean varArgs = false;
if (parameterTypeName.endsWith("...")) {
varArgs = true;
dimension = 1;
parameterTypeName = parameterTypeName.substring(
0, parameterTypeName.length() -3).trim();
}
boolean isPrimitive = PRIMITIVES.contains(parameterTypeName);
if (isPrimitive && dimension > 0) {
// When in an array, class name changes for primitive
switch(parameterTypeName)
{
case "boolean":
parameterTypeName = "Z";
break;
case "byte":
parameterTypeName = "B";
break;
case "char":
parameterTypeName = "C";
break;
case "double":
parameterTypeName = "D";
break;
case "float":
parameterTypeName = "F";
break;
case "int":
parameterTypeName = "I";
break;
case "long":
parameterTypeName = "J";
break;
case "short":
parameterTypeName = "S";
break;
default:
// Should never happen
break;
}
} else if (!isPrimitive &&
!parameterTypeName.contains(".")) {
Class<?> clazz = importHandler.resolveClass(
parameterTypeName);
if (clazz == null) {
throw new NoSuchMethodException(Util.message(
context,
"elProcessor.defineFunctionInvalidParameterTypeName",
parameterTypeNames[i], methodName,
className));
}
parameterTypeName = clazz.getName();
}
if (dimension > 0) {
// Convert to array form of class name
StringBuilder sb = new StringBuilder();
for (int j = 0; j < dimension; j++) {
sb.append('[');
}
if (!isPrimitive) {
sb.append('L');
}
sb.append(parameterTypeName);
if (!isPrimitive) {
sb.append(';');
}
parameterTypeName = sb.toString();
}
if (varArgs) {
parameterTypeName += "...";
}
parameterTypeNames[i] = parameterTypeName;
}
}
}
}
public String getName() {
return name;
}
/**
* @return <code>null</code> if just the method name was specified, an
* empty List if an empty parameter list was specified - i.e. ()
* - otherwise an ordered list of parameter type names
*/
public String[] getParamTypeNames() {
return parameterTypeNames;
}
}
}

View File

@@ -0,0 +1,142 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.util.Iterator;
/**
* @author Jacob Hookom [jacob/hookom.net]
*
*/
public abstract class ELResolver {
public static final String TYPE = "type";
public static final String RESOLVABLE_AT_DESIGN_TIME = "resolvableAtDesignTime";
/**
* @param context The EL context for this evaluation
* @param base The base object on which the property is to be found
* @param property The property whose value is to be returned
* @return the value of the provided property
* @throws NullPointerException
* If the supplied context is <code>null</code>
* @throws PropertyNotFoundException
* If the base/property combination provided to the resolver is
* one that the resolver can handle but no match was found or a
* match was found but was not readable
* @throws ELException
* Wraps any exception throw whilst resolving the property
*/
public abstract Object getValue(ELContext context, Object base,
Object property);
/**
* Invokes a method on the the given object. This default implementation
* always returns <code>null</code>.
*
* @param context The EL context for this evaluation
* @param base The base object on which the method is to be found
* @param method The method to invoke
* @param paramTypes The types of the parameters of the method to invoke
* @param params The parameters with which to invoke the method
*
* @return Always <code>null</code>
*
* @since EL 2.2
*/
public Object invoke(ELContext context, Object base, Object method,
Class<?>[] paramTypes, Object[] params) {
return null;
}
/**
* @param context The EL context for this evaluation
* @param base The base object on which the property is to be found
* @param property The property whose type is to be returned
* @return the type of the provided property
* @throws NullPointerException
* If the supplied context is <code>null</code>
* @throws PropertyNotFoundException
* If the base/property combination provided to the resolver is
* one that the resolver can handle but no match was found or a
* match was found but was not readable
* @throws ELException
* Wraps any exception throw whilst resolving the property
*/
public abstract Class<?> getType(ELContext context, Object base,
Object property);
/**
* @param context The EL context for this evaluation
* @param base The base object on which the property is to be found
* @param property The property whose value is to be set
* @param value The value to set the property to
* @throws NullPointerException
* If the supplied context is <code>null</code>
* @throws PropertyNotFoundException
* If the base/property combination provided to the resolver is
* one that the resolver can handle but no match was found
* @throws PropertyNotWritableException
* If the base/property combination provided to the resolver is
* one that the resolver can handle but the property was not
* writable
* @throws ELException
* Wraps any exception throw whilst resolving the property
*/
public abstract void setValue(ELContext context, Object base,
Object property, Object value);
/**
* @param context The EL context for this evaluation
* @param base The base object on which the property is to be found
* @param property The property to be checked for read only status
* @return <code>true</code> if the identified property is read only,
* otherwise <code>false</code>
* @throws NullPointerException
* If the supplied context is <code>null</code>
* @throws PropertyNotFoundException
* If the base/property combination provided to the resolver is
* one that the resolver can handle but no match was found
* @throws ELException
* Wraps any exception throw whilst resolving the property
*/
public abstract boolean isReadOnly(ELContext context, Object base,
Object property);
public abstract Iterator<java.beans.FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base);
public abstract Class<?> getCommonPropertyType(ELContext context,
Object base);
/**
* Converts the given object to the given type. This default implementation
* always returns <code>null</code>.
*
* @param context The EL context for this evaluation
* @param obj The object to convert
* @param type The type to which the object should be converted
*
* @return Always <code>null</code>
*
* @since EL 3.0
*/
public Object convertToType(ELContext context, Object obj, Class<?> type) {
context.setPropertyResolved(false);
return null;
}
}

View File

@@ -0,0 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
/**
* @since EL 3.0
*/
public abstract class EvaluationListener {
/**
* Fired before the evaluation of the expression.
*
* @param context The EL context in which the expression will be
* evaluated
* @param expression The expression that will be evaluated
*/
public void beforeEvaluation(ELContext context, String expression) {
// NO-OP
}
/**
* Fired after the evaluation of the expression.
*
* @param context The EL context in which the expression was evaluated
* @param expression The expression that was evaluated
*/
public void afterEvaluation(ELContext context, String expression) {
// NO-OP
}
/**
* Fired after a property has been resolved.
*
* @param context The EL context in which the property was resolved
* @param base The base object on which the property was resolved
* @param property The property that was resolved
*/
public void propertyResolved(ELContext context, Object base, Object property) {
// NO-OP
}
}

View File

@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.io.Serializable;
/**
*
*/
public abstract class Expression implements Serializable {
private static final long serialVersionUID = -6663767980471823812L;
public abstract String getExpressionString();
@Override
public abstract boolean equals(Object obj);
@Override
public abstract int hashCode();
public abstract boolean isLiteralText();
}

View File

@@ -0,0 +1,414 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
*
* @since 2.1
*/
public abstract class ExpressionFactory {
private static final boolean IS_SECURITY_ENABLED =
(System.getSecurityManager() != null);
private static final String PROPERTY_NAME = "javax.el.ExpressionFactory";
private static final String PROPERTY_FILE;
private static final CacheValue nullTcclFactory = new CacheValue();
private static final ConcurrentMap<CacheKey, CacheValue> factoryCache =
new ConcurrentHashMap<>();
static {
if (IS_SECURITY_ENABLED) {
PROPERTY_FILE = AccessController.doPrivileged(
new PrivilegedAction<String>(){
@Override
public String run() {
return System.getProperty("java.home") + File.separator +
"lib" + File.separator + "el.properties";
}
}
);
} else {
PROPERTY_FILE = System.getProperty("java.home") + File.separator + "lib" +
File.separator + "el.properties";
}
}
/**
* Create a new {@link ExpressionFactory}. The class to use is determined by
* the following search order:
* <ol>
* <li>services API (META-INF/services/javax.el.ExpressionFactory)</li>
* <li>$JRE_HOME/lib/el.properties - key javax.el.ExpressionFactory</li>
* <li>javax.el.ExpressionFactory</li>
* <li>Platform default implementation -
* org.apache.el.ExpressionFactoryImpl</li>
* </ol>
* @return the new ExpressionFactory
*/
public static ExpressionFactory newInstance() {
return newInstance(null);
}
/**
* Create a new {@link ExpressionFactory} passing in the provided
* {@link Properties}. Search order is the same as {@link #newInstance()}.
*
* @param properties the properties to be passed to the new instance (may be null)
* @return the new ExpressionFactory
*/
public static ExpressionFactory newInstance(Properties properties) {
ExpressionFactory result = null;
ClassLoader tccl = Util.getContextClassLoader();
CacheValue cacheValue;
Class<?> clazz;
if (tccl == null) {
cacheValue = nullTcclFactory;
} else {
CacheKey key = new CacheKey(tccl);
cacheValue = factoryCache.get(key);
if (cacheValue == null) {
CacheValue newCacheValue = new CacheValue();
cacheValue = factoryCache.putIfAbsent(key, newCacheValue);
if (cacheValue == null) {
cacheValue = newCacheValue;
}
}
}
final Lock readLock = cacheValue.getLock().readLock();
readLock.lock();
try {
clazz = cacheValue.getFactoryClass();
} finally {
readLock.unlock();
}
if (clazz == null) {
String className = null;
try {
final Lock writeLock = cacheValue.getLock().writeLock();
writeLock.lock();
try {
className = cacheValue.getFactoryClassName();
if (className == null) {
className = discoverClassName(tccl);
cacheValue.setFactoryClassName(className);
}
if (tccl == null) {
clazz = Class.forName(className);
} else {
clazz = tccl.loadClass(className);
}
cacheValue.setFactoryClass(clazz);
} finally {
writeLock.unlock();
}
} catch (ClassNotFoundException e) {
throw new ELException(Util.message(null, "expressionFactory.cannotFind", className), e);
}
}
try {
Constructor<?> constructor = null;
// Do we need to look for a constructor that will take properties?
if (properties != null) {
try {
constructor = clazz.getConstructor(Properties.class);
} catch (SecurityException se) {
throw new ELException(se);
} catch (NoSuchMethodException nsme) {
// This can be ignored
// This is OK for this constructor not to exist
}
}
if (constructor == null) {
result = (ExpressionFactory) clazz.getConstructor().newInstance();
} else {
result =
(ExpressionFactory) constructor.newInstance(properties);
}
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
Util.handleThrowable(cause);
throw new ELException(Util.message(null, "expressionFactory.cannotCreate", clazz.getName()), e);
} catch (ReflectiveOperationException | IllegalArgumentException e) {
throw new ELException(Util.message(null, "expressionFactory.cannotCreate", clazz.getName()), e);
}
return result;
}
/**
* Create a new value expression.
*
* @param context The EL context for this evaluation
* @param expression The String representation of the value expression
* @param expectedType The expected type of the result of evaluating the
* expression
*
* @return A new value expression formed from the input parameters
*
* @throws NullPointerException
* If the expected type is <code>null</code>
* @throws ELException
* If there are syntax errors in the provided expression
*/
public abstract ValueExpression createValueExpression(ELContext context,
String expression, Class<?> expectedType);
public abstract ValueExpression createValueExpression(Object instance,
Class<?> expectedType);
/**
* Create a new method expression instance.
*
* @param context The EL context for this evaluation
* @param expression The String representation of the method
* expression
* @param expectedReturnType The expected type of the result of invoking the
* method
* @param expectedParamTypes The expected types of the input parameters
*
* @return A new method expression formed from the input parameters.
*
* @throws NullPointerException
* If the expected parameters types are <code>null</code>
* @throws ELException
* If there are syntax errors in the provided expression
*/
public abstract MethodExpression createMethodExpression(ELContext context,
String expression, Class<?> expectedReturnType,
Class<?>[] expectedParamTypes);
/**
* Coerce the supplied object to the requested type.
*
* @param obj The object to be coerced
* @param expectedType The type to which the object should be coerced
*
* @return An instance of the requested type.
*
* @throws ELException
* If the conversion fails
*/
public abstract Object coerceToType(Object obj, Class<?> expectedType);
/**
* @return This default implementation returns null
*
* @since EL 3.0
*/
public ELResolver getStreamELResolver() {
return null;
}
/**
* @return This default implementation returns null
*
* @since EL 3.0
*/
public Map<String,Method> getInitFunctionMap() {
return null;
}
/**
* Key used to cache ExpressionFactory discovery information per class
* loader. The class loader reference is never {@code null}, because
* {@code null} tccl is handled separately.
*/
private static class CacheKey {
private final int hash;
private final WeakReference<ClassLoader> ref;
public CacheKey(ClassLoader cl) {
hash = cl.hashCode();
ref = new WeakReference<>(cl);
}
@Override
public int hashCode() {
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof CacheKey)) {
return false;
}
ClassLoader thisCl = ref.get();
if (thisCl == null) {
return false;
}
return thisCl == ((CacheKey) obj).ref.get();
}
}
private static class CacheValue {
private final ReadWriteLock lock = new ReentrantReadWriteLock();
private String className;
private WeakReference<Class<?>> ref;
public CacheValue() {
}
public ReadWriteLock getLock() {
return lock;
}
public String getFactoryClassName() {
return className;
}
public void setFactoryClassName(String className) {
this.className = className;
}
public Class<?> getFactoryClass() {
return ref != null ? ref.get() : null;
}
public void setFactoryClass(Class<?> clazz) {
ref = new WeakReference<Class<?>>(clazz);
}
}
/**
* Discover the name of class that implements ExpressionFactory.
*
* @param tccl
* {@code ClassLoader}
* @return Class name. There is default, so it is never {@code null}.
*/
private static String discoverClassName(ClassLoader tccl) {
String className = null;
// First services API
className = getClassNameServices(tccl);
if (className == null) {
if (IS_SECURITY_ENABLED) {
className = AccessController.doPrivileged(
new PrivilegedAction<String>() {
@Override
public String run() {
return getClassNameJreDir();
}
}
);
} else {
// Second el.properties file
className = getClassNameJreDir();
}
}
if (className == null) {
if (IS_SECURITY_ENABLED) {
className = AccessController.doPrivileged(
new PrivilegedAction<String>() {
@Override
public String run() {
return getClassNameSysProp();
}
}
);
} else {
// Third system property
className = getClassNameSysProp();
}
}
if (className == null) {
// Fourth - default
className = "org.apache.el.ExpressionFactoryImpl";
}
return className;
}
private static String getClassNameServices(ClassLoader tccl) {
ExpressionFactory result = null;
ServiceLoader<ExpressionFactory> serviceLoader = ServiceLoader.load(ExpressionFactory.class, tccl);
Iterator<ExpressionFactory> iter = serviceLoader.iterator();
while (result == null && iter.hasNext()) {
result = iter.next();
}
if (result == null) {
return null;
}
return result.getClass().getName();
}
private static String getClassNameJreDir() {
File file = new File(PROPERTY_FILE);
if (file.canRead()) {
try (InputStream is = new FileInputStream(file)){
Properties props = new Properties();
props.load(is);
String value = props.getProperty(PROPERTY_NAME);
if (value != null && value.trim().length() > 0) {
return value.trim();
}
} catch (FileNotFoundException e) {
// Should not happen - ignore it if it does
} catch (IOException e) {
throw new ELException(Util.message(null, "expressionFactory.readFailed", PROPERTY_FILE), e);
}
}
return null;
}
private static final String getClassNameSysProp() {
String value = System.getProperty(PROPERTY_NAME);
if (value != null && value.trim().length() > 0) {
return value.trim();
}
return null;
}
}

View File

@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.lang.reflect.Method;
public abstract class FunctionMapper {
public abstract Method resolveFunction(String prefix, String localName);
/**
* Map a method to a function name.
*
* @param prefix Function prefix
* @param localName Function name
* @param method Method
*
* @since EL 3.0
*/
public void mapFunction(String prefix, String localName, Method method) {
// NO-OP
}
}

View File

@@ -0,0 +1,491 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
* @since EL 3.0
*/
public class ImportHandler {
private static final Map<String,Set<String>> standardPackages = new HashMap<>();
static {
// Servlet 4.0
Set<String> servletClassNames = new HashSet<>();
// Interfaces
servletClassNames.add("AsyncContext");
servletClassNames.add("AsyncListener");
servletClassNames.add("Filter");
servletClassNames.add("FilterChain");
servletClassNames.add("FilterConfig");
servletClassNames.add("FilterRegistration");
servletClassNames.add("FilterRegistration.Dynamic");
servletClassNames.add("ReadListener");
servletClassNames.add("Registration");
servletClassNames.add("Registration.Dynamic");
servletClassNames.add("RequestDispatcher");
servletClassNames.add("Servlet");
servletClassNames.add("ServletConfig");
servletClassNames.add("ServletContainerInitializer");
servletClassNames.add("ServletContext");
servletClassNames.add("ServletContextAttributeListener");
servletClassNames.add("ServletContextListener");
servletClassNames.add("ServletRegistration");
servletClassNames.add("ServletRegistration.Dynamic");
servletClassNames.add("ServletRequest");
servletClassNames.add("ServletRequestAttributeListener");
servletClassNames.add("ServletRequestListener");
servletClassNames.add("ServletResponse");
servletClassNames.add("SessionCookieConfig");
servletClassNames.add("SingleThreadModel");
servletClassNames.add("WriteListener");
// Classes
servletClassNames.add("AsyncEvent");
servletClassNames.add("GenericFilter");
servletClassNames.add("GenericServlet");
servletClassNames.add("HttpConstraintElement");
servletClassNames.add("HttpMethodConstraintElement");
servletClassNames.add("MultipartConfigElement");
servletClassNames.add("ServletContextAttributeEvent");
servletClassNames.add("ServletContextEvent");
servletClassNames.add("ServletInputStream");
servletClassNames.add("ServletOutputStream");
servletClassNames.add("ServletRequestAttributeEvent");
servletClassNames.add("ServletRequestEvent");
servletClassNames.add("ServletRequestWrapper");
servletClassNames.add("ServletResponseWrapper");
servletClassNames.add("ServletSecurityElement");
// Enums
servletClassNames.add("DispatcherType");
servletClassNames.add("SessionTrackingMode");
// Exceptions
servletClassNames.add("ServletException");
servletClassNames.add("UnavailableException");
standardPackages.put("javax.servlet", servletClassNames);
// Servlet 4.0
Set<String> servletHttpClassNames = new HashSet<>();
// Interfaces
servletHttpClassNames.add("HttpServletMapping");
servletHttpClassNames.add("HttpServletRequest");
servletHttpClassNames.add("HttpServletResponse");
servletHttpClassNames.add("HttpSession");
servletHttpClassNames.add("HttpSessionActivationListener");
servletHttpClassNames.add("HttpSessionAttributeListener");
servletHttpClassNames.add("HttpSessionBindingListener");
servletHttpClassNames.add("HttpSessionContext");
servletHttpClassNames.add("HttpSessionIdListener");
servletHttpClassNames.add("HttpSessionListener");
servletHttpClassNames.add("HttpUpgradeHandler");
servletHttpClassNames.add("Part");
servletHttpClassNames.add("PushBuilder");
servletHttpClassNames.add("WebConnection");
// Classes
servletHttpClassNames.add("Cookie");
servletHttpClassNames.add("HttpFilter");
servletHttpClassNames.add("HttpServlet");
servletHttpClassNames.add("HttpServletRequestWrapper");
servletHttpClassNames.add("HttpServletResponseWrapper");
servletHttpClassNames.add("HttpSessionBindingEvent");
servletHttpClassNames.add("HttpSessionEvent");
servletHttpClassNames.add("HttpUtils");
// Enums
servletHttpClassNames.add("MappingMatch");
standardPackages.put("javax.servlet.http", servletHttpClassNames);
// JSP 2.3
Set<String> servletJspClassNames = new HashSet<>();
//Interfaces
servletJspClassNames.add("HttpJspPage");
servletJspClassNames.add("JspApplicationContext");
servletJspClassNames.add("JspPage");
// Classes
servletJspClassNames.add("ErrorData");
servletJspClassNames.add("JspContext");
servletJspClassNames.add("JspEngineInfo");
servletJspClassNames.add("JspFactory");
servletJspClassNames.add("JspWriter");
servletJspClassNames.add("PageContext");
servletJspClassNames.add("Exceptions");
servletJspClassNames.add("JspException");
servletJspClassNames.add("JspTagException");
servletJspClassNames.add("SkipPageException");
standardPackages.put("javax.servlet.jsp", servletJspClassNames);
Set<String> javaLangClassNames = new HashSet<>();
// Taken from Java 14 EA27 Javadoc
// Interfaces
javaLangClassNames.add("Appendable");
javaLangClassNames.add("AutoCloseable");
javaLangClassNames.add("CharSequence");
javaLangClassNames.add("Cloneable");
javaLangClassNames.add("Comparable");
javaLangClassNames.add("Iterable");
javaLangClassNames.add("ProcessHandle");
javaLangClassNames.add("ProcessHandle.Info");
javaLangClassNames.add("Readable");
javaLangClassNames.add("Runnable");
javaLangClassNames.add("StackWalker.StackFrame");
javaLangClassNames.add("System.Logger");
javaLangClassNames.add("Thread.UncaughtExceptionHandler");
//Classes
javaLangClassNames.add("Boolean");
javaLangClassNames.add("Byte");
javaLangClassNames.add("Character");
javaLangClassNames.add("Character.Subset");
javaLangClassNames.add("Character.UnicodeBlock");
javaLangClassNames.add("Class");
javaLangClassNames.add("ClassLoader");
javaLangClassNames.add("ClassValue");
javaLangClassNames.add("Compiler");
javaLangClassNames.add("Double");
javaLangClassNames.add("Enum");
javaLangClassNames.add("Enum.EnumDesc");
javaLangClassNames.add("Float");
javaLangClassNames.add("InheritableThreadLocal");
javaLangClassNames.add("Integer");
javaLangClassNames.add("Long");
javaLangClassNames.add("Math");
javaLangClassNames.add("Module");
javaLangClassNames.add("ModuleLayer");
javaLangClassNames.add("ModuleLayer.Controller");
javaLangClassNames.add("Number");
javaLangClassNames.add("Object");
javaLangClassNames.add("Package");
javaLangClassNames.add("Process");
javaLangClassNames.add("ProcessBuilder");
javaLangClassNames.add("ProcessBuilder.Redirect");
javaLangClassNames.add("Record");
javaLangClassNames.add("Runtime");
javaLangClassNames.add("Runtime.Version");
javaLangClassNames.add("RuntimePermission");
javaLangClassNames.add("SecurityManager");
javaLangClassNames.add("Short");
javaLangClassNames.add("StackTraceElement");
javaLangClassNames.add("StackWalker");
javaLangClassNames.add("StrictMath");
javaLangClassNames.add("String");
javaLangClassNames.add("StringBuffer");
javaLangClassNames.add("StringBuilder");
javaLangClassNames.add("System");
javaLangClassNames.add("System.LoggerFinder");
javaLangClassNames.add("Thread");
javaLangClassNames.add("ThreadGroup");
javaLangClassNames.add("ThreadLocal");
javaLangClassNames.add("Throwable");
javaLangClassNames.add("Void");
//Enums
javaLangClassNames.add("Character.UnicodeScript");
javaLangClassNames.add("ProcessBuilder.Redirect.Type");
javaLangClassNames.add("StackWalker.Option");
javaLangClassNames.add("System.Logger.Level");
javaLangClassNames.add("Thread.State");
//Exceptions
javaLangClassNames.add("ArithmeticException");
javaLangClassNames.add("ArrayIndexOutOfBoundsException");
javaLangClassNames.add("ArrayStoreException");
javaLangClassNames.add("ClassCastException");
javaLangClassNames.add("ClassNotFoundException");
javaLangClassNames.add("CloneNotSupportedException");
javaLangClassNames.add("EnumConstantNotPresentException");
javaLangClassNames.add("Exception");
javaLangClassNames.add("IllegalAccessException");
javaLangClassNames.add("IllegalArgumentException");
javaLangClassNames.add("IllegalCallerException");
javaLangClassNames.add("IllegalMonitorStateException");
javaLangClassNames.add("IllegalStateException");
javaLangClassNames.add("IllegalThreadStateException");
javaLangClassNames.add("IndexOutOfBoundsException");
javaLangClassNames.add("InstantiationException");
javaLangClassNames.add("InterruptedException");
javaLangClassNames.add("LayerInstantiationException");
javaLangClassNames.add("NegativeArraySizeException");
javaLangClassNames.add("NoSuchFieldException");
javaLangClassNames.add("NoSuchMethodException");
javaLangClassNames.add("NullPointerException");
javaLangClassNames.add("NumberFormatException");
javaLangClassNames.add("ReflectiveOperationException");
javaLangClassNames.add("RuntimeException");
javaLangClassNames.add("SecurityException");
javaLangClassNames.add("StringIndexOutOfBoundsException");
javaLangClassNames.add("TypeNotPresentException");
javaLangClassNames.add("UnsupportedOperationException");
//Errors
javaLangClassNames.add("AbstractMethodError");
javaLangClassNames.add("AssertionError");
javaLangClassNames.add("BootstrapMethodError");
javaLangClassNames.add("ClassCircularityError");
javaLangClassNames.add("ClassFormatError");
javaLangClassNames.add("Error");
javaLangClassNames.add("ExceptionInInitializerError");
javaLangClassNames.add("IllegalAccessError");
javaLangClassNames.add("IncompatibleClassChangeError");
javaLangClassNames.add("InstantiationError");
javaLangClassNames.add("InternalError");
javaLangClassNames.add("LinkageError");
javaLangClassNames.add("NoClassDefFoundError");
javaLangClassNames.add("NoSuchFieldError");
javaLangClassNames.add("NoSuchMethodError");
javaLangClassNames.add("OutOfMemoryError");
javaLangClassNames.add("StackOverflowError");
javaLangClassNames.add("ThreadDeath");
javaLangClassNames.add("UnknownError");
javaLangClassNames.add("UnsatisfiedLinkError");
javaLangClassNames.add("UnsupportedClassVersionError");
javaLangClassNames.add("VerifyError");
javaLangClassNames.add("VirtualMachineError");
//Annotation Types
javaLangClassNames.add("Deprecated");
javaLangClassNames.add("FunctionalInterface");
javaLangClassNames.add("Override");
javaLangClassNames.add("SafeVarargs");
javaLangClassNames.add("SuppressWarnings");
standardPackages.put("java.lang", javaLangClassNames);
}
private Map<String,Set<String>> packageNames = new ConcurrentHashMap<>();
private ConcurrentHashMap<String,String> classNames = new ConcurrentHashMap<>();
private Map<String,Class<?>> clazzes = new ConcurrentHashMap<>();
private Map<String,Class<?>> statics = new ConcurrentHashMap<>();
public ImportHandler() {
importPackage("java.lang");
}
public void importStatic(String name) throws javax.el.ELException {
int lastPeriod = name.lastIndexOf('.');
if (lastPeriod < 0) {
throw new ELException(Util.message(
null, "importHandler.invalidStaticName", name));
}
String className = name.substring(0, lastPeriod);
String fieldOrMethodName = name.substring(lastPeriod + 1);
Class<?> clazz = findClass(className, true);
if (clazz == null) {
throw new ELException(Util.message(
null, "importHandler.invalidClassNameForStatic",
className, name));
}
boolean found = false;
for (Field field : clazz.getFields()) {
if (field.getName().equals(fieldOrMethodName)) {
int modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers) &&
Modifier.isPublic(modifiers)) {
found = true;
break;
}
}
}
if (!found) {
for (Method method : clazz.getMethods()) {
if (method.getName().equals(fieldOrMethodName)) {
int modifiers = method.getModifiers();
if (Modifier.isStatic(modifiers) &&
Modifier.isPublic(modifiers)) {
found = true;
break;
}
}
}
}
if (!found) {
throw new ELException(Util.message(null,
"importHandler.staticNotFound", fieldOrMethodName,
className, name));
}
Class<?> conflict = statics.get(fieldOrMethodName);
if (conflict != null) {
throw new ELException(Util.message(null,
"importHandler.ambiguousStaticImport", name,
conflict.getName() + '.' + fieldOrMethodName));
}
statics.put(fieldOrMethodName, clazz);
}
public void importClass(String name) throws javax.el.ELException {
int lastPeriodIndex = name.lastIndexOf('.');
if (lastPeriodIndex < 0) {
throw new ELException(Util.message(
null, "importHandler.invalidClassName", name));
}
String unqualifiedName = name.substring(lastPeriodIndex + 1);
String currentName = classNames.putIfAbsent(unqualifiedName, name);
if (currentName != null && !currentName.equals(name)) {
// Conflict. Same unqualifiedName, different fully qualified names
throw new ELException(Util.message(null,
"importHandler.ambiguousImport", name, currentName));
}
}
public void importPackage(String name) {
// Import ambiguity is handled at resolution, not at import
// Whether the package exists is not checked,
// a) for sake of performance when used in JSPs (BZ 57142),
// b) java.lang.Package.getPackage(name) is not reliable (BZ 57574),
// c) such check is not required by specification.
Set<String> preloaded = standardPackages.get(name);
if (preloaded == null) {
preloaded = Collections.emptySet();
}
packageNames.put(name, preloaded);
}
public java.lang.Class<?> resolveClass(String name) {
if (name == null || name.contains(".")) {
return null;
}
// Has it been previously resolved?
Class<?> result = clazzes.get(name);
if (result != null) {
if (NotFound.class.equals(result)) {
return null;
} else {
return result;
}
}
// Search the class imports
String className = classNames.get(name);
if (className != null) {
Class<?> clazz = findClass(className, true);
if (clazz != null) {
clazzes.put(name, clazz);
return clazz;
}
}
// Search the package imports - note there may be multiple matches
// (which correctly triggers an error)
for (Map.Entry<String,Set<String>> entry : packageNames.entrySet()) {
if (!entry.getValue().isEmpty()) {
// Standard package where we know all the class names
if (!entry.getValue().contains(name)) {
// Requested name isn't in the list so it isn't in this
// package so move on to next package. This allows the
// class loader look-up to be skipped.
continue;
}
}
className = entry.getKey() + '.' + name;
Class<?> clazz = findClass(className, false);
if (clazz != null) {
if (result != null) {
throw new ELException(Util.message(null,
"importHandler.ambiguousImport", className,
result.getName()));
}
result = clazz;
}
}
if (result == null) {
// Cache NotFound results to save repeated calls to findClass()
// which is relatively slow
clazzes.put(name, NotFound.class);
} else {
clazzes.put(name, result);
}
return result;
}
public java.lang.Class<?> resolveStatic(String name) {
return statics.get(name);
}
private Class<?> findClass(String name, boolean throwException) {
Class<?> clazz;
ClassLoader cl = Util.getContextClassLoader();
String path = name.replace('.', '/') + ".class";
try {
/* Given that findClass() has to be called for every imported
* package and that getResource() is a lot faster then loadClass()
* for resources that don't exist, the overhead of the getResource()
* for the case where the class does exist is a lot less than the
* overhead we save by not calling loadClass().
*/
if (cl.getResource(path) == null) {
return null;
}
} catch (ClassCircularityError cce) {
// May happen under a security manager. Ignore it and try loading
// the class normally.
}
try {
clazz = cl.loadClass(name);
} catch (ClassNotFoundException e) {
return null;
}
// Class must be public, non-abstract, not an interface and (for
// Java 9+) in an exported package
JreCompat jreCompat = JreCompat.getInstance();
int modifiers = clazz.getModifiers();
if (!Modifier.isPublic(modifiers) || Modifier.isAbstract(modifiers) ||
Modifier.isInterface(modifiers) || !jreCompat.isExported(clazz)) {
if (throwException) {
throw new ELException(Util.message(
null, "importHandler.invalidClass", name));
} else {
return null;
}
}
return clazz;
}
/*
* Marker class used because null values are not permitted in a
* ConcurrentHashMap.
*/
private static class NotFound {
}
}

View File

@@ -0,0 +1,83 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Method;
/*
* This is a cut down version of org.apache.tomcat.util.Jre9Compat that provides
* only the methods required by the EL implementation.
*
* This class is duplicated in org.apache.el.util
* When making changes keep the two in sync.
*/
class Jre9Compat extends JreCompat {
private static final Method canAccessMethod;
private static final Method getModuleMethod;
private static final Method isExportedMethod;
static {
Method m1 = null;
Method m2 = null;
Method m3 = null;
try {
m1 = AccessibleObject.class.getMethod("canAccess", Object.class);
m2 = Class.class.getMethod("getModule");
Class<?> moduleClass = Class.forName("java.lang.Module");
m3 = moduleClass.getMethod("isExported", String.class);
} catch (NoSuchMethodException e) {
// Expected for Java 8
} catch (ClassNotFoundException e) {
// Can't log this so...
throw new RuntimeException(e);
}
canAccessMethod = m1;
getModuleMethod = m2;
isExportedMethod = m3;
}
public static boolean isSupported() {
return canAccessMethod != null;
}
@Override
public boolean canAcccess(Object base, AccessibleObject accessibleObject) {
try {
return ((Boolean) canAccessMethod.invoke(accessibleObject, base)).booleanValue();
} catch (ReflectiveOperationException | IllegalArgumentException e) {
return false;
}
}
@Override
public boolean isExported(Class<?> type) {
try {
String packageName = type.getPackage().getName();
Object module = getModuleMethod.invoke(type);
return ((Boolean) isExportedMethod.invoke(module, packageName)).booleanValue();
} catch (ReflectiveOperationException e) {
return false;
}
}
}

View File

@@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.lang.reflect.AccessibleObject;
/*
* This is cut down version of org.apache.tomcat.util.JreCompat that provides
* only the methods required by the EL implementation.
*
* This class is duplicated in org.apache.el.util
* When making changes keep the two in sync.
*/
class JreCompat {
private static final JreCompat instance;
static {
if (Jre9Compat.isSupported()) {
instance = new Jre9Compat();
} else {
instance = new JreCompat();
}
}
public static JreCompat getInstance() {
return instance;
}
/**
* Is the accessibleObject accessible (as a result of appropriate module
* exports) on the provided instance?
*
* @param base The specific instance to be tested.
* @param accessibleObject The method/field/constructor to be tested.
*
* @return {code true} if the AccessibleObject can be accessed otherwise
* {code false}
*/
public boolean canAcccess(Object base, AccessibleObject accessibleObject) {
// Java 8 doesn't support modules so default to true
return true;
}
/**
* Is the given class in an exported package?
*
* @param type The class to test
*
* @return Always {@code true} for Java 8. {@code true} if the enclosing
* package is exported for Java 9+
*/
public boolean isExported(Class<?> type) {
return true;
}
}

View File

@@ -0,0 +1,93 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class LambdaExpression {
private final List<String> formalParameters;
private final ValueExpression expression;
private final Map<String,Object> nestedArguments = new HashMap<>();
private ELContext context = null;
public LambdaExpression(List<String> formalParameters,
ValueExpression expression) {
this.formalParameters = formalParameters;
this.expression = expression;
}
public void setELContext(ELContext context) {
this.context = context;
}
@SuppressWarnings("null") // args[i] can't be null due to earlier checks
public Object invoke(ELContext context, Object... args)
throws ELException {
Objects.requireNonNull(context);
int formalParamCount = 0;
if (formalParameters != null) {
formalParamCount = formalParameters.size();
}
int argCount = 0;
if (args != null) {
argCount = args.length;
}
if (formalParamCount > argCount) {
throw new ELException(Util.message(context,
"lambdaExpression.tooFewArgs",
Integer.valueOf(argCount),
Integer.valueOf(formalParamCount)));
}
// Build the argument map
// Start with the arguments from any outer expressions so if there is
// any overlap the local arguments have priority
Map<String,Object> lambdaArguments = new HashMap<>();
lambdaArguments.putAll(nestedArguments);
for (int i = 0; i < formalParamCount; i++) {
lambdaArguments.put(formalParameters.get(i), args[i]);
}
context.enterLambdaScope(lambdaArguments);
try {
Object result = expression.getValue(context);
// Make arguments from this expression available to any nested
// expression
if (result instanceof LambdaExpression) {
((LambdaExpression) result).nestedArguments.putAll(
lambdaArguments);
}
return result;
} finally {
context.exitLambdaScope();
}
}
public java.lang.Object invoke(Object... args) {
return invoke (context, args);
}
}

View File

@@ -0,0 +1,155 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.beans.FeatureDescriptor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
public class ListELResolver extends ELResolver {
private final boolean readOnly;
private static final Class<?> UNMODIFIABLE =
Collections.unmodifiableList(new ArrayList<>()).getClass();
public ListELResolver() {
this.readOnly = false;
}
public ListELResolver(boolean readOnly) {
this.readOnly = readOnly;
}
@Override
public Class<?> getType(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base instanceof List<?>) {
context.setPropertyResolved(base, property);
List<?> list = (List<?>) base;
int idx = coerce(property);
if (idx < 0 || idx >= list.size()) {
throw new PropertyNotFoundException(
new ArrayIndexOutOfBoundsException(idx).getMessage());
}
return Object.class;
}
return null;
}
@Override
public Object getValue(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base instanceof List<?>) {
context.setPropertyResolved(base, property);
List<?> list = (List<?>) base;
int idx = coerce(property);
if (idx < 0 || idx >= list.size()) {
return null;
}
return list.get(idx);
}
return null;
}
@Override
public void setValue(ELContext context, Object base, Object property,
Object value) {
Objects.requireNonNull(context);
if (base instanceof List<?>) {
context.setPropertyResolved(base, property);
@SuppressWarnings("unchecked") // Must be OK to cast to Object
List<Object> list = (List<Object>) base;
if (this.readOnly) {
throw new PropertyNotWritableException(Util.message(context,
"resolverNotWriteable", base.getClass().getName()));
}
int idx = coerce(property);
try {
list.set(idx, value);
} catch (UnsupportedOperationException e) {
throw new PropertyNotWritableException(e);
} catch (IndexOutOfBoundsException e) {
throw new PropertyNotFoundException(e);
}
}
}
@Override
public boolean isReadOnly(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base instanceof List<?>) {
context.setPropertyResolved(base, property);
List<?> list = (List<?>) base;
try {
int idx = coerce(property);
if (idx < 0 || idx >= list.size()) {
throw new PropertyNotFoundException(
new ArrayIndexOutOfBoundsException(idx)
.getMessage());
}
} catch (IllegalArgumentException e) {
// ignore
}
return this.readOnly || UNMODIFIABLE.equals(list.getClass());
}
return this.readOnly;
}
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
return null;
}
@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
if (base instanceof List<?>) { // implies base != null
return Integer.class;
}
return null;
}
private static final int coerce(Object property) {
if (property instanceof Number) {
return ((Number) property).intValue();
}
if (property instanceof Character) {
return ((Character) property).charValue();
}
if (property instanceof Boolean) {
return ((Boolean) property).booleanValue() ? 1 : 0;
}
if (property instanceof String) {
return Integer.parseInt((String) property);
}
throw new IllegalArgumentException(property != null ?
property.toString() : "null");
}
}

View File

@@ -0,0 +1,52 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
beanNameELResolver.beanReadOnly=The bean name [{0}] is read-only
elProcessor.defineFunctionInvalidClass=The class [{0}] is not public
elProcessor.defineFunctionInvalidMethod=The method [{0}] on class [{1}] is not a public static method
elProcessor.defineFunctionInvalidParameterList=The parameter list [{0}] for method [{1}] on class [{2}] is not valid
elProcessor.defineFunctionInvalidParameterTypeName=The parameter type [{0}] for method [{1}] on class [{2}] is not valid
elProcessor.defineFunctionNoMethod=A public static method [{0}] on class [{1}] could not be found
elProcessor.defineFunctionNullParams=One or more of the input parameters was null
expressionFactory.cannotCreate=Unable to create ExpressionFactory of type [{0}]
expressionFactory.cannotFind=Unable to find ExpressionFactory of type [{0}]
expressionFactory.readFailed=Failed to read [{0}]
importHandler.ambiguousImport=The class [{0}] could not be imported as it conflicts with [{1}] which has already been imported
importHandler.ambiguousStaticImport=The static import [{0}] could not be processed as it conflicts with [{1}] which has already been imported
importHandler.classNotFound=The class [{0}] could not be imported as it could not be found
importHandler.invalidClass=The class [{0}] must be public, non-abstract, not an interface and (for Java 9+) in an exported package
importHandler.invalidClassName=Name of class to import [{0}] must include a package
importHandler.invalidClassNameForStatic=The class [{0}] specified for static import [{1}] is not valid
importHandler.invalidStaticName=Name of static method or field to import [{0}] must include a class
importHandler.staticNotFound=The static import [{0}] could not be found in class [{1}] for import [{2}]
lambdaExpression.tooFewArgs=Only [{0}] arguments were provided for a lambda expression that requires at least [{1}]
objectNotAssignable=Unable to add an object of type [{0}] to an array of objects of type [{1}]
propertyNotFound=Property [{1}] not found on type [{0}]
propertyNotReadable=Property [{1}] not readable on type [{0}]
propertyNotWritable=Property [{1}] not writable on type [{0}]
propertyReadError=Error reading [{1}] on type [{0}]
propertyWriteError=Error writing [{1}] on type [{0}]
staticFieldELResolver.methodNotFound=No matching public static method named [{0}] found on class [{1}]
staticFieldELResolver.notFound=No public static field named [{0}] was found on (exported for Java 9+) class [{1}]
staticFieldELResolver.notWriteable=Writing to static fields (in this case field [{0}] on class [{1}]) is not permitted
util.method.ambiguous=Unable to find unambiguous method: {0}.{1}({2})
util.method.notfound=Method not found: {0}.{1}({2})

View File

@@ -0,0 +1,22 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
elProcessor.defineFunctionInvalidClass=Die Klasse [{0}] ist nicht öffentlich
elProcessor.defineFunctionInvalidMethod=Die Methode [{0}] der Klasse [{1}] ist nicht public static
expressionFactory.cannotFind=Kann die ExpressionFactory mit dem Typ [{0}] nicht finden
importHandler.classNotFound=Die Klasse [{0}] konnte nicht importiert werden, da sie nicht gefunden werden konnte
importHandler.invalidClassNameForStatic=Ungültige Klasse [{0}] für angegebenen static import [{1}]

View File

@@ -0,0 +1,28 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
elProcessor.defineFunctionInvalidMethod=El método [{0}] en la clase [{1}] no es un método estático público
importHandler.ambiguousStaticImport=La importación estática [{0}] no puede ser procesada pues entra en conflicto con [{1}] la cual ya ha sido importada
importHandler.classNotFound=La clase [{0}] no puede ser importada debido a que no fué encontrada
importHandler.invalidClassNameForStatic=La clase [{0}] especificada para importación estática [{1}] no es valida
importHandler.staticNotFound=La importación estática [{0}] no se pudo encontrar en la clase [{1}] para importar [{2}]
objectNotAssignable=No puedo añadir un objeto del tipo [{0}] a un arreglo de objetos del tipo [{1}]
propertyNotFound=Propiedad [{1}] no hallada en el tipo [{0}]
propertyNotReadable=Propiedad [{1}] no legible para el tipo [{0}]
propertyNotWritable=Propiedad [{1}] no grabable para el tipo [{0}]
propertyReadError=Error reading [{1}] en el tipo [{0}]
propertyWriteError=Error writing [{1}] en el tipo [{0}]

View File

@@ -0,0 +1,52 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
beanNameELResolver.beanReadOnly=Le nom de bean [{0}] est en lecture seule
elProcessor.defineFunctionInvalidClass=La classe [{0}] n''est pas publique
elProcessor.defineFunctionInvalidMethod=La méthode [{0}] sur la classe [{1}] n''est pas une méthode statique publique
elProcessor.defineFunctionInvalidParameterList=La liste de paramètres [{0}] pour la méthode [{1}] de la classe [{2}] n''est pas valide
elProcessor.defineFunctionInvalidParameterTypeName=Le type [{0}] du paramètre de la méthode [{1}] sur la classe [{2}] n''est pas valide
elProcessor.defineFunctionNoMethod=Une méthode statique et publique [{0}] n''a pas pu être trouvée sur la classe [{1}]
elProcessor.defineFunctionNullParams=On ou plusieurs paramètres d'entrée sont null
expressionFactory.cannotCreate=Impossible de créer une ExpressionFactory de type [{0}]
expressionFactory.cannotFind=Impossible de trouver une ExpressionFactory de type [{0}]
expressionFactory.readFailed=Impossible de lire [{0}]
importHandler.ambiguousImport=La classe [{0}] n''a pas pu être importée car elle entre en conflit avec [{1}] qui a déjà été importée
importHandler.ambiguousStaticImport=L''import statique [{0}] ne peut pas être traité parce qu''il est en conflit avec [{1}] qui a déjà été importé
importHandler.classNotFound=La classe [{0}] n''a pu être importée, vu qu''on ne l''a pas trouvée
importHandler.invalidClass=La classe [{0}] doit être publique, non abstraite, et ne pas être une interface
importHandler.invalidClassName=Le nom de la classe à importer [{0}] doit comprendre un paquet
importHandler.invalidClassNameForStatic=La classe [{0}] spécifiée pour l''importation statique [{1}] n''est pas valide
importHandler.invalidStaticName=Le nom de la méthode statique ou champ à importer [{0}] doit inclure une calsse
importHandler.staticNotFound=L''importation statique [{0}] n''a pas été trouvée dans la classe [{1}] pour [{2}]
lambdaExpression.tooFewArgs=Seuls [{0}] arguments ont été fournis pour une expression lambda qui en demande au moins [{1}]
objectNotAssignable=Impossible d''ajouter un objet du type [{0}] à un tableau d''objets de type [{1}]
propertyNotFound=La propriété [{1}] n''a pas été trouvée sur le type [{0}]
propertyNotReadable=La propriété [{1}] n''est pas lisible sur le type [{0}]
propertyNotWritable=La propriété [{1}] ne peut pas être écrite pour le type [{0}]
propertyReadError=Erreur lors de la lecture de [{1}] sur le type [{0}]
propertyWriteError=Erreur d''écriture [{1}] sur le type [{0}]
staticFieldELResolver.methodNotFound=Aucune méthode publique et statique nommée [{0}] n''a été trouvée dans la classe [{1}]
staticFieldELResolver.notFound=Un champ statique et public nommé [{0}] n''a pas pu être trouvé sur la classe [{1}]
staticFieldELResolver.notWriteable=L''écriture dans les champs statiques (champ [{0}] dans la classe [{1}] dans le cas présent) est interdite
util.method.ambiguous=Impossible de trouver une méthode non ambiguë: {0}.{1}({2})
util.method.notfound=Méthode non trouvée: {0}.{1}({2})

View File

@@ -0,0 +1,52 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
beanNameELResolver.beanReadOnly=Bean名[{0}]は読み取り専用です
elProcessor.defineFunctionInvalidClass=クラス [{0}] はpublicではありません。
elProcessor.defineFunctionInvalidMethod=クラス [{1}] のメソッド [{0}] は public static メソッドではありません。
elProcessor.defineFunctionInvalidParameterList=クラス [{2}] のメソッド [{1}] に不正なパラメーターリスト [{0}] が指定されました。
elProcessor.defineFunctionInvalidParameterTypeName=クラス[{2}]のメソッド[{1}]のパラメータタイプ[{0}]が無効です
elProcessor.defineFunctionNoMethod=クラス[{1}]のpublic staticメソッド[{0}]が見つかりませんでした。
elProcessor.defineFunctionNullParams=1つ以上の入力パラメータがnullでした。
expressionFactory.cannotCreate=型[{0}]のExpressionFactoryを作成できません。
expressionFactory.cannotFind=[{0}]型のExpressionFactoryを見つけることができません。
expressionFactory.readFailed=[{0}]の読み取りに失敗しました
importHandler.ambiguousImport=クラス [{0}] はすでにインポートした [{1}] と衝突するためインポートできません。
importHandler.ambiguousStaticImport=static import [{0}] はすでにインポートした [{1}] と衝突するため処理できません。
importHandler.classNotFound=存在しないクラス [{0}] はインポートできません。
importHandler.invalidClass=クラス[{0}]は、パブリックで非abstract であり、インタフェースではない。
importHandler.invalidClassName=インポートするクラスの名前[{0}]にはパッケージが含まれている必要があります
importHandler.invalidClassNameForStatic=クラス [{0}] の static import [{1}] は不正です。
importHandler.invalidStaticName=インポートするstaticメソッドまたはフィールドの名前[{0}]にはクラスが含まれている必要があります。
importHandler.staticNotFound=インポート[{2}]の静的インポート[{0}]はクラス[{1}]で見つかりませんでした
lambdaExpression.tooFewArgs=少なくとも[{1}]を必要とするラムダ式に対しては、[{0}]引数のみが提供されました。
objectNotAssignable=クラス [{0}] のオブジェクトはクラス [{1}] のオブジェクト配列へ追加できません。
propertyNotFound=プロパティ[{1}]がタイプ[{0}]で見つかりません
propertyNotReadable=タイプ[{0}]でプロパティ[{1}]を読み込めません。
propertyNotWritable=プロパティ[{1}]はタイプ[{0}]に書き込み可能ではありません
propertyReadError=タイプ[{0}]の[{1}]の読み取りエラー
propertyWriteError=タイプ[{0}]の[{1}]への書き込みエラー
staticFieldELResolver.methodNotFound=クラス[{1}]に[{0}]という名前に一致するpublic staticメソッドが見つかりません。
staticFieldELResolver.notFound=クラス[{1}]に[{0}]という名前のpublic staticフィールドが見つかりませんでした。
staticFieldELResolver.notWriteable=静的フィールド(この場合、クラス[{1}]のフィールド[{0})への書き込みは許可されていません。
util.method.ambiguous=曖昧さのないメソッドを見つけることができません:{0}。{1}{2}
util.method.notfound=メソッドが見つかりません:{0}。{1}{2}

View File

@@ -0,0 +1,52 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
beanNameELResolver.beanReadOnly=Bean 이름 [{0}]은(는) 읽기 전용입니다.
elProcessor.defineFunctionInvalidClass=클래스 [{0}]은(는) public 클래스가 아닙니다.
elProcessor.defineFunctionInvalidMethod=클래스 [{1}]의 메소드 [{0}]은(는) public static 메소드가 아닙니다.
elProcessor.defineFunctionInvalidParameterList=클래스 [{2}]의 메소드 [{1}]을(를) 위한 파라미터 목록 [{0}]이(가) 유효하지 않습니다.
elProcessor.defineFunctionInvalidParameterTypeName=클래스 [{2}]의 메소드 [{1}]을(를) 위한 파라미터 타입 [{0}]은(는) 유효하지 않습니다.
elProcessor.defineFunctionNoMethod=클래스 [{1}]에서 public static 메소드 [{0}]을(를) 찾을 수 없었습니다.
elProcessor.defineFunctionNullParams=하나 이상의 입력 파라미터들이 널이었습니다.
expressionFactory.cannotCreate=타입 [{0}]의 ExpressionFactory를 생성할 수 없습니다.
expressionFactory.cannotFind=타입 [{0}]의 ExpressionFactory를 찾을 수 없습니다.
expressionFactory.readFailed=[{0}]을(를) 읽지 못했습니다.
importHandler.ambiguousImport=이미 임포트된 [{1}]와(과) 충돌하기에, 클래스 [{0}]은(는) 임포트될 수 없었습니다.
importHandler.ambiguousStaticImport=정적 임포트 [{0}]은(는), 이미 임포트된 [{1}]와(과) 충돌하기 때문에 처리될 수 없었습니다.
importHandler.classNotFound=클래스 [{0}]을(를) 찾을 수 없어서 임포트될 수 없습니다.
importHandler.invalidClass=클래스 [{0}]은(는), 반드시 public이어야 하고 abstract가 아니어야 하며 인터페이스가 아니어야 합니다.
importHandler.invalidClassName=임포트할 클래스 이름 [{0}]은(는) 반드시 패키지를 포함해야 합니다.
importHandler.invalidClassNameForStatic=정적 임포트 [{1}]을(를) 위해 지정된 클래스 [{0}]은(는) 유효하지 않습니다.
importHandler.invalidStaticName=임포트할 정적 메소드나 필드의 이름은, 반드시 클래스를 포함해야 합니다: [{0}]
importHandler.staticNotFound=임포트 [{2}]을(를) 위한 클래스 [{1}] 내에서, 정적 임포트 [{0}]을(를) 찾을 수 없습니다.
lambdaExpression.tooFewArgs=적어도 [{1}]개의 아규먼트들을 요구하는 람다 표현식에, 단지 [{0}]개의 아규먼트들만이 제공되었습니다.
objectNotAssignable=타입 [{0}]의 객체를, 타입 [{1}]의 객체 배열에 추가할 수 없습니다.
propertyNotFound=타입 [{0}]에서 프로퍼티 [{1}]을(를) 찾을 수 없습니다.
propertyNotReadable=타입 [{0}]에서 프로퍼티 [{1}]을(를) 읽을 수 없습니다.
propertyNotWritable=타입 [{0}]에서 쓰기 가능하지 않은 프로퍼티 [{1}]
propertyReadError=타입 [{0}]에서 [{1}]을(를) 읽는 중 오류 발생
propertyWriteError=타입 [{0}]에 [{1}]을(를) 쓰는 중 오류 발생
staticFieldELResolver.methodNotFound=클래스 [{1}]에 [{0}](이)라는 이름의 public static 메소드가 발견되지 않습니다.
staticFieldELResolver.notFound=클래스 [{1}]에, [{0}](이)라는 이름의 public static 필드가 없습니다.
staticFieldELResolver.notWriteable=정적 필드들에 대해 쓰기는 허용되지 않습니다 (이번 경우는 클래스 [{1}]의 필드 [{0}]).
util.method.ambiguous=애매하지 않고 명백하게 메소드를 찾을 수 없습니다: {0}.{1}({2})
util.method.notfound=메소드를 찾을 수 없습니다: {0}.{1}({2})

View File

@@ -0,0 +1,50 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
beanNameELResolver.beanReadOnly=名称为[{0}]的bean只读
elProcessor.defineFunctionInvalidClass=类[{0}]不是公共的
elProcessor.defineFunctionInvalidMethod=类[{1}]的方法[{0}]不是公共静态方法
elProcessor.defineFunctionInvalidParameterList=类[{2}]的方法[{1}]的参数列表[{0}]无效
elProcessor.defineFunctionInvalidParameterTypeName=类[{2}]的方法[{1}]的参数类型[{0}]无效
elProcessor.defineFunctionNoMethod=无法找到类[{1}]的公共静态方法[{0}]
elProcessor.defineFunctionNullParams=一个或多个输入参数为null
expressionFactory.cannotCreate=无法创建类型为[{0}]的表达式工厂
expressionFactory.readFailed=无法读取[{0}]
importHandler.ambiguousImport=无法导入类[{0}],因为它与已导入的[{1}]冲突
importHandler.ambiguousStaticImport=无法处理静态导入[{0}],因为它与已导入的[{1}]冲突
importHandler.classNotFound=无法导入类[{0}],因为无法找到它
importHandler.invalidClass=类[{0}]必须是公共的、非抽象的、非接口且对于Java 9+)在一个导出包
importHandler.invalidClassNameForStatic=为 static import [{1}] 指定的类 [{0}] 不可用
importHandler.invalidStaticName=导入 [{0}] 的静态方法或字段名称必须包含类
importHandler.staticNotFound=导入[{2}]的类[{1}]中找不到静态导入[{0}]
lambdaExpression.tooFewArgs=仅为至少需要[{1}]个参数的lambda表达式提供了[{0}]个参数
objectNotAssignable=无法将类型为[{0}]的对象添加到[{1}]类型的对象数组中
propertyNotFound=类型[{0}]上找不到属性[{1}]
propertyNotReadable=属性[{1}]在类型[{0}]上不可读
propertyNotWritable=属性[{1}]在类型[{0}]上不可写
propertyReadError=在类型[{0}]上读取[{1}]时出错
propertyWriteError=在类型[{0}]上写入[{1}]时出错
staticFieldELResolver.methodNotFound=在类[{1}]上找不到名为[{0}]的匹配的公共静态方法
staticFieldELResolver.notFound=Java 9+导出)类[{1}]上找不到名为[{0}]的公共静态字段
staticFieldELResolver.notWriteable=不允许写入静态字段(当前情况中为类[{1}]上的字段[{0}]
util.method.ambiguous=无法找到明确的方法:{0}.{1}({2})
util.method.notfound=找不到方法:{0}.{1}({2})

View File

@@ -0,0 +1,136 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.beans.FeatureDescriptor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class MapELResolver extends ELResolver {
private static final Class<?> UNMODIFIABLE =
Collections.unmodifiableMap(new HashMap<>()).getClass();
private final boolean readOnly;
public MapELResolver() {
this.readOnly = false;
}
public MapELResolver(boolean readOnly) {
this.readOnly = readOnly;
}
@Override
public Class<?> getType(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base instanceof Map<?,?>) {
context.setPropertyResolved(base, property);
return Object.class;
}
return null;
}
@Override
public Object getValue(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base instanceof Map<?,?>) {
context.setPropertyResolved(base, property);
return ((Map<?,?>) base).get(property);
}
return null;
}
@Override
public void setValue(ELContext context, Object base, Object property,
Object value) {
Objects.requireNonNull(context);
if (base instanceof Map<?, ?>) {
context.setPropertyResolved(base, property);
if (this.readOnly) {
throw new PropertyNotWritableException(Util.message(context,
"resolverNotWriteable", base.getClass().getName()));
}
try {
@SuppressWarnings("unchecked") // Must be OK
Map<Object, Object> map = ((Map<Object, Object>) base);
map.put(property, value);
} catch (UnsupportedOperationException e) {
throw new PropertyNotWritableException(e);
}
}
}
@Override
public boolean isReadOnly(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base instanceof Map<?, ?>) {
context.setPropertyResolved(base, property);
return this.readOnly || UNMODIFIABLE.equals(base.getClass());
}
return this.readOnly;
}
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
if (base instanceof Map<?, ?>) {
Iterator<?> itr = ((Map<?, ?>) base).keySet().iterator();
List<FeatureDescriptor> feats = new ArrayList<>();
Object key;
FeatureDescriptor desc;
while (itr.hasNext()) {
key = itr.next();
desc = new FeatureDescriptor();
desc.setDisplayName(key.toString());
desc.setShortDescription("");
desc.setExpert(false);
desc.setHidden(false);
desc.setName(key.toString());
desc.setPreferred(true);
desc.setValue(RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
desc.setValue(TYPE, key.getClass());
feats.add(desc);
}
return feats.iterator();
}
return null;
}
@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
if (base instanceof Map<?, ?>) {
return Object.class;
}
return null;
}
}

View File

@@ -0,0 +1,84 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
public abstract class MethodExpression extends Expression {
private static final long serialVersionUID = 8163925562047324656L;
/**
* @param context The EL context for this evaluation
*
* @return Information about the method that this expression resolves to
*
* @throws NullPointerException
* If the supplied context is <code>null</code>
* @throws PropertyNotFoundException
* If a property/variable resolution failed because no match
* was found or a match was found but was not readable
* @throws MethodNotFoundException
* If no matching method can be found
* @throws ELException
* Wraps any exception throw whilst resolving the property
*/
public abstract MethodInfo getMethodInfo(ELContext context);
/**
* @param context The EL context for this evaluation
* @param params The parameters with which to invoke this method expression
*
* @return The result of invoking this method expression
*
* @throws NullPointerException
* If the supplied context is <code>null</code>
* @throws PropertyNotFoundException
* If a property/variable resolution failed because no match
* was found or a match was found but was not readable
* @throws MethodNotFoundException
* If no matching method can be found
* @throws ELException
* Wraps any exception throw whilst resolving the property or
* coercion of the result to the expected return type fails
*/
public abstract Object invoke(ELContext context, Object[] params);
/**
* @return This default implementation always returns <code>false</code>
* @since EL 3.0
*/
public boolean isParametersProvided() {
// Expected to be over-ridden by implementation
return false;
}
/**
* @since EL 2.2
*
* Note: The spelling mistake is deliberate.
* isParmetersProvided() - Specification definition
* isParametersProvided() - Corrected spelling
*
* @return Always <code>false</code>
*
* @deprecated Use {@link #isParametersProvided()}
*/
@Deprecated
public boolean isParmetersProvided() {
// Expected to be over-ridden by implementation
return false;
}
}

View File

@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
public class MethodInfo {
private final String name;
private final Class<?>[] paramTypes;
private final Class<?> returnType;
public MethodInfo(String name, Class<?> returnType, Class<?>[] paramTypes) {
this.name = name;
this.returnType = returnType;
this.paramTypes = paramTypes;
}
public String getName() {
return this.name;
}
public Class<?> getReturnType() {
return this.returnType;
}
public Class<?>[] getParamTypes() {
return this.paramTypes;
}
}

View File

@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
public class MethodNotFoundException extends ELException {
private static final long serialVersionUID = -3631968116081480328L;
public MethodNotFoundException() {
super();
}
public MethodNotFoundException(String message) {
super(message);
}
public MethodNotFoundException(Throwable cause) {
super(cause);
}
public MethodNotFoundException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
public class PropertyNotFoundException extends ELException {
private static final long serialVersionUID = -3799200961303506745L;
public PropertyNotFoundException() {
super();
}
public PropertyNotFoundException(String message) {
super(message);
}
public PropertyNotFoundException(Throwable cause) {
super(cause);
}
public PropertyNotFoundException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
public class PropertyNotWritableException extends ELException {
private static final long serialVersionUID = 827987155471214717L;
public PropertyNotWritableException() {
super();
}
public PropertyNotWritableException(String message) {
super(message);
}
public PropertyNotWritableException(Throwable cause) {
super(cause);
}
public PropertyNotWritableException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -0,0 +1,124 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.beans.FeatureDescriptor;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.MissingResourceException;
import java.util.Objects;
import java.util.ResourceBundle;
public class ResourceBundleELResolver extends ELResolver {
public ResourceBundleELResolver() {
super();
}
@Override
public Object getValue(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base instanceof ResourceBundle) {
context.setPropertyResolved(base, property);
if (property != null) {
try {
return ((ResourceBundle) base).getObject(property
.toString());
} catch (MissingResourceException mre) {
return "???" + property.toString() + "???";
}
}
}
return null;
}
@Override
public Class<?> getType(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base instanceof ResourceBundle) {
context.setPropertyResolved(base, property);
}
return null;
}
@Override
public void setValue(ELContext context, Object base, Object property,
Object value) {
Objects.requireNonNull(context);
if (base instanceof ResourceBundle) {
context.setPropertyResolved(base, property);
throw new PropertyNotWritableException(Util.message(context,
"resolverNotWriteable", base.getClass().getName()));
}
}
@Override
public boolean isReadOnly(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base instanceof ResourceBundle) {
context.setPropertyResolved(base, property);
return true;
}
return false;
}
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(
ELContext context, Object base) {
if (base instanceof ResourceBundle) {
List<FeatureDescriptor> feats = new ArrayList<>();
Enumeration<String> e = ((ResourceBundle) base).getKeys();
FeatureDescriptor feat;
String key;
while (e.hasMoreElements()) {
key = e.nextElement();
feat = new FeatureDescriptor();
feat.setDisplayName(key);
feat.setShortDescription("");
feat.setExpert(false);
feat.setHidden(false);
feat.setName(key);
feat.setPreferred(true);
feat.setValue(RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
feat.setValue(TYPE, String.class);
feats.add(feat);
}
return feats.iterator();
}
return null;
}
@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
if (base instanceof ResourceBundle) {
return String.class;
}
return null;
}
}

View File

@@ -0,0 +1,210 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
/**
* @since EL 3.0
*/
public class StandardELContext extends ELContext {
private final ELContext wrappedContext;
private final VariableMapper variableMapper;
private final FunctionMapper functionMapper;
private final CompositeELResolver standardResolver;
private final CompositeELResolver customResolvers;
private final Map<String,Object> localBeans = new HashMap<>();
public StandardELContext(ExpressionFactory factory) {
wrappedContext = null;
variableMapper = new StandardVariableMapper();
functionMapper =
new StandardFunctionMapper(factory.getInitFunctionMap());
standardResolver = new CompositeELResolver();
customResolvers = new CompositeELResolver();
ELResolver streamResolver = factory.getStreamELResolver();
// Add resolvers in order
standardResolver.add(new BeanNameELResolver(
new StandardBeanNameResolver(localBeans)));
standardResolver.add(customResolvers);
if (streamResolver != null) {
standardResolver.add(streamResolver);
}
standardResolver.add(new StaticFieldELResolver());
standardResolver.add(new MapELResolver());
standardResolver.add(new ResourceBundleELResolver());
standardResolver.add(new ListELResolver());
standardResolver.add(new ArrayELResolver());
standardResolver.add(new BeanELResolver());
}
public StandardELContext(ELContext context) {
wrappedContext = context;
variableMapper = context.getVariableMapper();
functionMapper = context.getFunctionMapper();
standardResolver = new CompositeELResolver();
customResolvers = new CompositeELResolver();
// Add resolvers in order
standardResolver.add(new BeanNameELResolver(
new StandardBeanNameResolver(localBeans)));
standardResolver.add(customResolvers);
// Use resolvers from context from this point on
standardResolver.add(context.getELResolver());
}
// Can't use Class<?> because API needs to match specification
@Override
public void putContext(@SuppressWarnings("rawtypes") Class key,
Object contextObject) {
if (wrappedContext == null) {
super.putContext(key, contextObject);
} else {
wrappedContext.putContext(key, contextObject);
}
}
@Override
public Object getContext(@SuppressWarnings("rawtypes") Class key) {
if (wrappedContext == null) {
return super.getContext(key);
} else {
return wrappedContext.getContext(key);
}
}
@Override
public ELResolver getELResolver() {
return standardResolver;
}
public void addELResolver(ELResolver resolver) {
customResolvers.add(resolver);
}
@Override
public FunctionMapper getFunctionMapper() {
return functionMapper;
}
@Override
public VariableMapper getVariableMapper() {
return variableMapper;
}
Map<String,Object> getLocalBeans() {
return localBeans;
}
private static class StandardVariableMapper extends VariableMapper {
private Map<String, ValueExpression> vars;
@Override
public ValueExpression resolveVariable(String variable) {
if (vars == null) {
return null;
}
return vars.get(variable);
}
@Override
public ValueExpression setVariable(String variable,
ValueExpression expression) {
if (vars == null)
vars = new HashMap<>();
if (expression == null) {
return vars.remove(variable);
} else {
return vars.put(variable, expression);
}
}
}
private static class StandardBeanNameResolver extends BeanNameResolver {
private final Map<String,Object> beans;
public StandardBeanNameResolver(Map<String,Object> beans) {
this.beans = beans;
}
@Override
public boolean isNameResolved(String beanName) {
return beans.containsKey(beanName);
}
@Override
public Object getBean(String beanName) {
return beans.get(beanName);
}
@Override
public void setBeanValue(String beanName, Object value)
throws PropertyNotWritableException {
beans.put(beanName, value);
}
@Override
public boolean isReadOnly(String beanName) {
return false;
}
@Override
public boolean canCreateBean(String beanName) {
return true;
}
}
private static class StandardFunctionMapper extends FunctionMapper {
private final Map<String,Method> methods = new HashMap<>();
public StandardFunctionMapper(Map<String,Method> initFunctionMap) {
if (initFunctionMap != null) {
methods.putAll(initFunctionMap);
}
}
@Override
public Method resolveFunction(String prefix, String localName) {
String key = prefix + ':' + localName;
return methods.get(key);
}
@Override
public void mapFunction(String prefix, String localName,
Method method) {
String key = prefix + ':' + localName;
if (method == null) {
methods.remove(key);
} else {
methods.put(key, method);
}
}
}
}

View File

@@ -0,0 +1,209 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.beans.FeatureDescriptor;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Iterator;
import java.util.Objects;
/**
* @since EL 3.0
*/
public class StaticFieldELResolver extends ELResolver {
@Override
public Object getValue(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base instanceof ELClass && property instanceof String) {
context.setPropertyResolved(base, property);
Class<?> clazz = ((ELClass) base).getKlass();
String name = (String) property;
Exception exception = null;
try {
Field field = clazz.getField(name);
int modifiers = field.getModifiers();
JreCompat jreCompat = JreCompat.getInstance();
if (Modifier.isStatic(modifiers) &&
Modifier.isPublic(modifiers) &&
jreCompat.canAcccess(null, field)) {
return field.get(null);
}
} catch (IllegalArgumentException | IllegalAccessException |
NoSuchFieldException | SecurityException e) {
exception = e;
}
String msg = Util.message(context, "staticFieldELResolver.notFound",
name, clazz.getName());
if (exception == null) {
throw new PropertyNotFoundException(msg);
} else {
throw new PropertyNotFoundException(msg, exception);
}
}
return null;
}
@Override
public void setValue(ELContext context, Object base, Object property,
Object value) {
Objects.requireNonNull(context);
if (base instanceof ELClass && property instanceof String) {
Class<?> clazz = ((ELClass) base).getKlass();
String name = (String) property;
throw new PropertyNotWritableException(Util.message(context,
"staticFieldELResolver.notWriteable", name,
clazz.getName()));
}
}
@Override
public Object invoke(ELContext context, Object base, Object method,
Class<?>[] paramTypes, Object[] params) {
Objects.requireNonNull(context);
if (base instanceof ELClass && method instanceof String) {
context.setPropertyResolved(base, method);
Class<?> clazz = ((ELClass) base).getKlass();
String methodName = (String) method;
if ("<init>".equals(methodName)) {
Constructor<?> match =
Util.findConstructor(clazz, paramTypes, params);
Object[] parameters = Util.buildParameters(
match.getParameterTypes(), match.isVarArgs(), params);
Object result = null;
try {
result = match.newInstance(parameters);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
Util.handleThrowable(cause);
throw new ELException(cause);
} catch (ReflectiveOperationException e) {
throw new ELException(e);
}
return result;
} else {
// Static method so base should be null
Method match = Util.findMethod(clazz, null, methodName, paramTypes, params);
// Note: On Java 9 and above, the isStatic check becomes
// unnecessary because the canAccess() call in Util.findMethod()
// effectively performs the same check
if (match == null || !Modifier.isStatic(match.getModifiers())) {
throw new MethodNotFoundException(Util.message(context,
"staticFieldELResolver.methodNotFound", methodName,
clazz.getName()));
}
Object[] parameters = Util.buildParameters(
match.getParameterTypes(), match.isVarArgs(), params);
Object result = null;
try {
result = match.invoke(null, parameters);
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new ELException(e);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
Util.handleThrowable(cause);
throw new ELException(cause);
}
return result;
}
}
return null;
}
@Override
public Class<?> getType(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base instanceof ELClass && property instanceof String) {
context.setPropertyResolved(base, property);
Class<?> clazz = ((ELClass) base).getKlass();
String name = (String) property;
Exception exception = null;
try {
Field field = clazz.getField(name);
int modifiers = field.getModifiers();
JreCompat jreCompat = JreCompat.getInstance();
if (Modifier.isStatic(modifiers) &&
Modifier.isPublic(modifiers) &&
jreCompat.canAcccess(null, field)) {
return field.getType();
}
} catch (IllegalArgumentException | NoSuchFieldException |
SecurityException e) {
exception = e;
}
String msg = Util.message(context, "staticFieldELResolver.notFound",
name, clazz.getName());
if (exception == null) {
throw new PropertyNotFoundException(msg);
} else {
throw new PropertyNotFoundException(msg, exception);
}
}
return null;
}
@Override
public boolean isReadOnly(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
if (base instanceof ELClass && property instanceof String) {
context.setPropertyResolved(base, property);
}
return true;
}
/**
* Always returns <code>null</code>.
*/
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
Object base) {
return null;
}
/**
* Always returns <code>String.class</code>.
*/
@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
return String.class;
}
}

View File

@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.beans.FeatureDescriptor;
import java.util.Iterator;
/**
* @since EL 3.0
*/
public abstract class TypeConverter extends ELResolver {
@Override
public Object getValue(ELContext context, Object base, Object property) {
return null;
}
@Override
public Class<?> getType(ELContext context, Object base, Object property) {
return null;
}
@Override
public void setValue(ELContext context, Object base, Object property,
Object value) {
// NO-OP
}
@Override
public boolean isReadOnly(ELContext context, Object base, Object property) {
return false;
}
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
Object base) {
return null;
}
@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
return null;
}
@Override
public abstract Object convertToType(ELContext context, Object obj,
Class<?> type);
}

834
java/javax/el/Util.java Normal file
View File

@@ -0,0 +1,834 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.lang.ref.WeakReference;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
class Util {
private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[0];
private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
/**
* Checks whether the supplied Throwable is one that needs to be
* rethrown and swallows all others.
* @param t the Throwable to check
*/
static void handleThrowable(Throwable t) {
if (t instanceof ThreadDeath) {
throw (ThreadDeath) t;
}
if (t instanceof VirtualMachineError) {
throw (VirtualMachineError) t;
}
// All other instances of Throwable will be silently swallowed
}
static String message(ELContext context, String name, Object... props) {
Locale locale = null;
if (context != null) {
locale = context.getLocale();
}
if (locale == null) {
locale = Locale.getDefault();
if (locale == null) {
return "";
}
}
ResourceBundle bundle = ResourceBundle.getBundle(
"javax.el.LocalStrings", locale);
try {
String template = bundle.getString(name);
if (props != null) {
template = MessageFormat.format(template, props);
}
return template;
} catch (MissingResourceException e) {
return "Missing Resource: '" + name + "' for Locale " + locale.getDisplayName();
}
}
private static final CacheValue nullTcclFactory = new CacheValue();
private static final ConcurrentMap<CacheKey, CacheValue> factoryCache =
new ConcurrentHashMap<>();
/**
* Provides a per class loader cache of ExpressionFactory instances without
* pinning any in memory as that could trigger a memory leak.
*/
static ExpressionFactory getExpressionFactory() {
ClassLoader tccl = getContextClassLoader();
CacheValue cacheValue = null;
ExpressionFactory factory = null;
if (tccl == null) {
cacheValue = nullTcclFactory;
} else {
CacheKey key = new CacheKey(tccl);
cacheValue = factoryCache.get(key);
if (cacheValue == null) {
CacheValue newCacheValue = new CacheValue();
cacheValue = factoryCache.putIfAbsent(key, newCacheValue);
if (cacheValue == null) {
cacheValue = newCacheValue;
}
}
}
final Lock readLock = cacheValue.getLock().readLock();
readLock.lock();
try {
factory = cacheValue.getExpressionFactory();
} finally {
readLock.unlock();
}
if (factory == null) {
final Lock writeLock = cacheValue.getLock().writeLock();
writeLock.lock();
try {
factory = cacheValue.getExpressionFactory();
if (factory == null) {
factory = ExpressionFactory.newInstance();
cacheValue.setExpressionFactory(factory);
}
} finally {
writeLock.unlock();
}
}
return factory;
}
/**
* Key used to cache default ExpressionFactory information per class
* loader. The class loader reference is never {@code null}, because
* {@code null} tccl is handled separately.
*/
private static class CacheKey {
private final int hash;
private final WeakReference<ClassLoader> ref;
public CacheKey(ClassLoader key) {
hash = key.hashCode();
ref = new WeakReference<>(key);
}
@Override
public int hashCode() {
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof CacheKey)) {
return false;
}
ClassLoader thisKey = ref.get();
if (thisKey == null) {
return false;
}
return thisKey == ((CacheKey) obj).ref.get();
}
}
private static class CacheValue {
private final ReadWriteLock lock = new ReentrantReadWriteLock();
private WeakReference<ExpressionFactory> ref;
public CacheValue() {
}
public ReadWriteLock getLock() {
return lock;
}
public ExpressionFactory getExpressionFactory() {
return ref != null ? ref.get() : null;
}
public void setExpressionFactory(ExpressionFactory factory) {
ref = new WeakReference<>(factory);
}
}
/*
* This method duplicates code in org.apache.el.util.ReflectionUtil. When
* making changes keep the code in sync.
*/
static Method findMethod(Class<?> clazz, Object base, String methodName,
Class<?>[] paramTypes, Object[] paramValues) {
if (clazz == null || methodName == null) {
throw new MethodNotFoundException(
message(null, "util.method.notfound", clazz, methodName,
paramString(paramTypes)));
}
if (paramTypes == null) {
paramTypes = getTypesFromValues(paramValues);
}
Method[] methods = clazz.getMethods();
List<Wrapper<Method>> wrappers = Wrapper.wrap(methods, methodName);
Wrapper<Method> result = findWrapper(clazz, wrappers, methodName, paramTypes, paramValues);
return getMethod(clazz, base, result.unWrap());
}
/*
* This method duplicates code in org.apache.el.util.ReflectionUtil. When
* making changes keep the code in sync.
*/
@SuppressWarnings("null")
private static <T> Wrapper<T> findWrapper(Class<?> clazz, List<Wrapper<T>> wrappers,
String name, Class<?>[] paramTypes, Object[] paramValues) {
Map<Wrapper<T>,MatchResult> candidates = new HashMap<>();
int paramCount = paramTypes.length;
for (Wrapper<T> w : wrappers) {
Class<?>[] mParamTypes = w.getParameterTypes();
int mParamCount;
if (mParamTypes == null) {
mParamCount = 0;
} else {
mParamCount = mParamTypes.length;
}
// Check the number of parameters
// Multiple tests to improve readability
if (!w.isVarArgs() && paramCount != mParamCount) {
// Method has wrong number of parameters
continue;
}
if (w.isVarArgs() && paramCount < mParamCount -1) {
// Method has wrong number of parameters
continue;
}
if (w.isVarArgs() && paramCount == mParamCount && paramValues != null &&
paramValues.length > paramCount && !paramTypes[mParamCount -1].isArray()) {
// Method arguments don't match
continue;
}
if (w.isVarArgs() && paramCount > mParamCount && paramValues != null &&
paramValues.length != paramCount) {
// Might match a different varargs method
continue;
}
if (!w.isVarArgs() && paramValues != null && paramCount != paramValues.length) {
// Might match a different varargs method
continue;
}
// Check the parameters match
int exactMatch = 0;
int assignableMatch = 0;
int coercibleMatch = 0;
boolean noMatch = false;
for (int i = 0; i < mParamCount; i++) {
// Can't be null
if (w.isVarArgs() && i == (mParamCount - 1)) {
if (i == paramCount || (paramValues != null && paramValues.length == i)) {
// Nothing is passed as varargs
assignableMatch++;
break;
}
Class<?> varType = mParamTypes[i].getComponentType();
for (int j = i; j < paramCount; j++) {
if (isAssignableFrom(paramTypes[j], varType)) {
assignableMatch++;
} else {
if (paramValues == null) {
noMatch = true;
break;
} else {
if (isCoercibleFrom(paramValues[j], varType)) {
coercibleMatch++;
} else {
noMatch = true;
break;
}
}
}
// Don't treat a varArgs match as an exact match, it can
// lead to a varArgs method matching when the result
// should be ambiguous
}
} else {
if (mParamTypes[i].equals(paramTypes[i])) {
exactMatch++;
} else if (paramTypes[i] != null && isAssignableFrom(paramTypes[i], mParamTypes[i])) {
assignableMatch++;
} else {
if (paramValues == null) {
noMatch = true;
break;
} else {
if (isCoercibleFrom(paramValues[i], mParamTypes[i])) {
coercibleMatch++;
} else {
noMatch = true;
break;
}
}
}
}
}
if (noMatch) {
continue;
}
// If a method is found where every parameter matches exactly,
// return it
if (exactMatch == paramCount) {
return w;
}
candidates.put(w, new MatchResult(
exactMatch, assignableMatch, coercibleMatch, w.isBridge()));
}
// Look for the method that has the highest number of parameters where
// the type matches exactly
MatchResult bestMatch = new MatchResult(0, 0, 0, false);
Wrapper<T> match = null;
boolean multiple = false;
for (Map.Entry<Wrapper<T>, MatchResult> entry : candidates.entrySet()) {
int cmp = entry.getValue().compareTo(bestMatch);
if (cmp > 0 || match == null) {
bestMatch = entry.getValue();
match = entry.getKey();
multiple = false;
} else if (cmp == 0) {
multiple = true;
}
}
if (multiple) {
if (bestMatch.getExact() == paramCount - 1) {
// Only one parameter is not an exact match - try using the
// super class
match = resolveAmbiguousWrapper(candidates.keySet(), paramTypes);
} else {
match = null;
}
if (match == null) {
// If multiple methods have the same matching number of parameters
// the match is ambiguous so throw an exception
throw new MethodNotFoundException(message(
null, "util.method.ambiguous", clazz, name,
paramString(paramTypes)));
}
}
// Handle case where no match at all was found
if (match == null) {
throw new MethodNotFoundException(message(
null, "util.method.notfound", clazz, name,
paramString(paramTypes)));
}
return match;
}
private static final String paramString(Class<?>[] types) {
if (types != null) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < types.length; i++) {
if (types[i] == null) {
sb.append("null, ");
} else {
sb.append(types[i].getName()).append(", ");
}
}
if (sb.length() > 2) {
sb.setLength(sb.length() - 2);
}
return sb.toString();
}
return null;
}
/*
* This method duplicates code in org.apache.el.util.ReflectionUtil. When
* making changes keep the code in sync.
*/
private static <T> Wrapper<T> resolveAmbiguousWrapper(Set<Wrapper<T>> candidates,
Class<?>[] paramTypes) {
// Identify which parameter isn't an exact match
Wrapper<T> w = candidates.iterator().next();
int nonMatchIndex = 0;
Class<?> nonMatchClass = null;
for (int i = 0; i < paramTypes.length; i++) {
if (w.getParameterTypes()[i] != paramTypes[i]) {
nonMatchIndex = i;
nonMatchClass = paramTypes[i];
break;
}
}
if (nonMatchClass == null) {
// Null will always be ambiguous
return null;
}
for (Wrapper<T> c : candidates) {
if (c.getParameterTypes()[nonMatchIndex] ==
paramTypes[nonMatchIndex]) {
// Methods have different non-matching parameters
// Result is ambiguous
return null;
}
}
// Can't be null
Class<?> superClass = nonMatchClass.getSuperclass();
while (superClass != null) {
for (Wrapper<T> c : candidates) {
if (c.getParameterTypes()[nonMatchIndex].equals(superClass)) {
// Found a match
return c;
}
}
superClass = superClass.getSuperclass();
}
// Treat instances of Number as a special case
Wrapper<T> match = null;
if (Number.class.isAssignableFrom(nonMatchClass)) {
for (Wrapper<T> c : candidates) {
Class<?> candidateType = c.getParameterTypes()[nonMatchIndex];
if (Number.class.isAssignableFrom(candidateType) ||
candidateType.isPrimitive()) {
if (match == null) {
match = c;
} else {
// Match still ambiguous
match = null;
break;
}
}
}
}
return match;
}
/*
* This method duplicates code in org.apache.el.util.ReflectionUtil. When
* making changes keep the code in sync.
*/
static boolean isAssignableFrom(Class<?> src, Class<?> target) {
// src will always be an object
// Short-cut. null is always assignable to an object and in EL null
// can always be coerced to a valid value for a primitive
if (src == null) {
return true;
}
Class<?> targetClass;
if (target.isPrimitive()) {
if (target == Boolean.TYPE) {
targetClass = Boolean.class;
} else if (target == Character.TYPE) {
targetClass = Character.class;
} else if (target == Byte.TYPE) {
targetClass = Byte.class;
} else if (target == Short.TYPE) {
targetClass = Short.class;
} else if (target == Integer.TYPE) {
targetClass = Integer.class;
} else if (target == Long.TYPE) {
targetClass = Long.class;
} else if (target == Float.TYPE) {
targetClass = Float.class;
} else {
targetClass = Double.class;
}
} else {
targetClass = target;
}
return targetClass.isAssignableFrom(src);
}
/*
* This method duplicates code in org.apache.el.util.ReflectionUtil. When
* making changes keep the code in sync.
*/
private static boolean isCoercibleFrom(Object src, Class<?> target) {
// TODO: This isn't pretty but it works. Significant refactoring would
// be required to avoid the exception.
try {
getExpressionFactory().coerceToType(src, target);
} catch (ELException e) {
return false;
}
return true;
}
private static Class<?>[] getTypesFromValues(Object[] values) {
if (values == null) {
return EMPTY_CLASS_ARRAY;
}
Class<?> result[] = new Class<?>[values.length];
for (int i = 0; i < values.length; i++) {
if (values[i] == null) {
result[i] = null;
} else {
result[i] = values[i].getClass();
}
}
return result;
}
/*
* This method duplicates code in org.apache.el.util.ReflectionUtil. When
* making changes keep the code in sync.
*/
static Method getMethod(Class<?> type, Object base, Method m) {
JreCompat jreCompat = JreCompat.getInstance();
// If base is null, method MUST be static
// If base is non-null, method may be static or non-static
if (m == null ||
(Modifier.isPublic(type.getModifiers()) &&
(jreCompat.canAcccess(base, m) || base != null && jreCompat.canAcccess(null, m)))) {
return m;
}
Class<?>[] inf = type.getInterfaces();
Method mp = null;
for (int i = 0; i < inf.length; i++) {
try {
mp = inf[i].getMethod(m.getName(), m.getParameterTypes());
mp = getMethod(mp.getDeclaringClass(), base, mp);
if (mp != null) {
return mp;
}
} catch (NoSuchMethodException e) {
// Ignore
}
}
Class<?> sup = type.getSuperclass();
if (sup != null) {
try {
mp = sup.getMethod(m.getName(), m.getParameterTypes());
mp = getMethod(mp.getDeclaringClass(), base, mp);
if (mp != null) {
return mp;
}
} catch (NoSuchMethodException e) {
// Ignore
}
}
return null;
}
static Constructor<?> findConstructor(Class<?> clazz, Class<?>[] paramTypes,
Object[] paramValues) {
String methodName = "<init>";
if (clazz == null) {
throw new MethodNotFoundException(
message(null, "util.method.notfound", null, methodName,
paramString(paramTypes)));
}
if (paramTypes == null) {
paramTypes = getTypesFromValues(paramValues);
}
Constructor<?>[] constructors = clazz.getConstructors();
List<Wrapper<Constructor<?>>> wrappers = Wrapper.wrap(constructors);
Wrapper<Constructor<?>> wrapper = findWrapper(clazz, wrappers, methodName, paramTypes, paramValues);
Constructor<?> constructor = wrapper.unWrap();
JreCompat jreCompat = JreCompat.getInstance();
if (!Modifier.isPublic(clazz.getModifiers()) || !jreCompat.canAcccess(null, constructor)) {
throw new MethodNotFoundException(message(
null, "util.method.notfound", clazz, methodName,
paramString(paramTypes)));
}
return constructor;
}
static Object[] buildParameters(Class<?>[] parameterTypes,
boolean isVarArgs,Object[] params) {
ExpressionFactory factory = getExpressionFactory();
Object[] parameters = null;
if (parameterTypes.length > 0) {
parameters = new Object[parameterTypes.length];
int paramCount;
if (params == null) {
params = EMPTY_OBJECT_ARRAY;
}
paramCount = params.length;
if (isVarArgs) {
int varArgIndex = parameterTypes.length - 1;
// First argCount-1 parameters are standard
for (int i = 0; (i < varArgIndex); i++) {
parameters[i] = factory.coerceToType(params[i],
parameterTypes[i]);
}
// Last parameter is the varargs
Class<?> varArgClass =
parameterTypes[varArgIndex].getComponentType();
final Object varargs = Array.newInstance(
varArgClass,
(paramCount - varArgIndex));
for (int i = (varArgIndex); i < paramCount; i++) {
Array.set(varargs, i - varArgIndex,
factory.coerceToType(params[i], varArgClass));
}
parameters[varArgIndex] = varargs;
} else {
parameters = new Object[parameterTypes.length];
for (int i = 0; i < parameterTypes.length; i++) {
parameters[i] = factory.coerceToType(params[i],
parameterTypes[i]);
}
}
}
return parameters;
}
static ClassLoader getContextClassLoader() {
ClassLoader tccl;
if (System.getSecurityManager() != null) {
PrivilegedAction<ClassLoader> pa = new PrivilegedGetTccl();
tccl = AccessController.doPrivileged(pa);
} else {
tccl = Thread.currentThread().getContextClassLoader();
}
return tccl;
}
private abstract static class Wrapper<T> {
public static List<Wrapper<Method>> wrap(Method[] methods, String name) {
List<Wrapper<Method>> result = new ArrayList<>();
for (Method method : methods) {
if (method.getName().equals(name)) {
result.add(new MethodWrapper(method));
}
}
return result;
}
public static List<Wrapper<Constructor<?>>> wrap(Constructor<?>[] constructors) {
List<Wrapper<Constructor<?>>> result = new ArrayList<>();
for (Constructor<?> constructor : constructors) {
result.add(new ConstructorWrapper(constructor));
}
return result;
}
public abstract T unWrap();
public abstract Class<?>[] getParameterTypes();
public abstract boolean isVarArgs();
public abstract boolean isBridge();
}
private static class MethodWrapper extends Wrapper<Method> {
private final Method m;
public MethodWrapper(Method m) {
this.m = m;
}
@Override
public Method unWrap() {
return m;
}
@Override
public Class<?>[] getParameterTypes() {
return m.getParameterTypes();
}
@Override
public boolean isVarArgs() {
return m.isVarArgs();
}
@Override
public boolean isBridge() {
return m.isBridge();
}
}
private static class ConstructorWrapper extends Wrapper<Constructor<?>> {
private final Constructor<?> c;
public ConstructorWrapper(Constructor<?> c) {
this.c = c;
}
@Override
public Constructor<?> unWrap() {
return c;
}
@Override
public Class<?>[] getParameterTypes() {
return c.getParameterTypes();
}
@Override
public boolean isVarArgs() {
return c.isVarArgs();
}
@Override
public boolean isBridge() {
return false;
}
}
/*
* This class duplicates code in org.apache.el.util.ReflectionUtil. When
* making changes keep the code in sync.
*/
private static class MatchResult implements Comparable<MatchResult> {
private final int exact;
private final int assignable;
private final int coercible;
private final boolean bridge;
public MatchResult(int exact, int assignable, int coercible, boolean bridge) {
this.exact = exact;
this.assignable = assignable;
this.coercible = coercible;
this.bridge = bridge;
}
public int getExact() {
return exact;
}
public int getAssignable() {
return assignable;
}
public int getCoercible() {
return coercible;
}
public boolean isBridge() {
return bridge;
}
@Override
public int compareTo(MatchResult o) {
int cmp = Integer.compare(this.getExact(), o.getExact());
if (cmp == 0) {
cmp = Integer.compare(this.getAssignable(), o.getAssignable());
if (cmp == 0) {
cmp = Integer.compare(this.getCoercible(), o.getCoercible());
if (cmp == 0) {
// The nature of bridge methods is such that it actually
// doesn't matter which one we pick as long as we pick
// one. That said, pick the 'right' one (the non-bridge
// one) anyway.
cmp = Boolean.compare(o.isBridge(), this.isBridge());
}
}
}
return cmp;
}
@Override
public boolean equals(Object o)
{
return o == this || (null != o &&
this.getClass().equals(o.getClass()) &&
((MatchResult)o).getExact() == this.getExact() &&
((MatchResult)o).getAssignable() == this.getAssignable() &&
((MatchResult)o).getCoercible() == this.getCoercible() &&
((MatchResult)o).isBridge() == this.isBridge());
}
@Override
public int hashCode()
{
return (this.isBridge() ? 1 << 24 : 0) ^
this.getExact() << 16 ^
this.getAssignable() << 8 ^
this.getCoercible();
}
}
private static class PrivilegedGetTccl implements PrivilegedAction<ClassLoader> {
@Override
public ClassLoader run() {
return Thread.currentThread().getContextClassLoader();
}
}
}

View File

@@ -0,0 +1,106 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
public abstract class ValueExpression extends Expression {
private static final long serialVersionUID = 8577809572381654673L;
/**
* @param context The EL context for this evaluation
*
* @return The result of evaluating this value expression
*
* @throws NullPointerException
* If the supplied context is <code>null</code>
* @throws PropertyNotFoundException
* If a property/variable resolution failed because no match
* was found or a match was found but was not readable
* @throws ELException
* Wraps any exception throw whilst resolving a property or
* variable
*/
public abstract Object getValue(ELContext context);
/**
* @param context The EL context for this evaluation
* @param value The value to set the property to which this value
* expression refers
*
* @throws NullPointerException
* If the supplied context is <code>null</code>
* @throws PropertyNotFoundException
* If a property/variable resolution failed because no match
* was found
* @throws PropertyNotWritableException
* If a property/variable resolution failed because a match was
* found but was not writable
* @throws ELException
* Wraps any exception throw whilst resolving a property or
* variable
*/
public abstract void setValue(ELContext context, Object value);
/**
* @param context The EL context for this evaluation
*
* @return <code>true</code> if this expression is read only otherwise
* <code>false</code>
*
* @throws NullPointerException
* If the supplied context is <code>null</code>
* @throws PropertyNotFoundException
* If a property/variable resolution failed because no match
* was found or a match was found but was not readable
* @throws ELException
* Wraps any exception throw whilst resolving a property or
* variable
*/
public abstract boolean isReadOnly(ELContext context);
/**
* @param context The EL context for this evaluation
*
* @return The type of the result of this value expression
*
* @throws NullPointerException
* If the supplied context is <code>null</code>
* @throws PropertyNotFoundException
* If a property/variable resolution failed because no match
* was found or a match was found but was not readable
* @throws ELException
* Wraps any exception throw whilst resolving a property or
* variable
*/
public abstract Class<?> getType(ELContext context);
public abstract Class<?> getExpectedType();
/**
* @param context The EL context for this evaluation
*
* @return This default implementation always returns <code>null</code>
*
* @since EL 2.2
*/
public ValueReference getValueReference(ELContext context) {
// Expected to be over-ridden by implementation
context.notifyBeforeEvaluation(getExpressionString());
context.notifyAfterEvaluation(getExpressionString());
return null;
}
}

View File

@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
import java.io.Serializable;
/**
* @since EL 2.2
*/
public class ValueReference implements Serializable {
private static final long serialVersionUID = 1L;
private final Object base;
private final Object property;
public ValueReference(Object base, Object property) {
this.base = base;
this.property = property;
}
public Object getBase() {
return base;
}
public Object getProperty() {
return property;
}
}

View File

@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.el;
/**
*
*/
public abstract class VariableMapper {
public abstract ValueExpression resolveVariable(String variable);
public abstract ValueExpression setVariable(String variable, ValueExpression expression);
}

View File

@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.mail;
public class Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
return null;
}
}

View File

@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.mail;
@SuppressWarnings("unused") // Dummy implementation
public class PasswordAuthentication {
public PasswordAuthentication(String user, String password) {
// Dummy implementation
}
}

View File

@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.mail;
import java.util.Properties;
@SuppressWarnings("unused") // Dummy implementation
public class Session {
public static Session getInstance(Properties props, Authenticator auth) {
return null;
}
public static Session getInstance(Properties props) {
return null;
}
}

View File

@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.mail.internet;
@SuppressWarnings("unused") // Dummy implementation
public class InternetAddress {
public InternetAddress(String from) {
// Dummy implementation
}
}

View File

@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.mail.internet;
import javax.mail.Session;
@SuppressWarnings("unused") // Dummy implementation
public class MimeMessage implements MimePart {
public MimeMessage(Session session) {
// Dummy implementation
}
public void setFrom(InternetAddress from) {
// Dummy implementation
}
public void setSubject(String subject) {
// Dummy implementation
}
}

View File

@@ -0,0 +1,21 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.mail.internet;
public interface MimePart {
// Dummy implementation
}

View File

@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.mail.internet;
@SuppressWarnings("unused") // Dummy implementation
public class MimePartDataSource {
public MimePartDataSource(MimePart part) {
// Dummy implementation
}
}

View File

@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.persistence;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface PersistenceContext {
String name() default "";
String unitName() default "";
PersistenceContextType type() default PersistenceContextType.TRANSACTION;
PersistenceProperty[] properties() default {};
SynchronizationType synchronization() default SynchronizationType.SYNCHRONIZED;
}

View File

@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.persistence;
public enum PersistenceContextType {
TRANSACTION,
EXTENDED
}

View File

@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.persistence;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface PersistenceContexts {
PersistenceContext[] value();
}

View File

@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.persistence;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({})
@Retention(RetentionPolicy.RUNTIME)
public @interface PersistenceProperty {
String name();
String value();
}

View File

@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.persistence;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface PersistenceUnit {
String name() default "";
String unitName() default "";
}

View File

@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.persistence;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface PersistenceUnits {
PersistenceUnit[] value();
}

View File

@@ -0,0 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.persistence;
public enum SynchronizationType {
SYNCHRONIZED,
UNSYNCHRONIZED
}

View File

@@ -0,0 +1,30 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message;
import javax.security.auth.login.LoginException;
public class AuthException extends LoginException {
private static final long serialVersionUID = -1156951780670243758L;
public AuthException() {
}
public AuthException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,37 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message;
public class AuthStatus {
public static final AuthStatus SUCCESS = new AuthStatus("SUCCESS");
public static final AuthStatus FAILURE = new AuthStatus("FAILURE");
public static final AuthStatus SEND_SUCCESS = new AuthStatus("SEND_SUCCESS");
public static final AuthStatus SEND_FAILURE = new AuthStatus("SEND_FAILURE");
public static final AuthStatus SEND_CONTINUE = new AuthStatus("SEND_CONTINUE");
private final String name;
private AuthStatus(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}

View File

@@ -0,0 +1,30 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message;
import javax.security.auth.Subject;
public interface ClientAuth {
AuthStatus secureRequest(MessageInfo messageInfo, Subject clientSubject) throws AuthException;
AuthStatus validateResponse(MessageInfo messageInfo, Subject clientSubject,
Subject serviceSubject) throws AuthException;
void cleanSubject(MessageInfo messageInfo, Subject subject) throws AuthException;
}

View File

@@ -0,0 +1,33 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message;
import java.util.Map;
public interface MessageInfo {
Object getRequestMessage();
Object getResponseMessage();
void setRequestMessage(Object request);
void setResponseMessage(Object response);
@SuppressWarnings("rawtypes") // JASPIC API uses raw types
Map getMap();
}

View File

@@ -0,0 +1,85 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message;
public class MessagePolicy {
private final TargetPolicy[] targetPolicies;
private final boolean mandatory;
public MessagePolicy(TargetPolicy[] targetPolicies, boolean mandatory) {
if (targetPolicies == null) {
throw new IllegalArgumentException("targetPolicies is null");
}
this.targetPolicies = targetPolicies;
this.mandatory = mandatory;
}
public boolean isMandatory() {
return mandatory;
}
public TargetPolicy[] getTargetPolicies() {
if (targetPolicies.length == 0) {
return null;
}
return targetPolicies;
}
public static interface ProtectionPolicy {
static String AUTHENTICATE_SENDER = "#authenticateSender";
static String AUTHENTICATE_CONTENT = "#authenticateContent";
static String AUTHENTICATE_RECIPIENT = "#authenticateRecipient";
String getID();
}
public static interface Target {
Object get(MessageInfo messageInfo);
void remove(MessageInfo messageInfo);
void put(MessageInfo messageInfo, Object data);
}
public static class TargetPolicy {
private final Target[] targets;
private final ProtectionPolicy protectionPolicy;
public TargetPolicy(Target[] targets, ProtectionPolicy protectionPolicy) {
if (protectionPolicy == null) {
throw new IllegalArgumentException("protectionPolicy is null");
}
this.targets = targets;
this.protectionPolicy = protectionPolicy;
}
public Target[] getTargets() {
if (targets == null || targets.length == 0) {
return null;
}
return targets;
}
public ProtectionPolicy getProtectionPolicy() {
return protectionPolicy;
}
}
}

View File

@@ -0,0 +1,29 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message;
import javax.security.auth.Subject;
public interface ServerAuth {
AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject,
Subject serviceSubject) throws AuthException;
AuthStatus secureResponse(MessageInfo messageInfo, Subject serviceSubject) throws AuthException;
void cleanSubject(MessageInfo messageInfo, Subject subject) throws AuthException;
}

View File

@@ -0,0 +1,57 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.callback;
import java.security.Principal;
import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
/**
* Callback that enables an authentication module to inform the runtime of the
* call principal or name of the caller principal.
*/
public class CallerPrincipalCallback implements Callback {
private final Subject subject;
private final Principal principal;
private final String name;
public CallerPrincipalCallback(Subject subject, Principal principal) {
this.subject = subject;
this.principal = principal;
this.name = null;
}
public CallerPrincipalCallback(Subject subject, String name) {
this.subject = subject;
this.principal = null;
this.name = name;
}
public Subject getSubject() {
return subject;
}
public Principal getPrincipal() {
return principal;
}
public String getName() {
return name;
}
}

View File

@@ -0,0 +1,41 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.callback;
import java.security.cert.CertStore;
import javax.security.auth.callback.Callback;
/**
* Callback that enables a runtime to inform authentication modules of the
* CertStore to use.
*/
public class CertStoreCallback implements Callback {
private CertStore certStore;
public CertStoreCallback() {
}
public void setCertStore(CertStore certStore) {
this.certStore = certStore;
}
public CertStore getCertStore() {
return certStore;
}
}

View File

@@ -0,0 +1,43 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.callback;
import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
/**
* Callback that enables an authentication module to inform the runtime of the
* groups a user is in.
*/
public class GroupPrincipalCallback implements Callback {
private final Subject subject;
private final String[] groups;
public GroupPrincipalCallback(Subject subject, String[] groups) {
this.subject = subject;
this.groups = groups;
}
public Subject getSubject() {
return subject;
}
public String[] getGroups() {
return groups;
}
}

View File

@@ -0,0 +1,65 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.callback;
import java.util.Arrays;
import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
/**
* Callback that enables an authentication module to supply a user name and
* password (to a runtime?) and determine if the result of validation.
*/
public class PasswordValidationCallback implements Callback {
private final Subject subject;
private final String username;
private char[] password;
private boolean result;
public PasswordValidationCallback(Subject subject, String username, char[] password) {
this.subject = subject;
this.username = username;
this.password = password;
}
public Subject getSubject() {
return subject;
}
public String getUsername() {
return username;
}
public char[] getPassword() {
return password;
}
public void clearPassword() {
Arrays.fill(password, (char) 0);
password = new char[0];
}
public void setResult(boolean result) {
this.result = result;
}
public boolean getResult() {
return result;
}
}

View File

@@ -0,0 +1,123 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.callback;
import java.math.BigInteger;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import javax.security.auth.callback.Callback;
import javax.security.auth.x500.X500Principal;
/**
* Callback that enables an authentication module to request a certificate chain
* and private key from the runtime. The information specifying the chain and
* key may be an alias, a digest, a subject key, or an issuer ID. Other request
* types may be supported.
*/
public class PrivateKeyCallback implements Callback {
private final Request request;
private Certificate[] chain;
private PrivateKey key;
public PrivateKeyCallback(Request request) {
this.request = request;
}
public Request getRequest() {
return request;
}
public void setKey(PrivateKey key, Certificate[] chain) {
this.key = key;
this.chain = chain;
}
public PrivateKey getKey() {
return key;
}
public Certificate[] getChain() {
return chain;
}
public static interface Request {
}
public static class AliasRequest implements Request {
private final String alias;
public AliasRequest(String alias) {
this.alias = alias;
}
public String getAlias() {
return alias;
}
}
public static class DigestRequest implements Request {
private final byte[] digest;
private final String algorithm;
public DigestRequest(byte[] digest, String algorithm) {
this.digest = digest;
this.algorithm = algorithm;
}
public byte[] getDigest() {
return digest;
}
public String getAlgorithm() {
return algorithm;
}
}
public static class SubjectKeyIDRequest implements Request {
private final byte[] subjectKeyID;
public SubjectKeyIDRequest(byte[] subjectKeyID) {
this.subjectKeyID = subjectKeyID;
}
public byte[] getSubjectKeyID() {
return subjectKeyID;
}
}
public static class IssuerSerialNumRequest implements Request {
private final X500Principal issuer;
private final BigInteger serialNum;
public IssuerSerialNumRequest(X500Principal issuer, BigInteger serialNum) {
this.issuer = issuer;
this.serialNum = serialNum;
}
public X500Principal getIssuer() {
return issuer;
}
public BigInteger getSerialNum() {
return serialNum;
}
}
}

View File

@@ -0,0 +1,62 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.callback;
import javax.crypto.SecretKey;
import javax.security.auth.callback.Callback;
/**
* A callback enabling an authentication module to request a secret key from the
* runtime, by supplying an alias. Other request types may also be supported.
*/
public class SecretKeyCallback implements Callback {
private final Request request;
private SecretKey key;
public SecretKeyCallback(Request request) {
this.request = request;
}
public Request getRequest() {
return request;
}
public void setKey(SecretKey key) {
this.key = key;
}
public SecretKey getKey() {
return key;
}
public static interface Request {
}
public static class AliasRequest implements Request {
private final String alias;
public AliasRequest(String alias) {
this.alias = alias;
}
public String getAlias() {
return alias;
}
}
}

View File

@@ -0,0 +1,38 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.callback;
import java.security.KeyStore;
import javax.security.auth.callback.Callback;
/**
* A Callback enabling an authentication module to request a truststore from the
* runtime.
*/
public class TrustStoreCallback implements Callback {
private KeyStore trustStore;
public void setTrustStore(KeyStore trustStore) {
this.trustStore = trustStore;
}
public KeyStore getTrustStore() {
return trustStore;
}
}

View File

@@ -0,0 +1,32 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.config;
import javax.security.auth.message.MessageInfo;
public interface AuthConfig {
String getMessageLayer();
String getAppContext();
String getAuthContextID(MessageInfo messageInfo);
void refresh();
boolean isProtected();
}

View File

@@ -0,0 +1,153 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.config;
import java.security.AccessController;
import java.security.Permission;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.Security;
import java.security.SecurityPermission;
import java.util.Map;
public abstract class AuthConfigFactory {
public static final String DEFAULT_FACTORY_SECURITY_PROPERTY =
"authconfigprovider.factory";
public static final String GET_FACTORY_PERMISSION_NAME =
"getProperty.authconfigprovider.factory";
public static final String SET_FACTORY_PERMISSION_NAME =
"setProperty.authconfigprovider.factory";
public static final String PROVIDER_REGISTRATION_PERMISSION_NAME =
"setProperty.authconfigfactory.provider";
public static final SecurityPermission getFactorySecurityPermission =
new SecurityPermission(GET_FACTORY_PERMISSION_NAME);
public static final SecurityPermission setFactorySecurityPermission =
new SecurityPermission(SET_FACTORY_PERMISSION_NAME);
public static final SecurityPermission providerRegistrationSecurityPermission =
new SecurityPermission(PROVIDER_REGISTRATION_PERMISSION_NAME);
private static final String DEFAULT_JASPI_AUTHCONFIGFACTORYIMPL =
"org.apache.catalina.authenticator.jaspic.AuthConfigFactoryImpl";
private static volatile AuthConfigFactory factory;
public AuthConfigFactory() {
}
public static AuthConfigFactory getFactory() {
checkPermission(getFactorySecurityPermission);
if (factory != null) {
return factory;
}
synchronized (AuthConfigFactory.class) {
if (factory == null) {
final String className = getFactoryClassName();
try {
factory = AccessController.doPrivileged(
new PrivilegedExceptionAction<AuthConfigFactory>() {
@Override
public AuthConfigFactory run() throws ReflectiveOperationException,
IllegalArgumentException, SecurityException {
// Load this class with the same class loader as used for
// this class. Note that the Thread context class loader
// should not be used since that would trigger a memory leak
// in container environments.
Class<?> clazz = Class.forName(className);
return (AuthConfigFactory) clazz.getConstructor().newInstance();
}
});
} catch (PrivilegedActionException e) {
Exception inner = e.getException();
if (inner instanceof InstantiationException) {
throw (SecurityException) new SecurityException("AuthConfigFactory error:" +
inner.getCause().getMessage()).initCause(inner.getCause());
} else {
throw (SecurityException) new SecurityException(
"AuthConfigFactory error: " + inner).initCause(inner);
}
}
}
}
return factory;
}
public static synchronized void setFactory(AuthConfigFactory factory) {
checkPermission(setFactorySecurityPermission);
AuthConfigFactory.factory = factory;
}
public abstract AuthConfigProvider getConfigProvider(String layer, String appContext,
RegistrationListener listener);
@SuppressWarnings("rawtypes") // JASPIC API uses raw types
public abstract String registerConfigProvider(String className, Map properties, String layer,
String appContext, String description);
public abstract String registerConfigProvider(AuthConfigProvider provider, String layer,
String appContext, String description);
public abstract boolean removeRegistration(String registrationID);
public abstract String[] detachListener(RegistrationListener listener, String layer,
String appContext);
public abstract String[] getRegistrationIDs(AuthConfigProvider provider);
public abstract RegistrationContext getRegistrationContext(String registrationID);
public abstract void refresh();
private static void checkPermission(Permission permission) {
SecurityManager securityManager = System.getSecurityManager();
if (securityManager != null) {
securityManager.checkPermission(permission);
}
}
private static String getFactoryClassName() {
String className = AccessController.doPrivileged(new PrivilegedAction<String>() {
@Override
public String run() {
return Security.getProperty(DEFAULT_FACTORY_SECURITY_PROPERTY);
}
});
if (className != null) {
return className;
}
return DEFAULT_JASPI_AUTHCONFIGFACTORYIMPL;
}
public static interface RegistrationContext {
String getMessageLayer();
String getAppContext();
String getDescription();
boolean isPersistent();
}
}

View File

@@ -0,0 +1,31 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.config;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.message.AuthException;
public interface AuthConfigProvider {
ClientAuthConfig getClientAuthConfig(String layer, String appContext, CallbackHandler handler)
throws AuthException;
ServerAuthConfig getServerAuthConfig(String layer, String appContext, CallbackHandler handler)
throws AuthException;
void refresh();
}

View File

@@ -0,0 +1,29 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.config;
import java.util.Map;
import javax.security.auth.Subject;
import javax.security.auth.message.AuthException;
public interface ClientAuthConfig extends AuthConfig {
@SuppressWarnings("rawtypes") // JASPIC API uses raw types
ClientAuthContext getAuthContext(String authContextID, Subject clientSubject, Map properties)
throws AuthException;
}

View File

@@ -0,0 +1,22 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.config;
import javax.security.auth.message.ClientAuth;
public interface ClientAuthContext extends ClientAuth {
}

View File

@@ -0,0 +1,22 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.config;
public interface RegistrationListener {
void notify(String layer, String appContext);
}

View File

@@ -0,0 +1,29 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.config;
import java.util.Map;
import javax.security.auth.Subject;
import javax.security.auth.message.AuthException;
public interface ServerAuthConfig extends AuthConfig {
@SuppressWarnings("rawtypes") // JASPIC API uses raw types
ServerAuthContext getAuthContext(String authContextID, Subject serviceSubject, Map properties)
throws AuthException;
}

View File

@@ -0,0 +1,22 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.config;
import javax.security.auth.message.ServerAuth;
public interface ServerAuthContext extends ServerAuth {
}

View File

@@ -0,0 +1,34 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.module;
import java.util.Map;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.message.AuthException;
import javax.security.auth.message.ClientAuth;
import javax.security.auth.message.MessagePolicy;
public interface ClientAuthModule extends ClientAuth {
@SuppressWarnings("rawtypes") // JASPIC API uses raw types
void initialize(MessagePolicy requestPolicy, MessagePolicy responsePolicy,
CallbackHandler handler, Map options) throws AuthException;
@SuppressWarnings("rawtypes") // JASPIC API uses raw types
Class[] getSupportedMessageTypes();
}

View File

@@ -0,0 +1,34 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.security.auth.message.module;
import java.util.Map;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.message.AuthException;
import javax.security.auth.message.MessagePolicy;
import javax.security.auth.message.ServerAuth;
public interface ServerAuthModule extends ServerAuth {
@SuppressWarnings("rawtypes") // JASPIC API uses raw types
void initialize(MessagePolicy requestPolicy, MessagePolicy responsePolicy,
CallbackHandler handler, Map options) throws AuthException;
@SuppressWarnings("rawtypes") // JASPIC API uses raw types
Class[] getSupportedMessageTypes();
}

View File

@@ -0,0 +1,106 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.servlet;
/**
* TODO SERVLET3 - Add comments
* @since Servlet 3.0
*/
public interface AsyncContext {
public static final String ASYNC_REQUEST_URI =
"javax.servlet.async.request_uri";
public static final String ASYNC_CONTEXT_PATH =
"javax.servlet.async.context_path";
public static final String ASYNC_PATH_INFO =
"javax.servlet.async.path_info";
public static final String ASYNC_SERVLET_PATH =
"javax.servlet.async.servlet_path";
public static final String ASYNC_QUERY_STRING =
"javax.servlet.async.query_string";
ServletRequest getRequest();
ServletResponse getResponse();
boolean hasOriginalRequestAndResponse();
/**
* @throws IllegalStateException if this method is called when the request
* is not in asynchronous mode. The request is in asynchronous mode after
* {@link javax.servlet.http.HttpServletRequest#startAsync()} or
* {@link javax.servlet.http.HttpServletRequest#startAsync(ServletRequest,
* ServletResponse)} has been called and before {@link #complete()} or any
* other dispatch() method has been called.
*/
void dispatch();
/**
* @param path The path to which the request/response should be dispatched
* relative to the {@link ServletContext} from which this async
* request was started.
*
* @throws IllegalStateException if this method is called when the request
* is not in asynchronous mode. The request is in asynchronous mode after
* {@link javax.servlet.http.HttpServletRequest#startAsync()} or
* {@link javax.servlet.http.HttpServletRequest#startAsync(ServletRequest,
* ServletResponse)} has been called and before {@link #complete()} or any
* other dispatch() method has been called.
*/
void dispatch(String path);
/**
* @param path The path to which the request/response should be dispatched
* relative to the specified {@link ServletContext}.
* @param context The {@link ServletContext} to which the request/response
* should be dispatched.
*
* @throws IllegalStateException if this method is called when the request
* is not in asynchronous mode. The request is in asynchronous mode after
* {@link javax.servlet.http.HttpServletRequest#startAsync()} or
* {@link javax.servlet.http.HttpServletRequest#startAsync(ServletRequest,
* ServletResponse)} has been called and before {@link #complete()} or any
* other dispatch() method has been called.
*/
void dispatch(ServletContext context, String path);
void complete();
void start(Runnable run);
void addListener(AsyncListener listener);
void addListener(AsyncListener listener, ServletRequest request,
ServletResponse response);
<T extends AsyncListener> T createListener(Class<T> clazz)
throws ServletException;
/**
* Set the timeout.
*
* @param timeout The timeout in milliseconds. 0 or less indicates no
* timeout.
*/
void setTimeout(long timeout);
/**
* Get the current timeout.
*
* @return The timeout in milliseconds. 0 or less indicates no timeout.
*/
long getTimeout();
}

View File

@@ -0,0 +1,74 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.servlet;
/**
* TODO SERVLET3 - Add comments
* @since Servlet 3.0
*/
public class AsyncEvent {
private final AsyncContext context;
private final ServletRequest request;
private final ServletResponse response;
private final Throwable throwable;
public AsyncEvent(AsyncContext context) {
this.context = context;
this.request = null;
this.response = null;
this.throwable = null;
}
public AsyncEvent(AsyncContext context, ServletRequest request,
ServletResponse response) {
this.context = context;
this.request = request;
this.response = response;
this.throwable = null;
}
public AsyncEvent(AsyncContext context, Throwable throwable) {
this.context = context;
this.throwable = throwable;
this.request = null;
this.response = null;
}
public AsyncEvent(AsyncContext context, ServletRequest request,
ServletResponse response, Throwable throwable) {
this.context = context;
this.request = request;
this.response = response;
this.throwable = throwable;
}
public AsyncContext getAsyncContext() {
return context;
}
public ServletRequest getSuppliedRequest() {
return request;
}
public ServletResponse getSuppliedResponse() {
return response;
}
public Throwable getThrowable() {
return throwable;
}
}

View File

@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.servlet;
import java.io.IOException;
import java.util.EventListener;
/**
* TODO SERVLET3 - Add comments
* @since Servlet 3.0
*/
public interface AsyncListener extends EventListener {
void onComplete(AsyncEvent event) throws IOException;
void onTimeout(AsyncEvent event) throws IOException;
void onError(AsyncEvent event) throws IOException;
void onStartAsync(AsyncEvent event) throws IOException;
}

View File

@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.servlet;
/**
* @since Servlet 3.0
*/
public enum DispatcherType {
FORWARD,
INCLUDE,
REQUEST,
ASYNC,
ERROR
}

Some files were not shown because too many files have changed in this diff Show More