001: /*
002: * $Id: BinaryExchangeImpl.java,v 1.6 2007/05/29 22:11:33 ofung Exp $
003: */
004:
005: /*
006: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
007: *
008: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
009: *
010: * The contents of this file are subject to the terms of either the GNU
011: * General Public License Version 2 only ("GPL") or the Common Development
012: * and Distribution License("CDDL") (collectively, the "License"). You
013: * may not use this file except in compliance with the License. You can obtain
014: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
015: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
016: * language governing permissions and limitations under the License.
017: *
018: * When distributing the software, include this License Header Notice in each
019: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
020: * Sun designates this particular file as subject to the "Classpath" exception
021: * as provided by Sun in the GPL Version 2 section of the License file that
022: * accompanied this code. If applicable, add the following below the License
023: * Header, with the fields enclosed by brackets [] replaced by your own
024: * identifying information: "Portions Copyrighted [year]
025: * [name of copyright owner]"
026: *
027: * Contributor(s):
028: *
029: * If you wish your version of this file to be governed by only the CDDL or
030: * only the GPL Version 2, indicate your decision by adding "[Contributor]
031: * elects to include this software in this distribution under the [CDDL or GPL
032: * Version 2] license." If you don't indicate a single choice of license, a
033: * recipient has the option to distribute your version of this file under
034: * either the CDDL, the GPL Version 2 or to extend the choice of license to
035: * its licensees as provided above. However, if you add GPL Version 2 code
036: * and therefore, elected the GPL Version 2 license, then the option applies
037: * only if the new code is made subject to such option by the copyright
038: * holder.
039: */
040:
041: package com.sun.xml.ws.security.trust.impl.elements;
042:
043: import com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException;
044: import com.sun.org.apache.xml.internal.security.utils.Base64;
045: import com.sun.xml.ws.security.trust.elements.BinaryExchange;
046: import com.sun.xml.ws.security.trust.impl.bindings.BinaryExchangeType;
047:
048: import java.util.logging.Level;
049: import java.util.logging.Logger;
050: import com.sun.xml.ws.security.trust.logging.LogDomainConstants;
051:
052: import com.sun.istack.NotNull;
053:
054: import com.sun.xml.ws.security.trust.logging.LogStringsMessages;
055:
056: /**
057: *
058: * @author Manveen Kaur (manveen.kaur@sun.com).
059: */
060:
061: public class BinaryExchangeImpl extends BinaryExchangeType implements
062: BinaryExchange {
063:
064: private static final Logger log = Logger.getLogger(
065: LogDomainConstants.TRUST_IMPL_DOMAIN,
066: LogDomainConstants.TRUST_IMPL_DOMAIN_BUNDLE);
067:
068: public BinaryExchangeImpl(String encodingType, String valueType,
069: byte[] rawText) {
070: setEncodingType(encodingType);
071: setValueType(valueType);
072: setRawValue(rawText);
073: }
074:
075: public BinaryExchangeImpl(BinaryExchangeType bcType)
076: throws RuntimeException {
077: setEncodingType(bcType.getEncodingType());
078: setValueType(bcType.getValueType());
079: setValue(bcType.getValue());
080: }
081:
082: public byte[] getRawValue() {
083: try {
084: return Base64.decode(getTextValue());
085: } catch (Base64DecodingException de) {
086: log.log(Level.SEVERE, LogStringsMessages
087: .WST_0020_ERROR_DECODING(getTextValue()), de);
088: throw new RuntimeException(LogStringsMessages
089: .WST_0020_ERROR_DECODING(getTextValue()), de);
090: }
091: }
092:
093: public String getTextValue() {
094: return super .getValue();
095: }
096:
097: public void setTextValue(@NotNull
098: final String encodedText) {
099: super .setValue(encodedText);
100: }
101:
102: public final void setRawValue(@NotNull
103: final byte[] rawText) {
104: super.setValue(Base64.encode(rawText));
105: }
106:
107: }
|