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.screen.config;
17:
18: import org.romaframework.aspect.view.screen.Screen;
19: import org.romaframework.aspect.view.screen.ScreenFactory;
20: import org.romaframework.core.config.Configurable;
21: import org.romaframework.core.flow.ObjectContext;
22: import org.romaframework.core.schema.SchemaClassResolver;
23: import org.romaframework.xml.config.XmlConfigAreaType;
24:
25: /**
26: * Manage Desktop instances. It acts as Desktop factory and cache of desktop original instances. When a Desktop is requested, then a
27: * Desktop clone is created starting from original. This prevent to reload and parse Xml descriptor.
28: *
29: * @author Luca Garulli (luca.garulli@assetdata.it)
30: */
31: public abstract class ScreenManager extends Configurable<ScreenFactory> {
32:
33: public abstract Screen createScreenFromDefaultFactory(String iName,
34: XmlConfigAreaType iAreaTag);
35:
36: public Screen getScreen(String iTypeName) {
37: Screen screen = null;
38:
39: if (iTypeName.endsWith(SchemaClassResolver.DESCRIPTOR_SUFFIX))
40: iTypeName = iTypeName.substring(0, iTypeName.length()
41: - SchemaClassResolver.DESCRIPTOR_SUFFIX.length());
42:
43: // TRY TO GET DESKTOP FACTORY IN MEMORY
44: ScreenFactory factory = getConfiguration(iTypeName);
45:
46: if (factory != null) {
47: screen = factory.create();
48: } else {
49: synchronized (this ) {
50: // NO FACTORY DEFINED: CREATE A CONFIGURABLE DESKTOP LOADED FROM
51: // DESCRIPTOR
52: ScreenConfiguration descr = ObjectContext.getInstance()
53: .getComponent(ScreenConfigurationLoader.class)
54: .getDescriptor(iTypeName);
55:
56: if (descr == null)
57: // DESKTOP DESCRIPTOR NOT FOUND
58: return null;
59:
60: screen = createScreenFromDefaultFactory(iTypeName,
61: descr.getRootArea());
62: }
63: }
64:
65: return screen;
66: }
67: }
|