001: /*
002: * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
003: * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
004: */
005:
006: package javax.xml.ws.soap;
007:
008: import javax.xml.ws.Binding;
009: import javax.xml.ws.BindingType;
010: import javax.xml.ws.WebServiceFeature;
011: import javax.xml.ws.WebServiceException;
012: import javax.xml.ws.spi.Provider;
013:
014: /**
015: * This feature represents the use of MTOM with a
016: * web service.
017: *
018: * <p>
019: * The following describes the affects of this feature with respect
020: * to being enabled or disabled:
021: * <ul>
022: * <li> ENABLED: In this Mode, MTOM will be enabled.
023: * <li> DISABLED: In this Mode, MTOM will be disabled
024: * </ul>
025: * <p>
026: * The {@link #threshold} property can be used to set the threshold
027: * value used to determine when binary data should be XOP encoded.
028: *
029: * @since JAX-WS 2.1
030: */
031: public final class MTOMFeature extends WebServiceFeature {
032: /**
033: * Constant value identifying the MTOMFeature
034: */
035: public static final String ID = "http://www.w3.org/2004/08/soap/features/http-optimization";
036:
037: /**
038: * Property for MTOM threshold value. This property serves as a hint when
039: * MTOM is enabled, binary data above this size in bytes SHOULD be sent
040: * as attachment.
041: * The value of this property MUST always be >= 0. Default value is 0.
042: */
043: protected int threshold = 0;
044:
045: /**
046: * Create an <code>MTOMFeature</code>.
047: * The instance created will be enabled.
048: */
049: public MTOMFeature() {
050: this .enabled = true;
051: }
052:
053: /**
054: * Creates an <code>MTOMFeature</code>.
055: *
056: * @param enabled specifies if this feature should be enabled or not
057: */
058: public MTOMFeature(boolean enabled) {
059: this .enabled = enabled;
060: }
061:
062: /**
063: * Creates an <code>MTOMFeature</code>.
064: * The instance created will be enabled.
065: *
066: * @param threshold the size in bytes that binary data SHOULD be before
067: * being sent as an attachment.
068: *
069: * @throws WebServiceException if threshold is < 0
070: */
071: public MTOMFeature(int threshold) {
072: if (threshold < 0)
073: throw new WebServiceException(
074: "MTOMFeature.threshold must be >= 0, actual value: "
075: + threshold);
076: this .enabled = true;
077: this .threshold = threshold;
078: }
079:
080: /**
081: * Creates an <code>MTOMFeature</code>.
082: *
083: * @param enabled specifies if this feature should be enabled or not
084: * @param threshold the size in bytes that binary data SHOULD be before
085: * being sent as an attachment.
086: *
087: * @throws WebServiceException if threshold is < 0
088: */
089: public MTOMFeature(boolean enabled, int threshold) {
090: if (threshold < 0)
091: throw new WebServiceException(
092: "MTOMFeature.threshold must be >= 0, actual value: "
093: + threshold);
094: this .enabled = enabled;
095: this .threshold = threshold;
096: }
097:
098: /**
099: * {@inheritDoc}
100: */
101: public String getID() {
102: return ID;
103: }
104:
105: /**
106: * Gets the threshold value used to determine when binary data
107: * should be sent as an attachment.
108: *
109: * @return the current threshold size in bytes
110: */
111: public int getThreshold() {
112: return threshold;
113: }
114: }
|