[jboss-cvs] JBossAS SVN: r111569 - branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 9 16:57:53 EDT 2011


Author: thauser at redhat.com
Date: 2011-06-09 16:57:52 -0400 (Thu, 09 Jun 2011)
New Revision: 111569

Added:
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/CmdLineParser.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserAttributeBindings.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserNotificationBindings.java
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/MIBGenerator.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Parser.java
Log:
work on MIB Generator

Added: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/CmdLineParser.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/CmdLineParser.java	                        (rev 0)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/CmdLineParser.java	2011-06-09 20:57:52 UTC (rev 111569)
@@ -0,0 +1,558 @@
+/* Copyright (c) 2001-2003 Steve Purcell.
+ * Copyright (c) 2002      Vidar Holen.
+ * Copyright (c) 2002      Michal Ceresna.
+ * Copyright (c) 2005      Ewan Mellor.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: Redistributions of source code must retain the above copyright notice, 
+ * this list of conditions and the following disclaimer. Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. Neither the name of the copyright
+ * holder nor the names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+package org.jboss.jmx.adaptor.snmp.generator;
+
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.Hashtable;
+import java.util.Vector;
+import java.util.Enumeration;
+import java.util.Locale;
+
+/**
+ * Largely GNU-compatible command-line options parser. Has short (-v) and
+ * long-form (--verbose) option support, and also allows options with
+ * associated values (-d 2, --debug 2, --debug=2). Option processing
+ * can be explicitly terminated by the argument '--'.
+ *
+ * @author Steve Purcell
+ * @version $Revision: 1.10 $
+ * @see jargs.examples.gnu.OptionTest
+ */
+public class CmdLineParser {
+
+    /**
+     * Base class for exceptions that may be thrown when options are parsed
+     */
+    public static abstract class OptionException extends Exception {
+        OptionException(String msg) { super(msg); }
+    }
+
+    /**
+     * Thrown when the parsed command-line contains an option that is not
+     * recognised. <code>getMessage()</code> returns
+     * an error string suitable for reporting the error to the user (in
+     * English).
+     */
+    public static class UnknownOptionException extends OptionException {
+        UnknownOptionException( String optionName ) {
+            this(optionName, "Unknown option '" + optionName + "'");
+        }
+
+        UnknownOptionException( String optionName, String msg ) {
+            super(msg);
+            this.optionName = optionName;
+        }
+
+        /**
+         * @return the name of the option that was unknown (e.g. "-u")
+         */
+        public String getOptionName() { return this.optionName; }
+        private String optionName = null;
+    }
+
+    /**
+     * Thrown when the parsed commandline contains multiple concatenated
+     * short options, such as -abcd, where one is unknown.
+     * <code>getMessage()</code> returns an english human-readable error
+     * string.
+     * @author Vidar Holen
+     */
+    public static class UnknownSuboptionException
+        extends UnknownOptionException {
+        private char suboption;
+
+        UnknownSuboptionException( String option, char suboption ) {
+            super(option, "Illegal option: '"+suboption+"' in '"+option+"'");
+            this.suboption=suboption;
+        }
+        public char getSuboption() { return suboption; }
+    }
+
+    /**
+     * Thrown when the parsed commandline contains multiple concatenated
+     * short options, such as -abcd, where one or more requires a value.
+     * <code>getMessage()</code> returns an english human-readable error
+     * string.
+     * @author Vidar Holen
+     */
+    public static class NotFlagException extends UnknownOptionException {
+        private char notflag;
+
+        NotFlagException( String option, char unflaggish ) {
+            super(option, "Illegal option: '"+option+"', '"+
+                  unflaggish+"' requires a value");
+            notflag=unflaggish;
+        }
+
+        /**
+         * @return the first character which wasn't a boolean (e.g 'c')
+         */
+        public char getOptionChar() { return notflag; }
+    }
+
+    /**
+     * Thrown when an illegal or missing value is given by the user for
+     * an option that takes a value. <code>getMessage()</code> returns
+     * an error string suitable for reporting the error to the user (in
+     * English).
+     */
+    public static class IllegalOptionValueException extends OptionException {
+        public IllegalOptionValueException( Option opt, String value ) {
+            super("Illegal value '" + value + "' for option " +
+                  (opt.shortForm() != null ? "-" + opt.shortForm() + "/" : "") +
+                  "--" + opt.longForm());
+            this.option = opt;
+            this.value = value;
+        }
+
+        /**
+         * @return the name of the option whose value was illegal (e.g. "-u")
+         */
+        public Option getOption() { return this.option; }
+
+        /**
+         * @return the illegal value
+         */
+        public String getValue() { return this.value; }
+        private Option option;
+        private String value;
+    }
+
+    /**
+     * Representation of a command-line option
+     */
+    public static abstract class Option {
+
+        protected Option( String longForm, boolean wantsValue ) {
+            this(null, longForm, wantsValue);
+        }
+
+        protected Option( char shortForm, String longForm,
+                          boolean wantsValue ) {
+            this(new String(new char[]{shortForm}), longForm, wantsValue);
+        }
+
+        private Option( String shortForm, String longForm, boolean wantsValue ) {
+            if ( longForm == null )
+                throw new IllegalArgumentException("Null longForm not allowed");
+            this.shortForm = shortForm;
+            this.longForm = longForm;
+            this.wantsValue = wantsValue;
+        }
+
+        public String shortForm() { return this.shortForm; }
+
+        public String longForm() { return this.longForm; }
+
+        /**
+         * Tells whether or not this option wants a value
+         */
+        public boolean wantsValue() { return this.wantsValue; }
+
+        public final Object getValue( String arg, Locale locale )
+            throws IllegalOptionValueException {
+            if ( this.wantsValue ) {
+                if ( arg == null ) {
+                    throw new IllegalOptionValueException(this, "");
+                }
+                return this.parseValue(arg, locale);
+            }
+            else {
+                return Boolean.TRUE;
+            }
+        }
+
+        /**
+         * Override to extract and convert an option value passed on the
+         * command-line
+         */
+        protected Object parseValue( String arg, Locale locale )
+            throws IllegalOptionValueException {
+            return null;
+        }
+
+        private String shortForm = null;
+        private String longForm = null;
+        private boolean wantsValue = false;
+
+        public static class BooleanOption extends Option {
+            public BooleanOption( char shortForm, String longForm ) {
+                super(shortForm, longForm, false);
+            }
+            public BooleanOption( String longForm ) {
+                super(longForm, false);
+            }
+        }
+
+        /**
+         * An option that expects an integer value
+         */
+        public static class IntegerOption extends Option {
+            public IntegerOption( char shortForm, String longForm ) {
+                super(shortForm, longForm, true);
+            }
+            public IntegerOption( String longForm ) {
+                super(longForm, true);
+            }
+            protected Object parseValue( String arg, Locale locale )
+                throws IllegalOptionValueException {
+                try {
+                    return new Integer(arg);
+                }
+                catch (NumberFormatException e) {
+                    throw new IllegalOptionValueException(this, arg);
+                }
+            }
+        }
+
+        /**
+         * An option that expects a long integer value
+         */
+        public static class LongOption extends Option {
+            public LongOption( char shortForm, String longForm ) {
+                super(shortForm, longForm, true);
+            }
+            public LongOption( String longForm ) {
+                super(longForm, true);
+            }
+            protected Object parseValue( String arg, Locale locale )
+                throws IllegalOptionValueException {
+                try {
+                    return new Long(arg);
+                }
+                catch (NumberFormatException e) {
+                    throw new IllegalOptionValueException(this, arg);
+                }
+            }
+        }
+
+        /**
+         * An option that expects a floating-point value
+         */
+        public static class DoubleOption extends Option {
+            public DoubleOption( char shortForm, String longForm ) {
+                super(shortForm, longForm, true);
+            }
+            public DoubleOption( String longForm ) {
+                super(longForm, true);
+            }
+            protected Object parseValue( String arg, Locale locale )
+                throws IllegalOptionValueException {
+                try {
+                    NumberFormat format = NumberFormat.getNumberInstance(locale);
+                    Number num = (Number)format.parse(arg);
+                    return new Double(num.doubleValue());
+                }
+                catch (ParseException e) {
+                    throw new IllegalOptionValueException(this, arg);
+                }
+            }
+        }
+
+        /**
+         * An option that expects a string value
+         */
+        public static class StringOption extends Option {
+            public StringOption( char shortForm, String longForm ) {
+                super(shortForm, longForm, true);
+            }
+            public StringOption( String longForm ) {
+                super(longForm, true);
+            }
+            protected Object parseValue( String arg, Locale locale ) {
+                return arg;
+            }
+        }
+    }
+
+    /**
+     * Add the specified Option to the list of accepted options
+     */
+    public final Option addOption( Option opt ) {
+        if ( opt.shortForm() != null )
+            this.options.put("-" + opt.shortForm(), opt);
+        this.options.put("--" + opt.longForm(), opt);
+        return opt;
+    }
+
+    /**
+     * Convenience method for adding a string option.
+     * @return the new Option
+     */
+    public final Option addStringOption( char shortForm, String longForm ) {
+        return addOption(new Option.StringOption(shortForm, longForm));
+    }
+
+    /**
+     * Convenience method for adding a string option.
+     * @return the new Option
+     */
+    public final Option addStringOption( String longForm ) {
+        return addOption(new Option.StringOption(longForm));
+    }
+
+    /**
+     * Convenience method for adding an integer option.
+     * @return the new Option
+     */
+    public final Option addIntegerOption( char shortForm, String longForm ) {
+        return addOption(new Option.IntegerOption(shortForm, longForm));
+    }
+
+    /**
+     * Convenience method for adding an integer option.
+     * @return the new Option
+     */
+    public final Option addIntegerOption( String longForm ) {
+        return addOption(new Option.IntegerOption(longForm));
+    }
+
+    /**
+     * Convenience method for adding a long integer option.
+     * @return the new Option
+     */
+    public final Option addLongOption( char shortForm, String longForm ) {
+        return addOption(new Option.LongOption(shortForm, longForm));
+    }
+
+    /**
+     * Convenience method for adding a long integer option.
+     * @return the new Option
+     */
+    public final Option addLongOption( String longForm ) {
+        return addOption(new Option.LongOption(longForm));
+    }
+
+    /**
+     * Convenience method for adding a double option.
+     * @return the new Option
+     */
+    public final Option addDoubleOption( char shortForm, String longForm ) {
+        return addOption(new Option.DoubleOption(shortForm, longForm));
+    }
+
+    /**
+     * Convenience method for adding a double option.
+     * @return the new Option
+     */
+    public final Option addDoubleOption( String longForm ) {
+        return addOption(new Option.DoubleOption(longForm));
+    }
+
+    /**
+     * Convenience method for adding a boolean option.
+     * @return the new Option
+     */
+    public final Option addBooleanOption( char shortForm, String longForm ) {
+        return addOption(new Option.BooleanOption(shortForm, longForm));
+    }
+
+    /**
+     * Convenience method for adding a boolean option.
+     * @return the new Option
+     */
+    public final Option addBooleanOption( String longForm ) {
+        return addOption(new Option.BooleanOption(longForm));
+    }
+
+    /**
+     * Equivalent to {@link #getOptionValue(Option, Object) getOptionValue(o,
+     * null)}.
+     */
+    public final Object getOptionValue( Option o ) {
+        return getOptionValue(o, null);
+    }
+
+
+    /**
+     * @return the parsed value of the given Option, or null if the
+     * option was not set
+     */
+    public final Object getOptionValue( Option o, Object def ) {
+        Vector v = (Vector)values.get(o.longForm());
+
+        if (v == null) {
+            return def;
+        }
+        else if (v.isEmpty()) {
+            return null;
+        }
+        else {
+            Object result = v.elementAt(0);
+            v.removeElementAt(0);
+            return result;
+        }
+    }
+
+
+    /**
+     * @return A Vector giving the parsed values of all the occurrences of the
+     * given Option, or an empty Vector if the option was not set.
+     */
+    public final Vector getOptionValues( Option option ) {
+        Vector result = new Vector();
+
+        while (true) {
+            Object o = getOptionValue(option, null);
+
+            if (o == null) {
+                return result;
+            }
+            else {
+                result.addElement(o);
+            }
+        }
+    }
+
+
+    /**
+     * @return the non-option arguments
+     */
+    public final String[] getRemainingArgs() {
+        return this.remainingArgs;
+    }
+
+    /**
+     * Extract the options and non-option arguments from the given
+     * list of command-line arguments. The default locale is used for
+     * parsing options whose values might be locale-specific.
+     */
+    public final void parse( String[] argv )
+        throws IllegalOptionValueException, UnknownOptionException {
+
+        // It would be best if this method only threw OptionException, but for
+        // backwards compatibility with old user code we throw the two
+        // exceptions above instead.
+
+        parse(argv, Locale.getDefault());
+    }
+
+    /**
+     * Extract the options and non-option arguments from the given
+     * list of command-line arguments. The specified locale is used for
+     * parsing options whose values might be locale-specific.
+     */
+    public final void parse( String[] argv, Locale locale )
+        throws IllegalOptionValueException, UnknownOptionException {
+
+        // It would be best if this method only threw OptionException, but for
+        // backwards compatibility with old user code we throw the two
+        // exceptions above instead.
+
+        Vector otherArgs = new Vector();
+        int position = 0;
+        this.values = new Hashtable(10);
+        while ( position < argv.length ) {
+            String curArg = argv[position];
+            if ( curArg.startsWith("-") ) {
+                if ( curArg.equals("--") ) { // end of options
+                    position += 1;
+                    break;
+                }
+                String valueArg = null;
+                if ( curArg.startsWith("--") ) { // handle --arg=value
+                    int equalsPos = curArg.indexOf("=");
+                    if ( equalsPos != -1 ) {
+                        valueArg = curArg.substring(equalsPos+1);
+                        curArg = curArg.substring(0,equalsPos);
+                    }
+                } else if(curArg.length() > 2) {  // handle -abcd
+                    for(int i=1; i<curArg.length(); i++) {
+                        Option opt=(Option)this.options.get
+                            ("-"+curArg.charAt(i));
+                        if(opt==null) throw new 
+                            UnknownSuboptionException(curArg,curArg.charAt(i));
+                        if(opt.wantsValue()) throw new
+                            NotFlagException(curArg,curArg.charAt(i));
+                        addValue(opt, opt.getValue(null,locale));
+                        
+                    }
+                    position++;
+                    continue;
+                }
+                
+                Option opt = (Option)this.options.get(curArg);
+                if ( opt == null ) {
+                    throw new UnknownOptionException(curArg);
+                }
+                Object value = null;
+                if ( opt.wantsValue() ) {
+                    if ( valueArg == null ) {
+                        position += 1;
+                        if ( position < argv.length ) {
+                            valueArg = argv[position];
+                        }
+                    }
+                    value = opt.getValue(valueArg, locale);
+                }
+                else {
+                    value = opt.getValue(null, locale);
+                }
+
+                addValue(opt, value);
+
+                position += 1;
+            }
+            else {
+                otherArgs.addElement(curArg);
+                position += 1;
+            }
+        }
+        for ( ; position < argv.length; ++position ) {
+            otherArgs.addElement(argv[position]);
+        }
+
+        this.remainingArgs = new String[otherArgs.size()];
+        otherArgs.copyInto(remainingArgs);
+    }
+
+
+    private void addValue(Option opt, Object value) {
+        String lf = opt.longForm();
+
+        Vector v = (Vector)values.get(lf);
+
+        if (v == null) {
+            v = new Vector();
+            values.put(lf, v);
+        }
+
+        v.addElement(value);
+    }
+
+
+    private String[] remainingArgs = null;
+    private Hashtable options = new Hashtable(10);
+    private Hashtable values = new Hashtable(10);
+}
\ No newline at end of file

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-06-09 19:57:17 UTC (rev 111568)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Generator.java	2011-06-09 20:57:52 UTC (rev 111569)
@@ -31,6 +31,9 @@
 import org.jboss.jmx.adaptor.snmp.config.attribute.MappedAttribute;
 import org.jboss.jmx.adaptor.snmp.config.attribute.AttributeMappings;
 import org.jboss.jmx.adaptor.snmp.config.attribute.ManagedBean;
+import org.jboss.jmx.adaptor.snmp.config.notification.Mapping;
+import org.jboss.jmx.adaptor.snmp.config.notification.VarBind;
+import org.jboss.jmx.adaptor.snmp.config.notification.VarBindList;
 
 import javax.management.ObjectName;
 
@@ -57,11 +60,17 @@
 
 public class Generator {
 	private String outputResName; // the name of the output file (.mib or .xml)
+	private ArrayList<MIBObject> miboList; // internal list of MIBObjects
+	private ArrayList<MIBNotification> mibnList;
+	private ArrayList<MappedAttribute> maList; // list of Mapped Attributes we care about
+	private ArrayList<Mapping> nmList; // list of notification mappings we care about
+	private ArrayList<VarBind> vbList;
 	private AttributeMappings mbList;
-	private ArrayList<MIBObject> miboList; //internal list of MIBObjects
-	private ArrayList<MappedAttribute> maList;
-	private HashMap<String, OIDDef> oidDefMap;		
+	//private MBeanServer server; // used when this class is created in the snmp-adaptor itself
 	
+	private HashMap<String, OIDDef> oidDefMap;	
+
+	
 	/** 
 	 * Default constructor. Nulls all around.
 	 */
@@ -73,11 +82,27 @@
 		this.maList = null;
 	}
 	
+	/**
+	 * Constructor for use when also parsing Notifications.xml
+	 * @param outputResName the output filename
+	 * @param maList list of MappedAttributes received from the parser 
+	 * @param mbList list of ManagedBeans, can be null if we're generating an XML from an MIB
+	 * @param nmList list of notifications received from the parser
+	 */
+	
+	public Generator(String outputResName, ArrayList<MappedAttribute> maList, AttributeMappings mbList, ArrayList<Mapping> nmList){
+		this.outputResName = outputResName;
+		this.mbList = mbList;
+		this.miboList = new ArrayList<MIBObject>();
+		this.maList = maList;
+		this.oidDefMap = new HashMap<String, OIDDef>();
+		this.nmList = nmList;
+	}
+	
 	/** 
-	 * Most used constructor. 
+	 * Most used constructor. only attributes from the parser
 	 * 
-	 * @param outputResName the filename, can be either .mib or .xml. This extension will decide which type of 
-	 * file is produced by this class.
+	 * @param outputResName the output filename
 	 * @param maList the list of MappedAttributes, received from the Parser.
 	 * @param mbList the list of ManagedBeans. This can be null if, for example, we're parsing an MIB.
 	 */
@@ -88,7 +113,6 @@
 		this.miboList = new ArrayList<MIBObject>();
 		this.maList = maList;
 		this.oidDefMap = new HashMap<String, OIDDef>();
-		
 	}
 	
 	//mutators
@@ -126,24 +150,28 @@
 
 	/** 
 	 * Entry point method. Called by MIBGenerator class after all of the parsing is completed. 
-	 * Does nothing really itself. Which methods are called depends on the name of the output file.
+	 * Does nothing really itself. Which methods are called depends on the -r flag.
 	 */
 
-	public void writeFile(){
+	public void writeFile(boolean reverse){
 		try{
 			PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputResName)));
-			if (outputResName.matches("\\.mib$")){
-				createOidDefinitions();
+			if (!reverse){
 				createMibObjects();
+				//createMibNotifications();
 				writeMibHeader(out);
 				writeMibImports(out);
-				writeMibDefinitions(out);
+				writeMibObjectDefinitions(out);
 				writeMibObjects(out);
+				//writeMibNotificationDefinitions(out);
+				//writeMibNotifications(out);
+				out.println("END");
 			}
-			else if (outputResName.matches("\\.xml$")){
+			else {
 				writeXmlHeader(out);
 				writeXmlDefinitions(out);
 			}
+			
 			out.close();
 		}
 		catch (Exception e){e.printStackTrace();}
@@ -160,7 +188,7 @@
 		out.println();
 		out.println("JBOSS-AS-MIB DEFINITIONS ::=BEGIN");
 		out.println();
-		// maybe add more here, if notrrayList we don't need this to be a seperate method.
+		// maybe add more here, if not we don't need this to be a seperate method.
 	}
 	
 	/**
@@ -186,27 +214,19 @@
 	}
 	
 	/** 
-	 *  This method outputs all of the OID definitions we need in order for a manager
+	 *  This method outputs all of the Object OID definitions we need in order for a manager
 	 *  that loads the generated MIB to be able to know the names of metrics it is getting back.
 	 *  TODO: enable exact configuration of this section
 	 * @param out The PrintWriter that writes to the file we need it to
 	 * @author <a href="mailto:tom.hauser at gmail.com>Tom Hauser</a>
 	 */	
-	private void writeMibDefinitions(PrintWriter out){
-		/*org             OBJECT IDENTIFIER ::= { iso 3 }
-		dod             OBJECT IDENTIFIER ::= { org 6 }
-		internet        OBJECT IDENTIFIER ::= { dod 1 }
-
-		private         OBJECT IDENTIFIER ::= { internet 4 }
-		enterprise      OBJECT IDENTIFIER ::= { private 1 }
-		redhat          OBJECT IDENTIFIER ::= { enterprise 2312 }
-		jboss           OBJECT IDENTIFIER ::= { redhat 100 }
-		as              OBJECT IDENTIFIER ::= { jboss 1 }*/
+	private void writeMibObjectDefinitions(PrintWriter out){
 		Set<String> oidKeySet = oidDefMap.keySet();
 		Iterator<String> oidIt = oidKeySet.iterator();
 		while (oidIt.hasNext()){
 			out.println(oidDefMap.get(oidIt.next()));
 		}
+		out.println();
 	}
 	
 	/**
@@ -219,7 +239,6 @@
 		while (aIt.hasNext()){
 			out.println(aIt.next());
 		}
-		out.println("END");
 	}
 	
 	/**
@@ -233,25 +252,19 @@
 			MIBObject mibO = new MIBObject(aIt.next());
 			miboList.add(mibO);
 		}
-	}		
+	}	
 	
 	/** 
-	 * Method to create initial OID Definitions, to be at the top of the file in order to allow 
-	 * a manager to know the name of recieved metrics. 
-	 * TODO: make this user configurable, through a file or some such.
+	 * This method generates a list of MIBNotifications from a given ArrayList of Mappings from the parser,
+	 * and adds it to this instance's list of MIBNotifications for writing to the file
 	 */
 	
-	private void createOidDefinitions(){		
-		// expansion: make a way to discover these, rather than hardcoding them. 
-		// suggestion: add a map of oid-prefixes from the attributes.xml and create OIDDefs out of those.
-		// then how do we get names? :( 
-		// create ones we know about first
-		String as = "1.3.6.1.4.1.2312.100.1";
-		String system = "1.3.6.1.2.1.1";
-		OIDDef jbossas = new OIDDef("as", as);
-		OIDDef mib2system = new OIDDef("system", system);
-		this.oidDefMap.put(as, jbossas);
-		this.oidDefMap.put(system, mib2system);
+	private void createMibNotifications(){
+		Iterator<Mapping> mIt = nmList.iterator();
+		while (mIt.hasNext()){
+			MIBNotification mibN = new MIBNotification(mIt.next());
+			mibnList.add(mibN);
+		}
 	}
 	
 	/** 
@@ -270,7 +283,7 @@
 	
 	/* Internal Classes ----- */
 	
-	
+
 	/** 
 	 * Internal class used to represent a single MIB Object. Created by reading the required 
 	 * data from a MappedAttribute object, and filling in the rest.
@@ -282,6 +295,7 @@
 		private String status;
 		private String description;
 		private String objectId; 
+		private String fullOid;
 		private String oidDef;
 			
 		MIBObject(MappedAttribute ma){
@@ -317,7 +331,7 @@
 			// We need the last element in the array to be the registered OID, so we can put the correct 
 			// name in the output MIB
 			this.objectId = temp[temp.length-1];
-						
+			this.fullOid = ma.getOidPrefix() + this.objectId;
 			// check if there is already an OID definition for this prefix. If there is make this MIBObject's 
 			// oidDef reflect that
 			if (oidDefMap.containsKey(ma.getOidPrefix())){
@@ -325,13 +339,31 @@
 			}
 			// if they aren't part of the Map, then we add them to the map with a filler name "CHANGE-ME"
 			// as there is no way to glean this name from the attributes.xml without 
-			// complexifying it a great deal, OR making them configurable in another file (a very good possibility)
+			// complexifying it
 			else{
-				OIDDef newOidDef = new OIDDef("CHANGE-ME", ma.getOidPrefix());
-				oidDefMap.put(ma.getOidPrefix(), newOidDef);
+				if (ma.getOidDefName() != null){
+					// the name to be used is in the attributes.xml. use it.
+					OIDDef newOidDef = new OIDDef(ma.getOidDefName(), ma.getOidPrefix());
+					oidDefMap.put(ma.getOidPrefix(), newOidDef);
+					this.oidDef=ma.getOidDefName();
+				}
+				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", ma.getOidPrefix());
+					oidDefMap.put(ma.getOidPrefix(), newOidDef);
+					this.oidDef="UNKNOWN";
+				}
 			}
 		}
 		
+		public String getName(){
+			return this.name;
+		}
+		
+		public String getFullOid(){
+			return this.fullOid;
+		}
+			
 		@Override
 		public String toString(){
 			StringBuffer buf = new StringBuffer();
@@ -353,6 +385,132 @@
 		}
 	}
 	
+	/** 
+	 * Internal class for generating an MIB Notification from a notification mapping parsed from the notification.xml
+	 * @author <a href="mailto:tom.hauser at gmail.com>Tom Hauser 
+	 */
+	
+		private class MIBNotification{
+			private String name; 
+			private String status;
+			private String description;
+			private String oidDef;
+			private String objectId;
+			private ArrayList<String> objects;
+			
+			public MIBNotification(Mapping mp){
+				this.name = mp.getName();
+				this.status = "current";
+				this.description = ""; // TODO: improve this!!
+				ArrayList<VarBind> vbList = (ArrayList<VarBind>)mp.getVarBindList().getVarBindList();
+				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";
+				this.objectId = "."+String.valueOf(mp.getSpecific());
+				// check if there is already an OID definition for this prefix. If there is make this MIBObject's 
+				// oidDef reflect that
+				if (oidDefMap.containsKey(oidPrefix)){
+					this.oidDef = oidDefMap.get(oidPrefix).getName();
+				}
+				// if they aren't part of the Map, then we add them to the map
+				else{
+					if (mp.getName() != null){
+						// the name to be used is in the xml being parsed. use it.
+						OIDDef newOidDef = new OIDDef(mp.getName(),oidPrefix);
+						oidDefMap.put(oidPrefix, newOidDef);
+						this.oidDef=mp.getName();
+					}
+					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";
+					}
+				}
+			}
+			
+			public void setName(String name){
+				this.name = name;
+			}
+			
+			public String getName(){
+				return this.name;
+			}
+			
+			public void setDescription(String description){
+				this.description = description;
+			}
+			
+			public String getDescription(){
+				return this.description;
+			}
+			
+			public void setObjects(ArrayList<VarBind> vbList){
+				Iterator vbIt = vbList.iterator();
+				ArrayList<String> oids = new ArrayList<String>(10);
+				while(vbIt.hasNext()){
+					VarBind vb = (VarBind)vbIt.next();
+					oids.add(vb.getOid());					
+				}					
+				// have all the oids. compare these to the MIBObject's full OID. if it fails, 
+				// put OID into the Objects ArrayList.
+				Iterator<MIBObject> miboIt = miboList.iterator();
+				Iterator<String> oidIt = oids.iterator();
+				
+				// regrettably nested iterator queries. needed to 
+				while (oidIt.hasNext()){
+					while (miboIt.hasNext()){
+						MIBObject mibo = miboIt.next();
+						String oidString = oidIt.next();
+						if (oidString.equals(mibo.getFullOid())){
+							this.objects.add(mibo.getName());
+							continue;
+						}
+					// if we get here; there is no matching MIBObject for this oid. add the oid itself.
+					this.objects.add(oidString);
+					}
+				}
+			}
+			
+			public ArrayList<String> getObjects(){
+				return this.objects;
+			}
+			
+			public String printObjects(){
+				StringBuffer buf = new StringBuffer();
+				buf.append("{ ");
+				int index = 0;
+				while (index < this.objects.size()){
+					if (index == this.objects.size()-1)
+						buf.append(this.objects.get(index));
+					else
+						buf.append(this.objects.get(index)).append(",\n");
+				}
+				
+				buf.append(" }");
+				return buf.toString();
+			
+			}
+			
+			@Override
+			public String toString(){
+				StringBuffer buf = new StringBuffer();
+				buf.append(this.name+" NOTIFICATION-TYPE\n");
+				buf.append("\tOBJECTS ").append(printObjects());
+				buf.append("\tSTATUS ").append(this.status);
+				buf.append("\n");
+				buf.append("\tDESCRIPTION ");
+				buf.append("\n\t\t");
+				buf.append("\""+this.description+"\"");
+				buf.append("\n");
+				buf.append("::= {").append(" ");
+				buf.append(this.oidDef + " " + this.objectId  + " }");
+				buf.append("\n");
+				return buf.toString();
+			}
+		}
+	
 	/**
 	 * Internal class for keeping track of an OID Definition (used at the top of an MIB for naming purposes)
 	 * see http://www.simpleweb.org/ietf/mibs/modules/IETF/txt/SNMPv2-SMI 
@@ -361,14 +519,14 @@
 	 */
 	
 		private class OIDDef{
-			private String name; // the name of the OID, as dictated by the naming standard
+			private String name; // the name of the OID definition
 			private String definition; // the OID with '.' replaced by ' ', ready to be output into the MIB
 			private String rawOid; // the full dotted-string oid, untouched.
 			
 			public OIDDef(String name, String oid){
 				this.name = name;
-				this.rawOid = oid;
-				this.definition = parseDefinition(oid);
+				setRawOid(oid);
+				setDefinition();
 			}
 			
 			//mutators
@@ -384,18 +542,27 @@
 				return this.definition;
 			}
 			 
-			public void setDefinition(String def){
-				this.definition = def;
+			public void setDefinition(){
+				String temp = "{ ";
+				temp += this.rawOid;
+				temp += "}";
+				this.definition = temp;
 			}
 			
-			// returns a string with the '.' turned into ' '
-			public String parseDefinition(String oid){
-				String[] tokens = oid.split("\\.");
-				String temp = "{ ";
-				for (int i = 0; i < tokens.length;i++){
-					temp += tokens[i]+" ";
+			public void setRawOid(String oid){
+				String [] tokens = oid.split("\\.");
+				this.rawOid = replaceDottedOid(tokens).trim()+ " ";		
+			}
+			
+			public String getRawOid(){
+				return this.rawOid;
+			}
+			
+			private String replaceDottedOid(String [] tokens){
+				String temp = "";
+				for (int i = 0; i < tokens.length; i++){
+					temp+=tokens[i].trim()+" ";
 				}
-				temp += "}";
 				return temp;
 			}
 			
@@ -403,26 +570,11 @@
 			public String toString(){
 				StringBuffer buf = new StringBuffer();
 				buf.append(this.name);
-				buf.append("\t\tOBJECT IDENTIFIER ::= ");
+				buf.append("\t\tOBJECT IDE" +
+						"NTIFIER ::= ");
 				buf.append(this.definition);
 				return buf.toString();
 			}
-			
-			// used to compare OIDdefs. if their rawOid is equal, they are equal. Otherwise, they're not equal, even if 
-			// they have the same name and the same definition.
-			@Override
-			public boolean equals(Object other){
-			    if (other == null) return false;
-			    if (other == this) return true;
-			    if (this.getClass() != other.getClass())return false;
-			    OIDDef otherDef = (OIDDef)other;
-			    if(otherDef.rawOid == this.rawOid)
-			    	return true;
-			    else
-			    	return false;
-			}
-
-
 		}//end OIDDef
 	
 

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-06-09 19:57:17 UTC (rev 111568)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/MIBGenerator.java	2011-06-09 20:57:52 UTC (rev 111569)
@@ -34,11 +34,7 @@
 package org.jboss.jmx.adaptor.snmp.generator;
 
 public class MIBGenerator {
-	static Parser parser; // XMLParser instantiation that parses the xml
-	static Generator generator; // generator that outputs the mib or xml
-	
 	/**
-	 *
 	 * Get the filenames from the command line. Parse the input file, whether it be an mib or an xml. 
 	 * Create the needed objects for either one, and create a new generator object with the information.
 	 * Write the file using the generator. 
@@ -48,39 +44,42 @@
 	 * @author Tom Hauser
 	 */
 	public static void main (String [] args){
-		 sanitizeParams(args);
-		 parser = new Parser(args[0]);
-		 parser.parse();
-		 generator = new Generator(args[1], parser.getMaList(), parser.getMbList());
-		 generator.writeFile();		
+		CmdLineParser cmdParser = new CmdLineParser();
+		/*
+		 * Adds the desired options to the command line parser.
+		 * Options:
+		 * 		-h , --help : display the usage information
+		 * 		-r , --reverse : convert an MIB into an XML, as opposed to XML into MIB
+		 *   	-s , --snmptype : preserve snmp types gleaned from parsing the MIB. (only usable with -r)
+		 *   	-a , --append : do not overwrite the existing MIB; instead, add the newly parsed attributes to it. 
+		 * 		--import=<FILENAME> : add the import entries contained in the file to the MIB named by FILENAME to the produced MIB (valid only for xml -> mib)
+		 * 		--oiddef=<FILENAME> : add the OID definitions in the given file to the generator
+		 */
+		CmdLineParser.Option help = cmdParser.addBooleanOption('h', "help");
+		CmdLineParser.Option reverse = cmdParser.addBooleanOption('r', "reverse");
+	 	CmdLineParser.Option snmptype = cmdParser.addBooleanOption('s', "snmptype");
+	 	CmdLineParser.Option append = cmdParser.addBooleanOption('a', "append");
+	 	CmdLineParser.Option importOpt = cmdParser.addStringOption('i', "import");
+	 	CmdLineParser.Option oiddef = cmdParser.addStringOption('o', "oiddef");
+		
+	 	try {
+	 		cmdParser.parse(args);
+	 	}
+	 	catch (Exception e){
+	 		printUsageMessage();
+	 	}
+	 	
+	 	Boolean reverseVal = (Boolean)cmdParser.getOptionValue(reverse, Boolean.FALSE);
+	 	String [] remArgs = cmdParser.getRemainingArgs();
+		Parser parser = new Parser(remArgs[0], remArgs[1]);
+		parser.parse(reverseVal);
+		Generator generator = new Generator(remArgs[2], parser.getMaList(), parser.getMbList(), parser.getNmList());
+		generator.writeFile(reverseVal);		
 	}
 	
-	private static void sanitizeParams(String [] args){
-		if (args[0].equals("-help") || args.length != 2){
-			System.out.println(displayHelpMessage());
-			System.exit(1);
-		}
-		else if ((!args[0].matches("\\.mib$") || !args[0].matches("\\.xml$")) 
-			  && (!args[1].matches("\\.mib$") || !args[1].matches("\\.xml$"))){
-			System.out.println("Invalid filetypes entered. Please follow the guidelines below.");
-			System.out.println(displayHelpMessage());
-			System.exit(2);
-		}
-		else if ((args[0].matches("\\.mib$") && args[1].matches("\\.mib$"))
-			  || (args[0].matches("\\.xml$") && args[1].matches("\\.xml$"))){
-			System.out.println("The input/output filetypes are the same. This is not permitted.");
-			System.out.println(displayHelpMessage());
-			System.exit(3);
-		}
-	}
 	
-	private static String displayHelpMessage(){
-		StringBuffer buf = new StringBuffer();
-		buf.append("Usage:  \t-help : Display this message\n");
-		buf.append("Example:\tjava -jar jboss-as-varia-mib-generator.jar inputFile.{mib,xml} outputFile.{mib,xml}\n");
-		buf.append("Note: The types must be opposites. If you wish to convert from xml to mib, the first\n");
-		buf.append("file should have the .xml extension, and the second should have the .mib extension.");
-		return buf.toString();
+	private static String printUsageMessage(){
+		return "";
 	}
 	
 }
\ No newline at end of file

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-06-09 19:57:17 UTC (rev 111568)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Parser.java	2011-06-09 20:57:52 UTC (rev 111569)
@@ -31,7 +31,8 @@
 import org.jboss.jmx.adaptor.snmp.config.attribute.MappedAttribute;
 import org.jboss.jmx.adaptor.snmp.config.attribute.AttributeMappings;
 import org.jboss.jmx.adaptor.snmp.config.attribute.ManagedBean;
-import org.jboss.jmx.adaptor.snmp.generator.ParserBindings;
+import org.jboss.jmx.adaptor.snmp.config.notification.Mapping;
+import org.jboss.jmx.adaptor.snmp.generator.ParserAttributeBindings;
 
 import org.jboss.xb.binding.ObjectModelFactory;
 import org.jboss.xb.binding.Unmarshaller;
@@ -40,29 +41,54 @@
 /**
  * This class is used by the MIBGenerator to get the initial list of MappedAttributes out of an input file. 
  * 
+ * TODO: allow for the parser to have a list of files and implement an object that can hold all needed data for the generator
+ * inside it for each file. This will allow the generator to amalgate attribute definitions from deployed webapps once that 
+ * feature has been implemented. 
+ * 
  * @author<a href="mailto:tom.hauser at gmail.com"> or <a href="mailto:thauser at redhat.com">Tom Hauser
  *
  */
 
 public class Parser {
-	String inputFile;
+	String inputAttrFile;
+	String inputNotificationFile;
 	ArrayList<MappedAttribute> maList; 
+	ArrayList<Mapping> nmList;//list of notifications that we care about.
 	AttributeMappings mbList; 
 	
-	public Parser(String inputFile){
-		this.inputFile = inputFile;
+	// constructor with a single input file; simple, just parse this one file.
+	public Parser(String inputAttrFile){
+		this.inputAttrFile = inputAttrFile;
+		this.inputNotificationFile = null;
 		maList = new ArrayList<MappedAttribute>(10);
 		mbList = new AttributeMappings();
+		
 	}
+	
+	public Parser(String inputAttrFile, String inputNotificationFile){
+		this.inputAttrFile = inputAttrFile;
+		this.inputNotificationFile = inputNotificationFile;
+		maList = new ArrayList<MappedAttribute>(10);
+		mbList = new AttributeMappings();
+		nmList = new ArrayList<Mapping>(10);
+	}
 	 
-	public String getInputFile(){
-		return this.inputFile;
+	public String getNotiFile(){
+		return this.inputNotificationFile;
 	}
 	
-	public void setInputFile(String inputFile){
-		this.inputFile = inputFile;		
+	public void setNotiFile(String inputNotiFile){
+		this.inputNotificationFile = inputNotiFile;		
 	}
 	
+	public String getAttrFile(){
+		return this.inputAttrFile;
+	}
+	
+	public void setAttrFile(String inputAttrFile){
+		this.inputAttrFile = inputAttrFile;		
+	}
+	
 	public ArrayList<MappedAttribute> getMaList(){
 		return this.maList;
 	}
@@ -78,29 +104,73 @@
 	public void setMbList(AttributeMappings mbList){
 		this.mbList = mbList;
 	}
+	
+	public ArrayList<Mapping> getNmList(){
+		return this.nmList;
+	}
+	
+	public void setNmList(ArrayList<Mapping> nmList){
+		this.nmList = nmList;
+	}
 
 	/**
 	 * Based on the name of the input / output file, we either parse
 	 * an MIB or an XML, and from this construct a nescessary ArrayList of ManagedAttributes to write out	 
 	 * */
 	
-	public void parse(){
+	public void parse(boolean reverse){
 		// TODO: refine the checks here. they are not enough 
-		if (inputFile.contains(".mib")){
-			parseMib();
-		}
-		else if (inputFile.contains(".xml")){
+		if (!reverse){
 			try {
-			parseXml();
+			parseAttributesXml();
+			if (this.inputNotificationFile !=null)
+				parseNotificationsXml();
 			}
 			catch (Exception e){
-				System.out.println("Exception in parseXml:");
 				e.printStackTrace();
 				System.exit(1);				
 			}
+		}
+		else{
+			parseMib();
 		}		
 	}
 	
+	
+	private void parseNotificationsXml() throws Exception{
+		ObjectModelFactory omf = new ParserNotificationBindings();
+		InputStream is = null;
+		ArrayList<Mapping> mappings = null;
+		try{
+			is = new FileInputStream(this.inputNotificationFile);
+			
+			Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+			
+			mappings = (ArrayList)unmarshaller.unmarshal(is,omf,null);
+		}
+		catch (Exception e){
+			throw e;
+		}
+		finally{
+			if (is!=null){
+				try{
+					is.close();
+				}
+				catch (Exception e){
+					throw e;
+				}
+			}
+		}
+		if (mappings == null){
+			return;
+		}
+		
+		// mappings recieved! add them to our nmList
+		Iterator<Mapping> mIt = mappings.iterator();
+		while (mIt.hasNext()){
+			nmList.add(mIt.next());
+		}
+	}//end parseNotificationXml
 	/**
 	 * All work is done here, using ObjectModelFactory. ParseBindings is used to define how the given xml is parsed, 
 	 * and creates a AttributeMappings object, which is then used to add all ManagedAttributes along with their associated
@@ -108,13 +178,13 @@
 	 *
 	 * @throws Exception
 	 */
-	private void parseXml() throws Exception{
-		ObjectModelFactory omf = new ParserBindings();
+	private void parseAttributesXml() throws Exception{
+		ObjectModelFactory omf = new ParserAttributeBindings();
 		InputStream is = null;
 		AttributeMappings mappings = null;
 		try{
 		   // locate resource
-		   is = new FileInputStream(this.inputFile);
+		   is = new FileInputStream(this.inputAttrFile);
 		   
 		   // create unmarshaller
 		   Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
@@ -146,6 +216,7 @@
 			while (it.hasNext()){
 			   ManagedBean mmb = (ManagedBean)it.next();
 			   String oidPrefix = mmb.getOidPrefix();
+			   String oidDefName = mmb.getOidDefinition();
 			   List attrs = mmb.getAttributes();
 			   Iterator aIt = attrs.iterator();
 			   while (aIt.hasNext()){
@@ -153,12 +224,13 @@
 				  
 				  MappedAttribute ma = (MappedAttribute)check;
 
-				  if (oidPrefix != null){
+				  if (oidPrefix != null)
 					  ma.setOidPrefix(oidPrefix);
-				  }
-				  else{
+				  else
 					  ma.setOidPrefix(removeLast(ma.getOid()));
-				  }
+				  
+				  ma.setOidDefName(oidDefName);
+				  			  
 				  // for the MIB Generator
 				  ma.setMbean(mmb.getName());
 				  maList.add(ma);	  

Copied: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserAttributeBindings.java (from rev 111559, branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserBindings.java)
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserAttributeBindings.java	                        (rev 0)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserAttributeBindings.java	2011-06-09 20:57:52 UTC (rev 111569)
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.generator;
+
+import java.util.ArrayList;
+
+import org.jboss.jmx.adaptor.snmp.config.attribute.AttributeMappings;
+import org.jboss.jmx.adaptor.snmp.config.attribute.ManagedBean;
+import org.jboss.jmx.adaptor.snmp.config.attribute.MappedAttribute;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.UnmarshallingContext;
+import org.xml.sax.Attributes;
+
+/**
+ * Parse the mapping of JMX mbean attributes to SNMP OIDs
+ * 
+ *      </mbean>
+ * 
+ * @author <a href="mailto:tom.hauser at gmail.com>Tom Hauser</a>
+ * @version $Revision: 111505 $
+ */
+public class ParserAttributeBindings implements ObjectModelFactory
+{
+	
+	public Object newRoot(Object root, UnmarshallingContext ctx,
+			String namespaceURI, String localName, Attributes attrs)
+   {
+	   if (!localName.equals("attribute-mappings"))
+      {
+	      throw new IllegalStateException("Unexpected root " + localName + ". Expected <attribute-mappings>");
+		}
+	   return new AttributeMappings();
+	}
+
+	public Object completeRoot(Object root, UnmarshallingContext ctx, String uri, String name)
+   {
+	   return root;
+	}
+
+	public void setValue(AttributeMappings mappings, UnmarshallingContext navigator,
+		      String namespaceUri, String localName, String value)
+	{
+	}	
+	
+	public Object newChild(AttributeMappings mappings, UnmarshallingContext navigator,
+			String namespaceUri, String localName, Attributes attrs)
+	{
+		if ("mbean".equals(localName))
+      {
+			String name = attrs.getValue("name");
+			String oidPrefix = attrs.getValue("oid-prefix");
+			String oidDefinition = attrs.getValue("definition-name");
+			ManagedBean child = new ManagedBean();
+			child.setName(name);
+			child.setOidPrefix(oidPrefix);
+			child.setOidDefinition(oidDefinition);// the name of the oid definition to put into the mib
+			return child;
+		}
+		return null;
+	}
+	
+	public void addChild(AttributeMappings mappings, ManagedBean mbean,
+			UnmarshallingContext navigator, String namespaceURI, String localName) 
+	{
+		mappings.addMonitoredMBean(mbean);
+	}
+	
+	public Object newChild(ManagedBean mbean, UnmarshallingContext navigator,
+			String namespaceUri, String localName, Attributes attrs)
+	{
+		
+		MappedAttribute attribute = null;
+		if ("attribute".equals(localName)) {
+			String oid = attrs.getValue("oid");
+			String name = attrs.getValue("name");
+			String mode = attrs.getValue("mode");
+			String snmpType = attrs.getValue("snmp-type");
+			attribute = new MappedAttribute();
+			if ("rw".equalsIgnoreCase(mode))
+            attribute.setReadWrite(true);
+			attribute.setName(name);
+			attribute.setOid(oid);
+			attribute.setSnmpType(snmpType);
+		}
+		return attribute;
+	}
+	
+	public void addChild(ManagedBean mbean, MappedAttribute attribute,
+			UnmarshallingContext navigator, String namespaceURI, String localName)
+	{
+		if (mbean.getAttributes() == null)
+         mbean.setAttributes(new ArrayList());
+		
+		mbean.getAttributes().add(attribute);
+	}
+}

Added: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserNotificationBindings.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserNotificationBindings.java	                        (rev 0)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserNotificationBindings.java	2011-06-09 20:57:52 UTC (rev 111569)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.generator;
+
+import java.util.ArrayList;
+
+import org.jboss.jmx.adaptor.snmp.config.notification.Mapping;
+import org.jboss.jmx.adaptor.snmp.config.notification.VarBind;
+import org.jboss.jmx.adaptor.snmp.config.notification.VarBindList;
+import org.jboss.xb.binding.GenericObjectModelFactory;
+import org.jboss.xb.binding.UnmarshallingContext;
+import org.xml.sax.Attributes;
+
+	public class ParserNotificationBindings implements GenericObjectModelFactory {
+		// GenericObjectModelFactory implementation ----------------------
+
+		public Object completeRoot(Object root, UnmarshallingContext ctx,
+				String uri, String name) {
+			return root;
+		}
+
+		public Object newRoot(Object root, UnmarshallingContext navigator,
+				String namespaceURI, String localName, Attributes attrs) {
+			ArrayList notifList;
+
+			if (root == null) {
+				root = notifList = new ArrayList();
+			} else {
+				notifList = (ArrayList) root;
+			}
+			return root;
+		}
+
+		public Object newChild(Object parent, UnmarshallingContext navigator,
+				String namespaceURI, String localName, Attributes attrs) {
+			Object child = null;
+
+			if ("mapping".equals(localName)) {
+				Mapping m = new Mapping();
+				child = m;
+			} else if ("var-bind-list".equals(localName)) {
+				VarBindList vblist = new VarBindList();
+				child = vblist;
+				if (attrs.getLength() > 0) {
+					for (int i = 0; i < attrs.getLength(); i++) {
+						if ("wrapper-class".equals(attrs.getLocalName(i))) {
+							vblist.setWrapperClass(attrs.getValue(i));
+						}
+					}
+				}
+				// check that wrapper-class is set
+				if (vblist.getWrapperClass() == null) {
+					throw new RuntimeException(
+							"'wrapper-class' must be set at 'var-bind-list' element");
+				}
+			} else if ("var-bind".equals(localName)) {
+				VarBind vb = new VarBind();
+				child = vb;
+			}
+			return child;
+		}
+
+		public void addChild(Object parent, Object child,
+				UnmarshallingContext navigator, String namespaceURI,
+				String localName) {
+			if (parent instanceof ArrayList) {
+				ArrayList notifList = (ArrayList) parent;
+
+				if (child instanceof Mapping) {
+					notifList.add(child);
+				}
+			} else if (parent instanceof Mapping) {
+				Mapping m = (Mapping) parent;
+
+				if (child instanceof VarBindList) {
+					m.setVarBindList((VarBindList) child);
+				}
+			} else if (parent instanceof VarBindList) {
+				VarBindList vblist = (VarBindList) parent;
+
+				if (child instanceof VarBind) {
+					vblist.addVarBind((VarBind) child);
+				}
+			}
+		}
+
+		public void setValue(Object o, UnmarshallingContext navigator,
+				String namespaceURI, String localName, String value) {
+			if (o instanceof Mapping) {
+				Mapping m = (Mapping) o;
+
+				if ("notification-type".equals(localName)) {
+					m.setNotificationType(value);
+				} else if ("generic".equals(localName)) {
+					m.setGeneric(Integer.parseInt(value));
+				} else if ("specific".equals(localName)) {
+					m.setSpecific(Integer.parseInt(value));
+				} else if ("enterprise".equals(localName)) {
+					m.setEnterprise(value);
+				} else if ("inform".equals(localName)) {
+					m.setInform(Boolean.parseBoolean(value));
+				} else if ("security-name".equals(localName)) {
+					m.setSecurityName(value);
+				} else if ("name".equals(localName)){
+					m.setName(value);
+				}				
+			} else if (o instanceof VarBind) {
+				VarBind vb = (VarBind) o;
+
+				if ("tag".equals(localName)) {
+					vb.setTag(value);
+				} else if ("oid".equals(localName)) {
+					vb.setOid(value);
+				}
+			}
+		}
+
+		public Object completedRoot(Object root,
+				UnmarshallingContext navigator, String namespaceURI,
+				String localName) {
+			return root;
+		}
+	}
\ No newline at end of file



More information about the jboss-cvs-commits mailing list