org.apache.myfaces.trinidad.bean.FacesBeanFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of trinidad-api Show documentation
Show all versions of trinidad-api Show documentation
Public API for the Apache MyFaces Trinidad project
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.myfaces.trinidad.bean;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
import org.apache.myfaces.trinidad.util.ThreadLocalUtils;
/**
* Base interface for FacesBean storage.
*/
public class FacesBeanFactory
{
/**
* Create a FacesBean for a component class.
*/
// TODO change from ownerClass to componentFamily?
static public FacesBean createFacesBean(
Class> ownerClass,
String rendererType)
{
if (ownerClass == null)
return null;
String className = ownerClass.getName();
FacesBean bean = createFacesBean(className, rendererType);
if (bean == null && rendererType != null)
{
bean = createFacesBean(className, null);
_cacheFacesBeanClass(bean, className, rendererType);
}
if (bean == null)
{
bean = createFacesBean(ownerClass.getSuperclass(), rendererType);
_cacheFacesBeanClass(bean, className, rendererType);
}
return bean;
}
static public FacesBean createFacesBean(
String beanType,
String rendererType)
{
String typeKey = _buildTypeKey(beanType, rendererType);
Class> type = _TYPES_CLASS.get(typeKey);
if(type == null)
{
String className = (String) _TYPES_MAP.get(typeKey);
if (className == null)
return null;
// At this point we did not have a cached FacesBean class for the
// typeKey, but we did have a cached className for the typeKey.
// Get the FacesBean class from the className and cache.
// This will improve performance based on tests.
try
{
type = _getClassLoader().loadClass(className);
_TYPES_CLASS.put(typeKey, type);
}
catch (ClassNotFoundException cnfe)
{
_LOG.severe("CANNOT_FIND_FACESBEAN", className);
_LOG.severe(cnfe);
}
}
try
{
return (FacesBean) type.newInstance();
}
catch (IllegalAccessException iae)
{
_LOG.severe("CANNOT_CREATE_FACESBEAN_INSTANCE", type.getName());
_LOG.severe(iae);
}
catch (InstantiationException ie)
{
_LOG.severe("CANNOT_CREATE_FACESBEAN_INSTANCE", type.getName());
_LOG.severe(ie);
}
return null;
}
static private void _initializeBeanTypes()
{
_TYPES_MAP = new HashMap