KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > module > builders > Resources


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.module.builders;
11
12 import org.mmbase.module.core.*;
13 import org.mmbase.bridge.*;
14 import org.mmbase.util.*;
15 import org.mmbase.util.logging.*;
16
17 /**
18  * The resources builder can be used by {@link org.mmbase.util.ResourceLoader} to load resources from
19  * (configuration files, classes, resourcebundles).
20  *
21  * @author Michiel Meeuwissen
22  * @version $Id: Resources.java,v 1.4 2006/02/20 17:39:25 michiel Exp $
23  * @since MMBase-1.8
24  */

25 public class Resources extends Attachments {
26     private static final Logger log = Logging.getLoggerInstance(Resources.class);
27
28     /**
29      * Registers this builder in the ResourceLoader.
30      * {@inheritDoc}
31      */

32     public boolean init() {
33         boolean res = super.init();
34         if (res) {
35             ThreadPools.jobsExecutor.execute(new Runnable JavaDoc() {
36                     public void run() {
37                         Cloud cloud = null;
38                         while (cloud == null) {
39                             try {
40                                 cloud = ContextProvider.getDefaultCloudContext().getCloud("mmbase", "class", null);
41                             } catch (Throwable JavaDoc t) {
42                                 log.info(t.getMessage());
43                             }
44                             if (cloud == null) {
45                                 try {
46                                     log.info("No cloud found, waiting for 5 seconds");
47                                     Thread.sleep(5000);
48                                 } catch (InterruptedException JavaDoc ie) {
49                                     return;
50                                 }
51                             }
52                         }
53                         ResourceLoader.setResourceBuilder(cloud.getNodeManager(Resources.this.getTableName()));
54                     }
55                 });
56         }
57         return res;
58
59     }
60
61     /**
62      * Implements virtual filename field.
63      * {@inheritDoc}
64      */

65     public Object JavaDoc getValue(MMObjectNode node, String JavaDoc field) {
66         if (field.equals(ResourceLoader.FILENAME_FIELD)) {
67             String JavaDoc s = node.getStringValue(ResourceLoader.RESOURCENAME_FIELD);
68             int i = s.lastIndexOf("/");
69             if (i > 0) {
70                 return s.substring(i + 1);
71             } else {
72                 return s;
73             }
74         } else {
75             return super.getValue(node, field);
76         }
77     }
78
79 }
80
Popular Tags