Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.apache.cxf.binding.corba.types;
 
 
 
 public class CorbaPrimitiveHandler extends CorbaObjectHandler {
 
     private static final int UNSIGNED_MAX = 256; 
     private Object value;
     private String valueAsString;
     private boolean objectSet;
     private Any any;
     
     public CorbaPrimitiveHandler(QName primNameQName primIdlTypeTypeCode primTCObject primType) {
         super(primNameprimIdlTypeprimTCprimType);
     }
     
     public Object getValue() {
         return ;
     }
     public Any getAny() {
         return ;
     }
     
     public void setIntoAny(Any valCorbaStreamable streamboolean output) {
          = val;
         if (stream != null) {
             val.insert_Streamable(stream);
         }
         if (output &&  != null) {
             switch (this..kind().value()) {
             case .:
                 .insert_boolean((Boolean));
                 break;
             case .:
                 .insert_char(((Character)).charValue());
                 break;
             case .:
                 .insert_wchar(((Character)).charValue());
                 break;
             case .:
                 .insert_octet(((Byte)).byteValue());
                 break;
             case .:
                 .insert_short(((Short)).shortValue());
                 break;
             case .:
                 .insert_ushort((short)((Integer)).intValue());
                 break;
             case .:
                 .insert_long(((Integer)).intValue());
                 break;
             case .:
                 .insert_longlong(((Long)).longValue());
                 break;
             case .:
                 .insert_ulong((int)((Long)).longValue());
                 break;
             case .:
                 .insert_ulonglong(((java.math.BigInteger)).longValue());
                 break;
             case .:
                 .insert_float((Float));
                 break;
             case .:
                 .insert_double((Double));
                 break;
             case .:
                 .insert_string((String));
                 break;
             case .:
                 .insert_wstring((String));
                 break;
             default:
                 // Default: assume that whatever stored the data will also know how to convert it into what 
                 // it needs.
             }
        }
    }
    public void setValue(Object obj) {
         = true;
         = obj;
        if ( != null &&  != null) {
            setIntoAny(nulltrue);
        }
    }
    public String getDataFromValue() {
        if (! &&  != null) {
            return getDataFromAny();
        }
        if ( != null) {
            return ;
        }
        String data = "";
        switch (this..kind().value()) {
        case .:
            data = ((Boolean)).toString();
            break;
        case .:
            char charValue = ((Character)).charValue();
            // outside the normal range it will -256
            data = Byte.toString((byte)(charValue > . 
                                                    ? charValue -  
                                                    : charValue));
            break;
        case .:
            data = ((Character)).toString();
            break;
        case .:
            data = ((Byte)).toString();
            break;
        case .:
            data = ((Short)).toString();
            break;
        case .:
            data = ((Integer)).toString();
            break;
        case .:
            data = ((Integer)).toString();
            break;
        case .:
            data = ((Long)).toString();
            break;
        case .:
            data = ((Long)).toString();
            break;
        case .:
            data = ((java.math.BigInteger)).toString();
            break;
        case .:
            if (((Float)).equals(.)) {
                data = "-INF";
            } else if (((Float)).equals(.)) {
                data = "INF";
            } else {
                data = ((Float)).toString();
            }
            break;
        case .:
            if (((Double)).equals(.)) {
                data = "-INF";
            } else if (((Double)).equals(.)) {
                data = "INF";
            } else {
                data = ((Double)).toString();
            }
            break;
        case .:
        case .:
            data = (String);
            break;
        default:
            // Default: assume that whatever stored the data will also know how to convert it into what 
            // it needs.
            data = .toString();
        }
         = data;
        return data;
    }
    
    public void setValueFromData(String data) {
        Object obj = null;
        switch (.kind().value()) {
        case .:
            obj = Boolean.valueOf(data);
            break;
        case .:
            // A char is mapped to a byte, we need it as a character
            Byte byteValue = new Byte(data);
            // for values < 0 + 256 
            // This means that we can directly write out the chars in the normal
            // range 0-127 even when using UTF-8
            obj = Character.valueOf((char)(byteValue.byteValue() < 0 
                                         ? byteValue.byteValue() + 
                                         : byteValue.byteValue()));
            break;
        case .:
            // A wide char is mapped to a string, we need it as a character
            obj = Character.valueOf(data.charAt(0));
            break;
        case .:
            obj = new Short(data).byteValue();
            break;
        case .:
            obj = new Short(data);
            break;
        case .:
            obj = new Integer(data);
            break;
        case .:
            obj = new Integer(data);
            break;
        case .:
            obj = new Long(data);
            break;
        case .:
            obj = new Long(data);
            break;
        case .:
            obj = new java.math.BigInteger(data);
            break;
        case .:
            if ("INF".equals(data)) {
                obj = .;
            } else if ("-INF".equals(data)) {
                obj = .;
            } else {
                obj = new Float(data);
            }
            break;
        case .:
            if ("INF".equals(data)) {
                obj = .;
            } else if ("-INF".equals(data)) {
                obj = .;
            } else {
                obj = new Double(data);
            }
            break;
        case .:
        case .:
            obj = data;
            break;
        default:
            // Default: just store the data we were given.  We'll expect that whatever stored the data
            // will also know how to convert it into what it needs.
            obj = data;
        }
        setValue(obj);
    }
    public String getDataFromAny() {
        String data = "";
        if ( != null) {
            return ;
        }
        switch (this..kind().value()) {
        case .:
            data = .extract_boolean() ? "true" : "false";
            break;
        case .:
            char charValue = .extract_char();
            // outside the normal range it will -256
            data = Byte.toString((byte)(charValue > . 
                                                    ? charValue -  
                                                    : charValue));
            break;
        case .:
            data = Character.toString(.extract_wchar());
            break;
        case .:
            data = Byte.toString(.extract_octet());
            break;
        case .:
            data = Short.toString(.extract_short());
            break;
        case .:
            data = Integer.toString(.extract_ushort());
            break;
        case .:
            data = Integer.toString(.extract_long());
            break;
        case .:
            data = Long.toString(.extract_longlong());
            break;
        case .: {
            long l = .extract_ulong();
            data = Long.toString(l & 0xFFFFFFFFL);
            break;
        }
        case .:
            data = java.math.BigInteger.valueOf(.extract_ulonglong()).toString();
            break;
        case .:
            Float f = .extract_float();
            if (f.equals(.)) {
                data = "-INF";
            } else if (f.equals(.)) {
                data = "INF";
            } else {
                data = f.toString();
            }
            break;
        case .:
            Double d = .extract_double();
            if (d.equals(.)) {
                data = "-INF";
            } else if (d.equals(.)) {
                data = "INF";
            } else {
                data = d.toString();
            }
            break;
        case .:
            data = .extract_string();
            break;
        case .:
            data = .extract_wstring();
            break;
        default:
            //should not get here
            throw new RuntimeException("Unknown tc: " + this.);
        }
         = data;
        return data;
    }
    
    public void clear() {
         = null;
         = false;
         = null;
    }
New to GrepCode? Check out our FAQ X