src/share/jaxws_classes/com/sun/tools/internal/ws/processor/model/jaxb/JAXBModel.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/tools/internal/ws/processor/model/jaxb/JAXBModel.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,141 @@
     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.tools.internal.ws.processor.model.jaxb;
    1.30 +
    1.31 +import com.sun.tools.internal.xjc.api.J2SJAXBModel;
    1.32 +import com.sun.tools.internal.xjc.api.Mapping;
    1.33 +import com.sun.tools.internal.xjc.api.S2JJAXBModel;
    1.34 +
    1.35 +import javax.xml.namespace.QName;
    1.36 +import java.util.*;
    1.37 +
    1.38 +/**
    1.39 + * Root of the JAXB Model.
    1.40 + *
    1.41 + * <p>
    1.42 + * This is just a wrapper around a list of {@link JAXBMapping}s.
    1.43 + *
    1.44 + * @author Kohsuke Kawaguchi, Vivek Pandey
    1.45 + */
    1.46 +public class JAXBModel {
    1.47 +
    1.48 +    /**
    1.49 +     * All the mappings known to this model.
    1.50 +     */
    1.51 +    private List<JAXBMapping> mappings;
    1.52 +
    1.53 +    // index for faster access.
    1.54 +    private final Map<QName,JAXBMapping> byQName = new HashMap<QName,JAXBMapping>();
    1.55 +    private final Map<String,JAXBMapping> byClassName = new HashMap<String,JAXBMapping>();
    1.56 +
    1.57 +    private com.sun.tools.internal.xjc.api.JAXBModel rawJAXBModel;
    1.58 +
    1.59 +    public com.sun.tools.internal.xjc.api.JAXBModel getRawJAXBModel() {
    1.60 +        return rawJAXBModel;
    1.61 +    }
    1.62 +
    1.63 +    /**
    1.64 +     * @return Schema to Java model
    1.65 +     */
    1.66 +    public S2JJAXBModel getS2JJAXBModel(){
    1.67 +        if(rawJAXBModel instanceof S2JJAXBModel)
    1.68 +            return (S2JJAXBModel)rawJAXBModel;
    1.69 +        return null;
    1.70 +    }
    1.71 +
    1.72 +    /**
    1.73 +     * @return Java to Schema JAXBModel
    1.74 +     */
    1.75 +    public J2SJAXBModel getJ2SJAXBModel(){
    1.76 +        if(rawJAXBModel instanceof J2SJAXBModel)
    1.77 +            return (J2SJAXBModel)rawJAXBModel;
    1.78 +        return null;
    1.79 +    }
    1.80 +
    1.81 +
    1.82 +    /**
    1.83 +     * Default constructor for the persistence.
    1.84 +     */
    1.85 +    public JAXBModel() {}
    1.86 +
    1.87 +    /**
    1.88 +     * Constructor that fills in the values from the given raw model
    1.89 +     */
    1.90 +    public JAXBModel( com.sun.tools.internal.xjc.api.JAXBModel rawModel ) {
    1.91 +        this.rawJAXBModel = rawModel;
    1.92 +        if(rawModel instanceof S2JJAXBModel){
    1.93 +            S2JJAXBModel model = (S2JJAXBModel)rawModel;
    1.94 +            List<JAXBMapping> ms = new ArrayList<JAXBMapping>(model.getMappings().size());
    1.95 +            for( Mapping m : model.getMappings())
    1.96 +                ms.add(new JAXBMapping(m));
    1.97 +            setMappings(ms);
    1.98 +        }
    1.99 +    }
   1.100 +
   1.101 +    /**
   1.102 +     */
   1.103 +    public List<JAXBMapping> getMappings() {
   1.104 +        return mappings;
   1.105 +    }
   1.106 +
   1.107 +    //public void setMappings(List<JAXBMapping> mappings) {
   1.108 +    public void setMappings(List<JAXBMapping> mappings) {
   1.109 +        this.mappings = mappings;
   1.110 +        byQName.clear();
   1.111 +        byClassName.clear();
   1.112 +        for( JAXBMapping m : mappings ) {
   1.113 +            byQName.put(m.getElementName(),m);
   1.114 +            byClassName.put(m.getType().getName(),m);
   1.115 +        }
   1.116 +    }
   1.117 +
   1.118 +    /**
   1.119 +     */
   1.120 +    public JAXBMapping get( QName elementName ) {
   1.121 +        return byQName.get(elementName);
   1.122 +    }
   1.123 +
   1.124 +    /**
   1.125 +     */
   1.126 +    public JAXBMapping get( String className ) {
   1.127 +        return byClassName.get(className);
   1.128 +    }
   1.129 +
   1.130 +
   1.131 +    /**
   1.132 +     *
   1.133 +     * @return set of full qualified class names that jaxb will generate
   1.134 +     */
   1.135 +    public Set<String> getGeneratedClassNames() {
   1.136 +        return generatedClassNames;
   1.137 +    }
   1.138 +
   1.139 +    public void setGeneratedClassNames(Set<String> generatedClassNames) {
   1.140 +        this.generatedClassNames = generatedClassNames;
   1.141 +    }
   1.142 +
   1.143 +    private Set<String> generatedClassNames;
   1.144 +}

mercurial