/** * Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.sesame.component; import java.util.LinkedHashMap; 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.DirectBeanBuilder; import org.joda.beans.impl.direct.DirectMetaProperty; import org.joda.beans.impl.direct.DirectMetaPropertyMap; import com.opengamma.component.ComponentRepository; import com.opengamma.component.factory.AbstractComponentFactory; import com.opengamma.sesame.engine.Engine; import com.opengamma.sesame.engine.ViewRunner; import com.opengamma.sesame.server.DataFunctionServerResource; import com.opengamma.sesame.server.DefaultFunctionServer; import com.opengamma.sesame.server.FunctionServer; /** * Component factory for the function server. * * @deprecated use {@link ViewRunner} and {@link ViewRunnerComponentFactory} */ @BeanDefinition public class FunctionServerComponentFactory extends AbstractComponentFactory { /** * The classifier that the factory should publish under. */ @PropertyDefinition(validate = "notNull") private String _classifier; /** * Should the component be published over a REST interface. Set to false * if there is no desire to connect to the component remotely. */ @PropertyDefinition(validate = "notNull") private boolean _publishRest = true; /** * Engine to which the function server delegates requests. */ @PropertyDefinition(validate = "notNull") private Engine _engine; //------------------------------------------------------------------------- @Override public void init(ComponentRepository repo, LinkedHashMap<String, String> configuration) throws Exception { initFunctionServer(repo, _engine); } private DefaultFunctionServer initFunctionServer(ComponentRepository repo, Engine engine) { DefaultFunctionServer server = new DefaultFunctionServer(engine); repo.registerComponent(FunctionServer.class, getClassifier(), server); if (isPublishRest()) { repo.getRestComponents().publishResource(new DataFunctionServerResource(server)); } return server; } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code FunctionServerComponentFactory}. * @return the meta-bean, not null */ public static FunctionServerComponentFactory.Meta meta() { return FunctionServerComponentFactory.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(FunctionServerComponentFactory.Meta.INSTANCE); } @Override public FunctionServerComponentFactory.Meta metaBean() { return FunctionServerComponentFactory.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 should the component be published over a REST interface. Set to false * if there is no desire to connect to the component remotely. * @return the value of the property, not null */ public boolean isPublishRest() { return _publishRest; } /** * Sets should the component be published over a REST interface. Set to false * if there is no desire to connect to the component remotely. * @param publishRest the new value of the property, not null */ public void setPublishRest(boolean publishRest) { JodaBeanUtils.notNull(publishRest, "publishRest"); this._publishRest = publishRest; } /** * Gets the the {@code publishRest} property. * if there is no desire to connect to the component remotely. * @return the property, not null */ public final Property<Boolean> publishRest() { return metaBean().publishRest().createProperty(this); } //----------------------------------------------------------------------- /** * Gets engine to which the function server delegates requests. * @return the value of the property, not null */ public Engine getEngine() { return _engine; } /** * Sets engine to which the function server delegates requests. * @param engine the new value of the property, not null */ public void setEngine(Engine engine) { JodaBeanUtils.notNull(engine, "engine"); this._engine = engine; } /** * Gets the the {@code engine} property. * @return the property, not null */ public final Property<Engine> engine() { return metaBean().engine().createProperty(this); } //----------------------------------------------------------------------- @Override public FunctionServerComponentFactory clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { FunctionServerComponentFactory other = (FunctionServerComponentFactory) obj; return JodaBeanUtils.equal(getClassifier(), other.getClassifier()) && (isPublishRest() == other.isPublishRest()) && JodaBeanUtils.equal(getEngine(), other.getEngine()) && super.equals(obj); } return false; } @Override public int hashCode() { int hash = 7; hash = hash * 31 + JodaBeanUtils.hashCode(getClassifier()); hash = hash * 31 + JodaBeanUtils.hashCode(isPublishRest()); hash = hash * 31 + JodaBeanUtils.hashCode(getEngine()); return hash ^ super.hashCode(); } @Override public String toString() { StringBuilder buf = new StringBuilder(128); buf.append("FunctionServerComponentFactory{"); 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("publishRest").append('=').append(JodaBeanUtils.toString(isPublishRest())).append(',').append(' '); buf.append("engine").append('=').append(JodaBeanUtils.toString(getEngine())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code FunctionServerComponentFactory}. */ 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", FunctionServerComponentFactory.class, String.class); /** * The meta-property for the {@code publishRest} property. */ private final MetaProperty<Boolean> _publishRest = DirectMetaProperty.ofReadWrite( this, "publishRest", FunctionServerComponentFactory.class, Boolean.TYPE); /** * The meta-property for the {@code engine} property. */ private final MetaProperty<Engine> _engine = DirectMetaProperty.ofReadWrite( this, "engine", FunctionServerComponentFactory.class, Engine.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, (DirectMetaPropertyMap) super.metaPropertyMap(), "classifier", "publishRest", "engine"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case -281470431: // classifier return _classifier; case -614707837: // publishRest return _publishRest; case -1298662846: // engine return _engine; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder<? extends FunctionServerComponentFactory> builder() { return new DirectBeanBuilder<FunctionServerComponentFactory>(new FunctionServerComponentFactory()); } @Override public Class<? extends FunctionServerComponentFactory> beanType() { return FunctionServerComponentFactory.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 publishRest} property. * @return the meta-property, not null */ public final MetaProperty<Boolean> publishRest() { return _publishRest; } /** * The meta-property for the {@code engine} property. * @return the meta-property, not null */ public final MetaProperty<Engine> engine() { return _engine; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -281470431: // classifier return ((FunctionServerComponentFactory) bean).getClassifier(); case -614707837: // publishRest return ((FunctionServerComponentFactory) bean).isPublishRest(); case -1298662846: // engine return ((FunctionServerComponentFactory) bean).getEngine(); } return super.propertyGet(bean, propertyName, quiet); } @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case -281470431: // classifier ((FunctionServerComponentFactory) bean).setClassifier((String) newValue); return; case -614707837: // publishRest ((FunctionServerComponentFactory) bean).setPublishRest((Boolean) newValue); return; case -1298662846: // engine ((FunctionServerComponentFactory) bean).setEngine((Engine) newValue); return; } super.propertySet(bean, propertyName, newValue, quiet); } @Override protected void validate(Bean bean) { JodaBeanUtils.notNull(((FunctionServerComponentFactory) bean)._classifier, "classifier"); JodaBeanUtils.notNull(((FunctionServerComponentFactory) bean)._publishRest, "publishRest"); JodaBeanUtils.notNull(((FunctionServerComponentFactory) bean)._engine, "engine"); super.validate(bean); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }