Path: blob/master/src/jdk.dynalink/share/classes/jdk/dynalink/beans/MissingMemberHandlerFactory.java
41161 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package jdk.dynalink.beans;2627import java.lang.invoke.MethodHandle;28import jdk.dynalink.DynamicLinkerFactory;29import jdk.dynalink.NamedOperation;30import jdk.dynalink.NoSuchDynamicMethodException;31import jdk.dynalink.StandardOperation;32import jdk.dynalink.linker.LinkRequest;33import jdk.dynalink.linker.LinkerServices;3435/**36* A factory for creating method handles for linking missing member behavior37* in {@link BeansLinker}. BeansLinker links these method handles into guarded38* invocations for link requests specifying {@code GET_*} and {@code SET_*}39* {@link StandardOperation}s when it is either certain or possible that the40* requested member (property, method, or element) is missing. They will be41* linked both for {@link NamedOperation named} and unnamed operations. The42* implementer must ensure that the parameter types of the returned method43* handle match the parameter types of the call site described in the link44* request. The return types can differ, though, to allow45* {@link DynamicLinkerFactory#setPrelinkTransformer(jdk.dynalink.linker.GuardedInvocationTransformer)}46* late return type transformations}. It is allowed to return {@code null} for a47* method handle if the default behavior is sufficient.48* <h2>Default missing member behavior</h2>49* When a {@link BeansLinker} is configured without a missing member handler50* factory, or the factory returns {@code null} for a particular handler51* creation invocation, the default behavior is used. The default behavior is to52* return {@code null} from53* {@link BeansLinker#getGuardedInvocation(LinkRequest, LinkerServices)} when it54* can be determined at link time that the linked operation will never address55* an existing member. This lets the {@code DynamicLinker} attempt the next56* linker if there is one, or ultimately fail the link request with57* {@link NoSuchDynamicMethodException}. For other cases (typically all unnamed58* member operations as well as most named operations on collection elements)59* {@code BeansLinker} will produce a conditional linkage that will return60* {@code null} when invoked at runtime with a name that does not match any61* member for getters and silently ignore the passed values for setters.62* <h2>Implementing exception-throwing behavior</h2>63* Note that if the language-specific behavior for an operation on a missing64* member is to throw an exception then the factory should produce a method65* handle that throws the exception when invoked, and must not throw an66* exception itself, as the linkage for the missing member is often conditional.67*68* @see BeansLinker#BeansLinker(MissingMemberHandlerFactory)69*/70@FunctionalInterface71public interface MissingMemberHandlerFactory {72/**73* Returns a method handle suitable for implementing missing member behavior74* for a particular link request. See the class description for details.75* @param linkRequest the current link request76* @param linkerServices the current link services77* @return a method handle that can be invoked if the property, element, or78* method being addressed by an operation is missing. The return value can79* be null.80* @throws Exception if the operation fails for any reason. Please observe81* the class documentation notes for implementing exception-throwing82* missing member behavior.83*/84public MethodHandle createMissingMemberHandler(LinkRequest linkRequest, LinkerServices linkerServices) throws Exception;85}868788