001: package org.gridsphere.services.core.setup.modules.impl;
002:
003: import org.gridsphere.services.core.setup.modules.PortletsSetupModule;
004: import org.gridsphere.services.core.setup.modules.impl.descriptor.PortletsSetupModuleDefinition;
005: import org.gridsphere.services.core.setup.modules.impl.descriptor.PortletsSetupModuleStateDescriptor;
006: import org.gridsphere.portlet.service.spi.impl.descriptor.ConfigParam;
007: import org.gridsphere.portlet.service.spi.impl.descriptor.Description;
008: import org.gridsphere.portletcontainer.impl.descriptor.PortletDefinition;
009:
010: import javax.servlet.http.HttpServletRequest;
011: import javax.portlet.Portlet;
012: import java.util.*;
013:
014: /**
015: * @author <a href="mailto:docentt@man.poznan.pl">Tomasz Kuczynski</a>, PSNC
016: * @version $Id$
017: */
018: public abstract class BasePortletsSetupModule implements
019: PortletsSetupModule, Comparable {
020:
021: protected Map attributes = new HashMap();
022: protected PortletsSetupModuleDefinition moduleDef = null;
023: protected boolean preInitPhaseProcessed = false;
024: protected boolean postInitPhaseProcessed = false;
025:
026: public BasePortletsSetupModule(
027: PortletsSetupModuleDefinition moduleDef) {
028: this .moduleDef = moduleDef;
029: List configList = moduleDef.getConfigParamList();
030: Iterator it = configList.iterator();
031: while (it.hasNext()) {
032: ConfigParam param = (ConfigParam) it.next();
033: attributes.put(param.getParamName(), param.getParamValue());
034: }
035: if (!moduleDef.getPreInitModule())
036: preInitPhaseProcessed = true;
037: if (!moduleDef.getPostInitModule())
038: postInitPhaseProcessed = true;
039: }
040:
041: private BasePortletsSetupModule() {
042: }
043:
044: public void invokePreInit(HttpServletRequest request,
045: PortletDefinition portletDefinition)
046: throws IllegalArgumentException {
047: if (moduleDef.getPreInitModule())
048: throw new IllegalArgumentException("Not implemented !!!");
049: throw new IllegalArgumentException("Not supported");
050: }
051:
052: public void invokePostInit(HttpServletRequest request,
053: Portlet portlet) throws IllegalArgumentException {
054: if (moduleDef.getPostInitModule())
055: throw new IllegalArgumentException("Not implemented !!!");
056: throw new IllegalArgumentException("Not supported");
057: }
058:
059: public void fillPreInitStateDescriptor(
060: PortletsSetupModuleStateDescriptor portletsSetupModuleStateDescriptor,
061: PortletDefinition portletDefinition)
062: throws IllegalArgumentException {
063: if (!moduleDef.getPreInitModule())
064: throw new IllegalArgumentException("Not supported");
065: }
066:
067: public void fillPostInitStateDescriptor(
068: PortletsSetupModuleStateDescriptor portletsSetupModuleStateDescriptor)
069: throws IllegalArgumentException {
070: if (!moduleDef.getPostInitModule())
071: throw new IllegalArgumentException("Not supported");
072: }
073:
074: public String getAttribute(String name) {
075: return (String) attributes.get(name);
076: }
077:
078: public Map getAttributes() {
079: return attributes;
080: }
081:
082: public void setAttributes(Map attributes) {
083: this .attributes = attributes;
084: }
085:
086: public String getModuleName() {
087: return moduleDef.getModuleName();
088: }
089:
090: public String getContextName() {
091: return moduleDef.getContextName();
092: }
093:
094: public String getPortletName() {
095: return moduleDef.getPortletName();
096: }
097:
098: public String getModuleDefaultJSP(Locale locale) {
099: List modJSPs = moduleDef.getModuleDefaultJSPs();
100: if (locale == null)
101: throw new IllegalArgumentException("locale is NULL");
102: Iterator it = modJSPs.iterator();
103: String defTitle = "";
104: while (it.hasNext()) {
105: Description t = (Description) it.next();
106: if (t.getLang() == null)
107: t.setLang(Locale.ENGLISH.getLanguage());
108: if (locale.getLanguage().equals(
109: new Locale(t.getLang(), "", "").getLanguage()))
110: return t.getText();
111: if (t.getLang().equals(Locale.ENGLISH.getLanguage()))
112: defTitle = t.getText();
113: }
114: return defTitle;
115: }
116:
117: public boolean isPreInitModule() {
118: return moduleDef.getPreInitModule();
119: }
120:
121: public boolean isPostInitModule() {
122: return moduleDef.getPostInitModule();
123: }
124:
125: public String getModuleError(String key, Locale locale) {
126: List modErrs = moduleDef.getModuleErrors();
127: if (locale == null)
128: throw new IllegalArgumentException("locale is NULL");
129: Iterator it = modErrs.iterator();
130: String defTitle = null;
131: while (it.hasNext()) {
132: Description t = (Description) it.next();
133: if (t.getKey().equals(key)) {
134: if (t.getLang() == null)
135: t.setLang(Locale.ENGLISH.getLanguage());
136: if (locale.getLanguage().equals(
137: new Locale(t.getLang(), "", "").getLanguage()))
138: return t.getText();
139: if (t.getLang().equals(Locale.ENGLISH.getLanguage()))
140: defTitle = t.getText();
141: }
142: }
143: return defTitle;
144: }
145:
146: public String getModuleDescription(Locale locale) {
147: List modDescs = moduleDef.getModuleDescriptions();
148: if (locale == null)
149: throw new IllegalArgumentException("locale is NULL");
150: Iterator it = modDescs.iterator();
151: String defTitle = "";
152: while (it.hasNext()) {
153: Description t = (Description) it.next();
154: if (t.getLang() == null)
155: t.setLang(Locale.ENGLISH.getLanguage());
156: if (locale.getLanguage().equals(
157: new Locale(t.getLang(), "", "").getLanguage()))
158: return t.getText();
159: if (t.getLang().equals(Locale.ENGLISH.getLanguage()))
160: defTitle = t.getText();
161: }
162: return defTitle;
163: }
164:
165: public String getModuleTitle(Locale locale) {
166: List modTitls = moduleDef.getModuleTitles();
167: if (locale == null)
168: throw new IllegalArgumentException("locale is NULL");
169: Iterator it = modTitls.iterator();
170: String defTitle = "";
171: while (it.hasNext()) {
172: Description t = (Description) it.next();
173: if (t.getLang() == null)
174: t.setLang(Locale.ENGLISH.getLanguage());
175: if (locale.getLanguage().equals(
176: new Locale(t.getLang(), "", "").getLanguage()))
177: return t.getText();
178: if (t.getLang().equals(Locale.ENGLISH.getLanguage()))
179: defTitle = t.getText();
180: }
181: return defTitle;
182: }
183:
184: public int getModulePriority() {
185: return moduleDef.getModulePriority();
186: }
187:
188: public void setModulePriority(int priority) {
189: moduleDef.setModulePriority(priority);
190: }
191:
192: public boolean isModuleActive() {
193: return moduleDef.getModuleActive();
194: }
195:
196: public void setModuleActive(boolean active) {
197: moduleDef.setModuleActive(active);
198: }
199:
200: public PortletsSetupModuleDefinition getModuleDef() {
201: return moduleDef;
202: }
203:
204: public void setModuleDef(PortletsSetupModuleDefinition moduleDef) {
205: this .moduleDef = moduleDef;
206: }
207:
208: public boolean isPreInitPhaseProcessed() {
209: return preInitPhaseProcessed;
210: }
211:
212: public void setPreInitPhaseProcessed(
213: boolean prePortletsInitializationPhaseProcessed) {
214: this .preInitPhaseProcessed = prePortletsInitializationPhaseProcessed;
215: }
216:
217: public boolean isPostInitPhaseProcessed() {
218: return postInitPhaseProcessed;
219: }
220:
221: public void setPostInitPhaseProcessed(
222: boolean postPortletsInitializationPhaseProcessed) {
223: this .postInitPhaseProcessed = postPortletsInitializationPhaseProcessed;
224: }
225:
226: public int compareTo(Object obj) {
227: if ((obj != null) && (obj instanceof PortletsSetupModule)) {
228: PortletsSetupModule l = (PortletsSetupModule) obj;
229: if (this .moduleDef.getModulePriority() < l
230: .getModulePriority()) {
231: return -1;
232: } else if (this .moduleDef.getModulePriority() > l
233: .getModulePriority()) {
234: return 1;
235: } else {
236: return 0;
237: }
238: }
239: throw new ClassCastException(
240: "Unable to compare supplied object to this module");
241: }
242: }
|