1 Reply Latest reply on Nov 19, 2014 10:25 AM by michpetrov

    Compilation errors while migrating from richfaces 3.2.2 to richfaces 4.2.2.Final

    raovenu

      I am in the process of upgrading my project from richfaces 3.2.2 to richfaces 4.2.2.Final and getting several compilation errors. We were using myfaces 1.2 which I am now upgrading to myfaces 2.0. I am following the migration guide and changed my configurations accordingly. I am able to resolve most of my issues but I am stuck with getting my bean that uses a tree component to compile. I am getting unresolved errors on the following imports.

      import org.richfaces.model.ListRowKey;

      import org.richfaces.model.TreeRange;

      import org.richfaces.model.TreeRowKey;

       

      Can someone provide me any pointers to get these resolved. Here is my pom.xml content:

       

      <?xml version="1.0" encoding="UTF-8"?>

      <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"

               xmlns="http://maven.apache.org/POM/4.0.0"

          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

          

          <modelVersion>4.0.0</modelVersion>

          <parent>

              <artifactId>nams-parent</artifactId>

              <groupId>com.boeing.nmt.nams</groupId>

              <version>1.5-LIB-UPGRADE</version>

          </parent>

          <groupId>com.boeing.nmt.nams</groupId>

          <artifactId>nams</artifactId>

          <packaging>war</packaging>

          <name>NAMS GUI</name>

          <url>http://maven.apache.org</url>

         

          <properties>

              <el.version>1.0</el.version>

              <myfaces.version>2.0.0</myfaces.version>

              <richfaces.version>4.2.2.Final</richfaces.version>          

          </properties>              

       

          <build>

              <finalName>nams</finalName>

          </build>

         

          <profiles>

              <profile>

                  <id>jetty</id>

                  <activation>

                      <property>

                          <name>app.server.type</name>

                          <value>jetty</value>

                      </property>

                  </activation>

              </profile>

              <profile>

                  <id>tomcat</id>

                  <activation>

                      <property>

                          <name>app.server.type</name>

                          <value>tomcat</value>

                      </property>

                  </activation>

                  <dependencies>

                      <dependency>

                          <groupId>javax.el</groupId>

                          <artifactId>el-api</artifactId>

                          <version>${el.version}</version>

                          <scope>package</scope>

                      </dependency>

                      <dependency>

                          <groupId>com.sun.el</groupId>

                          <artifactId>el-ri</artifactId>

                          <version>${el.version}</version>

                          <scope>package</scope>

                      </dependency>

                  </dependencies>

              </profile>

              <profile>

                  <id>weblogic</id>

                  <activation>

                      <property>

                          <name>app.server.type</name>

                          <value>weblogic</value>

                      </property>

                  </activation>

                  <dependencies>

                      <dependency>

                          <groupId>javax.el</groupId>

                          <artifactId>el-api</artifactId>

                          <version>${el.version}</version>

                          <scope>package</scope>

                      </dependency>

                      <dependency>

                          <groupId>com.sun.el</groupId>

                          <artifactId>el-ri</artifactId>

                          <version>${el.version}</version>

                          <scope>package</scope>

                      </dependency>

                  </dependencies>

              </profile>

          </profiles>

         

          <dependencies>

              <dependency>

                  <groupId>${project.groupId}</groupId> 

                  <artifactId>nams-core</artifactId> 

                  <version>${project.version}</version> 

                  <scope>compile</scope>

              </dependency>       

              <dependency>

                  <groupId>jfree</groupId>

                  <artifactId>jcommon</artifactId>

                  <version>1.0.15</version>

              </dependency>       

              <dependency>

                  <groupId>jfree</groupId>

                  <artifactId>jfreechart</artifactId>

                  <version>1.0.13</version>

                  <scope>compile</scope>

              </dependency>                    

              <dependency>

                  <groupId>org.apache.myfaces.core</groupId>

                  <artifactId>myfaces-api</artifactId>

                  <version>2.0.0</version>

              </dependency>                             

              <dependency>

                  <groupId>org.apache.myfaces.core</groupId>

                  <artifactId>myfaces-impl</artifactId>

                  <version>2.0.0</version>

              </dependency>

              <dependency> 

                  <groupId>org.apache.myfaces.tomahawk</groupId> 

                  <artifactId>tomahawk12</artifactId> 

                  <version>1.1.9</version>

                  <scope>compile</scope>

                  <exclusions>

                      <exclusion>

                          <groupId>xml-apis</groupId>

                          <artifactId>xmlParserAPIs</artifactId>

                      </exclusion>

                  </exclusions>

              </dependency>       

              <dependency> 

                  <groupId>richfaces-components-api</groupId> 

                  <artifactId>richfaces-components-api</artifactId> 

                  <version>${richfaces.version}</version>

                  <scope>compile</scope>

              </dependency>

              <dependency> 

                  <groupId>richfaces-core-api</groupId> 

                  <artifactId>richfaces-core-api</artifactId> 

                  <version>${richfaces.version}</version>

                  <scope>compile</scope>

              </dependency>

              <dependency> 

                  <groupId>richfaces-core-impl</groupId> 

                  <artifactId>richfaces-core-impl</artifactId> 

                  <version>${richfaces.version}</version>

                  <scope>compile</scope>

              </dependency>

              <dependency> 

                  <groupId>richfaces-components-ui</groupId> 

                  <artifactId>richfaces-components-ui</artifactId> 

                  <version>${richfaces.version}</version>

                  <exclusions>

                      <exclusion>

                          <artifactId>jsf-api</artifactId>

                          <groupId>com.sun.faces</groupId>

                      </exclusion>

                      <exclusion>

                          <artifactId>jsf-impl</artifactId>

                          <groupId>com.sun.faces</groupId>

                      </exclusion>

                  </exclusions>

                  <scope>compile</scope>

              </dependency>                                              

              <dependency>

                  <groupId>org.springframework</groupId> 

                  <artifactId>spring-web</artifactId> 

                  <version>${springframework.version}</version> 

                  <scope>compile</scope>

              </dependency>

              <dependency>

                  <groupId>org.springframework.batch</groupId> 

                  <artifactId>spring-batch-core</artifactId> 

                  <version>${spring-batch.version}</version> 

                  <scope>compile</scope>

              </dependency>

              <dependency>

                  <groupId>org.springframework.batch</groupId> 

                  <artifactId>spring-batch-infrastructure</artifactId> 

                  <version>${spring-batch.version}</version> 

                  <scope>compile</scope>

              </dependency>

          </dependencies>

       

      </project>

      Here is my backing bean code:

       

      /*

      * Copyright (c) 2008 Boeing. All rights reserved.

      */

      package com.boeing.nmt.nams.view.bean.device;

       

      import java.io.IOException;

      import java.util.ArrayList;

      import java.util.Collections;

      import java.util.Comparator;

      import java.util.HashSet;

      import java.util.List;

      import java.util.Map;

      import java.util.Set;

      import java.util.TreeSet;

       

      import javax.faces.application.FacesMessage;

      import javax.faces.component.UIComponent;

      import javax.faces.context.FacesContext;

      import javax.faces.event.ActionEvent;

      import javax.servlet.http.Cookie;

       

      import org.ajax4jsf.model.DataVisitor;

      import org.ajax4jsf.model.Range;

      import org.apache.commons.logging.Log;

      import org.apache.commons.logging.LogFactory;

      //import org.richfaces.component.UIScrollableDataTable;

      import org.richfaces.component.UIExtendedDataTable;

      import org.richfaces.component.UITree;

      //import org.richfaces.component.state.TreeState;

      //import org.richfaces.event.NodeExpandedEvent;

      import org.richfaces.event.TreeToggleEvent;

      //import org.richfaces.event.NodeSelectedEvent;

      import org.richfaces.event.TreeSelectionChangeEvent;

      import org.richfaces.model.ListRowKey;

      import org.richfaces.model.TreeNode;

      import org.richfaces.model.TreeRange;

      import org.richfaces.model.TreeRowKey;

      import org.richfaces.renderkit.TreeNodeState;

      import org.springframework.util.StringUtils;

      import com.boeing.nmt.nams.dao.DeviceDao;

      import com.boeing.nmt.nams.dao.DeviceInterfaceDao;

      import com.boeing.nmt.nams.model.AddressBlock;

      import com.boeing.nmt.nams.model.Device;

      import com.boeing.nmt.nams.model.DeviceInterface;

      import com.boeing.nmt.nams.model.DeviceSummaryView;

      import com.boeing.nmt.nams.model.DeviceSummaryViewId;

      import com.boeing.nmt.nams.model.Domain;

      import com.boeing.nmt.nams.model.Fqdn;

      import com.boeing.nmt.nams.model.IpAddress;

      import com.boeing.nmt.nams.model.IpFqdn;

      import com.boeing.nmt.nams.model.IpInterface;

      import com.boeing.nmt.nams.model.Namespace;

      import com.boeing.nmt.nams.service.validation.PrivilegeValidator;

      import com.boeing.nmt.nams.util.BenchmarkTimer;

      import com.boeing.nmt.nams.util.FqdnUtils;

      import com.boeing.nmt.nams.view.bean.device.event.AliasFqdnCreatedEvent;

      import com.boeing.nmt.nams.view.bean.device.event.AliasFqdnUpdatedEvent;

      import com.boeing.nmt.nams.view.bean.device.event.DataCreatedEvent;

      import com.boeing.nmt.nams.view.bean.device.event.DataCreatedListener;

      import com.boeing.nmt.nams.view.bean.device.event.DataCreatedSource;

      import com.boeing.nmt.nams.view.bean.device.event.DataDeletedEvent;

      import com.boeing.nmt.nams.view.bean.device.event.DataDeletedListener;

      import com.boeing.nmt.nams.view.bean.device.event.DataDeletedSource;

      import com.boeing.nmt.nams.view.bean.device.event.DataSelectedEvent;

      import com.boeing.nmt.nams.view.bean.device.event.DataSelectedSource;

      import com.boeing.nmt.nams.view.bean.device.event.DataUpdatedEvent;

      import com.boeing.nmt.nams.view.bean.device.event.DataUpdatedListener;

      import com.boeing.nmt.nams.view.bean.device.event.DataUpdatedSource;

      import com.boeing.nmt.nams.view.bean.device.event.DeviceCreatedEvent;

      import com.boeing.nmt.nams.view.bean.device.event.DeviceInterfaceCreatedEvent;

      import com.boeing.nmt.nams.view.bean.device.event.DeviceInterfaceUpdatedEvent;

      import com.boeing.nmt.nams.view.bean.device.event.DeviceUpdatedEvent;

      import com.boeing.nmt.nams.view.bean.device.event.FqdnCreatedEvent;

      import com.boeing.nmt.nams.view.bean.device.event.FqdnUpdatedEvent;

      import com.boeing.nmt.nams.view.bean.device.event.IpAddressCreatedEvent;

      import com.boeing.nmt.nams.view.bean.device.event.IpAddressUpdatedEvent;

      import com.boeing.nmt.nams.view.exception.ViewException;

      import com.boeing.nmt.nams.view.util.CookieUtils;

      import com.boeing.nmt.nams.view.util.FacesUtils;

       

      /**

      * Device tree bean.

      *

      * @author uo580c

      */

      public class DeviceTreeBean implements DataCreatedListener, DataUpdatedListener, DataDeletedListener

      {

          private static final Log logger = LogFactory.getLog(DeviceTreeBean.class);

       

          public static final String RESTRICTED = DeviceSearchModel.RESTRICTED;

       

          // Oracle limit on maximum number of expressions in a list.

          public static final int MAXIMUM_EXPRESSIONS_IN_LIST = 1000;

       

          /*

           * Dependency injection member variables

           */

       

          private DeviceDao deviceDao;

          private DeviceInterfaceDao deviceInterfaceDao;

          private DeviceTreeContext deviceTreeContext;

          private DataCreatedSource dataCreatedSource;

          private DataDeletedSource dataDeletedSource;

          private DataSelectedSource dataSelectedSource;

          private DataUpdatedSource dataUpdatedSource;

          private PrivilegeValidator privilegeValidator;

          private DeviceTreeContextMenuBean deviceTreeContextMenuBean;

       

          /*

           * Other member variables

           */

       

          private Long deviceId;

          private UITree deviceTree;

          private DeviceSummaryViewId deviceSummaryViewId;

          private Data data;

          private Boolean filterByDeviceInterface = new Boolean(false);

          private List<Long> filteredDeviceInterfaceIds;

       

          /*

           * Nested classes

           */

       

          public class Data

          {

              private String key;

              private String value;

              private boolean flag;

       

              public Data()

              {

              }

       

              public String getKey()

              {

                  return this.key;

              }

       

              public void setKey(final String key)

              {

                  this.key = key;

              }

       

              public String getValue()

              {

                  return this.value;

              }

       

              public void setValue(final String value)

              {

                  this.value = value;

              }

       

              public boolean isFlag()

              {

                  return this.flag;

              }

       

              public void setFlag(final boolean flag)

              {

                  this.flag = flag;

              }

          }

       

          /*

           * Constructor

           */

       

          public DeviceTreeBean()

          {

              logger.debug("constructor");

          }

       

          /*

           * Dependency injection methods

           */

       

          public void setDeviceDao(final DeviceDao deviceDao)

          {

              this.deviceDao = deviceDao;

          }

       

          public void setDeviceInterfaceDao(final DeviceInterfaceDao deviceInterfaceDao)

          {

              this.deviceInterfaceDao = deviceInterfaceDao;

          }

       

          public void setDeviceTreeContext(final DeviceTreeContext deviceTreeContext)

          {

              this.deviceTreeContext = deviceTreeContext;

          }

       

          public void setDataCreatedSource(final DataCreatedSource dataCreatedSource)

          {

              this.dataCreatedSource = dataCreatedSource;

              this.dataCreatedSource.addDataCreatedListener(this);

          }

       

          public void setDataDeletedSource(final DataDeletedSource dataDeletedSource)

          {

              this.dataDeletedSource = dataDeletedSource;

              this.dataDeletedSource.addDataDeletedListener(this);

          }

       

          public void setDataSelectedSource(final DataSelectedSource dataSelectedSource)

          {

              this.dataSelectedSource = dataSelectedSource;

          }

       

          public void setDataUpdatedSource(final DataUpdatedSource dataUpdatedSource)

          {

              this.dataUpdatedSource = dataUpdatedSource;

              this.dataUpdatedSource.addDataUpdatedListener(this);

          }

       

          public void setPrivilegeValidator(final PrivilegeValidator privilegeValidator)

          {

              this.privilegeValidator = privilegeValidator;

          }

       

          public void setDeviceTreeContextMenuBean(final DeviceTreeContextMenuBean deviceTreeContextMenuBean)

          {

              this.deviceTreeContextMenuBean = deviceTreeContextMenuBean;

          }

       

          /*

           * Listener methods

           */

       

          @SuppressWarnings("unchecked")

          public void processDataCreated(final DataCreatedEvent event)

          {

              if (this.deviceTree == null)

              {

                  logger.warn("deviceTree is null, event=" + event);

                  return;

              }

              final TreeNodeState state = (TreeNodeState) this.deviceTree.getComponentState();

              final TreeRowKey<String> parentRowKey = state.getSelectedNode();

              logger.debug("processDataCreated(): event=" + event + ", parentRowKey=" + parentRowKey);

              if (DeviceCreatedEvent.class.isInstance(event))

              {

                  // Handled by onToDeviceTree().

              } else if (DeviceInterfaceCreatedEvent.class.isInstance(event))

              {

                  processDeviceInterfaceCreated(event, parentRowKey);

              } else if (IpAddressCreatedEvent.class.isInstance(event))

              {

                  processIpAddressCreated(event, parentRowKey);

              } else if (FqdnCreatedEvent.class.isInstance(event))

              {

                  processFqdnCreated(event, parentRowKey);

              } else if (AliasFqdnCreatedEvent.class.isInstance(event))

              {

                  processAliasFqdnCreated(event, parentRowKey);

              } else

              {

                  logger.warn("Unsupported event=" + event);

              }

          }

       

          private void processDeviceInterfaceCreated(final DataCreatedEvent event, final TreeRowKey<String> parentRowKey)

          {

              final DeviceInterfaceCreatedEvent deviceInterfaceCreatedEvent = (DeviceInterfaceCreatedEvent) event;

              final Device device = deviceInterfaceCreatedEvent.getDevice();

              final DeviceInterface deviceInterface = deviceInterfaceCreatedEvent.getDeviceInterface();

       

              final String key = parentRowKey.toString();

              final String subKey = "device-" + device.getId();

              if (!key.endsWith(subKey))

              {

                  logger.warn(key + " does not end with " + subKey);

                  return;

              }

       

              if (!this.filteredDeviceInterfaceIds.isEmpty())

              {

                  this.filteredDeviceInterfaceIds.add(deviceInterface.getId());

              }

              constructDeviceInterfaceTree(deviceInterface, parentRowKey);

          }

       

          private void processIpAddressCreated(final DataCreatedEvent event, final TreeRowKey<String> parentRowKey)

          {

              final IpAddressCreatedEvent ipAddressCreatedEvent = (IpAddressCreatedEvent) event;

              final Device device = ipAddressCreatedEvent.getDevice();

              final DeviceInterface deviceInterface = ipAddressCreatedEvent.getDeviceInterface();

              final IpAddress ipAddress = ipAddressCreatedEvent.getIpAddress();

              final Fqdn fqdn = ipAddressCreatedEvent.getFqdn();

       

              final String key = parentRowKey.toString();

              final String subKey = "deviceInterface-" + deviceInterface.getId();

              if (!key.endsWith(subKey))

              {

                  logger.warn(key + " does not end with " + subKey);

                  return;

              }

       

              constructIpAddressTree(ipAddress, parentRowKey);

       

              if (isUpdateDeviceInterface(deviceInterface, ipAddress, fqdn))

              {

                  updateDeviceInterface(device, deviceInterface);

              }

          }

       

          private void processFqdnCreated(final DataCreatedEvent event, final TreeRowKey<String> parentRowKey)

          {

              final FqdnCreatedEvent fqdnCreatedEvent = (FqdnCreatedEvent) event;

              final Device device = fqdnCreatedEvent.getDevice();

              final DeviceInterface deviceInterface = fqdnCreatedEvent.getDeviceInterface();

              final IpAddress ipAddress = fqdnCreatedEvent.getIpAddress();

              final Fqdn fqdn = fqdnCreatedEvent.getFqdn();

       

              final String key = parentRowKey.toString();

              final String subKey = "ipAddress-" + ipAddress.getId();

              if (!key.endsWith(subKey))

              {

                  logger.warn(key + " does not end with " + subKey);

                  return;

              }

       

              constructFqdnTree(fqdn, parentRowKey);

       

              if (isUpdateDeviceInterface(deviceInterface, ipAddress, fqdn))

              {

                  updateDeviceInterface(device, deviceInterface);

              }

          }

       

          private void processAliasFqdnCreated(final DataCreatedEvent event, final TreeRowKey<String> parentRowKey)

          {

              final AliasFqdnCreatedEvent aliasFqdnCreatedEvent = (AliasFqdnCreatedEvent) event;

              final Fqdn fqdn = aliasFqdnCreatedEvent.getFqdn();

              final Fqdn aliasFqdn = aliasFqdnCreatedEvent.getAliasFqdn();

       

              final String key = parentRowKey.toString();

              final String fqdnSubKey = "fqdn-" + fqdn.getId();

              final String aliasFqdnSubKey = "aliasFqdn-" + fqdn.getId();

              if (!key.endsWith(fqdnSubKey) && !key.endsWith(aliasFqdnSubKey))

              {

                  logger.warn(key + " does not end with " + fqdnSubKey + " and does not end with " + aliasFqdnSubKey);

                  return;

              }

       

              constructAliasFqdnTree(aliasFqdn, parentRowKey);

          }

       

          @SuppressWarnings("unchecked")

          private void constructDeviceInterfaceTree(final DeviceInterface deviceInterface,

                  final TreeRowKey<String> parentRowKey)

          {

              final DeviceInterfaceTreeNodeData deviceInterfaceTreeNodeData = new DeviceInterfaceTreeNodeData(

                      deviceInterface, getLabel(deviceInterface));

              final DeviceTreeNode<DeviceInterfaceTreeNodeData> deviceInterfaceTreeNode = new DeviceTreeNode<DeviceInterfaceTreeNodeData>();

              deviceInterfaceTreeNode.setData(deviceInterfaceTreeNodeData);

       

              final String id = "deviceInterface-" + deviceInterface.getId();

              this.deviceTree.addNode(parentRowKey, deviceInterfaceTreeNode, id, null);

       

              logger.debug("constructDeviceInterfaceTree(): id=" + id);

       

              final TreeRowKey<String> rowKey = (TreeRowKey<String>) this.deviceTree

                      .getTreeNodeRowKey(deviceInterfaceTreeNode);

              final Set<IpInterface> ipInterfaces = deviceInterface.getIpInterfaces();

              final Comparator<IpAddress> ipAddressComparator = new IpAddressComparator();

              final Set<IpAddress> ipAddresses = new TreeSet<IpAddress>(ipAddressComparator);

              for (final IpInterface ipInterface : ipInterfaces)

              {

                  final IpAddress ipAddress = ipInterface.getIpAddress();

                  ipAddresses.add(ipAddress);

              }

       

              for (final IpAddress ipAddress : ipAddresses)

              {

                  constructIpAddressTree(ipAddress, rowKey);

              }

          }

       

          @SuppressWarnings("unchecked")

          private void constructIpAddressTree(final IpAddress ipAddress, final TreeRowKey<String> parentRowKey)

          {

              final IpAddressTreeNodeData ipAddressTreeNodeData = new IpAddressTreeNodeData(ipAddress, getLabel(ipAddress));

              final DeviceTreeNode<IpAddressTreeNodeData> ipAddressTreeNode = new DeviceTreeNode<IpAddressTreeNodeData>();

              ipAddressTreeNode.setData(ipAddressTreeNodeData);

       

              final String id = "ipAddress-" + ipAddress.getId();

              this.deviceTree.addNode(parentRowKey, ipAddressTreeNode, id, null);

       

              logger.debug("constructIpAddressTree(): id=" + id);

       

              final TreeRowKey<String> rowKey = (TreeRowKey<String>) this.deviceTree.getTreeNodeRowKey(ipAddressTreeNode);

              final Set<IpFqdn> ipFqdns = ipAddress.getIpFqdns();

              final Comparator<Fqdn> fqdnComparator = new FqdnComparator();

              final Set<Fqdn> fqdns = new TreeSet<Fqdn>(fqdnComparator);

              for (final IpFqdn ipFqdn : ipFqdns)

              {

                  final Fqdn fqdn = ipFqdn.getFqdn();

                  fqdns.add(fqdn);

              }

       

              for (final Fqdn fqdn : fqdns)

              {

                  constructFqdnTree(fqdn, rowKey);

              }

          }

       

          @SuppressWarnings("unchecked")

          private void constructFqdnTree(final Fqdn fqdn, final TreeRowKey<String> parentRowKey)

          {

              final FqdnTreeNodeData fqdnTreeNodeData = new FqdnTreeNodeData(fqdn, getLabel(fqdn));

              final DeviceTreeNode<FqdnTreeNodeData> fqdnTreeNode = new DeviceTreeNode<FqdnTreeNodeData>();

              fqdnTreeNode.setData(fqdnTreeNodeData);

       

              final String id = "fqdn-" + fqdn.getId();

              this.deviceTree.addNode(parentRowKey, fqdnTreeNode, id, null);

       

              logger.debug("constructFqdnTree(): id=" + id);

       

              final TreeRowKey<String> rowKey = (TreeRowKey<String>) this.deviceTree.getTreeNodeRowKey(fqdnTreeNode);

              final Set<Fqdn> unsortedAliasFqdns = fqdn.getFqdns();

              final Set<Fqdn> aliasFqdns;

              if (unsortedAliasFqdns.size() > 1)

              {

                  final Comparator<Fqdn> fqdnComparator = new FqdnComparator();

                  aliasFqdns = new TreeSet<Fqdn>(fqdnComparator);

                  aliasFqdns.addAll(unsortedAliasFqdns);

              } else

              {

                  aliasFqdns = unsortedAliasFqdns;

              }

              for (final Fqdn aliasFqdn : aliasFqdns)

              {

                  constructAliasFqdnTree(aliasFqdn, rowKey);

              }

          }

       

          @SuppressWarnings("unchecked")

          private void constructAliasFqdnTree(final Fqdn fqdn, final TreeRowKey<String> parentRowKey)

          {

              final AliasFqdnTreeNodeData aliasFqdnTreeNodeData = new AliasFqdnTreeNodeData(fqdn, getLabel(fqdn));

              final DeviceTreeNode<AliasFqdnTreeNodeData> aliasFqdnTreeNode = new DeviceTreeNode<AliasFqdnTreeNodeData>();

              aliasFqdnTreeNode.setData(aliasFqdnTreeNodeData);

       

              final String id = "aliasFqdn-" + fqdn.getId();

              this.deviceTree.addNode(parentRowKey, aliasFqdnTreeNode, id, null);

       

              logger.debug("constructAliasFqdnTree(): id=" + id);

       

              final TreeRowKey<String> rowKey = (TreeRowKey<String>) this.deviceTree.getTreeNodeRowKey(aliasFqdnTreeNode);

              final Set<Fqdn> unsortedAliasFqdns = fqdn.getFqdns();

              final Set<Fqdn> aliasFqdns;

              if (unsortedAliasFqdns.size() > 1)

              {

                  final Comparator<Fqdn> fqdnComparator = new FqdnComparator();

                  aliasFqdns = new TreeSet<Fqdn>(fqdnComparator);

                  aliasFqdns.addAll(unsortedAliasFqdns);

              } else

              {

                  aliasFqdns = unsortedAliasFqdns;

              }

              for (final Fqdn aliasFqdn : aliasFqdns)

              {

                  constructAliasFqdnTree(aliasFqdn, rowKey);

              }

          }

       

          @SuppressWarnings("unchecked")

          public void processDataUpdated(final DataUpdatedEvent event)

          {

              final TreeNodeState state = (TreeNodeState) this.deviceTree.getComponentState();

              final TreeRowKey<String> rowKey = state.getSelectedNode();

              logger.debug("processDataUpdated(): event=" + event + ", rowKey=" + rowKey);

              final Data data = new Data();

              setData(data);

              if (DeviceUpdatedEvent.class.isInstance(event))

              {

                  processDeviceUpdated(event, rowKey);

              } else if (DeviceInterfaceUpdatedEvent.class.isInstance(event))

              {

                  processDeviceInterfaceUpdated(event, rowKey);

              } else if (IpAddressUpdatedEvent.class.isInstance(event))

              {

                  processIpAddressUpdated(event, rowKey);

              } else if (FqdnUpdatedEvent.class.isInstance(event))

              {

                  processFqdnUpdated(event, rowKey);

              } else if (AliasFqdnUpdatedEvent.class.isInstance(event))

              {

                  processAliasFqdnUpdated(event, rowKey);

              } else

              {

                  logger.warn("Unsupported event=" + event);

              }

          }

       

          @SuppressWarnings("unchecked")

          private void processDeviceUpdated(final DataUpdatedEvent event, final TreeRowKey<String> rowKey)

          {

              final DeviceUpdatedEvent deviceUpdatedEvent = (DeviceUpdatedEvent) event;

              final Device device = deviceUpdatedEvent.getDevice();

       

              final String key = rowKey.toString();

              final String subKey = "device-" + device.getId();

              if (!key.endsWith(subKey))

              {

                  logger.warn(key + " does not end with " + subKey);

                  return;

              }

       

              final TreeNode<DeviceTreeNodeData> treeNode = this.deviceTree.getModelTreeNode(rowKey);

              if (treeNode != null)

              {

                  final DeviceTreeNodeData deviceTreeNodeData = treeNode.getData();

                  deviceTreeNodeData.setDevice(device);

                  this.data.setKey(key);

                  this.data.setValue(deviceTreeNodeData.getData());

                  this.deviceTreeContext.setDevice(device);

              }

          }

       

          @SuppressWarnings("unchecked")

          private void processDeviceInterfaceUpdated(final DataUpdatedEvent event, final TreeRowKey<String> rowKey)

          {

              final DeviceInterfaceUpdatedEvent deviceInterfaceUpdatedEvent = (DeviceInterfaceUpdatedEvent) event;

              final DeviceInterface deviceInterface = deviceInterfaceUpdatedEvent.getDeviceInterface();

       

              final String key = rowKey.toString();

              final String subKey = "deviceInterface-" + deviceInterface.getId();

              if (!key.endsWith(subKey))

              {

                  logger.warn(key + " does not end with " + subKey);

                  return;

              }

       

              final TreeNode<DeviceInterfaceTreeNodeData> treeNode = this.deviceTree.getModelTreeNode(rowKey);

              if (treeNode != null)

              {

                  final DeviceInterfaceTreeNodeData deviceInterfaceTreeNodeData = treeNode.getData();

                  deviceInterfaceTreeNodeData.setDeviceInterface(deviceInterface, getLabel(deviceInterface));

                  this.data.setKey(key);

                  this.data.setValue(deviceInterfaceTreeNodeData.getData());

                  this.deviceTreeContext.setDeviceInterface(deviceInterface);

              }

          }

       

          @SuppressWarnings("unchecked")

          private void processIpAddressUpdated(final DataUpdatedEvent event, final TreeRowKey<String> rowKey)

          {

              final IpAddressUpdatedEvent ipAddressUpdatedEvent = (IpAddressUpdatedEvent) event;

              final IpAddress ipAddress = ipAddressUpdatedEvent.getIpAddress();

       

              final String key = rowKey.toString();

              final String subKey = "ipAddress-" + ipAddress.getId();

              if (!key.endsWith(subKey))

              {

                  logger.warn(key + " does not end with " + subKey);

                  return;

              }

       

              final TreeNode<IpAddressTreeNodeData> treeNode = this.deviceTree.getModelTreeNode(rowKey);

              if (treeNode != null)

              {

                  final IpAddressTreeNodeData ipAddressTreeNodeData = treeNode.getData();

                  ipAddressTreeNodeData.setIpAddress(ipAddress, getLabel(ipAddress));

                  this.data.setKey(key);

                  this.data.setValue(ipAddressTreeNodeData.getData());

                  this.deviceTreeContext.setIpAddress(ipAddress);

              }

          }

       

          @SuppressWarnings("unchecked")

          private void processFqdnUpdated(final DataUpdatedEvent event, final TreeRowKey<String> rowKey)

          {

              final FqdnUpdatedEvent fqdnUpdatedEvent = (FqdnUpdatedEvent) event;

              final Device device = fqdnUpdatedEvent.getDevice();

              final DeviceInterface deviceInterface = fqdnUpdatedEvent.getDeviceInterface();

              final IpAddress ipAddress = fqdnUpdatedEvent.getIpAddress();

              final Fqdn fqdn = fqdnUpdatedEvent.getFqdn();

       

              final String key = rowKey.toString();

              final String subKey = "fqdn-" + fqdn.getId();

              if (!key.endsWith(subKey))

              {

                  logger.warn(key + " does not end with " + subKey);

                  return;

              }

       

              final TreeNode<FqdnTreeNodeData> treeNode = this.deviceTree.getModelTreeNode(rowKey);

              if (treeNode != null)

              {

                  final FqdnTreeNodeData fqdnTreeNodeData = treeNode.getData();

                  fqdnTreeNodeData.setFqdn(fqdn, getLabel(fqdn));

                  this.data.setKey(key);

                  this.data.setValue(fqdnTreeNodeData.getData());

                  this.deviceTreeContext.setFqdn(fqdn);

              }

       

              if (isUpdateDeviceInterface(deviceInterface, ipAddress, fqdn))

              {

                  updateDeviceInterface(device, deviceInterface);

                  this.data.setFlag(true);

              }

          }

       

          private boolean isUpdateDeviceInterface(final DeviceInterface deviceInterface, final IpAddress ipAddress,

                  final Fqdn fqdn)

          {

              if (StringUtils.hasText(deviceInterface.getName()) || StringUtils.hasText(deviceInterface.getMac()))

              {

                  return false;

              }

       

              final IpFqdn ipFqdn = FqdnUtils.getIpFqdn(ipAddress, fqdn);

              if ((ipFqdn == null) || !ipFqdn.isPrimaryName())

              {

                  return false;

              }

       

              final IpAddress firstIpAddress = getFirstIpAddress(deviceInterface);

              if (!ipAddress.equals(firstIpAddress))

              {

                  return false;

              }

       

              return true;

          }

       

          @SuppressWarnings("unchecked")

          protected static IpAddress getFirstIpAddress(final DeviceInterface deviceInterface)

          {

              final Comparator<IpAddress> ipAddressComparator = new IpAddressComparator();

              final Set<IpAddress> ipAddresses = new TreeSet<IpAddress>(ipAddressComparator);

              final Set<IpInterface> ipInterfaces = deviceInterface.getIpInterfaces();

              for (final IpInterface ipInterface : ipInterfaces)

              {

                  final IpAddress ipAddress = ipInterface.getIpAddress();

                  ipAddresses.add(ipAddress);

              }

       

              for (final IpAddress ipAddress : ipAddresses)

              {

                  return ipAddress;

              }

       

              return null;

          }

       

          @SuppressWarnings("unchecked")

          private void updateDeviceInterface(final Device device, final DeviceInterface deviceInterface)

          {

              final String key = "device-" + device.getId() + ":" + "deviceInterface-" + deviceInterface.getId();

              logger.debug("updateDeviceInterface: key=" + key);

              final TreeRowKey<String> rowKey = toRowKey(key);

       

              final TreeNode<DeviceInterfaceTreeNodeData> treeNode = this.deviceTree.getModelTreeNode(rowKey);

              if (treeNode != null)

              {

                  final DeviceInterfaceTreeNodeData deviceInterfaceTreeNodeData = treeNode.getData();

                  deviceInterfaceTreeNodeData.setDeviceInterface(deviceInterface, getLabel(deviceInterface));

                  logger.debug("updateDeviceInterface(): found " + rowKey);

              } else

              {

                  logger.debug("updateDeviceInterface(): could not find " + rowKey);

              }

          }

       

          @SuppressWarnings("unchecked")

          private void processAliasFqdnUpdated(final DataUpdatedEvent event, final TreeRowKey<String> rowKey)

          {

              final AliasFqdnUpdatedEvent aliasFqdnUpdatedEvent = (AliasFqdnUpdatedEvent) event;

              final Fqdn aliasFqdn = aliasFqdnUpdatedEvent.getAliasFqdn();

       

              final String key = rowKey.toString();

              final String subKey = "aliasFqdn-" + aliasFqdn.getId();

              if (!key.endsWith(subKey))

              {

                  logger.warn(key + " does not end with " + subKey);

                  return;

              }

       

              final TreeNode<AliasFqdnTreeNodeData> treeNode = this.deviceTree.getModelTreeNode(rowKey);

              if (treeNode != null)

              {

                  final AliasFqdnTreeNodeData aliasFqdnTreeNodeData = treeNode.getData();

                  aliasFqdnTreeNodeData.setAliasFqdn(aliasFqdn, getLabel(aliasFqdn));

                  this.data.setKey(key);

                  this.data.setValue(aliasFqdnTreeNodeData.getData());

                  this.deviceTreeContext.setAliasFqdn(aliasFqdn);

              }

          }

       

          public void processDataDeleted(final DataDeletedEvent event)

          {

              refresh();

          }

       

          /*

           * Other methods

           */

       

          public UITree getDeviceTree()

          {

              logger.debug("getDeviceTree()");

              return this.deviceTree;

          }

       

          public void setDeviceTree(final UITree deviceTree)

          {

              logger.debug("setDeviceTree(): deviceTree=" + deviceTree);

              this.deviceTree = deviceTree;

       

              // Fix RFS# 45411 (NAMS hangs/times out after selecting the device node in the device tree) for Firefox. IE is

              // still broken.

              final String browserName = FacesUtils.getBrowserName();

              if (browserName.equals("Firefox"))

              {

                  final String oldBehavior = deviceTree.getAjaxNodeSelectionEncodeBehavior();

                  final String newBehavior = "node";

                  if (!newBehavior.equals(oldBehavior))

                  {

                      logger.warn("Changing deviceTree.ajaxNodeSelectionEncodeBehavior for " + browserName + ", oldBehavior="

                              + oldBehavior + ", newBehavior=" + newBehavior);

                      // This overrides the value for the rich:tree deviceTree ajaxNodeSelectionEncodeBehavior property in

                      // deviceTree.xhtml.

                      deviceTree.setAjaxNodeSelectionEncodeBehavior(newBehavior);

                  }

              }

       

          }

       

          public Data getData()

          {

              return this.data;

          }

       

          public void setData(final Data data)

          {

              this.data = data;

          }

       

          public Boolean isFilterByDeviceInterface()

          {

              return getFilterByDeviceInterface();

          }

       

          public Boolean getFilterByDeviceInterface()

          {

              final Cookie cookie = CookieUtils.getCookie("filterByDeviceInterface");

              if (cookie == null)

              {

                  CookieUtils.setCookie("filterByDeviceInterface", this.filterByDeviceInterface.toString(),

                          CookieUtils.DEFAULT_EXPIRY);

              } else

              {

                  this.filterByDeviceInterface = new Boolean(cookie.getValue());

              }

              return this.filterByDeviceInterface;

          }

       

          public void setFilterByDeviceInterface(final Boolean filterByDeviceInterface)

          {

              this.filterByDeviceInterface = filterByDeviceInterface;

              CookieUtils.setCookie("filterByDeviceInterface", this.filterByDeviceInterface.toString(),

                      CookieUtils.DEFAULT_EXPIRY);

          }

       

          synchronized public TreeNode<?> getRootTreeNode()

          {

              logger.debug("getRootTreeNode()");

              return this.deviceTreeContext.getRootTreeNode();

          }

       

          @SuppressWarnings("unchecked")

          private void constructDeviceTree(final Device device, final DeviceTreeNode<String> parentTreeNode)

          {

              if ((device == null) || (device.getId() == 0))

              {

                  return;

              }

       

              final BenchmarkTimer timer = new BenchmarkTimer();

       

              final DeviceTreeNodeData treeNodeData = new DeviceTreeNodeData(device);

              final DeviceTreeNode<DeviceTreeNodeData> treeNode = new DeviceTreeNode<DeviceTreeNodeData>();

              treeNode.setData(treeNodeData);

       

              final String id = "device-" + device.getId();

              parentTreeNode.addChild(id, treeNode);

              treeNode.setParent(parentTreeNode);

       

              logger.debug("constructDeviceTree(): id=" + id);

       

              Set<DeviceInterface> unsortedDeviceInterfaces;

              if (this.filteredDeviceInterfaceIds.isEmpty())

              {

                  unsortedDeviceInterfaces = device.getDeviceInterfaces();

              } else

              {

                  unsortedDeviceInterfaces = new HashSet<DeviceInterface>();

                  for (final Long deviceInterfaceId : this.filteredDeviceInterfaceIds)

                  {

                      final DeviceInterface deviceInterface = this.deviceInterfaceDao.get(deviceInterfaceId);

                      if (deviceInterface != null)

                      {

                          unsortedDeviceInterfaces.add(deviceInterface);

                      }

                  }

              }

       

              final List<DeviceInterface> deviceInterfaces = new ArrayList(unsortedDeviceInterfaces);

              final Comparator<DeviceInterface> deviceInterfaceComparator = new DeviceInterfaceComparator();

              Collections.sort(deviceInterfaces, deviceInterfaceComparator);

              for (final DeviceInterface deviceInterface : deviceInterfaces)

              {

                  constructDeviceInterfaceTree(deviceInterface, treeNode);

              }

       

              timer.done();

              logger.debug("constructDeviceTree(): " + timer.getSummary());

          }

       

          @SuppressWarnings("unchecked")

          private void constructDeviceInterfaceTree(final DeviceInterface deviceInterface,

                  final DeviceTreeNode<DeviceTreeNodeData> parentTreeNode)

          {

              final DeviceInterfaceTreeNodeData treeNodeData = new DeviceInterfaceTreeNodeData(deviceInterface,

                      getLabel(deviceInterface));

              final DeviceTreeNode<DeviceInterfaceTreeNodeData> treeNode = new DeviceTreeNode<DeviceInterfaceTreeNodeData>();

              treeNode.setData(treeNodeData);

       

              final String id = "deviceInterface-" + deviceInterface.getId();

              parentTreeNode.addChild(id, treeNode);

              treeNode.setParent(parentTreeNode);

       

              logger.debug("constructDeviceInterfaceTree(): id=" + id);

       

              final Set<IpInterface> ipInterfaces = deviceInterface.getIpInterfaces();

              final Comparator<IpAddress> ipAddressComparator = new IpAddressComparator();

              final Set<IpAddress> ipAddresses = new TreeSet<IpAddress>(ipAddressComparator);

              for (final IpInterface ipInterface : ipInterfaces)

              {

                  final IpAddress ipAddress = ipInterface.getIpAddress();

                  ipAddresses.add(ipAddress);

              }

       

              for (final IpAddress ipAddress : ipAddresses)

              {

                  constructIpAddressTree(ipAddress, treeNode);

              }

       

          }

       

          @SuppressWarnings("unchecked")

          private void constructIpAddressTree(final IpAddress ipAddress,

                  final DeviceTreeNode<DeviceInterfaceTreeNodeData> parentTreeNode)

          {

              final IpAddressTreeNodeData treeNodeData = new IpAddressTreeNodeData(ipAddress, getLabel(ipAddress));

              final DeviceTreeNode<IpAddressTreeNodeData> treeNode = new DeviceTreeNode<IpAddressTreeNodeData>();

              treeNode.setData(treeNodeData);

       

              final String id = "ipAddress-" + ipAddress.getId();

              parentTreeNode.addChild(id, treeNode);

              treeNode.setParent(parentTreeNode);

       

              logger.debug("constructIpAddressTree(): id=" + id);

       

              final Set<IpFqdn> ipFqdns = ipAddress.getIpFqdns();

              final Comparator<Fqdn> fqdnComparator = new FqdnComparator();

              final Set<Fqdn> fqdns = new TreeSet<Fqdn>(fqdnComparator);

              for (final IpFqdn ipFqdn : ipFqdns)

              {

                  final Fqdn fqdn = ipFqdn.getFqdn();

                  fqdns.add(fqdn);

              }

       

              for (final Fqdn fqdn : fqdns)

              {

                  constructFqdnTree(fqdn, treeNode);

              }

       

          }

       

          @SuppressWarnings("unchecked")

          private void constructFqdnTree(final Fqdn fqdn, final DeviceTreeNode<IpAddressTreeNodeData> parentTreeNode)

          {

              final FqdnTreeNodeData treeNodeData = new FqdnTreeNodeData(fqdn, getLabel(fqdn));

              final DeviceTreeNode<FqdnTreeNodeData> treeNode = new DeviceTreeNode<FqdnTreeNodeData>();

              treeNode.setData(treeNodeData);

       

              final String id = "fqdn-" + fqdn.getId();

              parentTreeNode.addChild(id, treeNode);

              treeNode.setParent(parentTreeNode);

       

              logger.debug("constructFqdnTree(): id=" + id);

       

              setSearchKey(treeNode, fqdn);

       

              final Set<Fqdn> unsortedAliasFqdns = fqdn.getFqdns();

              final Set<Fqdn> aliasFqdns;

              if (unsortedAliasFqdns.size() > 1)

              {

                  final Comparator<Fqdn> fqdnComparator = new FqdnComparator();

                  aliasFqdns = new TreeSet<Fqdn>(fqdnComparator);

                  aliasFqdns.addAll(unsortedAliasFqdns);

              } else

              {

                  aliasFqdns = unsortedAliasFqdns;

              }

              for (final Fqdn aliasFqdn : aliasFqdns)

              {

                  constructAliasFqdnTree(aliasFqdn, treeNode);

              }

       

          }

       

          @SuppressWarnings("unchecked")

          private void constructAliasFqdnTree(final Fqdn fqdn, final DeviceTreeNode<?> parentTreeNode)

          {

              final AliasFqdnTreeNodeData treeNodeData = new AliasFqdnTreeNodeData(fqdn, getLabel(fqdn));

              final DeviceTreeNode<AliasFqdnTreeNodeData> treeNode = new DeviceTreeNode<AliasFqdnTreeNodeData>();

              treeNode.setData(treeNodeData);

       

              final String id = "aliasFqdn-" + fqdn.getId();

              parentTreeNode.addChild(id, treeNode);

              treeNode.setParent(parentTreeNode);

       

              logger.debug("constructAliasFqdnTree(): id=" + id);

       

              setSearchKey(treeNode, fqdn);

       

              final Set<Fqdn> unsortedAliasFqdns = fqdn.getFqdns();

              final Set<Fqdn> aliasFqdns;

              if (unsortedAliasFqdns.size() > 1)

              {

                  final Comparator<Fqdn> fqdnComparator = new FqdnComparator();

                  aliasFqdns = new TreeSet<Fqdn>(fqdnComparator);

                  aliasFqdns.addAll(unsortedAliasFqdns);

              } else

              {

                  aliasFqdns = unsortedAliasFqdns;

              }

              for (final Fqdn aliasFqdn : aliasFqdns)

              {

                  constructAliasFqdnTree(aliasFqdn, treeNode);

              }

          }

       

          private String getLabel(final DeviceInterface deviceInterface)

          {

              String label;

              final String name = deviceInterface.getName();

              final String mac = deviceInterface.getMac();

              if (StringUtils.hasText(name))

              {

                  // Use the name.

                  label = name;

              } else if (StringUtils.hasText(mac))

              {

                  // Use the MAC.

                  label = deviceInterface.getMac();

              } else

              {

                  // Use the primary host name of the first IP address.

                  label = "";

                  final IpAddress ipAddress = getFirstIpAddress(deviceInterface);

                  if (ipAddress != null)

                  {

                      final Fqdn fqdn = FqdnUtils.getPrimaryFqdn(ipAddress);

                      if (fqdn != null)

                      {

                          label = "(" + getLabel(fqdn) + ")";

                      } else

                      {

                          logger.warn("Could not find primary host name for the IP address, ipAddress=" + ipAddress);

                      }

                  } else

                  {

                      logger.warn("Could not find first IP address for the device interface, deviceInterface="

                              + deviceInterface);

                  }

              }

              return label;

          }

       

          private String getLabel(final Fqdn fqdn)

          {

              String label;

              final Domain domain = fqdn.getDomain();

              final Namespace namespace = domain.getNamespace();

              final String namespaceName = namespace.getName();

              final boolean restricted = isRestricted(fqdn);

              if ("Boeing Intranet".equals(namespaceName))

              {

                  if (restricted)

                  {

                      label = RESTRICTED + "." + domain.getName();

                  } else

                  {

                      label = fqdn.getName() + "." + domain.getName();

                  }

              } else

              {

                  if (restricted)

                  {

                      label = RESTRICTED + "." + domain.getName() + " (" + namespaceName + ")";

                  } else

                  {

                      label = fqdn.getName() + "." + domain.getName() + " (" + namespaceName + ")";

                  }

              }

              return label;

          }

       

          private boolean isRestricted(final Fqdn fqdn)

          {

              final Domain domain = fqdn.getDomain();

              return !hasReadPrivilege(domain);

          }

       

          private boolean hasReadPrivilege(final Domain domain)

          {

              final Map<Domain, Boolean> domainReadPrivilegeCache = this.deviceTreeContext.getDomainReadPrivilegeCache();

              Boolean hasReadPrivilege = domainReadPrivilegeCache.get(domain);

              if (hasReadPrivilege == null)

              {

                  hasReadPrivilege = this.privilegeValidator.hasReadPrivilege(domain);

                  domainReadPrivilegeCache.put(domain, hasReadPrivilege);

              }

              return hasReadPrivilege;

          }

       

          private String getLabel(final IpAddress ipAddress)

          {

              String label;

              final AddressBlock addressBlock = ipAddress.getAddressBlock();

              final Namespace namespace = addressBlock.getNamespace();

              final String namespaceName = namespace.getName();

              final boolean restricted = isRestricted(ipAddress);

              if ("Boeing Intranet".equals(namespaceName))

              {

                  if (restricted)

                  {

                      label = RESTRICTED;

                  } else

                  {

                      label = ipAddress.getIp();

                  }

              } else

              {

                  if (restricted)

                  {

                      label = RESTRICTED + " (" + namespaceName + ")";

                  } else

                  {

                      label = ipAddress.getIp() + " (" + namespaceName + ")";

                  }

              }

              return label;

          }

       

          private boolean isRestricted(final IpAddress ipAddress)

          {

              final AddressBlock addressBlock = ipAddress.getAddressBlock();

              return !hasReadPrivilege(addressBlock);

          }

       

          private boolean hasReadPrivilege(final AddressBlock addressBlock)

          {

              final Map<AddressBlock, Boolean> addressBlockReadPrivilegeCache = this.deviceTreeContext

                      .getAddressBlockReadPrivilegeCache();

              Boolean hasReadPrivilege = addressBlockReadPrivilegeCache.get(addressBlock);

              if (hasReadPrivilege == null)

              {

                  hasReadPrivilege = this.privilegeValidator.hasReadPrivilege(addressBlock);

                  addressBlockReadPrivilegeCache.put(addressBlock, hasReadPrivilege);

              }

              return hasReadPrivilege;

          }

       

          private void setSearchKey(final DeviceTreeNode<?> treeNode, final Fqdn fqdn)

          {

              logger.debug("setSearchKey()");

              String searchKey = this.deviceTreeContext.getSearchKey();

              if (searchKey == null)

              {

                  final String searchString = this.deviceTreeContext.getSearchString();

                  final String label = getLabel(fqdn);

                  logger.debug("setSearchKey(): searchString=" + searchString + ", label=" + label);

                  if (label.equalsIgnoreCase(searchString))

                  {

                      searchKey = getKey(treeNode);

                      this.deviceTreeContext.setSearchKey(searchKey);

                  }

              }

              logger.debug("setSearchKey(): searchKey=" + searchKey);

          }

       

          private String getKey(final DeviceTreeNode<?> treeNode)

          {

              String key = null;

              final DeviceTreeNode<?> parentTreeNode = (DeviceTreeNode<?>) treeNode.getParent();

              if (parentTreeNode != null)

              {

                  final String parentKey = getKey(parentTreeNode);

                  if (parentKey != null)

                  {

                      key = parentKey + ":" + getId(treeNode);

                  } else

                  {

                      key = getId(treeNode);

                  }

              }

              return key;

          }

       

          private String getId(final DeviceTreeNode<?> treeNode)

          {

              String id = null;

              final Object data = treeNode.getData();

              if (DeviceTreeNodeData.class.isInstance(data))

              {

                  final DeviceTreeNodeData deviceTreeNodeData = (DeviceTreeNodeData) data;

                  id = "device-" + deviceTreeNodeData.getDevice().getId();

              } else if (DeviceInterfaceTreeNodeData.class.isInstance(data))

              {

                  final DeviceInterfaceTreeNodeData deviceInterfaceTreeNodeData = (DeviceInterfaceTreeNodeData) data;

                  id = "deviceInterface-" + deviceInterfaceTreeNodeData.getDeviceInterface().getId();

              } else if (IpAddressTreeNodeData.class.isInstance(data))

              {

                  final IpAddressTreeNodeData ipAddressTreeNodeData = (IpAddressTreeNodeData) data;

                  id = "ipAddress-" + ipAddressTreeNodeData.getIpAddress().getId();

              } else if (FqdnTreeNodeData.class.isInstance(data))

              {

                  final FqdnTreeNodeData fqdnTreeNodeData = (FqdnTreeNodeData) data;

                  id = "fqdn-" + fqdnTreeNodeData.getFqdn().getId();

              } else if (AliasFqdnTreeNodeData.class.isInstance(data))

              {

                  final AliasFqdnTreeNodeData aliasFqdnTreeNodeData = (AliasFqdnTreeNodeData) data;

                  id = "aliasFqdn-" + aliasFqdnTreeNodeData.getAliasFqdn().getId();

              }

              return id;

          }

       

          public Long getDeviceId()

          {

              return this.deviceId;

          }

       

          synchronized public void setDeviceId(final Long deviceId)

          {

              logger.debug("setDeviceId()");

              this.deviceId = deviceId;

              if (deviceId == null)

              {

                  reset();

                  this.deviceTreeContext.setSearchString("");

                  final Device device = this.deviceTreeContext.getDevice();

                  final DeviceTreeNode<String> rootTreeNode = this.deviceTreeContext.getRootTreeNode();

                  constructDeviceTree(device, rootTreeNode);

              } else

              {

                  reset();

                  Device device = getDeviceGraph(deviceId.longValue());

                  if (device == null)

                  {

                      device = this.deviceTreeContext.getDevice();

                  } else

                  {

                      this.deviceTreeContext.setDevice(device);

                  }

                  final DeviceTreeNode<String> rootTreeNode = this.deviceTreeContext.getRootTreeNode();

                  constructDeviceTree(device, rootTreeNode);

              }

              logger.debug("setDeviceId(): end");

          }

       

          @SuppressWarnings("unchecked")

          private Device getDeviceGraph(final long deviceId)

          {

              final List<Device> devices = this.deviceDao.findByNamedQueryAndNamedParam("populateDeviceGraph", "deviceId",

                      deviceId);

              if (devices.size() <= 0)

              {

                  logger.warn("Could not find device, deviceId=" + deviceId);

                  return null;

              }

              final Device device = (Device) devices.get(0);

       

              final Set<DeviceInterface> deviceInterfaces = device.getDeviceInterfaces();

              logger.debug("getDeviceGraph(): deviceInterfaces.size=" + deviceInterfaces.size());

       

              final Set<IpAddress> ipAddresses = getIpAddressGraphs(deviceInterfaces);

              final Set<Fqdn> fqdns = getFqdnGraphs(ipAddresses);

              Set<Fqdn> aliasFqdns = getAliasFqdnGraphs(fqdns);

              while (aliasFqdns.size() > 0)

              {

                  aliasFqdns = getAliasFqdnGraphs(aliasFqdns);

              }

       

              return device;

          }

       

          @SuppressWarnings("unchecked")

          private final Set<IpAddress> getIpAddressGraphs(final Set<DeviceInterface> deviceInterfaces)

          {

              final Set<Long> ipAddressIds = new HashSet<Long>();

              if (this.filteredDeviceInterfaceIds.isEmpty())

              {

                  for (final DeviceInterface deviceInterface : deviceInterfaces)

                  {

                      final Set<IpInterface> ipInterfaces = deviceInterface.getIpInterfaces();

                      for (final IpInterface ipInterface : ipInterfaces)

                      {

                          final IpAddress ipAddress = ipInterface.getIpAddress();

                          ipAddressIds.add(new Long(ipAddress.getId()));

                      }

                  }

              } else

              {

                  final int size = deviceInterfaces.size();

                  int count = 0;

                  for (final DeviceInterface deviceInterface : deviceInterfaces)

                  {

                      if (this.filteredDeviceInterfaceIds.contains(deviceInterface.getId()))

                      {

                          final Set<IpInterface> ipInterfaces = deviceInterface.getIpInterfaces();

                          for (final IpInterface ipInterface : ipInterfaces)

                          {

                              final IpAddress ipAddress = ipInterface.getIpAddress();

                              ipAddressIds.add(new Long(ipAddress.getId()));

                          }

                      }

                      count++;

                      if (count == size)

                      {

                          break;

                      }

                  }

              }

              logger.debug("getIpAddressGraphs(): ipAddressIds.size=" + ipAddressIds.size());

       

              final List<Long> ipAddressIdList = new ArrayList<Long>(ipAddressIds);

              final Set<IpAddress> ipAddresses = new HashSet<IpAddress>();

              final int size = ipAddressIdList.size();

              final int max = MAXIMUM_EXPRESSIONS_IN_LIST;

              int fromIndex = 0;

              int toIndex = Math.min(size, max);

              while (fromIndex < size)

              {

                  final List<IpAddress> ipAddressList = this.deviceDao.findByNamedQueryAndNamedParam(

                          "populateIpAddressGraphs", "ipAddressIds", ipAddressIdList.subList(fromIndex, toIndex));

                  ipAddresses.addAll(ipAddressList);

                  fromIndex = toIndex;

                  toIndex = Math.min(fromIndex + max, size);

              }

              logger.debug("getIpAddressGraphs(): ipAddresses.size=" + ipAddresses.size());

       

              return ipAddresses;

          }

       

          @SuppressWarnings("unchecked")

          private final Set<Fqdn> getFqdnGraphs(final Set<IpAddress> ipAddresses)

          {

              final Set<Long> fqdnIds = new HashSet<Long>();

              for (final IpAddress ipAddress : ipAddresses)

              {

                  final Set<IpFqdn> ipFqdns = ipAddress.getIpFqdns();

                  for (final IpFqdn ipFqdn : ipFqdns)

                  {

                      final Fqdn fqdn = ipFqdn.getFqdn();

                      fqdnIds.add(new Long(fqdn.getId()));

                  }

              }

              logger.debug("getFqdnGraphs(): fqdnIds.size=" + fqdnIds.size());

       

              final List<Long> fqdnIdList = new ArrayList<Long>(fqdnIds);

              final Set<Fqdn> fqdns = new HashSet<Fqdn>();

              final int size = fqdnIdList.size();

              final int max = MAXIMUM_EXPRESSIONS_IN_LIST;

              int fromIndex = 0;

              int toIndex = Math.min(size, max);

              while (fromIndex < size)

              {

                  final List<Fqdn> fqdnList = this.deviceDao.findByNamedQueryAndNamedParam("populateFqdnGraphs", "fqdnIds",

                          fqdnIdList.subList(fromIndex, toIndex));

                  fqdns.addAll(fqdnList);

                  fromIndex = toIndex;

                  toIndex = Math.min(fromIndex + max, size);

              }

              logger.debug("getFqdnGraphs(): fqdns.size=" + fqdns.size());

       

              return fqdns;

          }

       

          @SuppressWarnings("unchecked")

          private final Set<Fqdn> getAliasFqdnGraphs(final Set<Fqdn> fqdns)

          {

              final Set<Long> aliasFqdnIds = new HashSet<Long>();

              for (final Fqdn fqdn : fqdns)

              {

                  final Set<Fqdn> aliasFqdns = fqdn.getFqdns();

                  for (final Fqdn aliasFqdn : aliasFqdns)

                  {

                      aliasFqdnIds.add(new Long(aliasFqdn.getId()));

                  }

              }

              logger.debug("getAliasFqdnGraphs(): aliasFqdnIds.size=" + aliasFqdnIds.size());

       

              final List<Long> aliasFqdnIdList = new ArrayList<Long>(aliasFqdnIds);

              final Set<Fqdn> aliasFqdns = new HashSet<Fqdn>();

              final int size = aliasFqdnIdList.size();

              final int max = MAXIMUM_EXPRESSIONS_IN_LIST;

              int fromIndex = 0;

              int toIndex = Math.min(size, max);

              while (fromIndex < size)

              {

                  final List<Fqdn> aliasFqdnList = this.deviceDao.findByNamedQueryAndNamedParam("populateFqdnGraphs",

                          "fqdnIds", aliasFqdnIdList.subList(fromIndex, toIndex));

                  aliasFqdns.addAll(aliasFqdnList);

                  fromIndex = toIndex;

                  toIndex = Math.min(fromIndex + max, size);

              }

              logger.debug("getAliasFqdnGraphs(): aliasFqdns.size=" + aliasFqdns.size());

       

              return aliasFqdns;

          }

       

          @SuppressWarnings("unchecked")

          private void reset()

          {

              logger.debug("reset(): deviceTree=" + this.deviceTree);

              if (this.deviceTree != null)

              {

                  this.deviceTree.resetDataModel();

                  final TreeNodeState state = (TreeNodeState) this.deviceTree.getComponentState();

                  state.setSelected(null);

       

                  final DeviceTreeNode<String> rootTreeNode = this.deviceTreeContext.getRootTreeNode();

                  final Device device = this.deviceTreeContext.getDevice();

                  logger.debug("reset() device=" + device);

                  if (device != null)

                  {

                      final String id = "device-" + device.getId();

                      final DeviceTreeNode<Device> treeNode = (DeviceTreeNode<Device>) rootTreeNode.getChild(id);

                      logger.debug("reset(): treeNode=" + treeNode);

                      if (treeNode != null)

                      {

                          final Object rowKey = this.deviceTree.getTreeNodeRowKey(treeNode);

                          this.deviceTree.removeNode(rowKey);

                      }

                  }

              }

              this.deviceTreeContext.reset();

              final DeviceTreeNode<String> treeNode = new DeviceTreeNode<String>();

              treeNode.setData("root");

              this.deviceTreeContext.setRootTreeNode(treeNode);

              this.deviceTreeContext.getAddressBlockReadPrivilegeCache().clear();

              this.deviceTreeContext.getDomainReadPrivilegeCache().clear();

          }

       

          @SuppressWarnings("unchecked")

          synchronized public void onSelect(final TreeSelectionChangeEvent event)

          {

              logger.debug("onSelect()");

              final UIComponent component = event.getComponent();

              logger.debug(component);

              logger.debug("onSelect(): component.id=" + component.getId());

              final UITree tree = (UITree) component;

              logger.debug("onSelect(): tree=" + tree);

       

              final TreeNodeState state = (TreeNodeState) tree.getComponentState();

              final TreeRowKey<String> rowKey = state.getSelectedNode();

              logger.debug("onSelect(): rowKey=" + rowKey);

       

              Object data = null;

              TreeNode<?> treeNode = null;

              if (rowKey != null)

              {

                  logger.debug("onSelect(): rowKey.class.name=" + rowKey.getClass().getName());

                  data = tree.getRowData(rowKey);

                  logger.debug("onSelect(): data.class.name=" + data.getClass().getName());

                  treeNode = tree.getTreeNode(rowKey);

                  logger.debug("onSelect(): treeNode.class.name=" + treeNode.getClass().getName());

              }

       

              resetSelectedData();

              setSelectedData(treeNode, 0);

              showSelectedData(data);

              notifyDataSelectedListeners();

       

              FacesUtils.setSessionMapValue("aliasContactFlag", "N");

              FacesUtils.setSessionMapValue("contBeanFlag", "N");

              FacesUtils.setSessionMapValue("hostContactFlag", "N");

       

              logger.debug("onSelect(): end");

          }

       

          private void showSelectedData(final Object data)

          {

              if (this.deviceTreeContext.isShowAncestors())

              {

                  showSelectedDataAndAncestors(data);

              } else

              {

                  showSelectedDataOnly(data);

              }

       

              if (DeviceTreeNodeData.class.isInstance(data))

              {

                  this.deviceTreeContext.setDeviceSelected(true);

                  this.deviceTreeContext.setDeviceInterfaceSelected(false);

                  this.deviceTreeContext.setIpAddressSelected(false);

                  this.deviceTreeContext.setFqdnSelected(false);

                  this.deviceTreeContext.setAliasFqdnSelected(false);

              } else if (DeviceInterfaceTreeNodeData.class.isInstance(data))

              {

                  this.deviceTreeContext.setDeviceSelected(false);

                  this.deviceTreeContext.setDeviceInterfaceSelected(true);

                  this.deviceTreeContext.setIpAddressSelected(false);

                  this.deviceTreeContext.setFqdnSelected(false);

                  this.deviceTreeContext.setAliasFqdnSelected(false);

              } else if (IpAddressTreeNodeData.class.isInstance(data))

              {

                  this.deviceTreeContext.setDeviceSelected(false);

                  this.deviceTreeContext.setDeviceInterfaceSelected(false);

                  this.deviceTreeContext.setIpAddressSelected(true);

                  this.deviceTreeContext.setFqdnSelected(false);

                  this.deviceTreeContext.setAliasFqdnSelected(false);

              } else if (FqdnTreeNodeData.class.isInstance(data))

              {

                  this.deviceTreeContext.setDeviceSelected(false);

                  this.deviceTreeContext.setDeviceInterfaceSelected(false);

                  this.deviceTreeContext.setIpAddressSelected(false);

                  this.deviceTreeContext.setFqdnSelected(true);

                  this.deviceTreeContext.setAliasFqdnSelected(false);

              } else if (AliasFqdnTreeNodeData.class.isInstance(data))

              {

                  this.deviceTreeContext.setDeviceSelected(false);

                  this.deviceTreeContext.setDeviceInterfaceSelected(false);

                  this.deviceTreeContext.setIpAddressSelected(false);

                  this.deviceTreeContext.setFqdnSelected(false);

                  this.deviceTreeContext.setAliasFqdnSelected(true);

              } else

              {

                  this.deviceTreeContext.setDeviceSelected(false);

                  this.deviceTreeContext.setDeviceInterfaceSelected(false);

                  this.deviceTreeContext.setIpAddressSelected(false);

                  this.deviceTreeContext.setFqdnSelected(false);

                  this.deviceTreeContext.setAliasFqdnSelected(false);

              }

          }

       

          private void showSelectedDataOnly(final Object data)

          {

              logger.debug("showSelectedData(): data=" + data);

       

              if (DeviceTreeNodeData.class.isInstance(data))

              {

                  this.deviceTreeContext.setDevicePanelRendered(true);

                  this.deviceTreeContext.setDeviceInterfacePanelRendered(false);

                  this.deviceTreeContext.setIpAddressPanelRendered(false);

                  this.deviceTreeContext.setFqdnPanelRendered(false);

                  this.deviceTreeContext.setAliasFqdnPanelRendered(false);

              } else if (DeviceInterfaceTreeNodeData.class.isInstance(data))

              {

                  this.deviceTreeContext.setDevicePanelRendered(false);

                  this.deviceTreeContext.setDeviceInterfacePanelRendered(true);

                  this.deviceTreeContext.setIpAddressPanelRendered(false);

                  this.deviceTreeContext.setFqdnPanelRendered(false);

                  this.deviceTreeContext.setAliasFqdnPanelRendered(false);

              } else if (IpAddressTreeNodeData.class.isInstance(data))

              {

                  this.deviceTreeContext.setDevicePanelRendered(false);

                  this.deviceTreeContext.setDeviceInterfacePanelRendered(false);

                  this.deviceTreeContext.setIpAddressPanelRendered(true);

                  this.deviceTreeContext.setFqdnPanelRendered(false);

                  this.deviceTreeContext.setAliasFqdnPanelRendered(false);

              } else if (FqdnTreeNodeData.class.isInstance(data))

              {

                  this.deviceTreeContext.setDevicePanelRendered(false);

                  this.deviceTreeContext.setDeviceInterfacePanelRendered(false);

                  this.deviceTreeContext.setIpAddressPanelRendered(false);

                  this.deviceTreeContext.setFqdnPanelRendered(true);

                  this.deviceTreeContext.setAliasFqdnPanelRendered(false);

              } else if (AliasFqdnTreeNodeData.class.isInstance(data))

              {

                  this.deviceTreeContext.setDevicePanelRendered(false);

                  this.deviceTreeContext.setDeviceInterfacePanelRendered(false);

                  this.deviceTreeContext.setIpAddressPanelRendered(false);

                  this.deviceTreeContext.setFqdnPanelRendered(false);

                  this.deviceTreeContext.setAliasFqdnPanelRendered(true);

              } else

              {

                  this.deviceTreeContext.setDevicePanelRendered(false);

                  this.deviceTreeContext.setDeviceInterfacePanelRendered(false);

                  this.deviceTreeContext.setIpAddressPanelRendered(false);

                  this.deviceTreeContext.setFqdnPanelRendered(false);

                  this.deviceTreeContext.setAliasFqdnPanelRendered(false);

              }

          }

       

          private void showSelectedDataAndAncestors(final Object data)

          {

              logger.debug("showSelectedDataAndAncestors(): data=" + data);

       

              if (DeviceTreeNodeData.class.isInstance(data))

              {

                  this.deviceTreeContext.setDevicePanelRendered(true);

                  this.deviceTreeContext.setDeviceInterfacePanelRendered(false);

                  this.deviceTreeContext.setIpAddressPanelRendered(false);

                  this.deviceTreeContext.setFqdnPanelRendered(false);

                  this.deviceTreeContext.setAliasFqdnPanelRendered(false);

              } else if (DeviceInterfaceTreeNodeData.class.isInstance(data))

              {

                  this.deviceTreeContext.setDevicePanelRendered(true);

                  this.deviceTreeContext.setDeviceInterfacePanelRendered(true);

                  this.deviceTreeContext.setIpAddressPanelRendered(false);

                  this.deviceTreeContext.setFqdnPanelRendered(false);

                  this.deviceTreeContext.setAliasFqdnPanelRendered(false);

              } else if (IpAddressTreeNodeData.class.isInstance(data))

              {

                  this.deviceTreeContext.setDevicePanelRendered(true);

                  this.deviceTreeContext.setDeviceInterfacePanelRendered(true);

                  this.deviceTreeContext.setIpAddressPanelRendered(true);

                  this.deviceTreeContext.setFqdnPanelRendered(false);

                  this.deviceTreeContext.setAliasFqdnPanelRendered(false);

              } else if (FqdnTreeNodeData.class.isInstance(data))

              {

                  this.deviceTreeContext.setDevicePanelRendered(true);

                  this.deviceTreeContext.setDeviceInterfacePanelRendered(true);

                  this.deviceTreeContext.setIpAddressPanelRendered(true);

                  this.deviceTreeContext.setFqdnPanelRendered(true);

                  this.deviceTreeContext.setAliasFqdnPanelRendered(false);

              } else if (AliasFqdnTreeNodeData.class.isInstance(data))

              {

                  this.deviceTreeContext.setDevicePanelRendered(true);

                  this.deviceTreeContext.setDeviceInterfacePanelRendered(true);

                  this.deviceTreeContext.setIpAddressPanelRendered(true);

                  this.deviceTreeContext.setFqdnPanelRendered(true);

                  this.deviceTreeContext.setAliasFqdnPanelRendered(true);

              } else

              {

                  this.deviceTreeContext.setDevicePanelRendered(false);

                  this.deviceTreeContext.setDeviceInterfacePanelRendered(false);

                  this.deviceTreeContext.setIpAddressPanelRendered(false);

                  this.deviceTreeContext.setFqdnPanelRendered(false);

                  this.deviceTreeContext.setAliasFqdnPanelRendered(false);

              }

          }

       

          private void resetSelectedData()

          {

              this.deviceTreeContext.reset();

          }

       

          private void setSelectedData(final TreeNode<?> treeNode, int aliasLevel)

          {

       

              logger.debug("setSelectedData(): treeNode=" + treeNode);

       

              if (treeNode == null)

              {

                  return;

              }

       

              final Object data = treeNode.getData();

       

              if (DeviceTreeNodeData.class.isInstance(data))

              {

                  final DeviceTreeNodeData deviceTreeNodeData = (DeviceTreeNodeData) data;

                  final Device device = deviceTreeNodeData.getDevice();

                  this.deviceTreeContext.setDevice(device);

              } else if (DeviceInterfaceTreeNodeData.class.isInstance(data))

              {

                  final DeviceInterfaceTreeNodeData deviceInterfaceTreeNodeData = (DeviceInterfaceTreeNodeData) data;

                  final DeviceInterface deviceInterface = deviceInterfaceTreeNodeData.getDeviceInterface();

                  this.deviceTreeContext.setDeviceInterface(deviceInterface);

              } else if (IpAddressTreeNodeData.class.isInstance(data))

              {

                  final IpAddressTreeNodeData ipAddressTreeNodeData = (IpAddressTreeNodeData) data;

                  final IpAddress ipAddress = ipAddressTreeNodeData.getIpAddress();

                  this.deviceTreeContext.setIpAddress(ipAddress);

              } else if (FqdnTreeNodeData.class.isInstance(data))

              {

                  final FqdnTreeNodeData fqdnTreeNodeData = (FqdnTreeNodeData) data;

                  final Fqdn fqdn = fqdnTreeNodeData.getFqdn();

                  this.deviceTreeContext.setFqdn(fqdn);

              } else if (AliasFqdnTreeNodeData.class.isInstance(data))

              {

                  final AliasFqdnTreeNodeData aliasFqdnTreeNodeData = (AliasFqdnTreeNodeData) data;

                  final Fqdn aliasFqdn = aliasFqdnTreeNodeData.getAliasFqdn();

                  if (aliasLevel == 0)

                  {

                      this.deviceTreeContext.setAliasFqdn(aliasFqdn);

                  }

                  aliasLevel++;

              }

       

              final TreeNode<?> parentTreeNode = treeNode.getParent();

              setSelectedData(parentTreeNode, aliasLevel);

          }

       

          private void notifyDataSelectedListeners()

          {

              final DataSelectedEvent event = new DataSelectedEvent(this, this.deviceTreeContext.getDevice(),

                      this.deviceTreeContext.getDeviceInterface(), this.deviceTreeContext.getIpAddress(),

                      this.deviceTreeContext.getFqdn(), this.deviceTreeContext.getAliasFqdn());

       

              this.dataSelectedSource.notifyDataSelectedListeners(event);

          }

       

          public void onRefresh()

          {

              logger.debug("onRefresh()");

              refresh();

          }

       

          private void refresh()

          {

              logger.debug("refresh()");

              final Long deviceId = getDeviceId();

              setDeviceId(deviceId);

              this.deviceTreeContextMenuBean.reset();

          }

       

          synchronized public void onChangeExpand(final TreeToggleEvent event)

          {

              logger.debug("onChangeExpand()");

          }

       

          public void onExpandAll()

          {

              logger.debug("onExpandAll()");

              this.deviceTree.queueExpandAll();

          }

       

          public void onCollapseAll()

          {

              logger.debug("onCollapseAll()");

              final Device device = this.deviceTreeContext.getDevice();

              this.deviceTreeContext.reset();

              this.deviceTreeContext.setDevice(device);

              this.deviceTree.queueCollapseAll();

          }

       

          private class SearchDataVisitor implements DataVisitor

          {

              ListRowKey<String> foundRowKey;

       

              public ListRowKey<String> getFoundRowKey()

              {

                  return this.foundRowKey;

              }

       

              public void process(final javax.faces.context.FacesContext context, final java.lang.Object rowKey,

                      final java.lang.Object argument) throws java.io.IOException

              {

       

                  // Check whether a match was already found.

                  if (this.foundRowKey != null)

                  {

                      return;

                  }

       

                  final Object data = DeviceTreeBean.this.deviceTree.getRowData(rowKey);

                  logger.debug("SearchDataVisitor.process(): data=" + data + ", rowKey=" + rowKey);

       

                  final String targetString = data.toString();

                  final String searchString = (String) argument;

       

                  if (targetString == null)

                  {

                      // Do nothing.

                  } else if (targetString.toLowerCase().startsWith(searchString.trim().toLowerCase()))

                  {

                      expandNode(rowKey);

                  }

              }

       

              @SuppressWarnings("unchecked")

              private void expandNode(final java.lang.Object rowKey) throws java.io.IOException

              {

                  this.foundRowKey = (ListRowKey<String>) rowKey;

       

                  final String path = this.foundRowKey.getPath();

                  final int depth = this.foundRowKey.depth();

                  logger.debug("expandNode(): path=" + path + ", depth=" + depth);

       

                  String ancestorsKeyString = "";

                  for (int i = 0; i < depth - 1; ++i)

                  {

                      final String keyString = ancestorsKeyString + this.foundRowKey.get(i);

                      ancestorsKeyString = keyString + ":";

                      final TreeRowKey<String> treeRowKey = toRowKey(keyString);

                      DeviceTreeBean.this.deviceTree.queueNodeExpand(treeRowKey);

                  }

              }

       

          }

       

          @SuppressWarnings("unchecked")

          synchronized public void onSearch()

          {

              final String searchString = this.deviceTreeContext.getSearchString();

              logger.debug("onSearch(): searchString=" + searchString);

       

              final SearchDataVisitor dataVisitor = new SearchDataVisitor();

       

              final Range range = new TreeRange()

              {

       

                  public boolean processChildren(final TreeRowKey rowKey)

                  {

                      return true;

                  }

       

                  public boolean processNode(final TreeRowKey rowKey)

                  {

                      return true;

                  }

       

              };

       

              try

              {

                  this.deviceTree.walkModel(FacesContext.getCurrentInstance(), dataVisitor, range, null, searchString);

       

                  final ListRowKey<String> foundRowKey = dataVisitor.getFoundRowKey();

                  if (foundRowKey != null)

                  {

                      final TreeNodeState state = (TreeNodeState) this.deviceTree.getComponentState();

                      final TreeRowKey<String> oldSelectedRowKey = state.getSelectedNode();

                      logger.debug("onSearch(): oldSelectedRowKey=" + oldSelectedRowKey);

                      state.setSelected(foundRowKey);

       

                      final TreeSelectionChangeEvent nodeSelectedEvent = new TreeSelectionChangeEvent(this.deviceTree, oldSelectedRowKey);

                      onSelect(nodeSelectedEvent);

       

                      logger.debug("onSearch(): newSelectedNodeKey=" + state.getSelectedNode());

                  } else

                  {

                      final String summary = "Could not find element";

                      final String detail = summary + " " + searchString;

                      FacesContext.getCurrentInstance().addMessage(null,

                              new FacesMessage(FacesMessage.SEVERITY_INFO, summary, detail));

                  }

              } catch (final IOException e)

              {

                  logger.debug("Caught walkModel exception", e);

              }

       

              logger.debug("onSearch(): end");

          }

       

          private TreeRowKey<String> toRowKey(final String keyString)

          {

              final String[] keyArray = ListRowKey.fromString(keyString);

              final List<String> keyList = new ArrayList<String>();

              for (int i = 0; i < keyArray.length; ++i)

              {

                  keyList.add(keyArray[i]);

              }

              final TreeRowKey<String> treeRowKey = new ListRowKey<String>(keyList);

              return treeRowKey;

          }

       

          public void onSelectSearchResult(final ActionEvent event)

          {

              logger.debug("onSelectSearchResult(ActionEvent)");

              final UIExtendedDataTable table = (UIExtendedDataTable) event.getComponent().getParent();

              if (table != null)

              {

                  try

                  {

                      final DeviceSummaryView deviceSummaryView = (DeviceSummaryView) table.getRowData();

                      final Object rowKey = table.getRowKey();

                      if (Integer.class.isInstance(rowKey))

                      {

                          this.deviceSummaryViewId = deviceSummaryView.getId();

       

                      } else if (DeviceSummaryViewId.class.isInstance(rowKey))

                      {

                          this.deviceSummaryViewId = (DeviceSummaryViewId) rowKey;

                      } else

                      {

                          throw new ViewException("Unsupported row key type " + rowKey);

                      }

       

                      final String fqdnName = deviceSummaryView.getName();

                      final String domainName = deviceSummaryView.getDomainName();

                      if ((fqdnName != null) && (domainName != null))

                      {

                          String searchString = fqdnName + "." + domainName;

                          final String namespaceName = deviceSummaryView.getNamespace();

                          if (namespaceName != null)

                          {

                              if (!"Boeing Intranet".equals(namespaceName))

                              {

                                  searchString = searchString + " (" + namespaceName + ")";

                              }

                          }

                          this.deviceTreeContext.setSearchString(searchString);

                      }

       

                      this.filteredDeviceInterfaceIds = new ArrayList<Long>();

                      if (isFilterByDeviceInterface())

                      {

                          if (this.deviceSummaryViewId.getInterfaceId() != 0)

                          {

                              this.filteredDeviceInterfaceIds.add(this.deviceSummaryViewId.getInterfaceId());

                          }

                      }

       

                      if (this.deviceSummaryViewId.getDeviceId() != 0)

                      {

                          setDeviceId(this.deviceSummaryViewId.getDeviceId());

                      }

                  } catch (final Exception e)

                  {

                      final String summary = "Select device failed";

                      final String detail = summary + " " + e.getMessage();

                      logger.error(detail, e);

                      FacesContext.getCurrentInstance().addMessage(null,

                              new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, detail));

                  }

              }

          }

       

          public String onSelectSearchResult()

          {

              logger.debug("onSelectSearchResult()");

              if (this.deviceSummaryViewId.getDeviceId() == 0)

              {

                  final String summary = "Warning: Reserved IP addresses have no associated device information.";

                  final String detail = null;

                  FacesContext.getCurrentInstance().addMessage(null,

                          new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, detail));

                  return "failed";

              } else

              {

                  return "success";

              }

          }

       

          public void onToDeviceTree(final ActionEvent event)

          {

              logger.debug("onToDeviceTree(ActionEvent)");

              final UIComponent component = event.getComponent();

              final Map<String, Object> attributes = component.getAttributes();

              final Long newDeviceId = (Long) attributes.get("deviceId");

              logger.debug("onToDeviceTree(ActionEvent): newDeviceId=" + newDeviceId + ", newDeviceId.className="

                      + newDeviceId.getClass().getName());

              this.filteredDeviceInterfaceIds = new ArrayList<Long>();

              setDeviceId(newDeviceId);

          }

       

          public String onToDeviceTree()

          {

              logger.debug("onToDeviceTree()");

              return "success";

          }

       

      }

       

      Thanks for your time.

      RaoV