View Javadoc
1   /*
2    * Copyright 2006 Werner Guttmann
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11   * or implied. See the License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  package org.exolab.castor.builder.conflictresolution;
15  
16  import org.exolab.castor.builder.SGStateInfo;
17  import org.exolab.castor.builder.SingleClassGenerator;
18  import org.exolab.castor.builder.info.ClassInfo;
19  import org.exolab.castor.util.dialog.ConsoleDialog;
20  import org.exolab.javasource.JClass;
21  
22  /**
23   * Strategy pattern for dealing with class name conflicts during source code generation. The various
24   * implementations of this stragtegy will implement individual approaches for dealing with such a
25   * naming collision.
26   *
27   * @author <a href="mailto:werner DOT guttmann AT gmx DOT net">Werner Guttmann</a>
28   * @since 1.1
29   */
30  public interface ClassNameCRStrategy {
31  
32    /**
33     * Implements a specific strategy for dealing with class name conflicts.
34     * 
35     * @param state The current source generator state.
36     * @param newClassInfo The {@link CLassInfo} for the new class to be generated.
37     * @param conflict The {@link JClass} instance representing the potential conflict.
38     * @return the source generator state, as modified by the decision.
39     */
40    SGStateInfo dealWithClassNameConflict(final SGStateInfo state, final ClassInfo newClassInfo,
41        final JClass conflict);
42  
43    /**
44     * Implements a specific strategy for dealing with the fact that -- for a given file name -- an
45     * artifact with the same name already exists.
46     *
47     * @param filename The name of the file to be overwritten.
48     * @return True of the file should be overwritten.
49     */
50    boolean dealWithFileOverwrite(String filename);
51  
52    /**
53     * Returns the name of this strategy.
54     * 
55     * @return The name of this strategy.
56     */
57    String getName();
58  
59    /**
60     * Sets the {@link ConsoleDialog} instance to use (if required).
61     * 
62     * @param dialog the {@link ConsoleDialog} instance to use (if required).
63     */
64    void setConsoleDialog(ConsoleDialog dialog);
65  
66    /**
67     * Injects the {@link SingleClassGenerator} instance that actually is calling a method of this
68     * strategy.
69     *
70     * @param generator The calling {@link SingleClassGenerator}
71     * @see SingleClassGenerator
72     */
73    void setSingleClassGenerator(SingleClassGenerator generator);
74  
75  }