01: /*
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16:
17: $Header:$
18: */
19: package org.apache.beehive.controls.test.util;
20:
21: import org.apache.beehive.controls.api.bean.Controls;
22: import org.apache.beehive.controls.api.context.ControlThreadContext;
23: import org.apache.beehive.controls.api.context.ControlContainerContext;
24: import org.apache.beehive.controls.test.ControlTestException;
25:
26: /**
27: *
28: */
29: public class ControlContainerContextManager {
30:
31: private ControlContainerContext _controlContainerContext;
32:
33: protected ControlContainerContextManager(
34: ControlContainerContext controlContainerContext) {
35: super ();
36: _controlContainerContext = controlContainerContext;
37: }
38:
39: public ControlContainerContext getControlContainerContext() {
40: return ControlThreadContext.getContext();
41: }
42:
43: public void instantiateControls(Object object) {
44: Class testClass = object.getClass();
45: try {
46: Controls.initializeClient(Thread.currentThread()
47: .getContextClassLoader(), object,
48: ControlThreadContext.getContext());
49: } catch (Exception e) {
50: if (e.getCause() instanceof ClassNotFoundException)
51: System.err.println("Could not locate initializer for '"
52: + getClass().getName()
53: + "'. Assuming no controls to initialize");
54: else
55: throw new ControlTestException(
56: "Exception initializing controls for type '"
57: + testClass.getName() + "'", e);
58: }
59: }
60:
61: public void beginContext() {
62: _controlContainerContext.beginContext();
63: }
64:
65: public void endContext() {
66: _controlContainerContext.endContext();
67: }
68: }
|