View Javadoc

1   /*
2    * Copyright 2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.maven.plugin.jboss.modules.descriptor;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.commons.lang.builder.ToStringBuilder;
20  
21  /**
22   * Provides directives for a given {@link ModuleDescriptor module descriptor}.
23   * Directives control the building process of a single module.
24   */
25  public final class Directives
26  {
27    // ********************************* Fields *********************************
28  
29    // --- constants ------------------------------------------------------------
30  
31    // --- members --------------------------------------------------------------
32  
33    /**
34     * The flag to skip the export of the module. This allows to rename a
35     * dependency to an existing module in JBoss, but not to create a module in
36     * the target folder.
37     */
38    private Boolean skip;
39  
40    /**
41     * The signal to control, if the slot is to be inherited to the dependencies
42     * if not specified by a dependency otherwise. If set to <code>false</code>,
43     * the default slot will be used instead of the module's slot.
44     * <p>
45     * Useful to create extensions that have to reside in the main slot but have
46     * to depend on modules in another slot.
47     */
48    private Boolean inheritSlot;
49  
50    // ****************************** Initializer *******************************
51  
52    // ****************************** Constructors ******************************
53  
54    private Directives(final Builder builder)
55    {
56      this.skip = builder.skip;
57      this.inheritSlot = builder.inheritSlot;
58    }
59  
60    // ****************************** Inner Classes *****************************
61  
62    /**
63     * Builds instances of {@link Directives}.
64     */
65    public static final class Builder
66    {
67      // ******************************** Fields ********************************
68  
69      // --- constants ----------------------------------------------------------
70  
71      // --- members ------------------------------------------------------------
72  
73      /**
74       * The flag to skip the export of the module. This allows to rename a
75       * dependency to an existing module in JBoss, but not to create a module in
76       * the target folder.
77       * <p>
78       * Defaults to <code>false</code>.
79       * </p>
80       */
81      private Boolean skip = Boolean.FALSE;
82  
83      /**
84       * The signal to control, if the slot is to be inherited to the dependencies
85       * if not specified by a dependency otherwise. If set to <code>false</code>,
86       * the default slot will be used instead of the module's slot.
87       * <p>
88       * Useful to create extensions that have to reside in the main slot but have
89       * to depend on modules in another slot.
90       * <p>
91       * Defaults to <code>true</code>.
92       * </p>
93       */
94      private Boolean inheritSlot = Boolean.TRUE;
95  
96      // ***************************** Initializer ******************************
97  
98      // ***************************** Constructors *****************************
99  
100     // ***************************** Inner Classes ****************************
101 
102     // ******************************** Methods *******************************
103 
104     // --- init ---------------------------------------------------------------
105 
106     // --- get&set ------------------------------------------------------------
107 
108     /**
109      * Sets the flag to skip the export of the module. This allows to rename a
110      * dependency to an existing module in JBoss, but not to create a module in
111      * the target folder.
112      *
113      * @param skip the flag to skip the export of the module.
114      * @return a reference to this builder.
115      */
116     public Builder withSkip(final String skip)
117     {
118       if (StringUtils.isNotBlank(skip))
119       {
120         this.skip = Boolean.parseBoolean(skip);
121       }
122       return this;
123     }
124 
125     /**
126      * Sets the signal to control, if the slot is to be inherited to the
127      * dependencies if not specified by a dependency otherwise. If set to
128      * <code>false</code>, the default slot will be used instead of the module's
129      * slot.
130      * <p>
131      * Useful to create extensions that have to reside in the main slot but have
132      * to depend on modules in another slot.
133      *
134      * @param inheritSlot the signal to control, if the slot is to be inherited
135      *          to the dependencies if not specified by a dependency otherwise.
136      * @return a reference to this builder.
137      */
138     public Builder withInheritSlot(final String inheritSlot)
139     {
140       if (StringUtils.isNotBlank(inheritSlot))
141       {
142         this.inheritSlot = Boolean.parseBoolean(inheritSlot);
143       }
144       return this;
145     }
146 
147     // --- business -----------------------------------------------------------
148 
149     /**
150      * Builds an instance of {@link Directives}.
151      *
152      * @return the instance.
153      */
154     public Directives build()
155     {
156       return new Directives(this);
157     }
158 
159     // --- object basics ------------------------------------------------------
160   }
161 
162   // ********************************* Methods ********************************
163 
164   // --- init -----------------------------------------------------------------
165 
166   // --- get&set --------------------------------------------------------------
167 
168   /**
169    * Returns the flag to skip the export of the module. This allows to rename a
170    * dependency to an existing module in JBoss, but not to create a module in
171    * the target folder.
172    *
173    * @return the flag to skip the export of the module.
174    */
175   public Boolean getSkip()
176   {
177     return skip;
178   }
179 
180   /**
181    * Returns the signal to control, if the slot is to be inherited to the
182    * dependencies if not specified by a dependency otherwise. If set to
183    * <code>false</code>, the default slot will be used instead of the module's
184    * slot.
185    * <p>
186    * Useful to create extensions that have to reside in the main slot but have
187    * to depend on modules in another slot.
188    *
189    * @return the signal to control, if the slot is to be inherited to the
190    *         dependencies if not specified by a dependency otherwise.
191    */
192   public Boolean getInheritSlot()
193   {
194     return inheritSlot;
195   }
196 
197   // --- business -------------------------------------------------------------
198 
199   /**
200    * Merges the given directive with this instance.
201    *
202    * @param directives the instance to merge into this instance.
203    */
204   public void merge(final Directives directives)
205   {
206     skip |= directives.skip;
207     inheritSlot |= directives.inheritSlot;
208   }
209 
210   // --- object basics --------------------------------------------------------
211 
212   @Override
213   public String toString()
214   {
215     return ToStringBuilder.reflectionToString(this);
216   }
217 }