ManagedAttributeModel.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.model;
022 
023 import java.util.ArrayList;
024 import java.util.HashMap;
025 import java.util.List;
026 
027 public class ManagedAttributeModel
028 {
029     HashMap<String, AttributeData> _attributeMap = new HashMap<String, AttributeData>();
030     
031     public void setAttributeValue(String name, Object value)
032     {
033         if (value == null)
034             return;
035         
036         AttributeData data = null;
037         String dataType = value.getClass().getName();
038         if (_attributeMap.containsKey(name))
039         {
040             data = _attributeMap.get(name);
041             data.setValue(value);
042         }
043         else
044         {
045             data = new AttributeData();
046             data.setName(name);
047             data.setValue(value);
048             _attributeMap.put(name, data);
049         }
050         data.setDataType(dataType);
051     }
052     
053     
054     public void setAttributeDescription(String name, String value)
055     {
056         if (_attributeMap.containsKey(name))
057         {
058             _attributeMap.get(name).setDescription(value);
059         }
060         else
061         {
062             AttributeData data = new AttributeData();
063             data.setName(name);
064             data.setDescription(value);
065             _attributeMap.put(name, data);
066         }
067     }
068     
069     public void setAttributeReadable(String name, boolean readable)
070     {
071         if (_attributeMap.containsKey(name))
072         {
073             _attributeMap.get(name).setReadable(readable);
074         }
075         else
076         {
077             AttributeData data = new AttributeData();
078             data.setName(name);
079             data.setReadable(readable);
080             _attributeMap.put(name, data);
081         }
082     }
083     
084     public void setAttributeWritable(String name, boolean writable)
085     {
086         if (_attributeMap.containsKey(name))
087         {
088             _attributeMap.get(name).setWritable(writable);
089         }
090         else
091         {
092             AttributeData data = new AttributeData();
093             data.setName(name);
094             data.setWritable(writable);
095             _attributeMap.put(name, data);
096         }
097     }
098     
099     public List<String> getAttributeNames()
100     {
101         return new ArrayList<String>(_attributeMap.keySet());
102     }
103     
104     public AttributeData[] getAttributes()
105     {
106         return _attributeMap.values().toArray(new AttributeData[0]);
107     }
108     
109     public AttributeData getAttribute(String name)
110     {
111         return _attributeMap.get(name);
112     }
113     
114     public int getCount()
115     {
116         return _attributeMap.size();
117     }
118 }