Package jmri.profile

Class Profile

java.lang.Object
jmri.profile.Profile
All Implemented Interfaces:
Comparable<Profile>
Direct Known Subclasses:
NullProfile

public class Profile extends Object implements Comparable<Profile>
A JMRI application profile. Profiles allow a JMRI application to load completely separate set of preferences at each launch without relying on host OS-specific tricks to ensure this happens. It is recommended that profile directory names end in ".jmri" so that supporting iOS and macOS applications could potentially treat a JMRI profile as a single file, instead of as a directory structure. This would allow an application subject to mandatory security controls in iOS, and an application sandbox on macOS to request permission from the user to access the entire profile once, instead of needing to request permission to access each file individually. This would also allow a profile to be opened by double clicking on it, and to have a unique icon within the iOS Files app and macOS Finder. Note that JMRI itself is not currently capable of supporting opening a profile by double clicking on it, even if other applications on the same computer can.
  • Field Details

  • Constructor Details

    • Profile

      public Profile(@Nonnull File path) throws IOException
      Create a Profile object given just a path to it. The Profile must exist in storage on the computer.
      Parameters:
      path - The Profile's directory
      Throws:
      IOException - If unable to read the Profile from path
    • Profile

      public Profile(@Nonnull String name, @Nonnull String id, @Nonnull File path) throws IOException
      Create a Profile object and a profile in storage. A Profile cannot exist in storage on the computer at the path given. Since this is a new profile, the id must match the last element in the path.

      This is the only time the id can be set on a Profile, as the id becomes a read-only property of the Profile. The ProfileManager will only load a single profile with a given id.

      Parameters:
      name - Name of the profile. Will not be used to enforce uniqueness constraints.
      id - Id of the profile. Will be prepended to a random String to enforce uniqueness constraints.
      path - Location to store the profile; ".jmri" will be appended to this path if needed.
      Throws:
      IOException - If unable to create the profile at path
      IllegalArgumentException - If a profile already exists at or within path
    • Profile

      protected Profile(@Nonnull File path, boolean isReadable) throws IOException
      Create a Profile object given just a path to it. If isReadable is true, the Profile must exist in storage on the computer. Generates a random id for the profile.

      This method exists purely to support subclasses.

      Parameters:
      path - The Profile's directory
      isReadable - True if the profile has storage. See NullProfile for a Profile subclass where this is not true.
      Throws:
      IOException - If the profile's preferences cannot be read.
    • Profile

      protected Profile(@Nonnull File path, @Nonnull String id, boolean isReadable) throws IOException
      Create a Profile object given just a path to it. If isReadable is true, the Profile must exist in storage on the computer.

      This method exists purely to support subclasses.

      Parameters:
      path - The Profile's directory
      id - The Profile's id
      isReadable - True if the profile has storage. See NullProfile for a Profile subclass where this is not true.
      Throws:
      IOException - If the profile's preferences cannot be read.
  • Method Details

    • save

      protected final void save()
    • getName

      public String getName()
      Returns:
      the name
    • setName

      public void setName(String name)
      Set the name for this profile.

      Overriding classing must use setNameInConstructor(java.lang.String) to set the name in a constructor since this method passes this Profile object to an object excepting a completely constructed Profile.

      Parameters:
      name - the new name
    • setNameInConstructor

      protected final void setNameInConstructor(String name)
      Set the name for this profile while constructing the profile.

      Overriding classing must use this method to set the name in a constructor since setName(java.lang.String) passes this Profile object to an object expecting a completely constructed Profile.

      Parameters:
      name - the new name
    • getId

      @Nonnull public String getId()
      Returns:
      the id
    • getPath

      public File getPath()
      Returns:
      the path
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      This tests for equal ID values
      Overrides:
      equals in class Object
    • isComplete

      public boolean isComplete()
      Test if the profile is complete. A profile is considered complete if it can be instantiated using Profile(java.io.File) and has a profile.properties file within its "profile" directory.
      Returns:
      true if profile.properties exists where expected.
    • getUniqueId

      public String getUniqueId()
      Return the uniqueness portion of the Profile Id.

      This portion of the Id is automatically generated when the profile is created.

      Returns:
      An eight-character String of alphanumeric characters.
    • containsProfile

      public static boolean containsProfile(File path)
      Test if the given path or subdirectories contains a Profile.
      Parameters:
      path - Path to test.
      Returns:
      true if path or subdirectories contains a Profile.
      Since:
      3.9.4
    • inProfile

      public static boolean inProfile(File path)
      Test if the given path is within a directory that is a Profile.
      Parameters:
      path - Path to test.
      Returns:
      true if path or parent directories is a Profile.
      Since:
      3.9.4
    • isProfile

      public static boolean isProfile(File path)
      Test if the given path is a Profile.
      Parameters:
      path - Path to test.
      Returns:
      true if path is a Profile.
      Since:
      3.9.4
    • compareTo

      public int compareTo(Profile o)
      Specified by:
      compareTo in interface Comparable<Profile>