QosAccessListNameModel.java :  » App » learnandroid » com » lgnortel » r4 » r4equipment » management » ont » qos » Android Open Source

Android Open Source » App » learnandroid 
learnandroid » com » lgnortel » r4 » r4equipment » management » ont » qos » QosAccessListNameModel.java
package com.lgnortel.r4.r4equipment.management.ont.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.PonAccess;
import com.lgnortel.netconf.wdmpon.PonAccessQos;
import com.lgnortel.netconf.wdmpon.QosAccessList;
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;

/**
 * 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: QosClassifierClassModel<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 QosAccessListNameModel implements ManagementComplexModelIF {

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

  // table name
  public static final String TABLE_NAME = "Qos Access List";

  // Syntax information
  String sMaxOccurs = null;
  
  private final String MSP_MO = "msp";
  private final String PON_ACCESS_MO = "pon-access";
  private final String QOS_MO = "qos";
  private final String ACCESS_LIST_MO = "access-list";
  
  private final String ACL_NAME_ATTR = "acl-name";

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

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

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

    // 1. Locate "msp/qos/classifier/class" Node in the DOM tree of wdmpon.cs
    DOM4Confspec dom4Confspec = DOM4Confspec.getInstance();
    String[] fdn = {MSP_MO, PON_ACCESS_MO, QOS_MO, ACCESS_LIST_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);
    }
    
    keyColumnInfo = dom4Confspec.getComponentSchema(keyNode.getChildNodes());

    // columnInfo = keyColumnInfo + attrColumnInfo
    for (int i=0; i<keyColumnInfo.size(); i++) {
      columnInfo.addElement(keyColumnInfo.get(i));
    }

    return columnInfo;
  }

  /**
   * Return maxOccurs value of msp/qos/classifier 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;
  }

  //
  // table header is as below.
  // classifier-name : class-name : forwarding-class : color : policer : pbits : de
  //
  public Vector<Vector<Object>> makeTableInformation(Element element, Map<String, Object> keys) {

    logger.info("makeTableInformation()..");

    // return value
    Vector<Vector<Object>> tblInfo = new Vector<Vector<Object>>();

    // Locate intermediate-agent MO
    if( element == null)  return tblInfo;
    Msp msp = (Msp)element;
    if( msp == null) {
      logger.info("No msp configuration..");
      return tblInfo;
    }
    PonAccess ponAccess = msp.ponAccess;
    if (ponAccess == null) {
      logger.info("No pon-access configuration..");
      return tblInfo;
    }
    PonAccessQos qos = ponAccess.qos;
    if (qos == null) {
      logger.info("No qos configuration..");
      return tblInfo;
    }

    Object vAccessListName="";

    ElementChildrenIterator accessListIt = qos.accessListIterator();
    
    while(accessListIt.hasNext()) {
      
      QosAccessList accessList = (QosAccessList)accessListIt.next();
      Vector<Object> tblRow = new Vector<Object>();
        
      try {
        vAccessListName = R4Util.validateNullValue(accessList.getAclNameValue());
      } catch(Exception e) {
        logger.fine("Exception is occured !!");
      }
      tblRow.addElement(vAccessListName);
      tblInfo.addElement(tblRow);
    }
    // return table information
    return tblInfo;
  }
  
  //
  // table header is as below.
  // classifier-name : class-name : forwarding-class : color : policer : pbits : de
  //
  public Msp addTableInfoToMsp(Msp msp, List<Map<String, Object>> rows, Map<String, Object> key) throws ParameterCheckException  {

    try {
      // construct MO tree
      PonAccess ponAccess = msp.ponAccess;
      if (ponAccess == null) {
        logger.info("No pon-access configuration..");
        ponAccess = new PonAccess();
        msp.addPonAccess(ponAccess);
      }
      PonAccessQos qos = ponAccess.qos;
      if (qos == null) {
        logger.info("No qos configuration..");
        qos = new PonAccessQos();
        ponAccess.addQos(qos);
      }
      
      for (int i=0; i<rows.size(); i++) {
        Map<String, Object> oneRow = rows.get(i);
        
        QosAccessList accessList = new QosAccessList();
        qos.addAccessList(accessList);
        
        if (R4Util.isExistingField(oneRow.get(ACL_NAME_ATTR).toString())) {
          accessList.setAclNameValue(oneRow.get(ACL_NAME_ATTR).toString());
        }
      }
    } 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;
  }
}
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.