hammant 2002/09/28 17:19:13 Modified: metagenerate default.properties metagenerate/src/java/org/apache/avalon/excalibur/metagenerate MxinfoFactory.java MxinfoHelper.java metagenerate/src/test/org/apache/avalon/excalibur/metagenerate IntegrationTestCase.java Added: metagenerate/src/java/org/apache/avalon/excalibur/metagenerate Attribute.java Operation.java Log: Tested aginst Phoenix's mxinfos. Sorting needed. Revision Changes Path 1.2 +2 -2 jakarta-avalon-excalibur/metagenerate/default.properties Index: default.properties =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/metagenerate/default.properties,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- default.properties 28 Sep 2002 10:37:50 -0000 1.1 +++ default.properties 29 Sep 2002 00:19:13 -0000 1.2 @@ -8,8 +8,8 @@ name=excalibur-meta-generate Name=Excalibur MetaGenerate dir-name=metagenerate -version=0.7 -package-version=0.7 +version=0.8 +package-version=0.8 year=2002 # -------------------------------------------------- 1.2 +104 -54 jakarta-avalon-excalibur/metagenerate/src/java/org/apache/avalon/excalibur/metagenerate/MxinfoFactory.java Index: MxinfoFactory.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/metagenerate/src/java/org/apache/avalon/excalibur/metagenerate/MxinfoFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MxinfoFactory.java 28 Sep 2002 21:43:39 -0000 1.1 +++ MxinfoFactory.java 29 Sep 2002 00:19:13 -0000 1.2 @@ -15,6 +15,11 @@ import java.io.IOException; import java.io.File; +import java.util.Vector; +import java.util.List; +import java.util.Collections; +import java.util.ArrayList; +import java.util.Iterator; /** * A Mxinfo Factory @@ -25,6 +30,9 @@ private JavaClass m_javaClass; private File m_destDir; + private ArrayList m_attributes = new ArrayList(); + private ArrayList m_operations = new ArrayList(); + private MxinfoHelper m_mxinfo; /** * Construct a factory for a class. @@ -38,7 +46,7 @@ } /** - * Generate the mxinfo file + * Generate the m_mxinfo file * @throws IOException If a problem writing output */ public void generate() throws IOException @@ -46,71 +54,108 @@ 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 + m_mxinfo = new MxinfoHelper(file); + m_mxinfo.writeHeader(m_javaClass.getTagByName("phoenix:mx-topic").getNamedParameter("name")); + // m_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()); - } + makeAttribute(methods[j], m_mxinfo); } - mxinfo.writeOperationsHeader(); + writeAttributes(); + m_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) + makeOperation(methods[j], m_mxinfo); + } + writeOperations(); + m_mxinfo.writeFooter(); + m_mxinfo.close(); + } + + private void writeOperations() throws IOException + { + m_mxinfo.writeOperations(m_operations); + } + + private void makeAttribute(JavaMethod method, MxinfoHelper mxinfo) throws IOException + { + + 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 { - 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); + comment = tag.getValue(); + } + Type attributeType = method.getReturns(); + String attributeTypeString = attributeType.getValue() + (attributeType.isArray() ? "[]" : ""); + + Attribute attr = mxinfo.makeAttrLines(attributeName, + "\"" + comment + "\"", + attributeTypeString); + m_attributes.add(attr); + } + } - } - mxinfo.writeOperationFooter(); + private void writeAttributes() throws IOException + { + m_mxinfo.writeAttributes(m_attributes); + } + + private String makeOperation(JavaMethod method, MxinfoHelper mxinfo) throws IOException + { + String xml = ""; + DocletTag attribute = method.getTagByName("phoenix:mx-operation"); + if (attribute != null) + { + String operationName = method.getName(); + String description = method.getComment(); + Type type = method.getReturns(); + + String typeString = type.getValue() + (type.isArray() ? "[]" : ""); + + xml = xml + mxinfo.makeOperationHeader(operationName, description, typeString); + JavaParameter[] params = method.getParameters(); + for (int i = 0; i < params.length; i++) + { + xml = xml + makeOperationParameter(params[i], method, mxinfo); + + } + xml = xml + mxinfo.makeOperationFooter(); + Operation operation = new Operation(operationName,xml); + m_operations.add(operation); + } + return xml; + } + + private String makeOperationParameter(JavaParameter param, JavaMethod method, + MxinfoHelper mxinfo) throws IOException + { + 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()); } } - mxinfo.writeFooter(); - mxinfo.close(); + Type paramType = param.getType(); + String paramTypeString = paramType.getValue() + (paramType.isArray() ? "[]" : ""); + return mxinfo.makeOperationParameter(paramName, paramDescription, paramTypeString); } private String getName(final String name) @@ -119,6 +164,11 @@ if (retval.startsWith("set") || retval.startsWith("get")) { retval = retval.substring(3, retval.length()); + retval = retval.substring(0, 1).toLowerCase() + retval.substring(1, retval.length()); + } + else if (retval.startsWith("is")) + { + retval = retval.substring(2, retval.length()); retval = retval.substring(0, 1).toLowerCase() + retval.substring(1, retval.length()); } return retval; 1.2 +57 -16 jakarta-avalon-excalibur/metagenerate/src/java/org/apache/avalon/excalibur/metagenerate/MxinfoHelper.java Index: MxinfoHelper.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/metagenerate/src/java/org/apache/avalon/excalibur/metagenerate/MxinfoHelper.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MxinfoHelper.java 28 Sep 2002 21:43:39 -0000 1.1 +++ MxinfoHelper.java 29 Sep 2002 00:19:13 -0000 1.2 @@ -10,6 +10,9 @@ import java.io.FileWriter; import java.io.IOException; import java.io.File; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; /** * A Xinfo Helper. @@ -23,7 +26,7 @@ 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\">", + " \"http://jakarta.apache.org/avalon/dtds/phoenix/mxinfo_1_0.dtd\">", "", "<mxinfo>", ""}; @@ -54,11 +57,11 @@ " type=\"@RETURN@\">" }; private static final String PARAMETER[] = new String[]{ - "<param", - " name=\"@NAME@\"", - " description=\"@DESCRIPTION@\"", - " type=\"@TYPE@\"", - "/>" }; + " <param", + " name=\"@NAME@\"", + " description=\"@DESCRIPTION@\"", + " type=\"@TYPE@\"", + " />" }; private static final String OPERATION_FOOTER[] = new String[]{ " </operation>" }; @@ -112,19 +115,37 @@ * @param type The type * @throws IOException If a problem writing output */ - public void writeAttrLines(String attrName, String description, String type) throws IOException + public Attribute makeAttrLines(String attrName, String description, String type) throws IOException { + String xml = ""; 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"); + xml = xml + line + "\n"; } + return new Attribute(attrName, xml); } /** + * Write attributes. + * @param attributes A list of attributes + * @throws IOException If a problem writing output + */ + public void writeAttributes(List attributes) throws IOException + { + Collections.sort(attributes); + for (Iterator iterator = attributes.iterator(); iterator.hasNext();) + { + Attribute attribute = (Attribute) iterator.next(); + m_output.write(attribute.getXml()); + } + } + + + /** * Write the operations headers * @throws IOException If a problem writing output */ @@ -143,48 +164,68 @@ * @param type The type * @throws IOException If a problem writing output */ - public void writeOperationHeader(String operName, String description, String type) throws IOException + public String makeOperationHeader(String operName, String description, String type) throws IOException { + String xml = ""; 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"); + xml = xml + line + "\n"; } + return xml; } /** * Write the operation footer * @throws IOException If a problem writing output */ - public void writeOperationFooter() throws IOException + public String makeOperationFooter() throws IOException { + String xml = ""; for (int i = 0; i < OPERATION_FOOTER.length; i++) { - m_output.write(OPERATION_FOOTER[i] + "\n"); + xml = xml + OPERATION_FOOTER[i] + "\n"; } + return xml; } /** - * Write a parameter for an operation + * Make 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) + public String makeOperationParameter(String paramName, String description, String type) throws IOException { + String xml = ""; 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"); + xml = xml + line + "\n"; + } + return xml; + } + + /** + * Write operations + * @param operations A list of operations + * @throws IOException If a problem writing output + */ + public void writeOperations(List operations) throws IOException + { + Collections.sort(operations); + for (Iterator iterator = operations.iterator(); iterator.hasNext();) + { + Operation operation = (Operation) iterator.next(); + m_output.write(operation.getXml()); } } 1.1 jakarta-avalon-excalibur/metagenerate/src/java/org/apache/avalon/excalibur/metagenerate/Attribute.java Index: Attribute.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 Attribute implements Comparable { private String m_attributeName; private String m_xml; /** * Construct an Attribute * @param attributeName The attribute name * @param xml the XML */ public Attribute(String attributeName, String xml) { this.m_attributeName = attributeName; this.m_xml = xml; } /** * Get the attribute * @return The attribute */ public String getAttributeName() { return m_attributeName; } /** * Get the XML * @return The XML */ public String getXml() { return m_xml; } /** * From comparable * @param object The object to compare to. * @return whichever is order precidence */ public int compareTo(Object object) { Attribute attr = (Attribute) object; return m_attributeName.compareTo(attr.getAttributeName()); } } 1.1 jakarta-avalon-excalibur/metagenerate/src/java/org/apache/avalon/excalibur/metagenerate/Operation.java Index: Operation.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 Operation implements Comparable { private String m_operationName; private String m_xml; /** * Construct an Operation * @param operationName The attribute name * @param xml the XML */ public Operation(String operationName, String xml) { this.m_operationName = operationName; this.m_xml = xml; } /** * Get the Operation * @return The Operation */ public String getOperationName() { return m_operationName; } /** * Get the XML * @return The XML */ public String getXml() { return m_xml; } /** * From comparable * @param object The object to compare to. * @return whichever is order precidence */ public int compareTo(Object object) { Operation attr = (Operation) object; return m_operationName.compareTo(attr.getOperationName()); } } 1.4 +1 -1 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- IntegrationTestCase.java 28 Sep 2002 22:12:44 -0000 1.3 +++ IntegrationTestCase.java 29 Sep 2002 00:19:13 -0000 1.4 @@ -153,7 +153,7 @@ 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\">", + " \"http://jakarta.apache.org/avalon/dtds/phoenix/mxinfo_1_0.dtd\">", "", "<mxinfo>", "",
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>