Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * This program is free software; you can redistribute it and/or modify it under the 
   * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software 
   * Foundation.
   *
   * You should have received a copy of the GNU Lesser General Public License along with this 
   * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 
   * or from the Free Software Foundation, Inc., 
   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * See the GNU Lesser General Public License for more details.
  *
  * Copyright 2006 - 2009 Pentaho Corporation.  All rights reserved.
  *
 */
 package org.pentaho.platform.plugin.action.jfreereport.components;
 
 import java.util.Set;
 
 
 import org.dom4j.Node;
 import  org.pentaho.platform.api.data.IDataComponent;
 import  org.pentaho.platform.api.data.IPreparedComponent;
 import  org.pentaho.platform.api.engine.IActionSequenceResource;
 import  org.pentaho.platform.api.engine.IRuntimeContext;
 import  org.pentaho.platform.api.repository.ISolutionRepository;
 import  org.pentaho.platform.engine.core.system.PentahoSystem;
This is step 2 out of 3. This class is a wrapper around an other component, for instance the SQL- or MDX query component.

Deprecated:
Author(s):
Thomas Morgner
 
 
   private static final long serialVersionUID = -1708477862117476001L;
 
   private IDataComponent dataComponent;
 
   public JFreeReportDataComponent() {
   }

  
Validates the parameters of this action.

Returns:
 
   @Override
   protected boolean validateAction() {
     return true;
   }
 
   public IDataComponent getDataComponent() {
     return ;
   }
 
   @Override
   protected boolean validateSystemSettings() {
     return true;
   }
 
   @Override
   public void done() {
     // help the garbage collector ...
     if ( != null) {
       .dispose();
       .done();
     }
      = null;
   }
 
     PentahoTableDataFactory factory = null;
      = null;
     final Node sourceNode = getComponentDefinition()
         .selectSingleNode(.);
     if (sourceNode != null) {
      String dataComponentClass = sourceNode.getText();
        dataComponentClass = .;
      } else if (..equalsIgnoreCase(dataComponentClass)) {
        dataComponentClass = .;
      }
      if (dataComponentClass != null) {
        try {
          final Class componentClass = Class.forName(dataComponentClass);
           = (IDataComponent) componentClass.newInstance();
          .setInstanceId(getInstanceId());
          .setActionName(getActionName());
          .setProcessId(getProcessId());
          .setComponentDefinition(getComponentDefinition());
          .setRuntimeContext(getRuntimeContext());
          .setSession(getSession());
          .setLoggingLevel(getLoggingLevel());
          .setMessages(getMessages());
          // if that fails, then we know we messed up again.
          // Abort, we cant continue anyway.
          if ((.validate() == IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_OK) && .init()
              && (.execute() == IRuntimeContext.RUNTIME_STATUS_SUCCESS)) {
            final IPentahoResultSet resultset = .getResultSet();
                new PentahoTableModel(resultset));
          } else {
            throw new IllegalArgumentException(Messages.getErrorString("JFreeReport.ERROR_0021_DATA_COMPONENT_FAILED"));
          }
        } catch (ClassNotFoundException e) {
        } catch (InstantiationException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
    return factory;
  }
    PentahoTableDataFactory factory = null;
      final IActionSequenceResource resource = getResource(.);
      final ISolutionRepository solutionRepository = PentahoSystem.get(ISolutionRepository.classgetSession());
      final InputStream in;
      try {
        in = solutionRepository.getResourceInputStream(resourcetrue);
        try {
          // not being able to read a single char is definitly a big boo ..
          if (in.read() == -1) {
            throw new Exception(Messages.getErrorString("JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE")); //$NON-NLS-1$
          } else {
            final ClassLoader loader = ReportUtils.createJarLoader(getSession(), resource);
            if (loader == null) {
              throw new Exception(Messages
                  .getString("JFreeReportDataComponent.ERROR_0035_COULD_NOT_CREATE_CLASSLOADER")); //$NON-NLS-1$
              throw new Exception(Messages.getErrorString("JFreeReport.ERROR_0012_CLASS_LOCATION_MISSING")); //$NON-NLS-1$
            } else {
              final String classLocation = getInputStringValue(.);
              // Get input parameters, and set them as properties in the report
              // object.
              final ReportProperties reportProperties = new ReportProperties();
              final Set paramNames = getInputNames();
              final Iterator it = paramNames.iterator();
              while (it.hasNext()) {
                final String paramName = (Stringit.next();
                final Object paramValue = getInputValue(paramName);
                if (paramValue instanceof Object[]) {
                  final Object[] values = (Object[]) paramValue;
                  final StringBuffer valuesBuffer = new StringBuffer();
                  // TODO support non-string items
                  for (int i = 0; i < values.lengthi++) {
                    if (i == 0) {
                      valuesBuffer.append(values[i].toString());
                    } else {
                      valuesBuffer.append(',').append(values[i].toString());
                    }
                  }
                  reportProperties.put(paramNamevaluesBuffer.toString());
                } else {
                  reportProperties.put(paramNameparamValue);
                }
              }
              final DataFactory dataFactory = new PentahoDataFactory(loader);
              final TableModel model = dataFactory.queryData(classLocationnew ParameterDataRow(reportProperties));
              factory = new PentahoTableDataFactory(.model);
            }
          }
        } catch (Exception e) {
          throw new Exception(Messages.getErrorString("JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE"));
        }
      } catch (FileNotFoundException e1) {
        throw new Exception(Messages.getErrorString("JFreeReport.ERROR_0010_REPORT_JAR_MISSING"resource.getAddress()));
      }
    }
    return factory;
  }
    PentahoTableDataFactory factory = null;
      factory = new PentahoTableDataFactory();
      final Iterator iter = getInputNames().iterator();
      while (iter.hasNext()) {
        String name = (Stringiter.next();
        final Object dataObject = getInputValue(name);
        // if input name is "data", rename to "default" which is the name that jfreereport is expecting.
        }
        if (dataObject instanceof IPreparedComponent) {
          final IPreparedComponent comp = (IPreparedComponent) dataObject;
          factory.addPreparedComponent(namecomp);
        } else if (dataObject instanceof IPentahoResultSet) {
          final IPentahoResultSet resultset = (IPentahoResultSetdataObject;
          resultset.beforeFirst();
          factory.addTable(namenew PentahoTableModel(resultset));
        } else if (dataObject instanceof TableModel) {
          final TableModel model = (TableModeldataObject;
          factory.addTable(namemodel);
        }
      }
    }
    return factory;
  }
  protected boolean executeAction() throws Throwable {
    boolean result = false;
    //    try {
    //      PentahoTableDataFactory factory = getDataFactory();
    //      if (factory != null) {
    //        addTempParameterObject(DATACOMPONENT_REPORTTEMP_DATAFACTORY, factory);
    //      }
    result = true;
    //    } catch (ClassNotFoundException ex) {
    //      error(Messages.getErrorString("JFreeReport.ERROR_0021_DATA_COMPONENT_FAILED"), ex); //$NON-NLS-1$
    //    } catch (InstantiationException ex) {
    //      error(Messages.getErrorString("JFreeReport.ERROR_0021_DATA_COMPONENT_FAILED"), ex); //$NON-NLS-1$
    //    } catch (IllegalAccessException ex) {
    //      error(Messages.getErrorString("JFreeReport.ERROR_0021_DATA_COMPONENT_FAILED"), ex); //$NON-NLS-1$
    //    } catch (Exception ex) {
    //      error(ex.getMessage()); //$NON-NLS-1$
    //    }
    return result;
  }
  public boolean init() {
    return true;
  }
  public Log getLogger() {
    return LogFactory.getLog(JFreeReportDataComponent.class);
  }
New to GrepCode? Check out our FAQ X