![JAR search and dependency download from the Maven repository](/logo.png)
it.tidalwave.metadata.spi.MetadataItemEnhancer Maven / Gradle / Ivy
The newest version!
/***********************************************************************************************************************
*
* blueMarine Metadata - open source media workflow
* Copyright (C) 2007-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
*
***********************************************************************************************************************
*
* Licensed 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.
*
***********************************************************************************************************************
*
* WWW: http://bluemarine.tidalwave.it
* SCM: https://kenai.com/hg/bluemarine~metadata-src
*
**********************************************************************************************************************/
package it.tidalwave.metadata.spi;
import net.sf.cglib.proxy.Callback;
import it.tidalwave.beans.AbstractEnhancer;
import it.tidalwave.beans.JavaBean;
import it.tidalwave.metadata.spi.impl.MetadataItemAspect;
import java.beans.PropertyChangeListener;
import javax.annotation.Nonnull;
/*******************************************************************************
*
* This factory provides enhanced metadata items that support the JavaBean
* specification and implement the {@link MetadataItem} interface. The requisites
* for the source classes are:
*
*
* - to provide properties by means of getter/setters;
* - to provide an "*Available" property for each property (e.g.
*
isFooAvailable()
for getFoo()
);
*
*
*
* public class ExampleMetadataItem
* {
* private String name;
* private boolean nameAvailable;
*
* public void setName (final String name)
* {
* this.name = name;
* }
*
* public String getName()
* {
* return name;
* }
*
* public void setNameAvailable (final boolean nameAvailable)
* {
* this.nameAvailable = nameAvailable;
* }
*
* public boolean isNameAvailable()
* {
* return nameAvailable;
* }
* }
*
*
* Now, calling:
*
*
* ExampleMetadataItem item = MetadataItemEnhancer.createEnhancedItem(new ExampleMetadataItem()));
*
*
* an enhanced item is returned. To use the enhanced features such as the
* support for {@link PropertyChangeListener}s, you have to use the reflection API
* or to explicitly cast as in the example below:
*
*
* ((JavaBean)item).addPropertyChangeListener(...);
*
*
* In addition to the JavaBean specifications, the enhanced items also supports
* these semantics:
*
*
* - setting a property to a non-
null
value will force the related
* ***Available()
property to true
;
* - setting an
***Available()
property to false
will
* force the related property to null
.
*
*
* @hidden
*
* @author Fabrizio Giudici
* @version $Id$
*
******************************************************************************/
public class MetadataItemEnhancer extends AbstractEnhancer
{
private final static MetadataItemEnhancer instance = new MetadataItemEnhancer();
/***************************************************************************
*
*
**************************************************************************/
private MetadataItemEnhancer()
{
super(JavaBean.class);
}
/***************************************************************************
*
* Creates an enhanced item.
*
* @param bean the original item
* @return the enhanced item
*
**************************************************************************/
@Nonnull
public static T createEnhancedItem (@Nonnull final T bean, @Nonnull final Object ... arguments)
{
return (T)instance.createEnhancedBean(bean, arguments);
}
/***************************************************************************
*
* {@inheritDoc} This method specifies {@link MetadataItemAspect} as the
* aspect implementation to give to enhanced beans.
*
**************************************************************************/
@Override
@Nonnull
protected Callback createInterceptor (@Nonnull final Object bean, @Nonnull final Object ... arguments)
{
return new MetadataItemAspect(bean, this, arguments);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy