KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > extensions > types > AgentType


1 /*
2  */

3 package com.sslexplorer.extensions.types;
4
5 import java.io.IOException JavaDoc;
6 import java.util.Iterator JavaDoc;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10 import org.jdom.Element;
11
12 import com.sslexplorer.agent.AgentExtensionDefinition;
13 import com.sslexplorer.boot.Util;
14 import com.sslexplorer.extensions.ExtensionDescriptor;
15 import com.sslexplorer.extensions.ExtensionException;
16 import com.sslexplorer.extensions.ExtensionType;
17 import com.sslexplorer.security.SessionInfo;
18
19 /**
20  * Extension type that adds an <i>Agent Extension</i>.
21  *
22  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
23  */

24 public class AgentType implements ExtensionType {
25
26     final static Log log = LogFactory.getLog(AgentType.class);
27
28     /**
29      * Type name
30      */

31     public final static String JavaDoc TYPE = "agent";
32
33     // Private instance variables
34

35     private AgentExtensionDefinition def;
36
37     /*
38      * (non-Javadoc)
39      *
40      * @see com.sslexplorer.extensions.ExtensionType#start(com.sslexplorer.extensions.ExtensionDescriptor,
41      * org.jdom.Element)
42      */

43     public void start(ExtensionDescriptor descriptor, Element element) throws ExtensionException {
44
45         if (element.getName().equals(TYPE)) {
46             // Agent classname
47
String JavaDoc className = element.getAttributeValue("class");
48             String JavaDoc plugin = element.getAttributeValue("plugin");
49             Element xml = (Element) element.clone();
50             def = new AgentExtensionDefinition(descriptor, className, plugin, xml);
51             for (Iterator JavaDoc i = xml.getChildren().iterator(); i.hasNext();) {
52                 processElement((Element) i.next(), descriptor);
53             }
54
55             /**
56              * Notify the extension store of a new agent plugin
57              */

58             DefaultAgentType.addAgentExtension(def);
59         }
60     }
61     
62     private void processElement(Element xml, ExtensionDescriptor descriptor) throws ExtensionException {
63         
64         for (Iterator JavaDoc i = xml.getChildren().iterator(); i.hasNext();) {
65             Element el = (Element) i.next();
66             if (el.getName().equals("classpath")) {
67                 processElement(el, descriptor);
68             } else if(el.getName().equals("if")) {
69                 processElement(el, descriptor);
70             } else if(el.getName().equals("file")) {
71                 descriptor.processFile(el);
72             } else if(el.getName().equals("jar")) {
73                 descriptor.processFile(el);
74             }
75             
76         }
77     }
78
79     /*
80      * (non-Javadoc)
81      *
82      * @see com.sslexplorer.extensions.ExtensionType#verifyRequiredElements()
83      */

84     public void verifyRequiredElements() throws ExtensionException {
85
86     }
87
88     /*
89      * (non-Javadoc)
90      *
91      * @see com.sslexplorer.extensions.ExtensionType#isHidden()
92      */

93     public boolean isHidden() {
94         return true;
95     }
96
97     /*
98      * (non-Javadoc)
99      *
100      * @see com.sslexplorer.extensions.ExtensionType#getType()
101      */

102     public String JavaDoc getType() {
103         return TYPE;
104     }
105
106     /*
107      * (non-Javadoc)
108      *
109      * @see com.sslexplorer.extensions.ExtensionType#stop()
110      */

111     public void stop() throws ExtensionException {
112         if (def != null) {
113             DefaultAgentType.removeAgentExtension(def);
114         }
115     }
116
117     /*
118      * (non-Javadoc)
119      *
120      * @see com.sslexplorer.extensions.ExtensionType#active()
121      */

122     public void activate() throws ExtensionException {
123     }
124
125     /*
126      * (non-Javadoc)
127      *
128      * @see com.sslexplorer.extensions.ExtensionType#canStop()
129      */

130     public boolean canStop() throws ExtensionException {
131         return false;
132     }
133
134     /* (non-Javadoc)
135      * @see com.sslexplorer.extensions.ExtensionType#descriptorCreated(org.jdom.Element)
136      */

137     public void descriptorCreated(Element element, SessionInfo session) throws IOException JavaDoc {
138     }
139
140     /* (non-Javadoc)
141      * @see com.sslexplorer.extensions.ExtensionType#getTypeBundle()
142      */

143     public String JavaDoc getTypeBundle() {
144         return "extensions";
145     }
146 }
Popular Tags