root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / FrameFactory.java @ 27352
History | View | Annotate | Download (3.36 KB)
1 | 9516 | caballero | package com.iver.cit.gvsig.project.documents.layout.fframes; |
---|---|---|---|
2 | |||
3 | import java.security.KeyException; |
||
4 | import java.util.Iterator; |
||
5 | import java.util.Map; |
||
6 | |||
7 | import com.iver.andami.PluginServices; |
||
8 | import com.iver.utiles.extensionPoints.ExtensionPoint; |
||
9 | import com.iver.utiles.extensionPoints.ExtensionPoints; |
||
10 | import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
||
11 | import com.iver.utiles.extensionPoints.IExtensionBuilder; |
||
12 | |||
13 | /**
|
||
14 | * Factory of FFrame.
|
||
15 | *
|
||
16 | * @author Vicente Caballero Navarro
|
||
17 | */
|
||
18 | public abstract class FrameFactory implements IExtensionBuilder { |
||
19 | |||
20 | public static IFFrame createFrameFromName(String s) { |
||
21 | ExtensionPoints extensionPoints = |
||
22 | ExtensionPointsSingleton.getInstance(); |
||
23 | |||
24 | ExtensionPoint extensionPoint =(ExtensionPoint)extensionPoints.get("FFrames");
|
||
25 | Iterator iterator = extensionPoint.keySet().iterator();
|
||
26 | while (iterator.hasNext()) {
|
||
27 | try {
|
||
28 | FrameFactory frameFactory = (FrameFactory)extensionPoint.create((String)iterator.next());
|
||
29 | if (frameFactory.getRegisterName().equals(s)) {
|
||
30 | IFFrame frame=frameFactory.createFrame(); |
||
31 | if (frame == null) return null; |
||
32 | frame.setFrameLayoutFactory(frameFactory); |
||
33 | return frame;
|
||
34 | } |
||
35 | } catch (InstantiationException e) { |
||
36 | e.printStackTrace(); |
||
37 | } catch (IllegalAccessException e) { |
||
38 | e.printStackTrace(); |
||
39 | } catch (ClassCastException e) { |
||
40 | e.printStackTrace(); |
||
41 | } |
||
42 | } |
||
43 | return null; |
||
44 | } |
||
45 | |||
46 | |||
47 | /**
|
||
48 | * Returns the name of FFrame.
|
||
49 | *
|
||
50 | * @return Name of fframe.
|
||
51 | */
|
||
52 | public String getNameType() { |
||
53 | return PluginServices.getText(this, "frame"); |
||
54 | } |
||
55 | |||
56 | /**
|
||
57 | * Create a new IFFrame.
|
||
58 | *
|
||
59 | * @return IFFrame.
|
||
60 | */
|
||
61 | public abstract IFFrame createFrame(); |
||
62 | |||
63 | /**
|
||
64 | * Returns the name of registration in the point of extension.
|
||
65 | *
|
||
66 | * @return Name of registration
|
||
67 | */
|
||
68 | public abstract String getRegisterName(); |
||
69 | |||
70 | /**
|
||
71 | * Create a FrameLayoutFactory.
|
||
72 | *
|
||
73 | * @return FrameLayoutFactory.
|
||
74 | */
|
||
75 | public Object create() { |
||
76 | return this; |
||
77 | } |
||
78 | |||
79 | /**
|
||
80 | * Create a FrameLayoutFactory.
|
||
81 | *
|
||
82 | * @param args
|
||
83 | *
|
||
84 | * @return FrameLayoutFactory.
|
||
85 | */
|
||
86 | public Object create(Object[] args) { |
||
87 | return this; |
||
88 | } |
||
89 | |||
90 | /**
|
||
91 | * Create a FrameLayoutFactory.
|
||
92 | *
|
||
93 | * @param args
|
||
94 | *
|
||
95 | * @return FrameLayoutFactory.
|
||
96 | */
|
||
97 | public Object create(Map args) { |
||
98 | return this; |
||
99 | } |
||
100 | |||
101 | /**
|
||
102 | * Registers in the points of extension the Factory with alias.
|
||
103 | *
|
||
104 | * @param registerName Register name.
|
||
105 | * @param obj Class of register.
|
||
106 | * @param alias Alias.
|
||
107 | */
|
||
108 | public static void register(String registerName, Object obj, String alias) { |
||
109 | ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
||
110 | extensionPoints.add("FFrames", registerName, obj);
|
||
111 | |||
112 | ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints.get( |
||
113 | "FFrames"));
|
||
114 | |||
115 | try {
|
||
116 | extPoint.addAlias(registerName, alias); |
||
117 | } catch (KeyException e) { |
||
118 | e.printStackTrace(); |
||
119 | } |
||
120 | } |
||
121 | |||
122 | /**Registers in the points of extension the Factory
|
||
123 | *
|
||
124 | * @param registerName Register name.
|
||
125 | * @param obj Class of register.
|
||
126 | */
|
||
127 | public static void register(String registerName, Object obj) { |
||
128 | ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
||
129 | extensionPoints.add("FFrames", registerName, obj);
|
||
130 | } |
||
131 | } |