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.converter.totable;
 
 import java.util.List;
 
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:
22.06.2010 Time: 23:21:55

Dieser Converter kann NICHT einfacheDatentypen wie int und char verarbeiten. Des weiteren werden einfache Lsiten von z.B. Date dazu führen, das der Date in seine Einzelteile zerpflückt wird.

Also nur komplexe Klassen..
 
 
 public abstract class GenericList2TableConverter extends Abstract2TableConverter<Object> {
     private static final Logger logger = Logger.getLogger(GenericList2TableConverter.class);
     public static final String ZUWEISEN = "zuweisen";
     public static final String EDITIEREN = "editieren";
 
     private static final String postExtensionZuweisung = "Zuweisung";
     private static final String postExtensionEdit = "Edit";
 
 
     private String webAppCtx = "";
 
     public GenericList2TableConverter() {
     }
 
     public GenericList2TableConverter(final String webAppCtx) {
         this. = webAppCtx;
     }
 
     @Override
     protected void setTableName(final Table table) {
         table.setTableName("generic transformed table");
     }
 
 
     @Override
     protected <C extends ConfigElementsvoid convertImpl(final TableCreator tableCreatorfinal Object entityfinal C config) {
         convert2Table(tableCreatorentity);
     }
 
 
     private void convert2Table(final TableCreator tableCreatorfinal Object... valueList) {
 
         final int length = valueList.length;
         if ((length > 0)) {
             final List<ObjectobjList = new ArrayList<>();
             final Object o1 = valueList[0];  // hier ist schon der Inhalt
             if (!(o1 instanceof Iterable)) {
                 //atomarer Wert
                 final boolean isArray = o1.getClass().isArray();
                 if (isArray) {
                     //                    final Class<?> type = o1.getClass().getComponentType();
                     final int arrayLength = Array.getLength(o1);
                     for (int i = 0; i < arrayLengthi++) {
                         final Object arrayElement = Array.get(o1i);
                         objList.add(arrayElement);
                     }
 
                 } else {
                     objList.add(o1);
                 }
            } else {
                //Liste von...  [1] - fieldName == elementData dort ist die Liste enthalten
                final Iterable<ObjectelementData = (Iterable<Object>) o1;
                for (final Object o : elementData) {
                    objList.add(o);
                }
            }
            //einmal ColInfo erzeugen
            if (objList.isEmpty()) {
                //liste leer...
            } else {
                final Object firstObject = objList.get(0);
                final Class firstObjectClass = firstObject.getClass();
                //java.lang ??
                final Field[] fields = firstObjectClass.getDeclaredFields();
                for (final Field field : fields) {
                    final int modifiers = field.getModifiers();
                    if (!Modifier.isStatic(modifiers)) {
                        if (Modifier.isPrivate(modifiers)) {
                            final Class<?> type = field.getType();
                            final String fieldName = field.getName();
                            tableCreator.addNextColInfo(fieldName.toUpperCase(), typetruetrue); //JIRA MOD-31 steuern der ColNamen - Schreibweise
                        } else {
                            //
                        }
                    } else {
                        //not Accessible
                    }
                }
                tableCreator.addNextColInfo(String.classfalsefalse);
                for (final Object actualEntity : objList) {
                    final Long objId = getObjIdIfAvailable(actualEntity);
                    if (objId == null) {
                        //keine ID im Object...
                    } else {
                        tableCreator.addNewRow();
                        for (final Field field : fields) {
                            final int modifiers = field.getModifiers();
                            if (!Modifier.isStatic(modifiers)) {
                                if (Modifier.isPrivate(modifiers)) {
                                    final String fieldName = field.getName();
                                    if (fieldName == null) {
                                        //
                                    } else {
                                        try {
                                            field.setAccessible(true);
                                            final Object attributeObj = field.get(actualEntity);
                                            if (attributeObj == null) {
                                                //was machen mit null werten ?
                                            } else {
                                                //Liste oder einzelner Wert
                                                // aus svenruppert.orm ??
                                                final String ColName = fieldName.toUpperCase();
                                                //                                                if(attributeObj instanceof Iterable || attributeObj instanceof BeanCollection){
                                                if (attributeObj instanceof Iterable) {
                                                    //finde heraus welche Klasse enthalten ist.
                                                    final Iterable oIterable = (IterableattributeObj;
                                                    final Iterator iterator = oIterable.iterator();
                                                    if (iterator.hasNext()) {
                                                        //ist nicht leer..
                                                        final Object nextElement = iterator.next();
                                                        final boolean isNeoScioPkg = checkPkg(nextElement);
                                                        if (isNeoScioPkg) {
                                                            //umschalten auf Edit Feld Link
                                                            final Class<? extends ObjectnextElementClass = nextElement.getClass();
                                                            final String pageLink = createPageLinkFor(nextElementClass);
                                                            final String ctxValue = actualEntity.getClass().getName() + "/" + objId;
                                                            tableCreator.addNextCellRawLink(ColNamepageLink + "/" + ctxValue);
                                                            tableCreator.getTable().getColumnInformationFor(ColName).setExportable(false);
                                                            tableCreator.getTable().getColumnInformationFor(ColName).setSortable(false);
                                                        } else {
                                                            //ein Fall f die Std Formatter...
                                                            tableCreator.addNextCellRawData(ColNameattributeObj);
                                                        }
                                                    } else {
                                                        //leere Menge...  einfach mal adden
                                                        tableCreator.addNextCellRawData(ColNameattributeObj);
                                                    }
                                                } else {
                                                    //komplex und v svenruppert ? dann Link
                                                    if (checkPkg(attributeObj)) {
                                                        final Class<? extends ObjectaClass = attributeObj.getClass();
                                                        final String pageLink = createPageLinkFor(aClass);
                                                        final String ctxValue = actualEntity.getClass().getName() + "/" + objId;
                                                        tableCreator.addNextCellRawLink(ColNamepageLink + "/" + ctxValue);
                                                        tableCreator.getTable().getColumnInformationFor(ColName).setExportable(false);
                                                        tableCreator.getTable().getColumnInformationFor(ColName).setSortable(false);
                                                    } else {
                                                        //sonst..
                                                        tableCreator.addNextCellRawData(ColNameattributeObj);
                                                    }
                                                }
                                            }
                                            field.setAccessible(false);
                                        } catch (IllegalAccessException e) {
                                            .error(e);
                                        }
                                    }
                                } else {
                                    //
                                }
                            } else {
                                //not Accessible
                            }
                        }
                        //Edit Spalte..
                        //erzeuge PageLink   subpkg + Classanem + Edit;
                        if (checkPkg(actualEntity)) {
                            final Class<? extends ObjectactualEntityClass = actualEntity.getClass();
                            final String pageLink = createPageLinkFor(actualEntityClass);
                            tableCreator.addNextCellRawLink(pageLink + "/" + objId);
                        } else {
                            if (.isDebugEnabled()) {
                                .debug("Nicht aus dem Basis Pkg org.rapidpm.orm " + actualEntity.getClass().getName());
                            }
                        }
                    }
                }
            }
        } else {
        }
    }
    private Long getObjIdIfAvailable(final Object actualEntity) {
        Long objId = null;
        final Class<? extends ObjectentityClass = actualEntity.getClass();
        final Method[] methods = entityClass.getMethods();
        for (final Method method : methods) {
            final String methodName = method.getName();
            if (methodName.equals("getId")) {
                final Class<?> type = method.getReturnType();
                try {
                    final Method methodBeanB = entityClass.getMethod("getId");
                    final Object o = methodBeanB.invoke(actualEntity);
                    if (o instanceof Long) {
                        objId = (Longo;
                    } else {
                        //falscher typ
                    }
                    //                            break;
                } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
                    .error(e);
                }
            } else {
                //falsche Methode
            }
        }
        return objId;
    }
    private String createPageLinkFor(final Class<? extends ObjectaClassfinal String postExtension) {
        final String pkgName = aClass.getPackage().getName();
        final String ctxPath =  + "/admin" + pkgName.replace("org.rapidpm.orm""").replace(".""/") + "/" + aClass.getSimpleName() + postExtension;
        return ctxPath;
    }
    private boolean checkPkg(final Object nextElement) {
        final Class<? extends ObjectnextElementClass = nextElement.getClass();
        final Package aPackage = nextElementClass.getPackage();
        final String pkgname = aPackage.getName();
        final boolean isNeoScioPkg = pkgname.contains("org.rapidpm.orm");
        final boolean isEbeanPkg = pkgname.contains("com.avaje.ebean.bean");
        return isNeoScioPkg || isEbeanPkg;
    }
New to GrepCode? Check out our FAQ X