001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.controls.runtime.bean;
020:
021: import java.beans.beancontext.BeanContextServices;
022: import java.beans.beancontext.BeanContextServiceProvider;
023: import java.util.Iterator;
024: import java.util.Collections;
025:
026: import org.apache.beehive.controls.spi.context.ControlBeanContextFactory;
027: import org.apache.beehive.controls.runtime.webcontext.ControlBeanContextServicesSupport;
028:
029: /**
030: * <p>
031: * This class acts as a ControlBeanContextFactoryProvider that exposes this factory as a contextual service
032: * from inside of a ControlBeanContext.
033: * </p>
034: * <p>
035: * <b>Note:</b> This class, the service provider, and the contextual service it provides are considerd an implementation
036: * detail and <b>should not</b> be used from user code.
037: * </p>
038: */
039: public class WebContextFactoryProvider implements
040: BeanContextServiceProvider {
041:
042: private static final WebContextFactoryProvider theProvider = new WebContextFactoryProvider();
043: private static final WebControlBeanContextFactory theFactory = new WebControlBeanContextFactory();
044:
045: public static final ControlBeanContext.BeanContextServicesFactory WEB_CONTEXT_BCS_FACTORY = new WebContextBeanContextServicesFactory();
046:
047: public static BeanContextServiceProvider getProvider() {
048: return theProvider;
049: }
050:
051: private WebContextFactoryProvider() {
052: }
053:
054: public Object getService(BeanContextServices bcs, Object requestor,
055: Class serviceClass, Object serviceSelector) {
056: return theFactory;
057: }
058:
059: public void releaseService(BeanContextServices bcs,
060: Object requestor, Object service) {
061: }
062:
063: public Iterator getCurrentServiceSelectors(BeanContextServices bcs,
064: Class serviceClass) {
065: return Collections.EMPTY_LIST.iterator();
066: }
067:
068: /**
069: * <p>
070: * {@link ControlBeanContextFactory} implementation that provides a {@link ControlBeanContext} object
071: * used for web-tier control containment.
072: * </p>
073: * <p>
074: * <b>Note:</b> This factory is considerd an implementation detail and <b>should not</b> be referenced from user code.
075: * </p>
076: */
077: /*package*/static class WebControlBeanContextFactory implements
078: ControlBeanContextFactory {
079:
080: public org.apache.beehive.controls.api.context.ControlBeanContext instantiate(
081: org.apache.beehive.controls.api.bean.ControlBean controlBean) {
082:
083: if (!(controlBean instanceof ControlBean))
084: throw new IllegalArgumentException(
085: "The ControlBean of type \""
086: + controlBean.getClass().getName()
087: + "\" is unsupported. The ControlBean must extend "
088: + ControlBean.class.getName());
089:
090: ControlBean runtimeControlBean = (ControlBean) controlBean;
091:
092: return new ControlBeanContext(runtimeControlBean,
093: WEB_CONTEXT_BCS_FACTORY);
094: }
095: }
096:
097: /*package*/static class WebContextBeanContextServicesFactory
098: extends ControlBeanContext.BeanContextServicesFactory {
099: protected BeanContextServices instantiate(
100: ControlBeanContext controlBeanContext) {
101: return new ControlBeanContextServicesSupport(
102: controlBeanContext);
103:
104: /* The java implementation of the BeanContext support classes,
105: not currently used by Beehive due to performance issues.
106:
107: return new java.beans.beancontext.BeanContextServicesSupport(controlBeanContext);
108: */
109: }
110: }
111: }
|