001: /**
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: PortletServiceDefinition.java 6385 2007-10-25 14:02:26Z wehrens $
004: */package org.gridsphere.portlet.service.spi.impl.descriptor;
005:
006: import java.util.*;
007:
008: /**
009: * The <code>SportletServiceDefinition</code> defines a portlet service
010: * definition that is defined in the portlet service descripor.
011: */
012: public class PortletServiceDefinition {
013:
014: protected String serviceName = "";
015: protected List serviceDescriptions = new Vector();
016: protected String serviceInterface = "";
017: protected String serviceImplementation = "";
018: protected boolean userRequired = false;
019: protected List<ConfigParam> configParamList = new Vector<ConfigParam>();
020: protected Properties configProps = null;
021: protected boolean loadOnStartup = false;
022:
023: /**
024: * Sets the portlet service name
025: *
026: * @param serviceName the portlet service name
027: */
028: public void setServiceName(String serviceName) {
029: this .serviceName = serviceName;
030: }
031:
032: /**
033: * Returns the portlet service name
034: *
035: * @return the portlet service name
036: */
037: public String getServiceName() {
038: return this .serviceName;
039: }
040:
041: /**
042: * Sets the portlet service descriptions
043: *
044: * @param serviceDescriptions the list of portlet service descriptions
045: */
046: public void setServiceDescription(List serviceDescriptions) {
047: this .serviceDescriptions = serviceDescriptions;
048: }
049:
050: /**
051: * Returns the portlet service descriptions
052: *
053: * @return the portlet service descriptions
054: */
055: public List getServiceDescription() {
056: return this .serviceDescriptions;
057: }
058:
059: /**
060: * Sets the portlet service interface
061: *
062: * @param serviceInterface the portlet service interface
063: */
064: public void setServiceInterface(String serviceInterface) {
065: this .serviceInterface = serviceInterface;
066: }
067:
068: /**
069: * Returns the portlet service interface
070: *
071: * @return the portlet service interface
072: */
073: public String getServiceInterface() {
074: return this .serviceInterface;
075: }
076:
077: /**
078: * Returns the portlet service implementation
079: *
080: * @return the portlet service implementation
081: */
082: public String getServiceImplementation() {
083: return this .serviceImplementation;
084: }
085:
086: /**
087: * Sets the portlet service implementation
088: *
089: * @param serviceImplementation the portlet service implementation
090: */
091: public void setServiceImplementation(String serviceImplementation) {
092: this .serviceImplementation = serviceImplementation;
093: }
094:
095: /**
096: * Determines if this service is a user service or not
097: *
098: * @param userRequired if <code>true</code> then portlet service is
099: * an instance of a user service, <code>false</code> otherwise
100: */
101: public void setUserRequired(boolean userRequired) {
102: this .userRequired = userRequired;
103: }
104:
105: /**
106: * Determines if this service is a user service or not
107: *
108: * @return <code>true</code> if portlet service is
109: * an instance of a user service, <code>false</code> otherwise
110: */
111: public boolean getUserRequired() {
112: return this .userRequired;
113: }
114:
115: /**
116: * Sets the service configuration parameter list
117: *
118: * @param configParamList the configuration parameter list
119: */
120: public void setConfigParamList(List<ConfigParam> configParamList) {
121: this .configParamList = configParamList;
122: }
123:
124: /**
125: * Returns the service configuration parameter list
126: *
127: * @return the configuration parameter list
128: */
129: public List<ConfigParam> getConfigParamList() {
130: return this .configParamList;
131: }
132:
133: /**
134: * Creates a properties from the ConfigParamList
135: *
136: * @see #getConfigParamList
137: */
138: private void createProperties() {
139: configProps = new Properties();
140: Iterator it = this .configParamList.iterator();
141: ConfigParam param;
142: while (it.hasNext()) {
143: param = (ConfigParam) it.next();
144: configProps.setProperty(param.getParamName(), param
145: .getParamValue());
146: }
147: }
148:
149: /**
150: * Return the configuration properties
151: *
152: * @return the configuration properties
153: */
154: public Properties getConfigProperties() {
155: if (configProps == null)
156: createProperties();
157: return configProps;
158: }
159:
160: /**
161: * Sets the configuration properties
162: *
163: * @param props the configuration properties
164: */
165: public void setConfigProperties(Properties props) {
166: Enumeration e = props.keys();
167: if (!props.isEmpty()) {
168: configParamList = new Vector<ConfigParam>();
169: }
170: while (e.hasMoreElements()) {
171: String key = (String) e.nextElement();
172: ConfigParam param = new ConfigParam(key, props
173: .getProperty(key));
174: configParamList.add(param);
175: }
176: }
177:
178: /**
179: * Returns true if this service should be initialized on startup
180: *
181: * @return true if this service should be initialized on startup
182: */
183: public boolean isLoadOnStartup() {
184: return loadOnStartup;
185: }
186:
187: /**
188: * Sets whether this service should be initialized on startup
189: *
190: * @param loadOnStartup true if this service should be initialized on startup
191: */
192: public void setLoadOnStartup(boolean loadOnStartup) {
193: this .loadOnStartup = loadOnStartup;
194: }
195:
196: /**
197: * Returns a <code>String</code> representation if this portlet service
198: * definition
199: *
200: * @return the service definition as a <code>String</code>
201: */
202: public String toString() {
203: StringBuffer sb = new StringBuffer("\n");
204: sb.append("service name: ").append(serviceName).append("\n");
205: sb.append("service description: ").append(
206: this .serviceDescriptions.get(0)).append("\n");
207: sb.append("service interface: ").append(this .serviceInterface)
208: .append("\n");
209: sb.append("service implementation: ").append(
210: this .serviceImplementation).append("\n");
211: sb.append("user required: ").append(this .userRequired).append(
212: "\n");
213: sb.append("load on startup: ").append(this .loadOnStartup)
214: .append("\n");
215: sb.append("config properties: ");
216: Iterator it = this .configParamList.iterator();
217: ConfigParam c;
218: while (it.hasNext()) {
219: c = (ConfigParam) it.next();
220: sb.append("\tname: ").append(c.getParamName()).append(
221: "\tvalue: ").append(c.getParamValue());
222: }
223: return sb.toString();
224: }
225:
226: }
|