You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2006-2013 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.serverlists;
  23. import com.dmdirc.Server;
  24. import com.dmdirc.ServerManager;
  25. import java.net.URI;
  26. /**
  27. * Describes an entry for a server within a {@link ServerGroup}.
  28. *
  29. * @since 0.6.4
  30. * @author chris
  31. */
  32. public class ServerEntry extends ServerGroupItemBase {
  33. /** The address of the server in question. */
  34. private URI address;
  35. /** The group that owns this entry. */
  36. private final ServerGroup group;
  37. /** The manager to use to create new servers. */
  38. private final ServerManager serverManager;
  39. /**
  40. * Creates a new server entry.
  41. *
  42. * @param group The group that owns this entry
  43. * @param name The name of this server
  44. * @param address The address of this server
  45. * @param profile The name of the profile to be used by this server
  46. */
  47. public ServerEntry(final ServerManager serverManager,
  48. final ServerGroup group, final String name,
  49. final URI address, final String profile) {
  50. this.serverManager = serverManager;
  51. setName(name);
  52. setProfile(profile);
  53. this.address = address;
  54. this.group = group;
  55. }
  56. /** {@inheritDoc} */
  57. @Override
  58. public ServerGroup getGroup() {
  59. return group;
  60. }
  61. /** {@inheritDoc} */
  62. @Override
  63. protected ServerGroup getParent() {
  64. return getGroup();
  65. }
  66. /**
  67. * Retrieves the address used by this server.
  68. *
  69. * @return This server's address
  70. */
  71. @Override
  72. public URI getAddress() {
  73. return address;
  74. }
  75. /**
  76. * Sets the address for this server entry.
  77. *
  78. * @param address The new address for this entry
  79. */
  80. public void setAddress(final URI address) {
  81. setModified(true);
  82. this.address = address;
  83. }
  84. /** {@inheritDoc} */
  85. @Override
  86. public void connect() {
  87. final Server server = new Server(serverManager, address, getProfileIdentity());
  88. server.connect();
  89. }
  90. /** {@inheritDoc} */
  91. @Override
  92. public String toString() {
  93. return "[" + getName() + ": address: " + getAddress() + "]";
  94. }
  95. }