Changeset 134


Ignore:
Timestamp:
09/03/10 19:17:29 (21 months ago)
Author:
golgolito
Message:

Javadoc for GWT Module

Location:
trunk/blaapps/kernel-sandbox/gwt
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/blaapps/kernel-sandbox/gwt/core-shared/src/main/java/org/blaapps/gwt/GwtModuleMBean.java

    r131 r134  
    2525 
    2626/** 
    27  * Interface for the Web Module's Management Bean. 
     27 * Interface for the GWT Module's Management Bean. 
    2828 *  
    2929 * @author Víctor Jiménez Cerrada 
     
    3434 
    3535        /** 
    36          * Remote Module's Management Bean name. 
     36         * GWT Module's Management Bean name. 
    3737         */ 
    3838        public static final String GWT_MANAGER_OBJECT_NAME = "org.blaapps.gwt:type=GWT_MANAGER"; 
    3939         
     40        /** 
     41         * Returns the path where Blaapps stores static content for a Module. 
     42         *  
     43         * @param moduleName The module to search for static content 
     44         * @return the path where moduleName static contents are. 
     45         */ 
    4046        public String getModuleDeployerPath(String moduleName); 
    4147 
    42         /** 
    43          * @param parent 
    44          * @return 
    45          */ 
    46         Collection<Class<Widget>> getParentWidgets(String parent); 
    4748} 
  • trunk/blaapps/kernel-sandbox/gwt/core-shared/src/main/java/org/blaapps/gwt/annotations/GWT.java

    r131 r134  
    2626 
    2727/** 
     28 * <p> 
     29 * Annotation for GWT Modules. 
     30 * </p><p> 
     31 * Annotate a class with this annotation so Blaapps can Load the GWT module. 
     32 * </p> 
     33 *  
    2834 * @author Víctor Jiménez Cerrada 
    2935 * @version 0.5.0 
     
    3440@Shared 
    3541public @interface GWT { 
     42        /** 
     43         * The GWT module's name. 
     44         *  
     45         * Defaults to "". 
     46         */ 
    3647        String name() default ""; 
     48         
     49        /** 
     50         * The entry class for the module. 
     51         *  
     52         * Defaults to "". 
     53         */ 
    3754        String entryClass() default ""; 
    3855} 
  • trunk/blaapps/kernel-sandbox/gwt/core-shared/src/main/java/org/blaapps/gwt/annotations/GWTWidget.java

    r131 r134  
    2626 
    2727/** 
     28 * <p> 
     29 * Annotation for GWT Widgets. 
     30 * </p><p> 
     31 * Intended to annotate Widgets so blaapps could create dynamic interfaces... 
     32 * Was a failed experiment. 
     33 * </p> 
     34 *  
    2835 * @author Víctor Jiménez Cerrada 
    2936 * @version 0.5.0 
    3037 * @since 0.5.0 
    3138 */ 
     39// TODO Remove me. There's no more sense in my existence. 
    3240@Retention(RetentionPolicy.RUNTIME) 
    3341@Target(ElementType.TYPE) 
  • trunk/blaapps/kernel-sandbox/gwt/core/src/main/java/org/blaapps/gwt/BlaappsWorkDirs.java

    r131 r134  
    2929 
    3030/** 
     31 * Implementation of WorkDirs that reads static content location from Blaapps 
     32 * GWT Module. 
     33 *  
    3134 * @author Víctor Jiménez Cerrada 
    3235 * @version 0.5.0 
  • trunk/blaapps/kernel-sandbox/gwt/core/src/main/java/org/blaapps/gwt/GwtCompiler.java

    r131 r134  
    2323 
    2424/** 
     25 * Tools to Compile GWT modules inside Blaapps Modules. 
     26 *  
    2527 * @author Víctor Jiménez Cerrada 
    2628 * @version 0.5.0 
     
    2931public class GwtCompiler { 
    3032 
    31         static File tempdir; 
     33    /** 
     34     * Tempdir to store Compilation results 
     35     */ 
     36    static File tempdir; 
    3237 
    33         static { 
    34                 try { 
    35                         tempdir = File.createTempFile("Blaapps-GWT", ""); 
    36                         tempdir.delete(); 
    37                         tempdir.mkdirs(); 
    38                         tempdir.deleteOnExit(); 
    39                 } catch (IOException e) { 
    40                         // FIXME 
    41                         e.printStackTrace(); 
    42                         System.exit(1); 
    43                 } 
     38    static { 
     39        try { 
     40            tempdir = File.createTempFile("Blaapps-GWT", ""); 
     41            tempdir.delete(); 
     42            tempdir.mkdirs(); 
     43            tempdir.deleteOnExit(); 
     44        } catch (IOException e) { 
     45            // FIXME 
     46            e.printStackTrace(); 
     47            System.exit(1); 
     48        } 
     49    } 
     50 
     51    /** 
     52     * Security Manager to avoid GWT Compiler to terminate de JVM. 
     53     *  
     54     * @author Víctor Jiménez Cerrada 
     55     * @version 0.5.0 
     56     * @since 0.5.0 
     57     */ 
     58    private static class NoExitSecurityManager extends SecurityManager { 
     59        @Override 
     60        public void checkPermission(Permission perm) { 
     61            // allow anything. 
    4462        } 
    4563 
    46         private static class NoExitSecurityManager extends SecurityManager { 
    47                 @Override 
    48                 public void checkPermission(Permission perm) { 
    49                         // allow anything. 
    50                 } 
    51  
    52                 @Override 
    53                 public void checkPermission(Permission perm, Object context) { 
    54                         // allow anything. 
    55                 } 
    56  
    57                 @Override 
    58                 public void checkExit(int status) { 
    59                         super.checkExit(status); 
    60                         throw new NoExitException(status); 
    61                 } 
     64        @Override 
     65        public void checkPermission(Permission perm, Object context) { 
     66            // allow anything. 
    6267        } 
    6368 
    64         @SuppressWarnings("serial") 
    65         protected static class NoExitException extends SecurityException { 
     69        @Override 
     70        public void checkExit(int status) { 
     71            super.checkExit(status); 
     72            throw new NoExitException(status); 
     73        } 
     74    } 
    6675 
    67                 int status; 
     76    /** 
     77     * Exception wich stores the exit code when a {@link NoExitSecurityManager} 
     78     * frustrates a System.exit call. 
     79     *  
     80     * @author Víctor Jiménez Cerrada 
     81     * @version 0.5.0 
     82     * @since 0.5.0 
     83     */ 
     84    @SuppressWarnings("serial") 
     85    protected static class NoExitException extends SecurityException { 
    6886 
    69                 /** 
    70                  *  
    71                  */ 
    72                 public NoExitException(int status) { 
    73                         super("Someone tried to exit with exit status " + status 
    74                                         + ". Show must go on!"); 
    75                         this.status = status; 
    76                 } 
    77  
    78                 /** 
    79                  * @return the code 
    80                  */ 
    81                 public int getCode() { 
    82                         return status; 
    83                 } 
     87        int status; 
     88         
     89        public NoExitException(int status) { 
     90            super("Someone tried to exit with exit status " + status 
     91                    + ". Show must go on!"); 
     92            this.status = status; 
    8493        } 
    8594 
    86         public static String compileGwtModule(String moduleName, 
    87                         final String gwtName) throws InterruptedException { 
     95        public int getCode() { 
     96            return status; 
     97        } 
     98    } 
    8899 
    89                 final String compileOutput = tempdir.getAbsolutePath() + "/" + moduleName; 
     100    /** 
     101     * Compiles a GWT Module. 
     102     *  
     103     * @param moduleName 
     104     * @param gwtName 
     105     * @return The path where the result has been placed. 
     106     * @throws InterruptedException 
     107     */ 
     108    public static String compileGwtModule(String moduleName, 
     109            final String gwtName) throws InterruptedException { 
    90110 
    91                 Runnable compiler = new Runnable() { 
    92                         @Override 
    93                         public void run() { 
    94                                 com.google.gwt.dev.Compiler.main(new String[] { 
    95                                                 gwtName, 
    96                                                 "-war", 
    97                                                 compileOutput 
    98                                 }); 
    99                         } 
    100                 }; 
    101                  
    102                 Thread compilert = new Thread(compiler); 
    103                 SecurityManager manager = System.getSecurityManager(); 
    104                 System.setSecurityManager(new NoExitSecurityManager()); 
    105                 compilert.start(); 
    106                 compilert.join(); 
    107                 System.setSecurityManager(manager); 
     111        final String compileOutput = tempdir.getAbsolutePath() + "/" 
     112                + moduleName; 
    108113 
    109                 return compileOutput; 
    110         } 
     114        Runnable compiler = new Runnable() { 
     115            @Override 
     116            public void run() { 
     117                com.google.gwt.dev.Compiler.main(new String[] { gwtName, 
     118                        "-war", compileOutput }); 
     119            } 
     120        }; 
     121 
     122        Thread compilert = new Thread(compiler); 
     123        SecurityManager manager = System.getSecurityManager(); 
     124        System.setSecurityManager(new NoExitSecurityManager()); 
     125        compilert.start(); 
     126        compilert.join(); 
     127        System.setSecurityManager(manager); 
     128 
     129        return compileOutput; 
     130    } 
    111131} 
  • trunk/blaapps/kernel-sandbox/gwt/core/src/main/java/org/blaapps/gwt/GwtModule.java

    r131 r134  
    5252/** 
    5353 * <p> 
    54  * The Web Module. 
     54 * The GWT Module. 
    5555 * </p> 
    5656 *  
     
    6969) 
    7070public class GwtModule implements GwtModuleMBean { 
    71          
    72         /** 
    73          * Map of the current GWT modules grouped by module name. 
    74          */ 
    75         private HashMap<String, String> deploymentMap = new HashMap<String, String>(); 
    76  
    77         /** 
    78          * Map of the current Blaapps modules and it's GWT module name. 
    79          */ 
    80         private HashMap<String, String> modulesMap = new HashMap<String, String>(); 
    81          
    82         /** 
    83          * Map of the Modules and it's GWT Widgets name. 
    84          */ 
    85         private HashMap<String, Collection<Class<Widget>>> widgetsMap = new HashMap<String, Collection<Class<Widget>>>(); 
    86          
    87         /** 
    88          * Map of the GWT Widgets name sorted by parent. 
    89          */ 
    90         private HashMap<String, Collection<Class<Widget>>> parentMap = new HashMap<String, Collection<Class<Widget>>>(); 
    91          
    92         /** 
    93          * This module's {@link Logger} 
    94          */ 
    95         @Log 
    96         private Logger log; 
    97          
    98         /** 
    99          * This module's Configuration. 
    100          */ 
    101         @Conf 
    102         private Properties conf; 
    103          
    104         /** 
    105          * Blaapps {@link MBeanServer}. 
    106          */ 
    107         @ManagementServer 
    108         private MBeanServer server; 
    109  
    110         /** 
    111          * Initializes the Remote Module. 
    112          */ 
    113         public GwtModule() { 
    114                  
    115                 ObjectName webName; 
    116                 try { 
    117                         webName = new ObjectName(GWT_MANAGER_OBJECT_NAME); 
    118                         server.registerMBean(this, webName); 
    119                 } catch (Exception e) { 
    120                         // If an exception is raised it's because a programming error. 
    121                         // Don't raise a checked exception if it's not a runtime error. 
    122                         e.printStackTrace(); 
    123                         throw new Error(e); 
    124                 } 
    125 //              Blaapps.widgets = parentMap; 
    126         } 
    127  
    128         /** 
    129          * Starts the Jetty Server 
    130          *  
    131          */ 
    132         @SuppressWarnings("unused") 
    133         @BeforeDeployment 
    134         private synchronized void startWebServer() {} 
    135  
    136         /** 
    137          * Stops the Jetty Server 
    138          *  
    139          */ 
    140         @SuppressWarnings("unused") 
    141         @BeforeUndeployment 
    142         private synchronized void runUndeploy() {} 
    143  
    144         /** 
    145          * Registers a new GUI Item Instance 
    146          *  
    147          * @throws BlaappsJettyException 
    148          *             If server could not be restarted 
    149          * @throws IllegalAccessException  
    150          * @throws InstantiationException  
    151          */ 
    152         @InBox(CLASS_FOUND) 
    153         @SuppressWarnings("unused") 
    154         private synchronized void registerGwtModule(Message message) 
    155                         throws InstantiationException, IllegalAccessException { 
    156                 String moduleName = (String) message.getAttachments()[0]; 
    157                 Class<?> clazz = (Class<?>) message.getAttachments()[1]; 
    158  
    159                 // Interfaces to check 
    160                 GWT annon = clazz.getAnnotation(GWT.class); 
    161                  
    162                 if (annon != null) { 
    163                         String gwtName = annon.name(); 
    164                         String deploydir = null; 
    165                                                  
    166                         // compile Module 
    167                         try { 
    168                                 deploydir = GwtCompiler.compileGwtModule(moduleName, gwtName); 
    169                         } catch (InterruptedException e) { 
    170                                 log.error("Error while compiling GWT module " + moduleName); 
    171                                 // FIXME 
    172                                 // if compilation fails... loading should fail... 
    173                         } 
    174                          
    175                         // Once compiled, register 
    176                         modulesMap.put(moduleName, annon.name()); 
    177                         deploymentMap.put(annon.name(), deploydir); 
    178                 } 
    179         } 
    180          
    181         /** 
    182          * Registers a new GUI Item Instance 
    183          *  
    184          * @throws BlaappsJettyException 
    185          *             If server could not be restarted 
    186          * @throws IllegalAccessException  
    187          * @throws InstantiationException  
    188          */ 
    189         @InBox(CLASS_FOUND) 
    190         @SuppressWarnings({ "unused", "unchecked" }) 
    191         private synchronized void registerGwtWidget(Message message) 
    192                         throws InstantiationException, IllegalAccessException { 
    193                 String moduleName = (String) message.getAttachments()[0]; 
    194                 Class<?> clazz = (Class<?>) message.getAttachments()[1]; 
    195  
    196                 // Interfaces to check 
    197                 GWTWidget annon = clazz.getAnnotation(GWTWidget.class); 
    198                  
    199                 if (annon != null && Widget.class.isAssignableFrom(clazz)) { 
    200                          
    201                         Class<Widget> widget = (Class<Widget>) clazz; 
    202                          
    203                         String parent = annon.parent(); 
    204                          
    205                         // Register 
    206                         if (!widgetsMap.containsKey(moduleName)) {                               
    207                                 widgetsMap.put(moduleName, new HashSet<Class<Widget>>()); 
    208                         } 
    209                         widgetsMap.get(moduleName).add(widget); 
    210                          
    211                         if (!parentMap.containsKey(parent)) {            
    212                                 parentMap.put(parent, new HashSet<Class<Widget>>()); 
    213                         } 
    214                         parentMap.get(parent).add(widget); 
    215                 } 
    216         } 
    217          
    218         /** 
    219          * Unregisters Servlets defined by a module 
    220          *  
    221          * @throws BlaappsJettyException 
    222          *             If server can't be restarted 
    223          */ 
    224         @SuppressWarnings("unused") 
    225         @InBox(MODULE_UNLOADING) 
    226         private synchronized void unregisterModule(Message message) 
    227                         throws BlaappsJettyException { 
    228                 String moduleName = (String) message.getAttachments()[0]; 
    229                  
    230                 // Unregister only if there's something to unregister 
    231                 if (!modulesMap.containsKey(moduleName)) 
    232                         return; 
    233  
    234                 // Remove files on deploydir 
    235                 String gwtname = modulesMap.get(moduleName); 
    236                 String deploydir = deploymentMap.get(gwtname); 
    237                 File deployfile = new File(deploydir); 
    238                 deployfile.delete(); 
    239                  
    240                 // Remove from contextsMap 
    241                 deploymentMap.remove(gwtname); 
    242                 modulesMap.remove(moduleName); 
    243                  
    244                 // Remove widgets 
    245                 Collection<Class<Widget>> widgets = widgetsMap.get(moduleName); 
    246                 for (Collection<Class<Widget>> parents : widgetsMap.values()) { 
    247                         parents.removeAll(widgets); 
    248                 } 
    249                 widgetsMap.remove(moduleName); 
    250         } 
    251  
    252         @Override 
    253         public String getModuleDeployerPath(String moduleName) { 
    254                 return deploymentMap.get(moduleName); 
    255         } 
    256          
    257         @Override 
    258         public Collection<Class<Widget>> getParentWidgets(String parent) { 
    259                 return parentMap.get(parent); 
    260         } 
     71 
     72    /** 
     73     * Map of the current GWT modules grouped by module name. 
     74     */ 
     75    private HashMap<String, String> deploymentMap = new HashMap<String, String>(); 
     76 
     77    /** 
     78     * Map of the current Blaapps modules and it's GWT module name. 
     79     */ 
     80    private HashMap<String, String> modulesMap = new HashMap<String, String>(); 
     81 
     82    /** 
     83     * Map of the Modules and it's GWT Widgets name. 
     84     */ 
     85    private HashMap<String, Collection<Class<Widget>>> widgetsMap = new HashMap<String, Collection<Class<Widget>>>(); 
     86 
     87    /** 
     88     * Map of the GWT Widgets name sorted by parent. 
     89     */ 
     90    private HashMap<String, Collection<Class<Widget>>> parentMap = new HashMap<String, Collection<Class<Widget>>>(); 
     91 
     92    /** 
     93     * This module's {@link Logger} 
     94     */ 
     95    @Log 
     96    private Logger log; 
     97 
     98    /** 
     99     * This module's Configuration. 
     100     */ 
     101    @Conf 
     102    private Properties conf; 
     103 
     104    /** 
     105     * Blaapps {@link MBeanServer}. 
     106     */ 
     107    @ManagementServer 
     108    private MBeanServer server; 
     109 
     110    /** 
     111     * Initializes the Remote Module. 
     112     */ 
     113    public GwtModule() { 
     114 
     115        ObjectName webName; 
     116        try { 
     117            webName = new ObjectName(GWT_MANAGER_OBJECT_NAME); 
     118            server.registerMBean(this, webName); 
     119        } catch (Exception e) { 
     120            // If an exception is raised it's because a programming error. 
     121            // Don't raise a checked exception if it's not a runtime error. 
     122            e.printStackTrace(); 
     123            throw new Error(e); 
     124        } 
     125        // Blaapps.widgets = parentMap; 
     126    } 
     127 
     128    /** 
     129     * Registers a new GUI Item Instance 
     130     *  
     131     * @throws BlaappsJettyException 
     132     *             If server could not be restarted 
     133     * @throws IllegalAccessException 
     134     * @throws InstantiationException 
     135     */ 
     136    @InBox(CLASS_FOUND) 
     137    @SuppressWarnings("unused") 
     138    private synchronized void registerGwtModule(Message message) 
     139            throws InstantiationException, IllegalAccessException { 
     140        String moduleName = (String) message.getAttachments()[0]; 
     141        Class<?> clazz = (Class<?>) message.getAttachments()[1]; 
     142 
     143        // Interfaces to check 
     144        GWT annon = clazz.getAnnotation(GWT.class); 
     145 
     146        if (annon != null) { 
     147            String gwtName = annon.name(); 
     148            String deploydir = null; 
     149 
     150            // compile Module 
     151            try { 
     152                deploydir = GwtCompiler.compileGwtModule(moduleName, gwtName); 
     153            } catch (InterruptedException e) { 
     154                log.error("Error while compiling GWT module " + moduleName); 
     155                // FIXME 
     156                // if compilation fails... loading should fail... 
     157            } 
     158 
     159            // Once compiled, register 
     160            modulesMap.put(moduleName, annon.name()); 
     161            deploymentMap.put(annon.name(), deploydir); 
     162        } 
     163    } 
     164 
     165    /** 
     166     * Registers a new GUI Item Instance 
     167     *  
     168     * @throws BlaappsJettyException 
     169     *             If server could not be restarted 
     170     * @throws IllegalAccessException 
     171     * @throws InstantiationException 
     172     */ 
     173    @InBox(CLASS_FOUND) 
     174    @SuppressWarnings({ "unused", "unchecked" }) 
     175    private synchronized void registerGwtWidget(Message message) 
     176            throws InstantiationException, IllegalAccessException { 
     177        String moduleName = (String) message.getAttachments()[0]; 
     178        Class<?> clazz = (Class<?>) message.getAttachments()[1]; 
     179 
     180        // Interfaces to check 
     181        GWTWidget annon = clazz.getAnnotation(GWTWidget.class); 
     182 
     183        if (annon != null && Widget.class.isAssignableFrom(clazz)) { 
     184 
     185            Class<Widget> widget = (Class<Widget>) clazz; 
     186 
     187            String parent = annon.parent(); 
     188 
     189            // Register 
     190            if (!widgetsMap.containsKey(moduleName)) { 
     191                widgetsMap.put(moduleName, new HashSet<Class<Widget>>()); 
     192            } 
     193            widgetsMap.get(moduleName).add(widget); 
     194 
     195            if (!parentMap.containsKey(parent)) { 
     196                parentMap.put(parent, new HashSet<Class<Widget>>()); 
     197            } 
     198            parentMap.get(parent).add(widget); 
     199        } 
     200    } 
     201 
     202    /** 
     203     * Unregisters Servlets defined by a module 
     204     *  
     205     * @throws BlaappsJettyException 
     206     *             If server can't be restarted 
     207     */ 
     208    @SuppressWarnings("unused") 
     209    @InBox(MODULE_UNLOADING) 
     210    private synchronized void unregisterModule(Message message) 
     211            throws BlaappsJettyException { 
     212        String moduleName = (String) message.getAttachments()[0]; 
     213 
     214        // Unregister only if there's something to unregister 
     215        if (!modulesMap.containsKey(moduleName)) 
     216            return; 
     217 
     218        // Remove files on deploydir 
     219        String gwtname = modulesMap.get(moduleName); 
     220        String deploydir = deploymentMap.get(gwtname); 
     221        File deployfile = new File(deploydir); 
     222        deployfile.delete(); 
     223 
     224        // Remove from contextsMap 
     225        deploymentMap.remove(gwtname); 
     226        modulesMap.remove(moduleName); 
     227 
     228        // Remove widgets 
     229        Collection<Class<Widget>> widgets = widgetsMap.get(moduleName); 
     230        for (Collection<Class<Widget>> parents : widgetsMap.values()) { 
     231            parents.removeAll(widgets); 
     232        } 
     233        widgetsMap.remove(moduleName); 
     234    } 
     235 
     236    @Override 
     237    public String getModuleDeployerPath(String moduleName) { 
     238        return deploymentMap.get(moduleName); 
     239    } 
     240 
    261241} 
  • trunk/blaapps/kernel-sandbox/gwt/core/src/main/java/org/blaapps/gwt/GwtServlet.java

    r131 r134  
    3232 
    3333/** 
     34 * Servlet to serve GWT static content. 
     35 *  
    3436 * @author Víctor Jiménez Cerrada 
    3537 * @version 0.5.0 
     
    3941public class GwtServlet extends GWTShellServlet { 
    4042 
    41         private static final long serialVersionUID = 1L; 
     43    private static final long serialVersionUID = 1L; 
    4244 
    43          
    44         @Override 
    45         protected void service(HttpServletRequest request, 
    46                         HttpServletResponse response) throws ServletException, IOException { 
    47                 ServletContext servletContext = getServletContext(); 
    48                 final String attr = "com.google.gwt.dev.shell.workdirs"; 
    49                 WorkDirs workDirs = new BlaappsWorkDirs();  
    50                 servletContext.setAttribute(attr, workDirs);     
    51                  
    52                 super.service(request, response); 
    53         } 
    54          
     45    @Override 
     46    protected void service(HttpServletRequest request, 
     47            HttpServletResponse response) throws ServletException, IOException { 
     48        ServletContext servletContext = getServletContext(); 
     49        final String attr = "com.google.gwt.dev.shell.workdirs"; 
     50        WorkDirs workDirs = new BlaappsWorkDirs(); 
     51        servletContext.setAttribute(attr, workDirs); 
     52 
     53        super.service(request, response); 
     54    } 
     55 
    5556} 
Note: See TracChangeset for help on using the changeset viewer.