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.io.Serializable;
019: import java.net.PasswordAuthentication;
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.HashSet;
023: import java.util.Iterator;
024: import java.util.LinkedHashSet;
025: import java.util.Set;
026: import java.util.Vector;
027:
028: import javax.xml.registry.BulkResponse;
029: import javax.xml.registry.BusinessLifeCycleManager;
030: import javax.xml.registry.DeleteException;
031: import javax.xml.registry.InvalidRequestException;
032: import javax.xml.registry.JAXRException;
033: import javax.xml.registry.JAXRResponse;
034: import javax.xml.registry.LifeCycleManager;
035: import javax.xml.registry.RegistryService;
036: import javax.xml.registry.SaveException;
037: import javax.xml.registry.UnexpectedObjectException;
038: import javax.xml.registry.infomodel.Association;
039: import javax.xml.registry.infomodel.ClassificationScheme;
040: import javax.xml.registry.infomodel.Concept;
041: import javax.xml.registry.infomodel.Key;
042: import javax.xml.registry.infomodel.Organization;
043: import javax.xml.registry.infomodel.RegistryObject;
044: import javax.xml.registry.infomodel.Service;
045: import javax.xml.registry.infomodel.ServiceBinding;
046:
047: import org.apache.commons.logging.Log;
048: import org.apache.commons.logging.LogFactory;
049: import org.apache.ws.scout.registry.infomodel.ConceptImpl;
050: import org.apache.ws.scout.registry.infomodel.InternationalStringImpl;
051: import org.apache.ws.scout.registry.infomodel.KeyImpl;
052: import org.apache.ws.scout.uddi.AssertionStatusItem;
053: import org.apache.ws.scout.uddi.AssertionStatusReport;
054: import org.apache.ws.scout.uddi.AuthToken;
055: import org.apache.ws.scout.uddi.BindingDetail;
056: import org.apache.ws.scout.uddi.BindingTemplate;
057: import org.apache.ws.scout.uddi.BusinessDetail;
058: import org.apache.ws.scout.uddi.BusinessEntity;
059: import org.apache.ws.scout.uddi.BusinessService;
060: import org.apache.ws.scout.uddi.DispositionReport;
061: import org.apache.ws.scout.uddi.ErrInfo;
062: import org.apache.ws.scout.uddi.KeyedReference;
063: import org.apache.ws.scout.uddi.PublisherAssertion;
064: import org.apache.ws.scout.uddi.PublisherAssertions;
065: import org.apache.ws.scout.uddi.Result;
066: import org.apache.ws.scout.uddi.ServiceDetail;
067: import org.apache.ws.scout.uddi.TModel;
068: import org.apache.ws.scout.uddi.TModelDetail;
069: import org.apache.ws.scout.util.ScoutJaxrUddiHelper;
070: import org.apache.xmlbeans.XmlObject;
071:
072: /**
073: * Implements JAXR BusinessLifeCycleManager Interface.
074: * For futher details, look into the JAXR API Javadoc.
075: *
076: * @author <a href="mailto:anil@apache.org">Anil Saldhana</a>
077: * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
078: */
079: public class BusinessLifeCycleManagerImpl extends LifeCycleManagerImpl
080: implements BusinessLifeCycleManager, Serializable {
081:
082: private static final long serialVersionUID = 1L;
083: private Log log = LogFactory.getLog(this .getClass());
084:
085: public BusinessLifeCycleManagerImpl(RegistryService registry) {
086: super (registry);
087: }
088:
089: /**
090: * Deletes one or more previously submitted objects from the registry
091: * using the object keys and a specified objectType attribute.
092: *
093: * @param keys
094: * @param objectType
095: * @return
096: * @throws JAXRException
097: */
098: public BulkResponse deleteObjects(Collection<Key> keys,
099: String objectType) throws JAXRException {
100: BulkResponse bulk = null;
101:
102: if (objectType == LifeCycleManager.ASSOCIATION) {
103: bulk = this .deleteAssociations(keys);
104: } else if (objectType == LifeCycleManager.CLASSIFICATION_SCHEME) {
105: bulk = this .deleteClassificationSchemes(keys);
106: } else if (objectType == LifeCycleManager.CONCEPT) {
107: bulk = this .deleteConcepts(keys);
108: } else if (objectType == LifeCycleManager.ORGANIZATION) {
109: bulk = this .deleteOrganizations(keys);
110: } else if (objectType == LifeCycleManager.SERVICE) {
111: bulk = this .deleteServices(keys);
112: } else if (objectType == LifeCycleManager.SERVICE_BINDING) {
113: bulk = this .deleteServiceBindings(keys);
114: } else {
115: throw new JAXRException("Delete Operation for "
116: + objectType + " not implemented by Scout");
117: }
118:
119: return bulk;
120: }
121:
122: public BulkResponse deleteAssociations(
123: Collection<Key> associationKeys) throws JAXRException {
124: return this .deleteOperation(associationKeys,
125: "DELETE_ASSOCIATION");
126: }
127:
128: public BulkResponse deleteClassificationSchemes(
129: Collection<Key> schemeKeys) throws JAXRException {
130: return this .deleteOperation(schemeKeys,
131: "DELETE_CLASSIFICATIONSCHEME");
132: }
133:
134: public BulkResponse deleteConcepts(Collection<Key> conceptKeys)
135: throws JAXRException {
136: return this .deleteOperation(conceptKeys, "DELETE_CONCEPT");
137: }
138:
139: public BulkResponse deleteOrganizations(Collection<Key> orgkeys)
140: throws JAXRException {
141: return this .deleteOperation(orgkeys, "DELETE_ORG");
142: }
143:
144: public BulkResponse deleteServiceBindings(
145: Collection<Key> bindingKeys) throws JAXRException {
146: return this .deleteOperation(bindingKeys,
147: "DELETE_SERVICEBINDING");
148: }
149:
150: public BulkResponse deleteServices(Collection<Key> serviceKeys)
151: throws JAXRException {
152: return this .deleteOperation(serviceKeys, "DELETE_SERVICE");
153: }
154:
155: /**
156: * Saves one or more Objects to the registry. An object may be a
157: * RegistryObject subclass instance. If an object is not in the registry,
158: * it is created in the registry. If it already exists in the registry
159: * and has been modified, then its state is updated (replaced) in the
160: * registry
161: * <p/>
162: * TODO:Check if juddi can provide a facility to store a collection of heterogenous
163: * objects
164: * <p/>
165: * TODO - does this belong here? it's really an overload of
166: * LifecycleManager.saveObjects, but all the help we need
167: * like saveOrganization() is up here...
168: *
169: * @param col
170: * @return a BulkResponse containing the Collection of keys for those objects
171: * that were saved successfully and any SaveException that was encountered
172: * in case of partial commit
173: * @throws JAXRException
174: */
175: public BulkResponse saveObjects(Collection col)
176: throws JAXRException {
177:
178: Iterator iter = col.iterator();
179:
180: LinkedHashSet<Object> suc = new LinkedHashSet<Object>();
181: Collection<Exception> exc = new ArrayList<Exception>();
182:
183: while (iter.hasNext()) {
184: RegistryObject reg = (RegistryObject) iter.next();
185:
186: BulkResponse br = null;
187:
188: Collection<RegistryObject> c = new ArrayList<RegistryObject>();
189: c.add(reg);
190:
191: if (reg instanceof javax.xml.registry.infomodel.Association) {
192: br = saveAssociations(c, true);
193: } else if (reg instanceof javax.xml.registry.infomodel.ClassificationScheme) {
194: br = saveClassificationSchemes(c);
195: } else if (reg instanceof javax.xml.registry.infomodel.Concept) {
196: br = saveConcepts(c);
197: } else if (reg instanceof javax.xml.registry.infomodel.Organization) {
198: br = saveOrganizations(c);
199: } else if (reg instanceof javax.xml.registry.infomodel.Service) {
200: br = saveServices(c);
201: } else if (reg instanceof javax.xml.registry.infomodel.ServiceBinding) {
202: br = saveServiceBindings(c);
203: } else {
204: throw new JAXRException("Delete Operation for "
205: + reg.getClass() + " not implemented by Scout");
206: }
207:
208: if (br.getCollection() != null) {
209: suc.addAll(br.getCollection());
210: }
211:
212: if (br.getExceptions() != null) {
213: exc.addAll(br.getExceptions());
214: }
215: }
216:
217: BulkResponseImpl bulk = new BulkResponseImpl();
218:
219: /*
220: * TODO - what is the right status?
221: */
222: bulk.setStatus(JAXRResponse.STATUS_SUCCESS);
223:
224: bulk.setCollection(suc);
225: bulk.setExceptions(exc);
226:
227: return bulk;
228: }
229:
230: public BulkResponse saveAssociations(Collection associations,
231: boolean replace) throws JAXRException {
232: BulkResponseImpl bulk = new BulkResponseImpl();
233: PublisherAssertion[] sarr = new PublisherAssertion[associations
234: .size()];
235:
236: Collection<Key> coll = new ArrayList<Key>();
237: Collection<Exception> exceptions = new ArrayList<Exception>();
238:
239: Iterator iter = associations.iterator();
240: int currLoc = 0;
241: while (iter.hasNext()) {
242:
243: Association association = (Association) iter.next();
244: association.getSourceObject();
245: PublisherAssertion pa = ScoutJaxrUddiHelper
246: .getPubAssertionFromJAXRAssociation(association);
247: sarr[currLoc] = pa;
248: currLoc++;
249:
250: // Save PublisherAssertion
251: PublisherAssertions bd = null;
252: try {
253: bd = (PublisherAssertions) executeOperation(sarr,
254: "SAVE_ASSOCIATION");
255: } catch (RegistryException e) {
256: exceptions.add(new SaveException(e));
257: bulk.setExceptions(exceptions);
258: bulk.setStatus(JAXRResponse.STATUS_FAILURE);
259: return bulk;
260: }
261: if (bd != null) {
262: PublisherAssertion[] keyarr = bd
263: .getPublisherAssertionArray();
264: for (int i = 0; keyarr != null && i < keyarr.length; i++) {
265: PublisherAssertion result = (PublisherAssertion) keyarr[i];
266: KeyedReference keyr = result.getKeyedReference();
267: Concept c = new ConceptImpl(getRegistryService()
268: .getBusinessLifeCycleManager());
269: c.setName(new InternationalStringImpl(keyr
270: .getKeyName()));
271: c.setKey(new KeyImpl(keyr.getTModelKey()));
272: c.setValue(keyr.getKeyValue());
273: association.setAssociationType(c);
274: coll.add(association.getKey());
275: }
276: }
277: }
278: bulk.setCollection(coll);
279: bulk.setExceptions(exceptions);
280:
281: return bulk;
282: }
283:
284: public BulkResponse saveClassificationSchemes(Collection schemes)
285: throws JAXRException {
286: //Now we need to convert the collection into a vector for juddi
287: BulkResponseImpl bulk = new BulkResponseImpl();
288: TModel[] entityarr = new TModel[schemes.size()];
289:
290: LinkedHashSet<Key> coll = new LinkedHashSet<Key>();
291: Collection<Exception> exceptions = new ArrayList<Exception>();
292:
293: Iterator iter = schemes.iterator();
294: int currLoc = 0;
295: while (iter.hasNext()) {
296: try {
297: TModel en = ScoutJaxrUddiHelper
298: .getTModelFromJAXRClassificationScheme((ClassificationScheme) iter
299: .next());
300: entityarr[currLoc] = en;
301: currLoc++;
302: } catch (ClassCastException ce) {
303: throw new UnexpectedObjectException();
304: }
305: }
306: log.debug("Method:save_classificationscheme: ENlength="
307: + entityarr.length);
308: // Save business
309: TModelDetail td = null;
310: try {
311: td = (TModelDetail) executeOperation(entityarr,
312: "SAVE_TMODEL");
313: } catch (RegistryException e) {
314: exceptions.add(new SaveException(e.getLocalizedMessage()));
315: bulk.setStatus(JAXRResponse.STATUS_FAILURE);
316: return bulk;
317: }
318:
319: entityarr = td.getTModelArray();
320: log.debug("After Saving TModel. Obtained vector size:"
321: + entityarr != null ? entityarr.length : 0);
322: for (int i = 0; entityarr != null && i < entityarr.length; i++) {
323: TModel tm = (TModel) entityarr[i];
324: coll.add(new KeyImpl(tm.getTModelKey()));
325: }
326:
327: bulk.setCollection(coll);
328: bulk.setExceptions(exceptions);
329:
330: return bulk;
331: }
332:
333: public BulkResponse saveConcepts(Collection concepts)
334: throws JAXRException {
335: //Now we need to convert the collection into a vector for juddi
336: BulkResponseImpl bulk = new BulkResponseImpl();
337: TModel[] entityarr = new TModel[concepts.size()];
338:
339: LinkedHashSet<Key> coll = new LinkedHashSet<Key>();
340: Collection<Exception> exceptions = new ArrayList<Exception>();
341:
342: Iterator iter = concepts.iterator();
343: int currLoc = 0;
344: while (iter.hasNext()) {
345: try {
346: TModel en = ScoutJaxrUddiHelper
347: .getTModelFromJAXRConcept((Concept) iter.next());
348: entityarr[currLoc] = en;
349: currLoc++;
350: } catch (ClassCastException ce) {
351: throw new UnexpectedObjectException();
352: }
353: }
354: log.debug("Method:save_concept: ENlength=" + entityarr.length);
355: // Save business
356: TModelDetail td = null;
357: try {
358: td = (TModelDetail) executeOperation(entityarr,
359: "SAVE_TMODEL");
360: } catch (RegistryException e) {
361: exceptions.add(new SaveException(e.getLocalizedMessage()));
362: bulk.setStatus(JAXRResponse.STATUS_FAILURE);
363: return bulk;
364: }
365:
366: entityarr = td.getTModelArray();
367: log.debug("After Saving TModel. Obtained vector size:"
368: + entityarr != null ? entityarr.length : 0);
369: for (int i = 0; entityarr != null && i < entityarr.length; i++) {
370: TModel tm = (TModel) entityarr[i];
371: coll.add(new KeyImpl(tm.getTModelKey()));
372: }
373:
374: bulk.setCollection(coll);
375: bulk.setExceptions(exceptions);
376:
377: return bulk;
378: }
379:
380: public BulkResponse saveOrganizations(Collection organizations)
381: throws JAXRException {
382: //Now we need to convert the collection into a vector for juddi
383: BulkResponseImpl bulk = new BulkResponseImpl();
384: BusinessEntity[] entityarr = new BusinessEntity[organizations
385: .size()];
386:
387: LinkedHashSet<Key> coll = new LinkedHashSet<Key>();
388: Collection<Exception> exceptions = new ArrayList<Exception>();
389:
390: Iterator iter = organizations.iterator();
391: int currLoc = 0;
392: while (iter.hasNext()) {
393: try {
394: BusinessEntity en = ScoutJaxrUddiHelper
395: .getBusinessEntityFromJAXROrg((Organization) iter
396: .next());
397: entityarr[currLoc] = en;
398: currLoc++;
399: } catch (ClassCastException ce) {
400: throw new UnexpectedObjectException();
401: }
402: }
403: log.debug("Method:save_business: ENlength=" + entityarr.length);
404: // Save business
405: BusinessDetail bd = null;
406: try {
407: bd = (BusinessDetail) executeOperation(entityarr,
408: "SAVE_ORG");
409: } catch (RegistryException e) {
410: exceptions.add(new SaveException(e.getLocalizedMessage()));
411: bulk.setStatus(JAXRResponse.STATUS_FAILURE);
412: return bulk;
413: }
414:
415: entityarr = bd.getBusinessEntityArray();
416: log.debug("After Saving Business. Obtained vector size:"
417: + entityarr != null ? entityarr.length : 0);
418: for (int i = 0; entityarr != null && i < entityarr.length; i++) {
419: BusinessEntity entity = (BusinessEntity) entityarr[i];
420: coll.add(new KeyImpl(entity.getBusinessKey()));
421: }
422:
423: bulk.setCollection(coll);
424: bulk.setExceptions(exceptions);
425:
426: return bulk;
427: }
428:
429: public BulkResponse saveServiceBindings(Collection bindings)
430: throws JAXRException {
431: BulkResponseImpl bulk = new BulkResponseImpl();
432: BindingTemplate[] sbarr = new BindingTemplate[bindings.size()];
433:
434: LinkedHashSet<Key> coll = new LinkedHashSet<Key>();
435: Collection<Exception> exceptions = new ArrayList<Exception>();
436:
437: Iterator iter = bindings.iterator();
438: int currLoc = 0;
439: while (iter.hasNext()) {
440: try {
441: BindingTemplate bs = ScoutJaxrUddiHelper
442: .getBindingTemplateFromJAXRSB((ServiceBinding) iter
443: .next());
444: sbarr[currLoc] = bs;
445: currLoc++;
446: } catch (ClassCastException ce) {
447: throw new UnexpectedObjectException();
448: }
449: }
450: // Save ServiceBinding
451: BindingDetail bd = null;
452: try {
453: bd = (BindingDetail) executeOperation(sbarr,
454: "SAVE_SERVICE_BINDING");
455: } catch (RegistryException e) {
456: exceptions.add(new SaveException(e.getLocalizedMessage()));
457: bulk.setStatus(JAXRResponse.STATUS_FAILURE);
458: return bulk;
459: }
460:
461: sbarr = bd.getBindingTemplateArray();
462: for (int i = 0; sbarr != null && i < sbarr.length; i++) {
463: BindingTemplate bt = (BindingTemplate) sbarr[i];
464: coll.add(new KeyImpl(bt.getBindingKey()));
465: }
466: if (coll.size() > 0) {
467: bulk.setCollection(coll);
468: }
469: bulk.setExceptions(exceptions);
470:
471: return bulk;
472: }
473:
474: public BulkResponse saveServices(Collection services)
475: throws JAXRException {
476: BulkResponseImpl bulk = new BulkResponseImpl();
477: BusinessService[] sarr = new BusinessService[services.size()];
478:
479: LinkedHashSet<Key> coll = new LinkedHashSet<Key>();
480: Collection<Exception> exceptions = new ArrayList<Exception>();
481:
482: Iterator iter = services.iterator();
483: int currLoc = 0;
484: while (iter.hasNext()) {
485: try {
486: BusinessService bs = ScoutJaxrUddiHelper
487: .getBusinessServiceFromJAXRService((Service) iter
488: .next());
489: sarr[currLoc] = bs;
490: currLoc++;
491: } catch (ClassCastException ce) {
492: throw new UnexpectedObjectException();
493: }
494: }
495: // Save Service
496: ServiceDetail sd = null;
497: try {
498: sd = (ServiceDetail) executeOperation(sarr, "SAVE_SERVICE");
499: } catch (RegistryException e) {
500: exceptions.add(new SaveException(e.getLocalizedMessage()));
501: bulk.setStatus(JAXRResponse.STATUS_FAILURE);
502: return bulk;
503: }
504:
505: sarr = sd.getBusinessServiceArray();
506: for (int i = 0; sarr != null && i < sarr.length; i++) {
507: BusinessService entity = (BusinessService) sarr[i];
508: coll.add(new KeyImpl(entity.getServiceKey()));
509: }
510: bulk.setCollection(coll);
511: bulk.setExceptions(exceptions);
512:
513: return bulk;
514: }
515:
516: public void confirmAssociation(Association assoc)
517: throws JAXRException, InvalidRequestException {
518: //Store it in the UDDI registry
519: HashSet<Association> col = new HashSet<Association>();
520: col.add(assoc);
521: BulkResponse br = this .saveAssociations(col, true);
522: if (br.getExceptions() != null)
523: throw new JAXRException("Confiming the Association Failed");
524: }
525:
526: public void unConfirmAssociation(Association assoc)
527: throws JAXRException, InvalidRequestException {
528: //TODO
529: //Delete it from the UDDI registry
530: Collection<Key> col = new ArrayList<Key>();
531: col.add(assoc.getKey());
532: BulkResponse br = this .deleteAssociations(col);
533: if (br.getExceptions() != null)
534: throw new JAXRException(
535: "UnConfiming the Association Failed");
536: }
537:
538: //Protected Methods
539: protected XmlObject executeOperation(Object dataarray, String op)
540: throws RegistryException, JAXRException {
541: if (registry == null) {
542: throw new IllegalStateException("No registry");
543: }
544:
545: IRegistry ireg = registry.getRegistry();
546:
547: ConnectionImpl connection = registry.getConnection();
548: AuthToken token = getAuthToken(connection, ireg);
549: if (token == null) {
550: throw new IllegalStateException("No auth token returned");
551: }
552:
553: XmlObject regobj;
554: if (op.equalsIgnoreCase("SAVE_ASSOCIATION")) {
555: regobj = ireg.setPublisherAssertions(token.getAuthInfo(),
556: (PublisherAssertion[]) dataarray);
557: } else if (op.equalsIgnoreCase("SAVE_SERVICE")) {
558: regobj = ireg.saveService(token.getAuthInfo(),
559: (BusinessService[]) dataarray);
560: } else if (op.equalsIgnoreCase("SAVE_SERVICE_BINDING")) {
561: regobj = ireg.saveBinding(token.getAuthInfo(),
562: (BindingTemplate[]) dataarray);
563: } else if (op.equalsIgnoreCase("SAVE_ORG")) {
564: regobj = ireg.saveBusiness(token.getAuthInfo(),
565: (BusinessEntity[]) dataarray);
566: } else if (op.equalsIgnoreCase("SAVE_TMODEL")) {
567: regobj = ireg.saveTModel(token.getAuthInfo(),
568: (TModel[]) dataarray);
569: } else if (op.equalsIgnoreCase("DELETE_ORG")) {
570: clearPublisherAssertions(token.getAuthInfo(),
571: (String[]) dataarray, ireg);
572: regobj = ireg.deleteBusiness(token.getAuthInfo(),
573: (String[]) dataarray);
574: } else if (op.equalsIgnoreCase("DELETE_SERVICE")) {
575: regobj = ireg.deleteService(token.getAuthInfo(),
576: (String[]) dataarray);
577: } else if (op.equalsIgnoreCase("DELETE_SERVICEBINDING")) {
578: regobj = ireg.deleteBinding(token.getAuthInfo(),
579: (String[]) dataarray);
580: } else if (op.equalsIgnoreCase("DELETE_CONCEPT")) {
581: regobj = ireg.deleteTModel(token.getAuthInfo(),
582: (String[]) dataarray);
583: } else if (op.equalsIgnoreCase("DELETE_ASSOCIATION")) {
584: int len = ((String[]) dataarray).length;
585: PublisherAssertion[] paarr = new PublisherAssertion[len];
586: for (int i = 0; i < len; i++) {
587: String keystr = ((String[]) dataarray)[i];
588: paarr[i] = ScoutJaxrUddiHelper
589: .getPubAssertionFromJAXRAssociationKey(keystr);
590: }
591: regobj = ireg.deletePublisherAssertions(
592: token.getAuthInfo(), paarr);
593: } else if (op.equalsIgnoreCase("DELETE_CLASSIFICATIONSCHEME")) {
594: regobj = ireg.deleteTModel(token.getAuthInfo(),
595: (String[]) dataarray);
596: } else {
597: throw new JAXRException("Unsupported operation:" + op);
598: }
599:
600: return regobj;
601: }
602:
603: private void clearPublisherAssertions(String authinfo,
604: String[] orgkeys, IRegistry ireg) {
605: Vector<PublisherAssertion> pasvect = null;
606: PublisherAssertion[] pasarr = null;
607: try {
608: AssertionStatusReport report = ireg
609: .getAssertionStatusReport(authinfo,
610: "status:complete");
611: AssertionStatusItem[] a = report
612: .getAssertionStatusItemArray();
613:
614: int len = a != null ? a.length : 0;
615: for (int i = 0; i < len; i++) {
616: AssertionStatusItem asi = a[i];
617: /* String sourceKey = asi.getFromKey();
618: String targetKey = asi.getToKey();
619: PublisherAssertion pa = new PublisherAssertion();
620: pa.setFromKey(sourceKey);
621: pa.setToKey(targetKey);
622: KeyedReference keyr = asi.getKeyedReference();
623: pa.setKeyedReference(keyr);
624: pa.setTModelKey(keyr.getTModelKey());
625: pa.setKeyName(keyr.getKeyName());
626: pa.setKeyValue(keyr.getKeyValue());
627: if(pasvect == null) pasvect = new Vector(len);
628: pasvect.add(pa);*/
629: if (pasvect == null)
630: pasvect = new Vector<PublisherAssertion>(len);
631: pasvect.add(this .getPublisherAssertion(asi));
632: }
633: report = ireg.getAssertionStatusReport(authinfo,
634: "status:toKey_incomplete");
635: a = report.getAssertionStatusItemArray();
636:
637: len = a != null ? a.length : 0;
638: for (int i = 0; i < len; i++) {
639: AssertionStatusItem asi = (AssertionStatusItem) a[i];
640: if (pasvect == null)
641: pasvect = new Vector<PublisherAssertion>(len);
642: pasvect.add(this .getPublisherAssertion(asi));
643: }
644:
645: report = ireg.getAssertionStatusReport(authinfo,
646: "status:fromKey_incomplete");
647: a = report.getAssertionStatusItemArray();
648:
649: len = a != null ? a.length : 0;
650: for (int i = 0; i < len; i++) {
651: AssertionStatusItem asi = (AssertionStatusItem) a[i];
652: if (pasvect == null)
653: pasvect = new Vector<PublisherAssertion>(len);
654: pasvect.add(this .getPublisherAssertion(asi));
655: }
656:
657: if (pasvect != null) {
658: pasarr = new PublisherAssertion[pasvect.size()];
659: Iterator iter = pasvect.iterator();
660: int pasarrPos = 0;
661: while (iter.hasNext()) {
662: pasarr[pasarrPos] = ((PublisherAssertion) iter
663: .next());
664: pasarrPos++;
665: }
666: }
667: } catch (RegistryException e) {
668: e.printStackTrace();
669: }
670:
671: if (pasarr != null && pasarr.length > 0)
672: try {
673: ireg.deletePublisherAssertions(authinfo, pasarr);
674: } catch (RegistryException e) {
675: e.printStackTrace();
676: //IGNORE
677: }
678: }
679:
680: protected BulkResponse deleteOperation(Collection<Key> keys,
681: String op) throws JAXRException {
682: if (keys == null)
683: throw new JAXRException("Keys provided to " + op
684: + " are null");
685:
686: //Now we need to convert the collection into a vector for juddi
687: BulkResponseImpl bulk = new BulkResponseImpl();
688: String[] keyarr = new String[keys.size()];
689: Result[] keyResultArr;
690:
691: LinkedHashSet<Key> coll = new LinkedHashSet<Key>();
692: Collection<Exception> exceptions = new ArrayList<Exception>();
693:
694: try {
695: Iterator iter = keys.iterator();
696: int currLoc = 0;
697: while (iter.hasNext()) {
698: Key key = (Key) iter.next();
699: keyarr[currLoc] = key.getId();
700: currLoc++;
701: }
702: // Save business
703: DispositionReport bd = (DispositionReport) executeOperation(
704: keyarr, op);
705:
706: keyResultArr = bd.getResultArray();
707: log.debug("After deleting Business. Obtained vector size:"
708: + keyResultArr != null ? keyResultArr.length : 0);
709: for (int i = 0; keyResultArr != null
710: && i < keyResultArr.length; i++) {
711: Result result = (Result) keyResultArr[i];
712: int errno = result.getErrno();
713: if (errno == 0) {
714: coll.addAll(keys);
715: } else {
716: ErrInfo errinfo = result.getErrInfo();
717: DeleteException de = new DeleteException(errinfo
718: .getErrCode()
719: + ":" + errinfo.getStringValue());
720: bulk.setStatus(JAXRResponse.STATUS_FAILURE);
721: exceptions.add(de);
722: }
723: }
724: } catch (RegistryException regExcept) {
725:
726: /*
727: * jUDDI (and prollie others) throw an exception on any fault in
728: * the transaction w/ the registry, so we don't get any partial
729: * success
730: */
731: DeleteException de = new DeleteException(regExcept
732: .getFaultCode()
733: + ":" + regExcept.getFaultString(), regExcept);
734:
735: bulk.setStatus(JAXRResponse.STATUS_FAILURE);
736: exceptions.add(de);
737: } catch (JAXRException tran) {
738: exceptions
739: .add(new JAXRException("Apache JAXR Impl:", tran));
740: bulk.setStatus(JAXRResponse.STATUS_FAILURE);
741: }
742:
743: bulk.setCollection(coll);
744: bulk.setExceptions(exceptions);
745:
746: return bulk;
747: }
748:
749: /**
750: * Get the Auth Token from the registry
751: *
752: * @param connection
753: * @param ireg
754: * @return auth token
755: * @throws JAXRException
756: */
757: private AuthToken getAuthToken(ConnectionImpl connection,
758: IRegistry ireg) throws JAXRException {
759: Set creds = connection.getCredentials();
760: String username = "", pwd = "";
761: if (creds != null) {
762: Iterator it = creds.iterator();
763: while (it.hasNext()) {
764: PasswordAuthentication pass = (PasswordAuthentication) it
765: .next();
766: username = pass.getUserName();
767: pwd = new String(pass.getPassword());
768: }
769: }
770:
771: AuthToken token = null;
772: try {
773: token = ireg.getAuthToken(username, pwd);
774: } catch (Exception e) {
775: e.printStackTrace();
776: throw new JAXRException(e);
777: }
778: return token;
779: }
780:
781: private PublisherAssertion getPublisherAssertion(
782: AssertionStatusItem asi) {
783: String sourceKey = asi.getFromKey();
784: String targetKey = asi.getToKey();
785: PublisherAssertion pa = PublisherAssertion.Factory
786: .newInstance();
787:
788: if (sourceKey != null) {
789: pa.setFromKey(sourceKey);
790: }
791:
792: if (targetKey != null) {
793: pa.setToKey(targetKey);
794: }
795:
796: KeyedReference keyr = asi.getKeyedReference();
797:
798: if (keyr != null) {
799: pa.setKeyedReference(keyr);
800: }
801: //pa.setTModelKey(keyr.getTModelKey());
802: //pa.setKeyName(keyr.getKeyName());
803: //pa.setKeyValue(keyr.getKeyValue()); // -CBC- These are redundant?
804: return pa;
805: }
806:
807: }
|