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 CorbaUnionListener extends AbstractCorbaTypeListener {
 
     private CorbaTypeMap typeMap;
     private ServiceInfo serviceInfo;
     private ORB orb;
     private List<Unionbranchbranches;
     private Union unionType;
 
     public CorbaUnionListener(CorbaObjectHandler handler,
             CorbaTypeMap tmORB oorb,
             ServiceInfo sInfo) {
         super(handler);
          = tm;
          = sInfo;
          = oorb;
          = (Unionhandler.getType();
          = .getUnionbranch();  
     }
 
     public void processStartElement(QName name) {
         if ( == null) {
             for (Unionbranch branch : ) {               
                 CorbaObjectHandler content;
                 QName unionName = null;
                 String branchName = branch.getName();
                 if (branch.getName().equals(name.getLocalPart())) {
                     unionName = name;
                 } else if (.size() == 1) {
                     unionName = .getName();
                 }
                 if (unionName != null) {
                     CorbaObjectHandler discObj =
                         CorbaHandlerUtils.createTypeHandler(,
                                                             new QName("discriminator"),
                                                             .getDiscriminator(),
                                                             );
                     ((CorbaUnionHandler)).setDiscriminator(discObj);
                     String descriminatorValue = determineDescriminatorValue(branch);
                     ((CorbaUnionHandler)).setDiscriminatorValueFromData(descriminatorValue);
 
                      =
                         CorbaHandlerUtils.getTypeListener(unionName,
                                                           branch.getIdltype(),
                                                           ,
                                                           ,
                                                           );
                     .setNamespaceContext();
                     content = .getCorbaObject();
                     ((CorbaUnionHandler)).setValue(branchNamecontent);
                     if (.isSetNillable() && .isNillable()) {
                         .processStartElement(name);
                     }
                 } else {
                     QName emptyBranchContentQName = 
                         new QName(name.getNamespaceURI(), branchName);
                     content = CorbaHandlerUtils.initializeObjectHandler(,
                                                                         emptyBranchContentQName,
                                                                         branch.getIdltype(),
                                                                         ,
                                                                         );
                 }                
                 ((CorbaUnionHandler)).addCase(content);
             }
         } else {
             .processStartElement(name);
        }
    }
    public void processCharacters(String text) {
        if ( != null) {
            .processCharacters(text);
        } else {
            //Nillable primitive cases, you do not get the start element            
            CorbaPrimitiveHandler discObj =
                new CorbaPrimitiveHandler(new QName("discriminator"),
                                          .getDiscriminator(),
                                          .get_primitive_tc(TCKind.from_int(.)),
                                          null);
            discObj.setValue(.);
            ((CorbaUnionHandler)).setDiscriminator(discObj);           
            CorbaTypeListener typeListener =
                CorbaHandlerUtils.getTypeListener(.getName(),
                                                  .get(0).getIdltype(),
                                                  ,
                                                  ,
                                                  );
            typeListener.setNamespaceContext();
            ((CorbaUnionHandler)).setValue("value"typeListener.getCorbaObject());
            typeListener.processCharacters(text);
        }
    }
    public void processEndElement(QName name) {
        if ( != null) {
            .processEndElement(name);
        }
    }
    private String determineDescriminatorValue(Unionbranch branch) {
        String descriminatorValue;
        // Determine the value of the discriminator.  
        List<CaseTypebranchCases = branch.getCase();
        if (branchCases.size() != 0) {
            CaseType caseLabel = branchCases.get(0);
            descriminatorValue = caseLabel.getLabel();
        } else {
            // This represents the default case.
            descriminatorValue = ((CorbaUnionHandler)).createDefaultDiscriminatorLabel();
        }
        return descriminatorValue;
    }
    public void processWriteAttribute(String prefix,
                                      String namespaceURI,
                                      String localName,
                                      String val) {
        if ("nil".equals(localName)) {
            CorbaPrimitiveHandler discObj =
                new CorbaPrimitiveHandler(new QName("discriminator"),
                                          .getDiscriminator(),
                                          .get_primitive_tc(TCKind.from_int(.)),
                                          null);
            discObj.setValue(.);
            ((CorbaUnionHandler)).setDiscriminator(discObj);
            Unionbranch branch = .get(0);
            QName emptyBranchContentQName = 
                new QName(.getName().getNamespaceURI(), branch.getName());
            CorbaObjectHandler content = CorbaHandlerUtils.initializeObjectHandler(,
                                                                                   emptyBranchContentQName,
                                                                                   branch.getIdltype(),
                                                                                   ,
                                                                                   );
            ((CorbaUnionHandler)).addCase(content);
        } else if ( != null) {
            .processWriteAttribute(prefixnamespaceURIlocalNameval);
        }
    }
    public void processWriteNamespace(String prefixString namespaceURI) {
        if ( != null) {
            .processWriteNamespace(prefixnamespaceURI);
        }
    }
New to GrepCode? Check out our FAQ X