Update of /cvsroot/xdoclet/xdoclet2/src/java/xdoclet
In directory sc8-pr-cvs1:/tmp/cvs-serv12630/src/java/xdoclet

Modified Files:
        BeanContextSupportEx.java Plugin.java PluginFactory.java 
        Property.java XDoclet.java 
Log Message:
Removed the need for xdoclet-plugin.xml. All metadata is now in generated BeanInfo.

Index: BeanContextSupportEx.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet2/src/java/xdoclet/BeanContextSupportEx.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** BeanContextSupportEx.java   12 Mar 2003 23:41:02 -0000      1.1
--- BeanContextSupportEx.java   16 Mar 2003 17:06:55 -0000      1.2
***************
*** 12,25 ****
      private BeanContextSupportEx _parent;
  
!     public boolean add( Object o ) {
!         System.out.println("Adding " + o + " to " + this);
!         if( o instanceof BeanContextSupportEx ) {
              BeanContextSupportEx child = (BeanContextSupportEx) o;
!             child.setParent( this );
          }
!         return super.add( o );
      }
  
!     private void setParent( BeanContextSupportEx parent ) {
          _parent = parent;
      }
--- 12,26 ----
      private BeanContextSupportEx _parent;
  
!     public boolean add(Object o) {
!         if (o instanceof BeanContextSupportEx) {
              BeanContextSupportEx child = (BeanContextSupportEx) o;
! 
!             child.setParent(this);
          }
! 
!         return super.add(o);
      }
  
!     private void setParent(BeanContextSupportEx parent) {
          _parent = parent;
      }

Index: Plugin.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet2/src/java/xdoclet/Plugin.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** Plugin.java 12 Mar 2003 23:47:04 -0000      1.9
--- Plugin.java 16 Mar 2003 17:06:55 -0000      1.10
***************
*** 53,57 ****
      private String _packageName;
      private List _packageSubstitutions = new ArrayList();
- 
      private String _fileName = "";
  
--- 53,56 ----
***************
*** 123,126 ****
--- 122,131 ----
      }
  
+     /**
+      * Creates a new Accept
+      *
+      * @bean.method shortDescription="Add a new filter"
+      *              displayName="New Filter"
+      */
      public final Accept createAccept() {
          if (_accept != null) {
***************
*** 133,136 ****
--- 138,147 ----
      }
  
+     /**
+      * Creates a new Property
+      *
+      * @bean.method shortDescription="Add a new property"
+      *              displayName="New Property"
+      */
      public final Property createProperty() {
          Property property = new Property();
***************
*** 176,181 ****
              LogFactory.getLog(Plugin.class).info("Generating " + 
destinationFile.getAbsolutePath());
              generateOneFileForAll(destinationFile);
!         }
!         else {
              LogFactory.getLog(Plugin.class).info("Generating " + getFileName() + 
"...");
  
--- 187,191 ----
              LogFactory.getLog(Plugin.class).info("Generating " + 
destinationFile.getAbsolutePath());
              generateOneFileForAll(destinationFile);
!         } else {
              LogFactory.getLog(Plugin.class).info("Generating " + getFileName() + 
"...");
  
***************
*** 196,204 ****
  
                  String destinationUnqualifiedClassName = 
destinationFile.getName().substring(0,
!                                                                                      
        destinationFile.getName().length() - 5);
  
                  getContextObjects().put("destinationUnqualifiedClassName", 
destinationUnqualifiedClassName);
                  getContextObjects().put("destinationQualifiedClassName",
!                                         
TypeConversionUtil.getQualifiedClassName(destinationPackageName, 
destinationUnqualifiedClassName));
  
                  generateOneFileForEach(destinationFile, object);
--- 206,214 ----
  
                  String destinationUnqualifiedClassName = 
destinationFile.getName().substring(0,
!                         destinationFile.getName().length() - 5);
  
                  getContextObjects().put("destinationUnqualifiedClassName", 
destinationUnqualifiedClassName);
                  getContextObjects().put("destinationQualifiedClassName",
!                     TypeConversionUtil.getQualifiedClassName(destinationPackageName, 
destinationUnqualifiedClassName));
  
                  generateOneFileForEach(destinationFile, object);
***************
*** 208,212 ****
  
      protected void validate()
!             throws XDocletException {
          if (_packageName != null) {
              if (!_packageSubstitutions.isEmpty()) {
--- 218,222 ----
  
      protected void validate()
!         throws XDocletException {
          if (_packageName != null) {
              if (!_packageSubstitutions.isEmpty()) {
***************
*** 275,279 ****
  
      private final String getSubstitutedPackageName(Object object)
!             throws XDocletException {
          String packageName = null;
          String originalPackageName = 
getXDoclet().getMetadataProvider().getPackageName(object);
--- 285,289 ----
  
      private final String getSubstitutedPackageName(Object object)
!         throws XDocletException {
          String packageName = null;
          String originalPackageName = 
getXDoclet().getMetadataProvider().getPackageName(object);
***************
*** 287,292 ****
              if ((packageName != null) && (candidate != null)) {
                  throw new XDocletException("Ambiguous package substitution for "
!                                            + 
getXDoclet().getMetadataProvider().getPackageName(object) + ". Both " + packageName + 
" or "
!                                            + candidate + " are possible substitution 
results.");
              }
  
--- 297,302 ----
              if ((packageName != null) && (candidate != null)) {
                  throw new XDocletException("Ambiguous package substitution for "
!                     + getXDoclet().getMetadataProvider().getPackageName(object) + ". 
Both " + packageName + " or "
!                     + candidate + " are possible substitution results.");
              }
  
***************
*** 311,315 ****
       */
      protected final Collection getFilteredCollection()
!             throws XDocletException {
          // Get all the classes including inner classes.
          Collection collection = getXDoclet().getCollection();
--- 321,325 ----
       */
      protected final Collection getFilteredCollection()
!         throws XDocletException {
          // Get all the classes including inner classes.
          Collection collection = getXDoclet().getCollection();
***************
*** 319,324 ****
              // Filter out the objects we want.
              result = CollectionUtils.select(collection, _accept);
!         }
!         else {
              result = collection;
          }
--- 329,333 ----
              // Filter out the objects we want.
              result = CollectionUtils.select(collection, _accept);
!         } else {
              result = collection;
          }
***************
*** 338,342 ****
       * @throws XDocletException if generation fails.
       */
!     protected abstract void generateOneFileForAll(File file) throws XDocletException;
  
      /**
--- 347,352 ----
       * @throws XDocletException if generation fails.
       */
!     protected abstract void generateOneFileForAll(File file)
!         throws XDocletException;
  
      /**
***************
*** 348,352 ****
       * @throws XDocletException if generation fails.
       */
!     protected abstract void generateOneFileForEach(File file, Object object) throws 
XDocletException;
  
      /**
--- 358,363 ----
       * @throws XDocletException if generation fails.
       */
!     protected abstract void generateOneFileForEach(File file, Object object)
!         throws XDocletException;
  
      /**
***************
*** 356,360 ****
       */
      private final File getAndCreateRealDestDir(String packageName)
!             throws XDocletException {
          if (getDestination() == null) {
              throw new XDocletException("destination was not specified for plugin \"" 
+ getName() + "\"");
--- 367,371 ----
       */
      private final File getAndCreateRealDestDir(String packageName)
!         throws XDocletException {
          if (getDestination() == null) {
              throw new XDocletException("destination was not specified for plugin \"" 
+ getName() + "\"");
***************
*** 377,381 ****
       */
      public final File getDestinationFileForAll()
!             throws XDocletException {
          return new File(getAndCreateRealDestDir(getPackageName()), getFileName());
      }
--- 388,392 ----
       */
      public final File getDestinationFileForAll()
!         throws XDocletException {
          return new File(getAndCreateRealDestDir(getPackageName()), getFileName());
      }
***************
*** 390,396 ****
       */
      public final File getDestinationFileForOne(Object object)
!             throws XDocletException {
          String fileNameSubstitutionValue = 
getXDoclet().getMetadataProvider().getFilenameSubstitutionValue(object);
!         String fileName = MessageFormat.format(getFileName(), new 
String[]{fileNameSubstitutionValue});
          String packageName = getSubstitutedPackageName(object);
  
--- 401,407 ----
       */
      public final File getDestinationFileForOne(Object object)
!         throws XDocletException {
          String fileNameSubstitutionValue = 
getXDoclet().getMetadataProvider().getFilenameSubstitutionValue(object);
!         String fileName = MessageFormat.format(getFileName(), new String[] { 
fileNameSubstitutionValue });
          String packageName = getSubstitutedPackageName(object);
  
***************
*** 425,435 ****
       */
      protected static void checkClass(String className)
!             throws XDocletException {
          try {
              Class.forName(className);
!         }
!         catch (ClassNotFoundException e) {
              throw new XDocletException("Couldn't load " + className
!                                        + ". Make sure you have this class on the 
classpath used to define XDoclet.");
          }
      }
--- 436,445 ----
       */
      protected static void checkClass(String className)
!         throws XDocletException {
          try {
              Class.forName(className);
!         } catch (ClassNotFoundException e) {
              throw new XDocletException("Couldn't load " + className
!                 + ". Make sure you have this class on the classpath used to define 
XDoclet.");
          }
      }

Index: PluginFactory.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet2/src/java/xdoclet/PluginFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** PluginFactory.java  12 Mar 2003 23:41:03 -0000      1.6
--- PluginFactory.java  16 Mar 2003 17:06:55 -0000      1.7
***************
*** 2,23 ****
  
  import org.apache.commons.logging.LogFactory;
- import org.xml.sax.Attributes;
- import org.xml.sax.SAXException;
- import org.xml.sax.SAXParseException;
- import org.xml.sax.helpers.DefaultHandler;
  
  import xdoclet.util.ClasspathManager;
- import xdoclet.util.FileUtils;
  
! import javax.xml.parsers.ParserConfigurationException;
! import javax.xml.parsers.SAXParser;
! import javax.xml.parsers.SAXParserFactory;
  
  import java.io.*;
  
- import java.util.*;
- import java.beans.*;
  import java.lang.reflect.Method;
  
  /**
   * Parses deployment descriptors of all files on the classpath and registers plugins
--- 2,23 ----
  
  import org.apache.commons.logging.LogFactory;
  
+ import xdoclet.plugins.JellyPlugin;
+ import xdoclet.plugins.VelocityPlugin;
+ import xdoclet.sdk.beans.BeanInfoPlugin;
+ import xdoclet.sdk.beans.ManifestPlugin;
  import xdoclet.util.ClasspathManager;
  
! import java.beans.*;
  
  import java.io.*;
  
  import java.lang.reflect.Method;
  
+ import java.util.*;
+ import java.util.jar.Attributes;
+ import java.util.jar.JarFile;
+ import java.util.jar.Manifest;
+ 
  /**
   * Parses deployment descriptors of all files on the classpath and registers plugins
***************
*** 30,44 ****
   */
  public final class PluginFactory {
-     /** Where to look for descriptors. */
-     private static final String DESCRIPTOR_PATH = "META-INF/xdoclet-plugin.xml";
- 
      /** Helps us get files from the classpath. */
      private final ClasspathManager _classpathManager;
  
      /** Maps plugin name to class name. */
!     private final Map _nameToPluginClassNameMap = new HashMap();
  
      /** Maps plugin class to parent class. */
!     private final Map _pluginClassNameToXDocletClassNameMap = new HashMap();
  
      /**
--- 30,41 ----
   */
  public final class PluginFactory {
      /** Helps us get files from the classpath. */
      private final ClasspathManager _classpathManager;
  
      /** Maps plugin name to class name. */
!     private final Map _nameToPluginClassMap = new HashMap();
  
      /** Maps plugin class to parent class. */
!     private final Map _pluginClassToXDocletClassMap = new HashMap();
  
      /**
***************
*** 51,72 ****
  
          // Register the standard built-in plugins
!         registerPlugin("velocity", "xdoclet.plugins.VelocityPlugin", 
"xdoclet.XDoclet");
!         registerPlugin("jelly", "xdoclet.plugins.JellyPlugin", "xdoclet.XDoclet");
  
          // Register plugins from classpath
          registerDynamicPlugins();
- 
-         // Update BeanInfo for all XDoclet classes
-         for( Iterator i = _pluginClassNameToXDocletClassNameMap.values().iterator(); 
i.hasNext(); ) {
-             String xdocletClassName = (String) i.next();
-             try {
-                 Class xdocletClass = 
_classpathManager.getClassLoader().loadClass(xdocletClassName);
-                 updateBeanInfo(xdocletClass);
-             } catch (ClassNotFoundException e) {
-                 // Should never happen
-                 LogFactory.getLog(PluginFactory.class).error("Couldn't load class", 
e);;
-             }
-         }
- 
      }
  
--- 48,58 ----
  
          // Register the standard built-in plugins
!         registerPlugin("velocity", VelocityPlugin.class, XDoclet.class);
!         registerPlugin("jelly", JellyPlugin.class, XDoclet.class);
!         registerPlugin("manifest", ManifestPlugin.class, XDoclet.class);
!         registerPlugin("beaninfo", BeanInfoPlugin.class, XDoclet.class);
  
          // Register plugins from classpath
          registerDynamicPlugins();
      }
  
***************
*** 77,98 ****
       * @param xdocletClass
       */
!     private void updateBeanInfo(Class xdocletClass) {
          try {
-             // Get all allowed plugins
-             Collection allowedPluginNames = getAllowedPluginNames( xdocletClass );
- 
              BeanInfo beanInfo = Introspector.getBeanInfo(xdocletClass);
              MethodDescriptor[] md = beanInfo.getMethodDescriptors();
!             Method createPlugin = xdocletClass.getMethod("createPlugin", new Class[] 
{String.class});
              boolean didUpdate = false;
!             for( int i = 0; i < md.length; i++ ) {
!                 if( md[i].getMethod().equals( createPlugin ) ) {
!                     md[i].setValue("pluginNames", allowedPluginNames);
                      didUpdate = true;
                      break;
                  }
              }
!             if( !didUpdate ) {
!                 throw new IllegalStateException("BeanInfo was not properly updated. 
Couldn't find createPlugin method in " + xdocletClass.getName());
              }
          } catch (IntrospectionException e) {
--- 63,92 ----
       * @param xdocletClass
       */
!     private void updateBeanInfo(Class xdocletClass, Class pluginClass) {
          try {
              BeanInfo beanInfo = Introspector.getBeanInfo(xdocletClass);
              MethodDescriptor[] md = beanInfo.getMethodDescriptors();
!             Method createPlugin = xdocletClass.getMethod("createPlugin", new Class[] 
{ String.class });
              boolean didUpdate = false;
! 
!             for (int i = 0; i < md.length; i++) {
!                 if (md[i].getMethod().equals(createPlugin)) {
!                     List pluginClasses = (List) md[i].getValue("pluginClasses");
! 
!                     if (pluginClasses == null) {
!                         pluginClasses = new ArrayList();
!                         md[i].setValue("pluginNames", pluginClasses);
!                     }
! 
!                     pluginClasses.add(pluginClass);
                      didUpdate = true;
+ 
                      break;
                  }
              }
! 
!             if (!didUpdate) {
!                 throw new IllegalStateException(
!                     "BeanInfo was not properly updated. Couldn't find createPlugin 
method in " + xdocletClass.getName());
              }
          } catch (IntrospectionException e) {
***************
*** 123,127 ****
  
              // Look up the allowed parent class
!             Class parentClass = getContainerClass(pluginClass.getName());
  
              // Verify that the passed xdoclet is allowed to contain the plugin.
--- 117,121 ----
  
              // Look up the allowed parent class
!             Class parentClass = getContainerClass(pluginClass);
  
              // Verify that the passed xdoclet is allowed to contain the plugin.
***************
*** 133,155 ****
      }
  
- 
-     /**
-      * Returns a Collection of all known plugin names. This can be used to create 
plugins.
-      * @see <a 
href="XDoclet.html#createPlugin(java.lang.String)">XDoclet.createPlugin</a>.
-      * @return a Collection of [EMAIL PROTECTED] String}.
-      */
-     public Collection getAllowedPluginNames(Class xdocletClass) {
-         ArrayList allowedPluginNames = new ArrayList();
- 
-         for( Iterator i = _nameToPluginClassNameMap.keySet().iterator(); 
i.hasNext(); ) {
-             String pluginName = (String) i.next();
-             if( allowsPlugin(pluginName, xdocletClass) ) {
-                 allowedPluginNames.add( pluginName );
-             }
-         }
-         Collections.sort( allowedPluginNames );
-         return allowedPluginNames;
-     }
- 
      /**
       * Creates a new plugin and attaches it to an XDoclet instance.
--- 127,130 ----
***************
*** 167,170 ****
--- 142,146 ----
              throw new IllegalArgumentException("xdoclet cannot be null");
          }
+ 
          // plugin names are case insensitive
          pluginName = pluginName.toLowerCase(Locale.US);
***************
*** 174,178 ****
  
          // Look up the allowed parent class
!         Class parentClass = getContainerClass(pluginClass.getName());
  
          // Verify that the passed xdoclet is allowed to contain the plugin.
--- 150,154 ----
  
          // Look up the allowed parent class
!         Class parentClass = getContainerClass(pluginClass);
  
          // Verify that the passed xdoclet is allowed to contain the plugin.
***************
*** 189,193 ****
              // Instantiate the plugin. The instantiated
              // plugin will be added to the XDoclet's BeanContext by 
Beans.instantiate.
!             Plugin plugin = (Plugin) 
Beans.instantiate(_classpathManager.getClassLoader(), pluginClass.getName(), xdoclet);
  
              LogFactory.getLog(getClass()).debug("Creating plugin " + 
pluginClass.getName());
--- 165,170 ----
              // Instantiate the plugin. The instantiated
              // plugin will be added to the XDoclet's BeanContext by 
Beans.instantiate.
!             Plugin plugin = (Plugin) 
Beans.instantiate(_classpathManager.getClassLoader(), pluginClass.getName(),
!                     xdoclet);
  
              LogFactory.getLog(getClass()).debug("Creating plugin " + 
pluginClass.getName());
***************
*** 204,208 ****
              throw new XDocletException("Couldn't cast " + pluginClass.getName() + " 
to " + Plugin.class.getName(), e);
          } catch (Throwable e) {
!             e.printStackTrace();
              throw new XDocletException(e.getMessage(), e);
          }
--- 181,185 ----
              throw new XDocletException("Couldn't cast " + pluginClass.getName() + " 
to " + Plugin.class.getName(), e);
          } catch (Throwable e) {
!             LogFactory.getLog(getClass()).error(e.getMessage(), e);
              throw new XDocletException(e.getMessage(), e);
          }
***************
*** 213,225 ****
       *
       * @param pluginName the name of the plugin
!      * @param pluginClassName the class name of the plugin
!      * @param xdocletClassName the class name of the parent xdoclet
       */
!     private void registerPlugin(String pluginName, String pluginClassName, String 
xdocletClassName) {
          // plugin names are case insensitive
!           pluginName = pluginName.toLowerCase(Locale.US);
          LogFactory.getLog(getClass()).debug("Registered plugin: " + pluginName);
!         _nameToPluginClassNameMap.put(pluginName, pluginClassName);
!         _pluginClassNameToXDocletClassNameMap.put(pluginClassName, xdocletClassName);
      }
  
--- 190,204 ----
       *
       * @param pluginName the name of the plugin
!      * @param pluginClass the class of the plugin
!      * @param xdocletClass the parent xdoclet class
       */
!     private void registerPlugin(String pluginName, Class pluginClass, Class 
xdocletClass) {
          // plugin names are case insensitive
!         pluginName = pluginName.toLowerCase(Locale.US);
          LogFactory.getLog(getClass()).debug("Registered plugin: " + pluginName);
!         _nameToPluginClassMap.put(pluginName, pluginClass);
!         _pluginClassToXDocletClassMap.put(pluginClass, xdocletClass);
! 
!         updateBeanInfo(xdocletClass, pluginClass);
      }
  
***************
*** 233,237 ****
              File file = (File) classpathFiles.next();
  
!             parse(file);
          }
  
--- 212,216 ----
              File file = (File) classpathFiles.next();
  
!             registerPlugins(file);
          }
  
***************
*** 247,282 ****
      private Class getPluginClass(String pluginName)
          throws XDocletException {
!         // First try one of the built-in plugins.
!         if ("velocity".equals(pluginName)) {
!             try {
!                 return Class.forName("xdoclet.plugins.VelocityPlugin");
!             } catch (ClassNotFoundException e) {
!                 LogFactory.getLog(getClass()).error("Couldn't instantiate 
VelocityPlugin");
!             }
!         }
  
!         if ("jelly".equals(pluginName)) {
!             try {
!                 return Class.forName("xdoclet.plugins.JellyPlugin");
!             } catch (ClassNotFoundException e) {
!                 LogFactory.getLog(getClass()).error("Couldn't instantiate 
JellyPlugin");
!             }
!         }
! 
!         String pluginClassName = (String) _nameToPluginClassNameMap.get(pluginName);
! 
!         if (pluginClassName == null) {
              throw new XDocletException("No registered plugin class for plugin \"" + 
pluginName + "\". "
                  + "Make sure the classpath contains the plugin.");
          }
  
!         try {
!             // try instantiating the pluginClass
!             return _classpathManager.getClassLoader().loadClass(pluginClassName);
!         } catch (Throwable e) {
!             LogFactory.getLog(getClass()).error(e.getMessage(), e);
!             throw new XDocletException("Couldn't instantiate " + pluginClassName + 
". Classpath="
!                 + _classpathManager.getClasspath());
!         }
      }
  
--- 226,237 ----
      private Class getPluginClass(String pluginName)
          throws XDocletException {
!         Class pluginClass = (Class) _nameToPluginClassMap.get(pluginName);
  
!         if (pluginClass == null) {
              throw new XDocletException("No registered plugin class for plugin \"" + 
pluginName + "\". "
                  + "Make sure the classpath contains the plugin.");
          }
  
!         return pluginClass;
      }
  
***************
*** 284,389 ****
       * Returns the plugin's container class, which is XDoclet.class or a subclass of 
it.
       *
!      * @param pluginClassName the name of the plugin class
       * @return the corresponding plugin class
       */
!     private Class getContainerClass(String pluginClassName)
          throws XDocletException {
!         String xdocletClassName = (String) 
_pluginClassNameToXDocletClassNameMap.get(pluginClassName);
  
!         if (xdocletClassName == null) {
!             throw new XDocletException("No registered plugin container for plugin 
class \"" + pluginClassName + "\"");
          }
  
!         try {
!             // try instantiating the parentClass
!             return _classpathManager.getClassLoader().loadClass(xdocletClassName);
!         } catch (Throwable e) {
!             LogFactory.getLog(getClass()).error(e.getMessage(), e);
!             throw new XDocletException("Couldn't instantiate " + xdocletClassName + 
". Classpath="
!                 + _classpathManager.getClasspath());
!         }
      }
  
      /**
!      * Parses one deployment descriptor.
       */
!     private final void parse(File dirOrZip) {
!         InputStream deploymentDescriptor = FileUtils.getResourceAsStream(dirOrZip, 
DESCRIPTOR_PATH);
! 
!         // path is only for error reporting
!         String path = dirOrZip.getAbsolutePath() + File.separator + DESCRIPTOR_PATH;
! 
!         if (deploymentDescriptor != null) {
!             LogFactory.getLog(getClass()).debug("Parsing " + DESCRIPTOR_PATH + " in 
" + dirOrZip.getAbsolutePath());
! 
!             SAXParserFactory factory = SAXParserFactory.newInstance();
! 
!             assert factory != null : "factory (SAXParserFactory) is null";
!             factory.setValidating(false);
  
              try {
!                 SAXParser parser = factory.newSAXParser();
! 
!                 parser.parse(deploymentDescriptor, new DescriptorHandler());
!                 deploymentDescriptor.close();
!             } catch (NullPointerException e) {
!                 LogFactory.getLog(getClass()).error(e.getMessage(), e);
!                 throw new IllegalStateException("NullPointerException");
!             } catch (FileNotFoundException e) {
!                 LogFactory.getLog(getClass()).error(e.getMessage(), e);
!                 throw new IllegalStateException("Couldn't find the DTD declared in " 
+ path);
              } catch (IOException e) {
!                 LogFactory.getLog(getClass()).error(e.getMessage(), e);
!                 throw new IllegalStateException("Error reading " + path);
!             } catch (IllegalArgumentException e) {
!                 LogFactory.getLog(getClass()).error(e.getMessage(), e);
!                 throw new IllegalStateException("Error reading " + path);
!             } catch (ParserConfigurationException e) {
!                 LogFactory.getLog(getClass()).error(e.getMessage(), e);
!                 throw new IllegalStateException("Error reading " + path);
!             } catch (SAXParseException e) {
!                 Exception e2 = e.getException();
! 
!                 if (e2 != null) {
!                     LogFactory.getLog(getClass()).error(e.getMessage(), e2);
!                 }
! 
!                 LogFactory.getLog(getClass()).error(e.getMessage(), e);
!                 throw new IllegalStateException("SAXParseException at line=" + 
e.getLineNumber() + " column="
!                     + e.getColumnNumber() + " " + path);
!             } catch (SAXException e) {
!                 LogFactory.getLog(getClass()).error(e.getMessage(), e);
!                 throw new IllegalStateException("Error reading " + path);
              }
          } else {
!             LogFactory.getLog(getClass()).debug("No " + DESCRIPTOR_PATH + " in " + 
dirOrZip.getAbsolutePath());
!         }
!     }
! 
!     /**
!      * Handles the xdoclet-plugin.xml content.
!      */
!     private final class DescriptorHandler extends DefaultHandler {
!         public void startElement(String namespaceURI, String localName, String 
qName, Attributes attributes)
!             throws SAXException {
!             if (qName.equalsIgnoreCase("plugin")) {
!                 String pluginName = attributes.getValue("name");
!                 String pluginClassName = attributes.getValue("plugin-class");
!                 String parentClassName = attributes.getValue("parent-class");
! 
!                 if (pluginName == null) {
!                     throw new SAXException("Missing name attribute.");
!                 }
  
!                 if (pluginClassName == null) {
!                     throw new SAXException("Missing plugin-class attribute.");
!                 }
  
!                 if (parentClassName == null) {
!                     throw new SAXException("Missing parent-class attribute.");
                  }
- 
-                 assert (pluginName != null) && (pluginClassName != null) && 
(parentClassName != null);
-                 registerPlugin(pluginName, pluginClassName, parentClassName);
              }
          }
--- 239,326 ----
       * Returns the plugin's container class, which is XDoclet.class or a subclass of 
it.
       *
!      * @param pluginClass the plugin class
       * @return the corresponding plugin class
       */
!     private Class getContainerClass(Class pluginClass)
          throws XDocletException {
!         Class xdocletClass = (Class) _pluginClassToXDocletClassMap.get(pluginClass);
  
!         if (xdocletClass == null) {
!             throw new XDocletException("No registered plugin container for plugin 
class \"" + pluginClass.getName()
!                 + "\"");
          }
  
!         return xdocletClass;
      }
  
      /**
!      * Registers all plugins by looking at manifest and beaninfo
!      * @param dirOrZip
       */
!     private final void registerPlugins(File dirOrZip) {
!         Manifest manifest = null;
  
+         if (dirOrZip.isDirectory()) {
              try {
!                 manifest = new Manifest(new FileInputStream(new File(dirOrZip, 
"META-INF/MANIFEST.MF")));
              } catch (IOException e) {
!                 // Ignore. There was no Manifest here.
              }
          } else {
!             try {
!                 JarFile jarFile = new JarFile(dirOrZip);
  
!                 manifest = jarFile.getManifest();
!             } catch (IOException e) {
!                 // Ignore. Wasn't a jar file.
!             }
!         }
  
!         if (manifest != null) {
!             // Now loop over all entries in the Manifest.
!             for (Iterator entryNames = manifest.getEntries().keySet().iterator(); 
entryNames.hasNext();) {
!                 String entryName = (String) entryNames.next();
! 
!                 // Is it a class?
!                 if (entryName.endsWith(".class")) {
!                     Attributes attributes = manifest.getAttributes(entryName);
! 
!                     // See if it's a java bean.
!                     String javaBean = attributes.getValue("Java-Bean");
! 
!                     if ("true".equalsIgnoreCase(javaBean)) {
!                         // OK. Get the BeanInfo.
!                         String className = entryName.substring(0, entryName.length() 
- 6);
! 
!                         className = className.replace('/', '.');
! 
!                         // Load the class
!                         try {
!                             Class pluginClass = 
_classpathManager.getClassLoader().loadClass(className);
!                             BeanInfo beanInfo = 
Introspector.getBeanInfo(pluginClass);
!                             BeanDescriptor beanDescriptor = 
beanInfo.getBeanDescriptor();
! 
!                             String pluginName = beanDescriptor.getName();
!                             String parentClassName = (String) 
beanDescriptor.getValue("xdoclet-class");
! 
!                             if ((pluginName != null) && (parentClassName != null)) {
!                                 Class xdocletClass = 
_classpathManager.getClassLoader().loadClass(parentClassName);
! 
!                                 registerPlugin(pluginName, pluginClass, 
xdocletClass);
!                             }
!                         } catch (ClassNotFoundException e) {
!                             String errorMessage = className
!                                 + " was declared as a Java-Bean in the manifest, but 
the class was not found.";
! 
!                             
LogFactory.getLog(PluginFactory.class).error(errorMessage, e);
!                             throw new IllegalStateException(errorMessage);
!                         } catch (IntrospectionException e) {
!                             String errorMessage = "Couldn't find BeanInfo for " + 
className;
! 
!                             
LogFactory.getLog(PluginFactory.class).error(errorMessage, e);
!                             throw new IllegalStateException(errorMessage);
!                         }
!                     }
                  }
              }
          }

Index: Property.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet2/src/java/xdoclet/Property.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** Property.java       9 Mar 2003 15:46:32 -0000       1.4
--- Property.java       16 Mar 2003 17:06:55 -0000      1.5
***************
*** 1,4 ****
--- 1,5 ----
  package xdoclet;
  
+ 
  /**
   * Holds name=value pair. It is analog to XDoclet 1.2's configParameter, but it has 
the

Index: XDoclet.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet2/src/java/xdoclet/XDoclet.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** XDoclet.java        12 Mar 2003 23:41:03 -0000      1.8
--- XDoclet.java        16 Mar 2003 17:06:55 -0000      1.9
***************
*** 20,24 ****
   * "in ourself". The main reason for extending BeanContextSupport is to
   * be a ble to provide IDE integration in a convenient way. See the
!  * <a href="../swing/package.html"></a>xdoclet.swing</p> package.
   *
   * @bean.class locale="en"
--- 20,24 ----
   * "in ourself". The main reason for extending BeanContextSupport is to
   * be a ble to provide IDE integration in a convenient way. See the
!  * <a href="../gui/package.html"></a>xdoclet.gui</p> package.
   *
   * @bean.class locale="en"
***************
*** 44,47 ****
--- 44,51 ----
      private static PluginFactory _pluginFactory;
  
+     static {
+         setClasspath(System.getProperty("java.class.path"));
+     }
+ 
      /** Provides us with metadata. */
      private transient MetadataProvider _metadataProvider;
***************
*** 57,64 ****
      private transient Throwable _failure;
  
-     static {
-         setClasspath(System.getProperty("java.class.path"));
-     }
- 
      /**
       * Creates a new XDoclet.
--- 61,64 ----
***************
*** 205,209 ****
      }
  
!     private void failIfFailureSet() throws XDocletException {
          if (_failure != null) {
              if (_failure instanceof XDocletException) {
--- 205,210 ----
      }
  
!     private void failIfFailureSet()
!         throws XDocletException {
          if (_failure != null) {
              if (_failure instanceof XDocletException) {
***************
*** 224,229 ****
       * @throws XDocletException plugin creation fails
       */
!     public Plugin createPlugin(String name) throws XDocletException {
!         return _pluginFactory.createPlugin(name,this);
      }
  }
--- 225,231 ----
       * @throws XDocletException plugin creation fails
       */
!     public Plugin createPlugin(String name)
!         throws XDocletException {
!         return _pluginFactory.createPlugin(name, this);
      }
  }



-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open! 
Get cracking and register here for some mind boggling fun and 
the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
_______________________________________________
xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to