Coverage Report - com.aurea.maven.plugins.sonic.sdm.container.impl.DefaultMFContainer
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultMFContainer
0%
0/62
0%
0/22
2
 
 1  
 package com.aurea.maven.plugins.sonic.sdm.container.impl;
 2  
 
 3  
 import java.io.StringReader;
 4  
 import java.util.ArrayList;
 5  
 import java.util.Arrays;
 6  
 import java.util.List;
 7  
 
 8  
 import org.codehaus.plexus.util.StringUtils;
 9  
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 10  
 import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
 11  
 
 12  
 import com.aurea.maven.plugins.sonic.sdm.container.IMFContainer;
 13  
 import com.aurea.maven.plugins.sonic.sdo.AbstractDataObjectInstance;
 14  
 
 15  
 import commonj.sdo.DataObject;
 16  
 
 17  
 public class DefaultMFContainer extends AbstractDataObjectInstance implements IMFContainer {
 18  
 
 19  
   @Override
 20  
   protected String getNamespace() {
 21  
 
 22  0
     return "http://www.soa-knowledge.net/ESBPlugin";
 23  
   }
 24  
 
 25  
   @Override
 26  
   protected String getXSDType() {
 27  
 
 28  0
     return "ESBContainer";
 29  
   }
 30  
 
 31  
   @Override
 32  
   protected String getResourceLocation() {
 33  
 
 34  0
     return "schema/MFContainer.xsd";
 35  
   }
 36  
 
 37  
   /**
 38  
    * @param _name
 39  
    *          _name
 40  
    * @param _targetContainer
 41  
    *          _targetContainer
 42  
    * @param _bootContainer
 43  
    *          _bootContainer
 44  
    * @param _hosts
 45  
    *          _hosts
 46  
    */
 47  
   public DefaultMFContainer(
 48  
                   final String _name, 
 49  
                   final String _targetContainer, 
 50  
                   final boolean _bootContainer, 
 51  
                   final String _backupContainer,
 52  
                   final String _hosts,
 53  0
                   final boolean _clone) {
 54  
 
 55  0
     doInit(_name, _targetContainer, _bootContainer, _backupContainer, _hosts, _clone);
 56  0
   }
 57  
 
 58  
   
 59  
   public String getSegment(){
 60  
           //System.out.println("TIM TIM TIM - Calling getSegment and returning:" + getDataObject().getString("Segment"));
 61  0
           return getDataObject().getString("Segment");
 62  
   }
 63  
   
 64  
   public String getLogDirectory(){
 65  
           //System.out.println("TIM TIM TIM - Calling getLogDirectory and returning: " + getDataObject().getString("LogDirectory"));
 66  0
           return getDataObject().getString("LogDirectory");
 67  
   }
 68  
   
 69  
   public String getContainerParameterSet(){
 70  
          // System.out.println("TIM TIM TIM - Calling getContainerParameterSet and returning: " + getDataObject().getString("ContainerParameterSet"));
 71  0
           return getDataObject().getString("ContainerParameterSet");
 72  
   }
 73  
   /**
 74  
    * {@inheritDoc}
 75  
    */
 76  
   public String getName() {
 77  
           //System.out.println("TIM TIM TIM - Calling getName and returning: " + getDataObject().getString("Id"));
 78  0
     return getDataObject().getString("Id");
 79  
   }
 80  
 
 81  
   /**
 82  
    * {@inheritDoc}
 83  
    */
 84  
   public boolean isBootContainer() {
 85  
 
 86  0
     return getDataObject().getBoolean("BootContainer");
 87  
   }
 88  
   
 89  
   public boolean isClone(){
 90  0
           return getDataObject().getBoolean("Clone");
 91  
   }
 92  
 
 93  
   private void doInit(
 94  
                   final String _name, 
 95  
                   final String _targetContainer, 
 96  
                   final boolean _bootContainer, 
 97  
                   final String _backupContainer, 
 98  
                   final String _hosts,
 99  
                   final boolean _clone) {
 100  
 
 101  0
     DataObject dObj = getDataObject();
 102  
 
 103  0
     dObj.set("Id", _name);
 104  
 
 105  0
     if (_targetContainer != null) {
 106  0
       dObj.set("TargetContainer", _targetContainer);
 107  
     }
 108  
 
 109  0
     dObj.set("BootContainer", Boolean.valueOf(_bootContainer));
 110  
 
 111  0
     if(StringUtils.isNotEmpty(_backupContainer)) {
 112  0
             dObj.set("BackupContainer", _backupContainer);
 113  
 //            System.out.println("SETTING THE CLONE VALUE TO: " + _clone);
 114  0
             dObj.set("Clone", _clone);
 115  
     }
 116  
     
 117  
 //    if(StringUtils.isNotEmpty(_segment)){
 118  
 //            dObj.set("Segment", _segment);
 119  
 //    }
 120  
     
 121  0
     if (_hosts != null) {
 122  0
       DataObject obj = dObj.createDataObject("Hosts");
 123  0
       obj.setList("Host", Arrays.asList(_hosts.split(",")));
 124  
     }
 125  0
   }
 126  
 
 127  
   /**
 128  
    * @param _hosts
 129  
    *          _hosts
 130  
    */
 131  
   @SuppressWarnings("unchecked")
 132  
   public void addHosts(final String _hosts) {
 133  
 
 134  0
     if (_hosts == null) {
 135  0
       return;
 136  
     }
 137  
 
 138  0
     DataObject obj = getDataObject().getDataObject("Hosts");
 139  0
     if (obj == null) {
 140  0
       obj = getDataObject().createDataObject("Hosts");
 141  0
       obj.setList("Host", Arrays.asList(_hosts.split(",")));
 142  
     } else {
 143  0
       List<String> hostList = new ArrayList<String>();
 144  0
       hostList.addAll(obj.getList("Host"));
 145  0
       for (String host : _hosts.split(",")) {
 146  0
         if (!hostList.contains(host)) {
 147  0
           hostList.add(host);
 148  
         }
 149  
       }
 150  0
       obj.setList("Host", hostList);
 151  
     }
 152  0
   }
 153  
 
 154  
   /**
 155  
    * {@inheritDoc}
 156  
    */
 157  
   public Xpp3Dom removeNamespaces() {
 158  
 
 159  
     // TODO: fix this
 160  
     // quick hack to remove namespaces
 161  
 
 162  0
     Xpp3Dom element = new Xpp3Dom("ESBContainer");
 163  
 
 164  
     try {
 165  0
       Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(toString()));
 166  0
       for (Xpp3Dom child : dom.getChildren()) {
 167  0
         element.addChild(child);
 168  
       }
 169  0
     } catch (Exception e) {
 170  
       // ignore
 171  0
             e.printStackTrace();
 172  0
     }
 173  
 
 174  0
     return element;
 175  
   }
 176  
 
 177  
   /**
 178  
    * {@inheritDoc}
 179  
    */
 180  
   public Xpp3Dom removeNamespaces8() {
 181  
 
 182  
     // TODO: fix this
 183  
     // quick hack to remove namespaces
 184  
 
 185  0
     Xpp3Dom element = new Xpp3Dom("ESBContainer");
 186  
 
 187  
     try {
 188  0
       Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(toString()));
 189  0
       for (Xpp3Dom child : dom.getChildren()) {
 190  0
         if (child.getName().equals("Hosts")) {
 191  0
             Xpp3Dom changeHosts = new Xpp3Dom("LogicalHosts");
 192  0
             changeHosts.setValue(child.getValue());
 193  0
             for(Xpp3Dom changeHost : child.getChildren()){
 194  0
               Xpp3Dom logicalHost = new Xpp3Dom("LogicalHost");
 195  0
               logicalHost.setValue(changeHost.getValue());
 196  0
               changeHosts.addChild(logicalHost);
 197  
             }
 198  0
             element.addChild(changeHosts);
 199  0
         } else {
 200  0
           element.addChild(child);
 201  
         }
 202  
       }
 203  0
     } catch (Exception e) {
 204  
       // ignore
 205  0
             e.printStackTrace();
 206  0
     }
 207  
 
 208  0
     return element;
 209  
   }
 210  
 }