QosTaildropProfileProfileModel.java :  » App » learnandroid » com » lgnortel » r4 » r4equipment » management » olt » qos » Android Open Source

Android Open Source » App » learnandroid 
learnandroid » com » lgnortel » r4 » r4equipment » management » olt » qos » QosTaildropProfileProfileModel.java
package com.lgnortel.r4.r4equipment.management.olt.qos;

import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.dom.NamedNodeMap;

import com.lgnortel.lib.logger.LoggerUtil;
import com.lgnortel.netconf.DOM4Confspec;
import com.lgnortel.netconf.NetconfElementModel;
import com.lgnortel.netconf.wdmpon.Msp;
import com.lgnortel.netconf.wdmpon.Qos;
import com.lgnortel.netconf.wdmpon.TaildropProfile;
import com.lgnortel.netconf.wdmpon.TaildropProfileDropProfile;
import com.lgnortel.r4.r4equipment.common.ManagementComplexModelIF;
import com.lgnortel.r4.r4equipment.common.ParameterCheckException;
import com.lgnortel.r4.util.R4Constants;
import com.lgnortel.r4.util.R4Util;
import com.tailf.inm.Element;
import com.tailf.inm.ElementChildrenIterator;
import com.tailf.inm.INMException;

/**
 * Copyright (c) 2009 LG-Nortel, Inc. All Rights Reserved.
 * 
 * CONFIDENTIALITY AND LIMITED USE: This software, including any software of <br>
 * third parties embodied herein, contains code, information, data and concepts <br>
 * which are confidential and/or proprietary to LG-Nortel and such third <br>
 * parties. This software is licensed for use solely in accordance with the <br>
 * terms and conditions of the applicable license agreement with LG-Nortel or <br>
 * its authorized distributor, and not for any other use or purpose. No <br>
 * redistribution of this software by any party is permitted. <br>
 * 
 * Title: QosProfilesQueueProfileModel<br>
 * Description: <br>
 * Copyright: Copyright(c) 2009 LG-NORTEL ALL Rights Reserved<br>
 * Company: LG-Nortel<br>
 * 
 * @author Junggu, Lee
 * @version 0.1
 * @created 2009. 3. 26.
 * @modified 2009. 3. 26.
 * @product EFA R4.0 EMS
 * @sw_block
 */
public class QosTaildropProfileProfileModel implements ManagementComplexModelIF {

  // Log4J
  Logger logger = LoggerUtil.getInstance().getLogger(this.getClass().getName());

  // table name
  public static final String TABLE_NAME = "Taildrop-Profile";

  // Syntax information
  String sMaxOccurs = null;

  private final String MSP_MO = "msp";
  private final String QOS_MO = "qos";
  private final String TAILDROP_PROFILE_MO = "taildrop-profile";
  private final String DROP_PROFILE_MO = "drop-profile";
  
  private final String TAILDROP_PROFILE_NAME_ATTR = "name";
  private final String GREEN_YELLOW_ATTR = "green-yellow";
  private final String THRESHOLD_ATTR = "threshold";

  /**
   * Constructor
   * 
   * @param neId
   */
  public QosTaildropProfileProfileModel() {
  }

  /**
   * Return table schema information
   */
  public List<NetconfElementModel> getTableSchema() {

    Vector<NetconfElementModel> columnInfo = new Vector<NetconfElementModel>();

    // 1. Locate "msp/qos/taildrop-profile" Node in the DOM tree of wdmpon.cs
    DOM4Confspec dom4Confspec = DOM4Confspec.getInstance();
    String[] fdn = {MSP_MO, QOS_MO, TAILDROP_PROFILE_MO};
    org.w3c.dom.Node keyNode = dom4Confspec.findNode(fdn);
    if (keyNode == null) {
      logger.warning("wdmpon.cs parsing error!");
      return null;
    }
    
    // 2. Extract and save 'maxOccurs' value for getMaxOccurs()
    NamedNodeMap nnm = keyNode.getAttributes();
    org.w3c.dom.Node itemNode = nnm.getNamedItem(R4Constants.MAX_OCCURS_ATTR_NAME);
    if (itemNode != null) {
      sMaxOccurs = itemNode.getNodeValue();
      logger.info("sMaxOccurs: " + sMaxOccurs);
    }
    
    // 3. Extract leaf nodes' value of 'type' attribute  
    String[] attrFdn = {MSP_MO, QOS_MO, TAILDROP_PROFILE_MO, DROP_PROFILE_MO};
    org.w3c.dom.Node attrNode = dom4Confspec.findNode(attrFdn);

    columnInfo = dom4Confspec.getComponentSchema(attrNode.getChildNodes());

    // change column name and width, etc
    for (NetconfElementModel oneNem : columnInfo) {
      if (oneNem.getElementName().equals(THRESHOLD_ATTR)) {
        oneNem.setMandatory(true);
      }
    }

    return columnInfo;
  }

  /**
   * Return maxOccurs value of msp/qos/taildrop-profile Component
   */
  public int getMaxOccurs() {

    int maxOccurs = 1;

    if (sMaxOccurs != null) {
      if (sMaxOccurs.equals(R4Constants.MAX_OCCURS_VALUE_UNBOUNDED)) {
        maxOccurs = Integer.MAX_VALUE;
      } else {
        maxOccurs = Integer.parseInt(sMaxOccurs);
      }
    }

    return maxOccurs;
  }


  /**
   * Convert Element into the form that can be used in Table Model
   * =======================================================================================
     * name    green-yellow   threshold 
   * ---------------------------------------------------------------------------------------
   * =======================================================================================
   */
  public Vector<Vector<Object>> makeTableInformation(Element element, Map<String, Object> keys) {

    // return value
    Vector<Vector<Object>> tblInfo = new Vector<Vector<Object>>();
    
    // save parent MO's key
    if (keys == null) {
      logger.warning("keys should not be null.");
      return tblInfo;
    }

    String taildropProfileName = keys.get(TAILDROP_PROFILE_NAME_ATTR).toString();
    if (taildropProfileName == null) {
      logger.warning("Error in keys.. there should be 'wred-profile-name' key!");
      return tblInfo;
    }
    logger.info("makeTableInformation() under taildrop-profile['" + taildropProfileName + "']..");

    // Locate intermediate-agent MO.
    if(element == null)    return tblInfo;
    Msp msp = (Msp)element;
    if( msp == null) {
      logger.info("No msp configuration..");
      return tblInfo;
    }
    Qos qos = msp.qos;
    if (qos == null) {
      logger.info("No qos configuration..");
      return tblInfo;
    }
    
    Object vGreenYellow="", vThreshold="";
  
    TaildropProfile taildropProfile = null;
    try {
      taildropProfile = qos.getTaildropProfile(taildropProfileName);
    } catch (INMException ie) {
      logger.info("No qos/wred-profile['" + taildropProfileName + "'] configuration..");
      return tblInfo;
    }

    ElementChildrenIterator dropProfileIt = taildropProfile.dropProfileIterator();
    
    while(dropProfileIt.hasNext()) {
      Vector<Object> tblRow = new Vector<Object>();
      
      TaildropProfileDropProfile dropProfile = (TaildropProfileDropProfile)dropProfileIt.next();
      
      try {
        vGreenYellow = R4Util.validateNullValue(dropProfile.getGreenYellowValue());
        vThreshold = R4Util.validateNullValue(dropProfile.getThresholdValue());
      } catch (Exception e) {
        logger.fine("Exception is occurred !!");
      }
      
      tblRow.addElement(vGreenYellow);
      tblRow.addElement(vThreshold);

      tblInfo.addElement(tblRow);
    }
    // return table information
    return tblInfo;
  }
  

  public String[] getProfileList(Element element) {
    
    if( element == null)  return null;
    Msp msp = (Msp)element;
    Qos qos = msp.qos;
    if( msp == null) {
      logger.info("No msp configuration..");
      return null;
    }
    if (qos == null) {
      logger.info("No qos configuration..");
      return null;
    }
    
    ElementChildrenIterator taildropProfileIt = qos.taildropProfileIterator();
    
    int count = 0;
    while(taildropProfileIt.hasNext()) {
      taildropProfileIt.next();
      count++;
    }
    
    String[] profileNameList = new String[count];
    int index = 0;
    
    taildropProfileIt = qos.taildropProfileIterator();

    while(taildropProfileIt.hasNext()) {
    
      TaildropProfile taildropProfile = (TaildropProfile)taildropProfileIt.next();
      try {
        profileNameList[index++] = new String(R4Util.validateNullValue(taildropProfile.getNameValue()).toString());
      } catch (Exception ex) {
        logger.fine("Exception is occurred !!");
      }
    }
    return profileNameList;
  }
  
  /**
   * Convert Element into the form that can be used in Table Model
   * =======================================================================================
     * wred-profile-name    green-yellow   drop-probability  max-threshold  min-threshold
   * ---------------------------------------------------------------------------------------
   * =======================================================================================
   */
  public Msp addTableInfoToMsp(Msp msp, List<Map<String, Object>> rows, Map<String, Object> keys) throws ParameterCheckException {

    if (keys == null) {
      logger.warning("keys should not be null.");
      return null;
    }

    // save parent MO's key
    String taildropProfileName = keys.get(TAILDROP_PROFILE_NAME_ATTR).toString();
    if (taildropProfileName == null) {
      logger.warning("Error in keys.. there should be 'taildrop-profile-name' key!");
      return null;
    }
    
    try {
      // construct MO tree
      Qos qos = (Qos) msp.qos;
      if (qos == null) {
        logger.info("No qos configuration..");
        qos = new Qos();
        msp.addQos(qos);
      }
      
      for (int i=0; i<rows.size(); i++) {
        Map<String, Object> oneRow = rows.get(i);
        
        TaildropProfile taildropProfile = getSameTaildropProfileNameTaildropProfile(qos, taildropProfileName);
        
        if( taildropProfile == null ) {
          taildropProfile = new TaildropProfile();
          qos.addTaildropProfile(taildropProfile);
        } 
          
        taildropProfile.setNameValue(taildropProfileName);
        
        TaildropProfileDropProfile dropProfile = new TaildropProfileDropProfile();
        
        if (R4Util.isExistingField(oneRow.get(GREEN_YELLOW_ATTR).toString())) {
          dropProfile.setGreenYellowValue(oneRow.get(GREEN_YELLOW_ATTR).toString());
        }
        if (R4Util.isExistingField(oneRow.get(THRESHOLD_ATTR).toString())) {
          dropProfile.setThresholdValue(oneRow.get(THRESHOLD_ATTR).toString());
        }
        
        taildropProfile.addDropProfile(dropProfile);
      }
    } catch (Exception e) {
      logger.log(Level.SEVERE, "Exception in set()", e);
      throw new ParameterCheckException(ParameterCheckException.FIRST_MSG, ParameterCheckException.SECOND_MSG);
    }

    logger.fine("config ==> \n" + msp.toXMLString());
    
    return msp;
  }
  
  private TaildropProfile getSameTaildropProfileNameTaildropProfile(Qos qos, String taildropProfileName) {
    
    if( qos.getChildren() == null ) {
      return null;
    }
    
    ElementChildrenIterator taildropProfileIt = qos.taildropProfileIterator();
    
    while(taildropProfileIt.hasNext()) {
      
      TaildropProfile taildropProfile = (TaildropProfile)taildropProfileIt.next();
      try {
        String vTaildropProfileName = R4Util.validateNullValue(taildropProfile.getNameValue()).toString();
        
        if(vTaildropProfileName.equals(taildropProfileName)) {
          return taildropProfile;
        }
      } catch(Exception ex) {
        ex.printStackTrace();
        return null;
      }
    }

    return null;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.