1   package org.apache.fulcrum.yaafi;
2   
3   
4   /*
5    * Licensed to the Apache Software Foundation (ASF) under one
6    * or more contributor license agreements.  See the NOTICE file
7    * distributed with this work for additional information
8    * regarding copyright ownership.  The ASF licenses this file
9    * to you under the Apache License, Version 2.0 (the
10   * "License"); you may not use this file except in compliance
11   * with the License.  You may obtain a copy of the License at
12   *
13   *   http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing,
16   * software distributed under the License is distributed on an
17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   * KIND, either express or implied.  See the License for the
19   * specific language governing permissions and limitations
20   * under the License.
21   */
22  
23  
24  import java.io.File;
25  
26  import org.apache.avalon.framework.activity.Disposable;
27  import org.apache.avalon.framework.activity.Initializable;
28  import org.apache.avalon.framework.configuration.Configuration;
29  import org.apache.avalon.framework.configuration.ConfigurationException;
30  import org.apache.avalon.framework.configuration.Reconfigurable;
31  import org.apache.avalon.framework.context.Context;
32  import org.apache.avalon.framework.context.ContextException;
33  import org.apache.avalon.framework.context.Contextualizable;
34  import org.apache.avalon.framework.logger.AbstractLogEnabled;
35  import org.apache.avalon.framework.parameters.ParameterException;
36  import org.apache.avalon.framework.parameters.Parameterizable;
37  import org.apache.avalon.framework.parameters.Parameters;
38  
39  /**
40   * Implementation of the test component.
41   *
42   * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
43   */
44  public class TestComponentImpl
45          extends AbstractLogEnabled
46          implements Initializable, Reconfigurable, Parameterizable, Disposable, TestComponent, Contextualizable
47  {
48      public File urnAvaloneHome;
49      public File urnAvaloneTemp;
50      public String urnAvalonPartition;
51      public String urnAvalonName;
52      public ClassLoader urnAvalonClassLoader;
53  
54      public String foo;
55      public String bar;
56      public boolean decomissioned;
57      public String componentName;
58  
59      public void initialize() throws Exception
60      {
61          getLogger().debug("initialize() was called");
62          decomissioned = false;
63      }
64  
65      public void contextualize(Context context) throws ContextException
66      {
67          this.urnAvaloneHome = (File) context.get( "urn:avalon:home" );
68          this.urnAvaloneTemp = (File) context.get( "urn:avalon:temp" );
69          this.urnAvalonName = (String) context.get( "urn:avalon:name" );
70          this.urnAvalonPartition = (String) context.get( "urn:avalon:partition" );
71          this.urnAvalonClassLoader = (ClassLoader) context.get( "urn:avalon:classloader" );
72      }
73  
74      public void configure(Configuration configuration) throws ConfigurationException
75      {
76          this.foo = configuration.getChild("FOO").getValue("FOO Not Found?!");
77      }
78  
79      public void reconfigure(Configuration configuration)
80          throws ConfigurationException
81      {
82          this.configure(configuration);
83      }
84  
85      public void parameterize(Parameters parameters) throws ParameterException
86      {
87          this.bar = parameters.getParameter("BAR", "BAR Not Found?!");
88      }
89  
90      public void dispose()
91      {
92          getLogger().debug("dispose() was called");
93          this.decomissioned=true;
94      }
95  
96      public void test()
97      {
98          setupLogger(this, "TestComponent");
99          getLogger().debug("TestComponent.test() was called");
100         getLogger().debug("urnAvaloneHome = " + this.urnAvaloneHome.toString());
101         getLogger().debug("urnAvaloneTemp = " + this.urnAvaloneTemp.toString());
102         getLogger().debug("urnAvalonPartition = " + this.urnAvalonPartition);
103         getLogger().debug("urnAvalonName = " + this.urnAvalonName);
104         getLogger().debug("foo = " + this.foo );
105         getLogger().debug("bar = " + this.bar );
106     }
107     /**
108      * @return Returns the bar.
109      */
110     public String getBar()
111     {
112         return bar;
113     }
114     /**
115      * @return Returns the componentName.
116      */
117     public String getComponentName()
118     {
119         return componentName;
120     }
121     /**
122      * @return Returns the decomissioned.
123      */
124     public boolean isDecomissioned()
125     {
126         return decomissioned;
127     }
128     /**
129      * @return Returns the foo.
130      */
131     public String getFoo()
132     {
133         return foo;
134     }
135     /**
136      * @return Returns the urnAvalonClassLoader.
137      */
138     public ClassLoader getUrnAvalonClassLoader()
139     {
140         return urnAvalonClassLoader;
141     }
142     /**
143      * @return Returns the urnAvaloneHome.
144      */
145     public File getUrnAvaloneHome()
146     {
147         return urnAvaloneHome;
148     }
149     /**
150      * @return Returns the urnAvaloneTemp.
151      */
152     public File getUrnAvaloneTemp()
153     {
154         return urnAvaloneTemp;
155     }
156     /**
157      * @return Returns the urnAvalonName.
158      */
159     public String getUrnAvalonName()
160     {
161         return urnAvalonName;
162     }
163     /**
164      * @return Returns the urnAvalonPartition.
165      */
166     public String getUrnAvalonPartition()
167     {
168         return urnAvalonPartition;
169     }
170 
171     /**
172      * @see org.apache.fulcrum.yaafi.TestComponent#createException(String,Object)
173      */
174     public void createException(String reason, Object caller)
175     {
176         throw new RuntimeException(reason);
177     }
178 
179     public void doSomething(long millis, Object arg)
180     {
181         try
182         {
183             Thread.sleep(millis);
184         }
185         catch (InterruptedException e)
186         {
187             // nothing to do
188         }
189     }
190 }