Save This Page
Home » openjdk-7 » net » sf » rvpf » metadata » [javadoc | source]
    1   /**
    2    * Related Values Processing Framework.
    3    * 
    4    * Copyright (C) 2003 Serge Brisson.
    5    * 
    6    * This software is distributable under LGPL license.
    7    * See details at the bottom of this file.
    8    * 
    9    * $Header: /cvsroot/rvpf/RVPF/java/src/net/sf/rvpf/metadata/ClassDefEntity.java,v 1.4 2003/09/19 16:18:28 sfb Exp $
   10    */
   11   package net.sf.rvpf.metadata;
   12   
   13   import java.util.Iterator;
   14   import java.util.LinkedList;
   15   import java.util.List;
   16   
   17   import net.sf.rvpf.util.ServiceClassLoader;
   18   
   19   /** ClassDef Entity.
   20    * 
   21    * @author Serge Brisson
   22    * @version $Revision: 1.4 $
   23    */
   24   public class ClassDefEntity extends DefEntity {
   25   
   26       // Public Class Constants.
   27   
   28       public static final String PREFIX = "K";
   29   
   30       // Instance Properties.
   31   
   32       /** Sets the ClassLib.
   33        * 
   34        * @param classLib The ClassLib.
   35        */
   36       public void setClassLib(ClassLibEntity classLib) {
   37           this.classLib = classLib;
   38       }
   39   
   40       /** Sets the ClassLoader.
   41        * 
   42        * @param classLoader The ServiceClassLoader.
   43        */
   44       public void setClassLoader(ServiceClassLoader classLoader) {
   45           this.classLoader = classLoader;
   46       }
   47   
   48       /** Sets the Class name.
   49        * 
   50        * @param member The Class name without the package specification.
   51        */
   52       public void setMember(String member) {
   53           this.member = member;
   54       }
   55   
   56       /** Sets the package name for the Class.
   57        * 
   58        * @param packageName Name of the package containing the Class.
   59        */
   60       public void setPackageName(String packageName) {
   61           this.packageName = packageName;
   62       }
   63   
   64       /**
   65        */
   66       public String getPrefix() {
   67           return PREFIX;
   68       }
   69   
   70       // Public Instance Methods.
   71   
   72       /** Adds an other ClassDef as an implemented interface.
   73        * 
   74        * @param classDef The ClassDef to add.
   75        */
   76       public void addImplemented(ClassDefEntity classDef) {
   77           this.implemented.add(classDef);
   78       }
   79   
   80       /** Creates an instance of the Class.
   81        * 
   82        * @return The instance.
   83        */
   84       public Object createInstance() {
   85           Class loadedClass;
   86           Object instance;
   87   
   88           if (this.classLib != null)
   89               synchronized (this) {
   90                   if (this.classLib != null) {
   91                       this.classLoader.addFromClassLib(this.classLib);
   92                       this.classLib = null;
   93                   }
   94               }
   95   
   96           try {
   97               loadedClass = Class.forName(
   98                   this.packageName + "." + this.member,
   99                   true,
  100                   this.classLoader);
  101           } catch (ClassNotFoundException cnfe) {
  102               throw new RuntimeException(cnfe);
  103           }
  104           try {
  105               instance = loadedClass.newInstance();
  106           } catch (Exception e) {
  107               throw new RuntimeException(e);
  108           }
  109           
  110           return instance;
  111       }
  112   
  113       /** Asks if this ClassDef implements an interface.
  114        *
  115        * @param name The name of the ClassDef representing the interface.
  116        * @return True if the interface is implemented.
  117        */
  118       public boolean is(String name) {
  119           if (name.equals(getName())) return true;
  120   
  121           for (Iterator i = this.implemented.iterator(); i.hasNext(); )
  122               if (((ClassDefEntity) i.next()).is(name)) return true;
  123   
  124           return false;
  125       }
  126   
  127       // Instance Attributes.
  128   
  129       private ClassLibEntity classLib = null;
  130       private ServiceClassLoader classLoader = null;
  131       private List implemented = new LinkedList();
  132       private String member = null;
  133       private String packageName = null;
  134   }
  135   
  136   // $Log: ClassDefEntity.java,v $
  137   // Revision 1.4  2003/09/19 16:18:28  sfb
  138   // Refactored DefEntity.
  139   //
  140   
  141   /*
  142    * This is free software; you can redistribute it and/or modify
  143    * it under the terms of the GNU Lesser General Public License
  144    * as published by the Free Software Foundation; either version 2.1
  145    * of the License, or (at your option) any later version.
  146    *
  147    * This software is distributed in the hope that it will be useful,
  148    * but WITHOUT ANY WARRANTY; without even the implied warranty of
  149    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  150    * Lesser General Public License for more details.
  151    *
  152    * You should have received a copy of the GNU Lesser General Public
  153    * License along with this software; if not, write to the Free Software
  154    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  155    */

Save This Page
Home » openjdk-7 » net » sf » rvpf » metadata » [javadoc | source]