ErrorConnectorArtifact.java :  » Library » bonita » org » bonitasoft » studio » repository » connectors » Java Open Source

Java Open Source » Library » bonita 
bonita » org » bonitasoft » studio » repository » connectors » ErrorConnectorArtifact.java
/**
 * Copyright (C) 2010 BonitaSoft S.A.
 * BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2.0 of the License, or
 * (at your option) any later version.
 *
 * 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.bonitasoft.studio.repository.connectors;

import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.repository.myextensions.ExtensionProjectUtil;
import org.eclipse.jdt.core.IType;
import org.ow2.bonita.connector.core.ConnectorError;
import org.ow2.bonita.connector.core.ConnectorException;

/**
 * @author Mickael Istria
 *
 */
public class ErrorConnectorArtifact extends ConnectorRepositoryArtifact {

  private ConnectorException exception;
  
  /**
   * @param connectorId
   */
  public ErrorConnectorArtifact(ConnectorException connectorException) {
    super(connectorException.getConnectorClassName());
    this.exception = connectorException;
  }
  
  /**
   * @param string
   */
  public ErrorConnectorArtifact(String className) {
    super(className);
  }

  @Override
  public IType getConnectorClassType() {
    try {
      return ExtensionProjectUtil.getJavaProject().findType(getId());
    } catch (Exception ex) {
      BonitaStudioLog.log(ex);
      return null;
    }
  }

  /**
   * @return
   */
  public String getErrorMessage() {
    if (exception != null) {
      StringBuilder res = new StringBuilder();
      for (ConnectorError error : exception.getErrors()) {
        res.append("Error on field: " + error.getField()); res.append("\n");
        res.append("  " + error.getError().getMessage()); res.append("\n");
      }
      return res.toString();
    } else {
      return null;
    }
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.