View Javadoc
1   /*
2    * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.  Oracle designates this
8    * particular file as subject to the "Classpath" exception as provided
9    * by Oracle in the LICENSE file that accompanied this code.
10   *
11   * This code is distributed in the hope that it will be useful, but WITHOUT
12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   * version 2 for more details (a copy is included in the LICENSE file that
15   * accompanied this code).
16   *
17   * You should have received a copy of the GNU General Public License version
18   * 2 along with this work; if not, write to the Free Software Foundation,
19   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20   *
21   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22   * or visit www.oracle.com if you need additional information or have any
23   * questions.
24   */
25  
26  package com.sun.xml.internal.ws.client.sei;
27  
28  import javax.jws.WebParam.Mode;
29  import javax.xml.ws.Holder;
30  
31  /**
32   * Gets a value from an object that represents a parameter passed
33   * as a method argument.
34   *
35   * <p>
36   * This abstraction hides the handling of {@link Holder}.
37   *
38   * <p>
39   * {@link ValueGetter} is a stateless behavior encapsulation.
40   *
41   * @author Kohsuke Kawaguchi
42   */
43  enum ValueGetter {
44      /**
45       * {@link ValueGetter} that works for {@link Mode#IN}  parameter.
46       *
47       * <p>
48       * Since it's the IN mode, the parameter is not a {@link Holder},
49       * therefore the parameter itself is a value.
50       */
51      PLAIN() {
52          Object get(Object parameter) {
53              return parameter;
54          }
55      },
56      /**
57       * Creates {@link ValueGetter} that works for {@link Holder},
58       * which is  {@link Mode#INOUT} or  {@link Mode#OUT}.
59       *
60       * <p>
61       * In those {@link Mode}s, the parameter is a {@link Holder},
62       * so the value to be sent is obtained by getting the value of the holder.
63       */
64      HOLDER() {
65          Object get(Object parameter) {
66              if(parameter==null)
67                  // the user is allowed to pass in null where a Holder is expected.
68                  return null;
69              return ((Holder)parameter).value;
70          }
71      };
72  
73      /**
74       * Gets the value to be sent, from a parameter given as a method argument.
75       * @param parameter that is passed by proxy
76       * @return if it holder then its value, otherise parameter itself
77       */
78      abstract Object get(Object parameter);
79  
80  }