com-sun-tools-visualvm-core

16:33:46.384 INFO  jd.cli.Main - Decompiling com-sun-tools-visualvm-core.jar
package com.sun.tools.visualvm.core;

import com.sun.tools.visualvm.core.datasource.DataSourceRepository;
import com.sun.tools.visualvm.core.datasource.Storage;
import com.sun.tools.visualvm.core.datasupport.Utils;
import com.sun.tools.visualvm.core.snapshot.SnapshotsSupport;
import java.io.File;
import org.openide.modules.ModuleInstall;

public class Install
  extends ModuleInstall
{
  public void restored()
  {
    cleanupPreviousSession();
    
    DataSourceRepository.sharedInstance();
    
    SnapshotsSupport.getInstance();
  }
  
  private void cleanupPreviousSession()
  {
    File temporaryStorage = new File(Storage.getTemporaryStorageDirectoryString());
    Utils.delete(temporaryStorage, false);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.Install
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource;

final class DataSource$1
  extends DataSource
{}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.DataSource.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource;

import com.sun.tools.visualvm.core.datasupport.ComparableWeakReference;
import com.sun.tools.visualvm.core.datasupport.DataRemovedListener;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.openide.util.RequestProcessor;

public abstract class DataSource
{
  public static final String PROPERTY_VISIBLE = "prop_visible";
  public static final RequestProcessor EVENT_QUEUE = new RequestProcessor("DataSource Event Queue");
  public static final DataSource ROOT = new DataSource() {};
  private DataSource owner;
  private boolean isRemoved = false;
  private DataSource master;
  private boolean visible = true;
  private Storage storage;
  private DataSourceContainer repository;
  private PropertyChangeSupport changeSupport;
  private Set<ComparableWeakReference<DataRemovedListener>> removedListeners;
  
  public DataSource()
  {
    this(null);
  }
  
  public DataSource(DataSource master)
  {
    this.master = master;
  }
  
  public final DataSource getOwner()
  {
    return owner;
  }
  
  public final synchronized void setVisible(boolean newVisible)
  {
    if ((this == ROOT) && (!newVisible)) {
      throw new IllegalArgumentException("DataSourceRoot cannot be hidden");
    }
    boolean oldVisible = visible;
    visible = newVisible;
    getChangeSupport().firePropertyChange("prop_visible", oldVisible, newVisible);
  }
  
  public final boolean isVisible()
  {
    return visible;
  }
  
  public final DataSource getMaster()
  {
    return master;
  }
  
  public final synchronized Storage getStorage()
  {
    if (storage == null)
    {
      storage = createStorage();
      if (storage == null) {
        throw new NullPointerException("Storage cannot be null");
      }
    }
    return storage;
  }
  
  public final synchronized DataSourceContainer getRepository()
  {
    if (repository == null) {
      repository = new DataSourceContainer(this);
    }
    return repository;
  }
  
  public final void addPropertyChangeListener(PropertyChangeListener listener)
  {
    getChangeSupport().addPropertyChangeListener(listener);
  }
  
  public final void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
  {
    getChangeSupport().addPropertyChangeListener(propertyName, listener);
  }
  
  public final void removePropertyChangeListener(PropertyChangeListener listener)
  {
    getChangeSupport().removePropertyChangeListener(listener);
  }
  
  public final void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
  {
    getChangeSupport().removePropertyChangeListener(propertyName, listener);
  }
  
  public boolean supportsUserRemove()
  {
    return false;
  }
  
  public final void notifyWhenRemoved(DataRemovedListener listener)
  {
    if (listener == null) {
      throw new IllegalArgumentException("Listener cannot be null");
    }
    if (isRemoved()) {
      listener.dataRemoved(this);
    } else {
      getRemovedListeners().add(new ComparableWeakReference(listener));
    }
  }
  
  public final boolean isRemoved()
  {
    return isRemoved;
  }
  
  public boolean checkRemove(DataSource removeRoot)
  {
    return true;
  }
  
  protected void remove()
  {
    getStorage().deleteCustomPropertiesStorage();
  }
  
  final void addImpl(DataSource owner)
  {
    if (isRemoved) {
      throw new UnsupportedOperationException("DataSource can be added only once");
    }
    this.owner = owner;
  }
  
  final void removeImpl()
  {
    remove();
    
    owner = null;
    isRemoved = true;
    if (!hasRemovedListeners()) {
      return;
    }
    Set<ComparableWeakReference<DataRemovedListener>> listeners = getRemovedListeners();
    for (WeakReference<DataRemovedListener> listenerReference : listeners)
    {
      DataRemovedListener listener = (DataRemovedListener)listenerReference.get();
      if (listener != null) {
        listener.dataRemoved(this);
      }
    }
    listeners.clear();
  }
  
  protected Storage createStorage()
  {
    return new Storage();
  }
  
  protected final synchronized PropertyChangeSupport getChangeSupport()
  {
    if (changeSupport == null) {
      changeSupport = new PropertyChangeSupport(this);
    }
    return changeSupport;
  }
  
  final boolean hasRemovedListeners()
  {
    return removedListeners != null;
  }
  
  final synchronized Set<ComparableWeakReference<DataRemovedListener>> getRemovedListeners()
  {
    if (!hasRemovedListeners()) {
      removedListeners = Collections.synchronizedSet(new HashSet());
    }
    return removedListeners;
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.DataSource
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource;

import java.util.Iterator;
import java.util.Set;

public final class DataSourceContainer
  extends DataSourceProvider
{
  private final DataSource owner;
  
  DataSourceContainer(DataSource owner)
  {
    this.owner = owner;
  }
  
  public void addDataSource(DataSource added)
  {
    registerDataSource(added);
  }
  
  public void addDataSources(Set<? extends DataSource> added)
  {
    super.registerDataSources(added);
  }
  
  public void removeDataSource(DataSource removed)
  {
    unregisterDataSource(removed);
  }
  
  public void removeDataSources(Set<? extends DataSource> removed)
  {
    super.unregisterDataSources(removed);
  }
  
  public void updateDataSources(Set<? extends DataSource> added, Set<? extends DataSource> removed)
  {
    super.changeDataSources(added, removed);
  }
  
  protected void registerDataSourcesImpl(Set<? extends DataSource> added)
  {
    DataSource dataSource;
    for (Iterator i$ = added.iterator(); i$.hasNext(); dataSource.addImpl(owner)) {
      dataSource = (DataSource)i$.next();
    }
    super.registerDataSourcesImpl(added);
  }
  
  protected void unregisterDataSourcesImpl(Set<? extends DataSource> removed)
  {
    for (DataSource dataSource : removed)
    {
      DataSourceContainer dataSourceRepository = dataSource.getRepository();
      dataSourceRepository.unregisterDataSourcesImpl(dataSourceRepository.getDataSources());
      dataSource.removeImpl();
    }
    super.unregisterDataSourcesImpl(removed);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.DataSourceContainer
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource;

import com.sun.tools.visualvm.core.datasupport.DataChangeListener;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

class DataSourceProvider$1
  implements Runnable
{
  DataSourceProvider$1(DataSourceProvider paramDataSourceProvider, DataChangeListener paramDataChangeListener, Class paramClass) {}
  
  public void run()
  {
    if (DataSourceProvider.access$000(this$0).containsKey(val$listener))
    {
      String msg = "Listener " + val$listener + " already registered";
      DataSourceProvider.access$100().log(Level.SEVERE, msg, new UnsupportedOperationException(msg));
    }
    else
    {
      DataSourceProvider.access$000(this$0).put(val$listener, val$scope);
      DataSourceProvider.access$200(this$0, val$listener);
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.DataSourceProvider.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource;

import com.sun.tools.visualvm.core.datasupport.DataChangeListener;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

class DataSourceProvider$2
  implements Runnable
{
  DataSourceProvider$2(DataSourceProvider paramDataSourceProvider, DataChangeListener paramDataChangeListener) {}
  
  public void run()
  {
    if (!DataSourceProvider.access$000(this$0).containsKey(val$listener))
    {
      String msg = "Listener " + val$listener + " not registered";
      DataSourceProvider.access$100().log(Level.SEVERE, msg, new UnsupportedOperationException(msg));
    }
    else
    {
      DataSourceProvider.access$000(this$0).remove(val$listener);
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.DataSourceProvider.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource;

import java.util.Set;

class DataSourceProvider$3
  implements Runnable
{
  DataSourceProvider$3(DataSourceProvider paramDataSourceProvider, Set paramSet) {}
  
  public void run()
  {
    if (!val$added.isEmpty()) {
      this$0.registerDataSourcesImpl(DataSourceProvider.access$300(this$0, val$added));
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.DataSourceProvider.3
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource;

import java.util.Set;

class DataSourceProvider$4
  implements Runnable
{
  DataSourceProvider$4(DataSourceProvider paramDataSourceProvider, Set paramSet) {}
  
  public void run()
  {
    if (!val$removed.isEmpty()) {
      this$0.unregisterDataSourcesImpl(DataSourceProvider.access$400(this$0, val$removed));
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.DataSourceProvider.4
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource;

import java.util.Set;

class DataSourceProvider$5
  implements Runnable
{
  DataSourceProvider$5(DataSourceProvider paramDataSourceProvider, Set paramSet1, Set paramSet2) {}
  
  public void run()
  {
    if (!val$removed.isEmpty()) {
      this$0.unregisterDataSourcesImpl(DataSourceProvider.access$400(this$0, val$removed));
    }
    if (!val$added.isEmpty()) {
      this$0.registerDataSourcesImpl(DataSourceProvider.access$300(this$0, val$added));
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.DataSourceProvider.5
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource;

import com.sun.tools.visualvm.core.datasupport.DataChangeEvent;
import com.sun.tools.visualvm.core.datasupport.DataChangeListener;
import com.sun.tools.visualvm.core.datasupport.Utils;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.openide.util.RequestProcessor;

public class DataSourceProvider
{
  private static final boolean SUPPRESS_EXCEPTIONS_UI = Boolean.getBoolean(DataSourceProvider.class.getName() + ".suppressExceptionsUI");
  private static final Logger LOGGER = Logger.getLogger(DataSourceProvider.class.getName());
  private final Set<DataSource> dataSources = Collections.synchronizedSet(new HashSet());
  private final Map<DataChangeListener<? extends DataSource>, Class<? extends DataSource>> listeners = new HashMap();
  
  public final <Y extends DataSource> void addDataChangeListener(final DataChangeListener<Y> listener, final Class<Y> scope)
  {
    DataSource.EVENT_QUEUE.post(new Runnable()
    {
      public void run()
      {
        if (listeners.containsKey(listener))
        {
          String msg = "Listener " + listener + " already registered";
          DataSourceProvider.LOGGER.log(Level.SEVERE, msg, new UnsupportedOperationException(msg));
        }
        else
        {
          listeners.put(listener, scope);
          DataSourceProvider.this.fireCurrentState(listener);
        }
      }
    });
  }
  
  public final <Y extends DataSource> void removeDataChangeListener(final DataChangeListener<Y> listener)
  {
    DataSource.EVENT_QUEUE.post(new Runnable()
    {
      public void run()
      {
        if (!listeners.containsKey(listener))
        {
          String msg = "Listener " + listener + " not registered";
          DataSourceProvider.LOGGER.log(Level.SEVERE, msg, new UnsupportedOperationException(msg));
        }
        else
        {
          listeners.remove(listener);
        }
      }
    });
  }
  
  public final Set<DataSource> getDataSources()
  {
    return new HashSet(Arrays.asList(dataSources.toArray()));
  }
  
  public final <Y extends DataSource> Set<Y> getDataSources(Class<Y> scope)
  {
    return Utils.getFilteredSet(getDataSources(), scope);
  }
  
  protected final void registerDataSource(DataSource added)
  {
    registerDataSources(Collections.singleton(added));
  }
  
  protected final void registerDataSources(final Set<? extends DataSource> added)
  {
    DataSource.EVENT_QUEUE.post(new Runnable()
    {
      public void run()
      {
        if (!added.isEmpty()) {
          registerDataSourcesImpl(DataSourceProvider.this.checkAdded(added));
        }
      }
    });
  }
  
  protected final void unregisterDataSource(DataSource removed)
  {
    unregisterDataSources(Collections.singleton(removed));
  }
  
  protected final void unregisterDataSources(final Set<? extends DataSource> removed)
  {
    DataSource.EVENT_QUEUE.post(new Runnable()
    {
      public void run()
      {
        if (!removed.isEmpty()) {
          unregisterDataSourcesImpl(DataSourceProvider.this.checkRemoved(removed));
        }
      }
    });
  }
  
  protected final void changeDataSources(final Set<? extends DataSource> added, final Set<? extends DataSource> removed)
  {
    DataSource.EVENT_QUEUE.post(new Runnable()
    {
      public void run()
      {
        if (!removed.isEmpty()) {
          unregisterDataSourcesImpl(DataSourceProvider.this.checkRemoved(removed));
        }
        if (!added.isEmpty()) {
          registerDataSourcesImpl(DataSourceProvider.this.checkAdded(added));
        }
      }
    });
  }
  
  void registerDataSourcesImpl(Set<? extends DataSource> added)
  {
    dataSources.addAll(added);
    fireDataAdded(added);
  }
  
  void unregisterDataSourcesImpl(Set<? extends DataSource> removed)
  {
    dataSources.removeAll(removed);
    fireDataRemoved(removed);
  }
  
  private Set<? extends DataSource> checkAdded(Set<? extends DataSource> added)
  {
    Set<? extends DataSource> uniqueAdded = new HashSet(added);
    Iterator<? extends DataSource> it = uniqueAdded.iterator();
    while (it.hasNext())
    {
      DataSource ds = (DataSource)it.next();
      if (dataSources.contains(ds))
      {
        it.remove();
        logUnsupportedOperation("DataSource already in repository: " + ds);
      }
    }
    return uniqueAdded;
  }
  
  private Set<? extends DataSource> checkRemoved(Set<? extends DataSource> removed)
  {
    Set<? extends DataSource> uniqueRemoved = new HashSet(removed);
    Iterator<? extends DataSource> it = uniqueRemoved.iterator();
    while (it.hasNext())
    {
      DataSource ds = (DataSource)it.next();
      if (!dataSources.contains(ds))
      {
        it.remove();
        logUnsupportedOperation("DataSource not in repository: " + ds);
      }
    }
    return uniqueRemoved;
  }
  
  private static void logUnsupportedOperation(String msg)
  {
    if (SUPPRESS_EXCEPTIONS_UI) {
      LOGGER.severe(msg);
    } else {
      LOGGER.log(Level.SEVERE, msg, new UnsupportedOperationException(msg));
    }
  }
  
  private void fireCurrentState(DataChangeListener<? extends DataSource> listener)
  {
    fireDataChanged(listener, null, null);
  }
  
  private void fireDataAdded(Set<? extends DataSource> added)
  {
    fireDataChanged(added, Collections.EMPTY_SET);
  }
  
  private void fireDataRemoved(Set<? extends DataSource> removed)
  {
    fireDataChanged(Collections.EMPTY_SET, removed);
  }
  
  private void fireDataChanged(Set<? extends DataSource> added, Set<? extends DataSource> removed)
  {
    Set<DataChangeListener<? extends DataSource>> listenersSet = listeners.keySet();
    DataChangeListener listener;
    for (Iterator i$ = listenersSet.iterator(); i$.hasNext(); fireDataChanged(listener, added, removed)) {
      listener = (DataChangeListener)i$.next();
    }
  }
  
  private void fireDataChanged(DataChangeListener<? extends DataSource> listener, Set<? extends DataSource> added, Set<? extends DataSource> removed)
  {
    Class<? extends DataSource> filter = (Class)listeners.get(listener);
    Set<? extends DataSource> filteredCurrent = Utils.getFilteredSet(dataSources, filter);
    if ((added == null) && (removed == null))
    {
      DataChangeEvent event = new DataChangeEvent(filteredCurrent, filteredCurrent, null);
      listener.dataChanged(event);
    }
    else
    {
      Set<? extends DataSource> filteredAdded = added != null ? Utils.getFilteredSet(added, filter) : Collections.EMPTY_SET;
      Set<? extends DataSource> filteredRemoved = removed != null ? Utils.getFilteredSet(removed, filter) : Collections.EMPTY_SET;
      if ((!filteredAdded.isEmpty()) || (!filteredRemoved.isEmpty()))
      {
        DataChangeEvent event = new DataChangeEvent(filteredCurrent, filteredAdded, filteredRemoved);
        listener.dataChanged(event);
      }
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.DataSourceProvider
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource;

class DataSourceRepository$1 {}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.DataSourceRepository.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource;

import com.sun.tools.visualvm.core.datasupport.DataChangeEvent;
import com.sun.tools.visualvm.core.datasupport.DataChangeListener;
import java.util.Set;

class DataSourceRepository$Listener
  implements DataChangeListener<DataSource>
{
  private DataSourceRepository$Listener(DataSourceRepository paramDataSourceRepository) {}
  
  public void dataChanged(DataChangeEvent<DataSource> event)
  {
    Set<DataSource> added = event.getAdded();
    Set<DataSource> removed = event.getRemoved();
    if ((!added.isEmpty()) || (!removed.isEmpty())) {
      this$0.changeDataSources(added, removed);
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.DataSourceRepository.Listener
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource;

import com.sun.tools.visualvm.core.datasupport.DataChangeEvent;
import com.sun.tools.visualvm.core.datasupport.DataChangeListener;
import java.util.Iterator;
import java.util.Set;

public final class DataSourceRepository
  extends DataSourceProvider
{
  private static DataSourceRepository sharedInstance;
  private final Listener dataChangeListener = new Listener(null);
  
  public static synchronized DataSourceRepository sharedInstance()
  {
    if (sharedInstance == null) {
      sharedInstance = new DataSourceRepository();
    }
    return sharedInstance;
  }
  
  void registerDataSourcesImpl(Set<? extends DataSource> added)
  {
    super.registerDataSourcesImpl(added);
    DataSource dataSource;
    for (Iterator i$ = added.iterator(); i$.hasNext(); dataSource.getRepository().addDataChangeListener(dataChangeListener, DataSource.class)) {
      dataSource = (DataSource)i$.next();
    }
  }
  
  void unregisterDataSourcesImpl(Set<? extends DataSource> removed)
  {
    super.unregisterDataSourcesImpl(removed);
    DataSource dataSource;
    for (Iterator i$ = removed.iterator(); i$.hasNext(); dataSource.getRepository().removeDataChangeListener(dataChangeListener)) {
      dataSource = (DataSource)i$.next();
    }
  }
  
  private DataSourceRepository()
  {
    registerDataSource(DataSource.ROOT);
  }
  
  private class Listener
    implements DataChangeListener<DataSource>
  {
    private Listener() {}
    
    public void dataChanged(DataChangeEvent<DataSource> event)
    {
      Set<DataSource> added = event.getAdded();
      Set<DataSource> removed = event.getRemoved();
      if ((!added.isEmpty()) || (!removed.isEmpty())) {
        changeDataSources(added, removed);
      }
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.DataSourceRepository
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource;

import com.sun.tools.visualvm.core.datasupport.Utils;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

public final class Storage
{
  private static final String VISUALVM_TMP_DIR = System.getProperty("visualvm.tmpdir");
  private static final String TEMPORARY_STORAGE_DIRNAME = "visualvm.dat";
  private static final String PERSISTENT_STORAGE_DIRNAME = "repository";
  private static final Logger LOGGER = Logger.getLogger(Storage.class.getName());
  public static final String DEFAULT_PROPERTIES_EXT = ".properties";
  private static final Object temporaryStorageDirectoryLock = new Object();
  private static File temporaryStorageDirectory;
  private static final Object temporaryStorageDirectoryStringLock = new Object();
  private static String temporaryStorageDirectoryString;
  private static final Object persistentStorageDirectoryLock = new Object();
  private static File persistentStorageDirectory;
  private static final Object persistentStorageDirectoryStringLock = new Object();
  private static String persistentStorageDirectoryString;
  private final File directory;
  private final File propertiesFile;
  private Properties properties;
  
  public Storage()
  {
    this(new File(getTemporaryStorageDirectoryString()));
  }
  
  public Storage(File directory)
  {
    this(directory, null);
  }
  
  public Storage(File directory, String propertiesFile)
  {
    if (directory == null) {
      throw new NullPointerException("Directory cannot be null");
    }
    if (directory.isFile()) {
      throw new IllegalArgumentException("Not a valid directory: " + directory);
    }
    this.directory = directory;
    this.propertiesFile = (propertiesFile != null ? new File(directory, propertiesFile) : null);
  }
  
  public synchronized boolean directoryExists()
  {
    return directory.exists();
  }
  
  public synchronized File getDirectory()
  {
    if (!Utils.prepareDirectory(directory)) {
      throw new IllegalStateException("Cannot create storage directory " + directory);
    }
    return directory;
  }
  
  public String getCustomProperty(String key)
  {
    return getCustomProperties(new String[] { key })[0];
  }
  
  public synchronized String[] getCustomProperties(String[] keys)
  {
    String[] values = new String[keys.length];
    Properties prop = getCustomProperties(false);
    if (prop != null) {
      for (int i = 0; i < keys.length; i++) {
        values[i] = prop.getProperty(keys[i]);
      }
    }
    return values;
  }
  
  public void setCustomProperty(String key, String value)
  {
    setCustomProperties(new String[] { key }, new String[] { value });
  }
  
  public synchronized void setCustomProperties(String[] keys, String[] values)
  {
    Properties prop = getCustomProperties(true);
    for (int i = 0; i < keys.length; i++) {
      if (values[i] != null) {
        prop.put(keys[i], values[i]);
      } else {
        prop.remove(keys[i]);
      }
    }
    storeCustomProperties();
  }
  
  public void clearCustomProperty(String key)
  {
    clearCustomProperties(new String[] { key });
  }
  
  public synchronized void clearCustomProperties(String[] keys)
  {
    Properties prop = getCustomProperties(false);
    if (prop != null) {
      for (int i = 0; i < keys.length; i++) {
        prop.remove(keys[i]);
      }
    }
    storeCustomProperties();
  }
  
  public synchronized boolean hasCustomProperties()
  {
    Properties prop = getCustomProperties(false);
    return (prop != null) && (!prop.isEmpty());
  }
  
  public synchronized void saveCustomPropertiesTo(File file)
  {
    if (file == null) {
      throw new NullPointerException("File cannot be null");
    }
    if (file.isDirectory()) {
      throw new IllegalArgumentException("Not a valid file: " + file);
    }
    Properties prop = getCustomProperties(false);
    if ((prop != null) && (!prop.isEmpty())) {
      storeProperties(prop, file);
    }
  }
  
  public synchronized void deleteCustomPropertiesStorage()
  {
    if ((propertiesFile != null) && (propertiesFile.exists()) && 
      (!propertiesFile.delete())) {
      propertiesFile.deleteOnExit();
    }
  }
  
  public static String getTemporaryStorageDirectoryString()
  {
    synchronized (temporaryStorageDirectoryStringLock)
    {
      if (temporaryStorageDirectoryString == null)
      {
        String tmpDir = VISUALVM_TMP_DIR != null ? VISUALVM_TMP_DIR : System.getProperty("java.io.tmpdir");
        
        temporaryStorageDirectoryString = new File(tmpDir).getAbsolutePath() + File.separator + "visualvm.dat";
      }
      return temporaryStorageDirectoryString;
    }
  }
  
  public static File getTemporaryStorageDirectory()
  {
    synchronized (temporaryStorageDirectoryLock)
    {
      if (temporaryStorageDirectory == null)
      {
        String temporaryStorageString = getTemporaryStorageDirectoryString();
        temporaryStorageDirectory = new File(temporaryStorageString);
        if ((temporaryStorageDirectory.exists()) && (temporaryStorageDirectory.isFile())) {
          throw new IllegalStateException("Cannot create temporary storage directory " + temporaryStorageString + ", file in the way");
        }
        if ((temporaryStorageDirectory.exists()) && ((!temporaryStorageDirectory.canRead()) || (!temporaryStorageDirectory.canWrite()))) {
          throw new IllegalStateException("Cannot access temporary storage directory " + temporaryStorageString + ", read&write permission required");
        }
        if (!Utils.prepareDirectory(temporaryStorageDirectory)) {
          throw new IllegalStateException("Cannot create temporary storage directory " + temporaryStorageString);
        }
      }
      return temporaryStorageDirectory;
    }
  }
  
  public static String getPersistentStorageDirectoryString()
  {
    synchronized (persistentStorageDirectoryStringLock)
    {
      if (persistentStorageDirectoryString == null) {
        persistentStorageDirectoryString = new File(System.getProperty("netbeans.user")).getAbsolutePath() + File.separator + "repository";
      }
      return persistentStorageDirectoryString;
    }
  }
  
  public static File getPersistentStorageDirectory()
  {
    synchronized (persistentStorageDirectoryLock)
    {
      if (persistentStorageDirectory == null)
      {
        String persistentStorageString = getPersistentStorageDirectoryString();
        persistentStorageDirectory = new File(persistentStorageString);
        if ((persistentStorageDirectory.exists()) && (persistentStorageDirectory.isFile())) {
          throw new IllegalStateException("Cannot create persistent storage directory " + persistentStorageString + ", file in the way");
        }
        if ((persistentStorageDirectory.exists()) && ((!persistentStorageDirectory.canRead()) || (!persistentStorageDirectory.canWrite()))) {
          throw new IllegalStateException("Cannot access persistent storage directory " + persistentStorageString + ", read&write permission required");
        }
        if (!Utils.prepareDirectory(persistentStorageDirectory)) {
          throw new IllegalStateException("Cannot create persistent storage directory " + persistentStorageString);
        }
      }
      return persistentStorageDirectory;
    }
  }
  
  public static boolean persistentStorageDirectoryExists()
  {
    return new File(getPersistentStorageDirectoryString()).isDirectory();
  }
  
  private void storeCustomProperties()
  {
    if ((properties != null) && (propertiesFile != null)) {
      storeProperties(properties, propertiesFile);
    }
  }
  
  private Properties getCustomProperties(boolean createEmpty)
  {
    if ((properties == null) && (propertiesFile != null)) {
      properties = loadProperties(propertiesFile);
    }
    if ((properties == null) && (createEmpty)) {
      properties = new Properties();
    }
    return properties;
  }
  
  private static Properties loadProperties(File file)
  {
    if ((!file.exists()) || (!file.isFile())) {
      return null;
    }
    InputStream is = null;
    BufferedInputStream bis = null;
    try
    {
      is = new FileInputStream(file);
      bis = new BufferedInputStream(is);
      Properties properties = new Properties();
      properties.loadFromXML(bis);
      return properties;
    }
    catch (Exception e)
    {
      Properties localProperties1;
      LOGGER.log(Level.SEVERE, "Error loading properties", e);
      return null;
    }
    finally
    {
      try
      {
        if (bis != null) {
          bis.close();
        }
        if (is != null) {
          is.close();
        }
      }
      catch (Exception e)
      {
        LOGGER.log(Level.SEVERE, "Problem closing input stream", e);
      }
    }
  }
  
  private static void storeProperties(Properties properties, File file)
  {
    Utils.prepareDirectory(file.getParentFile());
    
    OutputStream os = null;
    BufferedOutputStream bos = null;
    try
    {
      os = new FileOutputStream(file);
      bos = new BufferedOutputStream(os);
      properties.storeToXML(os, null); return;
    }
    catch (Exception e)
    {
      LOGGER.log(Level.SEVERE, "Error storing properties", e);
    }
    finally
    {
      try
      {
        if (bos != null) {
          bos.close();
        }
        if (os != null) {
          os.close();
        }
      }
      catch (Exception e)
      {
        LOGGER.log(Level.SEVERE, "Problem closing output stream", e);
      }
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.Storage
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource.descriptor;

import com.sun.tools.visualvm.core.datasource.DataSource;
import com.sun.tools.visualvm.core.datasource.Storage;
import com.sun.tools.visualvm.core.datasupport.Positionable;
import com.sun.tools.visualvm.core.model.Model;
import java.awt.Image;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Comparator;

public abstract class DataSourceDescriptor<X extends DataSource>
  extends Model
  implements Positionable
{
  public static final String PROPERTY_ICON = "prop_icon";
  public static final String PROPERTY_NAME = "prop_name";
  public static final String PROPERTY_DESCRIPTION = "prop_description";
  public static final String PROPERTY_PREFERRED_POSITION = "prop_preferred_position";
  public static final String PROPERTY_CHILDREN_COMPARATOR = "prop_children_comparator";
  public static final String PROPERTY_EXPANSION_POLICY = "prop_expansion_policy";
  public static final int EXPAND_NEVER = 0;
  public static final int EXPAND_ON_FIRST_CHILD = 1;
  public static final int EXPAND_ON_EACH_FIRST_CHILD = 2;
  public static final int EXPAND_ON_EACH_NEW_CHILD = 3;
  public static final int EXPAND_ON_EACH_CHILD_CHANGE = 4;
  private X dataSource;
  private Image icon;
  private String name;
  private String description;
  private int preferredPosition;
  private Comparator<DataSource> childrenComparator;
  private int autoExpansionPolicy;
  private final PropertyChangeSupport changeSupport;
  
  public DataSourceDescriptor(X dataSource)
  {
    this(dataSource, dataSource != null ? dataSource.toString() : null, null, null, 2147483646, 1);
  }
  
  public DataSourceDescriptor(X ds, String n, String desc, Image ic, int pos, int aep)
  {
    if (ds == null) {
      throw new NullPointerException("DataSource cannot be null");
    }
    dataSource = ds;
    changeSupport = new PropertyChangeSupport(dataSource);
    name = n;
    description = desc;
    icon = ic;
    preferredPosition = pos;
    autoExpansionPolicy = aep;
  }
  
  public Image getIcon()
  {
    return icon;
  }
  
  public boolean supportsRename()
  {
    return false;
  }
  
  public void setName(String newName)
  {
    if (!supportsRename()) {
      throw new UnsupportedOperationException("Rename not supported for this descriptor");
    }
    if (newName == null) {
      throw new IllegalArgumentException("Name cannot be null");
    }
    String oldName = name;
    name = newName;
    getDataSource().getStorage().setCustomProperties(new String[] { "prop_name" }, new String[] { newName });
    getChangeSupport().firePropertyChange("prop_name", oldName, newName);
  }
  
  public String getName()
  {
    return name;
  }
  
  public String getDescription()
  {
    return description;
  }
  
  public int getPreferredPosition()
  {
    return preferredPosition;
  }
  
  public Comparator<DataSource> getChildrenComparator()
  {
    return childrenComparator;
  }
  
  public int getAutoExpansionPolicy()
  {
    return autoExpansionPolicy;
  }
  
  public boolean providesProperties()
  {
    return false;
  }
  
  public final void addPropertyChangeListener(PropertyChangeListener listener)
  {
    getChangeSupport().addPropertyChangeListener(listener);
  }
  
  public final void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
  {
    getChangeSupport().addPropertyChangeListener(propertyName, listener);
  }
  
  public final void removePropertyChangeListener(PropertyChangeListener listener)
  {
    getChangeSupport().removePropertyChangeListener(listener);
  }
  
  public final void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
  {
    getChangeSupport().removePropertyChangeListener(propertyName, listener);
  }
  
  protected final X getDataSource()
  {
    return dataSource;
  }
  
  protected void setDescription(String newDescription)
  {
    if ((description == null) && (newDescription == null)) {
      return;
    }
    String oldDescription = description;
    description = newDescription;
    getChangeSupport().firePropertyChange("prop_description", oldDescription, newDescription);
  }
  
  protected void setIcon(Image newIcon)
  {
    if ((icon == null) && (newIcon == null)) {
      return;
    }
    Image oldIcon = icon;
    icon = newIcon;
    getChangeSupport().firePropertyChange("prop_icon", oldIcon, newIcon);
  }
  
  protected void setPreferredPosition(int newPosition)
  {
    int oldPosition = preferredPosition;
    preferredPosition = newPosition;
    getChangeSupport().firePropertyChange("prop_preferred_position", oldPosition, newPosition);
  }
  
  protected void setChildrenComparator(Comparator<DataSource> newComparator)
  {
    Comparator<DataSource> oldComparator = childrenComparator;
    childrenComparator = newComparator;
    getChangeSupport().firePropertyChange("prop_children_comparator", oldComparator, newComparator);
  }
  
  protected void getAutoExpansionPolicy(int newPolicy)
  {
    int oldPolicy = autoExpansionPolicy;
    autoExpansionPolicy = newPolicy;
    getChangeSupport().firePropertyChange("prop_expansion_policy", oldPolicy, newPolicy);
  }
  
  protected final PropertyChangeSupport getChangeSupport()
  {
    return changeSupport;
  }
  
  protected static String resolveName(DataSource dataSource, String name)
  {
    String persistedName = dataSource.getStorage().getCustomProperty("prop_name");
    if (persistedName != null) {
      return persistedName;
    }
    return name;
  }
  
  protected static int resolvePosition(DataSource dataSource, int position, boolean savePosition)
  {
    Storage storage = dataSource.getStorage();
    String positionS = storage.getCustomProperty("prop_preferred_position");
    if (positionS != null) {
      try
      {
        position = Integer.parseInt(positionS);
      }
      catch (NumberFormatException e)
      {
        if (savePosition) {
          storage.setCustomProperty("prop_preferred_position", Integer.toString(position));
        }
      }
    } else if (savePosition) {
      storage.setCustomProperty("prop_preferred_position", Integer.toString(position));
    }
    return position;
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource.descriptor;

import com.sun.tools.visualvm.core.datasource.DataSource;

class DataSourceDescriptorFactory$DefaultDataSourceDescriptor
  extends DataSourceDescriptor
{
  DataSourceDescriptorFactory$DefaultDataSourceDescriptor(DataSource ds)
  {
    super(ds);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptorFactory.DefaultDataSourceDescriptor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource.descriptor;

import com.sun.tools.visualvm.core.datasource.DataSource;
import com.sun.tools.visualvm.core.model.ModelFactory;
import com.sun.tools.visualvm.core.model.ModelProvider;
import com.sun.tools.visualvm.core.properties.PropertiesSupport;

public final class DataSourceDescriptorFactory
  extends ModelFactory<DataSourceDescriptor, DataSource>
  implements ModelProvider<DataSourceDescriptor, DataSource>
{
  private static DataSourceDescriptorFactory dsDescFactory;
  
  public static synchronized DataSourceDescriptorFactory getDefault()
  {
    if (dsDescFactory == null)
    {
      dsDescFactory = new DataSourceDescriptorFactory();
      dsDescFactory.registerProvider(dsDescFactory);
      
      PropertiesSupport.sharedInstance().registerPropertiesProvider(new GeneralPropertiesProvider(), DataSource.class);
    }
    return dsDescFactory;
  }
  
  public static DataSourceDescriptor getDescriptor(DataSource ds)
  {
    return (DataSourceDescriptor)getDefault().getModel(ds);
  }
  
  public DataSourceDescriptor createModelFor(DataSource ds)
  {
    return new DefaultDataSourceDescriptor(ds);
  }
  
  private static class DefaultDataSourceDescriptor
    extends DataSourceDescriptor
  {
    DefaultDataSourceDescriptor(DataSource ds)
    {
      super();
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptorFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.core.datasource.descriptor;

import java.awt.Dimension;
import javax.swing.JTextArea;

class GeneralProperties
1 2 3 4 5 6 7 8 9 10 11 12 13

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-2019. Infinite Loop Ltd