001: /**
002: * Copyright 2003 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.wsrp.consumer.cli;
013:
014: import java.util.Map;
015: import java.util.Properties;
016: import java.util.logging.Level;
017: import java.util.logging.Logger;
018:
019: import java.net.URL;
020: import java.net.MalformedURLException;
021:
022: import com.sun.portal.wsrp.common.stubs.ServiceDescription;
023: import com.sun.portal.wsrp.common.stubs.RegistrationContext;
024: import com.sun.portal.wsrp.common.stubs.RegistrationData;
025:
026: import com.sun.portal.wsrp.common.WSRPFactory;
027: import com.sun.portal.wsrp.WSRPException;
028:
029: import com.sun.portal.wsrp.consumer.common.WSRPConsumerException;
030:
031: import com.sun.portal.wsrp.consumer.producermanager.ConsumerObjectFactory;
032: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityManager;
033: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntity;
034: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityStatus;
035: import com.sun.portal.wsrp.consumer.producermanager.InbandRegistrationNotSupportedException;
036: import com.sun.portal.log.common.PortalLogger;
037:
038: class PEAUpdate {
039:
040: public static final int TYPE_NAME = 0;
041: public static final int TYPE_URL = 1;
042: public static final int TYPE_STATUS = 2;
043: public static final int TYPE_SERVICE_DESCRIPTION = 3;
044: public static final int TYPE_REGISTRATION = 4;
045: public static final int TYPE_ALLOWED_USER_PROFILE_MAPPING = 5;
046: public static final int TYPE_CUSTOM_USER_PROFILE_MAPPING = 6;
047: public static final int TYPE_USER_CATEGORY_MAPPING = 7;
048: public static final int TYPE_DEFAULT_REGISTRATION = 8;
049: public static final int TYPE_STANDARD_USER_PROFILE_MAPPING = 9;
050: public static final int TYPE_CONSUMER_NAME = 10;
051:
052: protected static int type = -1;
053:
054: //
055: // lazy instantiation - use getWSRPFactory() to get a handle
056: //
057: private static WSRPFactory factory = null;
058:
059: //
060: // lazy instantiation - use getConsumerObjectFactory() to get a handle
061: //
062: private static ConsumerObjectFactory cofactory = null;
063:
064: private static Logger logger = PortalLogger
065: .getLogger(PEAUpdate.class);
066:
067: public void process(ProducerEntityManager pem, String dn,
068: String pid, String uType, String input, boolean verbose)
069: throws PEAException {
070:
071: //
072: // sanity check on the type option
073: //
074: if (uType.toLowerCase().equals("name")) {
075: type = TYPE_NAME;
076: } else if (uType.toLowerCase().equals("status")) {
077: type = TYPE_STATUS;
078: } else if (uType.toLowerCase().equals("service_description")) {
079: type = TYPE_SERVICE_DESCRIPTION;
080: } else if (uType.toLowerCase().equals("registration")) {
081: type = TYPE_REGISTRATION;
082: } else if (uType.toLowerCase().equals("default_registration")) {
083: type = TYPE_DEFAULT_REGISTRATION;
084: } else if (uType.toLowerCase().equals("user_category_map")) {
085: type = TYPE_USER_CATEGORY_MAPPING;
086: //
087: // TBD: not implemented yet
088: //
089: /*
090: } else if (uType.toLowerCase().equals("url")) {
091: type = TYPE_URL;
092: } else if (uType.toLowerCase().equals("allowed_user_profile_map")) {
093: type = TYPE_ALLOWED_USER_PROFILE_MAPPING;
094: } else if (uType.toLowerCase().equals("custom_user_profile_map")) {
095: type = TYPE_CUSTOM_USER_PROFILE_MAPPING;
096: } else if (uType.toLowerCase().equals("standard_user_profile_map")) {
097: type = TYPE_STANDARD_USER_PROFILE_MAPPING;
098: */
099: } else if (uType.toLowerCase().equals("consumer_name")) {
100: type = TYPE_CONSUMER_NAME;
101: } else {
102: Object[] tokens = { uType };
103: throw new PEAException("errorInvalidType", tokens);
104: }
105:
106: //
107: // pid required for some types
108: //
109: if (type != TYPE_DEFAULT_REGISTRATION
110: && type != TYPE_STANDARD_USER_PROFILE_MAPPING
111: && type != TYPE_CONSUMER_NAME) {
112: if (pid == null) {
113: Object[] tokens = { uType };
114: throw new PEAException("errorNoPID", tokens);
115: }
116: }
117:
118: //
119: // input is required for all types except for service description
120: //
121: if (type != TYPE_SERVICE_DESCRIPTION) {
122: if (input == null || input.length() == 0) {
123: Object[] tokens = { uType };
124: throw new PEAException("errorInputRequired", tokens);
125: }
126: }
127:
128: //
129: // dispatch command
130: //
131: switch (type) {
132: case TYPE_NAME:
133: updateName(pem, pid, input, verbose);
134: break;
135: case TYPE_URL:
136: updateURL(pem, pid, input, verbose);
137: break;
138: case TYPE_STATUS:
139: updateStatus(pem, pid, input, verbose);
140: break;
141: case TYPE_SERVICE_DESCRIPTION:
142: updateServiceDescription(pem, pid, verbose);
143: break;
144: case TYPE_REGISTRATION:
145: String fileInput = PEACommand.getFileInput(input);
146: updateRegistration(dn, pem, pid, fileInput, verbose);
147: break;
148: case TYPE_ALLOWED_USER_PROFILE_MAPPING:
149: case TYPE_CUSTOM_USER_PROFILE_MAPPING:
150: case TYPE_USER_CATEGORY_MAPPING:
151: case TYPE_STANDARD_USER_PROFILE_MAPPING:
152: fileInput = PEACommand.getFileInput(input);
153: updateMapping(pem, pid, type, fileInput, verbose);
154: break;
155: case TYPE_DEFAULT_REGISTRATION:
156: fileInput = PEACommand.getFileInput(input);
157: updateDefaultRegistration(pem, fileInput, verbose);
158: break;
159: case TYPE_CONSUMER_NAME:
160: updateConsumerName(pem, input, verbose);
161: }
162: }
163:
164: protected void updateName(ProducerEntityManager pem, String pid,
165: String name, boolean verbose) throws PEAException {
166:
167: if (logger.isLoggable(Level.FINEST)) {
168: Object[] tokens = { pid, name };
169: logger.log(Level.FINEST, "PSWS_CSPWCCL0021", tokens);
170: }
171:
172: try {
173: pem.setName(pid, name);
174: } catch (WSRPConsumerException wce) {
175: Object[] tokens = { pid, name };
176: throw new PEAException("errorUpdateName", wce, tokens);
177: }
178: }
179:
180: protected void updateURL(ProducerEntityManager pem, String pid,
181: String url, boolean verbose) throws PEAException {
182:
183: if (logger.isLoggable(Level.FINEST)) {
184: Object[] tokens = { pid, url };
185: logger.log(Level.FINEST, "PSWS_CSPWCCL0022", tokens);
186: }
187:
188: URL u = null;
189: try {
190: u = new URL(url);
191: } catch (MalformedURLException mue) {
192: Object[] tokens = { pid, url };
193: throw new PEAException("errorInvalidURL", mue, tokens);
194: }
195:
196: //
197: // TBD: PEM.setURL() not availble yet
198: //
199: /*
200: try {
201: pem.setURL(pid, u);
202: } catch (WSRPConsumerException wce) {
203: Object[] tokens = { pid, u };
204: throw new PEAException("errorUpdateURL", wce, tokens);
205: }
206: */
207: }
208:
209: protected void updateStatus(ProducerEntityManager pem, String pid,
210: String status, boolean verbose) throws PEAException {
211:
212: ProducerEntityStatus ps = ProducerEntityStatus
213: .getProducerEntityStatus(status);
214:
215: if (logger.isLoggable(Level.FINEST)) {
216: Object[] tokens = { pid, ps.toString() };
217: logger.log(Level.FINEST, "PSWS_CSPWCCL0023", tokens);
218: }
219:
220: try {
221: pem.setStatus(pid, ps);
222: } catch (WSRPConsumerException wce) {
223: Object[] tokens = { pid, status };
224: throw new PEAException("errorUpdateStatus", wce, tokens);
225: }
226: }
227:
228: protected void updateServiceDescription(ProducerEntityManager pem,
229: String pid, boolean verbose) throws PEAException {
230:
231: if (logger.isLoggable(Level.FINEST)) {
232: Object[] tokens = { pid };
233: logger.log(Level.FINEST, "PSWS_CSPWCCL0024", tokens);
234: }
235:
236: try {
237: pem.updateServiceDescription(pid);
238: } catch (WSRPConsumerException wce) {
239: Object[] tokens = { pid };
240: throw new PEAException("errorUpdateSD", wce, tokens);
241: }
242: }
243:
244: protected void updateRegistration(String dn,
245: ProducerEntityManager pem, String pid, String rdXML,
246: boolean verbose) throws PEAException {
247:
248: if (logger.isLoggable(Level.FINEST)) {
249: Object[] tokens = { pid };
250: logger.log(Level.FINEST, "PSWS_CSPWCCL0025", tokens);
251: }
252:
253: ProducerEntity pe = null;
254: try {
255: pe = pem.getProducerEntity(pid);
256: } catch (WSRPConsumerException wce) {
257: Object[] tokens = { dn, pid };
258: throw new PEAException("errorGetPE", wce, tokens);
259: }
260:
261: if (pe == null) {
262: Object[] tokens = { dn, pid };
263: throw new PEAException("errorInvalidPID", tokens);
264: }
265:
266: try {
267: RegistrationData registrationData = getWSRPFactory()
268: .getRegistrationData(rdXML);
269:
270: pem.modifyRegistration(pid, registrationData);
271:
272: } catch (InbandRegistrationNotSupportedException irnse) {
273: Object[] tokens = { dn, pe.getURL() };
274: throw new PEAException("errorNoInband", irnse, tokens);
275: } catch (WSRPConsumerException wce) {
276: Object[] tokens = { pid };
277: throw new PEAException("errorUpdateReg", wce, tokens);
278: } catch (WSRPException we) {
279: Object[] tokens = { rdXML };
280: throw new PEAException("errorParseReg", we, tokens);
281: }
282: }
283:
284: protected void updateMapping(ProducerEntityManager pem, String pid,
285: int type, String mapString, boolean verbose)
286: throws PEAException {
287:
288: if (type == TYPE_USER_CATEGORY_MAPPING) {
289: Map ucMap = null;
290: try {
291: ucMap = getConsumerObjectFactory().getMap(mapString);
292: } catch (WSRPConsumerException wce) {
293: throw new PEAException("errorParseXML", wce);
294: }
295:
296: if (ucMap != null && ucMap.size() > 0) {
297: try {
298: pem.setUserCategoryMapping(pid, ucMap);
299: } catch (WSRPConsumerException wce) {
300: Object[] tokens = { pid, ucMap };
301: throw new PEAException("errorSetUC", wce, tokens);
302: }
303: }
304: } else {
305: //
306: // TBD: yet to be implemented
307: //
308: }
309: }
310:
311: protected void updateDefaultRegistration(ProducerEntityManager pem,
312: String rdXML, boolean verbose) throws PEAException {
313:
314: if (logger.isLoggable(Level.FINEST))
315: logger.log(Level.FINEST, "PSWS_CSPWCCL0026");
316:
317: try {
318: RegistrationData defRegistrationData = getWSRPFactory()
319: .getRegistrationData(rdXML);
320:
321: pem.setDefaultRegistrationData(defRegistrationData);
322: } catch (WSRPConsumerException wce) {
323: throw new PEAException("errorUpdateRegData", wce);
324: } catch (WSRPException we) {
325: Object[] tokens = { rdXML };
326: throw new PEAException("errorParseReg", we, tokens);
327: }
328: }
329:
330: protected void updateConsumerName(ProducerEntityManager pem,
331: String name, boolean verbose) throws PEAException {
332:
333: if (logger.isLoggable(Level.FINEST)) {
334: Object[] tokens = { name };
335: logger.log(Level.FINEST, "PSWS_CSPWCCL0027");
336: }
337:
338: try {
339: pem.setConsumerName(name);
340: } catch (WSRPConsumerException wce) {
341: Object[] tokens = { name };
342: throw new PEAException("errorUpdateConsumerName", wce,
343: tokens);
344: }
345: }
346:
347: private WSRPFactory getWSRPFactory() throws WSRPException {
348: if (factory == null) {
349: factory = WSRPFactory.getInstance();
350: }
351: return factory;
352: }
353:
354: private ConsumerObjectFactory getConsumerObjectFactory()
355: throws WSRPConsumerException {
356:
357: if (cofactory == null) {
358: cofactory = ConsumerObjectFactory.getInstance();
359: }
360: return cofactory;
361: }
362: }
|