/*******************************************************************************
 * Copyright Searchbox - http://www.searchbox.com
 * 
 * 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.
 ******************************************************************************/
package com.searchbox.framework.model;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.searchbox.core.SearchElementBean;
import com.searchbox.core.ref.ReflectionUtils;

@Entity
public class SearchElementEntity<K extends SearchElementBean> extends
    BeanFactoryEntity<Long> implements ParametrizedBeanFactory<K>,
    Comparable<SearchElementEntity<K>> {
  
  private static final Logger LOGGER = LoggerFactory
      .getLogger(SearchElementEntity.class);

  @ManyToOne(targetEntity = PresetEntity.class)
  private PresetEntity preset;

  private Class<?> clazz;

  private String label;

  private Integer position;

  private String process;

  public SearchElementEntity() {
    // TODO infer class from generic Interface
  }
  
  public PresetEntity getPreset() {
    return preset;
  }

  public SearchElementEntity<?> setPreset(PresetEntity preset) {
    this.preset = preset;
    return this;
  }

  public PresetEntity end(){
    this.getPreset().getSearchElements().add(this);
    return this.getPreset();
  }
  
  @Override
  @SuppressWarnings("unchecked")
  public K build(){
    if(this.getClazz() == null){
      throw new MissingClassAttributeException();
    }
    LOGGER.debug("Building Class for {}",this.getClazz());
    return (K) super.build(this.getClazz());
  }

  public String getProcess() {
    return process;
  }

  public SearchElementEntity<?> setProcess(String process) {
    this.process = process;
    return this;
  }

  public Class<?> getClazz() {
    return clazz;
  }

  public SearchElementEntity<?> setClazz(Class<?> clazz) {
    this.clazz = clazz;
    ReflectionUtils.inspectAndSaveAttribute(clazz, this.getAttributes());
    return this;
  }

  public String getLabel() {
    return label;
  }

  public SearchElementEntity<K> setLabel(String label) {
    this.label = label;
    return this;
  }

  public Integer getPosition() {
    return position;
  }

  public SearchElementEntity<K> setPosition(Integer position) {
    this.position = position;
    return this;
  }

  @Override
  public int compareTo(SearchElementEntity<K> o) {
    return this.getPosition().compareTo(o.getPosition());
  }

  @Override
  public String toString() {
    return ReflectionToStringBuilder.toString(this,
        ToStringStyle.SHORT_PREFIX_STYLE);
  }

  public SearchElementEntity<K> setAttribute(String name, Object value) {
    //TODO throw exception if attribute is NOT a @SearchAttribute
    this.getAttributeByName(name).setValue(value).setType(value.getClass());
    return this;
  }
}

@@ -3342,103 +3342,357 @@
     
-//TODO throw exception if attribute is NOT a @SearchAttribute%0A    this.getAttributeByName(name)
+LOGGER.debug(%22Seeting attr %7B%7D%5B%7B%7D%5D to value %7B%7D%22,name,%0A        (value!=null)?value.getClass():%22xoxo%22, value);%0A    AttributeEntity attribute = this.getAttributeByName(name);%0A    if(attribute == null)%7B%0A      LOGGER.warn(%22CAUTION! Setting an attribute (%7B%7D) that is not defined in %7B%7D%22,%0A          name, this.getClazz());%0A    %7D else %7B%0A      attribute%0A      
 .set
@@ -3703,16 +3703,23 @@
 e(value)
+%0A      
 .setType
@@ -3734,24 +3734,30 @@
 etClass());%0A
+    %7D%0A
     return t

Check if attribute is a @SearchAttribute. If not WARN