/** * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.component; import java.util.HashMap; 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.DirectBean; import org.joda.beans.impl.direct.DirectBeanBuilder; import org.joda.beans.impl.direct.DirectMetaBean; import org.joda.beans.impl.direct.DirectMetaProperty; import org.joda.beans.impl.direct.DirectMetaPropertyMap; import com.opengamma.util.ArgumentChecker; /** * Stores information about a single component type. * <p> * Components are defined in terms of an interface type. */ @BeanDefinition public class ComponentTypeInfo extends DirectBean { /** * The type of the component, typically an interface. */ @PropertyDefinition(validate = "notNull") private Class<?> _type; /** * The component info. */ @PropertyDefinition(validate = "notNull") private final Map<String, ComponentInfo> _infoMap = new HashMap<String, ComponentInfo>(); /** * Creates an instance. */ protected ComponentTypeInfo() { } /** * Creates an instance. * * @param type the type of the component, typically an interface */ public ComponentTypeInfo(Class<?> type) { setType(type); } //------------------------------------------------------------------------- /** * Gets the component information by classifier. * * @param classifier the classifier that distinguishes the component, empty for default, not null * @return the component information, not null * @throws IllegalArgumentException if no component is available */ public ComponentInfo getInfo(String classifier) { ArgumentChecker.notNull(classifier, "classifier"); ComponentInfo info = _infoMap.get(classifier); if (info == null) { throw new IllegalArgumentException("No component available: " + _type + "::" + classifier); } return info; } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code ComponentTypeInfo}. * @return the meta-bean, not null */ public static ComponentTypeInfo.Meta meta() { return ComponentTypeInfo.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(ComponentTypeInfo.Meta.INSTANCE); } @Override public ComponentTypeInfo.Meta metaBean() { return ComponentTypeInfo.Meta.INSTANCE; } //----------------------------------------------------------------------- /** * Gets the type of the component, typically an interface. * @return the value of the property, not null */ public Class<?> getType() { return _type; } /** * Sets the type of the component, typically an interface. * @param type the new value of the property, not null */ public void setType(Class<?> type) { JodaBeanUtils.notNull(type, "type"); this._type = type; } /** * Gets the the {@code type} property. * @return the property, not null */ public final Property<Class<?>> type() { return metaBean().type().createProperty(this); } //----------------------------------------------------------------------- /** * Gets the component info. * @return the value of the property, not null */ public Map<String, ComponentInfo> getInfoMap() { return _infoMap; } /** * Sets the component info. * @param infoMap the new value of the property, not null */ public void setInfoMap(Map<String, ComponentInfo> infoMap) { JodaBeanUtils.notNull(infoMap, "infoMap"); this._infoMap.clear(); this._infoMap.putAll(infoMap); } /** * Gets the the {@code infoMap} property. * @return the property, not null */ public final Property<Map<String, ComponentInfo>> infoMap() { return metaBean().infoMap().createProperty(this); } //----------------------------------------------------------------------- @Override public ComponentTypeInfo clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { ComponentTypeInfo other = (ComponentTypeInfo) obj; return JodaBeanUtils.equal(getType(), other.getType()) && JodaBeanUtils.equal(getInfoMap(), other.getInfoMap()); } return false; } @Override public int hashCode() { int hash = getClass().hashCode(); hash = hash * 31 + JodaBeanUtils.hashCode(getType()); hash = hash * 31 + JodaBeanUtils.hashCode(getInfoMap()); return hash; } @Override public String toString() { StringBuilder buf = new StringBuilder(96); buf.append("ComponentTypeInfo{"); int len = buf.length(); toString(buf); if (buf.length() > len) { buf.setLength(buf.length() - 2); } buf.append('}'); return buf.toString(); } protected void toString(StringBuilder buf) { buf.append("type").append('=').append(JodaBeanUtils.toString(getType())).append(',').append(' '); buf.append("infoMap").append('=').append(JodaBeanUtils.toString(getInfoMap())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code ComponentTypeInfo}. */ public static class Meta extends DirectMetaBean { /** * The singleton instance of the meta-bean. */ static final Meta INSTANCE = new Meta(); /** * The meta-property for the {@code type} property. */ @SuppressWarnings({"unchecked", "rawtypes" }) private final MetaProperty<Class<?>> _type = DirectMetaProperty.ofReadWrite( this, "type", ComponentTypeInfo.class, (Class) Class.class); /** * The meta-property for the {@code infoMap} property. */ @SuppressWarnings({"unchecked", "rawtypes" }) private final MetaProperty<Map<String, ComponentInfo>> _infoMap = DirectMetaProperty.ofReadWrite( this, "infoMap", ComponentTypeInfo.class, (Class) Map.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, null, "type", "infoMap"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case 3575610: // type return _type; case 1945395662: // infoMap return _infoMap; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder<? extends ComponentTypeInfo> builder() { return new DirectBeanBuilder<ComponentTypeInfo>(new ComponentTypeInfo()); } @Override public Class<? extends ComponentTypeInfo> beanType() { return ComponentTypeInfo.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code type} property. * @return the meta-property, not null */ public final MetaProperty<Class<?>> type() { return _type; } /** * The meta-property for the {@code infoMap} property. * @return the meta-property, not null */ public final MetaProperty<Map<String, ComponentInfo>> infoMap() { return _infoMap; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 3575610: // type return ((ComponentTypeInfo) bean).getType(); case 1945395662: // infoMap return ((ComponentTypeInfo) bean).getInfoMap(); } return super.propertyGet(bean, propertyName, quiet); } @SuppressWarnings("unchecked") @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case 3575610: // type ((ComponentTypeInfo) bean).setType((Class<?>) newValue); return; case 1945395662: // infoMap ((ComponentTypeInfo) bean).setInfoMap((Map<String, ComponentInfo>) newValue); return; } super.propertySet(bean, propertyName, newValue, quiet); } @Override protected void validate(Bean bean) { JodaBeanUtils.notNull(((ComponentTypeInfo) bean)._type, "type"); JodaBeanUtils.notNull(((ComponentTypeInfo) bean)._infoMap, "infoMap"); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }