src/share/jaxws_classes/com/sun/tools/internal/xjc/model/TypeUseFactory.java

Thu, 24 May 2018 16:44:14 +0800

author
aoqi
date
Thu, 24 May 2018 16:44:14 +0800
changeset 1288
f4ace6971570
parent 0
373ffda63c9a
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright (c) 1997, 2011, 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  */
    26 package com.sun.tools.internal.xjc.model;
    28 import javax.activation.MimeType;
    29 import javax.xml.bind.annotation.adapters.XmlAdapter;
    31 import com.sun.xml.internal.bind.v2.TODO;
    32 import com.sun.xml.internal.bind.v2.model.core.Adapter;
    33 import com.sun.xml.internal.bind.v2.model.core.ID;
    35 /**
    36  * Factory methods to create a new {@link TypeUse} from an existing one.
    37  *
    38  * @author Kohsuke Kawaguchi
    39  */
    40 public final class TypeUseFactory {
    41     private TypeUseFactory() {}
    43     public static TypeUse makeID( TypeUse t, ID id ) {
    44         if(t.idUse()!=ID.NONE)
    45             // I don't think we let users tweak the idness, so
    46             // this error must indicate an inconsistency within the RI/spec.
    47             throw new IllegalStateException();
    48         return new TypeUseImpl( t.getInfo(), t.isCollection(), id, t.getExpectedMimeType(), t.getAdapterUse() );
    49     }
    51     public static TypeUse makeMimeTyped( TypeUse t, MimeType mt ) {
    52         if(t.getExpectedMimeType()!=null)
    53             // I don't think we let users tweak the idness, so
    54             // this error must indicate an inconsistency within the RI/spec.
    55             throw new IllegalStateException();
    56         return new TypeUseImpl( t.getInfo(), t.isCollection(), t.idUse(), mt, t.getAdapterUse() );
    57     }
    59     public static TypeUse makeCollection( TypeUse t ) {
    60         if(t.isCollection())    return t;
    61         CAdapter au = t.getAdapterUse();
    62         if(au!=null && !au.isWhitespaceAdapter()) {
    63             // we can't process this right now.
    64             // for now bind to a weaker type
    65             TODO.checkSpec();
    66             return CBuiltinLeafInfo.STRING_LIST;
    67         }
    68         return new TypeUseImpl( t.getInfo(), true, t.idUse(), t.getExpectedMimeType(), null );
    69     }
    71     public static TypeUse adapt(TypeUse t, CAdapter adapter) {
    72         assert t.getAdapterUse()==null;    // TODO: we don't know how to handle double adapters yet.
    73         return new TypeUseImpl(t.getInfo(),t.isCollection(),t.idUse(),t.getExpectedMimeType(),adapter);
    74     }
    76     /**
    77      * Creates a new adapter {@link TypeUse} by using the existing {@link Adapter} class.
    78      */
    79     public static TypeUse adapt( TypeUse t, Class<? extends XmlAdapter> adapter, boolean copy ) {
    80         return adapt( t, new CAdapter(adapter,copy) );
    81     }
    82 }

mercurial