Update of /cvsroot/xdoclet/xdoclet2/src/java/xdoclet/sdk/beans
In directory sc8-pr-cvs1:/tmp/cvs-serv13012/src/java/xdoclet/sdk/beans
Added Files:
BeanInfo.vm BeanInfoPlugin.java Manifest.vm
ManifestPlugin.java
Log Message:
Added Java Beans support. This is in order to make it possible for Bean containers
(such as IDEs) to configure XDoclet. We're generating BeanInfo and MANIFEST.MF files
that provide metadata about XDoclet. This is in fact the Metadata API for the
configuration part of XDoclet.
--- NEW FILE: BeanInfo.vm ---
package $destinationPackageName;
import java.awt.Image;
import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.beans.ParameterDescriptor;
import java.beans.MethodDescriptor;
import java.beans.SimpleBeanInfo;
import java.lang.reflect.Method;
import java.util.Vector;
public class $destinationUnqualifiedClassName extends SimpleBeanInfo {
#set( $beanTag = $class.doc.getTag("bean.class", false) )
## Set the default property
#set( $hasDefaultProperty = false )
#foreach( $method in $class.getMethods( true ) )
#if( $method.doc.getTag("bean.attribute", true) )
#set( $attributeTag = $method.doc.getTag("bean.attribute", true) )
#if( $attributeTag.getAttributeValue("default") == "true" )
private final String _defaultProperty = "$method.propertyName";
#set( $hasDefaultProperty = true )
#end
#end
#end
#if( !$hasDefaultProperty )
private final String _defaultProperty = null;
#end
#if( $beanTag.getAttributeValue("customizer") )
private final BeanDescriptor _beanDescriptor = new BeanDescriptor(
${class.qualifiedName}.class, $beanTag.getAttributeValue("customizer") );
#else
private final BeanDescriptor _beanDescriptor = new BeanDescriptor(
${class.qualifiedName}.class );
#end
public $destinationUnqualifiedClassName() throws java.beans.IntrospectionException
{
#if( $beanTag.getAttributeValue("displayName") )
_beanDescriptor.setDisplayName("$beanTag.getAttributeValue("displayName")");
#end
#if( $beanTag.getAttributeValue("expert") )
_beanDescriptor.setExpert("$beanTag.getAttributeValue("expert")");
#end
#if( $beanTag.getAttributeValue("hidden") )
_beanDescriptor.setHidden("$beanTag.getAttributeValue("hidden")");
#end
#if( $beanTag.getAttributeValue("name") )
_beanDescriptor.setName("$beanTag.getAttributeValue("name")");
#end
#if( $beanTag.getAttributeValue("preferred") )
_beanDescriptor.setPreferred("$beanTag.getAttributeValue("preferred")");
#end
#if( $beanTag.getAttributeValue("shortDescription") )
_beanDescriptor.setShortDescription("$beanTag.getAttributeValue("shortDescription")");
#end
#foreach($attributeTag in $class.doc.getTags("bean.attribute", false))
_beanDescriptor.setValue("$attributeTag.getAttributeValue("name")","$attributeTag.getAttributeValue("value")");
#end
// Set property descriptors from superclass
BeanInfo info =
Introspector.getBeanInfo(getBeanDescriptor().getBeanClass().getSuperclass());
String order = info.getBeanDescriptor().getValue("propertyorder") == null ? ""
: (String) info.getBeanDescriptor().getValue("propertyorder");
PropertyDescriptor[] pd = getPropertyDescriptors();
for (int i = 0; i != pd.length; i++) {
if (order.indexOf(pd[i].getName()) == -1) {
order = order + (order.length() == 0 ? "" : ":") + pd[i].getName();
}
}
getBeanDescriptor().setValue("propertyorder", order);
}
/**
* Gets the additional BeanInfo.
*
* @return additional BeanInfo.
*/
public BeanInfo[] getAdditionalBeanInfo() {
Vector bi = new Vector();
BeanInfo[] result = null;
#if( $beanTag.getAttributeValue("stopClass") )
for (Class cl = ${class.qualifiedName}.class.getSuperclass();
!cl.equals($beanTag.getAttributeValue("stopClass").class.getSuperclass()); cl =
cl.getSuperclass()) {
bi.addElement(Introspector.getBeanInfo(cl));
}
result = new BeanInfo[bi.size()];
bi.copyInto(result);
#end
return result;
}
/**
* Gets the BeanDescriptor.
*
* @return The BeanDescriptor.
*/
public BeanDescriptor getBeanDescriptor() {
return _beanDescriptor;
}
/**
* Gets the defaultPropertyIndex
*
* @return The defaultPropertyIndex value
*/
public int getDefaultPropertyIndex() {
if (_defaultProperty == null) {
return -1;
}
PropertyDescriptor[] pd = getPropertyDescriptors();
for (int i = 0; i < pd.length; i++) {
if (pd[i].getName().equals(_defaultProperty)) {
return i;
}
}
return -1;
}
}
--- NEW FILE: BeanInfoPlugin.java ---
package xdoclet.sdk.beans;
import xdoclet.plugins.VelocityPlugin;
import xdoclet.util.predicates.ReflectionPredicate;
import xdoclet.util.predicates.And;
import xdoclet.util.predicates.HasClassTag;
/**
* Generates BeanInfo classes for Java Beans.
*
* @ant.element display-name="BeanInfo" name="BeanInfo" parent="xdoclet.XDoclet"
* @author <a href="mailto:aslak.hellesoy at bekk.no">Aslak Hellesøy</a>
* @version $Revision: 1.1 $
*/
public class BeanInfoPlugin extends VelocityPlugin {
public BeanInfoPlugin() {
// We don't want inner classes, classes should be public and not abstract.
And and = new And();
and.add(new ReflectionPredicate("!isInner"));
and.add(new ReflectionPredicate("!isAbstract"));
and.add(new ReflectionPredicate("isPublic"));
and.add(new HasClassTag("bean.class"));
createAccept().setPredicate(and);
setTemplatePath("xdoclet/sdk/beans/BeanInfo.vm");
setFileName("{0}BeanInfo.java");
}
}
--- NEW FILE: Manifest.vm ---
#foreach( $class in $classes )
Name: ${plugin.getPathToClass($class.qualifiedName)}.class
Java-Bean: True
#end
--- NEW FILE: ManifestPlugin.java ---
package xdoclet.sdk.beans;
import xdoclet.plugins.VelocityPlugin;
import xdoclet.util.predicates.And;
import xdoclet.util.predicates.ReflectionPredicate;
import xdoclet.util.predicates.HasClassTag;
/**
* Generates a MANIFEST.MF file that registers XDoclet Java Beans.
*
* @ant.element display-name="Manifest" name="Manifest" parent="xdoclet.XDoclet"
* @author <a href="mailto:aslak.hellesoy at bekk.no">Aslak Hellesøy</a>
* @version $Revision: 1.1 $
*/
public class ManifestPlugin extends VelocityPlugin {
public ManifestPlugin() {
// We don't want inner classes, classes should be public and not abstract.
And and = new And();
and.add(new ReflectionPredicate("!isInner"));
and.add(new ReflectionPredicate("!isAbstract"));
and.add(new ReflectionPredicate("isPublic"));
and.add(new HasClassTag("bean.class"));
createAccept().setPredicate(and);
setTemplatePath("xdoclet/sdk/beans/Manifest.vm");
setFileName("MANIFEST.MF");
}
public String getPathToClass(String className) {
return className.replace('.', '/');
}
}
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger
for complex code. Debugging C/C++ programs can leave you feeling lost and
disoriented. TotalView can help you find your way. Available on major UNIX
and Linux platforms. Try it free. www.etnus.com
_______________________________________________
xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel