/**
* Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.component.factory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.joda.beans.Bean;
import org.joda.beans.BeanBuilder;
import org.joda.beans.BeanDefinition;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaProperty;
import org.joda.beans.Property;
import org.joda.beans.PropertyDefinition;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
import com.opengamma.component.ComponentInfo;
import com.opengamma.component.ComponentRepository;
/**
* Base component factory that supports a single main classifier output and multiple aliases.
*/
@BeanDefinition
public abstract class AbstractAliasedComponentFactory extends AbstractComponentFactory {
/**
* The classifier that the factory should publish under.
*/
@PropertyDefinition(validate = "notNull")
private String _classifier;
/**
* The alias classifiers that the factory should publish under.
* Aliases are alternate classifiers for the same object.
*/
@PropertyDefinition
private final List<String> _classifierAliases = new ArrayList<>();
/**
* Creates an instance.
*/
protected AbstractAliasedComponentFactory() {
}
//-------------------------------------------------------------------------
/**
* Registers the component and any aliases.
*
* @param repo the component repository, not null
* @param type the component type, not null
* @param component the component, not null
*/
protected void registerComponentAndAliases(ComponentRepository repo, Class<?> type, Object component) {
ComponentInfo info = new ComponentInfo(type, getClassifier());
repo.registerComponent(info, component);
for (String alias : getClassifierAliases()) {
ComponentInfo aliasInfo = new ComponentInfo(type, alias);
repo.registerComponent(aliasInfo, component);
}
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code AbstractAliasedComponentFactory}.
* @return the meta-bean, not null
*/
public static AbstractAliasedComponentFactory.Meta meta() {
return AbstractAliasedComponentFactory.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(AbstractAliasedComponentFactory.Meta.INSTANCE);
}
@Override
public AbstractAliasedComponentFactory.Meta metaBean() {
return AbstractAliasedComponentFactory.Meta.INSTANCE;
}
//-----------------------------------------------------------------------
/**
* Gets the classifier that the factory should publish under.
* @return the value of the property, not null
*/
public String getClassifier() {
return _classifier;
}
/**
* Sets the classifier that the factory should publish under.
* @param classifier the new value of the property, not null
*/
public void setClassifier(String classifier) {
JodaBeanUtils.notNull(classifier, "classifier");
this._classifier = classifier;
}
/**
* Gets the the {@code classifier} property.
* @return the property, not null
*/
public final Property<String> classifier() {
return metaBean().classifier().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the alias classifiers that the factory should publish under.
* Aliases are alternate classifiers for the same object.
* @return the value of the property, not null
*/
public List<String> getClassifierAliases() {
return _classifierAliases;
}
/**
* Sets the alias classifiers that the factory should publish under.
* Aliases are alternate classifiers for the same object.
* @param classifierAliases the new value of the property, not null
*/
public void setClassifierAliases(List<String> classifierAliases) {
JodaBeanUtils.notNull(classifierAliases, "classifierAliases");
this._classifierAliases.clear();
this._classifierAliases.addAll(classifierAliases);
}
/**
* Gets the the {@code classifierAliases} property.
* Aliases are alternate classifiers for the same object.
* @return the property, not null
*/
public final Property<List<String>> classifierAliases() {
return metaBean().classifierAliases().createProperty(this);
}
//-----------------------------------------------------------------------
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
AbstractAliasedComponentFactory other = (AbstractAliasedComponentFactory) obj;
return JodaBeanUtils.equal(getClassifier(), other.getClassifier()) &&
JodaBeanUtils.equal(getClassifierAliases(), other.getClassifierAliases()) &&
super.equals(obj);
}
return false;
}
@Override
public int hashCode() {
int hash = 7;
hash = hash * 31 + JodaBeanUtils.hashCode(getClassifier());
hash = hash * 31 + JodaBeanUtils.hashCode(getClassifierAliases());
return hash ^ super.hashCode();
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("AbstractAliasedComponentFactory{");
int len = buf.length();
toString(buf);
if (buf.length() > len) {
buf.setLength(buf.length() - 2);
}
buf.append('}');
return buf.toString();
}
@Override
protected void toString(StringBuilder buf) {
super.toString(buf);
buf.append("classifier").append('=').append(JodaBeanUtils.toString(getClassifier())).append(',').append(' ');
buf.append("classifierAliases").append('=').append(JodaBeanUtils.toString(getClassifierAliases())).append(',').append(' ');
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code AbstractAliasedComponentFactory}.
*/
public static class Meta extends AbstractComponentFactory.Meta {
/**
* The singleton instance of the meta-bean.
*/
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code classifier} property.
*/
private final MetaProperty<String> _classifier = DirectMetaProperty.ofReadWrite(
this, "classifier", AbstractAliasedComponentFactory.class, String.class);
/**
* The meta-property for the {@code classifierAliases} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<List<String>> _classifierAliases = DirectMetaProperty.ofReadWrite(
this, "classifierAliases", AbstractAliasedComponentFactory.class, (Class) List.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, (DirectMetaPropertyMap) super.metaPropertyMap(),
"classifier",
"classifierAliases");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return _classifier;
case -1645062755: // classifierAliases
return _classifierAliases;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends AbstractAliasedComponentFactory> builder() {
throw new UnsupportedOperationException("AbstractAliasedComponentFactory is an abstract class");
}
@Override
public Class<? extends AbstractAliasedComponentFactory> beanType() {
return AbstractAliasedComponentFactory.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code classifier} property.
* @return the meta-property, not null
*/
public final MetaProperty<String> classifier() {
return _classifier;
}
/**
* The meta-property for the {@code classifierAliases} property.
* @return the meta-property, not null
*/
public final MetaProperty<List<String>> classifierAliases() {
return _classifierAliases;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return ((AbstractAliasedComponentFactory) bean).getClassifier();
case -1645062755: // classifierAliases
return ((AbstractAliasedComponentFactory) bean).getClassifierAliases();
}
return super.propertyGet(bean, propertyName, quiet);
}
@SuppressWarnings("unchecked")
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
((AbstractAliasedComponentFactory) bean).setClassifier((String) newValue);
return;
case -1645062755: // classifierAliases
((AbstractAliasedComponentFactory) bean).setClassifierAliases((List<String>) newValue);
return;
}
super.propertySet(bean, propertyName, newValue, quiet);
}
@Override
protected void validate(Bean bean) {
JodaBeanUtils.notNull(((AbstractAliasedComponentFactory) bean)._classifier, "classifier");
JodaBeanUtils.notNull(((AbstractAliasedComponentFactory) bean)._classifierAliases, "classifierAliases");
super.validate(bean);
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}