001: /**
002: *
003: * Copyright 2004 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.ws.scout.registry;
017:
018: import java.util.ArrayList;
019: import java.util.Collection;
020: import java.util.List;
021: import java.util.Locale;
022:
023: import javax.activation.DataHandler;
024: import javax.xml.registry.BulkResponse;
025: import javax.xml.registry.InvalidRequestException;
026: import javax.xml.registry.JAXRException;
027: import javax.xml.registry.LifeCycleManager;
028: import javax.xml.registry.RegistryService;
029: import javax.xml.registry.UnsupportedCapabilityException;
030: import javax.xml.registry.infomodel.Association;
031: import javax.xml.registry.infomodel.Classification;
032: import javax.xml.registry.infomodel.ClassificationScheme;
033: import javax.xml.registry.infomodel.Concept;
034: import javax.xml.registry.infomodel.EmailAddress;
035: import javax.xml.registry.infomodel.ExternalIdentifier;
036: import javax.xml.registry.infomodel.ExternalLink;
037: import javax.xml.registry.infomodel.ExtrinsicObject;
038: import javax.xml.registry.infomodel.InternationalString;
039: import javax.xml.registry.infomodel.Key;
040: import javax.xml.registry.infomodel.LocalizedString;
041: import javax.xml.registry.infomodel.Organization;
042: import javax.xml.registry.infomodel.PersonName;
043: import javax.xml.registry.infomodel.PostalAddress;
044: import javax.xml.registry.infomodel.RegistryObject;
045: import javax.xml.registry.infomodel.RegistryPackage;
046: import javax.xml.registry.infomodel.Service;
047: import javax.xml.registry.infomodel.ServiceBinding;
048: import javax.xml.registry.infomodel.Slot;
049: import javax.xml.registry.infomodel.SpecificationLink;
050: import javax.xml.registry.infomodel.TelephoneNumber;
051: import javax.xml.registry.infomodel.User;
052:
053: import org.apache.ws.scout.registry.infomodel.AssociationImpl;
054: import org.apache.ws.scout.registry.infomodel.ClassificationImpl;
055: import org.apache.ws.scout.registry.infomodel.ClassificationSchemeImpl;
056: import org.apache.ws.scout.registry.infomodel.ConceptImpl;
057: import org.apache.ws.scout.registry.infomodel.EmailAddressImpl;
058: import org.apache.ws.scout.registry.infomodel.ExternalIdentifierImpl;
059: import org.apache.ws.scout.registry.infomodel.ExternalLinkImpl;
060: import org.apache.ws.scout.registry.infomodel.InternationalStringImpl;
061: import org.apache.ws.scout.registry.infomodel.KeyImpl;
062: import org.apache.ws.scout.registry.infomodel.LocalizedStringImpl;
063: import org.apache.ws.scout.registry.infomodel.OrganizationImpl;
064: import org.apache.ws.scout.registry.infomodel.PersonNameImpl;
065: import org.apache.ws.scout.registry.infomodel.PostalAddressImpl;
066: import org.apache.ws.scout.registry.infomodel.ServiceBindingImpl;
067: import org.apache.ws.scout.registry.infomodel.ServiceImpl;
068: import org.apache.ws.scout.registry.infomodel.SlotImpl;
069: import org.apache.ws.scout.registry.infomodel.SpecificationLinkImpl;
070: import org.apache.ws.scout.registry.infomodel.TelephoneNumberImpl;
071: import org.apache.ws.scout.registry.infomodel.UserImpl;
072: import org.apache.ws.scout.uddi.BusinessDetail;
073: import org.apache.ws.scout.uddi.BusinessInfo;
074: import org.apache.ws.scout.uddi.Description;
075: import org.apache.ws.scout.uddi.Name;
076: import org.apache.ws.scout.uddi.ServiceInfo;
077: import org.apache.ws.scout.util.ScoutUddiJaxrHelper;
078:
079: /**
080: * Implements JAXR LifeCycleManager Interface
081: * For futher details, look into the JAXR API Javadoc.
082: *
083: * @author <a href="mailto:anil@apache.org">Anil Saldhana</a>
084: * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
085: */
086: public abstract class LifeCycleManagerImpl implements LifeCycleManager {
087: protected final RegistryServiceImpl registry;
088:
089: public LifeCycleManagerImpl(RegistryService registry) {
090: this .registry = (RegistryServiceImpl) registry;
091: }
092:
093: public RegistryService getRegistryService() {
094: return registry;
095: }
096:
097: public Object createObject(String interfaceName)
098: throws JAXRException {
099: // we don't use reflection so that we can work in environments where
100: // we may not have permission to do so
101: if (LifeCycleManager.ASSOCIATION.equals(interfaceName)) {
102: return new AssociationImpl(this );
103: } else if (LifeCycleManager.AUDITABLE_EVENT
104: .equals(interfaceName)) {
105: throw new UnsupportedCapabilityException();
106: } else if (LifeCycleManager.CLASSIFICATION
107: .equals(interfaceName)) {
108: return new ClassificationImpl(this );
109: } else if (LifeCycleManager.CLASSIFICATION_SCHEME
110: .equals(interfaceName)) {
111: return new ClassificationSchemeImpl(this );
112: } else if (LifeCycleManager.CONCEPT.equals(interfaceName)) {
113: return new ConceptImpl(this );
114: } else if (LifeCycleManager.EMAIL_ADDRESS.equals(interfaceName)) {
115: return new EmailAddressImpl();
116: } else if (LifeCycleManager.EXTERNAL_IDENTIFIER
117: .equals(interfaceName)) {
118: return new ExternalIdentifierImpl(this );
119: } else if (LifeCycleManager.EXTERNAL_LINK.equals(interfaceName)) {
120: return new ExternalLinkImpl(this );
121: } else if (LifeCycleManager.EXTRINSIC_OBJECT
122: .equals(interfaceName)) {
123: throw new UnsupportedCapabilityException();
124: } else if (LifeCycleManager.INTERNATIONAL_STRING
125: .equals(interfaceName)) {
126: return new InternationalStringImpl();
127: } else if (LifeCycleManager.KEY.equals(interfaceName)) {
128: return new KeyImpl();
129: } else if (LifeCycleManager.LOCALIZED_STRING
130: .equals(interfaceName)) {
131: return new LocalizedStringImpl();
132: } else if (LifeCycleManager.ORGANIZATION.equals(interfaceName)) {
133: return new OrganizationImpl(this );
134: } else if (LifeCycleManager.PERSON_NAME.equals(interfaceName)) {
135: return new PersonNameImpl();
136: } else if (LifeCycleManager.POSTAL_ADDRESS
137: .equals(interfaceName)) {
138: return new PostalAddressImpl(registry
139: .getDefaultPostalScheme());
140: } else if (LifeCycleManager.REGISTRY_ENTRY
141: .equals(interfaceName)) {
142: throw new UnsupportedCapabilityException();
143: } else if (LifeCycleManager.REGISTRY_PACKAGE
144: .equals(interfaceName)) {
145: throw new UnsupportedCapabilityException();
146: } else if (LifeCycleManager.SERVICE.equals(interfaceName)) {
147: return new ServiceImpl(this );
148: } else if (LifeCycleManager.SERVICE_BINDING
149: .equals(interfaceName)) {
150: return new ServiceBindingImpl(this );
151: } else if (LifeCycleManager.SLOT.equals(interfaceName)) {
152: return new SlotImpl();
153: } else if (LifeCycleManager.SPECIFICATION_LINK
154: .equals(interfaceName)) {
155: return new SpecificationLinkImpl(this );
156: } else if (LifeCycleManager.TELEPHONE_NUMBER
157: .equals(interfaceName)) {
158: return new TelephoneNumberImpl();
159: } else if (LifeCycleManager.USER.equals(interfaceName)) {
160: return new UserImpl(this );
161: } else if (LifeCycleManager.VERSIONABLE.equals(interfaceName)) {
162: throw new UnsupportedCapabilityException();
163: } else {
164: throw new InvalidRequestException("Unknown interface: "
165: + interfaceName);
166: }
167: }
168:
169: public Association createAssociation(RegistryObject targetObject,
170: Concept associationType) throws JAXRException {
171: Association assoc = (Association) this
172: .createObject(LifeCycleManager.ASSOCIATION);
173: assoc.setTargetObject(targetObject);
174: assoc.setAssociationType(associationType);
175: return assoc;
176: }
177:
178: public Classification createClassification(Concept concept)
179: throws JAXRException, InvalidRequestException {
180: if (concept.getClassificationScheme() == null) {
181: throw new InvalidRequestException(
182: "Concept is not under classification scheme");
183: }
184: Classification classify = (Classification) this
185: .createObject(LifeCycleManager.CLASSIFICATION);
186: classify.setConcept(concept);
187: return classify;
188: }
189:
190: public Classification createClassification(
191: ClassificationScheme scheme, InternationalString name,
192: String value) throws JAXRException {
193: Classification cl = (Classification) this
194: .createObject(LifeCycleManager.CLASSIFICATION);
195: cl.setClassificationScheme(scheme);
196: cl.setName(name);
197: cl.setValue(value);
198:
199: ((ClassificationImpl) cl).setExternal(true);
200:
201: return cl;
202: }
203:
204: public Classification createClassification(
205: ClassificationScheme scheme, String name, String value)
206: throws JAXRException {
207: return createClassification(scheme, this
208: .createInternationalString(name), value);
209: }
210:
211: public ClassificationScheme createClassificationScheme(
212: Concept concept) throws JAXRException,
213: InvalidRequestException {
214: //Check if the passed concept has a classificationscheme or has a parent concept
215: if (concept.getParentConcept() != null
216: || concept.getClassificationScheme() != null) {
217: throw new InvalidRequestException(
218: "Concept has classificationscheme or has a parent");
219: }
220:
221: ClassificationScheme cs = new ClassificationSchemeImpl(this );
222: cs.addChildConcept(concept);
223: return cs;
224: }
225:
226: public ClassificationScheme createClassificationScheme(
227: InternationalString name, InternationalString des)
228: throws JAXRException, InvalidRequestException {
229: ClassificationScheme cs = new ClassificationSchemeImpl(this );
230: cs.setName(name);
231: cs.setDescription(des);
232: return cs;
233: }
234:
235: public ClassificationScheme createClassificationScheme(String name,
236: String desc) throws JAXRException, InvalidRequestException {
237: return createClassificationScheme(this
238: .createInternationalString(name), this
239: .createInternationalString(desc));
240: }
241:
242: public Concept createConcept(RegistryObject parent,
243: InternationalString name, String value)
244: throws JAXRException {
245: ConceptImpl concept = new ConceptImpl(this );
246: concept.setClassificationScheme((ClassificationScheme) parent);
247: concept.setParent(parent);
248: concept.setName(name);
249: concept.setValue(value);
250: return concept;
251: }
252:
253: public Concept createConcept(RegistryObject parent, String name,
254: String value) throws JAXRException {
255: return createConcept(parent, this
256: .createInternationalString(name), value);
257: }
258:
259: public EmailAddress createEmailAddress(String address)
260: throws JAXRException {
261: return new EmailAddressImpl(address);
262: }
263:
264: public EmailAddress createEmailAddress(String address, String type)
265: throws JAXRException {
266: return new EmailAddressImpl(address, type);
267: }
268:
269: public ExternalIdentifier createExternalIdentifier(
270: ClassificationScheme ids, InternationalString name,
271: String value) throws JAXRException {
272: return new ExternalIdentifierImpl(this , ids, name, value);
273: }
274:
275: public ExternalIdentifier createExternalIdentifier(
276: ClassificationScheme ids, String name, String value)
277: throws JAXRException {
278: return createExternalIdentifier(ids, this
279: .createInternationalString(name), value);
280: }
281:
282: public ExternalLink createExternalLink(String uri,
283: InternationalString desc) throws JAXRException {
284: ExternalLink ext = new ExternalLinkImpl(this );
285: ext.setExternalURI(uri);
286: ext.setDescription(desc);
287: return ext;
288: }
289:
290: public ExternalLink createExternalLink(String uri, String desc)
291: throws JAXRException {
292: return createExternalLink(uri, createInternationalString(desc));
293: }
294:
295: public InternationalString createInternationalString()
296: throws JAXRException {
297: return new InternationalStringImpl();
298: }
299:
300: public InternationalString createInternationalString(String value)
301: throws JAXRException {
302: return new InternationalStringImpl(Locale.getDefault(), value,
303: LocalizedString.DEFAULT_CHARSET_NAME);
304: }
305:
306: public InternationalString createInternationalString(Locale locale,
307: String value) throws JAXRException {
308: return new InternationalStringImpl(locale, value,
309: LocalizedString.DEFAULT_CHARSET_NAME);
310: }
311:
312: public Key createKey(String id) {
313: return new KeyImpl(id);
314: }
315:
316: public LocalizedString createLocalizedString(Locale locale,
317: String value) throws JAXRException {
318: return new LocalizedStringImpl(locale, value,
319: LocalizedString.DEFAULT_CHARSET_NAME);
320: }
321:
322: public LocalizedString createLocalizedString(Locale locale,
323: String value, String charsetName) throws JAXRException {
324: return new LocalizedStringImpl(locale, value, charsetName);
325: }
326:
327: public Organization createOrganization(InternationalString name)
328: throws JAXRException {
329: Organization org = (Organization) this
330: .createObject(LifeCycleManager.ORGANIZATION);
331: org.setName(name);
332: return org;
333: }
334:
335: public Organization createOrganization(String name)
336: throws JAXRException {
337: Organization org = (Organization) this
338: .createObject(LifeCycleManager.ORGANIZATION);
339: org.setName(this .createInternationalString(name));
340: return org;
341: }
342:
343: public PersonName createPersonName(String fullName)
344: throws JAXRException {
345: PersonName pn = (PersonName) this
346: .createObject(LifeCycleManager.PERSON_NAME);
347: pn.setFullName(fullName);
348: return pn;
349: }
350:
351: public PostalAddress createPostalAddress(String streetNumber,
352: String street, String city, String stateOrProvince,
353: String country, String postalCode, String type)
354: throws JAXRException {
355: PostalAddress post = new PostalAddressImpl();
356: post.setStreetNumber(streetNumber);
357: post.setStreet(street);
358: post.setCity(city);
359: post.setStateOrProvince(stateOrProvince);
360: post.setCountry(country);
361: post.setPostalCode(postalCode);
362: post.setType(type);
363: return post;
364: }
365:
366: public Service createService(InternationalString name)
367: throws JAXRException {
368: Service ser = (Service) this
369: .createObject(LifeCycleManager.SERVICE);
370: ser.setName(name);
371: return ser;
372: }
373:
374: public Service createService(String name) throws JAXRException {
375: return createService(this .createInternationalString(name));
376: }
377:
378: public ServiceBinding createServiceBinding() throws JAXRException {
379: return (ServiceBinding) this
380: .createObject(LifeCycleManager.SERVICE_BINDING);
381: }
382:
383: public Slot createSlot(String name, String value, String slotType)
384: throws JAXRException {
385: Collection<String> col = new ArrayList<String>();
386: col.add(value);
387: Slot slot = (Slot) this .createObject(LifeCycleManager.SLOT);
388: slot.setName(name);
389: slot.setValues(col);
390: slot.setSlotType(slotType);
391: return slot;
392: }
393:
394: public Slot createSlot(String name, Collection<String> values,
395: String slotType) throws JAXRException {
396: Slot slot = (Slot) this .createObject(LifeCycleManager.SLOT);
397: slot.setName(name);
398: slot.setValues(values);
399: slot.setSlotType(slotType);
400: return slot;
401: }
402:
403: public SpecificationLink createSpecificationLink()
404: throws JAXRException {
405: return (SpecificationLink) this
406: .createObject(LifeCycleManager.SPECIFICATION_LINK);
407: }
408:
409: public TelephoneNumber createTelephoneNumber() throws JAXRException {
410: return (TelephoneNumber) this
411: .createObject(LifeCycleManager.TELEPHONE_NUMBER);
412: }
413:
414: public User createUser() throws JAXRException {
415: return (User) this .createObject(LifeCycleManager.USER);
416: }
417:
418: /**
419: * aves one or more Objects to the registry. An object may be a
420: * RegistryObject subclass instance. If an object is not in the registry,
421: * it is created in the registry. If it already exists in the registry
422: * and has been modified, then its state is updated (replaced) in the
423: * registry
424: *
425: * @param objects
426: * @return a BulkResponse containing the Collection of keys for those objects
427: * that were saved successfully and any SaveException that was encountered
428: * in case of partial commit
429: * @throws JAXRException
430: */
431:
432: public abstract BulkResponse saveObjects(Collection objects)
433: throws JAXRException;
434:
435: /**
436: * Deletes one or more previously submitted objects from the registry
437: * using the object keys and a specified objectType attribute.
438: *
439: * @param keys
440: * @param objectType
441: * @return
442: * @throws JAXRException
443: */
444: public abstract BulkResponse deleteObjects(Collection<Key> keys,
445: String objectType) throws JAXRException;
446:
447: /*************************************************************************
448: * Level 1 Features
449: ************************************************************************/
450:
451: /**
452: * @param repositoryItem
453: * @return
454: * @throws JAXRException
455: */
456: public ExtrinsicObject createExtrinsicObject(
457: DataHandler repositoryItem) throws JAXRException {
458: throw new UnsupportedCapabilityException();
459: }
460:
461: public PersonName createPersonName(String firstName,
462: String middleName, String lastName) throws JAXRException {
463: throw new UnsupportedCapabilityException();
464: }
465:
466: public RegistryPackage createRegistryPackage(
467: InternationalString name) throws JAXRException {
468: throw new UnsupportedCapabilityException();
469: }
470:
471: public RegistryPackage createRegistryPackage(String name)
472: throws JAXRException {
473: throw new UnsupportedCapabilityException();
474: }
475:
476: public BulkResponse deprecateObjects(Collection<Key> keys)
477: throws JAXRException {
478: throw new UnsupportedCapabilityException();
479: }
480:
481: public BulkResponse unDeprecateObjects(Collection<Key> keys)
482: throws JAXRException {
483: throw new UnsupportedCapabilityException();
484: }
485:
486: public BulkResponse deleteObjects(Collection<Key> keys)
487: throws JAXRException {
488: throw new UnsupportedCapabilityException();
489: }
490:
491: Organization createOrganization(BusinessInfo info)
492: throws JAXRException {
493: String key = info.getBusinessKey();
494: Name[] names = info.getNameArray();
495: Description[] descriptions = info.getDescriptionArray();
496: ServiceInfo[] serviceInfos = info.getServiceInfos()
497: .getServiceInfoArray();
498: OrganizationImpl org = new OrganizationImpl(this );
499: org.setKey(createKey(key));
500: if (names != null && names.length > 0) {
501: org.setName(createInternationalString(((Name) names[0])
502: .getStringValue()));
503: }
504: if (descriptions != null && descriptions.length > 0) {
505: org
506: .setDescription(createInternationalString(((Description) descriptions[0])
507: .getStringValue()));
508: }
509: if (serviceInfos != null && serviceInfos.length > 0) {
510: List<Service> services = new ArrayList<Service>(
511: serviceInfos.length);
512: for (int i = 0; i < serviceInfos.length; i++) {
513: ServiceInfo serviceInfo = (ServiceInfo) serviceInfos[i];
514: services.add(createService(serviceInfo));
515: }
516: org.addServices(services);
517: }
518:
519: return org;
520: }
521:
522: Organization createOrganization(BusinessDetail detail)
523: throws JAXRException {
524: return ScoutUddiJaxrHelper.getOrganization(detail, this );
525: }
526:
527: Service createService(ServiceInfo info) throws JAXRException {
528: String key = info.getServiceKey();
529: Name[] names = info.getNameArray();
530: ServiceImpl service = new ServiceImpl(this );
531: service.setKey(createKey(key));
532: if (names != null && names.length > 0) {
533: service.setName(createInternationalString(names[0]
534: .getStringValue()));
535: }
536: return service;
537: }
538: }
|