View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.start;
20  
21  public class FileArg
22  {
23      public final String moduleName;
24      public final String uri;
25      public final String location;
26      
27      public FileArg(final Module module, final String uriLocation)
28      {
29          this(module == null?(String)null:module.getName(),uriLocation);
30      }
31      
32      public FileArg(final String uriLocation)
33      {
34          this((String)null,uriLocation);
35      }
36      
37      private FileArg(final String moduleName, final String uriLocation)
38      {
39          this.moduleName = moduleName;
40          String parts[] = uriLocation.split("\\|",3);
41          if (parts.length > 2)
42          {
43              StringBuilder err = new StringBuilder();
44              final String LN = System.lineSeparator();
45              err.append("Unrecognized [file] argument: ").append(uriLocation);
46              err.append(LN).append("Valid Syntaxes: ");
47              err.append(LN).append("          <relative-path> - eg: resources/");
48              err.append(LN).append(" or       <absolute-path> - eg: /var/run/jetty.pid");
49              err.append(LN).append(" or <uri>|<relative-path> - eg: http://machine/my.conf|resources/my.conf");
50              err.append(LN).append(" or <uri>|<absolute-path> - eg: http://machine/glob.dat|/opt/run/glob.dat");
51              throw new IllegalArgumentException(err.toString());
52          }
53          if (parts.length == 2)
54          {
55              this.uri = parts[0];
56              this.location = parts[1];
57          }
58          else
59          {
60              this.uri = null;
61              this.location = uriLocation;
62          }
63      }
64      
65      @Override
66      public boolean equals(Object obj)
67      {
68          if (this == obj)
69          {
70              return true;
71          }
72          if (obj == null)
73          {
74              return false;
75          }
76          if (getClass() != obj.getClass())
77          {
78              return false;
79          }
80          FileArg other = (FileArg)obj;
81          if (uri == null)
82          {
83              if (other.uri != null)
84              {
85                  return false;
86              }
87          }
88          else if (!uri.equals(other.uri))
89          {
90              return false;
91          }
92          if (location == null)
93          {
94              if (other.location != null)
95              {
96                  return false;
97              }
98          }
99          else if (!location.equals(other.location))
100         {
101             return false;
102         }
103         return true;
104     }
105 
106     @Override
107     public int hashCode()
108     {
109         final int prime = 31;
110         int result = 1;
111         result = (prime * result) + ((uri == null)?0:uri.hashCode());
112         result = (prime * result) + ((location == null)?0:location.hashCode());
113         return result;
114     }
115 
116     @Override
117     public String toString()
118     {
119         StringBuilder builder = new StringBuilder();
120         builder.append("DownloadArg [uri=");
121         builder.append(uri);
122         builder.append(", location=");
123         builder.append(location);
124         builder.append("]");
125         return builder.toString();
126     }
127 }