/** * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.web.convention; import java.util.Map; import javax.ws.rs.core.UriInfo; 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.DirectBeanBuilder; import org.joda.beans.impl.direct.DirectMetaProperty; import org.joda.beans.impl.direct.DirectMetaPropertyMap; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.opengamma.id.UniqueId; import com.opengamma.master.convention.ConventionDocument; import com.opengamma.master.convention.ConventionMaster; import com.opengamma.master.convention.ManageableConvention; import com.opengamma.web.WebPerRequestData; /** * Data class for web-based convention management. */ @BeanDefinition public class WebConventionData extends WebPerRequestData { /** * The convention master. */ @PropertyDefinition private ConventionMaster _conventionMaster; /** * The type of data being stored. */ @PropertyDefinition private Class<?> _type; /** * The convention id from the input URI. */ @PropertyDefinition private String _uriConventionId; /** * The version id from the URI. */ @PropertyDefinition private String _uriVersionId; /** * The convention. */ @PropertyDefinition private ConventionDocument _convention; /** * The versioned convention. */ @PropertyDefinition private ConventionDocument _versioned; /** * The valid map of types. */ @PropertyDefinition(set = "setClearPutAll") private final BiMap<String, Class<? extends ManageableConvention>> _typeMap = HashBiMap.create(); /** * Creates an instance. */ public WebConventionData() { } /** * Creates an instance. * @param uriInfo the URI information */ public WebConventionData(final UriInfo uriInfo) { setUriInfo(uriInfo); } //------------------------------------------------------------------------- /** * Gets the best available convention id. * @param overrideId the override id, null derives the result from the data * @return the id, may be null */ public String getBestConventionUriId(final UniqueId overrideId) { if (overrideId != null) { return overrideId.toLatest().toString(); } return getConvention() != null ? getConvention().getUniqueId().toLatest().toString() : getUriConventionId(); } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code WebConventionData}. * @return the meta-bean, not null */ public static WebConventionData.Meta meta() { return WebConventionData.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(WebConventionData.Meta.INSTANCE); } @Override public WebConventionData.Meta metaBean() { return WebConventionData.Meta.INSTANCE; } //----------------------------------------------------------------------- /** * Gets the convention master. * @return the value of the property */ public ConventionMaster getConventionMaster() { return _conventionMaster; } /** * Sets the convention master. * @param conventionMaster the new value of the property */ public void setConventionMaster(ConventionMaster conventionMaster) { this._conventionMaster = conventionMaster; } /** * Gets the the {@code conventionMaster} property. * @return the property, not null */ public final Property<ConventionMaster> conventionMaster() { return metaBean().conventionMaster().createProperty(this); } //----------------------------------------------------------------------- /** * Gets the type of data being stored. * @return the value of the property */ public Class<?> getType() { return _type; } /** * Sets the type of data being stored. * @param type the new value of the property */ public void setType(Class<?> 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 convention id from the input URI. * @return the value of the property */ public String getUriConventionId() { return _uriConventionId; } /** * Sets the convention id from the input URI. * @param uriConventionId the new value of the property */ public void setUriConventionId(String uriConventionId) { this._uriConventionId = uriConventionId; } /** * Gets the the {@code uriConventionId} property. * @return the property, not null */ public final Property<String> uriConventionId() { return metaBean().uriConventionId().createProperty(this); } //----------------------------------------------------------------------- /** * Gets the version id from the URI. * @return the value of the property */ public String getUriVersionId() { return _uriVersionId; } /** * Sets the version id from the URI. * @param uriVersionId the new value of the property */ public void setUriVersionId(String uriVersionId) { this._uriVersionId = uriVersionId; } /** * Gets the the {@code uriVersionId} property. * @return the property, not null */ public final Property<String> uriVersionId() { return metaBean().uriVersionId().createProperty(this); } //----------------------------------------------------------------------- /** * Gets the convention. * @return the value of the property */ public ConventionDocument getConvention() { return _convention; } /** * Sets the convention. * @param convention the new value of the property */ public void setConvention(ConventionDocument convention) { this._convention = convention; } /** * Gets the the {@code convention} property. * @return the property, not null */ public final Property<ConventionDocument> convention() { return metaBean().convention().createProperty(this); } //----------------------------------------------------------------------- /** * Gets the versioned convention. * @return the value of the property */ public ConventionDocument getVersioned() { return _versioned; } /** * Sets the versioned convention. * @param versioned the new value of the property */ public void setVersioned(ConventionDocument versioned) { this._versioned = versioned; } /** * Gets the the {@code versioned} property. * @return the property, not null */ public final Property<ConventionDocument> versioned() { return metaBean().versioned().createProperty(this); } //----------------------------------------------------------------------- /** * Gets the valid map of types. * @return the value of the property, not null */ public BiMap<String, Class<? extends ManageableConvention>> getTypeMap() { return _typeMap; } /** * Sets the valid map of types. * @param typeMap the new value of the property, not null */ public void setTypeMap(BiMap<String, Class<? extends ManageableConvention>> typeMap) { JodaBeanUtils.notNull(typeMap, "typeMap"); this._typeMap.clear(); this._typeMap.putAll(typeMap); } /** * Gets the the {@code typeMap} property. * @return the property, not null */ public final Property<BiMap<String, Class<? extends ManageableConvention>>> typeMap() { return metaBean().typeMap().createProperty(this); } //----------------------------------------------------------------------- @Override public WebConventionData clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { WebConventionData other = (WebConventionData) obj; return JodaBeanUtils.equal(getConventionMaster(), other.getConventionMaster()) && JodaBeanUtils.equal(getType(), other.getType()) && JodaBeanUtils.equal(getUriConventionId(), other.getUriConventionId()) && JodaBeanUtils.equal(getUriVersionId(), other.getUriVersionId()) && JodaBeanUtils.equal(getConvention(), other.getConvention()) && JodaBeanUtils.equal(getVersioned(), other.getVersioned()) && JodaBeanUtils.equal(getTypeMap(), other.getTypeMap()) && super.equals(obj); } return false; } @Override public int hashCode() { int hash = 7; hash = hash * 31 + JodaBeanUtils.hashCode(getConventionMaster()); hash = hash * 31 + JodaBeanUtils.hashCode(getType()); hash = hash * 31 + JodaBeanUtils.hashCode(getUriConventionId()); hash = hash * 31 + JodaBeanUtils.hashCode(getUriVersionId()); hash = hash * 31 + JodaBeanUtils.hashCode(getConvention()); hash = hash * 31 + JodaBeanUtils.hashCode(getVersioned()); hash = hash * 31 + JodaBeanUtils.hashCode(getTypeMap()); return hash ^ super.hashCode(); } @Override public String toString() { StringBuilder buf = new StringBuilder(256); buf.append("WebConventionData{"); 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("conventionMaster").append('=').append(JodaBeanUtils.toString(getConventionMaster())).append(',').append(' '); buf.append("type").append('=').append(JodaBeanUtils.toString(getType())).append(',').append(' '); buf.append("uriConventionId").append('=').append(JodaBeanUtils.toString(getUriConventionId())).append(',').append(' '); buf.append("uriVersionId").append('=').append(JodaBeanUtils.toString(getUriVersionId())).append(',').append(' '); buf.append("convention").append('=').append(JodaBeanUtils.toString(getConvention())).append(',').append(' '); buf.append("versioned").append('=').append(JodaBeanUtils.toString(getVersioned())).append(',').append(' '); buf.append("typeMap").append('=').append(JodaBeanUtils.toString(getTypeMap())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code WebConventionData}. */ public static class Meta extends WebPerRequestData.Meta { /** * The singleton instance of the meta-bean. */ static final Meta INSTANCE = new Meta(); /** * The meta-property for the {@code conventionMaster} property. */ private final MetaProperty<ConventionMaster> _conventionMaster = DirectMetaProperty.ofReadWrite( this, "conventionMaster", WebConventionData.class, ConventionMaster.class); /** * The meta-property for the {@code type} property. */ @SuppressWarnings({"unchecked", "rawtypes" }) private final MetaProperty<Class<?>> _type = DirectMetaProperty.ofReadWrite( this, "type", WebConventionData.class, (Class) Class.class); /** * The meta-property for the {@code uriConventionId} property. */ private final MetaProperty<String> _uriConventionId = DirectMetaProperty.ofReadWrite( this, "uriConventionId", WebConventionData.class, String.class); /** * The meta-property for the {@code uriVersionId} property. */ private final MetaProperty<String> _uriVersionId = DirectMetaProperty.ofReadWrite( this, "uriVersionId", WebConventionData.class, String.class); /** * The meta-property for the {@code convention} property. */ private final MetaProperty<ConventionDocument> _convention = DirectMetaProperty.ofReadWrite( this, "convention", WebConventionData.class, ConventionDocument.class); /** * The meta-property for the {@code versioned} property. */ private final MetaProperty<ConventionDocument> _versioned = DirectMetaProperty.ofReadWrite( this, "versioned", WebConventionData.class, ConventionDocument.class); /** * The meta-property for the {@code typeMap} property. */ @SuppressWarnings({"unchecked", "rawtypes" }) private final MetaProperty<BiMap<String, Class<? extends ManageableConvention>>> _typeMap = DirectMetaProperty.ofReadWrite( this, "typeMap", WebConventionData.class, (Class) BiMap.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, (DirectMetaPropertyMap) super.metaPropertyMap(), "conventionMaster", "type", "uriConventionId", "uriVersionId", "convention", "versioned", "typeMap"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case 41113907: // conventionMaster return _conventionMaster; case 3575610: // type return _type; case -566451208: // uriConventionId return _uriConventionId; case 666567687: // uriVersionId return _uriVersionId; case 2039569265: // convention return _convention; case -1407102089: // versioned return _versioned; case -853107774: // typeMap return _typeMap; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder<? extends WebConventionData> builder() { return new DirectBeanBuilder<WebConventionData>(new WebConventionData()); } @Override public Class<? extends WebConventionData> beanType() { return WebConventionData.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code conventionMaster} property. * @return the meta-property, not null */ public final MetaProperty<ConventionMaster> conventionMaster() { return _conventionMaster; } /** * 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 uriConventionId} property. * @return the meta-property, not null */ public final MetaProperty<String> uriConventionId() { return _uriConventionId; } /** * The meta-property for the {@code uriVersionId} property. * @return the meta-property, not null */ public final MetaProperty<String> uriVersionId() { return _uriVersionId; } /** * The meta-property for the {@code convention} property. * @return the meta-property, not null */ public final MetaProperty<ConventionDocument> convention() { return _convention; } /** * The meta-property for the {@code versioned} property. * @return the meta-property, not null */ public final MetaProperty<ConventionDocument> versioned() { return _versioned; } /** * The meta-property for the {@code typeMap} property. * @return the meta-property, not null */ public final MetaProperty<BiMap<String, Class<? extends ManageableConvention>>> typeMap() { return _typeMap; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 41113907: // conventionMaster return ((WebConventionData) bean).getConventionMaster(); case 3575610: // type return ((WebConventionData) bean).getType(); case -566451208: // uriConventionId return ((WebConventionData) bean).getUriConventionId(); case 666567687: // uriVersionId return ((WebConventionData) bean).getUriVersionId(); case 2039569265: // convention return ((WebConventionData) bean).getConvention(); case -1407102089: // versioned return ((WebConventionData) bean).getVersioned(); case -853107774: // typeMap return ((WebConventionData) bean).getTypeMap(); } return super.propertyGet(bean, propertyName, quiet); } @SuppressWarnings("unchecked") @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case 41113907: // conventionMaster ((WebConventionData) bean).setConventionMaster((ConventionMaster) newValue); return; case 3575610: // type ((WebConventionData) bean).setType((Class<?>) newValue); return; case -566451208: // uriConventionId ((WebConventionData) bean).setUriConventionId((String) newValue); return; case 666567687: // uriVersionId ((WebConventionData) bean).setUriVersionId((String) newValue); return; case 2039569265: // convention ((WebConventionData) bean).setConvention((ConventionDocument) newValue); return; case -1407102089: // versioned ((WebConventionData) bean).setVersioned((ConventionDocument) newValue); return; case -853107774: // typeMap ((WebConventionData) bean).setTypeMap((BiMap<String, Class<? extends ManageableConvention>>) newValue); return; } super.propertySet(bean, propertyName, newValue, quiet); } @Override protected void validate(Bean bean) { JodaBeanUtils.notNull(((WebConventionData) bean)._typeMap, "typeMap"); super.validate(bean); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }