src/share/jaxws_classes/com/sun/xml/internal/ws/api/model/ParameterBinding.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/model/ParameterBinding.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,130 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.ws.api.model;
    1.30 +
    1.31 +/**
    1.32 + * Denotes the binding of a parameter.
    1.33 + *
    1.34 + * <p>
    1.35 + * This is somewhat like an enumeration (but it is <b>NOT</b> an enumeration.)
    1.36 + *
    1.37 + * <p>
    1.38 + * The possible values are
    1.39 + * BODY, HEADER, UNBOUND, and ATTACHMENT. BODY, HEADER, and UNBOUND
    1.40 + * has a singleton semantics, but there are multiple ATTACHMENT instances
    1.41 + * as it carries additional MIME type parameter.
    1.42 + *
    1.43 + * <p>
    1.44 + * So don't use '==' for testing the equality.
    1.45 + */
    1.46 +public final class ParameterBinding {
    1.47 +    /**
    1.48 +     * Singleton instance that represents 'BODY'
    1.49 +     */
    1.50 +    public static final ParameterBinding BODY = new ParameterBinding(Kind.BODY,null);
    1.51 +    /**
    1.52 +     * Singleton instance that represents 'HEADER'
    1.53 +     */
    1.54 +    public static final ParameterBinding HEADER = new ParameterBinding(Kind.HEADER,null);
    1.55 +    /**
    1.56 +     * Singleton instance that represents 'UNBOUND',
    1.57 +     * meaning the parameter doesn't have a representation in a SOAP message.
    1.58 +     */
    1.59 +    public static final ParameterBinding UNBOUND = new ParameterBinding(Kind.UNBOUND,null);
    1.60 +    /**
    1.61 +     * Creates an instance that represents the attachment
    1.62 +     * with a given MIME type.
    1.63 +     *
    1.64 +     * <p>
    1.65 +     * TODO: shall we consider givint the singleton semantics by using
    1.66 +     * a cache? It's more elegant to do so, but
    1.67 +     * no where in JAX-WS RI two {@link ParameterBinding}s are compared today,
    1.68 +     */
    1.69 +    public static ParameterBinding createAttachment(String mimeType) {
    1.70 +        return new ParameterBinding(Kind.ATTACHMENT,mimeType);
    1.71 +    }
    1.72 +
    1.73 +    /**
    1.74 +     * Represents 4 kinds of binding.
    1.75 +     */
    1.76 +    public static enum Kind {
    1.77 +        BODY, HEADER, UNBOUND, ATTACHMENT;
    1.78 +    }
    1.79 +
    1.80 +
    1.81 +    /**
    1.82 +     * Represents the kind of {@link ParameterBinding}.
    1.83 +     * Always non-null.
    1.84 +     */
    1.85 +    public final Kind kind;
    1.86 +
    1.87 +    /**
    1.88 +     * Only used with attachment binding.
    1.89 +     */
    1.90 +    private String mimeType;
    1.91 +
    1.92 +    private ParameterBinding(Kind kind,String mimeType) {
    1.93 +        this.kind = kind;
    1.94 +        this.mimeType = mimeType;
    1.95 +    }
    1.96 +
    1.97 +
    1.98 +
    1.99 +    public String toString() {
   1.100 +        return kind.toString();
   1.101 +    }
   1.102 +
   1.103 +    /**
   1.104 +     * Returns the MIME type associated with this binding.
   1.105 +     *
   1.106 +     * @throws IllegalStateException
   1.107 +     *      if this binding doesn't represent an attachment.
   1.108 +     *      IOW, if {@link #isAttachment()} returns false.
   1.109 +     * @return
   1.110 +     *      Can be null, if the MIME type is not known.
   1.111 +     */
   1.112 +    public String getMimeType() {
   1.113 +        if(!isAttachment())
   1.114 +            throw new IllegalStateException();
   1.115 +        return mimeType;
   1.116 +    }
   1.117 +
   1.118 +    public boolean isBody(){
   1.119 +        return this==BODY;
   1.120 +    }
   1.121 +
   1.122 +    public boolean isHeader(){
   1.123 +        return this==HEADER;
   1.124 +    }
   1.125 +
   1.126 +    public boolean isUnbound(){
   1.127 +        return this==UNBOUND;
   1.128 +    }
   1.129 +
   1.130 +    public boolean isAttachment(){
   1.131 +        return kind==Kind.ATTACHMENT;
   1.132 +    }
   1.133 +}

mercurial