src/share/jaxws_classes/com/oracle/webservices/internal/api/databinding/ExternalMetadataFeature.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 408
b0610cd08440
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2013, 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.oracle.webservices.internal.api.databinding;
    28 import com.sun.xml.internal.ws.api.databinding.MetadataReader;
    29 import com.sun.xml.internal.ws.model.ExternalMetadataReader;
    31 import javax.xml.ws.WebServiceFeature;
    32 import java.io.File;
    33 import java.util.ArrayList;
    34 import java.util.Collections;
    35 import java.util.List;
    37 /**
    38  * WebServiceFeature allowing to define either on server or client side external xml descriptors replacing/supplementing
    39  * WS metadata provided by class annotations. This can be useful if those annotations are missing (existing non-WS
    40  * components) or if it is necessary to override those.
    41  *
    42  * @author Miroslav Kos (miroslav.kos at oracle.com)
    43  */
    44 public class ExternalMetadataFeature extends WebServiceFeature {
    46     private static final String ID = "com.oracle.webservices.internal.api.databinding.ExternalMetadataFeature";
    48     /**
    49      * Enable this feature.  Defaults to true.
    50      */
    51     private boolean enabled = true;
    53     private List<String> resourceNames;
    54     private List<File> files;
    55     private MetadataReader reader;
    57     private ExternalMetadataFeature() {
    58     }
    60     public void addResources(String... resourceNames) {
    61         if (this.resourceNames == null) {
    62             this.resourceNames = new ArrayList<String>();
    63         }
    64         Collections.addAll(this.resourceNames, resourceNames);
    65     }
    67     public List<String> getResourceNames() { return resourceNames; }
    69     public void addFiles(File... files) {
    70         if (this.files == null) {
    71             this.files = new ArrayList<File>();
    72         }
    73         Collections.addAll(this.files, files);
    74     }
    76     public List<File> getFiles() { return files; }
    78     public boolean isEnabled() {
    79         return enabled;
    80     }
    82     private void setEnabled(final boolean x) {
    83         enabled = x;
    84     }
    86     @Override
    87     public String getID() {
    88         return ID;
    89     }
    91     public MetadataReader getMetadataReader(ClassLoader classLoader, boolean disableXmlSecurity) {
    92         if (reader != null && enabled) return reader;
    93         return enabled ? new ExternalMetadataReader(files, resourceNames, classLoader, true, disableXmlSecurity) : null;
    94     }
    96     @Override
    97     public boolean equals(Object o) {
    98         if (this == o) return true;
    99         if (o == null || getClass() != o.getClass()) return false;
   101         ExternalMetadataFeature that = (ExternalMetadataFeature) o;
   103         if (enabled != that.enabled) return false;
   104         if (files != null ? !files.equals(that.files) : that.files != null) return false;
   105         if (resourceNames != null ? !resourceNames.equals(that.resourceNames) : that.resourceNames != null)
   106             return false;
   108         return true;
   109     }
   111     @Override
   112     public int hashCode() {
   113         int result = (enabled ? 1 : 0);
   114         result = 31 * result + (resourceNames != null ? resourceNames.hashCode() : 0);
   115         result = 31 * result + (files != null ? files.hashCode() : 0);
   116         return result;
   117     }
   119     @Override
   120     public String toString() {
   121         return "[" + getID() +
   122                 ", enabled=" + enabled +
   123                 ", resourceNames=" + resourceNames +
   124                 ", files=" + files +
   125                 ']';
   126     }
   128     public static Builder builder() {
   129         return new Builder(new ExternalMetadataFeature());
   130     }
   132     public final static class Builder {
   133         final private ExternalMetadataFeature o;
   135         Builder(final ExternalMetadataFeature x) {
   136             o = x;
   137         }
   139         public ExternalMetadataFeature build() {
   140             return o;
   141         }
   143         public Builder addResources(String... res) {
   144             o.addResources(res);
   145             return this;
   146         }
   148         public Builder addFiles(File... files) {
   149             o.addFiles(files);
   150             return this;
   151         }
   153         public Builder setEnabled(boolean enabled) {
   154             o.setEnabled(enabled);
   155             return this;
   156         }
   158         public Builder setReader( MetadataReader r ) {
   159             o.reader = r;
   160             return this;
   161         }
   162     }
   163 }

mercurial