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 Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,163 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, 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.oracle.webservices.internal.api.databinding; 1.30 + 1.31 +import com.sun.xml.internal.ws.api.databinding.MetadataReader; 1.32 +import com.sun.xml.internal.ws.model.ExternalMetadataReader; 1.33 + 1.34 +import javax.xml.ws.WebServiceFeature; 1.35 +import java.io.File; 1.36 +import java.util.ArrayList; 1.37 +import java.util.Collections; 1.38 +import java.util.List; 1.39 + 1.40 +/** 1.41 + * WebServiceFeature allowing to define either on server or client side external xml descriptors replacing/supplementing 1.42 + * WS metadata provided by class annotations. This can be useful if those annotations are missing (existing non-WS 1.43 + * components) or if it is necessary to override those. 1.44 + * 1.45 + * @author Miroslav Kos (miroslav.kos at oracle.com) 1.46 + */ 1.47 +public class ExternalMetadataFeature extends WebServiceFeature { 1.48 + 1.49 + private static final String ID = "com.oracle.webservices.internal.api.databinding.ExternalMetadataFeature"; 1.50 + 1.51 + /** 1.52 + * Enable this feature. Defaults to true. 1.53 + */ 1.54 + private boolean enabled = true; 1.55 + 1.56 + private List<String> resourceNames; 1.57 + private List<File> files; 1.58 + private MetadataReader reader; 1.59 + 1.60 + private ExternalMetadataFeature() { 1.61 + } 1.62 + 1.63 + public void addResources(String... resourceNames) { 1.64 + if (this.resourceNames == null) { 1.65 + this.resourceNames = new ArrayList<String>(); 1.66 + } 1.67 + Collections.addAll(this.resourceNames, resourceNames); 1.68 + } 1.69 + 1.70 + public List<String> getResourceNames() { return resourceNames; } 1.71 + 1.72 + public void addFiles(File... files) { 1.73 + if (this.files == null) { 1.74 + this.files = new ArrayList<File>(); 1.75 + } 1.76 + Collections.addAll(this.files, files); 1.77 + } 1.78 + 1.79 + public List<File> getFiles() { return files; } 1.80 + 1.81 + public boolean isEnabled() { 1.82 + return enabled; 1.83 + } 1.84 + 1.85 + private void setEnabled(final boolean x) { 1.86 + enabled = x; 1.87 + } 1.88 + 1.89 + @Override 1.90 + public String getID() { 1.91 + return ID; 1.92 + } 1.93 + 1.94 + public MetadataReader getMetadataReader(ClassLoader classLoader, boolean disableXmlSecurity) { 1.95 + if (reader != null && enabled) return reader; 1.96 + return enabled ? new ExternalMetadataReader(files, resourceNames, classLoader, true, disableXmlSecurity) : null; 1.97 + } 1.98 + 1.99 + @Override 1.100 + public boolean equals(Object o) { 1.101 + if (this == o) return true; 1.102 + if (o == null || getClass() != o.getClass()) return false; 1.103 + 1.104 + ExternalMetadataFeature that = (ExternalMetadataFeature) o; 1.105 + 1.106 + if (enabled != that.enabled) return false; 1.107 + if (files != null ? !files.equals(that.files) : that.files != null) return false; 1.108 + if (resourceNames != null ? !resourceNames.equals(that.resourceNames) : that.resourceNames != null) 1.109 + return false; 1.110 + 1.111 + return true; 1.112 + } 1.113 + 1.114 + @Override 1.115 + public int hashCode() { 1.116 + int result = (enabled ? 1 : 0); 1.117 + result = 31 * result + (resourceNames != null ? resourceNames.hashCode() : 0); 1.118 + result = 31 * result + (files != null ? files.hashCode() : 0); 1.119 + return result; 1.120 + } 1.121 + 1.122 + @Override 1.123 + public String toString() { 1.124 + return "[" + getID() + 1.125 + ", enabled=" + enabled + 1.126 + ", resourceNames=" + resourceNames + 1.127 + ", files=" + files + 1.128 + ']'; 1.129 + } 1.130 + 1.131 + public static Builder builder() { 1.132 + return new Builder(new ExternalMetadataFeature()); 1.133 + } 1.134 + 1.135 + public final static class Builder { 1.136 + final private ExternalMetadataFeature o; 1.137 + 1.138 + Builder(final ExternalMetadataFeature x) { 1.139 + o = x; 1.140 + } 1.141 + 1.142 + public ExternalMetadataFeature build() { 1.143 + return o; 1.144 + } 1.145 + 1.146 + public Builder addResources(String... res) { 1.147 + o.addResources(res); 1.148 + return this; 1.149 + } 1.150 + 1.151 + public Builder addFiles(File... files) { 1.152 + o.addFiles(files); 1.153 + return this; 1.154 + } 1.155 + 1.156 + public Builder setEnabled(boolean enabled) { 1.157 + o.setEnabled(enabled); 1.158 + return this; 1.159 + } 1.160 + 1.161 + public Builder setReader( MetadataReader r ) { 1.162 + o.reader = r; 1.163 + return this; 1.164 + } 1.165 + } 1.166 +}