1 package org.apache.maven.resolver.internal.ant.types;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.resolver.internal.ant.AntRepoSys;
23 import org.apache.tools.ant.BuildException;
24 import org.apache.tools.ant.Project;
25 import org.apache.tools.ant.types.DataType;
26 import org.apache.tools.ant.types.Reference;
27
28
29
30 public class Proxy
31 extends DataType
32 {
33
34 private String host;
35
36 private int port;
37
38 private String type;
39
40 private String nonProxyHosts;
41
42 private Authentication authentication;
43
44 @Override
45 public void setProject( Project project )
46 {
47 super.setProject( project );
48
49 AntRepoSys.getInstance( project ).addProxy( this );
50 }
51
52 protected Proxy getRef()
53 {
54 return (Proxy) getCheckedRef();
55 }
56
57 public void setRefid( Reference ref )
58 {
59 if ( host != null || port != 0 || type != null || nonProxyHosts != null )
60 {
61 throw tooManyAttributes();
62 }
63 if ( authentication != null )
64 {
65 throw noChildrenAllowed();
66 }
67 super.setRefid( ref );
68 }
69
70 public String getHost()
71 {
72 if ( isReference() )
73 {
74 return getRef().getHost();
75 }
76 return host;
77 }
78
79 public void setHost( String host )
80 {
81 checkAttributesAllowed();
82 this.host = host;
83 }
84
85 public int getPort()
86 {
87 if ( isReference() )
88 {
89 return getRef().getPort();
90 }
91 return port;
92 }
93
94 public void setPort( int port )
95 {
96 checkAttributesAllowed();
97 if ( port <= 0 || port > 0xFFFF )
98 {
99 throw new BuildException( "The port number must be within the range 1 - 65535" );
100 }
101 this.port = port;
102 }
103
104 public String getType()
105 {
106 if ( isReference() )
107 {
108 return getRef().getType();
109 }
110 return type;
111 }
112
113 public void setType( String type )
114 {
115 checkAttributesAllowed();
116 this.type = type;
117 }
118
119 public String getNonProxyHosts()
120 {
121 if ( isReference() )
122 {
123 return getRef().getNonProxyHosts();
124 }
125 return nonProxyHosts;
126 }
127
128 public void setNonProxyHosts( String nonProxyHosts )
129 {
130 checkAttributesAllowed();
131 this.nonProxyHosts = nonProxyHosts;
132 }
133
134 public Authentication getAuthentication()
135 {
136 if ( isReference() )
137 {
138 return getRef().getAuthentication();
139 }
140 return authentication;
141 }
142
143 public void addAuthentication( Authentication authentication )
144 {
145 checkChildrenAllowed();
146 if ( this.authentication != null )
147 {
148 throw new BuildException( "You must not specify multiple <authentication> elements" );
149 }
150 this.authentication = authentication;
151 }
152
153 public void setAuthRef( Reference ref )
154 {
155 if ( authentication == null )
156 {
157 authentication = new Authentication();
158 authentication.setProject( getProject() );
159 }
160 authentication.setRefid( ref );
161 }
162
163 }