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;
 
 import java.util.List;
 
 
 
 
 public class CorbaUnionHandler extends CorbaObjectHandler {
 
     private CorbaObjectHandler discriminator;
     private CorbaObjectHandler value;
     private List<CorbaObjectHandlercases = new ArrayList<CorbaObjectHandler>();
     private int defaultIndex;
     private List<Stringlabels = new ArrayList<String>();
 
     public CorbaUnionHandler(QName unionNameQName unionIdlTypeTypeCode unionTCObject unionType) {
         super(unionNameunionIdlTypeunionTCunionType);
         
         // Build a list of labels.  This will be used to generate a discriminator value for the 
         // default case (since we are not provided with one from the Stax stream of the Celtix object)
         Union union = (Union)unionType;
         List<Unionbranchbranches = union.getUnionbranch();
         int index = 0;
         for (Iterator<UnionbranchbranchesIter = branches.iterator(); branchesIter.hasNext();) {
             Unionbranch branch = branchesIter.next();
             List<CaseTypebranchCases = branch.getCase();
             if (branchCases.size() == 0) {
                  = index;
             } else {
                 for (Iterator<CaseTypecasesIter = branchCases.iterator(); casesIter.hasNext();) {
                     CaseType ct = casesIter.next();
                     .add(ct.getLabel());
                 }
             }
             
             index++;
         }
     }
     
     public CorbaObjectHandler getDiscriminator() {
         return ;
     }
     
     public String getDisciminatorValueData() {
         String result = null;
         // The discriminator is handled by either the enum handler or the primitive handler.
         if (.getTypeCodeKind().value() == .) {
             CorbaEnumHandler enumHandler = (CorbaEnumHandler);
             result = enumHandler.getValue();
         } else {
             CorbaPrimitiveHandler primitiveHandler = (CorbaPrimitiveHandler);
             result = primitiveHandler.getDataFromValue();
         }
         return result;        
     }
     
     public void setDiscriminator(CorbaObjectHandler disc) {
          = disc;
     }
     
     public void setDiscriminatorValueFromData(String data) {
         // The discriminator is handled by either the enum handler or the primitive handler.
         if (.getTypeCodeKind().value() == .) {
             CorbaEnumHandler enumHandler = (CorbaEnumHandler);
             enumHandler.setValue(data);
         } else {
             CorbaPrimitiveHandler primitiveHandler = (CorbaPrimitiveHandler);
             primitiveHandler.setValueFromData(data);
         }
     }
     
    public List<CorbaObjectHandlergetCases() {
        return ;
    }
    
    public CorbaObjectHandler getBranchByName(String caseName) {
        for (Iterator<CorbaObjectHandlercaseIter = .iterator(); caseIter.hasNext();) {
            CorbaObjectHandler obj = caseIter.next();
            if (obj.getName().getLocalPart().equals(caseName)) {
                return obj;
            }
        }
        
        return null;
    }
    
    public void addCase(CorbaObjectHandler unionCase) {
        .add(unionCase);
    }
    
    public CorbaObjectHandler getValue() {
        return ;
    }
    
    public void setValue(String caseNameCorbaObjectHandler val) {
         = val;
    }
    
    public int getDefaultIndex() {
        return ;
    }
    
        String label = null;
        // According to the CORBA specification, an enumeration discriminator can be one of the 
        // following types:
        //   - *integer* (short, long, ulong, either signed or unsigned)
        //   - boolean
        //   - character
        //   - enumeration
        // So when we need to create a default discriminator to accomodate for the lack of a 
        // discriminator from, these are the four cases we must check for.
        if (.getTypeCodeKind().value() == .) {
            // We can only have a default case with a boolean discriminator if we have
            // only one case, either TRUE or FALSE.  Therefore, we only need to check
            // against the first label, if there is one.
            if (.isEmpty()) {
                label = "false";
            } else {
                boolean boolValue = Boolean.parseBoolean(.get(0));
                label = String.valueOf(!boolValue);
            }
        } else if (.getTypeCodeKind().value() == .) {
            if (.isEmpty()) {
                label = String.valueOf('0');
            } else {
                char charValue = .get(0).charAt(0);
                while (.contains(String.valueOf(charValue))) {
                    charValue++;
                }
                label = String.valueOf(charValue);
            }
        } else if (.getTypeCodeKind().value() == .) {
            // Get the list of possible enumerations in the enumerator and compare these to the
            // labels we obtained from the Union definition.  In order for the union/enum 
            // combination to be syntactically correct, there must be one enumeration not included
            // as a case for the default case to be valid.
            Enum enumType = (Enum).getType();
            List<Enumeratorenumerators = enumType.getEnumerator();
            if (.isEmpty()) {
                // Any value will do since we only have a default case.
                label = enumerators.get(0).getValue();                  
            } else {
                String enumLabel = null;
                for (Iterator<EnumeratorenumIter = enumerators.iterator(); enumIter.hasNext();) {
                    enumLabel = enumIter.next().getValue();
                    if (!.contains(enumLabel)) {
                        label = enumLabel;
                        break;
                    }
                }
            }
        } else if ((.getTypeCodeKind().value() == .)
                   || (.getTypeCodeKind().value() == .)) {
            if (.isEmpty()) {
                label = String.valueOf(.);
            }
            for (int i = .i >= .i--) {
                if (!.contains(String.valueOf(i))) {
                    label = String.valueOf(i);
                    break;
                }   
            }
        } else if ((.getTypeCodeKind().value() == .)
                   || (.getTypeCodeKind().value() == .)) {
            if (.isEmpty()) {
                label = String.valueOf(.);
            }
            for (int i = .i >= .i--) {
                if (!.contains(String.valueOf(i))) {
                    label = String.valueOf(i);
                    break;
                }   
            }
        }
        return label;
    }
    public void clear() {
        if ( != null) {
            .clear();          
        }
        if ( != null) {
            .clear();
        }
    }  
New to GrepCode? Check out our FAQ X