01: /*
02: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 org.romaframework.aspect.view.echo2.component.resolver;
17:
18: import org.romaframework.aspect.view.ViewConstants;
19: import org.romaframework.aspect.view.rendering.RenderingMode;
20: import org.romaframework.aspect.view.rendering.RenderingModeManager;
21: import org.romaframework.core.config.Configurable;
22: import org.romaframework.core.flow.ObjectContext;
23: import org.romaframework.core.schema.SchemaAction;
24: import org.romaframework.core.schema.SchemaElement;
25: import org.romaframework.core.schema.SchemaEvent;
26: import org.romaframework.core.schema.SchemaField;
27:
28: /**
29: * RenderingResolver implementation. Handle configurable map between types and rendering implementations.
30: *
31: * @author Luca Garulli (luca.garulli@assetdata.it)
32: */
33: public class ConfigurableRenderingResolver extends Configurable<String>
34: implements RenderingResolver {
35: private static final String ACTION_CFG = "action";
36: private static final String OBJECT_CFG = "object";
37: private static RenderingModeManager manager = null;
38:
39: public RenderingMode getRenderingMode(SchemaElement iElement,
40: String iRenderingMode) {
41: if (manager == null)
42: // DOUBLE CHECKED SINGLETON
43: synchronized (getClass()) {
44: if (manager == null) {
45: manager = ObjectContext.getInstance().getComponent(
46: RenderingModeManager.class);
47: }
48: }
49:
50: if (iRenderingMode != null) {
51: // GIVE THE PRIORITY TO THE DEFINED RENDERING MODE
52: return manager.getComponent(iRenderingMode);
53: }
54:
55: String cfg;
56: // RENDERING MODE NOT DEFINED: DETERMINE THE BEST FOR THE ELEMENT
57: if (iElement instanceof SchemaEvent) {
58: } else if (iElement instanceof SchemaAction) {
59: cfg = getConfiguration(ACTION_CFG);
60: if (cfg != null)
61: return manager.getComponent(cfg);
62: } else if (iElement instanceof SchemaField) {
63: Class type = ((SchemaField) iElement).getTypeClass();
64: cfg = getConfiguration(type.getName());
65: if (cfg != null)
66: return manager.getComponent(cfg);
67: }
68:
69: // RETURN THE DEFAULT
70: return manager.getComponent(ViewConstants.RENDER_DEFAULT);
71: }
72: }
|