View Javadoc
1   package org.apache.maven.resolver.internal.ant.types;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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 }