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

Tue, 23 Apr 2013 18:33:20 -0700

author
katleman
date
Tue, 23 Apr 2013 18:33:20 -0700
changeset 374
72e03566f0a6
parent 368
0989ad8c0860
child 384
8f2986ff0235
permissions
-rw-r--r--

8012643: JDK8 b86 source with GPL header errors
Reviewed-by: dholmes, alanb

     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;
    56     private ExternalMetadataFeature() {
    57     }
    59     public void addResources(String... resourceNames) {
    60         if (this.resourceNames == null) {
    61             this.resourceNames = new ArrayList<String>();
    62         }
    63         Collections.addAll(this.resourceNames, resourceNames);
    64     }
    66     public List<String> getResourceNames() { return resourceNames; }
    68     public void addFiles(File... files) {
    69         if (this.files == null) {
    70             this.files = new ArrayList<File>();
    71         }
    72         Collections.addAll(this.files, files);
    73     }
    75     public List<File> getFiles() { return files; }
    77     public boolean isEnabled() {
    78         return enabled;
    79     }
    81     private void setEnabled(final boolean x) {
    82         enabled = x;
    83     }
    85     @Override
    86     public String getID() {
    87         return ID;
    88     }
    90     public MetadataReader getMetadataReader(ClassLoader classLoader, boolean disableSecureXmlProcessing) {
    91         return enabled ? new ExternalMetadataReader(files, resourceNames, classLoader, true, disableSecureXmlProcessing) : null;
    92     }
    94     @Override
    95     public boolean equals(Object o) {
    96         if (this == o) return true;
    97         if (o == null || getClass() != o.getClass()) return false;
    99         ExternalMetadataFeature that = (ExternalMetadataFeature) o;
   101         if (enabled != that.enabled) return false;
   102         if (files != null ? !files.equals(that.files) : that.files != null) return false;
   103         if (resourceNames != null ? !resourceNames.equals(that.resourceNames) : that.resourceNames != null)
   104             return false;
   106         return true;
   107     }
   109     @Override
   110     public int hashCode() {
   111         int result = (enabled ? 1 : 0);
   112         result = 31 * result + (resourceNames != null ? resourceNames.hashCode() : 0);
   113         result = 31 * result + (files != null ? files.hashCode() : 0);
   114         return result;
   115     }
   117     @Override
   118     public String toString() {
   119         return "[" + getID() +
   120                 ", enabled=" + enabled +
   121                 ", resourceNames=" + resourceNames +
   122                 ", files=" + files +
   123                 ']';
   124     }
   126     public static Builder builder() {
   127         return new Builder(new ExternalMetadataFeature());
   128     }
   130     public final static class Builder {
   131         final private ExternalMetadataFeature o;
   133         Builder(final ExternalMetadataFeature x) {
   134             o = x;
   135         }
   137         public ExternalMetadataFeature build() {
   138             return o;
   139         }
   141         public Builder addResources(String... res) {
   142             o.addResources(res);
   143             return this;
   144         }
   146         public Builder addFiles(File... files) {
   147             o.addFiles(files);
   148             return this;
   149         }
   151         public Builder setEnabled(boolean enabled) {
   152             o.setEnabled(enabled);
   153             return this;
   154         }
   156     }
   157 }

mercurial