001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.developer;
038:
039: import com.sun.istack.NotNull;
040: import com.sun.xml.ws.api.message.Header;
041: import com.sun.xml.ws.api.message.Headers;
042:
043: import javax.xml.transform.Source;
044: import javax.xml.ws.EndpointReference;
045: import javax.xml.ws.wsaddressing.W3CEndpointReference;
046: import java.util.ArrayList;
047: import java.util.List;
048:
049: /**
050: * Represents additional data to be added to EPRs
051: * created from {@link StatefulWebServiceManager} (for advanced users).
052: *
053: * <p>
054: * Occasionally it is convenient to be able to control the data to be
055: * present on {@link EndpointReference}s created by {@link StatefulWebServiceManager}.
056: * You can do so by using this class like this:
057: *
058: * <pre>
059: * statefulWebServiceManager.export({@link W3CEndpointReference}.class,myObject,
060: * new EPRRecipe().addReferenceParameter({@link Headers}.create(...))
061: * .addReferenceParameter({@link Headers}.create(...)));
062: * </pre>
063: *
064: * <p>
065: * The methods on this class follows <a href="http://www.martinfowler.com/bliki/FluentInterface.html">
066: * the fluent interface design</a> to allow construction without using a variable.
067: *
068: *
069: * <p>
070: * See <a href="http://www.w3.org/TR/2006/REC-ws-addr-core-20060509/#eprinfomodel">
071: * WS-Addressing EPR information model</a> for more details.
072: *
073: * @author Kohsuke Kawaguchi
074: * @since 2.1.1
075: * @see StatefulWebServiceManager
076: * @see Headers
077: */
078: public final class EPRRecipe {
079: private final List<Header> referenceParameters = new ArrayList<Header>();
080: private final List<Source> metadata = new ArrayList<Source>();
081:
082: /**
083: * Gets all the reference parameters added so far.
084: */
085: public @NotNull
086: List<Header> getReferenceParameters() {
087: return referenceParameters;
088: }
089:
090: /**
091: * Gets all the metadata added so far.
092: */
093: public @NotNull
094: List<Source> getMetadata() {
095: return metadata;
096: }
097:
098: /**
099: * Adds a new reference parameter.
100: */
101: public EPRRecipe addReferenceParameter(Header h) {
102: if (h == null)
103: throw new IllegalArgumentException();
104: referenceParameters.add(h);
105: return this ;
106: }
107:
108: /**
109: * Adds all the headers as reference parameters.
110: */
111: public EPRRecipe addReferenceParameters(Header... headers) {
112: for (Header h : headers)
113: addReferenceParameter(h);
114: return this ;
115: }
116:
117: /**
118: * Adds all the headers as reference parameters.
119: */
120: public EPRRecipe addReferenceParameters(
121: Iterable<? extends Header> headers) {
122: for (Header h : headers)
123: addReferenceParameter(h);
124: return this ;
125: }
126:
127: /**
128: * Adds a new metadata.
129: */
130: public EPRRecipe addMetadata(Source source) {
131: if (source == null)
132: throw new IllegalArgumentException();
133: metadata.add(source);
134: return this ;
135: }
136:
137: public EPRRecipe addMetadata(Source... sources) {
138: for (Source s : sources)
139: addMetadata(s);
140: return this ;
141: }
142:
143: public EPRRecipe addMetadata(Iterable<? extends Source> sources) {
144: for (Source s : sources)
145: addMetadata(s);
146: return this;
147: }
148: }
|