001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.commons.bean;
018
019import static org.apache.juneau.commons.utils.Shorts.*;
020
021import org.apache.juneau.commons.*;
022
023/**
024 * Utility classes and methods for the {@link BeanCtor @BeanCtor} annotation.
025 *
026 * <p>
027 * Provides a {@link Builder} that constructs a synthetic {@link BeanCtor @BeanCtor} annotation instance
028 * programmatically without requiring it to be declared on a program element at compile time.
029 *
030 * <h5 class='section'>See Also:</h5><ul>
031 *    <li class='ja'>{@link BeanCtor}
032 *    <li class='jc'>{@link AnnotationObject}
033 * </ul>
034 */
035public class BeanCtorAnnotation {
036
037   /**
038    * Prevents instantiation.
039    */
040   private BeanCtorAnnotation() {}
041
042   /**
043    * Builder class.
044    */
045   public static class Builder extends AnnotationObject.Builder {
046
047      private String[] description = {};
048      private String properties = "";
049
050      /**
051       * Constructor.
052       */
053      protected Builder() {
054         super(BeanCtor.class);
055      }
056
057      /**
058       * Instantiates a new {@link BeanCtor @BeanCtor} object initialized with this builder.
059       *
060       * @return A new {@link BeanCtor @BeanCtor} object.
061       */
062      public BeanCtor build() {
063         return new Object(this);
064      }
065
066      /**
067       * Sets the description property on this annotation.
068       *
069       * @param value The new value for this property.  Can be <jk>null</jk> (stored as-is, with no default substitution).
070       * @return This object.
071       */
072      public Builder description(String...value) {
073         description = value;
074         return this;
075      }
076
077      /**
078       * Sets the {@link BeanCtor#properties()} property on this annotation.
079       *
080       * @param value The new value for this property.  Can be <jk>null</jk> (stored as-is, with no default substitution).
081       * @return This object.
082       */
083      public Builder properties(String value) {
084         properties = value;
085         return this;
086      }
087
088   }
089
090   @SuppressWarnings({
091      "annotationSuperInterface", // Eclipse JDT: intentional concrete implementation of annotation interface for runtime-built annotation instances
092      "java:S2160" // equals() inherited from AnnotationObject compares all annotation interface methods; subclass fields are accessed via those methods
093   })
094   private static class Object extends AnnotationObject implements BeanCtor {
095
096      private final String[] description;
097      private final String properties;
098
099      Object(BeanCtorAnnotation.Builder b) {
100         super(b);
101         description = cp(b.description);
102         properties = b.properties;
103      }
104
105      @Override /* Overridden from BeanCtor */
106      public String[] description() {
107         return cp(description);
108      }
109
110      @Override /* Overridden from BeanCtor */
111      public String properties() {
112         return properties;
113      }
114   }
115
116   /** Default value */
117   public static final BeanCtor DEFAULT = create().build();
118
119   /**
120    * Instantiates a new builder for this class.
121    *
122    * @return A new builder object.
123    */
124   public static Builder create() {
125      return new Builder();
126   }
127}