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.runtime.bean;
20:
21: import org.apache.beehive.controls.api.bean.ControlBean;
22: import org.apache.beehive.controls.api.context.ControlBeanContext;
23: import org.apache.beehive.controls.spi.context.ControlBeanContextFactory;
24:
25: /**
26: * Default implementation of the {@link ControlBeanContextFactory} that simply creates an instance of a
27: * {@link ControlBeanContext} given the current {@link ControlBean}.
28: */
29: /* package */class DefaultControlBeanContextFactory implements
30: ControlBeanContextFactory {
31:
32: /**
33: * Create the {@link ControlBeanContext} for the {@link ControlBean}.
34: * @param controlBean
35: * @return the {@link ControlBeanContext}
36: */
37: public ControlBeanContext instantiate(ControlBean controlBean) {
38: if (!(controlBean instanceof org.apache.beehive.controls.runtime.bean.ControlBean))
39: throw new IllegalArgumentException(
40: "The ControlBean of type \""
41: + controlBean.getClass().getName()
42: + "\" is unsupported. The ControlBean must extend "
43: + org.apache.beehive.controls.runtime.bean.ControlBean.class
44: .getName());
45:
46: /*
47: The provided ControlBean is a "api.bean.ControlBean"; this factory implementation only creates
48: ControlBeanContext implementations for "runtime.bean.ControlBean" types. Ensuare that this is
49: of that type.
50: */
51: org.apache.beehive.controls.runtime.bean.ControlBean runtimeControlBean = (org.apache.beehive.controls.runtime.bean.ControlBean) controlBean;
52:
53: /*
54: Create a simple new ControlBeanContext.
55: */
56: return new org.apache.beehive.controls.runtime.bean.ControlBeanContext(
57: runtimeControlBean);
58: }
59: }
|