User: andreas 
  Date: 00/10/14 22:26:50

  Modified:    examples/ejb/src/com/dreambean/ejx/ejb
                        ContainerTransaction.java EnterpriseBeans.java
                        Entity.java MethodPermission.java Session.java
  Added:       examples/ejb/src/com/dreambean/ejx/ejb
                        EjbResourceManager.java
                        EjbResourceManagerFactory.java
  Removed:     examples/ejb/src/com/dreambean/ejx/ejb EjbFileManager.java
                        EjbFileManagerFactory.java
  Log:
  Replaced FileManager and FileManagerFactory by the new
  ResourceManager and ResourceManagerFactory supporting
  URL instead of just files.
  ATTENTION:
  - At the moment you can still only use files to open and store
  Data because of unresolved issues (FilterFilter and JFile-
  Chooser)
  - These changes are NOT PORTED to jBoss CVS module
  
  Revision  Changes    Path
  1.2       +5 -5      
ejx/examples/ejb/src/com/dreambean/ejx/ejb/ContainerTransaction.java
  
  Index: ContainerTransaction.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/ejx/examples/ejb/src/com/dreambean/ejx/ejb/ContainerTransaction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ContainerTransaction.java 2000/09/29 05:56:15     1.1
  +++ ContainerTransaction.java 2000/10/15 05:26:48     1.2
  @@ -25,7 +25,7 @@
    *      
    *   @see <related>
    *   @author Rickard Oberg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.1 $
  + *   @version $Revision: 1.2 $
    */
   public class ContainerTransaction
      extends BeanContextSupport
  @@ -263,7 +263,7 @@
                bean.add(beanHome);
                try
                {
  -                     ClassLoader cl = 
((EjbFileManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
  +                     ClassLoader cl = 
((EjbResourceManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
                        Class clazz = cl.loadClass(ent.getHome());
                        java.lang.reflect.Method[] methods = clazz.getMethods();
                        for (int i = 0; i < methods.length; i++)
  @@ -282,7 +282,7 @@
                bean.add(beanRemote);
                try
                {
  -                     ClassLoader cl = 
((EjbFileManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
  +                     ClassLoader cl = 
((EjbResourceManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
                        Class clazz = cl.loadClass(ent.getRemote());
                        java.lang.reflect.Method[] methods = clazz.getMethods();
                        for (int i = 0; i < methods.length; i++)
  @@ -313,7 +313,7 @@
                bean.add(beanHome);
                try
                {
  -                     ClassLoader cl = 
((EjbFileManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
  +                     ClassLoader cl = 
((EjbResourceManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
                        Class clazz = cl.loadClass(sess.getHome());
                        java.lang.reflect.Method[] methods = clazz.getMethods();
                        for (int i = 0; i < methods.length; i++)
  @@ -332,7 +332,7 @@
                bean.add(beanRemote);
                try
                {
  -                     ClassLoader cl = 
((EjbFileManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
  +                     ClassLoader cl = 
((EjbResourceManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
                        Class clazz = cl.loadClass(sess.getRemote());
                        java.lang.reflect.Method[] methods = clazz.getMethods();
                        for (int i = 0; i < methods.length; i++)
  
  
  
  1.2       +2 -2      ejx/examples/ejb/src/com/dreambean/ejx/ejb/EnterpriseBeans.java
  
  Index: EnterpriseBeans.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/ejx/examples/ejb/src/com/dreambean/ejx/ejb/EnterpriseBeans.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EnterpriseBeans.java      2000/09/29 05:56:16     1.1
  +++ EnterpriseBeans.java      2000/10/15 05:26:49     1.2
  @@ -26,7 +26,7 @@
    *      
    *   @see <related>
    *   @author Rickard Oberg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.1 $
  + *   @version $Revision: 1.2 $
    */
   public class EnterpriseBeans
      extends BeanContextSupport
  @@ -125,7 +125,7 @@
               list += ((CMPField)currentFields.next()).getFieldName() + ",";
            }
            
  -         ClassLoader cl = 
((EjbFileManager)getBeanContext().getBeanContext()).getClassLoader();
  +         ClassLoader cl = 
((EjbResourceManager)getBeanContext().getBeanContext()).getClassLoader();
            try
            {
               Class clazz = cl.loadClass(entity.getEjbClass());
  
  
  
  1.2       +5 -5      ejx/examples/ejb/src/com/dreambean/ejx/ejb/Entity.java
  
  Index: Entity.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/ejx/examples/ejb/src/com/dreambean/ejx/ejb/Entity.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Entity.java       2000/09/29 05:56:17     1.1
  +++ Entity.java       2000/10/15 05:26:49     1.2
  @@ -24,7 +24,7 @@
    *      
    *   @see <related>
    *   @author Rickard Oberg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.1 $
  + *   @version $Revision: 1.2 $
    */
   public class Entity
      extends BeanContextSupport
  @@ -365,7 +365,7 @@
               // Set home
               try
               {
  -               ClassLoader cl = 
((EjbFileManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
  +               ClassLoader cl = 
((EjbResourceManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
                  Class clazz = cl.loadClass(getRemote()+"Home");
                  if (javax.ejb.EJBHome.class.isAssignableFrom(clazz))
                     setHome(getRemote()+"Home");
  @@ -380,7 +380,7 @@
               // Set bean, EJB spec style
               try
               {
  -               ClassLoader cl = 
((EjbFileManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
  +               ClassLoader cl = 
((EjbResourceManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
                  Class clazz = cl.loadClass(getRemote()+"Bean");
                  if (javax.ejb.EntityBean.class.isAssignableFrom(clazz))
                  {
  @@ -395,7 +395,7 @@
               // Set bean, J2EE RI style
               try
               {
  -               ClassLoader cl = 
((EjbFileManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
  +               ClassLoader cl = 
((EjbResourceManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
                  Class clazz = cl.loadClass(getRemote()+"EJB");
                  if (javax.ejb.EntityBean.class.isAssignableFrom(clazz))
                  {
  @@ -414,7 +414,7 @@
                  // Remote = com.mycompany.interfaces.Foo
                  // Bean   = com.mycompany.beans.FooBean
                  
  -               ClassLoader cl = 
((EjbFileManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
  +               ClassLoader cl = 
((EjbResourceManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
                  String remoteName = 
getRemote().substring(getRemote().lastIndexOf(".")+1);
                  String packageName = getRemote().substring(0, 
getRemote().lastIndexOf("."));
                  packageName = getRemote().substring(0, packageName.lastIndexOf(".")) 
+ ".beans.";
  
  
  
  1.2       +5 -5      ejx/examples/ejb/src/com/dreambean/ejx/ejb/MethodPermission.java
  
  Index: MethodPermission.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/ejx/examples/ejb/src/com/dreambean/ejx/ejb/MethodPermission.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MethodPermission.java     2000/09/29 05:56:17     1.1
  +++ MethodPermission.java     2000/10/15 05:26:49     1.2
  @@ -24,7 +24,7 @@
    *      
    *   @see <related>
    *   @author Rickard Oberg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.1 $
  + *   @version $Revision: 1.2 $
    */
   public class MethodPermission
      extends BeanContextSupport
  @@ -275,7 +275,7 @@
                bean.add(beanHome);
                try
                {
  -                     ClassLoader cl = 
((EjbFileManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
  +                     ClassLoader cl = 
((EjbResourceManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
                        Class clazz = cl.loadClass(ent.getHome());
                        java.lang.reflect.Method[] methods = clazz.getMethods();
                        for (int i = 0; i < methods.length; i++)
  @@ -294,7 +294,7 @@
                bean.add(beanRemote);
                try
                {
  -                     ClassLoader cl = 
((EjbFileManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
  +                     ClassLoader cl = 
((EjbResourceManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
                        Class clazz = cl.loadClass(ent.getRemote());
                        java.lang.reflect.Method[] methods = clazz.getMethods();
                        for (int i = 0; i < methods.length; i++)
  @@ -325,7 +325,7 @@
                bean.add(beanHome);
                try
                {
  -                     ClassLoader cl = 
((EjbFileManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
  +                     ClassLoader cl = 
((EjbResourceManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
                        Class clazz = cl.loadClass(sess.getHome());
                        java.lang.reflect.Method[] methods = clazz.getMethods();
                        for (int i = 0; i < methods.length; i++)
  @@ -344,7 +344,7 @@
                bean.add(beanRemote);
                try
                {
  -                     ClassLoader cl = 
((EjbFileManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
  +                     ClassLoader cl = 
((EjbResourceManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
                        Class clazz = cl.loadClass(sess.getRemote());
                        java.lang.reflect.Method[] methods = clazz.getMethods();
                        for (int i = 0; i < methods.length; i++)
  
  
  
  1.2       +5 -5      ejx/examples/ejb/src/com/dreambean/ejx/ejb/Session.java
  
  Index: Session.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/ejx/examples/ejb/src/com/dreambean/ejx/ejb/Session.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Session.java      2000/09/29 05:56:18     1.1
  +++ Session.java      2000/10/15 05:26:49     1.2
  @@ -19,7 +19,7 @@
    *      
    *   @see <related>
    *   @author Rickard Oberg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.1 $
  + *   @version $Revision: 1.2 $
    */
   public class Session
      extends BeanContextSupport
  @@ -335,7 +335,7 @@
               // Set home
               try
               {
  -               ClassLoader cl = 
((EjbFileManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
  +               ClassLoader cl = 
((EjbResourceManager)getBeanContext().getBeanContext().getBeanContext()).getClassLoader();
                  Class clazz = cl.loadClass(getRemote()+"Home");
                  if (javax.ejb.EJBHome.class.isAssignableFrom(clazz))
                     setHome(getRemote()+"Home");
  @@ -352,7 +352,7 @@
               BeanContext ejbJar = eb.getBeanContext();
               try
               {
  -               ClassLoader cl = 
((EjbFileManager)ejbJar.getBeanContext()).getClassLoader();
  +               ClassLoader cl = 
((EjbResourceManager)ejbJar.getBeanContext()).getClassLoader();
                  Class clazz = cl.loadClass(getRemote()+"Bean");
                  if (javax.ejb.SessionBean.class.isAssignableFrom(clazz))
                     setEjbClass(getRemote()+"Bean");
  @@ -364,7 +364,7 @@
               // Set bean, J2EE RI style
               try
               {
  -               ClassLoader cl = 
((EjbFileManager)ejbJar.getBeanContext()).getClassLoader();
  +               ClassLoader cl = 
((EjbResourceManager)ejbJar.getBeanContext()).getClassLoader();
                  Class clazz = cl.loadClass(getRemote()+"EJB");
                  if (javax.ejb.SessionBean.class.isAssignableFrom(clazz))
                     setEjbClass(getRemote()+"EJB");
  @@ -379,7 +379,7 @@
                  // Example:
                  // Remote = com.mycompany.interfaces.Foo
                  // Bean   = com.mycompany.beans.FooBean
  -               ClassLoader cl = 
((EjbFileManager)ejbJar.getBeanContext()).getClassLoader();
  +               ClassLoader cl = 
((EjbResourceManager)ejbJar.getBeanContext()).getClassLoader();
                  
                  String remoteName = 
getRemote().substring(getRemote().lastIndexOf(".")+1);
                  String packageName = getRemote().substring(0, 
getRemote().lastIndexOf("."));
  
  
  
  1.1                  
ejx/examples/ejb/src/com/dreambean/ejx/ejb/EjbResourceManager.java
  
  Index: EjbResourceManager.java
  ===================================================================
  /*
   * Copyright 1999 by dreamBean Software,
   * All rights reserved.
   */
  package com.dreambean.ejx.ejb;
  
  import java.awt.*;
  import java.awt.event.*;
  import java.beans.*;
  import java.beans.beancontext.*;
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import java.util.zip.*;
  import javax.swing.*;
  
  import org.w3c.dom.*;
  
  import com.dreambean.awt.*;
  import com.dreambean.ejx.xml.XMLManager;
  import com.dreambean.ejx.xml.XmlExternalizable;
  import com.dreambean.ejx.Util;
  import com.dreambean.ejx.ResourceManager;
  import com.dreambean.ejx.ResourceManagerFactory;
  
  /**
   *   <description> 
   *      
   *   @see <related>
   *   @author Rickard Oberg ([EMAIL PROTECTED])
   *   @version $Revision: 1.1 $
   */
  public class EjbResourceManager
        extends BeanContextServicesSupport
        implements ResourceManager
  {
     // Constants -----------------------------------------------------
      
     // Attributes ----------------------------------------------------
        XMLManager xm;
     URL resource;
     Component comp;
     
     EjbJar ejbJar;
     
     EjbResourceManagerFactory fact;
     
     ClassLoader cl;
      
     // Static --------------------------------------------------------
  
     // Constructors --------------------------------------------------
     EjbResourceManager(EjbResourceManagerFactory f)
        {
                fact = f;
        }
        
     // Public --------------------------------------------------------
     public EjbJar getEjbJar()
        {
                return ejbJar;
        }
  
     public EjbJar loadArchive(URL file)
        throws Exception
     {
        // Create classloader
        {
           URL fileUrl = file;
           if (fileUrl.toString().endsWith("ejb-jar.xml"))
              fileUrl = new 
File(fileUrl.getFile()).getParentFile().getParentFile().toURL();
              
           cl = new URLClassLoader(new URL[] { fileUrl }, 
Thread.currentThread().getContextClassLoader());
        }
           
        Document doc;
        
        ejbJar = new EjbJar();
        add(ejbJar);
  
        // XML file
        if (file.getFile().endsWith(".xml"))
        {
           Reader in = new InputStreamReader(file.openStream());
           doc = xm.load(in);
           in.close();
        } else if (file.getFile().endsWith(".jar")) // JAR file
        {
           InputStream ejbXml = 
getClassLoader().getResourceAsStream("META-INF/ejb-jar.xml");
           if (ejbXml == null)
           {
              // We want to use this file, but it doesn't contain the XML file yet 
(i.e. it's a JAR without the ejb-jar.xml file)
              return ejbJar;
           }
           Reader in = new BufferedReader(new InputStreamReader(ejbXml));
           doc = xm.load(in);
           in.close();
        } else
        {
           // Load from directory
           InputStream ejbXml = 
getClassLoader().getResourceAsStream("META-INF/ejb-jar.xml");
           Reader in = new BufferedReader(new InputStreamReader(ejbXml));
           doc = xm.load(in);
           ejbXml.close();
        }
        
        ejbJar.importXml(doc.getDocumentElement());
        
        return ejbJar;
     }
     
     // ResourceManager implementation ------------------------------------
     public boolean isChanged()
        {
                return true;
        }
        
        public void createNew()
        {
                ejbJar = new EjbJar();
                add(ejbJar);
        }
        
     public void load(URL resource)
        throws Exception
     {
          // First check if it is a file otherwise do nothing
          File file = Util.convertURL( resource );
          if( file == null ) {
                  return;
          }
        setResource(file.toURL());
        
        // Copy to prevent locking by load if we want to save later on
        if (file.toString().endsWith(".jar"))
        {
           File tmp = File.createTempFile("ejbjar",".jar");
           tmp.deleteOnExit();
           FileInputStream fin = new FileInputStream(file);
           byte[] bytes = new byte[(int)file.length()];
           fin.read(bytes);
           FileOutputStream fout = new FileOutputStream(tmp);
           fout.write(bytes);
           fin.close();
           fout.close();
           file = tmp;
        }
        
        loadArchive(file.toURL());
     }
     
        public void save(URL resource)
                throws Exception
        {
          // Check if it is a file
          File file = Util.convertURL( resource );
          if( file == null ) {
                  return;
          }
          
        // Prepare XML document
                Document doc = xm.create();
        doc.appendChild(ejbJar.exportXml(doc));
  
                // Save to file
        if (file.toString().endsWith(".jar"))
        {
           // Save to existing file
           if (file.exists())
           {
              // Store XML
              ByteArrayOutputStream out = new ByteArrayOutputStream();
              Writer w = new OutputStreamWriter(out);
              xm.save(doc,w);
              w.close();
              byte[] arr = out.toByteArray();
              
              Util.insertFileIntoZip(file, "META-INF/ejb-jar.xml", arr);
           } else
           {
              ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(file));
              
              zipOut.putNextEntry(new ZipEntry("META-INF/ejb-jar.xml"));
              
              ByteArrayOutputStream out = new ByteArrayOutputStream();
              Writer w = new OutputStreamWriter(out);
              xm.save(doc,w);
              w.close();
              byte[] arr = out.toByteArray();
              zipOut.write(arr);
              zipOut.closeEntry();
              zipOut.close();
           }
           
           setResource(file.toURL());
        }
        else if (file.toString().endsWith(".xml"))
        {
           FileWriter out = new FileWriter(file);
           xm.save(doc,out);
           out.close();
           
           setResource(file.toURL());
        } else
                {
                        // Check extension and add if possible
                        String name = file.getName();
                        if (name.indexOf(".") == -1)
                        {
                                name += ".xml";
                                save( (new File(file.getParent(),name)).toURL());
                        } else
                        {
                                JOptionPane.showMessageDialog(null, "Unknown filetype. 
File has not been saved!", "Save", JOptionPane.ERROR_MESSAGE);
                        }
                }
        
        }
        
        public URL getResource()
        {
                return resource;
        }
  
        public void setResource(URL resouce)
        {
                URL old = resource;
                this.resource = resource;
                firePropertyChange("File",old,resource);
        }
        
        public ResourceManagerFactory getFactory() { return fact; }
        
        public Component getComponent()
        {
                if (comp == null)
                {
                        comp = ejbJar.getComponent();
                }
                return comp;
        }
     
     public ClassLoader getClassLoader()
     {
        return cl;
     }
  
     // Package protected ---------------------------------------------
      
     // Protected -----------------------------------------------------
        protected void initializeBeanContextResources()
        {
                try
                {
                        xm = 
(XMLManager)((BeanContextServices)getBeanContext()).getService(this,this,XMLManager.class,null,this);
                } catch (Exception e)
                {
                        e.printStackTrace();
                }
        }
        
     // Private -------------------------------------------------------
  
     // Inner classes -------------------------------------------------
  }
  
  
  
  1.1                  
ejx/examples/ejb/src/com/dreambean/ejx/ejb/EjbResourceManagerFactory.java
  
  Index: EjbResourceManagerFactory.java
  ===================================================================
  /*
   * Copyright 1999 by dreamBean Software,
   * All rights reserved.
   */
  package com.dreambean.ejx.ejb;
  
  import java.io.File;
  import javax.swing.filechooser.FileFilter;
  
  import com.dreambean.ejx.ResourceManager;
  import com.dreambean.ejx.ResourceManagerFactory;
  
  /**
   *   <description> 
   *      
   *   @see <related>
   *   @author Rickard Oberg ([EMAIL PROTECTED])
   *   @version $Revision: 1.1 $
   */
  public class EjbResourceManagerFactory
        extends FileFilter
        implements ResourceManagerFactory
  {
     // Constants -----------------------------------------------------
      
     // Static --------------------------------------------------------
  
     // Public --------------------------------------------------------
  
     // FileFilter implementation -------------------------------------
        public boolean accept(File f)
        {
                return (f.getName().endsWith("ejb-jar.xml") || 
f.getName().endsWith(".jar"))
                                        || f.isDirectory();
        }
        
        public String getDescription() { return toString(); }
  
     // ResourceManagerFactory implementation -----------------------------
     public ResourceManager createResourceManager()
        {
                return new EjbResourceManager(this);
        }
     
     public FileFilter getFileFilter()
        {
                return this;
        }
        
        public String toString()
        {
                return "EJB 1.1 XML";
        }
  }
  
  
  

Reply via email to