Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2011 the original author or authors. 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 org.springframework.data.neo4j.fieldaccess;
 
 
 import java.util.List;
 import java.util.Map;

Author(s):
Michael Hunger
Since:
12.09.2010
 
 public abstract class DefaultEntityState<STATE> implements EntityState<STATE> {
     protected final Object entity;
     protected final Class<?> type;
     private STATE state;
     protected final static Logger log= LoggerFactory.getLogger(DefaultEntityState.class);
     protected final Neo4jPersistentEntity<?> persistentEntity;
 
     public DefaultEntityState(final STATE underlyingStatefinal Object entityfinal Class<?> typefinal DelegatingFieldAccessorFactory delegatingFieldAccessorFactoryNeo4jPersistentEntity<?> persistentEntity) {
         this. = underlyingState;
         this. = entity;
         this. = type;
         this. = persistentEntity;
         if (delegatingFieldAccessorFactory!=null) {
              = delegatingFieldAccessorFactory.accessorFactoriesFor(persistentEntity);
         } else {
              = null// todo
         }
     }
 
     @Override
     public abstract void createAndAssignState();
 
     @Override
     public Object getEntity() {
         return ;
     }
 
     @Override
     public void setPersistentState(final STATE state) {
         this. = state;
     }
 
     @Override
     public boolean hasPersistentState() {
         return this.!=null;
     }
 
     @Override
     public STATE getPersistentState() {
         return ;
     }
 
     public Neo4jPersistentEntity<?> getPersistentEntity() {
         return ;
     }
 
     @Override
     public boolean isWritable(Neo4jPersistentProperty property) {
         final FieldAccessor accessor = accessorFor(property);
         if (accessor == nullreturn true;
         return accessor.isWriteable();
     }
 
     @Override
     public Object getValue(final Neo4jPersistentProperty propertyMappingPolicy mappingPolicy) {
         final FieldAccessor accessor = accessorFor(property);
         if (accessor == nullreturn null;
         else return accessor.getValue(mappingPolicy);
     }
 
    @Override
    public Object getValue(final Field fieldMappingPolicy mappingPolicy) {
        return getValue(property(field), mappingPolicy);
    }
    @Override
    public Object setValue(final Field fieldfinal Object newValMappingPolicy mappingPolicy) {
        return setValue(property(field),newValmappingPolicy);
    }
    @Override
    public Object setValue(final Neo4jPersistentProperty propertyfinal Object newValMappingPolicy mappingPolicy) {
        final FieldAccessor accessor = accessorFor(property);
        final Object result=accessor!=null ? accessor.setValue(newValmappingPolicy) : newVal;
        notifyListeners(propertyresult);
        return result;
    }
        final FieldAccessor accessor = accessorFor(property);
        if (accessor == nullreturn null;
        else return accessor.getDefaultValue();
	}
    protected Neo4jPersistentProperty property(Field field) {
        return .getPersistentProperty(field.getName());
    }
    protected FieldAccessor accessorFor(final Neo4jPersistentProperty property) {
        return .get(property);
    }
    private void notifyListeners(final Neo4jPersistentProperty fieldfinal Object result) {
        if (!.containsKey(field) || .get(field) == nullreturn;
        for (final FieldAccessListener listener : .get(field)) {
            listener.valueChanged(nullresult); // todo oldValue
        }
    }
    protected Object getIdFromEntity() {
        if (idProperty==nullreturn null;
        return idProperty.getValue(idProperty.getMappingPolicy());
    }
New to GrepCode? Check out our FAQ X