001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.soap.annotation;
014
015import static java.lang.annotation.ElementType.*;
016import static java.lang.annotation.RetentionPolicy.*;
017import static org.apache.juneau.internal.ArrayUtils.*;
018
019import java.lang.annotation.*;
020import java.lang.reflect.*;
021
022import org.apache.juneau.*;
023import org.apache.juneau.annotation.*;
024import org.apache.juneau.reflect.*;
025import org.apache.juneau.svl.*;
026
027/**
028 * Utility classes and methods for the {@link SoapXml @SoapXml} annotation.
029 *
030 * <h5 class='section'>See Also:</h5><ul>
031 * </ul>
032 */
033public class SoapXmlAnnotation {
034
035   //-----------------------------------------------------------------------------------------------------------------
036   // Static
037   //-----------------------------------------------------------------------------------------------------------------
038
039   /** Default value */
040   public static final SoapXml DEFAULT = create().build();
041
042   /**
043    * Instantiates a new builder for this class.
044    *
045    * @return A new builder object.
046    */
047   public static Builder create() {
048      return new Builder();
049   }
050
051   /**
052    * Instantiates a new builder for this class.
053    *
054    * @param on The targets this annotation applies to.
055    * @return A new builder object.
056    */
057   public static Builder create(Class<?>...on) {
058      return create().on(on);
059   }
060
061   /**
062    * Instantiates a new builder for this class.
063    *
064    * @param on The targets this annotation applies to.
065    * @return A new builder object.
066    */
067   public static Builder create(String...on) {
068      return create().on(on);
069   }
070
071   /**
072    * Creates a copy of the specified annotation.
073    *
074    * @param a The annotation to copy.s
075    * @param r The var resolver for resolving any variables.
076    * @return A copy of the specified annotation.
077    */
078   public static SoapXml copy(SoapXml a, VarResolverSession r) {
079      return
080         create()
081         .on(r.resolve(a.on()))
082         .onClass(a.onClass())
083         .build();
084   }
085
086   //-----------------------------------------------------------------------------------------------------------------
087   // Builder
088   //-----------------------------------------------------------------------------------------------------------------
089
090   /**
091    * Builder class.
092    *
093    * <h5 class='section'>See Also:</h5><ul>
094    *    <li class='jm'>{@link org.apache.juneau.BeanContext.Builder#annotations(Annotation...)}
095    * </ul>
096    */
097   public static class Builder extends TargetedAnnotationTMFBuilder {
098
099      /**
100       * Constructor.
101       */
102      protected Builder() {
103         super(SoapXml.class);
104      }
105
106      /**
107       * Instantiates a new {@link SoapXml @SoapXml} object initialized with this builder.
108       *
109       * @return A new {@link SoapXml @SoapXml} object.
110       */
111      public SoapXml build() {
112         return new Impl(this);
113      }
114
115      // <FluentSetters>
116
117      @Override /* GENERATED - TargetedAnnotationBuilder */
118      public Builder on(String...values) {
119         super.on(values);
120         return this;
121      }
122
123      @Override /* GENERATED - TargetedAnnotationTBuilder */
124      public Builder on(java.lang.Class<?>...value) {
125         super.on(value);
126         return this;
127      }
128
129      @Override /* GENERATED - TargetedAnnotationTBuilder */
130      public Builder onClass(java.lang.Class<?>...value) {
131         super.onClass(value);
132         return this;
133      }
134
135      @Override /* GENERATED - TargetedAnnotationTMFBuilder */
136      public Builder on(Field...value) {
137         super.on(value);
138         return this;
139      }
140
141      @Override /* GENERATED - TargetedAnnotationTMFBuilder */
142      public Builder on(Method...value) {
143         super.on(value);
144         return this;
145      }
146
147      // </FluentSetters>
148   }
149
150   //-----------------------------------------------------------------------------------------------------------------
151   // Implementation
152   //-----------------------------------------------------------------------------------------------------------------
153
154   private static class Impl extends TargetedAnnotationTImpl implements SoapXml {
155
156      Impl(Builder b) {
157         super(b);
158         postConstruct();
159      }
160   }
161
162   //-----------------------------------------------------------------------------------------------------------------
163   // Appliers
164   //-----------------------------------------------------------------------------------------------------------------
165
166   /**
167    * Applies targeted {@link SoapXml} annotations to a {@link org.apache.juneau.Context.Builder}.
168    */
169   public static class Apply extends AnnotationApplier<SoapXml,Context.Builder> {
170
171      /**
172       * Constructor.
173       *
174       * @param vr The resolver for resolving values in annotations.
175       */
176      public Apply(VarResolverSession vr) {
177         super(SoapXml.class, Context.Builder.class, vr);
178      }
179
180      @Override
181      public void apply(AnnotationInfo<SoapXml> ai, Context.Builder b) {
182         SoapXml a = ai.inner();
183         if (isEmptyArray(a.on(), a.onClass()))
184            return;
185         b.annotations(copy(a, vr()));
186      }
187   }
188
189   //-----------------------------------------------------------------------------------------------------------------
190   // Other
191   //-----------------------------------------------------------------------------------------------------------------
192
193   /**
194    * A collection of {@link SoapXml @SoapXml annotations}.
195    */
196   @Documented
197   @Target({METHOD,TYPE})
198   @Retention(RUNTIME)
199   @Inherited
200   public static @interface Array {
201
202      /**
203       * The child annotations.
204       *
205       * @return The annotation value.
206       */
207      SoapXml[] value();
208   }
209}