org.eclipse.datatools.connectivity.oda.profile_3.2.7.v201112290953

16:42:44.314 INFO  jd.cli.Main - Decompiling org.eclipse.datatools.connectivity.oda.profile_3.2.7.v201112290953.jar
package org.eclipse.datatools.connectivity.oda.profile;

import org.eclipse.datatools.connectivity.oda.profile.nls.Messages;

public class Constants
{
  public static String ODA_COMPONENT_NAME = Messages.constants_componentName;
  public static final String ODA_COMPONENT_VERSION = "3.0.6";
  public static final String EMPTY_STRING = "";
  public static final String CONN_PROFILE_APPL_ID = "org.eclipse.datatools.connectivity.oda.profile.connectionPropertyService";
  public static final String ODA_PARENT_CATEGORY_ID = "org.eclipse.datatools.connectivity.oda.profileCategory";
  public static final String DB_PROFILE_PROVIDER_ID = "org.eclipse.datatools.connectivity.oda.profile.db.provider.id";
  public static final String DATABASE_CATEGORY_ID = "org.eclipse.datatools.connectivity.db.category";
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.profile.Constants
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.profile;

import org.eclipse.datatools.connectivity.IConnection;
import org.eclipse.datatools.connectivity.IConnectionFactory;
import org.eclipse.datatools.connectivity.IConnectionProfile;

public class OdaConnectionFactory
  implements IConnectionFactory
{
  public IConnection createConnection(IConnectionProfile profile)
  {
    return new OdaConnectionWrapper(profile);
  }
  
  public IConnection createConnection(IConnectionProfile profile, String uid, String pwd)
  {
    return createConnection(profile);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.profile.OdaConnectionFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.profile;

import org.eclipse.datatools.connectivity.ConnectionProfileConstants;
import org.eclipse.datatools.connectivity.Version;

class OdaConnectionWrapper$1
  extends Version
{
  OdaConnectionWrapper$1(int $anonymous0, int $anonymous1, int $anonymous2, String $anonymous3)
  {
    super($anonymous0, $anonymous1, $anonymous2, $anonymous3);
  }
  
  public String toString()
  {
    return ConnectionProfileConstants.UNKNOWN_VERSION;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.profile.OdaConnectionWrapper.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.profile;

import org.eclipse.datatools.connectivity.ConnectionProfileConstants;
import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.datatools.connectivity.Version;
import org.eclipse.datatools.connectivity.VersionProviderConnection;
import org.eclipse.datatools.connectivity.oda.IConnection;
import org.eclipse.datatools.connectivity.oda.IDataSetMetaData;
import org.eclipse.datatools.connectivity.oda.IDriver;
import org.eclipse.datatools.connectivity.oda.OdaException;
import org.eclipse.datatools.connectivity.oda.consumer.helper.OdaDriver;

public class OdaConnectionWrapper
  extends VersionProviderConnection
{
  private static final String EMPTY_STR = "";
  private static final Version ODA_UNKNOWN_VERSION = new Version(3, 0, 0, "")
  {
    public String toString()
    {
      return ConnectionProfileConstants.UNKNOWN_VERSION;
    }
  };
  private String m_odaDataSourceId;
  private IConnection m_odaConnectionHelper;
  private IDriver m_odaDriverHelper;
  private IDataSetMetaData m_odaMetadataHelper;
  private Exception m_connectException;
  
  public OdaConnectionWrapper(IConnectionProfile profile)
  {
    super(profile, OdaConnectionFactory.class);
    
    m_odaDataSourceId = profile.getProviderId();
    try
    {
      getOdaConnectionHelper(m_odaDataSourceId);
      assert (m_odaConnectionHelper != null);
      open();
      m_connectException = null;
    }
    catch (OdaException ex)
    {
      m_connectException = ex;
      clearVersionCache();
      return;
    }
    try
    {
      m_odaMetadataHelper = 
        m_odaConnectionHelper.getMetaData("");
    }
    catch (OdaException e)
    {
      e.printStackTrace();
    }
    if (!canProvideVersionMetaData()) {
      m_odaMetadataHelper = null;
    }
    updateVersionCache();
  }
  
  public Object getRawConnection()
  {
    return m_odaConnectionHelper;
  }
  
  public void close()
  {
    if (getRawConnection() == null) {
      return;
    }
    try
    {
      m_odaConnectionHelper.close();
      m_odaMetadataHelper = null;
      m_connectException = null;
    }
    catch (OdaException localOdaException) {}
  }
  
  public Throwable getConnectException()
  {
    return m_connectException;
  }
  
  protected String getTechnologyRootKey()
  {
    if ((m_odaDataSourceId == null) || (m_odaDataSourceId.length() == 0)) {
      return getClass().getName();
    }
    return m_odaDataSourceId;
  }
  
  public Version getProviderVersion()
  {
    if (m_odaMetadataHelper == null) {
      return ODA_UNKNOWN_VERSION;
    }
    try
    {
      return Version.valueOf(m_odaMetadataHelper.getDataSourceProductVersion());
    }
    catch (OdaException e)
    {
      e.printStackTrace();
    }
    return ODA_UNKNOWN_VERSION;
  }
  
  public String getProviderName()
  {
    if (m_odaMetadataHelper == null) {
      return "";
    }
    try
    {
      return m_odaMetadataHelper.getDataSourceProductName();
    }
    catch (OdaException localOdaException) {}
    return getTechnologyRootKey();
  }
  
  public Version getTechnologyVersion()
  {
    return Version.valueOf("3.0.6");
  }
  
  public String getTechnologyName()
  {
    return Constants.ODA_COMPONENT_NAME;
  }
  
  public void open()
    throws OdaException
  {
    IConnection odaConn = m_odaConnectionHelper;
    assert (odaConn != null);
    try
    {
      odaConn.open(getConnectionProfile().getBaseProperties());
    }
    catch (Throwable ex)
    {
      if ((ex instanceof OdaException)) {
        throw ((OdaException)ex);
      }
      throw new OdaException(ex);
    }
  }
  
  private IConnection getOdaConnectionHelper(String odaDataSourceElementId)
    throws OdaException
  {
    if (m_odaConnectionHelper != null) {
      return m_odaConnectionHelper;
    }
    IDriver odaDriver = getOdaDriverHelper(odaDataSourceElementId);
    
    assert (odaDriver != null);
    m_odaConnectionHelper = odaDriver.getConnection(odaDataSourceElementId);
    return m_odaConnectionHelper;
  }
  
  private IDriver getOdaDriverHelper(String odaDataSourceElementId)
    throws OdaException
  {
    if (m_odaDriverHelper == null) {
      m_odaDriverHelper = new OdaDriver(odaDataSourceElementId);
    }
    return m_odaDriverHelper;
  }
  
  private boolean canProvideVersionMetaData()
  {
    if (m_odaMetadataHelper == null) {
      return false;
    }
    try
    {
      getProviderVersion();
      getProviderName();
    }
    catch (RuntimeException localRuntimeException)
    {
      return false;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.profile.OdaConnectionWrapper
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.profile;

import java.io.File;

class OdaProfileExplorer$FileKey
  implements Comparable<FileKey>
{
  private File m_file;
  
  OdaProfileExplorer$FileKey(OdaProfileExplorer paramOdaProfileExplorer, File aFile)
  {
    m_file = aFile;
  }
  
  public boolean equals(Object obj)
  {
    if (!(obj instanceof FileKey)) {
      return false;
    }
    return compareTo((FileKey)obj) == 0;
  }
  
  public int compareTo(FileKey obj)
  {
    if ((this == obj) || (m_file == obj.getFile())) {
      return 0;
    }
    return m_file.compareTo(obj.getFile());
  }
  
  private File getFile()
  {
    return m_file;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.profile.OdaProfileExplorer.FileKey
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.profile;

import java.io.File;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import java.util.logging.Logger;
import org.eclipse.datatools.connectivity.ICategory;
import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.datatools.connectivity.ProfileManager;
import org.eclipse.datatools.connectivity.internal.ConnectionProfileMgmt;
import org.eclipse.datatools.connectivity.oda.OdaException;
import org.eclipse.datatools.connectivity.oda.consumer.services.impl.ProviderUtil;
import org.eclipse.datatools.connectivity.oda.profile.internal.OdaConnectionProfile;
import org.eclipse.datatools.connectivity.oda.profile.internal.OdaProfileFactory;
import org.eclipse.datatools.connectivity.oda.profile.provider.ProfilePropertyProviderImpl;

public class OdaProfileExplorer
{
  private static OdaProfileExplorer sm_instance = null;
  private static final String sm_className = OdaProfileExplorer.class.getName();
  private static Logger sm_logger;
  private Map<FileKey, IConnectionProfile[]> m_loadedProfilesByFile;
  private File m_defaultProfileStoreFile;
  
  public static OdaProfileExplorer getInstance()
  {
    if (sm_instance == null) {
      synchronized (OdaProfileExplorer.class)
      {
        if (sm_instance == null) {
          sm_instance = new OdaProfileExplorer();
        }
      }
    }
    return sm_instance;
  }
  
  public static void releaseInstance()
  {
    synchronized (OdaProfileExplorer.class)
    {
      if (sm_instance != null)
      {
        sm_instance.refresh();
        sm_instance = null;
      }
      sm_logger = null;
    }
  }
  
  private static Logger getLogger()
  {
    if (sm_logger == null) {
      synchronized (OdaProfileExplorer.class)
      {
        if (sm_logger == null) {
          sm_logger = Logger.getLogger(sm_className);
        }
      }
    }
    return sm_logger;
  }
  
  public void refresh()
  {
    if ((m_loadedProfilesByFile == null) || (m_loadedProfilesByFile.isEmpty())) {
      return;
    }
    m_loadedProfilesByFile.clear();
  }
  
  private Map<FileKey, IConnectionProfile[]> getLoadedProfilesMap()
  {
    if (m_loadedProfilesByFile == null) {
      synchronized (this)
      {
        if (m_loadedProfilesByFile == null) {
          m_loadedProfilesByFile = Collections.synchronizedMap(new TreeMap());
        }
      }
    }
    return m_loadedProfilesByFile;
  }
  
  private File defaultProfileStoreFile()
  {
    if (m_defaultProfileStoreFile == null) {
      synchronized (this)
      {
        if (m_defaultProfileStoreFile == null) {
          m_defaultProfileStoreFile = OdaProfileFactory.defaultProfileStoreFile();
        }
      }
    }
    return m_defaultProfileStoreFile;
  }
  
  /**
   * @deprecated
   */
  public Map getProfiles(String odaDataSourceId)
    throws OdaException
  {
    return getProfileIdentifiersByOdaProviderId(odaDataSourceId, null);
  }
  
  /**
   * @deprecated
   */
  public Map getProfiles(String odaDataSourceId, File storageFile)
    throws OdaException
  {
    return getProfileIdentifiersByOdaProviderId(odaDataSourceId, storageFile);
  }
  
  public Map getProfileIdentifiersByOdaProviderId(String odaDataSourceId, File storageFile)
    throws OdaException
  {
    return getProfileIdentifiersByCategoryOrProviderId(null, odaDataSourceId, storageFile, true);
  }
  
  public Map getProfileIdentifiersByCategory(String categoryId, File storageFile)
    throws OdaException
  {
    return getProfileIdentifiersByCategoryOrProviderId(categoryId, null, storageFile, true);
  }
  
  public Map<String, String> getProfileIdsAndNamesByCategory(String categoryId, File storageFile)
    throws OdaException
  {
    return getProfileIdentifiersByCategoryOrProviderId(categoryId, null, storageFile, false);
  }
  
  private Map getProfileIdentifiersByCategoryOrProviderId(String categoryId, String odaDataSourceId, File storageFile, boolean useDescriptionAsPropValue)
    throws OdaException
  {
    IConnectionProfile[] profilesInFile = loadProfiles(storageFile);
    
    Properties profileIds = new Properties();
    for (int i = 0; i < profilesInFile.length; i++)
    {
      IConnectionProfile aProfile = profilesInFile[i];
      if (categoryId != null)
      {
        if (!aProfile.getCategory().getId().equals(categoryId)) {
          continue;
        }
      }
      else
      {
        if (odaDataSourceId == null) {
          continue;
        }
        if (!aProfile.getProviderId().equals(odaDataSourceId)) {
          continue;
        }
      }
      addProfileIdentifier(aProfile, profileIds, useDescriptionAsPropValue);
    }
    return profileIds;
  }
  
  private IConnectionProfile[] loadProfiles(File storageFile)
    throws OdaException
  {
    return loadProfiles(storageFile, null);
  }
  
  private IConnectionProfile[] loadProfiles(File storageFile, String encryptedFileExtension)
    throws OdaException
  {
    if (storageFile == null)
    {
      getLogger().fine("A null storageFile argument is specified. Using default profile storage location instead.");
      storageFile = defaultProfileStoreFile();
      encryptedFileExtension = null;
      
      ProfileManager.getInstance().getProfiles(false);
    }
    IConnectionProfile[] profilesInFile = getLoadedProfiles(storageFile);
    if (profilesInFile != null) {
      return profilesInFile;
    }
    try
    {
      profilesInFile = ConnectionProfileMgmt.loadCPsUsingFileExtension(storageFile, encryptedFileExtension);
    }
    catch (Exception ex)
    {
      throw new OdaException(ex);
    }
    return addToCacheByFile(storageFile, profilesInFile);
  }
  
  private IConnectionProfile[] addToCacheByFile(File storageFile, IConnectionProfile[] profilesInFile)
  {
    Map<FileKey, IConnectionProfile[]> loadedProfilesMap = getLoadedProfilesMap();
    FileKey storageFileKey = new FileKey(storageFile);
    synchronized (loadedProfilesMap)
    {
      IConnectionProfile[] cachedProfiles = (IConnectionProfile[])loadedProfilesMap.get(storageFileKey);
      if (cachedProfiles == null)
      {
        cachedProfiles = profilesInFile;
        loadedProfilesMap.put(storageFileKey, cachedProfiles);
      }
    }
    IConnectionProfile[] cachedProfiles;
    return cachedProfiles;
  }
  
  private IConnectionProfile[] getLoadedProfiles(File storageFile)
  {
    return (IConnectionProfile[])getLoadedProfilesMap().get(new FileKey(storageFile));
  }
  
  class FileKey
    implements Comparable<FileKey>
  {
    private File m_file;
    
    FileKey(File aFile)
    {
      m_file = aFile;
    }
    
    public boolean equals(Object obj)
    {
      if (!(obj instanceof FileKey)) {
        return false;
      }
      return compareTo((FileKey)obj) == 0;
    }
    
    public int compareTo(FileKey obj)
    {
      if ((this == obj) || (m_file == obj.getFile())) {
        return 0;
      }
      return m_file.compareTo(obj.getFile());
    }
    
    private File getFile()
    {
      return m_file;
    }
  }
  
  private void addProfileIdentifier(IConnectionProfile profile, Properties profileIds, boolean useDescriptionAsPropValue)
  {
    assert ((profile != null) && (profileIds != null));
    
    String profileName = null;
    if (useDescriptionAsPropValue) {
      profileName = profile.getDescription();
    }
    if ((profileName == null) || (profileName.length() == 0)) {
      profileName = profile.getName();
    }
    profileIds.setProperty(profile.getInstanceID(), 
      profileName);
  }
  
  /**
   * @deprecated
   */
  public Properties getProfileProperties(String profileInstanceId)
  {
    IConnectionProfile profile = getProfile(profileInstanceId);
    return profile.getBaseProperties();
  }
  
  public Properties getProfileProperties(String profileInstanceId, File storageFile)
  {
    IConnectionProfile profile = null;
    try
    {
      profile = getProfileById(profileInstanceId, storageFile);
    }
    catch (OdaException ex)
    {
      throw new IllegalArgumentException(ex.toString());
    }
    if (profile == null) {
      throw new IllegalArgumentException(profileInstanceId);
    }
    return profile.getBaseProperties();
  }
  
  /**
   * @deprecated
   */
  public IConnectionProfile getProfile(String profileInstanceId)
  {
    IConnectionProfile profile = 
      ProfileManager.getInstance().getProfileByInstanceID(profileInstanceId);
    if (profile == null) {
      throw new IllegalArgumentException(profileInstanceId);
    }
    return createOdaWrapper(profile);
  }
  
  public IConnectionProfile getProfileById(String profileInstanceId, File storageFile)
    throws OdaException
  {
    IConnectionProfile[] profilesInFile = loadProfiles(storageFile);
    for (int i = 0; i < profilesInFile.length; i++) {
      if (profilesInFile[i].getInstanceID().equals(profileInstanceId)) {
        return createOdaWrapper(profilesInFile[i]);
      }
    }
    return null;
  }
  
  public IConnectionProfile getProfileByName(String profileName, File storageFile)
    throws OdaException
  {
    return getProfileByName(profileName, storageFile, null);
  }
  
  public IConnectionProfile getProfileByName(String profileName, File profileStoreFile, String encryptedFileExtension)
    throws OdaException
  {
    IConnectionProfile[] profilesInFile = loadProfiles(profileStoreFile, encryptedFileExtension);
    for (int i = 0; i < profilesInFile.length; i++) {
      if (matchesProfileName(profilesInFile[i].getName(), profileName)) {
        return createOdaWrapper(profilesInFile[i]);
      }
    }
    return null;
  }
  
  private boolean matchesProfileName(String profileName, String nameToMatch)
  {
    return profileName.equals(nameToMatch);
  }
  
  public IConnectionProfile getProfileByName(Properties dataSourceDesignProps, Object appContext)
  {
    Object connPropContext = ProviderUtil.getConnectionPropertyContext(appContext);
    if (connPropContext == null) {
      connPropContext = appContext;
    }
    ProfilePropertyProviderImpl profileProvider = new ProfilePropertyProviderImpl();
    profileProvider.setRefreshProfileStore(false);
    return createOdaWrapper(
      profileProvider.getConnectionProfile(dataSourceDesignProps, connPropContext));
  }
  
  private OdaConnectionProfile createOdaWrapper(IConnectionProfile wrappedProfile)
  {
    if (wrappedProfile == null) {
      return null;
    }
    if ((wrappedProfile instanceof OdaConnectionProfile)) {
      if (((OdaConnectionProfile)wrappedProfile).hasWrappedProfile()) {
        return (OdaConnectionProfile)wrappedProfile;
      }
    }
    return new OdaConnectionProfile(wrappedProfile);
  }
  
  public static boolean isProfileNameUsed(String profileName)
  {
    return OdaProfileFactory.isProfileNameUsed(profileName);
  }
  
  public IConnectionProfile createTransientProfile(String odaDataSourceId, Properties profileProperties)
    throws OdaException
  {
    String profileProviderId = odaDataSourceId;
    
    IConnectionProfile referencedProfile = getProfileByName(profileProperties, null);
    if ((referencedProfile instanceof OdaConnectionProfile)) {
      profileProviderId = ((OdaConnectionProfile)referencedProfile).getDirectProviderId();
    }
    return OdaProfileFactory.createTransientProfile(profileProviderId, profileProperties);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.profile.OdaProfileExplorer
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.profile;

import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.BundleContext;

public class OdaProfilePlugin
  extends Plugin
{
  public static final String PLUGIN_ID = "org.eclipse.datatools.connectivity.oda.profile";
  private static OdaProfilePlugin sm_plugin;
  
  public void start(BundleContext context)
    throws Exception
  {
    super.start(context);
    sm_plugin = this;
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    OdaProfileExplorer.releaseInstance();
    
    sm_plugin = null;
    super.stop(context);
  }
  
  public static OdaProfilePlugin getDefault()
  {
    return sm_plugin;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.profile.OdaProfilePlugin
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.profile;

import java.util.logging.Logger;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IContributor;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.datatools.connectivity.oda.profile.nls.Messages;

public class ProfileFileExtension
{
  public static final String FILE_EXT_SEPARATOR = ".";
  private static final String PROFILE_STORE_EXT_POINT = "org.eclipse.datatools.connectivity.oda.profile.profileStore";
  private static final String FILE_EXT_ELEMENT = "fileExtension";
  private static final String DEFAULT_ATTRIBUTE = "default";
  private static final String EMPTY_STRING = "";
  private static String sm_defaultFileExtension;
  private static final String sm_className = ProfileFileExtension.class.getName();
  
  public static String getDefault()
  {
    if (sm_defaultFileExtension == null) {
      synchronized (ProfileFileExtension.class)
      {
        if (sm_defaultFileExtension == null) {
          sm_defaultFileExtension = loadDefaultFileExtension();
        }
      }
    }
    return sm_defaultFileExtension;
  }
  
  public static boolean exists(String defaultFileExtension)
  {
    return (defaultFileExtension != null) && (defaultFileExtension.trim().length() > 0);
  }
  
  private static String loadDefaultFileExtension()
  {
    IExtensionRegistry extReg = Platform.getExtensionRegistry();
    IExtensionPoint extPoint = extReg.getExtensionPoint("org.eclipse.datatools.connectivity.oda.profile.profileStore");
    if (extPoint == null) {
      return "";
    }
    IExtension[] extensions = extPoint.getExtensions();
    if (extensions.length < 1) {
      return "";
    }
    if (extensions.length > 1)
    {
      String warningMsg = Messages.bind(Messages.profileFileExtension_MULTIPLE_EXTENSIONS_FOUND, 
        "org.eclipse.datatools.connectivity.oda.profile.profileStore");
      Logger.getLogger(sm_className).warning(warningMsg);
    }
    for (int i = 0; i < extensions.length; i++)
    {
      IConfigurationElement[] configElements = extensions[i].getConfigurationElements();
      if (configElements.length >= 1) {
        for (int j = 0; j < configElements.length; j++)
        {
          IConfigurationElement configElement = configElements[j];
          if (configElement.getName().equals("fileExtension"))
          {
            String defaultFileExt = configElement.getAttribute("default");
            if (defaultFileExt != null)
            {
              defaultFileExt = defaultFileExt.trim();
              if (defaultFileExt.startsWith(".")) {
                defaultFileExt = defaultFileExt.substring(".".length());
              }
              if (defaultFileExt.length() > 0)
              {
                Logger.getLogger(sm_className).info(
                  Messages.bind(Messages.profileFileExtension_APPLIED_DEFAULT_FILE_EXT, 
                  new Object[] { defaultFileExt, "org.eclipse.datatools.connectivity.oda.profile.profileStore", 
                  extensions[i].getContributor().getName() }));
                return defaultFileExt;
              }
            }
          }
        }
      }
    }
    return "";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.profile.ProfileFileExtension
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.profile.internal;

import java.util.Map;
import java.util.Properties;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.datatools.connectivity.ICategory;
import org.eclipse.datatools.connectivity.IConfigurationType;
import org.eclipse.datatools.connectivity.IConnectListener;
import org.eclipse.datatools.connectivity.IConnection;
import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.datatools.connectivity.IConnectionProfileProvider;
import org.eclipse.datatools.connectivity.IManagedConnection;
import org.eclipse.datatools.connectivity.IPropertySetListener;
import org.eclipse.datatools.connectivity.ProfileManager;
import org.eclipse.datatools.connectivity.internal.ConnectionProfile;
import org.eclipse.datatools.connectivity.internal.ConnectionProfile.DisconnectJob;

public class OdaConnectionProfile
  extends PlatformObject
  implements IConnectionProfile
{
  private IConnectionProfile m_wrappedProfile;
  private String m_odaWrapperExtensionId;
  private boolean m_hideWrapperId = false;
  private String m_directProviderId;
  
  public OdaConnectionProfile(IConnectionProfile wrappedProfile)
  {
    if (wrappedProfile == null) {
      throw new NullPointerException();
    }
    setWrappedProfile(wrappedProfile);
  }
  
  protected OdaConnectionProfile() {}
  
  protected void setWrappedProfile(IConnectionProfile wrappedProfile)
  {
    m_wrappedProfile = wrappedProfile;
  }
  
  public IConnectionProfile getWrappedProfile()
  {
    return m_wrappedProfile;
  }
  
  private IConnectionProfile getLeafWrappedProfile()
  {
    IConnectionProfile wrappedProfile = getWrappedProfile();
    while (((wrappedProfile instanceof OdaConnectionProfile)) && (
      ((OdaConnectionProfile)wrappedProfile).hasWrappedProfile())) {
      wrappedProfile = ((OdaConnectionProfile)wrappedProfile).getWrappedProfile();
    }
    return wrappedProfile;
  }
  
  public boolean hasWrappedProfile()
  {
    return m_wrappedProfile != null;
  }
  
  public boolean equals(IConnectionProfile aProfile)
  {
    if ((aProfile == null) || (!hasWrappedProfile())) {
      return false;
    }
    return getWrappedProfile().getInstanceID().equals(aProfile.getInstanceID());
  }
  
  public void setOdaWrapperExtensionId(String odaWrapperExtensionId)
  {
    if ((hasWrappedProfile()) && 
      (!getWrappedProfile().getProviderId().equals(odaWrapperExtensionId))) {
      m_odaWrapperExtensionId = odaWrapperExtensionId;
    } else {
      m_odaWrapperExtensionId = null;
    }
  }
  
  public void setDirectProviderId(String directProviderId)
  {
    m_directProviderId = directProviderId;
  }
  
  public void setHideWrapperId(boolean hide)
  {
    m_hideWrapperId = hide;
  }
  
  public String getProviderId()
  {
    if (m_hideWrapperId) {
      return getDirectProviderId();
    }
    return hasOdaWrapperProvider() ? 
      m_odaWrapperExtensionId : 
      getDirectProviderId();
  }
  
  public boolean hasOdaWrapperProvider()
  {
    return m_odaWrapperExtensionId != null;
  }
  
  public String getDirectProviderId()
  {
    if (m_directProviderId != null) {
      return m_directProviderId;
    }
    return hasWrappedProfile() ? getLeafWrappedProfile().getProviderId() : null;
  }
  
  public void close()
  {
    IConnectionProfile wrappedProfile = getLeafWrappedProfile();
    
    boolean isClosed = ProfileManager.getInstance().deleteTransientProfile(wrappedProfile);
    if (!isClosed) {
      disconnect(null);
    }
  }
  
  public void addConnectListener(IConnectListener listener)
  {
    m_wrappedProfile.addConnectListener(listener);
  }
  
  public void addPropertySetListener(IPropertySetListener listener)
  {
    m_wrappedProfile.addPropertySetListener(listener);
  }
  
  public boolean arePropertiesComplete()
  {
    if (hasWrappedProfile()) {
      return getWrappedProfile().arePropertiesComplete();
    }
    return false;
  }
  
  public boolean arePropertiesComplete(String type)
  {
    if (hasWrappedProfile()) {
      return getWrappedProfile().arePropertiesComplete(type);
    }
    return false;
  }
  
  public boolean canWorkOffline()
  {
    if (hasWrappedProfile()) {
      return getWrappedProfile().canWorkOffline();
    }
    return false;
  }
  
  public IStatus connectSynchronously()
  {
    waitForDisconnectingJobs(getLeafWrappedProfile());
    if (isConnected()) {
      return Status.OK_STATUS;
    }
    return connect();
  }
  
  public IStatus connect()
  {
    return m_wrappedProfile.connect();
  }
  
  public IStatus connectWithoutJob()
  {
    return m_wrappedProfile.connectWithoutJob();
  }
  
  public void connect(IJobChangeListener listener)
  {
    m_wrappedProfile.connect(listener);
  }
  
  private void waitForDisconnectingJobs(IConnectionProfile disconnectingProfile)
  {
    Job[] profileJobs = Job.getJobManager().find(disconnectingProfile);
    if (profileJobs.length == 0) {
      return;
    }
    for (int index = 0; index < profileJobs.length; index++) {
      if ((profileJobs[index] instanceof ConnectionProfile.DisconnectJob))
      {
        Job disconnectProfileJob = profileJobs[index];
        if (disconnectProfileJob.getState() != 0) {
          try
          {
            disconnectProfileJob.join();
          }
          catch (InterruptedException localInterruptedException) {}
        }
      }
    }
  }
  
  public IStatus disconnect()
  {
    return m_wrappedProfile.disconnect();
  }
  
  public void disconnect(IJobChangeListener listener)
  {
    m_wrappedProfile.disconnect(listener);
  }
  
  public IStatus saveWorkOfflineData()
  {
    return m_wrappedProfile.saveWorkOfflineData();
  }
  
  public void saveWorkOfflineData(IJobChangeListener listener)
  {
    m_wrappedProfile.saveWorkOfflineData(listener);
  }
  
  public IStatus workOffline()
  {
    return m_wrappedProfile.workOffline();
  }
  
  public void workOffline(IJobChangeListener listener)
  {
    m_wrappedProfile.workOffline(listener);
  }
  
  public IConnection createConnection(String factory)
  {
    return m_wrappedProfile.createConnection(factory);
  }
  
  public IConnection createConnection(String factoryId, String uid, String pwd)
  {
    return m_wrappedProfile.createConnection(factoryId, uid, pwd);
  }
  
  public Properties getBaseProperties()
  {
    return m_wrappedProfile.getBaseProperties();
  }
  
  public ICategory getCategory()
  {
    return m_wrappedProfile.getCategory();
  }
  
  public IConfigurationType getConfigurationType()
  {
    return m_wrappedProfile.getConfigurationType();
  }
  
  public int getConnectionState()
  {
    if (hasWrappedProfile()) {
      return getWrappedProfile().getConnectionState();
    }
    return 0;
  }
  
  public String getDescription()
  {
    return m_wrappedProfile.getDescription();
  }
  
  public String getInstanceID()
  {
    return m_wrappedProfile.getInstanceID();
  }
  
  public IManagedConnection getManagedConnection(String type)
  {
    return m_wrappedProfile.getManagedConnection(type);
  }
  
  public String getName()
  {
    return m_wrappedProfile.getName();
  }
  
  public IConnectionProfile getParentProfile()
  {
    return m_wrappedProfile.getParentProfile();
  }
  
  public Map getProfileExtensions()
  {
    return m_wrappedProfile.getProfileExtensions();
  }
  
  public Properties getProperties(String type)
  {
    return m_wrappedProfile.getProperties(type);
  }
  
  public IConnectionProfileProvider getProvider()
  {
    return m_wrappedProfile.getProvider();
  }
  
  public String getProviderName()
  {
    return m_wrappedProfile.getProviderName();
  }
  
  public boolean isAutoConnect()
  {
    if (hasWrappedProfile()) {
      return getWrappedProfile().isAutoConnect();
    }
    return false;
  }
  
  public boolean isConnected()
  {
    if (hasWrappedProfile()) {
      return getWrappedProfile().isConnected();
    }
    return false;
  }
  
  public void removeConnectListener(IConnectListener listener)
  {
    m_wrappedProfile.removeConnectListener(listener);
  }
  
  public void removePropertySetListener(IPropertySetListener listener)
  {
    m_wrappedProfile.removePropertySetListener(listener);
  }
  
  public void setBaseProperties(Properties props)
  {
    m_wrappedProfile.setBaseProperties(props);
  }
  
  public void setConnected(boolean connected)
  {
    if (hasWrappedProfile()) {
      getWrappedProfile().setConnected(connected);
    }
  }
  
  public void setProperties(String type, Properties props)
  {
    if ((ProfileManager.getInstance().isTransientProfile(m_wrappedProfile)) && 
      ((m_wrappedProfile instanceof ConnectionProfile))) {
      ((ConnectionProfile)m_wrappedProfile).internalSetProperties(type, props);
    } else {
      m_wrappedProfile.setProperties(type, props);
    }
  }
  
  public boolean supportsWorkOfflineMode()
  {
    if (hasWrappedProfile()) {
      return getWrappedProfile().supportsWorkOfflineMode();
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.profile.internal.OdaConnectionProfile
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.profile.internal;

import java.io.File;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.core.runtime.IPath;
import org.eclipse.datatools.connectivity.ConnectionProfileException;
import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.datatools.connectivity.ProfileManager;
import org.eclipse.datatools.connectivity.internal.ConnectionProfileMgmt;
import org.eclipse.datatools.connectivity.internal.InternalProfileManager;
import org.eclipse.datatools.connectivity.oda.OdaException;
import org.eclipse.datatools.connectivity.oda.util.manifest.ConnectionProfileProperty;

public class OdaProfileFactory
{
  private static final String NAME_SEPARATOR = " ";
  private static final String sm_className = OdaProfileFactory.class.getName();
  private static Logger sm_logger;
  
  public static IConnectionProfile createProfile(String name, String description, String odaDataSourceId, Properties profileProperties)
    throws OdaException
  {
    String uniqueName = getUniqueProfileName(name);
    
    String profileProviderId = profileProperties.getProperty("org.eclipse.datatools.connectivity.oda.profile.db.provider.id");
    if (profileProviderId != null) {
      odaDataSourceId = profileProviderId;
    }
    try
    {
      IConnectionProfile newProfile = 
        ProfileManager.getInstance().createProfile(uniqueName, description, 
        odaDataSourceId, profileProperties);
      return new OdaConnectionProfile(newProfile);
    }
    catch (ConnectionProfileException ex)
    {
      getLogger().logp(Level.WARNING, sm_className, "createProfile(String,String,String,Properties)", 
        "Unable to create a persistent profile instance.", ex);
      throw new OdaException(ex);
    }
  }
  
  public static IConnectionProfile createTransientProfile(Properties connProperties)
    throws OdaException
  {
    if (ConnectionProfileProperty.hasProfileName(connProperties))
    {
      getLogger().logp(Level.FINE, sm_className, "createTransientProfile(Properties)", 
        "The connection properties contain an external profile name reference; not expected to use for a transient profile.");
      
      return null;
    }
    String profileProviderId = connProperties != null ? 
      connProperties.getProperty("org.eclipse.datatools.connectivity.oda.profile.db.provider.id") : null;
    if ((profileProviderId == null) || (profileProviderId.length() == 0))
    {
      getLogger().logp(Level.FINE, sm_className, "createTransientProfile(Properties)", 
        "No profile provider id specified in the connection properties.");
      return null;
    }
    return createTransientProfile(profileProviderId, connProperties);
  }
  
  public static IConnectionProfile createTransientProfile(String odaDataSourceId, Properties profileProperties)
    throws OdaException
  {
    try
    {
      IConnectionProfile newProfile = 
        ProfileManager.getInstance().createTransientProfile(odaDataSourceId, profileProperties);
      return new OdaConnectionProfile(newProfile);
    }
    catch (ConnectionProfileException ex)
    {
      getLogger().logp(Level.WARNING, sm_className, "createTransientProfile(String,Properties)", 
        "Unable to create a transient profile instance.", ex);
      throw new OdaException(ex);
    }
  }
  
  public static boolean isProfileNameUsed(String profileName)
  {
    IConnectionProfile existingProfile = 
      InternalProfileManager.getInstance().getProfileByName(profileName, false);
    return existingProfile != null;
  }
  
  private static String getUniqueProfileName(String profileName)
  {
    if (!isProfileNameUsed(profileName)) {
      return profileName;
    }
    int nameCounter = 1;
    String newName = formatProfileName(profileName, nameCounter);
    while (isProfileNameUsed(newName)) {
      newName = formatProfileName(profileName, ++nameCounter);
    }
    return newName;
  }
  
  private static String formatProfileName(String profileName, int nameCounter)
  {
    return profileName + " " + nameCounter;
  }
  
  public static File defaultProfileStoreFile()
  {
    return 
      ConnectionProfileMgmt.getStorageLocation().append("ServerProfiles.dat").toFile();
  }
  
  private static Logger getLogger()
  {
    if (sm_logger == null) {
      synchronized (OdaProfileFactory.class)
      {
        if (sm_logger == null) {
          sm_logger = Logger.getLogger(sm_className);
        }
      }
    }
    return sm_logger;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.profile.internal.OdaProfileFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.profile.internal;

import org.eclipse.datatools.connectivity.ICategory;
import org.eclipse.datatools.connectivity.IConnectionProfileProvider;
import org.eclipse.datatools.connectivity.internal.ConnectionProfileManager;

public class ProfileCategoryUtil
{
  public static ICategory getCategory(String odaDataSourceId)
  {
    IConnectionProfileProvider profileProvider = 
      ConnectionProfileManager.getInstance().getProvider(odaDataSourceId);
    
    return profileProvider != null ? profileProvider.getCategory() : null;
  }
  
  public static boolean isUnknownCategory(ICategory profileCategory)
  {
    String categoryId = profileCategory != null ? 
      profileCategory.getId() : null;
    return isUnknownCategory(categoryId);
  }
  
  public static boolean isUnknownCategory(String categoryId)
  {
    return (categoryId == null) || (categoryId.equals("org.eclipse.datatools.connectivity.category.unknown"));
  }
  
  public static boolean hasODAParentCategory(ICategory profileCategory)
  {
    if ((profileCategory == null) || (profileCategory.getParent() == null)) {
      return false;
    }
    return 
      profileCategory.getParent().getId().equalsIgnoreCase("org.eclipse.datatools.connectivity.oda.profileCategory");
  }
}

/* Location:
 * Qualified Name:     org.eclipse.datatools.connectivity.oda.profile.internal.ProfileCategoryUtil
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.datatools.connectivity.oda.profile.nls;

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.datatools.connectivity.oda.profile.nls.messages";
  public static String constants_componentName;
  public static String profileFileExtension_APPLIED_DEFAULT_FILE_EXT;
  public static String profileFileExtension_MULTIPLE_EXTENSIONS_FOUND;
  public static String propertyProvider_CANNOT_FIND_PROFILE;
  public static String propertyProvid
1 2

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd