001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the License). You may not use this file except in
005: * compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * Header Notice in each file and include the License file
014: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
015: * If applicable, add the following below the CDDL Header,
016: * with the fields enclosed by brackets [] replaced by
017: * you own identifying information:
018: * "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
021: */
022:
023: /*
024: * DataWrapper.java
025: *
026: * Created on May 2, 2005, 9:43 AM
027: */
028:
029: package com.sun.xml.wss.impl.dsig;
030:
031: import com.sun.xml.wss.impl.MessageConstants;
032: import com.sun.xml.wss.impl.policy.mls.SignatureTarget;
033: import javax.xml.crypto.Data;
034: import javax.xml.crypto.NodeSetData;
035: import javax.xml.crypto.OctetStreamData;
036:
037: /**
038: * Wrapper class for JSR 105 Data objects.Caches SignatureTarget
039: * object and data resolved using this signature target.Reduces
040: * the burden of instanceof checks.
041: * @author K.Venugopal@sun.com
042: */
043: public class DataWrapper {
044:
045: private Data data = null;
046: private int type = -1;
047: private SignatureTarget signatureTarget = null;
048:
049: /**
050: *
051: * @param data
052: */
053: DataWrapper(Data data) {
054: this .data = data;
055: if (data instanceof AttachmentData) {
056: type = MessageConstants.ATTACHMENT_DATA;
057: } else if (data instanceof NodeSetData) {
058: type = MessageConstants.NODE_SET_DATA;
059: } else if (data instanceof OctetStreamData) {
060: type = MessageConstants.OCTECT_STREAM_DATA;
061: }
062:
063: }
064:
065: /**
066: *
067: * @return Data object.
068: */
069: public Data getData() {
070: return this .data;
071: }
072:
073: /**
074: *
075: * @return type of data object wrapped.
076: */
077: public int getType() {
078: return type;
079: }
080:
081: /**
082: *
083: * @return if Data is AttachmentData
084: */
085: public boolean isAttachmentData() {
086: if (type == MessageConstants.ATTACHMENT_DATA) {
087: return true;
088: } else {
089: return false;
090: }
091: }
092:
093: /**
094: *
095: * @return true if Data is NodeSetData.
096: */
097: public boolean isNodesetData() {
098: if (type == MessageConstants.NODE_SET_DATA) {
099: return true;
100: } else {
101: return false;
102: }
103: }
104:
105: /**
106: *
107: * @return true if Data is OctetStreamData.
108: */
109: public boolean isOctectData() {
110: if (type == MessageConstants.OCTECT_STREAM_DATA) {
111: return true;
112: } else {
113: return false;
114: }
115: }
116:
117: /**
118: * null if no target has been set.
119: * @return
120: */
121: public SignatureTarget getTarget() {
122: return signatureTarget;
123: }
124:
125: /**
126: *
127: * @param target
128: */
129: public void setTarget(SignatureTarget target) {
130: this.signatureTarget = target;
131: }
132: }
|