Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright [2013] [www.rapidpm.org / Sven Ruppert (sven.ruppert@rapidpm.org)]
   *
   *    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.rapidpm.data.table;
 
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
Sven Ruppert - www.svenruppert.de

Author(s):
Sven Ruppert
Version:
0.1

This Source Code is part of the www.svenruppert.de project. please contact sven.ruppert@me.com
Since:
28.03.2010 Time: 21:32:53
 
 
 public class BaseCellFactory {
     private static final Logger logger = Logger.getLogger(BaseCellFactory.class);
 
     protected final Map<ClassTypedCellFactoryclass2CellMap = new HashMap<>();
 
     public BaseCellFactory() {
         .put(String.classnew StringCellFactory());
         .put(Integer.classnew IntegerCellFactory());
         .put(Float.classnew FloatCellFactory());
         .put(Double.classnew DoubleCellFactory());
         .put(Long.classnew LongCellFactory());
         .put(Boolean.classnew BooleanCellFactory());
         .put(Date.classnew DateCellFactory());
         .put(Timestamp.classnew DateCellFactory());
 
         .put(List.classnew ListCellFactory());
         .put(Collection.classnew ListCellFactory());//JIRA MOD-25 ListCellFactory ersetzen durch CollectionCellFactory
         .put(ArrayList.classnew ListCellFactory());
         .put(LinkedList.classnew ListCellFactory());
 
         .put(HashSet.classnew IterableCellFactory());
         .put(Set.classnew IterableCellFactory());
         .put(Collection.classnew IterableCellFactory());
 
 //        class2CellMap.put(PersistentBag.class, new ListCellFactory());
 //        class2CellMap.put(PersistentList.class, new ListCellFactory());
 //        class2CellMap.put(PersistentSet.class, new ListCellFactory());
 //        class2CellMap.put(PersistentMap.class, new ListCellFactory());
 
 //        class2CellMap.put(GenderEnum.class, new GenderEnumCellFactory());
 
         .put(SelectList.classnew SelectListFactory());
 
     }
 
     //    public <T> void registerNewCellForClass(T clazz){
     //        final Cell<T> tCell = new Cell<T>();
     //        final Class<? extends Cell> cellClass = tCell.getClass();
     //        class2CellMap.put(clazz.getClass(), tCell);
     //    }
 
 
     //JIRA MOD-26 Null values verarbeiten bei createNewCell(final C value, final String valueContext)
 
     public <C> Cell<C> createNewCell(final C valuefinal String valueContext) {
         final Cell<C> cell;
         final Class<? extends ObjectaClass = value.getClass();
         final TypedCellFactory cellFactory = .get(aClass);
         cell = cellFactory.newInstance();
         cell.setValue(value);
         cell.setValueContext(valueContext);
         return cell;
    }
    public <C> Cell<C> createNewCell(final C valuefinal String labelfinal String valueContext) {
        final Cell<C> cell;
        final Class<? extends ObjectaClass = value.getClass();
        final TypedCellFactory cellFactory = .get(aClass);
        cell = cellFactory.newInstance();
        cell.setValue(value);
        cell.setLabel(label);
        cell.setValueContext(valueContext);
        return cell;
    }
    //JIRA MOD-27 Null values verarbeiten bei createNewCell(final C value)
    public <C> Cell<C> createNewCell(final C value) {
        final Cell<C> cell;
        if (value == null) {
            cell = new Cell();
        } else {
            final Class<? extends ObjectaClass = value.getClass();
            final TypedCellFactory cellFactory = .get(aClass);
            if (cellFactory == null) {
                cell = new Cell();
                .warn("Typedef fehlt in CellFactory " + aClass.getName());
            } else {
                cell = cellFactory.newInstance();
                cell.setValue(value);
            }
        }
        return cell;
    }
    public Cell createNewEmptyCell(final Class cellValueClass) {
        Cell<Objectcell = null;
        final AbstractRegistry<FactoryForFactory<?>> registry = Registry.get(FactoryRegistry.class);
        if (registry.hasClassFor(cellValueClass)) {
            final Factory factoryFor = registry.getClassFor(cellValueClass);
            try {
                final Object object = factoryFor.createInstance();
                cell = createNewCell(object);
            } catch (InstantiationException e) {
                .error(e);
            }
        } else {
            try {
                final Object object = cellValueClass.newInstance();
                cell = createNewCell(object);
            } catch (InstantiationException | IllegalAccessException e) {
                .error(e);
            }
        }
        return cell;
    }
    protected interface TypedCellFactory<T> {
        public Cell<T> newInstance();
    }
    //JIRA MOD-28 laden und assoziieren per annotation
    private class IterableCellFactory implements TypedCellFactory<Iterable> {
        @Override
        public Cell<IterablenewInstance() {
            return new Cell<>();
        }
    }
    private class ListCellFactory implements TypedCellFactory<List> {
        @Override
        public Cell<ListnewInstance() {
            return new Cell<>();
        }
    }
    private class StringCellFactory implements TypedCellFactory<String> {
        @Override
        public Cell<StringnewInstance() {
            return new Cell<>();
        }
    }
    private class IntegerCellFactory implements TypedCellFactory<Integer> {
        @Override
        public Cell<IntegernewInstance() {
            return new Cell<>();
        }
    }
    private class FloatCellFactory implements TypedCellFactory<Float> {
        @Override
        public Cell<FloatnewInstance() {
            return new Cell<>();
        }
    }
    private class DoubleCellFactory implements TypedCellFactory<Double> {
        @Override
        public Cell<DoublenewInstance() {
            return new Cell<>();
        }
    }
    private class LongCellFactory implements TypedCellFactory<Long> {
        @Override
        public Cell<LongnewInstance() {
            return new Cell<>();
        }
    }
    private class BooleanCellFactory implements TypedCellFactory<Boolean> {
        @Override
        public Cell<BooleannewInstance() {
            return new Cell<>();
        }
    }
    private class DateCellFactory implements TypedCellFactory<Date> {
        @Override
        public Cell<DatenewInstance() {
            return new Cell<>();
        }
    }
    private class SelectListFactory implements TypedCellFactory<SelectList> {
        @Override
        public Cell<SelectListnewInstance() {
            return new Cell<>();
        }
    }
New to GrepCode? Check out our FAQ X