01: /**
02: * $Id: DefaultRegistrationValidator.java,v 1.3 2005/02/08 06:41:56 sm140826 Exp $
03: * Copyright 2003 Sun Microsystems, Inc. All
04: * rights reserved. Use of this product is subject
05: * to license terms. Federal Acquisitions:
06: * Commercial Software -- Government Users
07: * Subject to Standard License Terms and
08: * Conditions.
09: *
10: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
11: * are trademarks or registered trademarks of Sun Microsystems,
12: * Inc. in the United States and other countries.
13: */package com.sun.portal.wsrp.producer.registration.validator.impl;
14:
15: import com.sun.portal.wsrp.common.stubs.MissingParametersFault;
16: import com.sun.portal.wsrp.common.stubs.RegistrationData;
17: import com.sun.portal.wsrp.common.stubs.ServiceDescription;
18: import com.sun.portal.wsrp.common.stubs.OperationFailedFault;
19: import com.sun.portal.wsrp.common.stubs.ModelDescription;
20: import com.sun.portal.wsrp.common.stubs.PropertyDescription;
21: import com.sun.portal.wsrp.common.stubs.Property;
22:
23: import com.sun.portal.wsrp.producer.registration.validator.RegistrationValidator;
24:
25: import com.iplanet.am.util.Debug;
26:
27: public class DefaultRegistrationValidator implements
28: RegistrationValidator {
29: public DefaultRegistrationValidator() {
30: // nothing
31: }
32:
33: /**
34: * This method returns three possible codes.
35: * 0=succes
36: * -1=Missing Registration Property
37: * -2=Unknown failure
38: */
39: public int validate(RegistrationData registrationData,
40: ServiceDescription serviceDescription) {
41: int code = 0;
42:
43: try {
44: ModelDescription rpds = serviceDescription
45: .getRegistrationPropertyDescription();
46: PropertyDescription[] pds = rpds.getPropertyDescriptions();
47:
48: Property[] rps = registrationData
49: .getRegistrationProperties();
50:
51: //
52: // for every registration property description in the
53: // service description, make sure that the
54: // registration properties contains a like-named
55: // property and that the like-named property's value
56: // is non-null and not empty
57: //
58:
59: for (int i = 0; pds == null || i < pds.length; i++) {
60: String name = pds[i].getName();
61:
62: String value = getPropertyValue(rps, name);
63: if (value == null || value.trim().length() == 0) {
64: code = -1;
65: break;
66: }
67: }
68: } catch (Throwable t) {
69: t.printStackTrace(System.err);
70: return -2;
71: }
72:
73: return code;
74: }
75:
76: private static String getPropertyValue(Property[] properties,
77: String name) {
78: if (properties == null) {
79: return null;
80: }
81:
82: String value = null;
83:
84: for (int i = 0; i < properties.length; i++) {
85: if (properties[i].getName().equals(name)) {
86: value = properties[i].getStringValue();
87: break;
88: }
89: }
90:
91: return value;
92: }
93: }
|