View Javadoc

1   /*
2    * Copyright 2006-2016 The JGUIraffe Team.
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 net.sf.jguiraffe.transform;
17  
18  import java.util.Locale;
19  import java.util.Map;
20  
21  import net.sf.jguiraffe.resources.ResourceManager;
22  
23  /**
24   * <p>
25   * Definition of an interface for accessing data needed by transformers.
26   * </p>
27   * <p>
28   * This interface defines a set of methods for accessing system information like
29   * the current {@code Locale} or the resource manager. A {@link Transformer}
30   * object is passed an implementation of this interface, so it can make use of
31   * the methods defined here to obtain the data it needs.
32   * </p>
33   *
34   * @author Oliver Heger
35   * @version $Id: TransformerContext.java 205 2012-01-29 18:29:57Z oheger $
36   */
37  public interface TransformerContext
38  {
39      /**
40       * Returns the current {@code Locale}.
41       *
42       * @return the {@code Locale} to use
43       */
44      Locale getLocale();
45  
46      /**
47       * Returns the current {@code ResourceManager}. This object can be
48       * used to access resources.
49       *
50       * @return the {@code ResourceManager}
51       */
52      ResourceManager getResourceManager();
53  
54      /**
55       * Returns a map with properties. Transformers or validators can use this
56       * method for obtaining specific properties that may influence their
57       * behavior.
58       *
59       * @return a map with properties assigned to this context
60       */
61      Map<String, Object> properties();
62  
63      /**
64       * Returns the value of the property with the given type. Objects that are
65       * passed a {@code TransformerContext} have access to a set of properties
66       * which can impact their behavior. Using this method properties can be
67       * queried in a type-safe way. This is in contrast to the properties
68       * available through the {@link #properties()} method. While the standard
69       * transformer implementations shipped with this library typically use the
70       * plain properties, this method is intended to be used by high-level custom
71       * transformers that need access to certain application-global objects. For
72       * instance, an application may store information about the currently edited
73       * object in its context. A {@code Validator} implementation may then access
74       * this data to perform specific checks. The type-safe properties available
75       * through this method are typically disjunct to the the ones provided by
76       * {@link #properties()}.An implementation should check whether a property
77       * of the specified type is available and return it. Otherwise, the method
78       * should return <b>null</b>.
79       *
80       * @param <T> the type of the property
81       * @param propCls the property class
82       * @return the value of this property or <b>null</b> if it is not set
83       */
84      <T> T getTypedProperty(Class<T> propCls);
85  
86      /**
87       * Returns the {@code ValidationMessageHandler} associated with this
88       * context. This object can be used for obtaining validation messages. It is
89       * used for instance by concrete {@link Validator}
90       * implementations.
91       *
92       * @return the {@code ValidationMessageHandler} for this context
93       */
94      ValidationMessageHandler getValidationMessageHandler();
95  }