KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > plugins > preferences > ProxyPreferenceSetPlugin


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.core.plugins.preferences;
10
11 import java.lang.reflect.Proxy JavaDoc;
12
13 import org.apache.log4j.Logger;
14 import org.jboss.portal.common.metadata.MetaData;
15 import org.jboss.portal.common.util.ProxyInfo;
16 import org.jboss.portal.core.metadata.ProxyPreferenceSetMetaData;
17 import org.jboss.portal.core.util.ProxyValidator;
18 import org.jboss.portal.server.Application;
19 import org.jboss.portal.server.Component;
20 import org.jboss.portal.server.plugins.PluginService;
21
22 /**
23  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
24  * @version $Revision: 1.2 $
25  */

26 public class ProxyPreferenceSetPlugin
27    extends PluginService
28 {
29
30    /** Our logger. */
31    protected Logger log = Logger.getLogger(getClass());
32
33    /** Our meta data. */
34    protected ProxyPreferenceSetMetaData metaData;
35
36    /** The loaded proxy infos. */
37    protected ProxyInfo proxy;
38
39    public ProxyPreferenceSetPlugin()
40    {
41    }
42
43    public void start() throws Exception JavaDoc
44    {
45       String JavaDoc proxyClassName = this.metaData.getProxyClassName();
46
47       try
48       {
49          Component component = (Component)container;
50          Application application = component.getApplication();
51          ClassLoader JavaDoc loader = application.getClassLoader();
52          Class JavaDoc proxyITF = loader.loadClass(proxyClassName);
53          log.debug("Preferences proxy class loaded " + proxyClassName);
54
55          // Check interface validity
56
ProxyValidator.Error[] errors = ProxyValidator.validate(proxyITF);
57          if (errors.length == 0)
58          {
59             // Create proxy class
60
Class JavaDoc proxyClass = Proxy.getProxyClass(loader, new Class JavaDoc[]{proxyITF});
61             proxy = new ProxyInfo(proxyClass);
62             log.debug("Preferences proxy class created " + proxyClassName);
63          }
64          else
65          {
66             // julien : consider to throw an appropriate exception, for now it will suffice
67
log.error("Invalid preference proxy class, it will not be created");
68             for (int i = 0;i < errors.length;i++)
69             {
70                ProxyValidator.Error error = errors[i];
71                log.error("Invalid preference proxy class" + error.getDescription());
72             }
73          }
74       }
75       catch (Exception JavaDoc e)
76       {
77          log.error("Cannot load preference proxy class " + proxyClassName);
78       }
79    }
80
81    public void setMetaData(MetaData metaData)
82    {
83       // Get meta data
84
this.metaData = (ProxyPreferenceSetMetaData)metaData;
85    }
86
87    public MetaData getMetaData()
88    {
89       return metaData;
90    }
91
92    public ProxyInfo getProxy()
93    {
94       return proxy;
95    }
96 }
97
Popular Tags