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