hammant 2002/09/28 14:43:39 Modified: metagenerate build.xml metagenerate/src/java/org/apache/avalon/excalibur/metagenerate MetaGenerateQdoxTask.java XinfoFactory.java XinfoHelper.java metagenerate/src/test/org/apache/avalon/excalibur/metagenerate IntegrationTestCase.java Added: metagenerate/src/java/org/apache/avalon/excalibur/metagenerate AbstractHelper.java MxinfoFactory.java MxinfoHelper.java metagenerate/src/test/org/apache/avalon/excalibur/metagenerate TestMBean.java Log: Mxinfo capability Revision Changes Path 1.3 +1 -0 jakarta-avalon-excalibur/metagenerate/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/metagenerate/build.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- build.xml 28 Sep 2002 10:43:39 -0000 1.2 +++ build.xml 28 Sep 2002 21:43:38 -0000 1.3 @@ -169,6 +169,7 @@ <copy todir="${build.tests}"> <fileset dir="build/metagenerate"> <include name="**/*.xinfo"/> + <include name="**/*.mxinfo"/> </fileset> </copy> 1.2 +19 -7 jakarta-avalon-excalibur/metagenerate/src/java/org/apache/avalon/excalibur/metagenerate/MetaGenerateQdoxTask.java Index: MetaGenerateQdoxTask.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/metagenerate/src/java/org/apache/avalon/excalibur/metagenerate/MetaGenerateQdoxTask.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MetaGenerateQdoxTask.java 28 Sep 2002 10:37:50 -0000 1.1 +++ MetaGenerateQdoxTask.java 28 Sep 2002 21:43:39 -0000 1.2 @@ -21,14 +21,16 @@ * MetaInfo Generation Ant Taskdef * @author Paul Hammant */ -public class MetaGenerateQdoxTask extends AbstractQdoxTask { +public class MetaGenerateQdoxTask extends AbstractQdoxTask +{ private File m_destDir; /** * Execute */ - public void execute() { + public void execute() + { super.execute(); try { @@ -46,7 +48,8 @@ * Set the desitation * @param destinationDir The destination directory */ - public void setDest(File destinationDir) { + public void setDest(File destinationDir) + { m_destDir = destinationDir; } @@ -54,15 +57,24 @@ * Output the classes * @throws IOException If a problem writing output */ - protected void outputClasses() throws IOException { - for (int i = 0; i < allClasses.size(); i++) { + protected void outputClasses() throws IOException + { + for (int i = 0; i < allClasses.size(); i++) + { JavaClass javaClass = (JavaClass) allClasses.get(i); - DocletTag tag = javaClass.getTagByName("phoenix:block"); - if (tag != null) + DocletTag block = javaClass.getTagByName("phoenix:block"); + if (block != null) { XinfoFactory factory = new XinfoFactory(m_destDir, javaClass); factory.generate(); } + DocletTag topic = javaClass.getTagByName("phoenix:mx-topic"); + if (topic != null) + { + MxinfoFactory factory = new MxinfoFactory(m_destDir, javaClass); + factory.generate(); + } + } } 1.2 +1 -1 jakarta-avalon-excalibur/metagenerate/src/java/org/apache/avalon/excalibur/metagenerate/XinfoFactory.java Index: XinfoFactory.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/metagenerate/src/java/org/apache/avalon/excalibur/metagenerate/XinfoFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- XinfoFactory.java 28 Sep 2002 10:37:50 -0000 1.1 +++ XinfoFactory.java 28 Sep 2002 21:43:39 -0000 1.2 @@ -38,7 +38,7 @@ } /** - * Generate the class + * Generate the xinfo file * @throws IOException If a problem writing output */ public void generate() throws IOException 1.2 +5 -29 jakarta-avalon-excalibur/metagenerate/src/java/org/apache/avalon/excalibur/metagenerate/XinfoHelper.java Index: XinfoHelper.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/metagenerate/src/java/org/apache/avalon/excalibur/metagenerate/XinfoHelper.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- XinfoHelper.java 28 Sep 2002 10:37:50 -0000 1.1 +++ XinfoHelper.java 28 Sep 2002 21:43:39 -0000 1.2 @@ -15,7 +15,7 @@ * A Xinfo Helper. * @author Paul Hammant */ -public class XinfoHelper +public class XinfoHelper extends AbstractHelper { private FileWriter m_output; @@ -92,19 +92,8 @@ for (int i = 0; i < SERVICE_LINES.length; i++) { String line = SERVICE_LINES[i]; - int ix = line.indexOf("\"@SERVICE-CLASS@\""); - if (ix != -1) - { - m_output.write( - line.substring(0, ix) + - service + - line.substring(ix + "\"@SERVICE-CLASS@\"".length(), line.length()) + - "\n"); - } - else - { - m_output.write(line + "\n"); - } + line = replaceString(line, "\"@SERVICE-CLASS@\"", service); + m_output.write(line + "\n"); } } @@ -130,19 +119,8 @@ for (int i = 0; i < DEPENDENCY_SECTION.length; i++) { String line = DEPENDENCY_SECTION[i]; - int ix = line.indexOf("\"@SERVICE-CLASS@\""); - if (ix != -1) - { - m_output.write( - line.substring(0, ix) + - dependency + - line.substring(ix + "\"@SERVICE-CLASS@\"".length(), line.length()) + - "\n"); - } - else - { - m_output.write(line + "\n"); - } + line = replaceString(line, "\"@SERVICE-CLASS@\"", dependency); + m_output.write(line + "\n"); } } @@ -166,7 +144,5 @@ { m_output.close(); } - - } 1.1 jakarta-avalon-excalibur/metagenerate/src/java/org/apache/avalon/excalibur/metagenerate/AbstractHelper.java Index: AbstractHelper.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.excalibur.metagenerate; public class AbstractHelper { protected String replaceString(final String source, String term, String replacement) { String retval = source; int ix = retval.indexOf(term); if (ix != -1) { retval = retval.substring(0, ix) + replacement + retval.substring(ix + term.length(), retval.length()); } return retval; } } 1.1 jakarta-avalon-excalibur/metagenerate/src/java/org/apache/avalon/excalibur/metagenerate/MxinfoFactory.java Index: MxinfoFactory.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.excalibur.metagenerate; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.Type; import com.thoughtworks.qdox.model.JavaParameter; import java.io.IOException; import java.io.File; /** * A Mxinfo Factory * @author Paul Hammant */ public class MxinfoFactory { private JavaClass m_javaClass; private File m_destDir; /** * Construct a factory for a class. * @param destDir * @param javaClass */ public MxinfoFactory(File destDir, JavaClass javaClass) { m_javaClass = javaClass; m_destDir = destDir; } /** * Generate the mxinfo file * @throws IOException If a problem writing output */ public void generate() throws IOException { File file = new File(m_destDir, m_javaClass.getFullyQualifiedName().replace('.', File.separatorChar) + ".mxinfo"); file.getParentFile().mkdirs(); MxinfoHelper mxinfo = new MxinfoHelper(file); mxinfo.writeHeader(m_javaClass.getTagByName("phoenix:mx-topic").getNamedParameter("name")); // attributes JavaMethod[] methods = m_javaClass.getMethods(); for (int j = 0; j < methods.length; j++) { JavaMethod method = methods[j]; DocletTag attribute = method.getTagByName("phoenix:mx-attribute"); if (attribute != null) { String attributeName = getName(method.getName()); DocletTag tag = method.getTagByName("phoenix:mx-description"); String comment; if (tag == null) { comment = method.getComment(); } else { comment = tag.getValue(); } mxinfo.writeAttrLines(attributeName, "\"" + comment + "\"", method.getReturns().getValue()); } } mxinfo.writeOperationsHeader(); // operations methods = m_javaClass.getMethods(); for (int j = 0; j < methods.length; j++) { JavaMethod method = methods[j]; DocletTag attribute = method.getTagByName("phoenix:mx-operation"); if (attribute != null) { String operationName = method.getName(); String description = method.getComment(); String type = method.getReturns().getValue(); mxinfo.writeOperationHeader(operationName, description, type); JavaParameter[] params = method.getParameters(); for (int i = 0; i < params.length; i++) { JavaParameter param = params[i]; String paramName = param.getName(); DocletTag[] paramTags = method.getTagsByName("param"); String paramDescription = ""; for (int k = 0; k < paramTags.length; k++) { String paramTagValue = paramTags[k].getValue().trim(); if (paramTagValue.startsWith(paramName)) { paramDescription = paramTagValue.substring( paramTagValue.indexOf(" ") + 1, paramTagValue.length()); } } String paramType = param.getType().getValue(); mxinfo.writeOperationParameter(paramName, paramDescription, paramType); } mxinfo.writeOperationFooter(); } } mxinfo.writeFooter(); mxinfo.close(); } private String getName(final String name) { String retval = name; if (retval.startsWith("set") || retval.startsWith("get")) { retval = retval.substring(3, retval.length()); retval = retval.substring(0, 1).toLowerCase() + retval.substring(1, retval.length()); } return retval; } } 1.1 jakarta-avalon-excalibur/metagenerate/src/java/org/apache/avalon/excalibur/metagenerate/MxinfoHelper.java Index: MxinfoHelper.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.excalibur.metagenerate; import java.io.FileWriter; import java.io.IOException; import java.io.File; /** * A Xinfo Helper. * @author Paul Hammant */ public class MxinfoHelper extends AbstractHelper { private FileWriter m_output; private static final String HEADER[] = new String[]{ "<?xml version=\"1.0\"?>", "<!DOCTYPE mxinfo PUBLIC \"-//PHOENIX/Mx Info DTD Version 1.0//EN\"", " \"http://jakarta.apache.org/phoenix/mxinfo_1_0.dtd\">", "", "<mxinfo>", ""}; private static final String TOPIC[] = new String[]{ " <topic name=\"@TOPIC@\" >"}; private static final String ATTR_HEADER[] = new String[]{ "", " <!-- attributes -->"}; private static final String ATTRIBUTE[] = new String[]{ " <attribute", " name=\"@NAME@\"", " description=\"@DESCRIPTION@\"", " type=\"@RETURN@\"", " />"}; private static final String OPERATIONS_HEADER[] = new String[]{ "", " <!-- operations -->", "" }; private static final String OPERATION_HEADER[] = new String[]{ " <operation", " name=\"@NAME@\"", " description=\"@DESCRIPTION@\"", " type=\"@RETURN@\">" }; private static final String PARAMETER[] = new String[]{ "<param", " name=\"@NAME@\"", " description=\"@DESCRIPTION@\"", " type=\"@TYPE@\"", "/>" }; private static final String OPERATION_FOOTER[] = new String[]{ " </operation>" }; private static final String FOOTER[] = new String[]{ "", " </topic>", "", "</mxinfo>"}; /** * Construct * @param file The File to create * @throws IOException If a problem writing output */ public MxinfoHelper(File file) throws IOException { m_output = new FileWriter(file); } /** * Write the header * @param topic The topic * @throws IOException If a problem writing output */ public void writeHeader(String topic) throws IOException { for (int i = 0; i < HEADER.length; i++) { m_output.write(HEADER[i] + "\n"); } for (int i = 0; i < TOPIC.length; i++) { String line = TOPIC[i]; line = replaceString(line, "\"@TOPIC@\"", topic); m_output.write(line + "\n"); } for (int i = 0; i < ATTR_HEADER.length; i++) { m_output.write(ATTR_HEADER[i] + "\n"); } } /** * Write the Attribute Lines * @param attrName The attribute name * @param description The description * @param type The type * @throws IOException If a problem writing output */ public void writeAttrLines(String attrName, String description, String type) throws IOException { for (int i = 0; i < ATTRIBUTE.length; i++) { String line = ATTRIBUTE[i]; line = replaceString(line, "@NAME@", attrName); line = replaceString(line, "\"@DESCRIPTION@\"", description); line = replaceString(line, "@RETURN@", type); m_output.write(line + "\n"); } } /** * Write the operations headers * @throws IOException If a problem writing output */ public void writeOperationsHeader() throws IOException { for (int i = 0; i < OPERATIONS_HEADER.length; i++) { m_output.write(OPERATIONS_HEADER[i] + "\n"); } } /** * Write the operation headers * @param operName The attribute name * @param description The description * @param type The type * @throws IOException If a problem writing output */ public void writeOperationHeader(String operName, String description, String type) throws IOException { for (int i = 0; i < OPERATION_HEADER.length; i++) { String line = OPERATION_HEADER[i]; line = replaceString(line, "@NAME@", operName); line = replaceString(line, "@DESCRIPTION@", description); line = replaceString(line, "@RETURN@", type); m_output.write(line + "\n"); } } /** * Write the operation footer * @throws IOException If a problem writing output */ public void writeOperationFooter() throws IOException { for (int i = 0; i < OPERATION_FOOTER.length; i++) { m_output.write(OPERATION_FOOTER[i] + "\n"); } } /** * Write a parameter for an operation * @param paramName The attribute name * @param description The description * @param type The type * @throws IOException If a problem writing output */ public void writeOperationParameter(String paramName, String description, String type) throws IOException { for (int i = 0; i < PARAMETER.length; i++) { String line = PARAMETER[i]; line = replaceString(line, "@NAME@", paramName); line = replaceString(line, "@DESCRIPTION@", description); line = replaceString(line, "@TYPE@", type); m_output.write(line + "\n"); } } /** * Write footer * @throws IOException If a problem writing output */ public void writeFooter() throws IOException { for (int i = 0; i < FOOTER.length; i++) { m_output.write(FOOTER[i] + "\n"); } } /** * Close the file. * @throws IOException If a problem writing output */ public void close() throws IOException { m_output.close(); } } 1.2 +63 -6 jakarta-avalon-excalibur/metagenerate/src/test/org/apache/avalon/excalibur/metagenerate/IntegrationTestCase.java Index: IntegrationTestCase.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/metagenerate/src/test/org/apache/avalon/excalibur/metagenerate/IntegrationTestCase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- IntegrationTestCase.java 28 Sep 2002 10:37:50 -0000 1.1 +++ IntegrationTestCase.java 28 Sep 2002 21:43:39 -0000 1.2 @@ -1,10 +1,9 @@ /* - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 28-Sep-02 - * Time: 11:13:36 - * To change template for new class use - * Code Style | Class Templates options (Tools | IDE Options). + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE file. */ package org.apache.avalon.excalibur.metagenerate; @@ -60,6 +59,26 @@ } + public void testMBeanOutput() throws Exception + { + + String fileName + = "org/apache/avalon/excalibur/metagenerate/TestMBean.mxinfo"; + fileName.replace('\\',File.separatorChar); + fileName.replace('/',File.separatorChar); + + LineNumberReader reader = new LineNumberReader(new FileReader(fileName)); + String line = reader.readLine(); + int ix =0; + while (line != null) + { + assertEquals("Line not expected", line.trim(), MXINFO[ix].trim()); + ix++; + line = reader.readLine(); + } + } + + private static final String XINFO[] = new String[] { " <?xml version=\"1.0\"?>", " <!DOCTYPE blockinfo PUBLIC \"-//PHOENIX/Block Info DTD Version 1.0//EN\"", @@ -88,5 +107,43 @@ " </dependency>", " </dependencies>", " </blockinfo>" }; + + private static final String MXINFO[] = new String[] { + "<?xml version=\"1.0\"?>", + "<!DOCTYPE mxinfo PUBLIC \"-//PHOENIX/Mx Info DTD Version 1.0//EN\"", + " \"http://jakarta.apache.org/phoenix/mxinfo_1_0.dtd\">", + "", + "<mxinfo>", + "", + " <topic name=\"Greeting\" >", + "", + " <!-- attributes -->", + " <attribute", + " name=\"greeting\"", + " description=\"The greeting that is returned to each HTTP request\"", + " type=\"void\"", + " />", + "", + " <!-- operations -->", + "", + " <operation", + " name=\"someOperation\"", + " description=\"Blah Blah Blah Blah.\"", + " type=\"java.lang.String\">", + " <param", + " name=\"parm1\"", + " description=\"parameter one\"", + " type=\"java.lang.String\"", + " />", + " <param", + " name=\"parm2\"", + " description=\"parameter two\"", + " type=\"java.lang.String\"", + " />", + " </operation>", + "", + " </topic>", + "", + "</mxinfo>" }; } 1.1 jakarta-avalon-excalibur/metagenerate/src/test/org/apache/avalon/excalibur/metagenerate/TestMBean.java Index: TestMBean.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE file. */ package org.apache.avalon.excalibur.metagenerate; /** * Specifies methods to export via Management interface. * * @phoenix:mx-topic name="Greeting" * * @author Huw Roberts <[EMAIL PROTECTED]> * @version 1.0 */ public interface TestMBean { /** * The greeting that is returned to each HTTP request * * @phoenix:mx-attribute */ public void setGreeting( final String greeting ); /** * Gets the greeting that is returned to each HTTP request * */ String getGreeting(); /** * Blah Blah * Blah Blah. * * @param parm1 parameter one * @param parm2 parameter two * @return some return thing * @phoenix:mx-operation */ String someOperation( final String parm1, final String parm2 ); }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>