CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-liferay-portal--com-liferay-portal-impl

Core implementation module containing the fundamental services, utilities, and infrastructure components for the Liferay Digital Experience Platform.

Pending
Overview
Eval results
Files

bean-management.mddocs/

Bean Management & Dependency Injection

Spring-based dependency injection system providing comprehensive bean location, property access, manipulation, and Velocity template integration for the Liferay portal framework.

Capabilities

Bean Location

Locates and retrieves beans from the Spring ApplicationContext with special handling for Velocity template integration.

/**
 * Implementation of BeanLocator interface providing Spring ApplicationContext-based bean location
 */
public class BeanLocatorImpl implements BeanLocator {
    
    /**
     * Locates a bean by name with special handling for .velocity suffix
     * @param name the bean name to locate
     * @return the located bean instance
     * @throws BeanLocatorException if bean not found
     */
    public Object locate(String name) throws BeanLocatorException;
    
    /**
     * Locates beans by type and returns a map of bean names to instances
     * @param clazz the class type to locate
     * @return Map of bean names to bean instances of specified type
     * @throws BeanLocatorException if beans cannot be located
     */
    public <T> Map<String, T> locate(Class<T> clazz) throws BeanLocatorException;
    
    /**
     * Returns all bean definition names in the ApplicationContext
     * @return array of all bean names
     */
    public String[] getNames();
    
    /**
     * Cleanup method for ApplicationContext resources
     */
    public void destroy();
    
    /**
     * Gets the underlying Spring ApplicationContext
     * @return ApplicationContext instance
     */
    public ApplicationContext getApplicationContext();
    
    /**
     * Gets the ClassLoader used by this bean locator
     * @return ClassLoader instance
     */
    public ClassLoader getClassLoader();
    
    /**
     * Gets the type of the specified bean
     * @param name the bean name
     * @return Class type of the bean
     */
    public Class<?> getType(String name);
}

Usage Examples:

BeanLocatorImpl beanLocator = new BeanLocatorImpl();

// Locate bean by name
Object myService = beanLocator.locate("myServiceBean");

// Locate beans by type (returns Map)
Map<String, UserService> userServices = beanLocator.locate(UserService.class);
UserService userService = userServices.values().iterator().next();

// Get all bean names
String[] allBeans = beanLocator.getNames();

// Special Velocity integration - appending .velocity suffix
Object velocityBean = beanLocator.locate("templateEngine.velocity");

Bean Properties

Comprehensive bean property access and manipulation utilities with support for all primitive types, HTTP parameter binding, and deep copying.

/**
 * Implementation of BeanProperties interface for bean property operations
 */
public class BeanPropertiesImpl implements BeanProperties {
    
    /**
     * Get boolean property value from bean
     * @param bean the target bean
     * @param param the property name
     * @return boolean value of property
     */
    public boolean getBoolean(Object bean, String param);
    
    /**
     * Get boolean property value from bean with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return boolean value of property or default value
     */
    public boolean getBoolean(Object bean, String param, boolean defaultValue);
    
    /**
     * Get boolean property value from bean without throwing exceptions
     * @param bean the target bean  
     * @param param the property name
     * @return boolean value or false if property not found
     */
    public boolean getBooleanSilent(Object bean, String param);
    
    /**
     * Get boolean property value from bean without throwing exceptions with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return boolean value or default value if property not found
     */
    public boolean getBooleanSilent(Object bean, String param, boolean defaultValue);
    
    /**
     * Get integer property value from bean
     * @param bean the target bean
     * @param param the property name
     * @return integer value of property
     */
    public int getInteger(Object bean, String param);
    
    /**
     * Get integer property value from bean with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return integer value of property or default value
     */
    public int getInteger(Object bean, String param, int defaultValue);
    
    /**
     * Get integer property value from bean without throwing exceptions
     * @param bean the target bean
     * @param param the property name
     * @return integer value or 0 if property not found
     */
    public int getIntegerSilent(Object bean, String param);
    
    /**
     * Get integer property value from bean without throwing exceptions with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return integer value or default value if property not found
     */
    public int getIntegerSilent(Object bean, String param, int defaultValue);
    
    /**
     * Get long property value from bean
     * @param bean the target bean
     * @param param the property name
     * @return long value of property
     */
    public long getLong(Object bean, String param);
    
    /**
     * Get long property value from bean with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return long value of property or default value
     */
    public long getLong(Object bean, String param, long defaultValue);
    
    /**
     * Get long property value from bean without throwing exceptions
     * @param bean the target bean
     * @param param the property name
     * @return long value or 0 if property not found
     */
    public long getLongSilent(Object bean, String param);
    
    /**
     * Get long property value from bean without throwing exceptions with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return long value or default value if property not found
     */
    public long getLongSilent(Object bean, String param, long defaultValue);
    
    /**
     * Get byte property value from bean
     * @param bean the target bean
     * @param param the property name
     * @return byte value of property
     */
    public byte getByte(Object bean, String param);
    
    /**
     * Get byte property value from bean with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return byte value of property or default value
     */
    public byte getByte(Object bean, String param, byte defaultValue);
    
    /**
     * Get byte property value from bean without throwing exceptions
     * @param bean the target bean
     * @param param the property name
     * @return byte value or 0 if property not found
     */
    public byte getByteSilent(Object bean, String param);
    
    /**
     * Get byte property value from bean without throwing exceptions with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return byte value or default value if property not found
     */
    public byte getByteSilent(Object bean, String param, byte defaultValue);
    
    /**
     * Get double property value from bean
     * @param bean the target bean
     * @param param the property name
     * @return double value of property
     */
    public double getDouble(Object bean, String param);
    
    /**
     * Get double property value from bean with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return double value of property or default value
     */
    public double getDouble(Object bean, String param, double defaultValue);
    
    /**
     * Get double property value from bean without throwing exceptions
     * @param bean the target bean
     * @param param the property name
     * @return double value or 0.0 if property not found
     */
    public double getDoubleSilent(Object bean, String param);
    
    /**
     * Get double property value from bean without throwing exceptions with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return double value or default value if property not found
     */
    public double getDoubleSilent(Object bean, String param, double defaultValue);
    
    /**
     * Get float property value from bean
     * @param bean the target bean
     * @param param the property name
     * @return float value of property
     */
    public float getFloat(Object bean, String param);
    
    /**
     * Get float property value from bean with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return float value of property or default value
     */
    public float getFloat(Object bean, String param, float defaultValue);
    
    /**
     * Get float property value from bean without throwing exceptions
     * @param bean the target bean
     * @param param the property name
     * @return float value or 0.0f if property not found
     */
    public float getFloatSilent(Object bean, String param);
    
    /**
     * Get float property value from bean without throwing exceptions with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return float value or default value if property not found
     */
    public float getFloatSilent(Object bean, String param, float defaultValue);
    
    /**
     * Get short property value from bean
     * @param bean the target bean
     * @param param the property name
     * @return short value of property
     */
    public short getShort(Object bean, String param);
    
    /**
     * Get short property value from bean with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return short value of property or default value
     */
    public short getShort(Object bean, String param, short defaultValue);
    
    /**
     * Get short property value from bean without throwing exceptions
     * @param bean the target bean
     * @param param the property name
     * @return short value or 0 if property not found
     */
    public short getShortSilent(Object bean, String param);
    
    /**
     * Get short property value from bean without throwing exceptions with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return short value or default value if property not found
     */
    public short getShortSilent(Object bean, String param, short defaultValue);
    
    /**
     * Get Object property value from bean
     * @param bean the target bean
     * @param param the property name
     * @return Object value of property
     */
    public Object getObject(Object bean, String param);
    
    /**
     * Get Object property value from bean with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return Object value of property or default value
     */
    public Object getObject(Object bean, String param, Object defaultValue);
    
    /**
     * Get Object property value from bean without throwing exceptions
     * @param bean the target bean
     * @param param the property name
     * @return Object value or null if property not found
     */
    public Object getObjectSilent(Object bean, String param);
    
    /**
     * Get Object property value from bean without throwing exceptions with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return Object value or default value if property not found
     */
    public Object getObjectSilent(Object bean, String param, Object defaultValue);
    
    /**
     * Get property type from bean
     * @param bean the target bean
     * @param param the property name
     * @return Class type of the property
     */
    public Class<?> getObjectType(Object bean, String param);
    
    /**
     * Get property type from bean with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default class type if property not found
     * @return Class type of the property or default value
     */
    public Class<?> getObjectType(Object bean, String param, Class<?> defaultValue);
    
    /**
     * Get property type from bean without throwing exceptions
     * @param bean the target bean
     * @param param the property name
     * @return Class type of the property or null if property not found
     */
    public Class<?> getObjectTypeSilent(Object bean, String param);
    
    /**
     * Get property type from bean without throwing exceptions with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default class type if property not found
     * @return Class type of the property or default value if property not found
     */
    public Class<?> getObjectTypeSilent(Object bean, String param, Class<?> defaultValue);
    
    /**
     * Get string property value from bean
     * @param bean the target bean
     * @param param the property name
     * @return string value of property
     */
    public String getString(Object bean, String param);
    
    /**
     * Get string property value from bean with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return string value of property or default value
     */
    public String getString(Object bean, String param, String defaultValue);
    
    /**
     * Get string property value from bean without throwing exceptions
     * @param bean the target bean
     * @param param the property name
     * @return string value or null if property not found
     */
    public String getStringSilent(Object bean, String param);
    
    /**
     * Get string property value from bean without throwing exceptions with default value
     * @param bean the target bean
     * @param param the property name
     * @param defaultValue the default value if property not found
     * @return string value or default value if property not found
     */
    public String getStringSilent(Object bean, String param, String defaultValue);
    
    /**
     * Copy properties from source bean to target bean
     * @param source the source bean
     * @param target the target bean
     */
    public void copyProperties(Object source, Object target);
    
    /**
     * Create deep copy of bean using serialization
     * @param source the bean to copy
     * @return deep copy of the source bean
     * @throws Exception if serialization fails
     */
    public <T> T deepCopyProperties(Object source) throws Exception;
    
    /**
     * Set bean properties from HTTP request parameters
     * @param bean the target bean
     * @param request the HTTP servlet request
     */
    public void setProperties(Object bean, HttpServletRequest request);
    
    /**
     * Set bean properties from HTTP request parameters with ignored properties
     * @param bean the target bean
     * @param request the HTTP servlet request
     * @param ignoreProperties array of property names to ignore
     */
    public void setProperties(Object bean, HttpServletRequest request, String[] ignoreProperties);
    
    /**
     * Set a single property on the bean
     * @param bean the target bean
     * @param param the property name
     * @param value the value to set
     */
    public void setProperty(Object bean, String param, Object value);
    
    /**
     * Set a single property on the bean without throwing exceptions
     * @param bean the target bean
     * @param param the property name
     * @param value the value to set
     */
    public void setPropertySilent(Object bean, String param, Object value);
}

Usage Examples:

BeanPropertiesImpl beanProps = new BeanPropertiesImpl();

// Get properties of various types
boolean active = beanProps.getBoolean(user, "active");
int age = beanProps.getInteger(user, "age");
String name = beanProps.getString(user, "name");

// Silent property access (no exceptions)
boolean isActive = beanProps.getBooleanSilent(user, "active");
String email = beanProps.getStringSilent(user, "email");

// Copy properties between beans
User sourceUser = getUserFromDatabase();
User targetUser = new User();
beanProps.copyProperties(sourceUser, targetUser);

// Deep copy using serialization
User originalUser = getUserFromDatabase();
User clonedUser = (User) beanProps.deepCopyProperties(originalUser);

// Set properties from HTTP request
HttpServletRequest request = getRequest();
User user = new User();
beanProps.setProperties(user, request);

Velocity Bean Handler

Proxy handler enabling Velocity templates to access beans with proper ClassLoader context management.

/**
 * InvocationHandler implementation for Velocity template engine bean access
 */
public class VelocityBeanHandler implements InvocationHandler {
    
    /**
     * Constructor creating handler for specified bean
     * @param bean the target bean to proxy
     */
    public VelocityBeanHandler(Object bean);
    
    /**
     * Proxies method calls with proper ClassLoader context
     * @param proxy the proxy instance
     * @param method the method being invoked
     * @param arguments the method arguments
     * @return the method result
     * @throws Throwable if method invocation fails
     */
    public Object invoke(Object proxy, Method method, Object[] arguments) throws Throwable;
}

Usage Examples:

// Create proxy for Velocity template access
Object originalBean = getMyService();
VelocityBeanHandler handler = new VelocityBeanHandler(originalBean);

// Create proxy instance
Object proxy = Proxy.newProxyInstance(
    originalBean.getClass().getClassLoader(),
    originalBean.getClass().getInterfaces(),
    handler
);

// Use proxy in Velocity context
VelocityContext context = new VelocityContext();
context.put("myService", proxy);

Integration with Portal Framework

The bean management system integrates deeply with the Liferay portal framework:

  • ApplicationContext Integration - Works with Spring ApplicationContext for bean lifecycle management
  • Velocity Template Support - Special handling for Velocity template engine integration
  • Portal Service Integration - Enables dependency injection for portal services
  • HTTP Request Binding - Direct binding of HTTP parameters to bean properties
  • ClassLoader Management - Proper ClassLoader handling for OSGi environments

Error Handling

Common exceptions and error scenarios:

  • BeanLocatorException - Thrown when beans cannot be located by name or type
  • PropertyAccessException - Thrown when bean properties cannot be accessed or set
  • SerializationException - Thrown during deep copy operations if beans are not serializable
  • ClassCastException - Thrown when type casting fails during bean location

Best practices include using silent methods for optional properties and implementing proper exception handling for bean location operations.

Install with Tessl CLI

npx tessl i tessl/maven-com-liferay-portal--com-liferay-portal-impl

docs

bean-management.md

database-orm.md

database-upgrades.md

framework-integration.md

index.md

lifecycle-events.md

portlet-framework.md

service-layer.md

template-processing.md

utility-services.md

web-security.md

tile.json