hammant 2002/09/30 17:10:05
Modified: . build.xml project.properties
Added: lib qdox-1.0.jar
src/java/org/apache/avalon/phoenix/metagenerate
AbstractHelper.java ManifestFactory.java
ManifestHelper.java MetaGenerateQdoxTask.java
MxinfoFactory.java MxinfoHelper.java
NamedXmlSnippet.java XinfoFactory.java
XinfoHelper.java
src/test/org/apache/avalon/phoenix/metagenerate
IntegrationTestCase.java TestBlock.java
TestMBean.java TestNonBlock.java
Log:
MetaGenerate moved to Phoenix
Revision Changes Path
1.171 +50 -3 jakarta-avalon-phoenix/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-phoenix/build.xml,v
retrieving revision 1.170
retrieving revision 1.171
diff -u -r1.170 -r1.171
--- build.xml 30 Sep 2002 23:17:13 -0000 1.170
+++ build.xml 1 Oct 2002 00:10:04 -0000 1.171
@@ -41,6 +41,8 @@
<property name="build.testclasses" value="${build.dir}/testclasses"/>
<property name="build.reports" value="${build.dir}/reports"/>
<property name="build.xdoclet" value="${build.dir}/xdoclet"/>
+ <property name="build.metagenerate" value="${build.dir}/metagenerate"/>
+ <property name="build.test-metagenerate"
value="${build.dir}/test-metagenerate"/>
<!-- Set the properties for source directories -->
<property name="src.dir" value="src"/>
@@ -236,12 +238,34 @@
</copy>
</target>
+
+ <target name="test-generate">
- <!-- Compiles the source code -->
- <target name="test" depends="compile" description="compiles and runs unit
tests">
+ <taskdef name="generatemeta"
classname="org.apache.avalon.phoenix.metagenerate.MetaGenerateQdoxTask">
+ <classpath refid="test.class.path" />
+ </taskdef>
+
+ <generatemeta dest="${build.test-metagenerate}"
manifestName="TestManifest.mf">
+ <fileset dir="src/test">
+ <include name="**/*.java"/>
+ </fileset>
+ </generatemeta>
+
+ </target>
+
+ <!-- Runs the tests -->
+ <target name="test" depends="compile, test-generate" description="compiles and
runs unit tests">
<mkdir dir="${build.testclasses}"/>
+ <copy todir="${build.tests}">
+ <fileset dir="${build.test-metagenerate}">
+ <include name="**/*.xinfo"/>
+ <include name="**/*.mxinfo"/>
+ <include name="**/*.mf"/>
+ </fileset>
+ </copy>
+
<javac srcdir="${test.dir}"
destdir="${build.testclasses}"
debug="${build.debug}"
@@ -271,6 +295,7 @@
<batchtest todir="${build.tests}">
<fileset dir="${build.testclasses}">
<include name="**/test/*TestCase.class"/>
+ <include name="**/metagenerate/*TestCase.class"/>
<exclude name="**/Abstract*"/>
</fileset>
</batchtest>
@@ -298,8 +323,26 @@
</target>
+ <!-- Make .xinfo, .mxinfo and manifest automatically for blocks -->
+ <target name="phoenix-metagenerate" depends="compile">
+
+ <mkdir dir="${build.metagenerate}"/>
+
+ <taskdef name="generatemeta"
classname="org.apache.avalon.phoenix.metagenerate.MetaGenerateQdoxTask">
+ <classpath refid="project.class.path" />
+ </taskdef>
+
+ <generatemeta dest="${build.metagenerate}"
manifestName="PhoenixManifest.mf">
+ <fileset dir="${java.dir}">
+ <include name="**/*.java"/>
+ </fileset>
+ </generatemeta>
+
+ </target>
+
+
<!-- Creates all the .jar files -->
- <target name="jars" depends="phoenix-xdoclet">
+ <target name="jars" depends="phoenix-xdoclet, phoenix-metagenerate">
<mkdir dir="${build.lib}"/>
@@ -343,6 +386,10 @@
<zipfileset dir="src/bsh" prefix="bsh/commands/">
<include name="**"/>
</zipfileset>
+ </jar>
+
+ <jar jarfile="${build.lib}/phoenix-metagenerate.jar"
basedir="${build.classes}">
+ <include name="org/apache/avalon/phoenix/metagenerate/**"/>
</jar>
</target>
1.8 +1 -20 jakarta-avalon-phoenix/project.properties
<<Binary file>>
1.1 jakarta-avalon-phoenix/lib/qdox-1.0.jar
<<Binary file>>
1.1
jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/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.phoenix.metagenerate;
/**
* Abstract Helper
* @author Paul Hammant
*/
public abstract class AbstractHelper
{
/**
* Replace a test with another in a string
* @param source The string to be changed.
* @param term The term to replace.
* @param replacement To replace with.
* @return The resulting string.
*/
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-phoenix/src/java/org/apache/avalon/phoenix/metagenerate/ManifestFactory.java
Index: ManifestFactory.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.phoenix.metagenerate;
import java.io.IOException;
import java.io.File;
import java.util.Vector;
/**
* A Xinfo Factory
* @author Paul Hammant
*/
public class ManifestFactory
{
private String m_manifestName;
private File m_destDir;
private Vector m_blocks = new Vector();
/**
* Construct a factory for a class.
* @param destDir
* @param mainfestName
*/
public ManifestFactory(File destDir, String mainfestName)
{
m_manifestName = mainfestName;
m_destDir = destDir;
}
/**
* Add a block
* @param className
*/
public void addBlock(String className)
{
m_blocks.add(className);
}
/**
* Generate the xinfo file
* @throws IOException If a problem writing output
*/
public void generate() throws IOException
{
File file = new File(m_destDir, m_manifestName);
file.getParentFile().mkdirs();
ManifestHelper manifest = new ManifestHelper(file);
manifest.writeHeader();
for (int i = 0; i < m_blocks.size(); i++)
{
String block = (String) m_blocks.elementAt(i);
manifest.writeBlockLines(block);
}
manifest.close();
}
}
1.1
jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/metagenerate/ManifestHelper.java
Index: ManifestHelper.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.phoenix.metagenerate;
import java.io.FileWriter;
import java.io.IOException;
import java.io.File;
/**
* A Xinfo Helper.
* @author Paul Hammant
*/
public class ManifestHelper extends AbstractHelper
{
private FileWriter m_output;
private static final String[] HEADER = new String[]{
"Manifest-Version: 1.0",
"Created-By: Apache Avalon Project (Automatically via MetaGenerate)",
""};
private static final String[] BLOCK_LINES = new String[]{
"Name: @[email protected]",
"Avalon-Block: true"};
/**
* Construct
* @param file The File to create
* @throws IOException If a problem writing output
*/
public ManifestHelper(File file) throws IOException
{
m_output = new FileWriter(file);
}
/**
* Write the header
* @throws IOException If a problem writing output
*/
public void writeHeader() throws IOException
{
for (int i = 0; i < HEADER.length; i++)
{
m_output.write(HEADER[i] + "\n");
}
}
/**
* Write Block lines
* @param className The class name
* @throws IOException If a problem writing output
*/
public void writeBlockLines(String className) throws IOException
{
for (int i = 0; i < BLOCK_LINES.length; i++)
{
String line = BLOCK_LINES[i];
line = replaceString(line, "@FULL-CLASS-PATH@", className.replace('.',
'/'));
m_output.write(line + "\n");
}
}
/**
* Close the file.
* @throws IOException If a problem writing output
*/
public void close() throws IOException
{
m_output.close();
}
}
1.1
jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/metagenerate/MetaGenerateQdoxTask.java
Index: MetaGenerateQdoxTask.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.phoenix.metagenerate;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.ant.AbstractQdoxTask;
import org.apache.tools.ant.BuildException;
import java.io.File;
import java.io.IOException;
/**
* MetaInfo Generation Ant Taskdef
* @author Paul Hammant
*/
public class MetaGenerateQdoxTask extends AbstractQdoxTask
{
private File m_destDir;
private String m_manifestName;
/**
* Execute
*/
public void execute()
{
super.execute();
try
{
m_destDir.mkdirs();
outputClasses();
}
catch (IOException e)
{
e.printStackTrace();
throw new BuildException("IOException " + e.getMessage());
}
}
/**
* Set the desitation
* @param destinationDir The destination directory
*/
public void setDest(File destinationDir)
{
m_destDir = destinationDir;
}
/**
* Set the manifest name
* @param manifestName The Manifest Name
*/
public void setManifestName(String manifestName)
{
m_manifestName = manifestName;
}
/**
* Output the classes
* @throws IOException If a problem writing output
*/
protected void outputClasses() throws IOException
{
ManifestFactory manifestFactory = new ManifestFactory(m_destDir,
m_manifestName);
for (int i = 0; i < allClasses.size(); i++)
{
JavaClass javaClass = (JavaClass) allClasses.get(i);
DocletTag block = javaClass.getTagByName("phoenix:block");
if (block != null)
{
XinfoFactory factory = new XinfoFactory(m_destDir, javaClass);
factory.generate();
manifestFactory.addBlock(javaClass.getFullyQualifiedName());
}
DocletTag topic = javaClass.getTagByName("phoenix:mx-topic");
if (topic != null)
{
MxinfoFactory factory = new MxinfoFactory(m_destDir, javaClass);
factory.generate();
}
if (m_manifestName != null)
{
manifestFactory.generate();
}
}
}
}
1.1
jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/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.phoenix.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;
import java.util.ArrayList;
/**
* A Mxinfo Factory
* @author Paul Hammant
*/
public class MxinfoFactory
{
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.
* @param destDir
* @param javaClass
*/
public MxinfoFactory(File destDir, JavaClass javaClass)
{
m_javaClass = javaClass;
m_destDir = destDir;
}
/**
* Generate the m_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();
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++)
{
makeAttribute(methods[j], m_mxinfo);
}
writeAttributes();
m_mxinfo.writeOperationsHeader();
// operations
methods = m_javaClass.getMethods();
for (int j = 0; j < methods.length; j++)
{
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
{
comment = tag.getValue();
}
Type attributeType = method.getReturns();
String attributeTypeString =
attributeType.getValue() + (attributeType.isArray() ? "[]" : "");
NamedXmlSnippet attr = mxinfo.makeAttrLines(attributeName,
"\"" + comment + "\"",
attributeTypeString);
m_attributes.add(attr);
}
}
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();
NamedXmlSnippet operation = new NamedXmlSnippet(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());
}
}
Type paramType = param.getType();
String paramTypeString = paramType.getValue() + (paramType.isArray() ? "[]"
: "");
return mxinfo.makeOperationParameter(paramName, paramDescription,
paramTypeString);
}
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());
}
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.1
jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/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.phoenix.metagenerate;
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.
* @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/avalon/dtds/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 NamedXmlSnippet 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);
xml = xml + line + "\n";
}
return new NamedXmlSnippet(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();)
{
NamedXmlSnippet attribute = (NamedXmlSnippet) iterator.next();
m_output.write(attribute.getXml());
}
}
/**
* 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 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);
xml = xml + line + "\n";
}
return xml;
}
/**
* Write the operation footer
* @throws IOException If a problem writing output
*/
public String makeOperationFooter() throws IOException
{
String xml = "";
for (int i = 0; i < OPERATION_FOOTER.length; i++)
{
xml = xml + OPERATION_FOOTER[i] + "\n";
}
return xml;
}
/**
* 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 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);
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();)
{
NamedXmlSnippet operation = (NamedXmlSnippet) iterator.next();
m_output.write(operation.getXml());
}
}
/**
* 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.1
jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/metagenerate/NamedXmlSnippet.java
Index: NamedXmlSnippet.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.phoenix.metagenerate;
/**
* A named XML snippet
* @author Paul Hammant
*/
public class NamedXmlSnippet implements Comparable
{
private String m_name;
private String m_xml;
/**
* Construct an NamedXmlSnippet
* @param name The node name
* @param xml the XML
*/
public NamedXmlSnippet(String name, String xml)
{
this.m_name = name;
this.m_xml = xml;
}
/**
* Get the name
* @return The Name
*/
public String getName()
{
return m_name;
}
/**
* 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)
{
NamedXmlSnippet attr = (NamedXmlSnippet) object;
return m_name.compareTo(attr.getName());
}
}
1.1
jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/metagenerate/XinfoFactory.java
Index: XinfoFactory.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.phoenix.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 java.io.IOException;
import java.io.File;
/**
* A Xinfo Factory
* @author Paul Hammant
*/
public class XinfoFactory
{
private JavaClass m_javaClass;
private File m_destDir;
/**
* Construct a factory for a class.
* @param destDir
* @param javaClass
*/
public XinfoFactory(File destDir, JavaClass javaClass)
{
m_javaClass = javaClass;
m_destDir = destDir;
}
/**
* Generate the xinfo 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)
+ ".xinfo");
file.getParentFile().mkdirs();
XinfoHelper xinfo = new XinfoHelper(file);
xinfo.writeHeader();
// services
processServiceInterfaces(xinfo);
xinfo.writeEndOfServicesSection();
processManagementInterfaces(xinfo);
xinfo.writeEndOfManagementSection();
processServiceMethod(xinfo);
xinfo.writeFooter();
xinfo.close();
}
/**
* Process the service interfaces
* @param xinfo the xinfo helper
* @throws IOException If a problem
*/
private void processServiceInterfaces(XinfoHelper xinfo) throws IOException
{
DocletTag[] services = m_javaClass.getTagsByName("phoenix:service");
for (int i = 0; i < services.length; i++)
{
DocletTag service = services[i];
xinfo.writeServiceLines(service.getNamedParameter("name"));
}
}
/**
* Process the management interface lines
* @param xinfo the xinfo helper
* @throws IOException If a problem
*/
private void processManagementInterfaces(XinfoHelper xinfo) throws IOException
{
DocletTag[] managementInterfaces = m_javaClass.getTagsByName("phoenix:mx");
for (int i = 0; i < managementInterfaces.length; i++)
{
xinfo.writeManagementLine(managementInterfaces[i].getNamedParameter("name"));
}
}
/**
* Process the service method. Cehck for the right signature.
* @param xinfo The xinfo helper
* @throws IOException If a problem
*/
private void processServiceMethod(XinfoHelper xinfo) throws IOException
{
JavaMethod[] methods = m_javaClass.getMethods();
for (int j = 0; j < methods.length; j++)
{
// dependencies
JavaMethod method = methods[j];
if (method.getName().equals("service")
&& method.getReturns().equals(new Type("void",0))
&& method.getParameters().length == 1
&& method.getParameters()[0].getType().getValue().equals(
"org.apache.avalon.framework.service.ServiceManager"))
{
DocletTag[] dependencies =
method.getTagsByName("phoenix:dependency");
for (int i = 0; i < dependencies.length; i++)
{
DocletTag dependency = dependencies[i];
xinfo.writeDependencyLines(dependency.getNamedParameter("name"));
}
}
}
}
}
1.1
jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/metagenerate/XinfoHelper.java
Index: XinfoHelper.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.phoenix.metagenerate;
import java.io.FileWriter;
import java.io.IOException;
import java.io.File;
/**
* A Xinfo Helper.
* @author Paul Hammant
*/
public class XinfoHelper extends AbstractHelper
{
private FileWriter m_output;
private static final String[] HEADER = new String[] {
"<?xml version=\"1.0\"?>",
"<!DOCTYPE blockinfo PUBLIC \"-//PHOENIX/Block Info DTD Version 1.0//EN\"",
"
\"http://jakarta.apache.org/avalon/dtds/phoenix/blockinfo_1_0.dtd\">",
"",
"<blockinfo>",
"",
" <!-- section to describe block -->",
" <block>",
" <version>1.0</version>",
" </block>",
"",
" <!-- services that are offered by this block -->",
" <services>" };
private static final String[] SERVICE_LINES = new String[] {
" <service name=\"@SERVICE-CLASS@\"/>" };
private static final String[] END_OF_SERVICES = new String[] {
" </services>",
"",
" <!-- interfaces that may be exported to manange this block -->",
" <management-access-points>" };
private static final String[] MANAGEMENT_LINE = new String[] {
" <service name=@INTERFACE-NAME@/>" };
private static final String[] END_OF_MGMT = new String[] {
" </management-access-points>",
"",
" <!-- services that are required by this block -->",
" <dependencies>" };
private static final String[] DEPENDENCY_SECTION = new String[] {
" <dependency>",
" <service name=\"@SERVICE-CLASS@\"/>",
" </dependency>" };
private static final String[] FOOTER = new String[] {
" </dependencies>",
"</blockinfo>" };
/**
* Construct
* @param file The File to create
* @throws IOException If a problem writing output
*/
public XinfoHelper(File file) throws IOException
{
m_output = new FileWriter(file);
}
/**
* Write the header
* @throws IOException If a problem writing output
*/
public void writeHeader() throws IOException
{
for (int i = 0; i < HEADER.length; i++)
{
m_output.write(HEADER[i] + "\n");
}
}
/**
* Write the Service Lines
* @param service The service name
* @throws IOException If a problem writing output
*/
public void writeServiceLines(String service) throws IOException
{
for (int i = 0; i < SERVICE_LINES.length; i++)
{
String line = SERVICE_LINES[i];
line = replaceString(line, "\"@SERVICE-CLASS@\"", service);
m_output.write(line + "\n");
}
}
/**
* Write the end of services section
* @throws IOException If a problem writing output
*/
public void writeEndOfServicesSection() throws IOException
{
for (int i = 0; i < END_OF_SERVICES.length; i++)
{
m_output.write(END_OF_SERVICES[i] + "\n");
}
}
public void writeManagementLine(String interfaceName) throws IOException
{
for (int i = 0; i < MANAGEMENT_LINE.length; i++)
{
String line = MANAGEMENT_LINE[i];
line = replaceString(line, "@INTERFACE-NAME@", interfaceName);
m_output.write(line + "\n");
}
}
/**
* Write the end of management section
* @throws IOException If a problem writing output
*/
public void writeEndOfManagementSection() throws IOException
{
for (int i = 0; i < END_OF_MGMT.length; i++)
{
m_output.write(END_OF_MGMT[i] + "\n");
}
}
/**
* Write Dependency Lines
* @param dependency The Dependency
* @throws IOException If a problem writing output
*/
public void writeDependencyLines(String dependency) throws IOException
{
for (int i = 0; i < DEPENDENCY_SECTION.length; i++)
{
String line = DEPENDENCY_SECTION[i];
line = replaceString(line, "\"@SERVICE-CLASS@\"", dependency);
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.1
jakarta-avalon-phoenix/src/test/org/apache/avalon/phoenix/metagenerate/IntegrationTestCase.java
Index: IntegrationTestCase.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.phoenix.metagenerate;
import junit.framework.TestCase;
import java.io.FileReader;
import java.io.File;
import java.io.LineNumberReader;
import java.io.FileNotFoundException;
public class IntegrationTestCase extends TestCase
{
public IntegrationTestCase(String name)
{
super(name);
}
public void testBlockInfoOutput() throws Exception
{
String fileName
= "org/apache/avalon/phoenix/metagenerate/TestBlock.xinfo";
fileName.replace('\\',File.separatorChar);
fileName.replace('/',File.separatorChar);
LineNumberReader reader = null;
try
{
reader = new LineNumberReader(new FileReader(fileName));
}
catch (FileNotFoundException e)
{
fail("The generated xinfo file is missing");
}
String line = reader.readLine();
int ix =0;
while (line != null)
{
assertEquals("Line not expected", XINFO[ix].trim(), line.trim());
ix++;
line = reader.readLine();
}
}
public void testNonBlockInfoOutput() throws Exception
{
String fileName
= "org/apache/avalon/phoenix/metagenerate/TestNonBlock.xinfo";
fileName.replace('\\',File.separatorChar);
fileName.replace('/',File.separatorChar);
try
{
new LineNumberReader(new FileReader(fileName));
fail("Non Block should not generate an xinfo file");
}
catch (FileNotFoundException e)
{
// expected.
}
}
public void testMBeanOutput() throws Exception
{
String fileName
= "org/apache/avalon/phoenix/metagenerate/TestMBean.mxinfo";
fileName.replace('\\',File.separatorChar);
fileName.replace('/',File.separatorChar);
LineNumberReader reader = null;
try
{
reader = new LineNumberReader(new FileReader(fileName));
}
catch (FileNotFoundException e)
{
fail("The generated mxinfo file was missing");
}
String line = reader.readLine();
int ix =0;
while (line != null)
{
assertEquals("Line not expected", MXINFO[ix].trim(), line.trim());
ix++;
line = reader.readLine();
}
}
public void testManifest() throws Exception
{
String fileName
= "TestManifest.mf";
fileName.replace('\\',File.separatorChar);
fileName.replace('/',File.separatorChar);
LineNumberReader reader = null;
try
{
reader = new LineNumberReader(new FileReader(fileName));
}
catch (FileNotFoundException e)
{
fail("The generated manifest file is missing");
}
String line = reader.readLine();
int ix =0;
while (line != null)
{
assertEquals("Line not expected", MANIFEST[ix].trim(), line.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\"",
"
\"http://jakarta.apache.org/avalon/dtds/phoenix/blockinfo_1_0.dtd\">",
"",
" <blockinfo>",
"",
" <!-- section to describe block -->",
" <block>",
" <version>1.0</version>",
" </block>",
"",
" <!-- services that are offered by this block -->",
" <services>",
" <service name=\"blah.BlahService\"/>",
" </services>",
"",
" <!-- interfaces that may be exported to manange this block -->",
" <management-access-points>",
" <service name=\"YeeeHaaa\"/>",
" </management-access-points>",
"",
" <!-- services that are required by this block -->",
" <dependencies>",
" <dependency>",
" <service name=\"blah.OtherBlahService\"/>",
" </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/avalon/dtds/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>" };
private static final String MANIFEST[] = new String[] {
"Manifest-Version: 1.0",
"Created-By: Apache Avalon Project (Automatically via MetaGenerate)",
"",
"Name: org/apache/avalon/phoenix/metagenerate/TestBlock.class",
"Avalon-Block: true" };
}
1.1
jakarta-avalon-phoenix/src/test/org/apache/avalon/phoenix/metagenerate/TestBlock.java
Index: TestBlock.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.phoenix.metagenerate;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
/**
* Blah!
*
* @phoenix:block
* @phoenix:service name="blah.BlahService"
* @phoenix:mx name="YeeeHaaa"
*
*/
public class TestBlock implements Serviceable
{
/**
* @phoenix:dependency name="blah.OtherBlahService"
*/
public void service( final ServiceManager serviceManager )
throws ServiceException
{
}
}
1.1
jakarta-avalon-phoenix/src/test/org/apache/avalon/phoenix/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.phoenix.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 );
}
1.1
jakarta-avalon-phoenix/src/test/org/apache/avalon/phoenix/metagenerate/TestNonBlock.java
Index: TestNonBlock.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.phoenix.metagenerate;
public class TestNonBlock
{
public void service() {
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>