public static XmlArray createFrom(InputStream is)
      throws IOException, ParserConfigurationException, SAXException {
    XmlArray array = new XmlArray();

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(is);
    Node root = document.getFirstChild();
    if (!TAG_ARRAY.equals(root.getNodeName())) {
      throw new IOException(Messages.getString("XmlArray.InvalidFile")); // $NON-NLS-1$
    }

    // Rows
    NodeList rows = root.getChildNodes();
    int counter = 0;
    for (int r = 0; r < rows.getLength(); r++) {
      Node row = rows.item(r);
      if (TAG_ROW.equals(row.getNodeName())) {
        XmlRow xRow = new XmlRow();

        NodeList fields = row.getChildNodes();
        for (int f = 0; f < fields.getLength(); f++) {
          Node field = fields.item(f);
          if (TAG_FIELD.equals(field.getNodeName())) {
            XmlField xField = new XmlField(field.getTextContent());
            xRow.add(xField);
          }
        }

        array.add(xRow);
        counter++;
        if (counter >= rowLimit) {
          break;
        }
      }
    }

    return array;
  }
Beispiel #2
0
/**
 * Different types of connections in Talend. <br>
 * $Id: EConnectionType.java 38013 2010-03-05 14:21:59Z mhirt $
 */
public enum EConnectionType implements IConnectionCategory, IDraw2dGraphics {
  FLOW_MAIN(
      0,
      "FLOW", //$NON-NLS-1$
      EConnectionCategory.MAIN,
      MAIN | DATA | FLOW | CUSTOM_NAME | UNIQUE_NAME,
      "Main",
      Messages.getString("EConnectionType.mainMenu"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(230, 100, 0)),

  RUN_AFTER(
      2,
      "AFTER", //$NON-NLS-1$
      EConnectionCategory.OTHER,
      EXECUTION_ORDER | DEPENDENCY,
      "RunAfter",
      Messages.getString("EConnectionType.runAfterMenu"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(100, 100, 100)),

  RUN_IF(
      6,
      "RUN_IF", //$NON-NLS-1$
      EConnectionCategory.OTHER,
      CONDITION | DEPENDENCY | CUSTOM_NAME | UNIQUE_NAME,
      "If",
      Messages.getString("EConnectionType.runIfMenu"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_DASHDOTDOT),
      new RGB(180, 100, 30)),

  ON_SUBJOB_OK(
      1,
      "SUBJOB_OK", //$NON-NLS-1$
      EConnectionCategory.OTHER,
      EXECUTION_ORDER | DEPENDENCY | UNIQUE_NAME,
      "OnSubjobOk",
      Messages.getString("EConnectionType.onSubjobOkMenu"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(0, 100, 0)),

  ON_SUBJOB_ERROR(
      4,
      "SUBJOB_ERROR", //$NON-NLS-1$
      EConnectionCategory.OTHER,
      EXECUTION_ORDER | DEPENDENCY | UNIQUE_NAME,
      "OnSubjobError",
      Messages.getString("EConnectionType.onSubjobErrorMenu"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(128, 0, 0)),

  ON_COMPONENT_OK(
      3,
      "COMPONENT_OK", //$NON-NLS-1$
      EConnectionCategory.OTHER,
      CONDITION | DEPENDENCY | UNIQUE_NAME,
      "OnComponentOk",
      Messages.getString("EConnectionType.onComponentOkMenu"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(0, 150, 0)),

  ON_COMPONENT_ERROR(
      5,
      "COMPONENT_ERROR", //$NON-NLS-1$
      EConnectionCategory.OTHER,
      CONDITION | DEPENDENCY | UNIQUE_NAME,
      "OnComponentError",
      Messages.getString("EConnectionType.onComponentErrorMenu"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(200, 0, 0)),

  ON_ROWS_END(
      11,
      "ROWS_END", //$NON-NLS-1$
      EConnectionCategory.MAIN,
      MAIN | USE_ITERATE,
      "OnRowsEnd",
      Messages.getString("EConnectionType.onRowsEndMenu"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(0, 150, 0)),

  ITERATE(
      7,
      "ITERATE", //$NON-NLS-1$
      EConnectionCategory.MAIN,
      MAIN | USE_ITERATE | UNIQUE_NAME,
      "Iterate",
      Messages.getString("EConnectionType.iteratorMenu"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(100, 230, 0)),

  FLOW_REF(
      8,
      "LOOKUP", //$NON-NLS-1$
      EConnectionCategory.OTHER,
      DATA | FLOW | CUSTOM_NAME | USE_HASH | UNIQUE_NAME,
      "Lookup",
      Messages.getString("EConnectionType.lookupMenu"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_DOT),
      new RGB(230, 100, 0)),

  TABLE(
      9,
      "TABLE", //$NON-NLS-1$
      EConnectionCategory.MAIN,
      MAIN | DATA | CUSTOM_NAME,
      "Table",
      Messages.getString("EConnectionType.tableMenu"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(0, 150, 100)),

  FLOW_MERGE(
      10,
      "MERGE", //$NON-NLS-1$
      EConnectionCategory.MAIN,
      MAIN | DATA | FLOW | CUSTOM_NAME | UNIQUE_NAME | MERGE,
      "Merge",
      Messages.getString("EConnectionType.mergeMenu"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_DASHDOT),
      new RGB(230, 100, 0)),

  SYNCHRONIZE(
      12,
      "SYNCHRONIZE", //$NON-NLS-1$
      EConnectionCategory.MAIN,
      EXECUTION_ORDER | DEPENDENCY,
      "Synchronize",
      Messages.getString("EConnectionType.synchronize"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_DASH),
      new RGB(0, 50, 150)),
  PARALLELIZE(
      13,
      "PARALLELIZE", //$NON-NLS-1$
      EConnectionCategory.MAIN,
      EXECUTION_ORDER | DEPENDENCY,
      "Parallelize",
      Messages.getString("EConnectionType.parallelize"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_DASH),
      new RGB(0, 50, 150)),
  ROUTE(
      14,
      "ROUTE", //$NON-NLS-1$
      EConnectionCategory.MAIN,
      CAMEL | UNIQUE_NAME | CUSTOM_NAME,
      "Route",
      Messages.getString("EConnectionType.route"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(230, 100, 0)),
  ROUTE_WHEN(
      15,
      "ROUTE_WHEN", //$NON-NLS-1$
      EConnectionCategory.MAIN,
      CONDITION | CAMEL | UNIQUE_NAME | CUSTOM_NAME,
      "When",
      Messages.getString("EConnectionType.when"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(230, 100, 0)),
  ROUTE_OTHER(
      16,
      "ROUTE_OTHER", //$NON-NLS-1$
      EConnectionCategory.MAIN,
      CAMEL | UNIQUE_NAME | CUSTOM_NAME,
      "Otherwise",
      Messages.getString("EConnectionType.otherwise"), // $NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(230, 100, 0)),
  ROUTE_TRY(
      17,
      "ROUTE_TRY", //$NON-NLS-1$
      EConnectionCategory.MAIN,
      CAMEL | UNIQUE_NAME | CUSTOM_NAME,
      "Try",
      "Try", //$NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(0, 100, 0)),
  ROUTE_CATCH(
      18,
      "ROUTE_CATCH", //$NON-NLS-1$
      EConnectionCategory.MAIN,
      CONDITION | CAMEL | UNIQUE_NAME | CUSTOM_NAME,
      "Catch",
      "Catch", //$NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(128, 0, 0)),
  ROUTE_FINALLY(
      19,
      "ROUTE_FINALLY", //$NON-NLS-1$
      EConnectionCategory.MAIN,
      CAMEL | UNIQUE_NAME | CUSTOM_NAME,
      "Finally",
      "Finally", //$NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(0, 0, 160)),
  ROUTE_ENDBLOCK(
      20,
      "ROUTE_ENDBLOCK", //$NON-NLS-1$
      EConnectionCategory.MAIN,
      CAMEL | UNIQUE_NAME | CUSTOM_NAME,
      "Route",
      "Route", //$NON-NLS-1$ //$NON-NLS-2$
      new Integer(LINE_SOLID),
      new RGB(230, 100, 0)),

  STARTS(
      21,
      "STARTS",
      EConnectionCategory.OTHER,
      CONDITION | DEPENDENCY | UNIQUE_NAME,
      "Starts",
      Messages.getString("EConnectionType.startsMenu"),
      new Integer(LINE_SOLID),
      new RGB(0, 0, 150));

  private String name;

  private int id;

  private EConnectionCategory category;

  private int connectionCategory;

  private String defaultMenuName;

  private String defaultLinkName;

  /** @see org.eclipse.draw2d.Graphics */
  private Integer defaultLineStyle;

  private RGB rgb;

  EConnectionType(
      int id,
      String name,
      EConnectionCategory category,
      int connectionCategory,
      String linkName,
      String menuName,
      Integer lineStyle,
      RGB rgb) {
    this.id = id;
    this.name = name;
    this.category = category;
    this.connectionCategory = connectionCategory;
    this.defaultLinkName = linkName;
    this.defaultMenuName = menuName;
    this.defaultLineStyle = lineStyle;
    this.rgb = rgb;
  }

  public static EConnectionType getTypeFromId(int id) {
    EConnectionType[] listConnectionType = EConnectionType.values();
    for (int i = 0; i < listConnectionType.length; i++) {
      if ((listConnectionType[i].getId()) == id) {
        return listConnectionType[i];
      }
    }
    // Default Value
    return EConnectionType.FLOW_MAIN;
  }

  public static EConnectionType getTypeFromName(String name) {
    EConnectionType[] listConnectionType = EConnectionType.values();
    for (int i = 0; i < listConnectionType.length; i++) {
      if (listConnectionType[i].getName().equals(name)) {
        return listConnectionType[i];
      }
    }
    return null;
  }

  public String getName() {
    return this.name;
  }

  public int getId() {
    return this.id;
  }

  /**
   * Getter for category.
   *
   * @return the category
   * @deprecated
   */
  @Deprecated
  public EConnectionCategory getCategory() {
    return this.category;
  }

  public boolean hasConnectionCategory(int category) {
    return (connectionCategory & category) != 0;
  }

  /**
   * Getter for defaultColor.
   *
   * @return the defaultColor
   */
  public RGB getRGB() {
    return rgb;
  }

  /**
   * Getter for defaultLineStyle.
   *
   * @return the defaultLineStyle
   */
  public Integer getDefaultLineStyle() {
    return defaultLineStyle;
  }

  /**
   * Getter for defaultLinkName.
   *
   * @return the defaultLinkName
   */
  public String getDefaultLinkName() {
    return defaultLinkName;
  }

  /**
   * Getter for defaultMenuName.
   *
   * @return the defaultMenuName
   */
  public String getDefaultMenuName() {
    return defaultMenuName;
  }
}
/**
 * class global comment. Detailled comment <br>
 * $Id: FunctionManager.java,v 1.13 2007/01/31 05:20:51 pub Exp $
 */
public class FunctionManager {

  public static final String PURE_PERL_NAME = "..."; // $NON-NLS-1$

  public static final String PURE_PERL_DESC =
      Messages.getString("FunctionManager.PurePerl.Desc"); // $NON-NLS-1$

  public static final String PURE_PERL_PARAM =
      Messages.getString("FunctionManager.PurePerl.ParaName"); // $NON-NLS-1$

  private List<TalendType> talendTypes = null;

  public static final String PERL_FUN_PREFIX = "sub{"; // $NON-NLS-1$

  public static final String PERL_FUN_SUFFIX = ")}"; // $NON-NLS-1$

  public static final String FUN_PARAM_SEPARATED = ","; // $NON-NLS-1$

  public static final String JAVA_METHOD_SEPARATED = "."; // $NON-NLS-1$

  public static final String FUN_PREFIX = "("; // $NON-NLS-1$

  public static final String FUN_SUFFIX = ")"; // $NON-NLS-1$

  public static final String EMPTY_STRING = " "; // $NON-NLS-1$

  /**
   * qzhang Comment method "getFunctionByName".
   *
   * @param name is TalendType name.
   * @return
   */
  @SuppressWarnings("unchecked")
  public List<Function> getFunctionsByType(String name) {
    List<Function> funtions = new ArrayList<Function>();

    for (TalendType talendType : talendTypes) {
      if (talendType.getName().equals(name)) {
        funtions.addAll(talendType.getFunctions());
      }
    }
    funtions.add(createCustomizeFunction());
    return funtions;
  }

  private Function createCustomizeFunction() {
    Function function = new Function();
    function.setName(PURE_PERL_NAME);
    function.setDescription(PURE_PERL_DESC);
    StringParameter param = new StringParameter();
    List<Parameter> params = new ArrayList<Parameter>();
    param.setName(PURE_PERL_PARAM);
    params.add(param);
    function.setParameters(params);
    return function;
  }

  public RepositoryContext getRepositoryContext() {
    Context ctx = CoreRuntimePlugin.getInstance().getContext();
    return (RepositoryContext) ctx.getProperty(Context.REPOSITORY_CONTEXT_KEY);
  }

  @SuppressWarnings("unchecked")
  public FunctionManager() {
    // this code move to FunctionParser .
    //
    // for (int i = 0; i < list.size(); i++) {
    // URL url = list.get(i);
    // try {
    // url = FileLocator.toFileURL(url);
    // File file = new File(url.getFile());
    // files.add(file);
    // } catch (Exception e) {
    // ExceptionHandler.process(e);
    // }
    // }
    AbstractFunctionParser parser = null;
    parser = new RoutineFunctionParser();
    parser.parse();
    talendTypes = parser.getList();
  }

  @SuppressWarnings("unchecked")
  public FunctionManager(String type) {
    AbstractFunctionParser parser = null;
    if (JavaUtils.JAVA_PIG_DIRECTORY.equals(type)) {
      // pig map expressionbuilder
      if (GlobalServiceRegister.getDefault().isServiceRegistered(IPigMapService.class)) {
        final IPigMapService service =
            (IPigMapService) GlobalServiceRegister.getDefault().getService(IPigMapService.class);
        parser = service.pigFunctionParser();
        parser.parse();
        talendTypes = parser.getList();
      }
    }
  }

  public static boolean isJavaProject() {
    ECodeLanguage codeLanguage = LanguageManager.getCurrentLanguage();
    return (codeLanguage == ECodeLanguage.JAVA);
  }

  public List<TalendType> getTalendTypes() {
    return this.talendTypes;
  }

  /**
   * DOC ggu Comment method "getFunctionMethod".
   *
   * @param f
   */
  public static String getFunctionMethod(Function f) {
    String newValue = ""; // $NON-NLS-1$
    if (f != null) {

      final List<Parameter> parameters = f.getParameters();
      if (isJavaProject()) {
        String fullName = f.getClassName() + JAVA_METHOD_SEPARATED + f.getName();
        newValue = fullName + FUN_PREFIX;
        for (Parameter pa : parameters) {
          newValue += pa.getValue() + FUN_PARAM_SEPARATED;
        }
        if (!parameters.isEmpty()) {
          newValue = newValue.substring(0, newValue.length() - 1);
        }
        newValue += FUN_SUFFIX;

      } else {
        newValue = f.getName() + FUN_PREFIX;
        for (Parameter pa : parameters) {
          newValue += pa.getValue() + FUN_PARAM_SEPARATED;
        }
        if (!parameters.isEmpty()) {
          newValue = newValue.substring(0, newValue.length() - 1);
        }
        newValue += FUN_SUFFIX;
      }
    }
    return newValue;
  }
}
Beispiel #4
0
  /** Create the contents in the main composite. */
  protected void createMainContents() {
    if (displayTitle) {
      title = new TabbedPropertyTitle(mainComposite, factory);

      FormData data = new FormData();
      data.left = new FormAttachment(0, 0);
      if (displayCompactToolbar) {
        data.right = new FormAttachment(90, 0);
      } else {
        data.right = new FormAttachment(100, 0);
      }
      data.top = new FormAttachment(0, 0);
      title.setLayoutData(data);

      if (displayCompactToolbar) {
        toolBarComposite = new Composite(mainComposite, SWT.NONE);
        compactButton = new Button(toolBarComposite, SWT.PUSH);
        compactButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
        compactButton.setToolTipText(
            Messages.getString(
                "TalendTabbedPropertyComposite.compactButton.toolTip")); //$NON-NLS-1$

        tableButton = new Button(toolBarComposite, SWT.PUSH);
        tableButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
        tableButton.setToolTipText(
            Messages.getString("TalendTabbedPropertyComposite.tableButton.toolTip")); // $NON-NLS-1$

        if (isCompactView()) {
          compactButton.setImage(ImageProvider.getImage(EImage.COMPACT_VIEW));
          tableButton.setImage(ImageProvider.getImage(EImage.NO_TABLE_VIEW));
        } else {
          compactButton.setImage(ImageProvider.getImage(EImage.NO_COMPACT_VIEW));
          tableButton.setImage(ImageProvider.getImage(EImage.TABLE_VIEW));
        }

        Rectangle compactRectangle = compactButton.getBounds();
        tableButton.setBounds(compactRectangle);

        compactButton.setVisible(false);
        tableButton.setVisible(false);

        data = new FormData();
        data.left = new FormAttachment(title, 0);
        data.top = new FormAttachment(0, -5);
        toolBarComposite.setLayoutData(data);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = SWT.RIGHT;
        gridData.verticalAlignment = SWT.TOP;
        compactButton.setData(gridData);
        tableButton.setData(gridData);

        GridLayout layout = new GridLayout();
        layout.numColumns = 2;
        layout.horizontalSpacing = 0;
        layout.verticalSpacing = 0;
        layout.makeColumnsEqualWidth = true;
        toolBarComposite.setLayout(layout);
        toolBarComposite.setBackground(title.getBackground());
      }
    }

    leftComposite = factory.createComposite(mainComposite, SWT.NO_FOCUS);
    leftComposite.setLayout(new FormLayout());

    scrolledComposite =
        factory.createScrolledComposite(mainComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS);
    scrolledComposite.setLayout(new FormLayout());

    FormData formData = new FormData();
    formData.left = new FormAttachment(leftComposite, 0);
    formData.right = new FormAttachment(100, 0);
    if (displayTitle) {
      formData.top = new FormAttachment(title, 0);
    } else {
      formData.top = new FormAttachment(0, 0);
    }
    formData.bottom = new FormAttachment(100, 0);
    scrolledComposite.setLayoutData(formData);

    formData = new FormData();
    formData.left = new FormAttachment(0, 0);
    formData.right = new FormAttachment(scrolledComposite, 0);
    if (displayTitle) {
      formData.top = new FormAttachment(title, 0);
    } else {
      formData.top = new FormAttachment(0, 0);
    }
    formData.bottom = new FormAttachment(100, 0);
    leftComposite.setLayoutData(formData);

    tabComposite = factory.createComposite(scrolledComposite, SWT.NO_FOCUS);
    tabComposite.setLayout(new FormLayout());
    tabComposite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));

    scrolledComposite.setContent(tabComposite);
    scrolledComposite.setAlwaysShowScrollBars(false);
    scrolledComposite.setExpandVertical(true);
    scrolledComposite.setExpandHorizontal(true);

    listComposite = new TalendTabbedPropertyList(leftComposite, factory);
    formData = new FormData();
    formData.left = new FormAttachment(0, 0);
    formData.right = new FormAttachment(100, 0);
    formData.top = new FormAttachment(0, 0);
    formData.bottom = new FormAttachment(100, 0);
    listComposite.setLayoutData(formData);

    FormData data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    tabComposite.setLayoutData(data);
  }