[jboss-cvs] JBossAS SVN: r111754 - in branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp: config/attribute and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 13 14:15:26 EDT 2011


Author: thauser at redhat.com
Date: 2011-07-13 14:15:25 -0400 (Wed, 13 Jul 2011)
New Revision: 111754

Added:
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/AttributeTableMapper.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/exceptions/
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/exceptions/NotEnoughInformationException.java
Modified:
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/AttributeMappingsBinding.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/BindEntry.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TableMapper.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MappedAttribute.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Generator.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/MIBGenerator.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Parser.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/MappedAttribute.java
Log:
refactoring and improvements, especially to error handling.


Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/AttributeMappingsBinding.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/AttributeMappingsBinding.java	2011-07-13 15:43:24 UTC (rev 111753)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/AttributeMappingsBinding.java	2011-07-13 18:15:25 UTC (rev 111754)
@@ -112,9 +112,11 @@
 			String oid = attrs.getValue("oid");
 			String name = attrs.getValue("name");
 			String mode = attrs.getValue("mode");
+			String table = attrs.getValue("table");
 			attribute = new MappedAttribute();		
             attribute.setMode(mode);
 			attribute.setName(name);
+			attribute.setTable(table);
 			attribute.setOid(oid);
 		}
 		return attribute;

Added: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/AttributeTableMapper.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/AttributeTableMapper.java	                        (rev 0)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/AttributeTableMapper.java	2011-07-13 18:15:25 UTC (rev 111754)
@@ -0,0 +1,343 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jmx.adaptor.snmp.agent;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.jboss.jmx.adaptor.snmp.config.attribute.ManagedBean;
+import org.jboss.jmx.adaptor.snmp.config.attribute.MappedAttribute;
+import org.jboss.logging.Logger;
+import org.snmp4j.smi.OID;
+import org.snmp4j.smi.OctetString;
+import org.snmp4j.smi.Variable;
+
+/**
+ * @author jean.deruelle at gmail.com
+ * 
+ */
+public class AttributeTableMapper {
+
+	private SortedSet<OID> tables = new TreeSet<OID>();
+//	private SortedSet<OID> tableRowEntrys = new TreeSet<OID>();
+	/**
+	 * keep an index of the OID from attributes.xml
+	 */	
+	private SortedMap<OID, BindEntry> tableMappings = new TreeMap<OID, BindEntry>();
+//	private SortedMap<OID, BindEntry> tableRowEntryMappings = new TreeMap<OID, BindEntry>();
+
+	private MBeanServer server;
+	private Logger log;
+
+	public AttributeTableMapper(MBeanServer server, Logger log) {
+		this.server = server;
+		this.log = log;
+	}
+	
+	/**
+	 * 
+	 * @param oid
+	 * @return
+	 */
+	public BindEntry getTableBinding(OID oid, boolean isRowEntry) {
+		Set<Entry<OID,BindEntry>> entries = null;
+//		if(isRowEntry) {
+//			entries = tableRowEntryMappings.entrySet();
+//		} else {
+			entries = tableMappings.entrySet();
+//		}
+		for (Entry<OID,BindEntry> entry : entries) {			
+			if (oid.startsWith(entry.getKey())) {
+				BindEntry value = entry.getValue();
+				BindEntry bindEntry = (BindEntry) value.clone();
+				int[] oidValue = oid.getValue();
+				int[] subOid = new int[oid.size() - entry.getKey().size()];
+				System.arraycopy(oidValue, entry.getKey().size(), subOid, 0, oid.size() - entry.getKey().size());
+				if(subOid.length > 0) {
+					bindEntry.setTableIndexOID(new OID(subOid));
+				}
+				return bindEntry;
+			}			
+		}
+		return null;
+	}
+	
+	public OID getNextTable(OID oid) {
+		OID currentOID = oid;
+		// means that the oid is the one from the table itself
+		boolean isRowEntry = false;
+		if(tables.contains(oid)) {
+			currentOID = oid.append(1);
+		}
+//		if(tableRowEntrys.contains(currentOID)) {
+//			currentOID = oid.append(1);
+//			isRowEntry = true;
+//		}
+		BindEntry be = getTableBinding(currentOID, isRowEntry);
+//		if(be == null) {
+//			be = getTableBinding(currentOID, true);
+//			isRowEntry = true;
+//		}
+		if(be == null) {
+			return null; // it's not there
+		}
+		Object val = null;
+		try {
+			val = server.getAttribute(be.getMbean(), be.getAttr().getName());
+		} catch(Exception e) {
+			log.error("Impossible to fetch " + be.getAttr().getName());
+			return null;
+		}
+		OID tableIndexOID = be.getTableIndexOID();
+		if(tableIndexOID == null) {
+			if(val instanceof Map) {
+				Set<Object> keySet = ((Map)val).keySet();
+				if(keySet.size() > 0) {
+					return new OID(currentOID.append("'" + keySet.iterator().next().toString() + "'"));
+				} else {
+					return null;
+				}
+			} else {
+				return new OID(currentOID).append(1);
+			}			
+		}		
+		if(val instanceof List) {
+			int index = Integer.valueOf(tableIndexOID.toString());
+			if(index - 1 < 0) {
+				return null;
+			}
+			index++;
+			if(index <= ((List)val).size()) { 
+				return new OID(currentOID.trim().append(index));
+			} else {
+//				if(isRowEntry) {
+//					return new OID(currentOID.trim().trim().append(2).append(1));
+//				} else {
+					return null;
+//				}
+			}
+		}
+		if(val instanceof Map) {	
+//			if(tableIndexOID.size() <= 1) {
+//				int index = Integer.valueOf(tableIndexOID.toString());
+//				if(index - 1 < 0) {
+//					return null;
+//				}
+//				index++;
+//				if(index <= ((Map)val).size()) { 
+//					return new OID(currentOID.trim().append(index));
+//				} else {
+//					Set<Object> keySet = ((Map)val).keySet();
+//					if(keySet.size() > 0) {
+//						return new OID(currentOID.trim().trim().append(2).append("'" + keySet.iterator().next().toString() + "'"));
+//					} else {
+//						return null;
+//					}
+//				}
+//		} else {
+				String key = new String(tableIndexOID.toByteArray());
+				Iterator<Object> keySet = ((Map)val).keySet().iterator();
+				while (keySet.hasNext()) {
+					Object entryKey = keySet.next();
+					if(entryKey.equals(key)) {
+						if(keySet.hasNext()) {
+							Object nextKey = keySet.next();
+							OID nextOID = new OID(currentOID);
+							nextOID.trim(tableIndexOID.size());
+							nextOID.append("'" + nextKey + "'");
+							return nextOID;
+						} else {
+							return null;
+						}
+					}
+				}
+				return null;
+//			}			
+		}
+		if (val instanceof int[]) {
+			int index = Integer.valueOf(tableIndexOID.toString());
+			if(index - 1 < 0) {
+				return null;
+			}
+			index++;
+			if(index <= ((int[])val).length) { 
+				return new OID(currentOID.trim().append(index));
+			} else {
+				if(isRowEntry) {
+					return new OID(currentOID.trim().trim().append(2).append(1));
+				} else {
+					return null;
+				}
+			}
+		}
+		if (val instanceof long[]) {
+			int index = Integer.valueOf(tableIndexOID.toString());
+			if(index - 1 < 0) {
+				return null;
+			}
+			index++;
+			if(index <= ((long[])val).length) { 
+				return new OID(currentOID.trim().append(index));
+			} else {
+				if(isRowEntry) {
+					return new OID(currentOID.trim().trim().append(2).append(1));
+				} else {
+					return null;
+				}
+			}
+		}
+		if (val instanceof boolean[]) {
+			int index = Integer.valueOf(tableIndexOID.toString());
+			if(index - 1 < 0) {
+				return null;
+			}
+			index++;
+			if(index <= ((boolean[])val).length) { 
+				return new OID(currentOID.trim().append(index));
+			} else {
+				if(isRowEntry) {
+					return new OID(currentOID.trim().trim().append(2).append(1));
+				} else {
+					return null;
+				}
+			}
+		}
+		if (val instanceof Object[]) {
+			int index = Integer.valueOf(tableIndexOID.toString());
+			if(index - 1 < 0) {
+				return null;
+			}
+			index++;
+			if(index <= ((Object[])val).length) { 
+				return new OID(currentOID.trim().append(index));
+			} else {
+				if(isRowEntry) {
+					return new OID(currentOID.trim().trim().append(2).append(1));
+				} else {
+					return null;
+				}
+			}
+		}
+		return null;
+	}	
+
+	/**
+	 * 
+	 * @param mmb
+	 * @param oname
+	 */
+	public void addTableMapping(ManagedBean mmb, MappedAttribute ma) {
+		String oid;
+		String oidPrefix = mmb.getOidPrefix();
+		if (oidPrefix != null) {
+			oid = oidPrefix + ma.getOid();
+		} else {
+			oid = ma.getOid();
+		}
+		OID coid = new OID(oid);
+		BindEntry be = new BindEntry(coid, mmb.getName(), ma.getName());
+		be.setReadWrite(ma.isReadWrite());
+		be.setTable(ma.isAttributeTable());
+
+		if (log.isTraceEnabled())
+			log.trace("New bind entry   " + be);
+		if (tables.contains(coid)) {
+			log.info("Duplicate oid " + coid + RequestHandlerImpl.SKIP_ENTRY);
+		}
+		if (mmb == null || mmb.equals("")) {
+			log.info("Invalid mbean name for oid " + coid + RequestHandlerImpl.SKIP_ENTRY);
+		}
+		if (ma == null || ma.equals("")) {
+			log.info("Invalid attribute name " + ma + " for oid " + coid
+					+ RequestHandlerImpl.SKIP_ENTRY);
+		}
+//		tableRowEntrys.add(coid);
+		tables.add(coid.trim());
+//		tableRowEntryMappings.put(new OID(coid).append(1), be);
+		tableMappings.put(new OID(coid), be);	
+//		tableMappings.put(new OID(coid.trim()), be);
+	}
+
+	public boolean belongsToTables(OID oid) {
+		for (OID attributeOID : tables) {			
+			if (oid.startsWith(attributeOID)) {
+				return true;
+			}			
+		}
+		return false;
+	}
+
+	public void removeTableMapping(ManagedBean mmb, MappedAttribute ma) {
+		
+	}
+
+	public Variable getIndexValue(OID oid) {
+		BindEntry be = getTableBinding(oid, true);
+		Object val = null;
+		if(be == null) {
+			return null;
+		}
+		try {
+			val = server.getAttribute(be.getMbean(), be.getAttr().getName());
+		} catch(Exception e) {
+			log.error("Impossible to fetch " + be.getAttr().getName());
+			return null;
+		}
+		OID tableIndexOID = be.getTableIndexOID();
+		if(val instanceof List) {			
+			return new OctetString("" + oid.get(oid.size()-1));
+		}
+		if(val instanceof Map) {	
+			int index = oid.get(oid.size()-1);
+			int i = 1;
+			for(Object key : ((Map) val).keySet()) {
+				if(i == index) {
+					return new OctetString((String)key);
+				}
+				i++;
+			}			
+		}
+		if (val instanceof int[]) {
+			return new OctetString("" + oid.get(oid.size()-1));
+		}
+		if (val instanceof long[]) {
+			return new OctetString("" + oid.get(oid.size()-1));
+		}
+		if (val instanceof boolean[]) {
+			return new OctetString("" + oid.get(oid.size()-1));
+		}
+		if (val instanceof Object[]) {
+			return new OctetString("" + oid.get(oid.size()-1));
+		}
+		return null;
+	}
+}

Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/BindEntry.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/BindEntry.java	2011-07-13 15:43:24 UTC (rev 111753)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/BindEntry.java	2011-07-13 18:15:25 UTC (rev 111754)
@@ -43,6 +43,8 @@
 	private String mName;
 	private String aName;
 	private boolean isReadWrite = false;
+	private boolean isTable = false;
+	private OID tableIndexOID;
 
 	/**
 	 * Constructs a new BindEntry
@@ -54,9 +56,9 @@
 	 * @param attrName
 	 *            The name of the attribute to query
 	 */
-	BindEntry(final String oidString, final String mbName, final String attrName) {
-		this(new OID(oidString), mbName, attrName);
-	}
+//	BindEntry(final String oidString, final String mbName, final String attrName) {
+//		this(new OID(oidString), mbName, attrName);
+//	}
 
 	/**
 	 * Constructs a new BindEntry.
@@ -92,6 +94,7 @@
 		buf.append(oid).append(", mbean=");
 		buf.append(mName).append(", attr=");
 		buf.append(aName).append(", rw=");
+		buf.append(", table=").append(isTable());
 		buf.append(isReadWrite()).append("]");
 
 		return buf.toString();
@@ -163,4 +166,40 @@
 		this.attr = attr;
 	}
 
+	/**
+	 * @param isTable the isTable to set
+	 */
+	public void setTable(boolean isTable) {
+		this.isTable = isTable;
+	}
+
+	/**
+	 * @return the isTable
+	 */
+	public boolean isTable() {
+		return isTable;
+	}
+
+	/**
+	 * @param tableIndexOID the tableIndexOID to set
+	 */
+	public void setTableIndexOID(OID tableIndexOID) {
+		this.tableIndexOID = tableIndexOID;
+	}
+
+	/**
+	 * @return the tableIndexOID
+	 */
+	public OID getTableIndexOID() {
+		return tableIndexOID;
+	}
+
+	protected BindEntry clone(){
+		BindEntry bindEntry = new BindEntry(oid, mName, aName);
+		bindEntry.setAttr(attr);
+		bindEntry.setMbean(mbean);
+		bindEntry.setReadWrite(isReadWrite);
+		bindEntry.setTable(isTable);
+		return bindEntry;
+	}
 }

Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java	2011-07-13 15:43:24 UTC (rev 111753)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java	2011-07-13 18:15:25 UTC (rev 111754)
@@ -23,11 +23,10 @@
 
 import java.io.InputStream;
 import java.net.InetAddress;
-import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
+import java.util.Map;
 import java.util.SortedMap;
 import java.util.SortedSet;
 import java.util.TreeMap;
@@ -84,9 +83,10 @@
 	private SortedSet<OID> oidKeys = null;
 	
 	/** keep track of the objects created */
-	private SortedSet<OID> objectKeys = null;
+//	private SortedSet<OID> objectKeys = null;
 	
 	private TableMapper tableMapper = null;
+	private AttributeTableMapper attributeTableMapper = null;
 	
 	/** Has this RequestHandler instance been initialized? */
 	private boolean initialized = false;
@@ -99,8 +99,8 @@
 	public RequestHandlerImpl() 
 	{
 		bindings = new TreeMap<OID, BindEntry>();
-		oidKeys = new TreeSet<OID>();
-		objectKeys = new TreeSet<OID>();
+		oidKeys = new TreeSet<OID>();		
+//		objectKeys = new TreeSet<OID>();
 	}
 
 	// RequestHandler Implementation ---------------------------------
@@ -119,6 +119,7 @@
       log.debug("initialize() with res=" + resourceName);
 	   super.initialize(resourceName, server, log, uptime);
 	   tableMapper = new TableMapper(server, log);
+	   attributeTableMapper = new AttributeTableMapper(server, log);
 		if (resourceName != null)
 			initializeBindings();
 		else
@@ -354,8 +355,7 @@
 			}
 			else {
 				newVB = new VariableBinding(oid);
-				var = null;
-				//TODO will be called for each get, not performing well, to be optimized
+				var = null;				
 				tableMapper.checkTables(oid);
 				// check the existence of the object for the requested instance
 				// the object is the OID with the last number removed.
@@ -434,7 +434,6 @@
 			VariableBinding newVB = new VariableBinding(oid,newVal);
 			
 			try{
-				//TODO will be called for each set, not performing well, to be optimized
 				tableMapper.checkTables(oid);
 				oldVar = getValueFor(oid);
 				modified.add(new VariableBinding(oid, oldVar)); // keep a record of the old variable binding.
@@ -449,19 +448,19 @@
 				}
 			}
 			catch (NoSuchInstanceException e){
-				log.error("snmpReceivedSet: attempt to set a non-existent instance: " + oid.last() + " of object: " + oid.trim(), e);
+				log.info("snmpReceivedSet: attempt to set a non-existent instance: " + oid.last() + " of object: " + oid.trim(), e);
 				undoSets(modified);
 				makeErrorPdu(response, pdu, errorIndex, PDU.noCreation);
 				return response;
 			}
 			catch (VariableTypeException e){
-				log.error("snmpReceievedSet: could not convert the given value into an appropriate type: " +newVal, e);
+				log.info("snmpReceievedSet: could not convert the given value into an appropriate type: " +newVal, e);
 				undoSets(modified);
 				makeErrorPdu(response, pdu, errorIndex, PDU.wrongType);
 				return response;
 			}
 			catch (ReadOnlyException e){
-				log.error("snmpReceivedSet: attempt to set a read-only attribute: " + newVB, e);
+				log.info("snmpReceivedSet: attempt to set a read-only attribute: " + newVB, e);
 				undoSets(modified);
 				makeErrorPdu(response, pdu, errorIndex, PDU.notWritable);
 				return response;
@@ -653,13 +652,19 @@
 					String oid;
 					if (oidPrefix != null) {
 						oid = oidPrefix + ma.getOid();
-						addObjectEntry(new OID(oidPrefix));
+//							addObjectEntry(new OID(oidPrefix));
 					} else {
 						oid = ma.getOid();
-						OID objectOID = new OID(oid);
-						addObjectEntry(objectOID.trim());
+//							OID objectOID = new OID(oid);
+//							addObjectEntry(objectOID.trim());
 					}
-					addBindEntry(oid, mmb.getName(), ma.getName(), ma.isReadWrite());
+					if(ma.isAttributeTable()) {
+						attributeTableMapper.addTableMapping(mmb, ma);
+						oidKeys.add(new OID(oid));
+					} else {
+						oid = oid + ".0";
+						addBindEntry(oid, mmb.getName(), ma.getName(), ma.isReadWrite());
+					}
 				}
 			}
 		}
@@ -687,16 +692,21 @@
 					String oid;
 					if (oidPrefix != null) {
 						oid = oidPrefix + ma.getOid();
-						objectKeys.remove(new OID(oidPrefix));
+//							addObjectEntry(new OID(oidPrefix));
 					} else {
 						oid = ma.getOid();
-						OID objectOID = new OID(oid);
-						objectKeys.remove(objectOID.trim());
+//							OID objectOID = new OID(oid);
+//							addObjectEntry(objectOID.trim());
 					}
-					OID coid = new OID(oid);
-					oidKeys.remove(coid);
-					bindings.remove(coid);
-	
+					if(ma.isAttributeTable()) {
+						attributeTableMapper.removeTableMapping(mmb, ma);
+						oidKeys.remove(new OID(oid));
+					} else {
+						oid = oid + ".0";
+						OID coid = new OID(oid);
+						oidKeys.remove(coid);
+						bindings.remove(coid);
+					}
 				}
  			}
 		}
@@ -706,15 +716,15 @@
 	 * @param String representation of the OID to add. 
 	 * 
 	 * **/
-	private void addObjectEntry(OID oid){
-		if (objectKeys.contains(oid))
-			log.debug("duplicate object " + oid + SKIP_ENTRY);
-		
-		if (oid == null)
-			log.debug("null oid for object");
-		objectKeys.add(oid);
-				
-	}
+//	private void addObjectEntry(OID oid){
+//		if (objectKeys.contains(oid))
+//			log.debug("duplicate object " + oid + SKIP_ENTRY);
+//		
+//		if (oid == null)
+//			log.debug("null oid for object");
+//		objectKeys.add(oid);
+//				
+//	}
 	
 	/** 
 	 * 
@@ -724,10 +734,10 @@
 	 * @param rw indicates whether this Attribute is read-write or not (readonly if false)
 	 */
 	private void addBindEntry(String oid, String mmb, String ma, boolean rw){
-	  BindEntry be = new BindEntry(oid, mmb, ma);
+	  OID coid = new OID(oid);
+	  BindEntry be = new BindEntry(coid, mmb, ma);
 	  be.setReadWrite(rw);
-	  
-	  OID coid = new OID(oid);
+	  	  
 	  if (log.isTraceEnabled())
 		  log.trace("New bind entry   " + be);
 	  if (bindings.containsKey(coid)) {
@@ -758,11 +768,14 @@
 	 */
 	
 	private boolean checkObject(final OID oid) {
-		OID coid = oid.trim(); 
-		boolean exists = objectKeys.contains(coid);
+//		OID coid = oid; 
+		boolean exists = bindings.get(oid) != null;
 		if(!exists) {
 			//needed for table
 			exists = tableMapper.belongsToTable(oid);
+			if(!exists) {
+				exists = attributeTableMapper.belongsToTables(oid);
+			}
 		}
 		return exists;
 	}	
@@ -784,7 +797,11 @@
         
 			try {
 			   Object val = server.getAttribute(be.getMbean(), be.getAttr().getName());
-			   ssy = prepForPdu(val);
+			   OID tableIndexOID = null;
+			   if(be.isTable()) {
+				    tableIndexOID = be.getTableIndexOID();				   
+			   } 
+			   ssy = prepForPdu(val, tableIndexOID);
 			} catch (VariableTypeException e){
 				log.debug("getValueFor: didn't find a suitable data type for the requested data");
 				throw e;
@@ -792,7 +809,15 @@
 					log.warn("getValueFor: (" + be.getMbean().toString() + ", "
 							+ be.getAttr().getName() + ": " + e.toString());
 	        }
-		} else {		
+		} else {
+			ssy = tableMapper.getObjectNameIndexValue(oid);
+			if(ssy != null) {
+				return ssy;
+			}
+			ssy = attributeTableMapper.getIndexValue(oid);
+			if(ssy != null) {
+				return ssy;
+			}
 			log.debug("getValueFor: " + NO_ENTRY_FOUND_FOR_OID + oid);
 			throw new NoSuchInstanceException();
 		}
@@ -811,30 +836,101 @@
 	 * 
 	 */
 	
-	private Variable prepForPdu(final Object val) throws VariableTypeException{
+	public static Variable prepForPdu(final Object val, final OID tableIndexOID) throws VariableTypeException{
 		Variable result = null;
+		Object value = val;
+		if(val == null) {
+			return new Null();
+		}
 		//TODO: all types managed by the PDU
-		if(val == null) {
-			result = new Null();
-		} else if (val instanceof Long) {
-			result = new OctetString(((Long)val).toString());
-		} else if (val instanceof Boolean) {
-			if(((Boolean)val).booleanValue())
+		
+		// manage arrays and lists
+		if(tableIndexOID != null) {						
+			if(val instanceof List) {
+				int index = Integer.valueOf(tableIndexOID.toString()) - 1;
+				if(index < 0) {
+					return Null.noSuchObject;
+				}
+				if(index < ((List)val).size()) { 
+					value = ((List)val).get(index);
+				} else {
+					return Null.noSuchObject;
+				}
+			}
+			if(val instanceof Map) {
+				String key = new String(tableIndexOID.toByteArray());
+				value = ((Map)val).get(key);
+				if(value == null) { 
+					return Null.noSuchObject;
+				}
+			}
+			if (value instanceof int[]) {
+				int index = Integer.valueOf(tableIndexOID.toString()) - 1;
+				if(index < 0) {
+					return Null.noSuchObject;
+				}
+				if(index < ((int[])val).length) { 
+					value = ((int[])val)[index];
+				} else {
+					return Null.noSuchObject;
+				}
+			}
+			if (value instanceof long[]) {
+				int index = Integer.valueOf(tableIndexOID.toString()) - 1;
+				if(index < 0) {
+					return Null.noSuchObject;
+				}
+				if(index < ((long[])val).length) { 
+					value = ((long[])val)[index];
+				} else {
+					return Null.noSuchObject;
+				}
+			}
+			if (value instanceof boolean[]) {
+				int index = Integer.valueOf(tableIndexOID.toString()) - 1;
+				if(index < 0) {
+					return Null.noSuchObject;
+				}
+				if(index < ((boolean[])val).length) { 
+					value = ((boolean[])val)[index];
+				} else {
+					return Null.noSuchObject;
+				}
+			}
+			if (value instanceof Object[]) {
+				int index = Integer.valueOf(tableIndexOID.toString()) - 1;
+				if(index < 0) {
+					return Null.noSuchObject;
+				}
+				if(index < ((Object[])val).length) { 
+					value = ((Object[])val)[index];
+				} else {
+					return Null.noSuchObject;
+				}
+			}
+		}
+		
+		// manage regular java types
+		if (value instanceof Long) {
+			result = new OctetString(((Long)value).toString());
+		} else if (value instanceof Boolean) {
+			if(((Boolean)value).booleanValue())
 				result = new Integer32(1);
 			else 
 				result = new Integer32(0);
-		} else if (val instanceof String) {
-        	result = new OctetString((String) val);
-		} else if (val instanceof Integer) {
-			result = new Integer32((Integer)val);
-		} else if (val instanceof OID) {
-        	result = new OID((OID)val);
-        } else if (val instanceof TimeTicks) {
+		} else if (value instanceof String) {
+        	result = new OctetString((String) value);
+		} else if (value instanceof Integer) {
+			result = new Integer32((Integer)value);
+		} else if (value instanceof OID) {
+        	result = new OID((OID)value);
+        } else if (value instanceof TimeTicks) {
         	// the SNMP4J class TimeTicks default toString method is formatted horribly. This 
         	// call emulates the joesnmp SnmpTimeTicks display.
-        	result = (TimeTicks) val;
-        } else if (val instanceof Counter32) {
-     	   	result = (Counter32) val;
+//        	result = new OctetString(((TimeTicks)val).toString("{0} d {1} h {2} m {3} s {4} hs"));
+        	result = (TimeTicks) value;
+        } else if (value instanceof Counter32) {
+     	   	result = (Counter32) value;
         } else {
         	throw new VariableTypeException(); // no instance of an SNMP Variable could be created for type
         }
@@ -906,30 +1002,91 @@
 		if (trace)
 			log.trace("setValueFor: found bind entry for " + oid);
 		
-		if (be != null)
-		{
+		if (be != null) {
 			if (trace)
 				log.trace("setValueFor: " + be.toString());
          
-			if (be.isReadWrite() == false)
-			{
+			if (be.isReadWrite() == false) {
 				if (trace)
 					log.trace("setValueFor: this is marked read only");
             
 				throw new ReadOnlyException(oid);
 			}
-			try
-			{		
+			try {		
 				Object other = server.getAttribute(be.getMbean(), be.getAttr().getName());
 				Object val = convertVariableToValue(newVal, other);
 				
-				if (other != null && val.getClass() != other.getClass() ){
-					log.debug("setValueFor: attempt to set an MBean Attribute with the wrong type.");
+				if (other != null && val.getClass() != other.getClass() ) {
+					if(log.isDebugEnabled())
+						log.debug("setValueFor: attempt to set an MBean Attribute with the wrong type.");
 					ssy = newVal;
 				}
-								
-				Attribute at = new Attribute(be.getAttr().getName(), val);
-				server.setAttribute(be.getMbean(), at);
+				OID tableIndexOID = be.getTableIndexOID();
+				if(tableIndexOID == null) {				
+					Attribute at = new Attribute(be.getAttr().getName(), val);
+					server.setAttribute(be.getMbean(), at);
+				} else {
+					// manage arrays and lists					
+					if(other instanceof List) {
+						int index = Integer.valueOf(tableIndexOID.toString()) - 1;
+						if(index < 0) {
+							return Null.noSuchObject;
+						}
+						if(index < ((List)other).size()) { 
+							((List)other).set(index, val);
+						} else {
+							return Null.noSuchObject;
+						}
+					}
+					if(other instanceof Map) {
+						String key = new String(tableIndexOID.toByteArray());
+						((Map)other).put(key, val);						
+					}
+					if (other instanceof int[]) {
+						int index = Integer.valueOf(tableIndexOID.toString()) - 1;
+						if(index < 0) {
+							return Null.noSuchObject;
+						}
+						if(index < ((int[])other).length) { 
+							((int[])other)[index] = (Integer) val;
+						} else {
+							return Null.noSuchObject;
+						}
+					}
+					if (other instanceof long[]) {
+						int index = Integer.valueOf(tableIndexOID.toString()) - 1;
+						if(index < 0) {
+							return Null.noSuchObject;
+						}
+						if(index < ((long[])other).length) { 
+							((long[])other)[index] = (Long) val;
+						} else {
+							return Null.noSuchObject;
+						}
+					}
+					if (other instanceof boolean[]) {
+						int index = Integer.valueOf(tableIndexOID.toString()) - 1;
+						if(index < 0) {
+							return Null.noSuchObject;
+						}
+						if(index < ((boolean[])other).length) { 
+							((boolean[])other)[index] = (Boolean) val;
+						} else {
+							return Null.noSuchObject;
+						}
+					}
+					if (other instanceof Object[]) {
+						int index = Integer.valueOf(tableIndexOID.toString()) - 1;
+						if(index < 0) {
+							return Null.noSuchObject;
+						}
+						if(index < ((Object[])other).length) { 
+							((Object[])other)[index] = val;
+						} else {
+							return Null.noSuchObject;
+						}
+					}
+				}
 			
 				if (trace)
 					log.trace("setValueFor: set attribute in mbean server");
@@ -964,10 +1121,10 @@
 		
 		while (iter.hasNext()){
 			try{
-			VariableBinding vb = iter.next();
-			OID oid = vb.getOid();
-			Variable var = vb.getVariable();
-			setValueFor(oid,var);// this will not fail, because it succeeded earlier.
+				VariableBinding vb = iter.next();
+				OID oid = vb.getOid();
+				Variable var = vb.getVariable();
+				setValueFor(oid,var);// this will not fail, because it succeeded earlier.
 			}
 			catch(NoSuchInstanceException e){
 				//impossible
@@ -1004,6 +1161,9 @@
 		if(be == null) {
 			//needed for tables
 			be = tableMapper.getTableBinding(coid);
+			if(be == null) {
+				be = attributeTableMapper.getTableBinding(coid, false);
+			}
 		}
 
 		return be;
@@ -1036,12 +1196,15 @@
 	 */
 	private OID getNextOid(final OID oid) throws EndOfMibViewException {
 		OID coid = new OID(oid);
-		//TODO will be called for each get, not performing well, to be optimized		
 		tableMapper.checkTables(oid);
 		OID nextOid =  tableMapper.getNextTable(coid);
 		if(nextOid != null) {
-			return nextOid;
+			return nextOid;			
 		}
+		nextOid =  attributeTableMapper.getNextTable(coid);
+		if(nextOid != null) {
+			return nextOid;			
+		}
 		SortedSet<OID> ret;
 		ret=oidKeys.tailSet(oid);  // get oids >= oid
 		Iterator<OID> it = ret.iterator();

Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TableMapper.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TableMapper.java	2011-07-13 15:43:24 UTC (rev 111753)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TableMapper.java	2011-07-13 18:15:25 UTC (rev 111754)
@@ -21,7 +21,6 @@
  */
 package org.jboss.jmx.adaptor.snmp.agent;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -37,6 +36,8 @@
 import org.jboss.jmx.adaptor.snmp.config.attribute.MappedAttribute;
 import org.jboss.logging.Logger;
 import org.snmp4j.smi.OID;
+import org.snmp4j.smi.OctetString;
+import org.snmp4j.smi.Variable;
 
 /**
  * @author jean.deruelle at gmail.com
@@ -53,6 +54,7 @@
 	private SortedMap<OID, ManagedBean> tables = new TreeMap<OID, ManagedBean>();
 	private SortedMap<OID, BindEntry> tableBindings = new TreeMap<OID, BindEntry>();
 	private SortedMap<OID, OID> tableIndexes = new TreeMap<OID, OID>();
+	private SortedMap<OID, Variable> objectNameIndexes = new TreeMap<OID, Variable>();
 
 	private MBeanServer server;
 	private Logger log;
@@ -79,6 +81,15 @@
 	public OID getNextTable(OID oid) {
 		return tableIndexes.get(oid);
 	}
+	
+	/**
+	 * 
+	 * @param oid
+	 * @return
+	 */
+	public Variable getObjectNameIndexValue(OID oid) {		
+		return objectNameIndexes.get(oid);
+	}
 
 	/**
 	 * 
@@ -113,7 +124,6 @@
 	 */
 	private void createMappings(Set<ObjectName> mbeanNames,
 			List<MappedAttribute> attrs, String tableOid) {
-		boolean firstTableIndexSet = false;
 		boolean firstColumnIndexSet = false;
 		SortedSet<String> onameStrings = new TreeSet<String>();
 		for (ObjectName oname : mbeanNames) {
@@ -121,16 +131,16 @@
 		}
 		String previousMBeanName = null;
 		String lastMBeanName = onameStrings.last();
+//		OID rowIndexOID = null;
+//		OID previousRowIndexOID = null;
+		OID firstOID = null;
+//		int rowIndex = 1;
 		for (String mbeanRealName : onameStrings) {
 			String previousAttribute = null;
 			for (MappedAttribute ma : attrs) {
-				String oid = "";
-				String columnOid = null;
+				String oid = tableOid;
+				String columnOid = oid + ma.getOid();
 				String previousOid = null;
-				if (tableOid != null) {
-					oid = tableOid;
-				}			
-				columnOid = oid + ma.getOid(); 
 				String fullOid = columnOid + ".'" + mbeanRealName + "'";
 				if(previousMBeanName != null) {
 					previousOid = columnOid + ".'" + previousMBeanName + "'";
@@ -142,28 +152,45 @@
 				if(previousOid != null) {
 					OID previousOID = new OID(previousOid);
 					tableIndexes.put(previousOID, coid);
+				}				
+				if(firstOID == null) {
+					firstOID = coid;
 				}
-				if(!firstTableIndexSet) {
-					// adding mapping between the table oid  and table entry oid and the first OID in the table
-					tableIndexes.put(new OID(tableOid), coid);
-					tableIndexes.put(new OID(tableOid.substring(0,
-							tableOid.lastIndexOf("."))), coid);
-					firstTableIndexSet = true;
-				}
 				// By issuing a GETNEXT request with the bare MIB name of one of the columns, the agent will return that entry from the first row of the table:
-				if(!firstColumnIndexSet) {
+				if(!firstColumnIndexSet) {					
 					// adding mapping between the table oid  and table entry oid and the first OID in the table
-					tableIndexes.put(new OID(columnOid), coid);
+//					tableIndexes.put(new OID(oid + ".'" + ma.getName() + "'"), coid);
+					tableIndexes.put(new OID(oid + ma.getOid()), coid);
 					if(previousAttribute != null) {
 						String lastRowOID = oid + previousAttribute +  ".'" + lastMBeanName + "'";
 						tableIndexes.put(new OID(lastRowOID), coid);
 					}
 				}		
 				previousAttribute = ma.getOid();
-			}			
+			}	
+//			rowIndexOID = new OID(tableOid + ".1." + rowIndex);			
+//			if(previousRowIndexOID == null) {
+//				// adding mapping between the table oid  and table entry oid and the first OID in the table
+//				tableIndexes.put(new OID(tableOid), rowIndexOID);
+//				tableIndexes.put(new OID(tableOid.substring(0,
+//						tableOid.lastIndexOf("."))), rowIndexOID);
+//				objectNameIndexes.put(rowIndexOID, new OctetString(mbeanRealName));
+//				previousRowIndexOID = rowIndexOID;
+//			} else {
+//				tableIndexes.put(previousRowIndexOID, rowIndexOID);
+//				objectNameIndexes.put(rowIndexOID, new OctetString(mbeanRealName));
+//				previousRowIndexOID = rowIndexOID;
+//			}
+//			rowIndex++;
 			firstColumnIndexSet = true;
 			previousMBeanName = mbeanRealName;
-		}		
+		}
+		tableIndexes.put(new OID(tableOid), firstOID);
+		tableIndexes.put(new OID(tableOid.substring(0,
+				tableOid.lastIndexOf("."))), firstOID);
+//		if(firstOID != null && previousRowIndexOID != null) {
+//			tableIndexes.put(previousRowIndexOID, firstOID);
+//		}
 	}
 
 	/**

Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java	2011-07-13 15:43:24 UTC (rev 111753)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java	2011-07-13 18:15:25 UTC (rev 111754)
@@ -92,10 +92,10 @@
    private Counter trapCount = null;   
    
    /** attributes gathered from attributes.xml, used for bindings **/
-//  private SortedMap bindings = null;
+ //  private SortedMap bindings = null;
    
    /** MBeanServer instance to query about BindEntry objects contained in the bindings map**/
- //  private MBeanServer server = null; 
+  // private MBeanServer server = null; 
    
    /**
     * Create TrapFactorySupport
@@ -171,6 +171,9 @@
          for (int i = 0; i < vbList.size(); i++)
          {
             VarBind vb = (VarBind)vbList.get(i);
+            
+            // we should first attempt to find the OID's value in the list of bindings, whether it be a table cell 
+            // or otherwise. We do this by calling into the list of bind entries.
                 
             // Append the var bind. Interrogate read vb for OID and 
             // variable tag. The later is used as the key passed to the 

Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MappedAttribute.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MappedAttribute.java	2011-07-13 15:43:24 UTC (rev 111753)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MappedAttribute.java	2011-07-13 18:15:25 UTC (rev 111754)
@@ -34,7 +34,10 @@
 	private String name;
 	private String oid;
 	private String mode;
-	private boolean isReadWrite = false;	
+	private boolean isReadWrite = false;
+	private String table;
+	private boolean isAttributeTable = false;
+	
 	private String mbName = ""; //the name of the mBean this MappedAttribute is associated with
 	private String snmpType = ""; //the type for the MIB we should use, if provided
 	private String oidPrefix = "";
@@ -80,7 +83,24 @@
 			isReadWrite = true;
 		}
 	}
+	/** Attribute table  */
+	public boolean isAttributeTable() {
+		return isAttributeTable;
+	}
 	
+	/** Attribute table  */
+	public String getTable() {
+		return table;
+	}
+
+	@XmlAttribute(name="table")
+	public void setTable(String table) {
+		this.table = table;
+		if(table != null && Boolean.valueOf(table)) {
+			isAttributeTable = true;
+		}
+	}
+	
 	public String getMbean(){
 		return this.mbName;
 	}

Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Generator.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Generator.java	2011-07-13 15:43:24 UTC (rev 111753)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Generator.java	2011-07-13 18:15:25 UTC (rev 111754)
@@ -55,6 +55,7 @@
 
 public class Generator {
 	private String outputResName; // the name of the output file (.mib or .xml)
+	private String moduleName; // the name of the output SNMP module
 	private ArrayList<MIBObject> miboList; // internal list of MIBObjects
 	private ArrayList<MIBNotification> mibnList;
 	private ArrayList<MIBTable> tableList;
@@ -89,8 +90,9 @@
 	 * @param nmList list of notifications received from the parser
 	 */
 	
-	public Generator(String outputResName, ArrayList<MappedAttribute> maList, AttributeMappings mbList, ArrayList<Mapping> nmList){
+	public Generator(String outputResName, String moduleName, ArrayList<MappedAttribute> maList, AttributeMappings mbList, ArrayList<Mapping> nmList){
 		this.outputResName = outputResName;
+		this.moduleName = moduleName;
 		this.mbList = mbList;
 		this.miboList = new ArrayList<MIBObject>();
 		this.maList = maList;
@@ -166,7 +168,7 @@
 	private void writeMibHeader(PrintWriter out){
 		out.println("-- This MIB Generated by the JBoss MIB Generator");
 		out.println();
-		out.println("JBOSS-AS-MIB DEFINITIONS ::=BEGIN");
+		out.println(this.moduleName+" DEFINITIONS ::=BEGIN");
 		out.println();
 		// maybe add more here, if not we don't need this to be a seperate method.
 	}
@@ -226,6 +228,8 @@
 		}
 	}
 	
+
+	
 	/**
 	 * This method generates an appropriate MIBObject from a given MappedAttribute, and adds
 	 * it to this instance's list of mibObjects for writing to the file.
@@ -234,10 +238,18 @@
 	private void createEntries(){
 		if (maList != null){
 			for (MappedAttribute ma : maList){
-				if (ma.isAttributeTable())
-					tableList.add(new MIBTable(ma));
-				else
-					miboList.add(new MIBObject(ma));
+				try{
+					if (ma.isAttributeTable())
+						tableList.add(new MIBTable(ma));
+					else{
+						MIBObject mibo = new MIBObject(ma);
+						miboList.add(mibo);
+					}
+				}
+				catch (NotEnoughInformationException e){
+					System.err.println(e.getMessage());
+					System.exit(1);
+				}
 			}
 		}
 		else {
@@ -250,10 +262,21 @@
 				ObjectName test = null;
 				try{
 				test = new ObjectName(mb.getName());
-				}catch(Exception e){}
-				if (test != null && test.isPattern())
-					tableList.add(new MIBTable(mb));
-			
+				}
+				catch(Exception e){
+					e.printStackTrace();
+					System.exit(1);
+				}
+				if (test != null && test.isPattern()){
+					try{
+						MIBTable mibT = new MIBTable(mb);
+						tableList.add(mibT);
+					}
+					catch (NotEnoughInformationException e){
+						System.err.println(e.getMessage());
+						System.exit(1);
+					}
+				}
 			}
 		}
 		else { 
@@ -261,8 +284,15 @@
 			System.out.println("Attribute parsing was skipped. No list of MBeans is available.");
 		}
 		if (nmList != null){
-			for(Mapping mibN : nmList){
-				mibnList.add(new MIBNotification(mibN));
+			for(Mapping nm : nmList){
+				try{
+					MIBNotification mibN = new MIBNotification(nm);
+					mibnList.add(new MIBNotification(nm));
+				}
+				catch (NotEnoughInformationException e){
+					System.err.println(e.getMessage());
+					System.exit(1);
+				}
 			}
 		}
 		else {
@@ -282,7 +312,7 @@
 		private String fullOid;
 		private boolean rowEntry; //internally used to avoid adding an OIDDef for a member of an entry
 	
-		MIBObject(String name, VarBind vb){
+		MIBObject(String name, VarBind vb) throws NotEnoughInformationException {
 			super();
 			this.name = name;
 			this.syntax = (vb.getType()!=null) ? vb.getType() : "DisplayString";
@@ -301,13 +331,15 @@
 			}
 			this.fullOid = fullOid;
 			setOidDef(oidPrefix, null);
+
+
 		}
 		
-		MIBObject(MappedAttribute ma){
+		MIBObject(MappedAttribute ma) throws NotEnoughInformationException{
 			this(ma, false);
 		}
 			
-		MIBObject(MappedAttribute ma, boolean rowEntry){
+		MIBObject(MappedAttribute ma, boolean rowEntry) throws NotEnoughInformationException{
 			// names must begin with lowercase, or the manager complains / gives warnings
 			this.name = ma.getName().substring(0,1).toLowerCase() + ma.getName().substring(1);
 			
@@ -344,7 +376,6 @@
 				this.oidDef = ma.getOidDefName();
 			else
 				setOidDef(ma.getOidPrefix(), ma.getOidDefName());
-
 		}
 		
 		public String getName(){
@@ -354,6 +385,10 @@
 		public String getFullOid(){
 			return this.fullOid;
 		}
+		
+		public boolean equals(Object o){
+			return super.equals(o);
+		}
 			
 		@Override
 		public String toString(){
@@ -384,17 +419,17 @@
 		private class MIBNotification extends MIBEntity{
 			private ArrayList<String> objects;
 			
-			public MIBNotification(Mapping mp){
+			public MIBNotification(Mapping mp) throws NotEnoughInformationException {
 				this.objects = new ArrayList<String>();
 				
-				this.name = (mp.getName()!=null) ? mp.getName() : "UNDEFINED";
-				
+				this.name = mp.getName();
+				if (this.name==null){
+					throw new NotEnoughInformationException("The notification "+mp.getNotificationType()+" has no valid name for the MIB.");
+				}
 				this.status = (mp.getStatus()!=null) ? mp.getStatus() : "current";
-				
 				this.description = (mp.getDesc()!=null) ? mp.getDesc() : "";
-				
 				ArrayList<VarBind> vbList = (ArrayList<VarBind>)mp.getVarBindList().getVarBindList();
-				setObjects(vbList);	
+				setObjects(vbList);
 				// the OID of a v2 trap = <enterpriseid>.0.<specificid>
 				// for predefined traps, see RFC1907 / 3413 / 3418 / http://www.oid-info.com/get/1.3.6.1.6.3.13
 				String oidPrefix = mp.getEnterprise()+".0";
@@ -402,6 +437,7 @@
 				// check if there is already an OID definition for this prefix. If there is make this MIBObject's 
 				// oidDef reflect that
 				setOidDef(oidPrefix, mp.getOidDef());
+
 			}
 			
 			public void setName(String name){
@@ -420,9 +456,9 @@
 				return this.description;
 			}
 			
-			public void setObjects(ArrayList<VarBind> vbList){
-				// there are special conditions in this section that we need to accoutn for, and 
-				// define more MIBObjects. They are all of the n:tags
+			public void setObjects(ArrayList<VarBind> vbList) throws NotEnoughInformationException{
+				// there are special conditions in this section that we need to account for, and 
+				// define more MIBObjects. They are all of the n:tags and u:tags
 				// more changes need to be done 
 				Iterator vbIt = vbList.iterator();
 				ArrayList<String> oids = new ArrayList<String>(10);
@@ -447,14 +483,15 @@
 						}
 					}
 					// if we get here; there is no matching MIBObject for this oid. put UNKNOWNOBJECT here instead.
-					this.objects.add("UNKNOWNOBJECT");
+					//this.objects.add("UNKNOWNOBJECT");
+					throw new NotEnoughInformationException("The notification "+this.name+" contains an OID that does not exist in the MIB.");
 				}
 			}
 
 			//if we found a tag that matches n:.*, we create a new MIBObject so that this object
 			//is included in the mib.
 			
-			public void createNotifPayloadMibo(VarBind vb){
+			public void createNotifPayloadMibo(VarBind vb) throws NotEnoughInformationException{
 				String[] tag = vb.getTag().split(":");
 				//hacky. maybe a cleaner way to do this later?
 				String name = "jbossJmxNotification"+tag[tag.length-1].substring(0,1).toUpperCase()+tag[tag.length-1].substring(1);
@@ -571,14 +608,14 @@
 			private MIBTableRow row; // the row created from information contained in 
 									 // this MIBTable
 			//creating a table out of an attribute 
-			public MIBTable(MappedAttribute ma){
+			public MIBTable(MappedAttribute ma) throws NotEnoughInformationException {
 				this.tablePrefix=ma.getName().substring(0,1).toLowerCase() + ma.getName().substring(1);
-				this.name = (this.tablePrefix!=null) ? this.tablePrefix+"Table" : "UKNOWNTable";
+				this.name = this.tablePrefix+"Table";
 				this.maxAccess = "not-accessible";
 				String [] temp = ma.getOid().split("\\.");
 				this.objectId = temp[temp.length-1];
 				this.description = (ma.getSnmpDesc()!=null) ? ma.getSnmpDesc() : "";
-				this.rowName = (this.tablePrefix!=null) ? this.tablePrefix+"Entry" : "UNKNOWNRow";
+				this.rowName = this.tablePrefix+"Entry";
 				this.syntax = this.rowName.substring(0,1).toUpperCase() + this.rowName.substring(1);
 				this.status = (ma.getStatus()!=null) ? ma.getStatus() : "current";
 				setOidDef(ma.getOidPrefix(), ma.getOidDefName());
@@ -587,11 +624,17 @@
 			
 			
 			// if we find a managedbean with a wildcard object name, we make a table
-			public MIBTable(ManagedBean mb){
+			public MIBTable(ManagedBean mb) throws NotEnoughInformationException{
 				this.tablePrefix = mb.getTableName();
-				this.name = (this.tablePrefix!=null) ? this.tablePrefix+"Table" : "UNKNOWNTable";
+				if (this.tablePrefix == null){
+					throw new NotEnoughInformationException("The mbean "+mb.getName()+" has no table-name attribute defined. Cannot create table definition.");
+				}
+				this.name = this.tablePrefix+"Table";
 				this.maxAccess = "not-accessible";
 				String oid = mb.getOidPrefix();
+				if (oid == null){
+					throw new NotEnoughInformationException("The mbean "+mb.getName()+" has no oid-prefix attribute defined. Cannot create table definition.");
+				}
 				String oidPrefix = "";
 				String [] temp = oid.split("\\.");
 				this.objectId = temp[temp.length-2];
@@ -602,7 +645,7 @@
 						oidPrefix += temp[i]+".";
 				}
 				this.description = (mb.getDesc()!=null) ? mb.getDesc() : "";
-				this.rowName = (this.tablePrefix!=null) ? this.tablePrefix+"Entry" : "UNKNOWNRow";
+				this.rowName = this.tablePrefix+"Entry";
 				this.syntax = this.rowName.substring(0,1).toUpperCase() + this.rowName.substring(1);
 				this.status = (mb.getStatus()!=null) ? mb.getStatus() : "current";
 				setOidDef(oidPrefix, mb.getOidDefinition());
@@ -616,7 +659,7 @@
 				   .append("\tSYNTAX\tSEQUENCE OF ").append(this.syntax).append("\n")
 				   .append("\tMAX-ACCESS\t").append(this.maxAccess).append("\n")
 				   .append("\tSTATUS\t").append(this.status).append("\n")
-				   .append("\tDESCRIPTION\t\n\t\t").append("\""+this.description+"\"").append("\n")
+				   .append("\tDESCRIPTION\n\t\t").append("\""+this.description+"\"").append("\n")
 				   .append("::= { ").append(this.oidDef+" " +this.objectId+" }\n\n")
 				   .append(row);
 				return buf.toString();
@@ -634,7 +677,7 @@
 			private String indexName;
 			
 			//build from a table=true attribute index and contents are generic.
-			MIBTableRow(String tableName, String tablePrefix, String rowName, String rowOid, String mode){
+			MIBTableRow(String tableName, String tablePrefix, String rowName, String rowOid, String mode) throws NotEnoughInformationException{
 				this.tableName = tableName;
 				this.tablePrefix = tablePrefix;
 				this.name = rowName;
@@ -671,7 +714,7 @@
 			}
 
 			// build from ManagedBean, so we have an attrlist.
-			MIBTableRow(String tableName, String tablePrefix, String rowName, String rowOid, ArrayList<MappedAttribute> attrList){
+			MIBTableRow(String tableName, String tablePrefix, String rowName, String rowOid, ArrayList<MappedAttribute> attrList) throws NotEnoughInformationException{
 				this.tableName = tableName;
 				this.tablePrefix = tablePrefix;
 				this.name = rowName;
@@ -685,8 +728,15 @@
 				setRowObjects(attrList);				
 			}
 			
-			private void setRowObjects(ArrayList<MappedAttribute> attrList){
+			private void setRowObjects(ArrayList<MappedAttribute> attrList) throws NotEnoughInformationException{
 				this.rowObjects = new ArrayList<MIBObject>(1);
+				// check if there's an invalid OID in the attrList, ie: one defined with a .1 oid
+				for (MappedAttribute ma: attrList){
+					if (ma.getOid().equals(".1")){
+						System.out.println("The attribute '"+ma.getName()+"' has an OID of 1. This value is reserved for the index in a table. MIB Generation failed.");
+						System.exit(1);
+					}
+				}
 				MappedAttribute objectName = new MappedAttribute();
 				objectName.setSnmpType("DisplayString");
 				objectName.setName(this.tablePrefix+"ObjectName");
@@ -723,10 +773,10 @@
 				   .append("\tSYNTAX\t")       .append(this.typeName)       .append("\n")
 				   .append("\tMAX-ACCESS\t")   .append(this.maxAccess)  .append("\n")
 				   .append("\tSTATUS\t")	   .append(this.status)     .append("\n")
-				   .append("\tDESCRIPTION\n\t").append("\""+this.description+"\"\n")
+				   .append("\tDESCRIPTION\n\t\t").append("\""+this.description+"\"\n")
 				   .append("\n\t\t").append("INDEX\t{\n\t\tIMPLIED "+this.indexName+"\n\t\t}\n")         
 				   .append("::= { ").append(this.tableName).append(" "+this.objectId)
-				   .append(" }\t\t\n\n");
+				   .append(" }\n\n");
 				buf.append(writeRowDefinition()+"\n");
 				// print the rest of the objects
 				for (MIBObject object : rowObjects){
@@ -762,7 +812,7 @@
 			
 			public abstract String toString();
 				
-			public void setOidDef(String oidPrefix, String oidDefName){
+			public void setOidDef(String oidPrefix, String oidDefName) throws NotEnoughInformationException{
 				if (oidDefMap.containsKey(oidPrefix)){
 					this.oidDef = oidDefMap.get(oidPrefix).getName();
 				}
@@ -778,12 +828,37 @@
 					}
 					else { // everything failed. the attributes.xml doesn't specify a name for the oid definition to be used,
 						   // nor do we already know about it.
-						OIDDef newOidDef = new OIDDef("UNKNOWN", oidPrefix);
-						oidDefMap.put(oidPrefix, newOidDef);
-						this.oidDef="UNKNOWN";
+						throw new NotEnoughInformationException("There was no definition-name for oid-prefix: "+oidPrefix);
 					}
 				}
 			}
+			
+			/** 
+			 * Compares two MIBEntities, in order to allow us to know if there are duplicates or not, or maybe even use SortedSet.
+			 * If the OIDDef and objectId are not equal, then we return false. This is because, no MIB Object can have the same OIDDef and the same objectId.
+			 * 
+			 * @param o Object to compare to
+			 * @return true if equal, false otherwise
+			 */
+			@Override
+			public boolean equals(Object o){
+				if (this == o)
+					return true;
+								
+				if (o == null) 
+					return false;
+				
+				MIBEntity test = (MIBEntity) o;
+				
+				if (this.objectId != null ? !this.objectId.equals(test.objectId) : test.objectId != null) 
+					return false;
+				
+				if (this.oidDef != null ? !this.oidDef.equals(test.oidDef) : test.oidDef != null) 
+					return false;
+				
+				return true;
+
+			}
 		}
 
 }// end MIB Generator
\ No newline at end of file

Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/MIBGenerator.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/MIBGenerator.java	2011-07-13 15:43:24 UTC (rev 111753)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/MIBGenerator.java	2011-07-13 18:15:25 UTC (rev 111754)
@@ -57,7 +57,8 @@
 		CmdLineParser.Option help = cmdParser.addBooleanOption('h', "help");
 		CmdLineParser.Option attributes = cmdParser.addStringOption('a', "attributes");
 		CmdLineParser.Option notifications = cmdParser.addStringOption('n', "notifications");
-		CmdLineParser.Option mib = cmdParser.addStringOption('m', "mib");
+		CmdLineParser.Option output = cmdParser.addStringOption('o', "output");
+		CmdLineParser.Option module = cmdParser.addStringOption('m', "module");
 		
 	 	try {
 	 		cmdParser.parse(args);
@@ -69,7 +70,8 @@
 	 	Boolean isHelp = (Boolean)cmdParser.getOptionValue(help, Boolean.FALSE);
 	 	String aFile = (String)cmdParser.getOptionValue(attributes);
 	 	String nFile = (String)cmdParser.getOptionValue(notifications);
-	 	String mibFile = (String)cmdParser.getOptionValue(mib);
+	 	String oFile = (String)cmdParser.getOptionValue(output);
+	 	String moduleName = (String)cmdParser.getOptionValue(module);
 	 	
 	 	if (isHelp){
 	 		printUsageMessage();
@@ -78,7 +80,7 @@
 
 	 	parser = new Parser(aFile, nFile);
 		parser.parse();
-		Generator generator = new Generator(mibFile, parser.getMaList(), parser.getMbList(), parser.getNmList());
+		Generator generator = new Generator(oFile, moduleName, parser.getMaList(), parser.getMbList(), parser.getNmList());
 		generator.writeFile();		
 	}
 	
@@ -88,7 +90,8 @@
 				"[FLAG]s:\n-h , --help : display the usage information\n" +
 				"-a , --attributes : indicate the name of the snmp-adaptor formatted attributes.xml, if any.\n" +
 				"-n , --notifications : indicate the name of the snmp-adaptor formatted notification.xml file, if any.\n" +
-				"-m , --mib : indicate the desired name of the MIB file. This can be a path.\n"+
+				"-o , --output : indicate the desired name of the output MIB file. This can be a path.\n" +
+				"-m , --module : indicate the desired name of the output MIB module. This is the name that the SNMP manager will know the MIB by.\n"+
 				"Example: java -jar mib-generator.jar -a attributes.xml -n notifications.xml -m /home/user/TEST-MIB.mib");
 	}
 	

Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Parser.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Parser.java	2011-07-13 15:43:24 UTC (rev 111753)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Parser.java	2011-07-13 18:15:25 UTC (rev 111754)
@@ -118,13 +118,13 @@
 				parseAttributesXml();
 			}
 			else
-				System.out.println("No attributes file indicated, skipping.");
+				System.err.println("No attributes file indicated, skipping.");
 			
 			if (this.inputNotificationFile != null){
 				parseNotificationsXml();
 			}
 			else 
-				System.out.println("No notifications file indicated, skipping;");
+				System.err.println("No notifications file indicated, skipping;");
 		}
 		catch (Exception e){
 			e.printStackTrace();
@@ -147,11 +147,11 @@
 			mappings = (ArrayList)unmarshaller.unmarshal(is,omf,null);
 		}
 		catch (NoClassDefFoundError e){
-			System.out.println("The notifications file is not formatted correctly: '"+this.inputNotificationFile+"'");
+			System.err.println("The notifications file is not formatted correctly: '"+this.inputNotificationFile+"'");
 			System.exit(1);
 		}
 		catch (FileNotFoundException e){
-			System.out.println("Filename given for notifications does not exist: '"+this.inputNotificationFile+"'");
+			System.err.println("Filename given for notifications does not exist: '"+this.inputNotificationFile+"'");
 			System.exit(1);
 		}
 		catch (Exception e){
@@ -201,11 +201,11 @@
 		   setMbList(mappings);
 		}
 		catch (NoClassDefFoundError e){
-			System.out.println("The attributes file is not formatted correctly: '"+this.inputAttrFile+"'");
+			System.err.println("The attributes file is not formatted correctly: '"+this.inputAttrFile+"'");
 			System.exit(1);
 		}
 		catch (FileNotFoundException e){
-			System.out.println("Filename given for attributes.xml does not exist: '"+this.inputAttrFile+"'");
+			System.err.println("Filename given for attributes.xml does not exist: '"+this.inputAttrFile+"'");
 			System.exit(1);
 		}
 		catch (Exception e){
@@ -237,6 +237,11 @@
 				   test = new ObjectName(mbeanName);
 			   } catch (Exception e) {}
 			   
+			   if (test == null){
+				   System.err.println("The mbeanName '"+mbeanName+"' could not be converted to an ObjectName. MIB generation failed.");
+				   System.exit(1);
+			   }
+			   
 			   if(!test.isPattern()){
 				   String oidPrefix = mmb.getOidPrefix();
 				   String oidDefName = mmb.getOidDefinition();
@@ -249,22 +254,38 @@
 	
 					  if (oidPrefix != null)
 						  ma.setOidPrefix(oidPrefix);
-					  else
+					  else{
 						  ma.setOidPrefix(removeLast(ma.getOid()));
+						  ma.setOid(getLast(ma.getOid()));
+					  }
 					  
 					  ma.setOidDefName(oidDefName);
 					  			  
 					  // for the MIB Generator
 					  ma.setMbean(mmb.getName());
-					  maList.add(ma);	  
+					  if(!maList.contains(ma)){
+						  maList.add(ma); 
+					  }
+					  else{
+						  System.err.println("The attribute '"+ma.getName()+"' is defined using a duplicated OID. MIB generation failed.");
+						  System.exit(1);
+					  }
 			  }
 		   }
 		}
 	}//end parseXml
 	
 	/**
+	 * This method returns the last element of a dotted string representing an OID
+	 */
+	private String getLast(String oid){
+		String [] split = oid.split("\\.");
+		return split[split.length-1];
+	}
+	
+	/**
 	 * This private method removes the last element of a dotted string like
-	 * 1.3.6.1.2.1.1, and returns it.
+	 * 1.3.6.1.2.1.1, and returns the rest of the string.
 	 */
 	private String removeLast(String oid){
 		String [] split = oid.split("\\.");

Added: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/exceptions/NotEnoughInformationException.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/exceptions/NotEnoughInformationException.java	                        (rev 0)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/exceptions/NotEnoughInformationException.java	2011-07-13 18:15:25 UTC (rev 111754)
@@ -0,0 +1,18 @@
+package org.jboss.jmx.adaptor.snmp.generator;
+/** This exception is thrown when there is not enough information inside the input files 
+ *  to create a complete, valid MIB.
+ *  
+ * @author Thomas Hauser <a href="mailto:thauser at redhat.com"></a>
+ *
+ */
+public class NotEnoughInformationException extends Exception {
+
+	public NotEnoughInformationException(){
+		super("Incomplete information in the parsed files. MIB cannot be created.");
+	}
+	
+	public NotEnoughInformationException(String m){
+		super(m);
+	}
+	
+}
\ No newline at end of file

Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/MappedAttribute.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/MappedAttribute.java	2011-07-13 15:43:24 UTC (rev 111753)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/MappedAttribute.java	2011-07-13 18:15:25 UTC (rev 111754)
@@ -172,4 +172,34 @@
 		buf.append("]");
 		return buf.toString();
 	}
+	
+	@Override
+	public boolean equals(Object o){
+		if (this == o) 
+			return true;
+		
+		if (o == null)
+			return false;
+		
+		MappedAttribute that = (MappedAttribute) o;
+		
+		String fullOidThis = this.oidPrefix+"."+this.oid;
+		String fullOidThat = that.oidPrefix+"."+that.oid;
+		return (fullOidThis.equals(fullOidThat));
+		
+		
+	}
+	
+	@Override 
+	public int hashCode(){
+		int result = 1;
+		int PRIME = 31;
+		if (this.oidPrefix == null)
+			return PRIME * result + this.oid.hashCode();
+		else {
+			String fullOid = this.oidPrefix+"."+this.oid;
+			return PRIME * result + fullOid.hashCode();
+		}	
+			
+	}
 }



More information about the jboss-cvs-commits mailing list