84 package jdk.internal.dynalink.support; |
84 package jdk.internal.dynalink.support; |
85 |
85 |
86 import java.io.Serializable; |
86 import java.io.Serializable; |
87 import java.util.LinkedList; |
87 import java.util.LinkedList; |
88 import java.util.List; |
88 import java.util.List; |
|
89 import java.util.Objects; |
89 import jdk.internal.dynalink.linker.GuardedInvocation; |
90 import jdk.internal.dynalink.linker.GuardedInvocation; |
90 import jdk.internal.dynalink.linker.GuardingDynamicLinker; |
91 import jdk.internal.dynalink.linker.GuardingDynamicLinker; |
91 import jdk.internal.dynalink.linker.LinkRequest; |
92 import jdk.internal.dynalink.linker.LinkRequest; |
92 import jdk.internal.dynalink.linker.LinkerServices; |
93 import jdk.internal.dynalink.linker.LinkerServices; |
93 |
94 |
94 /** |
95 /** |
95 * A {@link GuardingDynamicLinker} that delegates sequentially to a list of other guarding dynamic linkers. The first |
96 * A {@link GuardingDynamicLinker} that delegates sequentially to a list of |
96 * value returned from a component linker other than null is returned. If no component linker returns an invocation, |
97 * other guarding dynamic linkers in its |
97 * null is returned. |
98 * {@link #getGuardedInvocation(LinkRequest, LinkerServices)}. |
98 */ |
99 */ |
99 public class CompositeGuardingDynamicLinker implements GuardingDynamicLinker, Serializable { |
100 public class CompositeGuardingDynamicLinker implements GuardingDynamicLinker, Serializable { |
100 |
101 |
101 private static final long serialVersionUID = 1L; |
102 private static final long serialVersionUID = 1L; |
102 |
103 |
104 |
105 |
105 /** |
106 /** |
106 * Creates a new composite linker. |
107 * Creates a new composite linker. |
107 * |
108 * |
108 * @param linkers a list of component linkers. |
109 * @param linkers a list of component linkers. |
|
110 * @throws NullPointerException if {@code linkers} or any of its elements |
|
111 * are null. |
109 */ |
112 */ |
110 public CompositeGuardingDynamicLinker(final Iterable<? extends GuardingDynamicLinker> linkers) { |
113 public CompositeGuardingDynamicLinker(final Iterable<? extends GuardingDynamicLinker> linkers) { |
111 final List<GuardingDynamicLinker> l = new LinkedList<>(); |
114 final List<GuardingDynamicLinker> l = new LinkedList<>(); |
112 for(final GuardingDynamicLinker linker: linkers) { |
115 for(final GuardingDynamicLinker linker: linkers) { |
113 l.add(linker); |
116 l.add(Objects.requireNonNull(linker)); |
114 } |
117 } |
115 this.linkers = l.toArray(new GuardingDynamicLinker[l.size()]); |
118 this.linkers = l.toArray(new GuardingDynamicLinker[l.size()]); |
116 } |
119 } |
117 |
120 |
|
121 /** |
|
122 * Delegates the call to its component linkers. The first non-null value |
|
123 * returned from a component linker is returned. If no component linker |
|
124 * returns a non-null invocation, null is returned. |
|
125 * @param linkRequest the object describing the request for linking a |
|
126 * particular invocation |
|
127 * @param linkerServices linker services |
|
128 * @return the first non-null return value from a component linker, or null |
|
129 * if none of the components returned a non-null. |
|
130 */ |
118 @Override |
131 @Override |
119 public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) |
132 public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) |
120 throws Exception { |
133 throws Exception { |
121 for(final GuardingDynamicLinker linker: linkers) { |
134 for(final GuardingDynamicLinker linker: linkers) { |
122 final GuardedInvocation invocation = linker.getGuardedInvocation(linkRequest, linkerServices); |
135 final GuardedInvocation invocation = linker.getGuardedInvocation(linkRequest, linkerServices); |