001: /*
002: * Copyright 2005 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: */
013:
014: package com.sun.portal.wsrp.common.registry.ebxml;
015:
016: import com.sun.portal.wsrp.common.registry.RegistryObjectManager;
017: import com.sun.portal.wsrp.common.registry.WSRPProducer;
018: import com.sun.portal.wsrp.common.registry.WSRPOrganization;
019: import com.sun.portal.wsrp.common.registry.WSRPPortlet;
020: import com.sun.portal.wsrp.common.registry.RegistryConstants;
021: import com.sun.portal.wsrp.WSRPException;
022:
023: import java.util.Properties;
024: import java.util.Collection;
025: import java.util.Collections;
026:
027: public class RegistryObjectManagerImpl implements
028: RegistryObjectManager, RegistryConstants {
029:
030: public WSRPProducer getWSRPProducer(Properties producerData)
031: throws WSRPException {
032:
033: if (producerData == null) {
034: throw new IllegalArgumentException("producerData is null");
035: }
036: WSRPProducerImpl producer = new WSRPProducerImpl();
037: Object value = producerData
038: .get(RegistryConstants.PRODUCER_NAME);
039: if (value != null) {
040: producer.setName(value.toString());
041: } else {
042: throw new IllegalArgumentException("producer name is null");
043: }
044: value = producerData.get(RegistryConstants.PRODUCER_DESC);
045:
046: if (value != null) {
047: producer.setDescription(value.toString());
048: } else {
049: throw new IllegalArgumentException(
050: "producer description is null");
051: }
052:
053: value = producerData.get(RegistryConstants.PRODUCER_URL);
054:
055: if (value != null) {
056: producer.setProducerURL((Collection) value);
057: } else {
058: throw new IllegalArgumentException(
059: "producer description is null");
060: }
061:
062: value = producerData
063: .get(RegistryConstants.PRODUCER_REQUIRES_REG);
064:
065: if (value != null) {
066: producer.setRequiresRegistration(Boolean.valueOf(
067: value.toString()).booleanValue());
068: } else {
069: throw new IllegalArgumentException(
070: "producer requires registration is null");
071: }
072:
073: value = producerData
074: .get(RegistryConstants.PRODUCER_REQUIRES_INIT_COOKIE);
075:
076: if (value != null) {
077: producer.setRequiresInitCookie(value.toString());
078: } else {
079: throw new IllegalArgumentException(
080: "producer requires initcookie is null");
081: }
082:
083: value = producerData.get(RegistryConstants.PRODUCER_KEY);
084:
085: if (value != null) {
086: producer.setKey(value.toString());
087: }
088:
089: return producer;
090:
091: }
092:
093: public WSRPPortlet getWSRPPortlet(Properties portletData)
094: throws WSRPException {
095: WSRPPortletImpl portlet = new WSRPPortletImpl();
096: if (portletData == null) {
097: throw new IllegalArgumentException("portletData is null");
098: }
099: Object value = portletData.get(RegistryConstants.PORTLET_NAME);
100: if (value != null) {
101: portlet.setName(value.toString());
102: } else {
103: throw new IllegalArgumentException("portlet name is null");
104: }
105: value = portletData.get(RegistryConstants.PORTLET_DESC);
106:
107: if (value != null) {
108: portlet.setDescription(value.toString());
109: } else {
110: throw new IllegalArgumentException(
111: "producer description is null");
112: }
113:
114: value = portletData.get(RegistryConstants.PORTLET_HANDLE);
115:
116: if (value != null) {
117: portlet.setHandle(value.toString());
118: } else {
119: throw new IllegalArgumentException("portlet handle is null");
120: }
121:
122: value = portletData.get(RegistryConstants.PORTLET_PRODUCER_URL);
123:
124: if (value != null) {
125: portlet.setProducerURL(Collections.singletonList(value
126: .toString()));
127: } else {
128: throw new IllegalArgumentException(
129: "portlet producer url is null");
130: }
131:
132: value = portletData.get(RegistryConstants.PORTLET_MARKUPTYPE);
133:
134: if (value != null) {
135: portlet.setMarkupTypes((Collection) value);
136: } else {
137: throw new IllegalArgumentException(
138: "portlet markup type is null");
139: }
140:
141: value = portletData.get(RegistryConstants.PORTLET_KEY);
142:
143: if (value != null) {
144: portlet.setKey(value.toString());
145: }
146:
147: return portlet;
148: //TODO : Do it for offered Portlets and Producer URL
149: }
150:
151: public WSRPOrganization getWSRPOrganization(Properties orgData)
152: throws WSRPException {
153: WSRPOrganizationImpl org = new WSRPOrganizationImpl();
154:
155: if (orgData == null) {
156: throw new IllegalArgumentException("orgData is null");
157: }
158:
159: Object value = orgData.get(RegistryConstants.ORG_KEY);
160: //If Key exists, then the organization already exists in the
161: // registry hence ignoring all other details
162: if (value != null && value.toString().trim().length() > 0) {
163: org.setKey(value.toString());
164: return org;
165: }
166:
167: value = orgData.get(RegistryConstants.ORG_NAME);
168:
169: if (value != null) {
170: org.setName(value.toString());
171: } else {
172: throw new IllegalArgumentException(
173: "organization name is null");
174: }
175: value = orgData.get(RegistryConstants.ORG_DESC);
176:
177: if (value != null) {
178: org.setDescription(value.toString());
179: } else {
180: throw new IllegalArgumentException(
181: "organization description is null");
182: }
183:
184: //TODO The following are not mandatory keys hence assume default value
185: // "" -> empty string rather than throwing exception
186:
187: value = orgData.get(RegistryConstants.ORG_PRIMARYCONTACT_NAME);
188:
189: if (value != null) {
190: org.setPersonName(value.toString());
191: } else {
192: throw new IllegalArgumentException(
193: "primary contact name is null");
194: }
195: value = orgData.get(RegistryConstants.ORG_PRIMARYCONTACT_PHONE);
196:
197: if (value != null) {
198: org.setPersonPhoneNo(value.toString());
199: } else {
200: throw new IllegalArgumentException(
201: "primary contact phoneno is null");
202: }
203:
204: value = orgData.get(RegistryConstants.ORG_PRIMARYCONTACT_EMAIL);
205:
206: if (value != null) {
207: org.setEmail(value.toString());
208: } else {
209: throw new IllegalArgumentException(
210: "primary contact email is null");
211: }
212:
213: return org;
214:
215: }
216: }
|