/** Generates the code for the checker. */ protected void addChecker( Context ctxt, MibNode node, String description, String syntax, String var, StringBuffer buff) { buff.append( Def.TAB + "/**\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment.checker", var) + "\n" + Def.TAB + " */\n"); buff.append( Def.TAB + Def.PUBLIC + Def.VOID + Def.CHECK + var + "(" + syntax + "x) " + accessThrows); buff.append( Def.TAB2 + "//\n" + Def.TAB2 + "// " + MessageHandler.getMessage("generate.mbean.comment.checker.policy") + "\n" + Def.TAB2 + "//\n"); buff.append(Def.TAB + Def.RBRACE + "\n"); }
private void addRowStatusSetter( Context ctxt, MibNode node, String description, String syntax, String var, StringBuffer buff) { buff.append( Def.TAB + "/**\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment.setter", var) + "\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment." + "setter.rs.nochecker") + "\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment." + "checker.rs.override") + "\n" + Def.TAB + " */\n"); buff.append( Def.TAB + Def.PUBLIC + Def.VOID + Def.SET + var + "(" + syntax + "x) " + accessThrows); buff.append(Def.TAB2 + var + " = x" + Def.SEMICOLON); buff.append(Def.TAB + Def.RBRACE + "\n"); }
protected void buildConstructorHeader() throws IOException { constructor1.append( "\n" + Def.TAB + "/**\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment.constr", symboleName) + "\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment.noRegistration") + "\n" + Def.TAB + " */\n"); constructor1.append(Def.TAB + Def.PUBLIC + symboleName + "(SnmpMib myMib)" + Def.LBRACE); constructor2.append( "\n" + Def.TAB + "/**\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment.constr", symboleName) + "\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment.registration") + "\n" + Def.TAB + " */\n"); constructor2.append( Def.TAB + Def.PUBLIC + symboleName + "(SnmpMib myMib, MBeanServer server)" + Def.LBRACE); }
@Test public void test_incorrect() { System.out.println("--- Testing with incorrect input values --- "); final String inputMessage = "{\"sum\":123,\"days\":-5}"; handler.setPublisher( new Publisher() { public boolean publish(String message) { assert false; return true; } public void setQueue(String queue) {} }); try { handler.getMessage(inputMessage); assert false; } catch (Exception e) { System.out.println(e.getMessage()); assert true; } final String inputMessage2 = "{\"sum\":-123,\"days\":5}"; try { handler.getMessage(inputMessage2); assert false; } catch (Exception e) { System.out.println(e.getMessage()); assert true; } final String inputMessage3 = "{\"sum\":0,\"days\":5}"; try { handler.getMessage(inputMessage3); assert false; } catch (Exception e) { System.out.println(e.getMessage()); assert true; } final String inputMessage4 = "{\"sum\":123,\"days\":0}"; try { handler.getMessage(inputMessage4); assert false; } catch (Exception e) { System.out.println(e.getMessage()); assert true; } System.out.println("--- End of test ---"); System.out.println(); }
public MbeanGenerator(ResourceManager mgr, MibNode aGroup, Context ctxt) throws IOException { super(mgr, aGroup, ctxt); gentype = ctxt.gentype; // Specify oid of the current bean ... // oid = node.getComputedOid(); // Try to find a symbol to associate to the group // varName = node.getSymbolName(); if (varName == null) varName = getClassName(node.getComputedOid()); symboleName = getNodeSymbolName(node); Trace.info(MessageHandler.getMessage("generate.info.var", varName)); // Open the file which will represent the M-bean. // out = openFile(symboleName + Def.JAVA); // Write generic header ... // writeHeader(); // write our own header ... // writeClassDeclaration(); // write the beginning of the constructor // buildConstructorHeader(); }
private void addRowStatusChecker( Context ctxt, MibNode node, String description, String syntax, String var, StringBuffer buff) { buff.append( Def.TAB + "/**\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment.checker", var) + "\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment.checker.rs.deprecated") + "\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment.checker.rs.override") + "\n" + Def.TAB + " */\n"); buff.append( Def.TAB + Def.PUBLIC + Def.VOID + Def.CHECK + var + "(" + syntax + "x) " + BeanGenerator.accessThrows); buff.append( Def.TAB2 + "//\n" + Def.TAB2 + "// " + MessageHandler.getMessage("generate.mbean.comment.checker.rs.policy") + "\n" + Def.TAB2 + "//\n"); buff.append(Def.TAB + Def.RBRACE + "\n"); }
protected void addCacheVar(MibNode node, String syntax, long fixed, String init, String var) throws IOException { // Put some comments ... // var_list.append( Def.TAB + "/**\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment.varUse", var) + "\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment.varOid", node.getOid()) + "\n" + Def.TAB); if (fixed != -1) { var_list.append( " * " + MessageHandler.getMessage("generate.mbean.comment.varFix", String.valueOf(fixed)) + "\n" + Def.TAB); } // Shall we put the description in the generated code ? // if yes call the formatDescription method ... // The answer is yes if requested ! if (mib.isDescriptionOn()) { // Get the object definition associated to the node // ASTObjectTypeDefinition definition = node.getObjectType(); String description = definition.getDefinition().getDescription(); var_list.append(formatDescription(description)); } var_list.append(" */\n"); if (init == null) init = ""; // Declare the variable // var_list.append(Def.TAB + Def.PROTECTED + syntax + var + init + Def.SEMICOLON + "\n"); }
protected void writeClassDeclaration() throws IOException { // Add some comments // write( "/**\n" + " * " + MessageHandler.getMessage("generate.mbean.comment.desc", varName) + "\n" + " * " + MessageHandler.getMessage("generate.mbean.comment.oid", oid) + "\n" + " */\n"); write( Def.PUBLIC + Def.CLASS + symboleName + Def.IMPLEMENT + symboleName + Def.MBEANSUFFIX + ", " + Def.SERIALIZABLE + Def.LBRACE + "\n"); }
/** Generates the code for the getter. */ protected void addGetter( Context ctxt, MibNode node, String description, String syntax, String var, StringBuffer buff) { buff.append( Def.TAB + "/**\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment.getter", var) + "\n" + Def.TAB + " */\n"); buff.append(Def.TAB + Def.PUBLIC + syntax + Def.GET + var + "() " + accessThrows); buff.append(Def.TAB2 + Def.RETURN + var + Def.SEMICOLON); buff.append(Def.TAB + Def.RBRACE + "\n"); }
@Test public void test_correct() { System.out.println("--- Testing with correct input values --- "); final String inputMessage = "{\"sum\":123,\"days\":5}"; final String outputMessage = "{\"sum\":123,\"days\":5,\"interest\":18.45,\"totalSum\":141.45,\"token\":\"test_token\"}"; handler.setPublisher( new Publisher() { public boolean publish(String message) { System.out.println("Expected> " + outputMessage); System.out.println("Actual > " + message); assertTrue(message.equals(outputMessage)); return true; } public void setQueue(String queue) {} }); try { handler.getMessage(inputMessage); } catch (Exception e) { e.printStackTrace(); } final String inputMessage2 = "{\"sum\":383,\"days\":26}"; final String outputMessage2 = "{\"sum\":383,\"days\":26,\"interest\":283.42,\"totalSum\":666.42,\"token\":\"test_token\"}"; handler.setPublisher( new Publisher() { public boolean publish(String message) { System.out.println("Expected> " + outputMessage2); System.out.println("Actual > " + message); assertTrue(message.equals(outputMessage2)); return true; } public void setQueue(String queue) {} }); try { handler.getMessage(inputMessage2); } catch (Exception e) { e.printStackTrace(); } final String inputMessage3 = "{\"sum\":824,\"days\":8}"; final String outputMessage3 = "{\"sum\":824,\"days\":8,\"interest\":197.76,\"totalSum\":1021.76,\"token\":\"test_token\"}"; handler.setPublisher( new Publisher() { public boolean publish(String message) { System.out.println("Expected> " + outputMessage3); System.out.println("Actual > " + message); assertTrue(message.equals(outputMessage3)); return true; } public void setQueue(String queue) {} }); try { handler.getMessage(inputMessage3); } catch (Exception e) { e.printStackTrace(); } final String inputMessage4 = "{\"sum\":938,\"days\":235108086}"; final String outputMessage4 = "{\"sum\":938,\"days\":235108086,\"interest\":6321899682.56,\"totalSum\":6321900620.56,\"token\":\"test_token\"}"; handler.setPublisher( new Publisher() { public boolean publish(String message) { System.out.println("Expected> " + outputMessage4); System.out.println("Actual > " + message); assertTrue(message.equals(outputMessage4)); return true; } public void setQueue(String queue) {} }); try { handler.getMessage(inputMessage4); } catch (Exception e) { e.printStackTrace(); } final String inputMessage5 = "{\"sum\":387,\"days\":11}"; final String outputMessage5 = "{\"sum\":387,\"days\":11,\"interest\":119.97,\"totalSum\":506.97,\"token\":\"test_token\"}"; handler.setPublisher( new Publisher() { public boolean publish(String message) { System.out.println("Expected> " + outputMessage5); System.out.println("Actual > " + message); assertTrue(message.equals(outputMessage5)); return true; } public void setQueue(String queue) {} }); try { handler.getMessage(inputMessage5); } catch (Exception e) { e.printStackTrace(); } System.out.println("--- End of test ---"); System.out.println(); }
/** Process table. */ protected void handleTable(MibNode node) throws IOException { // create a table generator // TableBeanGenerator table = new TableBeanGenerator(manager, node, context); // The meta table generator is now created by the // MetaBeanGenerator, which is more logic. // // // MetaTableGenerator metatable= // // new MetaTableGenerator(manager, node, context); // create a table generator interface // // TableBeanIfGenerator tableIf= new TableBeanIfGenerator(manager, packageName, prefix, // targetDir, node, mib); // Get the entry name // String entry = table.getEntryName(); // Get the table name // String tableName = table.getTableClassName(); // Name of the symbol // String variable = table.getSymbolName(); // Add cache variable for storing table // addCacheVar(node, tableName, (long) -1, null, variable); // Initialize the table in the constructor // constructor1.append( Def.TAB2 + variable + " = " + Def.NEW + tableName + "(myMib)" + Def.SEMICOLON); constructor2.append( Def.TAB2 + variable + " = " + Def.NEW + tableName + "(myMib, server)" + Def.SEMICOLON); // Add access method on the table // accessors.append( Def.TAB + "/**\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment.table.access", variable) + "\n" + Def.TAB + " */\n"); accessors.append( Def.TAB + Def.PUBLIC + tableName + Def.ACCESS + variable + "() " + accessThrows); accessors.append( Def.TAB2 + Def.RETURN + variable + Def.SEMICOLON + Def.TAB + Def.RBRACE + "\n"); // Show the table as an indexed property... // accessors.append( Def.TAB + "/**\n" + Def.TAB + " * " + MessageHandler.getMessage("generate.mbean.comment.table.entry", variable) + "\n" + Def.TAB + " */\n"); accessors.append( Def.TAB + Def.PUBLIC + entry + Def.MBEANSUFFIX + "[] " + Def.GET + variable + "() " + accessThrows); accessors.append( Def.TAB2 + Def.RETURN + variable + ".getEntries()" + Def.SEMICOLON + Def.TAB + Def.RBRACE + "\n"); }
// Specify the version of mibgen used for generating the code // protected void writeVersion() throws IOException { String msgid = "generate.version"; write("\n//\n// " + MessageHandler.getMessage(msgid, mib.getModuleName()) + "\n//\n\n"); }