TreeObject.java
001 /*
002  *
003  * Licensed to the Apache Software Foundation (ASF) under one
004  * or more contributor license agreements.  See the NOTICE file
005  * distributed with this work for additional information
006  * regarding copyright ownership.  The ASF licenses this file
007  * to you under the Apache License, Version 2.0 (the
008  * "License"); you may not use this file except in compliance
009  * with the License.  You may obtain a copy of the License at
010  
011  *   http://www.apache.org/licenses/LICENSE-2.0
012  
013  * Unless required by applicable law or agreed to in writing,
014  * software distributed under the License is distributed on an
015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016  * KIND, either express or implied.  See the License for the
017  * specific language governing permissions and limitations
018  * under the License.
019  *
020  */
021 package org.apache.qpid.management.ui.views;
022 
023 import java.util.ArrayList;
024 import java.util.List;
025 
026 import org.apache.qpid.management.ui.Constants;
027 import org.apache.qpid.management.ui.ManagedBean;
028 import org.apache.qpid.management.ui.ManagedObject;
029 
030 public class TreeObject
031 {
032     private String _name;
033     private String _type;
034     private String _virtualHost;
035     private TreeObject _parent;
036     private List<TreeObject> _children = new ArrayList<TreeObject>();
037     private ManagedObject _object;
038     
039     public TreeObject(String name, String type)
040     {
041        this._name = name;
042        this._type = type;
043     }
044     
045     public TreeObject(ManagedObject obj)
046     {
047         _name = obj.getName();
048         if (_name == null && (obj instanceof ManagedBean))
049         {
050             String[] types = ((ManagedBean)obj).getType().split("\\.");
051             _name = types[types.length - 1];
052         }
053         this._type = Constants.MBEAN;
054         this._object = obj;
055     }
056     
057     public void addChild(TreeObject child)
058     {
059         _children.add(child);
060     }
061     
062     public void addChildren(List<TreeObject> subList)
063     {
064         _children.addAll(subList);
065     }
066     
067     public List<TreeObject> getChildren()
068     {
069         return _children;
070     }
071     
072     public void setChildren(List<TreeObject> children)
073     {
074         this._children = children;
075     }
076     
077     public void setName(String value)
078     {
079         _name = value;
080     }
081     
082     public String getName()
083     {
084         return _name;
085     }
086     public String getType()
087     {
088         return _type;
089     }
090     
091     public String getVirtualHost()
092     {
093         // To make it work with the broker with no virtual host implementation
094         return _virtualHost == null ? Constants.DEFAULT_VH : _virtualHost;
095     }
096     
097     public void setVirtualHost(String vHost)
098     {
099         _virtualHost = vHost;
100     }
101 
102     public ManagedObject getManagedObject()
103     {
104         return _object;
105     }
106 
107     public void setManagedObject(ManagedObject obj)
108     {
109         this._object = obj;
110     }
111     
112     public TreeObject getParent()
113     {
114         return _parent;
115     }
116     
117     public void setParent(TreeObject parent)
118     {
119         this._parent = parent;
120         
121         if (parent != null)
122         {
123             parent.addChild(this);
124         }
125     }
126 }