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

changeset 368
0989ad8c0860
child 374
72e03566f0a6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/oracle/webservices/internal/api/databinding/ExternalMetadataFeature.java	Tue Apr 09 14:51:13 2013 +0100
     1.3 @@ -0,0 +1,172 @@
     1.4 +/*
     1.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     1.6 + *
     1.7 + * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
     1.8 + *
     1.9 + * The contents of this file are subject to the terms of either the GNU
    1.10 + * General Public License Version 2 only ("GPL") or the Common Development
    1.11 + * and Distribution License("CDDL") (collectively, the "License").  You
    1.12 + * may not use this file except in compliance with the License.  You can
    1.13 + * obtain a copy of the License at
    1.14 + * http://glassfish.java.net/public/CDDL+GPL_1_1.html
    1.15 + * or packager/legal/LICENSE.txt.  See the License for the specific
    1.16 + * language governing permissions and limitations under the License.
    1.17 + *
    1.18 + * When distributing the software, include this License Header Notice in each
    1.19 + * file and include the License file at packager/legal/LICENSE.txt.
    1.20 + *
    1.21 + * GPL Classpath Exception:
    1.22 + * Oracle designates this particular file as subject to the "Classpath"
    1.23 + * exception as provided by Oracle in the GPL Version 2 section of the License
    1.24 + * file that accompanied this code.
    1.25 + *
    1.26 + * Modifications:
    1.27 + * If applicable, add the following below the License Header, with the fields
    1.28 + * enclosed by brackets [] replaced by your own identifying information:
    1.29 + * "Portions Copyright [year] [name of copyright owner]"
    1.30 + *
    1.31 + * Contributor(s):
    1.32 + * If you wish your version of this file to be governed by only the CDDL or
    1.33 + * only the GPL Version 2, indicate your decision by adding "[Contributor]
    1.34 + * elects to include this software in this distribution under the [CDDL or GPL
    1.35 + * Version 2] license."  If you don't indicate a single choice of license, a
    1.36 + * recipient has the option to distribute your version of this file under
    1.37 + * either the CDDL, the GPL Version 2 or to extend the choice of license to
    1.38 + * its licensees as provided above.  However, if you add GPL Version 2 code
    1.39 + * and therefore, elected the GPL Version 2 license, then the option applies
    1.40 + * only if the new code is made subject to such option by the copyright
    1.41 + * holder.
    1.42 + */
    1.43 +
    1.44 +package com.oracle.webservices.internal.api.databinding;
    1.45 +
    1.46 +import com.sun.xml.internal.ws.api.databinding.MetadataReader;
    1.47 +import com.sun.xml.internal.ws.model.ExternalMetadataReader;
    1.48 +
    1.49 +import javax.xml.ws.WebServiceFeature;
    1.50 +import java.io.File;
    1.51 +import java.util.ArrayList;
    1.52 +import java.util.Collections;
    1.53 +import java.util.List;
    1.54 +
    1.55 +/**
    1.56 + * WebServiceFeature allowing to define either on server or client side external xml descriptors replacing/supplementing
    1.57 + * WS metadata provided by class annotations. This can be useful if those annotations are missing (existing non-WS
    1.58 + * components) or if it is necessary to override those.
    1.59 + *
    1.60 + * @author Miroslav Kos (miroslav.kos at oracle.com)
    1.61 + */
    1.62 +public class ExternalMetadataFeature extends WebServiceFeature {
    1.63 +
    1.64 +    private static final String ID = "com.oracle.webservices.internal.api.databinding.ExternalMetadataFeature";
    1.65 +
    1.66 +    /**
    1.67 +     * Enable this feature.  Defaults to true.
    1.68 +     */
    1.69 +    private boolean enabled = true;
    1.70 +
    1.71 +    private List<String> resourceNames;
    1.72 +    private List<File> files;
    1.73 +
    1.74 +    private ExternalMetadataFeature() {
    1.75 +    }
    1.76 +
    1.77 +    public void addResources(String... resourceNames) {
    1.78 +        if (this.resourceNames == null) {
    1.79 +            this.resourceNames = new ArrayList<String>();
    1.80 +        }
    1.81 +        Collections.addAll(this.resourceNames, resourceNames);
    1.82 +    }
    1.83 +
    1.84 +    public List<String> getResourceNames() { return resourceNames; }
    1.85 +
    1.86 +    public void addFiles(File... files) {
    1.87 +        if (this.files == null) {
    1.88 +            this.files = new ArrayList<File>();
    1.89 +        }
    1.90 +        Collections.addAll(this.files, files);
    1.91 +    }
    1.92 +
    1.93 +    public List<File> getFiles() { return files; }
    1.94 +
    1.95 +    public boolean isEnabled() {
    1.96 +        return enabled;
    1.97 +    }
    1.98 +
    1.99 +    private void setEnabled(final boolean x) {
   1.100 +        enabled = x;
   1.101 +    }
   1.102 +
   1.103 +    @Override
   1.104 +    public String getID() {
   1.105 +        return ID;
   1.106 +    }
   1.107 +
   1.108 +    public MetadataReader getMetadataReader(ClassLoader classLoader, boolean disableSecureXmlProcessing) {
   1.109 +        return enabled ? new ExternalMetadataReader(files, resourceNames, classLoader, true, disableSecureXmlProcessing) : null;
   1.110 +    }
   1.111 +
   1.112 +    @Override
   1.113 +    public boolean equals(Object o) {
   1.114 +        if (this == o) return true;
   1.115 +        if (o == null || getClass() != o.getClass()) return false;
   1.116 +
   1.117 +        ExternalMetadataFeature that = (ExternalMetadataFeature) o;
   1.118 +
   1.119 +        if (enabled != that.enabled) return false;
   1.120 +        if (files != null ? !files.equals(that.files) : that.files != null) return false;
   1.121 +        if (resourceNames != null ? !resourceNames.equals(that.resourceNames) : that.resourceNames != null)
   1.122 +            return false;
   1.123 +
   1.124 +        return true;
   1.125 +    }
   1.126 +
   1.127 +    @Override
   1.128 +    public int hashCode() {
   1.129 +        int result = (enabled ? 1 : 0);
   1.130 +        result = 31 * result + (resourceNames != null ? resourceNames.hashCode() : 0);
   1.131 +        result = 31 * result + (files != null ? files.hashCode() : 0);
   1.132 +        return result;
   1.133 +    }
   1.134 +
   1.135 +    @Override
   1.136 +    public String toString() {
   1.137 +        return "[" + getID() +
   1.138 +                ", enabled=" + enabled +
   1.139 +                ", resourceNames=" + resourceNames +
   1.140 +                ", files=" + files +
   1.141 +                ']';
   1.142 +    }
   1.143 +
   1.144 +    public static Builder builder() {
   1.145 +        return new Builder(new ExternalMetadataFeature());
   1.146 +    }
   1.147 +
   1.148 +    public final static class Builder {
   1.149 +        final private ExternalMetadataFeature o;
   1.150 +
   1.151 +        Builder(final ExternalMetadataFeature x) {
   1.152 +            o = x;
   1.153 +        }
   1.154 +
   1.155 +        public ExternalMetadataFeature build() {
   1.156 +            return o;
   1.157 +        }
   1.158 +
   1.159 +        public Builder addResources(String... res) {
   1.160 +            o.addResources(res);
   1.161 +            return this;
   1.162 +        }
   1.163 +
   1.164 +        public Builder addFiles(File... files) {
   1.165 +            o.addFiles(files);
   1.166 +            return this;
   1.167 +        }
   1.168 +
   1.169 +        public Builder setEnabled(boolean enabled) {
   1.170 +            o.setEnabled(enabled);
   1.171 +            return this;
   1.172 +        }
   1.173 +
   1.174 +    }
   1.175 +}

mercurial