< prev index next >

src/jdk.dynalink/share/classes/jdk/dynalink/NamespaceOperation.java

Print this page




  72  *     StandardNamespace.PROPERTY);
  73  * </pre>
  74  * They are often combined with {@link NamedOperation}, e.g. to express a
  75  * property getter for a property named "color", you would construct:
  76  * <pre>
  77  * Operation colorPropertyGetter = new NamedOperation(
  78  *     new NamespaceOperation(
  79  *         StandardOperation.GET,
  80  *         StandardNamespace.PROPERTY),
  81  *     "color");
  82  * </pre>
  83  * <p>While {@code NamespaceOperation} can be constructed directly, it is often convenient
  84  * to use the {@link Operation#withNamespace(Namespace)} and {@link Operation#withNamespaces(Namespace...)} factory
  85  * methods instead, e.g.:
  86  * <pre>
  87  * Operation getElementOrPropertyEmpty =
  88  *     StandardOperation.GET
  89  *         .withNamespace(StandardNamespace.PROPERTY)
  90  *         .named("color");
  91  * </pre>
  92  * <h2>Operations on multiple namespaces</h2>
  93  * If multiple namespaces are specified, the namespaces are treated as
  94  * alternatives to each other in order of preference. The semantics of
  95  * such operation is "first applicable".
  96  * That is, a composite of {@code GET:PROPERTY|ELEMENT:color} should be
  97  * interpreted as <i>get the property named "color" on the object, but if the
  98  * property does not exist, then get the collection element named "color"
  99  * instead</i>.
 100  * <p>
 101  * Operations with multiple namespaces are helpful in implementation of languages that
 102  * don't distinguish between one or more of the namespaces, or when expressing operations
 103  * against objects that can be considered both ordinary objects and collections, e.g. Java
 104  * {@link java.util.Map} objects. A {@code GET:PROPERTY|ELEMENT:empty} operation
 105  * against a Java map will always match
 106  * the {@link java.util.Map#isEmpty()} property, but
 107  * {@code GET:ELEMENT|PROPERTY:empty} will actually match a map element with
 108  * key {@code "empty"} if the map contains that key, and only fall back to the
 109  * {@code isEmpty()} property getter if the map does not contain the key. If
 110  * the source language mandates this semantics, it can be easily achieved using
 111  * operations on multiple namespaces.
 112  * <p>




  72  *     StandardNamespace.PROPERTY);
  73  * </pre>
  74  * They are often combined with {@link NamedOperation}, e.g. to express a
  75  * property getter for a property named "color", you would construct:
  76  * <pre>
  77  * Operation colorPropertyGetter = new NamedOperation(
  78  *     new NamespaceOperation(
  79  *         StandardOperation.GET,
  80  *         StandardNamespace.PROPERTY),
  81  *     "color");
  82  * </pre>
  83  * <p>While {@code NamespaceOperation} can be constructed directly, it is often convenient
  84  * to use the {@link Operation#withNamespace(Namespace)} and {@link Operation#withNamespaces(Namespace...)} factory
  85  * methods instead, e.g.:
  86  * <pre>
  87  * Operation getElementOrPropertyEmpty =
  88  *     StandardOperation.GET
  89  *         .withNamespace(StandardNamespace.PROPERTY)
  90  *         .named("color");
  91  * </pre>
  92  * <h3>Operations on multiple namespaces</h3>
  93  * If multiple namespaces are specified, the namespaces are treated as
  94  * alternatives to each other in order of preference. The semantics of
  95  * such operation is "first applicable".
  96  * That is, a composite of {@code GET:PROPERTY|ELEMENT:color} should be
  97  * interpreted as <i>get the property named "color" on the object, but if the
  98  * property does not exist, then get the collection element named "color"
  99  * instead</i>.
 100  * <p>
 101  * Operations with multiple namespaces are helpful in implementation of languages that
 102  * don't distinguish between one or more of the namespaces, or when expressing operations
 103  * against objects that can be considered both ordinary objects and collections, e.g. Java
 104  * {@link java.util.Map} objects. A {@code GET:PROPERTY|ELEMENT:empty} operation
 105  * against a Java map will always match
 106  * the {@link java.util.Map#isEmpty()} property, but
 107  * {@code GET:ELEMENT|PROPERTY:empty} will actually match a map element with
 108  * key {@code "empty"} if the map contains that key, and only fall back to the
 109  * {@code isEmpty()} property getter if the map does not contain the key. If
 110  * the source language mandates this semantics, it can be easily achieved using
 111  * operations on multiple namespaces.
 112  * <p>


< prev index next >