alanb@368: /* katleman@374: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. katleman@374: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. alanb@368: * katleman@374: * This code is free software; you can redistribute it and/or modify it katleman@374: * under the terms of the GNU General Public License version 2 only, as katleman@374: * published by the Free Software Foundation. Oracle designates this katleman@374: * particular file as subject to the "Classpath" exception as provided katleman@374: * by Oracle in the LICENSE file that accompanied this code. alanb@368: * katleman@374: * This code is distributed in the hope that it will be useful, but WITHOUT katleman@374: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or katleman@374: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License katleman@374: * version 2 for more details (a copy is included in the LICENSE file that katleman@374: * accompanied this code). alanb@368: * katleman@374: * You should have received a copy of the GNU General Public License version katleman@374: * 2 along with this work; if not, write to the Free Software Foundation, katleman@374: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. alanb@368: * katleman@374: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA katleman@374: * or visit www.oracle.com if you need additional information or have any katleman@374: * questions. alanb@368: */ alanb@368: alanb@368: package com.oracle.webservices.internal.api.databinding; alanb@368: alanb@368: import com.sun.xml.internal.ws.api.databinding.MetadataReader; alanb@368: import com.sun.xml.internal.ws.model.ExternalMetadataReader; alanb@368: alanb@368: import javax.xml.ws.WebServiceFeature; alanb@368: import java.io.File; alanb@368: import java.util.ArrayList; alanb@368: import java.util.Collections; alanb@368: import java.util.List; alanb@368: alanb@368: /** alanb@368: * WebServiceFeature allowing to define either on server or client side external xml descriptors replacing/supplementing alanb@368: * WS metadata provided by class annotations. This can be useful if those annotations are missing (existing non-WS alanb@368: * components) or if it is necessary to override those. alanb@368: * alanb@368: * @author Miroslav Kos (miroslav.kos at oracle.com) alanb@368: */ alanb@368: public class ExternalMetadataFeature extends WebServiceFeature { alanb@368: alanb@368: private static final String ID = "com.oracle.webservices.internal.api.databinding.ExternalMetadataFeature"; alanb@368: alanb@368: /** alanb@368: * Enable this feature. Defaults to true. alanb@368: */ alanb@368: private boolean enabled = true; alanb@368: alanb@368: private List resourceNames; alanb@368: private List files; mkos@384: private MetadataReader reader; alanb@368: alanb@368: private ExternalMetadataFeature() { alanb@368: } alanb@368: alanb@368: public void addResources(String... resourceNames) { alanb@368: if (this.resourceNames == null) { alanb@368: this.resourceNames = new ArrayList(); alanb@368: } alanb@368: Collections.addAll(this.resourceNames, resourceNames); alanb@368: } alanb@368: alanb@368: public List getResourceNames() { return resourceNames; } alanb@368: alanb@368: public void addFiles(File... files) { alanb@368: if (this.files == null) { alanb@368: this.files = new ArrayList(); alanb@368: } alanb@368: Collections.addAll(this.files, files); alanb@368: } alanb@368: alanb@368: public List getFiles() { return files; } alanb@368: alanb@368: public boolean isEnabled() { alanb@368: return enabled; alanb@368: } alanb@368: alanb@368: private void setEnabled(final boolean x) { alanb@368: enabled = x; alanb@368: } alanb@368: alanb@368: @Override alanb@368: public String getID() { alanb@368: return ID; alanb@368: } alanb@368: mkos@408: public MetadataReader getMetadataReader(ClassLoader classLoader, boolean disableXmlSecurity) { mkos@384: if (reader != null && enabled) return reader; mkos@408: return enabled ? new ExternalMetadataReader(files, resourceNames, classLoader, true, disableXmlSecurity) : null; alanb@368: } alanb@368: alanb@368: @Override alanb@368: public boolean equals(Object o) { alanb@368: if (this == o) return true; alanb@368: if (o == null || getClass() != o.getClass()) return false; alanb@368: alanb@368: ExternalMetadataFeature that = (ExternalMetadataFeature) o; alanb@368: alanb@368: if (enabled != that.enabled) return false; alanb@368: if (files != null ? !files.equals(that.files) : that.files != null) return false; alanb@368: if (resourceNames != null ? !resourceNames.equals(that.resourceNames) : that.resourceNames != null) alanb@368: return false; alanb@368: alanb@368: return true; alanb@368: } alanb@368: alanb@368: @Override alanb@368: public int hashCode() { alanb@368: int result = (enabled ? 1 : 0); alanb@368: result = 31 * result + (resourceNames != null ? resourceNames.hashCode() : 0); alanb@368: result = 31 * result + (files != null ? files.hashCode() : 0); alanb@368: return result; alanb@368: } alanb@368: alanb@368: @Override alanb@368: public String toString() { alanb@368: return "[" + getID() + alanb@368: ", enabled=" + enabled + alanb@368: ", resourceNames=" + resourceNames + alanb@368: ", files=" + files + alanb@368: ']'; alanb@368: } alanb@368: alanb@368: public static Builder builder() { alanb@368: return new Builder(new ExternalMetadataFeature()); alanb@368: } alanb@368: alanb@368: public final static class Builder { alanb@368: final private ExternalMetadataFeature o; alanb@368: alanb@368: Builder(final ExternalMetadataFeature x) { alanb@368: o = x; alanb@368: } alanb@368: alanb@368: public ExternalMetadataFeature build() { alanb@368: return o; alanb@368: } alanb@368: alanb@368: public Builder addResources(String... res) { alanb@368: o.addResources(res); alanb@368: return this; alanb@368: } alanb@368: alanb@368: public Builder addFiles(File... files) { alanb@368: o.addFiles(files); alanb@368: return this; alanb@368: } alanb@368: alanb@368: public Builder setEnabled(boolean enabled) { alanb@368: o.setEnabled(enabled); alanb@368: return this; alanb@368: } alanb@368: mkos@384: public Builder setReader( MetadataReader r ) { mkos@384: o.reader = r; mkos@384: return this; mkos@384: } alanb@368: } alanb@368: }