Source Code Cross Referenced for UDDI4JRegistryQueryServiceComponent.java in  » Science » Cougaar12_4 » org » cougaar » servicediscovery » service » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.servicediscovery.service 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * <copyright>
0003:         *  
0004:         *  Copyright 2002-2004 BBNT Solutions, LLC
0005:         *  under sponsorship of the Defense Advanced Research Projects
0006:         *  Agency (DARPA).
0007:         * 
0008:         *  You can redistribute this software and/or modify it under the
0009:         *  terms of the Cougaar Open Source License as published on the
0010:         *  Cougaar Open Source Website (www.cougaar.org).
0011:         * 
0012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0023:         *  
0024:         * </copyright>
0025:         */
0026:
0027:        package org.cougaar.servicediscovery.service;
0028:
0029:        import java.util.ArrayList;
0030:        import java.util.Collection;
0031:        import java.util.Collections;
0032:        import java.util.Enumeration;
0033:        import java.util.HashMap;
0034:        import java.util.Iterator;
0035:        import java.util.Vector;
0036:
0037:        import org.cougaar.core.component.Component;
0038:        import org.cougaar.core.component.ServiceBroker;
0039:        import org.cougaar.core.component.ServiceProvider;
0040:        import org.cougaar.core.mts.MessageAddress;
0041:        import org.cougaar.core.service.AgentIdentificationService;
0042:        import org.cougaar.core.service.LoggingService;
0043:        import org.cougaar.core.service.ThreadService;
0044:        import org.cougaar.core.service.UIDService;
0045:        import org.cougaar.core.service.community.Community;
0046:        import org.cougaar.servicediscovery.description.BusinessClassificationImpl;
0047:        import org.cougaar.servicediscovery.description.Classification;
0048:        import org.cougaar.servicediscovery.description.ProviderInfo;
0049:        import org.cougaar.servicediscovery.description.ServiceBinding;
0050:        import org.cougaar.servicediscovery.description.ServiceClassificationImpl;
0051:        import org.cougaar.servicediscovery.description.ServiceInfo;
0052:        import org.cougaar.servicediscovery.transaction.RegistryQuery;
0053:        import org.cougaar.util.GenericStateModelAdapter;
0054:        import org.cougaar.yp.YPProxy;
0055:        import org.cougaar.yp.YPService;
0056:        import org.uddi4j.datatype.Name;
0057:        import org.uddi4j.datatype.binding.BindingTemplate;
0058:        import org.uddi4j.datatype.binding.BindingTemplates;
0059:        import org.uddi4j.datatype.binding.InstanceParms;
0060:        import org.uddi4j.datatype.binding.TModelInstanceInfo;
0061:        import org.uddi4j.datatype.business.BusinessEntity;
0062:        import org.uddi4j.datatype.service.BusinessService;
0063:        import org.uddi4j.datatype.service.BusinessServices;
0064:        import org.uddi4j.response.BusinessDetail;
0065:        import org.uddi4j.response.BusinessList;
0066:        import org.uddi4j.response.ServiceDetail;
0067:        import org.uddi4j.response.ServiceList;
0068:        import org.uddi4j.util.CategoryBag;
0069:        import org.uddi4j.util.FindQualifier;
0070:        import org.uddi4j.util.FindQualifiers;
0071:        import org.uddi4j.util.KeyedReference;
0072:
0073:        /**
0074:         */
0075:        public final class UDDI4JRegistryQueryServiceComponent extends
0076:                GenericStateModelAdapter implements  Component {
0077:            private static String ypAgent = System.getProperty(
0078:                    "org.cougaar.yp.ypAgent", "OSD.GOV");
0079:
0080:            private LoggingService log;
0081:
0082:            public void setLoggingService(LoggingService log) {
0083:                this .log = (log == null) ? LoggingService.NULL : log;
0084:            }
0085:
0086:            protected YPService ypService;
0087:
0088:            public void setYPService(YPService yps) {
0089:                this .ypService = yps;
0090:            }
0091:
0092:            private UIDService uidService;
0093:
0094:            public void setUIDService(UIDService us) {
0095:                uidService = us;
0096:            }
0097:
0098:            private AgentIdentificationService agentIdentificationService;
0099:
0100:            public void setAgentIdentificationService(
0101:                    AgentIdentificationService ais) {
0102:                agentIdentificationService = ais;
0103:            }
0104:
0105:            private ThreadService threads;
0106:
0107:            public void setThreadService(ThreadService t) {
0108:                threads = t;
0109:            }
0110:
0111:            private RegistryQueryServiceProviderImpl mySP;
0112:            private ServiceBroker sb;
0113:
0114:            public void setServiceBroker(ServiceBroker sb) {
0115:                this .sb = sb;
0116:            }
0117:
0118:            public void load() {
0119:                super .load();
0120:
0121:                // create and advertise the service
0122:                this .mySP = new RegistryQueryServiceProviderImpl();
0123:                sb.addService(RegistryQueryService.class, mySP);
0124:            }
0125:
0126:            public void unload() {
0127:                // revoke our service
0128:                if (mySP != null) {
0129:                    sb.revokeService(RegistryQueryService.class, mySP);
0130:                    mySP = null;
0131:                }
0132:                super .unload();
0133:            }
0134:
0135:            private class RegistryQueryServiceProviderImpl implements 
0136:                    ServiceProvider {
0137:                private final RegistryQueryServiceImpl myService;
0138:
0139:                public RegistryQueryServiceProviderImpl() {
0140:                    myService = new RegistryQueryServiceImpl();
0141:                }
0142:
0143:                public Object getService(ServiceBroker sb, Object requestor,
0144:                        Class serviceClass) {
0145:                    if (serviceClass == RegistryQueryService.class) {
0146:                        return myService;
0147:                    } else {
0148:                        return null;
0149:                    }
0150:                }
0151:
0152:                public void releaseService(ServiceBroker sb, Object requestor,
0153:                        Class serviceClass, Object service) {
0154:                }
0155:            }
0156:
0157:            private class RegistryQueryServiceImpl extends UDDI4JUtility
0158:                    implements  RegistryQueryService {
0159:                private int maxRows = 100;
0160:
0161:                public RegistryQueryServiceImpl() {
0162:                    super (UDDI4JRegistryQueryServiceComponent.this .log,
0163:                            UDDI4JRegistryQueryServiceComponent.this .ypService,
0164:                            UDDI4JRegistryQueryServiceComponent.this .threads);
0165:
0166:                }
0167:
0168:                /**
0169:                 * Returns providers matching the attributes in the RegistryQuery 
0170:                 * object. Uses default YPService search, i.e. query progresses
0171:                 * up the structure of YP servers until either a match is found or
0172:                 * search has reached the topmost server. 
0173:                 * @param query RegistryQuery containing the attributes to be matched.
0174:                 * @param callback  callback.invoke(Collection) of ProviderInfo objects.
0175:                 * If no matches, returns empty list. 
0176:                 */
0177:                public void findProviders(RegistryQuery query, Callback callback) {
0178:                    // Explicit call for a specific service
0179:                    YPProxy proxy = makeProxy(ypAgent);
0180:
0181:                    if (query.getServiceName() != null) {
0182:                        findServiceByNames(query, callback, proxy);
0183:                    } else {
0184:                        findAllProviders(query, callback, proxy);
0185:                    }
0186:                }
0187:
0188:                /**
0189:                 * Returns providers matching the attributes in the RegistryQuery 
0190:                 * object. Uses single step YPService search. Query is applied to the
0191:                 * YP server in the next YPContext. If lastYPContext argument is null, 
0192:                 * search starts with the closest YPServer. 
0193:                 * @param lastYPContext YP context where the previous search ended. 
0194:                 * Use null if starting search.
0195:                 * @param query RegistryQuery containing the attributes to be matched.
0196:                 * @param callback  CallbackWithContext, callback.setNextContext(object) with
0197:                 * yp server context, callback.invoke(Collection) of ProviderInfo objects. 
0198:                 * If no matches, returns empty list. 
0199:                 */
0200:                public void findProviders(final Object lastYPContext,
0201:                        final RegistryQuery query,
0202:                        final CallbackWithContext callback) {
0203:                    // Explicit call for a specific service
0204:                    ypService.nextYPServerContext(lastYPContext,
0205:                            new YPService.NextContextCallback() {
0206:                                public void setNextContext(Object context) {
0207:                                    callback.setNextContext(context);
0208:
0209:                                    if (context != null) {
0210:                                        YPProxy proxy = makeProxy(
0211:                                                context,
0212:                                                YPProxy.SearchMode.SINGLE_COMMUNITY_SEARCH);
0213:
0214:                                        if (query.getServiceName() != null) {
0215:                                            findServiceByNames(query, callback,
0216:                                                    proxy);
0217:                                        } else {
0218:                                            findAllProviders(query, callback,
0219:                                                    proxy);
0220:                                        }
0221:                                    } else {
0222:                                        if (log.isDebugEnabled()) {
0223:                                            log
0224:                                                    .debug("No subsequent yp context for "
0225:                                                            + lastYPContext);
0226:                                        }
0227:
0228:                                        callback.invoke(Collections.EMPTY_LIST);
0229:                                    }
0230:                                }
0231:                            });
0232:
0233:                }
0234:
0235:                /**
0236:                 * Returns providers matching the attributes in the RegistryQuery 
0237:                 * object. Uses single step YPService search. Query is applied to the
0238:                 * YP server for the specified agent.
0239:                 * 
0240:                 * @param agentName Name of the agent whose YP server should be queried
0241:                 * @param query RegistryQuery containing the attributes to be matched.
0242:                 * @param callback  CallbackWithContext, callback.setNextContext(object) with
0243:                 * yp server context, callback.invoke(Collection) of ProviderInfo objects. 
0244:                 * If no matches, returns empty list. 
0245:                 */
0246:                public void findProviders(final String agentName,
0247:                        final RegistryQuery query,
0248:                        final CallbackWithContext callback) {
0249:
0250:                    // Explicit call for a specific service
0251:                    ypService.getYPServerContext(agentName,
0252:                            new YPService.NextContextCallback() {
0253:                                public void setNextContext(Object context) {
0254:                                    callback.setNextContext(agentName);
0255:
0256:                                    if (context != null) {
0257:                                        if (log.isDebugEnabled()) {
0258:                                            log
0259:                                                    .debug("Found YPServerContext for "
0260:                                                            + agentName
0261:                                                            + " - will continue in "
0262:                                                            + context);
0263:                                        }
0264:                                        YPProxy proxy = makeProxy(
0265:                                                context,
0266:                                                YPProxy.SearchMode.SINGLE_COMMUNITY_SEARCH);
0267:
0268:                                        if (query.getServiceName() != null) {
0269:                                            findServiceByNames(query, callback,
0270:                                                    proxy);
0271:                                        } else {
0272:                                            findAllProviders(query, callback,
0273:                                                    proxy);
0274:                                        }
0275:                                    } else {
0276:                                        if (log.isDebugEnabled()) {
0277:                                            log.debug("No yp context for "
0278:                                                    + agentName);
0279:                                        }
0280:                                        callback.invoke(Collections.EMPTY_LIST);
0281:                                    }
0282:                                }
0283:                            });
0284:                }
0285:
0286:                /**
0287:                 * Returns all services matching the attributes in the RegistryQuery object.
0288:                 * @param query RegistryQuery containing the attributes to be matched.
0289:                 * @note callback.invoke(Collection) of ServiceInfo objects.  If no matches, returns empty list.
0290:                 */
0291:                public void findServices(RegistryQuery query, Callback callback) {
0292:                    YPProxy proxy = makeProxy(ypAgent);
0293:
0294:                    findAllServices(query, callback, proxy);
0295:                }
0296:
0297:                /**
0298:                 * Returns all services matching the attributes in the RegistryQuery object.
0299:                 * Uses single step YPService search. Query is applied to the
0300:                 * YP server in the next YPContext. If lastYPContext argument is null, 
0301:                 * search starts with the closest YPServer. 
0302:                 * @param lastYPContext YP context where the previous search ended. 
0303:                 * Use null if starting search.
0304:                 * @param query RegistryQuery containing the attributes to be matched.
0305:                 * @param callback  CallbackWithContext, callback.setNextContext(object) 
0306:                 * with yp server context, callback.invoke(Collection) with ServiceInfo 
0307:                 * objects. If no matches, returns empty list. 
0308:                 */
0309:                public void findServices(final Object lastYPContext,
0310:                        final RegistryQuery query,
0311:                        final CallbackWithContext callback) {
0312:                    ypService.nextYPServerContext(lastYPContext,
0313:                            new YPService.NextContextCallback() {
0314:                                public void setNextContext(Object context) {
0315:                                    callback.setNextContext(context);
0316:
0317:                                    if (context != null) {
0318:                                        YPProxy proxy = makeProxy(
0319:                                                context,
0320:                                                YPProxy.SearchMode.SINGLE_COMMUNITY_SEARCH);
0321:
0322:                                        findAllServices(query, callback, proxy);
0323:                                    } else {
0324:                                        if (log.isDebugEnabled()) {
0325:                                            log
0326:                                                    .debug("No subsequent yp context for "
0327:                                                            + lastYPContext);
0328:                                        }
0329:                                        callback.invoke(Collections.EMPTY_LIST);
0330:                                    }
0331:                                }
0332:                            });
0333:                }
0334:
0335:                /**
0336:                 * Returns all services matching the attributes in the RegistryQuery object.
0337:                 * Uses single step YPService search.  Query is applied to the
0338:                 * YP server for the specified agent. Currently requires that agent 
0339:                 * also be a YPServer.
0340:                 *
0341:                 * @param agentName Name of the agent whose YP server should be queried
0342:                 * @param query RegistryQuery containing the attributes to be matched.
0343:                 * @param callback  CallbackWithContext, callback.setNextContext(object) 
0344:                 * with yp server context, callback.invoke(Collection) with ServiceInfo
0345:                 * objects. If no matches, returns empty list. 
0346:                 */
0347:                public void findServices(final String agentName,
0348:                        final RegistryQuery query,
0349:                        final CallbackWithContext callback) {
0350:
0351:                    // Explicit call for a specific service
0352:                    ypService.getYPServerContext(agentName,
0353:                            new YPService.NextContextCallback() {
0354:                                public void setNextContext(Object context) {
0355:                                    callback.setNextContext(agentName);
0356:
0357:                                    if (context != null) {
0358:                                        if (log.isDebugEnabled()) {
0359:                                            log
0360:                                                    .debug("Found YPServerContext for "
0361:                                                            + agentName
0362:                                                            + " - will continue in "
0363:                                                            + context);
0364:                                        }
0365:                                        YPProxy proxy = makeProxy(
0366:                                                context,
0367:                                                YPProxy.SearchMode.SINGLE_COMMUNITY_SEARCH);
0368:
0369:                                        findAllServices(query, callback, proxy);
0370:                                    } else {
0371:                                        if (log.isDebugEnabled()) {
0372:                                            log.debug("No yp context for "
0373:                                                    + agentName);
0374:                                        }
0375:                                        callback.invoke(Collections.EMPTY_LIST);
0376:                                    }
0377:                                }
0378:                            });
0379:                }
0380:
0381:                /**
0382:                 * Returns all services matching the attributes in the RegistryQuery object.
0383:                 * Uses default YPService search, i.e. query progresses
0384:                 * up the structure of YP servers until either a match is found or
0385:                 * search has reached the topmost server. 
0386:                 * @param query RegistryQuery containing the attributes to be matched.
0387:                 * @param callback  callback.invoke(Collection) of lightweight ServiceInfo 
0388:                 * objects. If no matches, returns empty list. 
0389:                 */
0390:                public void findServiceAndBinding(RegistryQuery query,
0391:                        Callback callback) {
0392:                    YPProxy proxy = makeProxy(ypAgent);
0393:
0394:                    findServiceAndBinding(query, callback, proxy);
0395:                }
0396:
0397:                /**
0398:                 * Returns all services matching the attributes in the RegistryQuery object.
0399:                 * Uses single step YPService search. Query is applied to the
0400:                 * YP server in the next YPContext. If lastYPContext argument is null, 
0401:                 * search starts with the closest YPServer. 
0402:                 * @param lastYPContext YP context where the previous search ended. 
0403:                 * Use null if starting search.
0404:                 * @param query RegistryQuery containing the attributes to be matched.
0405:                 * @param callback  CallbackWithContext, callback.setNextContext(object) with
0406:                 * yp server context, callback.invoke(Collection) with lightweight 
0407:                 * ServiceInfo, objects. If no matches, returns empty list. 
0408:                 */
0409:                public void findServiceAndBinding(final Object lastYPContext,
0410:                        final RegistryQuery query,
0411:                        final CallbackWithContext callback) {
0412:
0413:                    // Explicit call for a specific service
0414:                    ypService.nextYPServerContext(lastYPContext,
0415:                            new YPService.NextContextCallback() {
0416:                                public void setNextContext(Object context) {
0417:                                    callback.setNextContext(context);
0418:
0419:                                    if (context != null) {
0420:                                        if (log.isDebugEnabled()) {
0421:                                            log
0422:                                                    .debug("Found next YPServerContext for "
0423:                                                            + lastYPContext
0424:                                                            + " - will continue in "
0425:                                                            + context);
0426:                                        }
0427:                                        YPProxy proxy = makeProxy(
0428:                                                context,
0429:                                                YPProxy.SearchMode.SINGLE_COMMUNITY_SEARCH);
0430:
0431:                                        findServiceAndBinding(query, callback,
0432:                                                proxy);
0433:                                    } else {
0434:                                        if (log.isDebugEnabled()) {
0435:                                            log
0436:                                                    .debug("No subsequent yp context for "
0437:                                                            + lastYPContext);
0438:                                        }
0439:                                        callback.invoke(Collections.EMPTY_LIST);
0440:                                    }
0441:                                }
0442:                            });
0443:                }
0444:
0445:                /**
0446:                 * Returns all services matching the attributes in the RegistryQuery object.
0447:                 * Uses single step YPService search. Query is applied to the
0448:                 * YP server for the specified agent. Currently requires that agent 
0449:                 * also be a YPServer. Bug in CommunityService 
0450:                 * (http://bugs.cougaar.org/show_bug.cgi?id=3585) prevents a more general
0451:                 * implementation.
0452:                 * 
0453:                 * @param agentName Name of the agent whose YP server will be queried
0454:                 * @param query RegistryQuery containing the attributes to be matched.
0455:                 * @param callback  CallbackWithContext, callback.setNextContext(object) with
0456:                 * yp server context, callback.invoke(Collection) with lightweight 
0457:                 * ServiceInfo, objects. If no matches, returns empty list. 
0458:                 */
0459:                public void findServiceAndBinding(final String agentName,
0460:                        final RegistryQuery query,
0461:                        final CallbackWithContext callback) {
0462:                    // Explicit call for a specific service
0463:                    ypService.getYPServerContext(agentName,
0464:                            new YPService.NextContextCallback() {
0465:                                public void setNextContext(Object context) {
0466:                                    callback.setNextContext(agentName);
0467:
0468:                                    if (context != null) {
0469:                                        if (log.isDebugEnabled()) {
0470:                                            log
0471:                                                    .debug("Found YPServerContext for "
0472:                                                            + agentName
0473:                                                            + " - will continue in "
0474:                                                            + context);
0475:                                        }
0476:                                        YPProxy proxy = makeProxy(
0477:                                                context,
0478:                                                YPProxy.SearchMode.SINGLE_COMMUNITY_SEARCH);
0479:
0480:                                        findServiceAndBinding(query, callback,
0481:                                                proxy);
0482:                                    } else {
0483:                                        if (log.isDebugEnabled()) {
0484:                                            log.debug("No yp context for "
0485:                                                    + agentName);
0486:                                        }
0487:                                        callback.invoke(Collections.EMPTY_LIST);
0488:                                    }
0489:                                }
0490:                            });
0491:                }
0492:
0493:                private void findAllServices(final RegistryQuery rq,
0494:                        final Callback callback, YPProxy proxy) {
0495:                    class State {
0496:                        Collection services = new ArrayList();
0497:                        CategoryBag bag = null;
0498:                        FindQualifiers fq = null;
0499:                        Vector serviceNames = null;
0500:                        ServiceList serviceList = null;
0501:                        Callback step1, step2, step3, step4;
0502:                        YPProxy proxy;
0503:                        Object finalYPContext;
0504:                    }
0505:                    final State state = new State();
0506:
0507:                    state.proxy = proxy;
0508:
0509:                    // step1 create category bag 
0510:                    state.step1 = new CallbackDelegate(callback) {
0511:                        public void invoke(Object result) {
0512:                            if (rq.getServiceClassifications() != null) {
0513:                                createCategoryBag(rq
0514:                                        .getServiceClassifications(),
0515:                                        state.step2, state.proxy);
0516:                            } else {
0517:                                state.step2.invoke(null);
0518:                            }
0519:                        }
0520:                    };
0521:
0522:                    // consume cb, set up fq, names.  invoke findService
0523:                    state.step2 = new CallbackDelegate(callback) {
0524:                        public void invoke(Object result) {
0525:                            state.bag = (CategoryBag) result;
0526:
0527:                            if (rq.getFindQualifiers() != null) {
0528:                                state.fq = new FindQualifiers();
0529:                                // BUG: original version just took the first one
0530:                                for (Iterator it = rq.getFindQualifiers()
0531:                                        .iterator(); it.hasNext();) {
0532:                                    String qualifier = (String) it.next();
0533:                                    state.fq.getFindQualifierVector().add(
0534:                                            new FindQualifier(qualifier));
0535:                                }
0536:                            }
0537:
0538:                            if (rq.getServiceName() != null) {
0539:                                state.serviceNames = new Vector(1);
0540:                                state.serviceNames.add(new Name(rq
0541:                                        .getServiceName()));
0542:                            }
0543:
0544:                            findService(state.proxy, null, state.serviceNames,
0545:                                    state.bag, null, state.fq, maxRows,
0546:                                    state.step3);
0547:                        }
0548:                    };
0549:
0550:                    state.step3 = new CallbackDelegate(callback) {
0551:                        public void invoke(Object result) {
0552:                            state.serviceList = (ServiceList) result;
0553:
0554:                            Vector serviceKeys = new Vector();
0555:                            for (Iterator it = state.serviceList
0556:                                    .getServiceInfos().getServiceInfoVector()
0557:                                    .iterator(); it.hasNext();) {
0558:                                org.uddi4j.response.ServiceInfo si = (org.uddi4j.response.ServiceInfo) it
0559:                                        .next();
0560:                                serviceKeys.add(si.getServiceKey());
0561:                                if (log.isDebugEnabled()) {
0562:                                    log.debug("[findAllServices]ServiceName : "
0563:                                            + si.getNameString());
0564:                                }
0565:                            }
0566:
0567:                            if (!serviceKeys.isEmpty()) {
0568:                                createServiceInfos(serviceKeys, state.step4,
0569:                                        state.proxy);
0570:                            } else {
0571:                                if (log.isDebugEnabled()) {
0572:                                    log.debug("No services were found ");
0573:                                }
0574:                                state.step4.invoke(Collections.EMPTY_LIST);
0575:                            }
0576:                        }
0577:                    };
0578:
0579:                    state.step4 = new CallbackDelegate(callback) {
0580:                        public void invoke(Object result) {
0581:                            super .invoke(result);
0582:                        }
0583:                    };
0584:
0585:                    state.step1.invoke(null);
0586:                }
0587:
0588:                private void findAllProviders(final RegistryQuery rq,
0589:                        Callback callback, final YPProxy proxy) {
0590:                    class State {
0591:                        CategoryBag bag = null;
0592:                        FindQualifiers fq = null;
0593:                        Vector providerNames = null;
0594:                        BusinessList bzList;
0595:                        Callback step1, step2, step3, step4;
0596:                        YPProxy proxy;
0597:                        Object finalYPContext;
0598:                    }
0599:                    final State state = new State();
0600:
0601:                    state.proxy = proxy;
0602:
0603:                    // step1 create category bag 
0604:                    state.step1 = new CallbackDelegate(callback) {
0605:                        public void invoke(Object result) {
0606:                            if (rq.getBusinessClassifications() != null) {
0607:                                createCategoryBag(rq
0608:                                        .getBusinessClassifications(),
0609:                                        state.step2, state.proxy);
0610:                            } else {
0611:                                state.step2.invoke(null);
0612:                            }
0613:                        }
0614:                    };
0615:
0616:                    // step2: consume category bag, do FQ and providernames, launch findBusiness
0617:                    state.step2 = new CallbackDelegate(callback) {
0618:                        public void invoke(Object result) {
0619:                            state.bag = (CategoryBag) result;
0620:
0621:                            if (rq.getFindQualifiers() != null) {
0622:                                state.fq = new FindQualifiers();
0623:                                // BUG: original version just took the first one
0624:                                for (Iterator it = rq.getFindQualifiers()
0625:                                        .iterator(); it.hasNext();) {
0626:                                    String qualifier = (String) it.next();
0627:                                    state.fq.getFindQualifierVector().add(
0628:                                            new FindQualifier(qualifier));
0629:                                }
0630:                            }
0631:
0632:                            if (rq.getProviderName() != null) {
0633:                                state.providerNames = new Vector(1);
0634:                                state.providerNames.add(new Name(rq
0635:                                        .getProviderName()));
0636:                            }
0637:
0638:                            findBusiness(state.proxy, state.providerNames,
0639:                                    null, null, state.bag, null, state.fq,
0640:                                    maxRows, state.step3);
0641:                        }
0642:                    };
0643:
0644:                    // step3: consume businesses, createProviderInfos
0645:                    state.step3 = new CallbackDelegate(callback) {
0646:                        public void invoke(Object result) {
0647:                            state.bzList = (BusinessList) result;
0648:                            Vector businessKeys = new Vector();
0649:                            String serviceKey = null; // serviceKey never gets set to something real - is this ok?
0650:
0651:                            for (Iterator it = state.bzList.getBusinessInfos()
0652:                                    .getBusinessInfoVector().iterator(); it
0653:                                    .hasNext();) {
0654:                                org.uddi4j.response.BusinessInfo bi = (org.uddi4j.response.BusinessInfo) it
0655:                                        .next();
0656:                                businessKeys.add(bi.getBusinessKey());
0657:                                if (log.isDebugEnabled()) {
0658:                                    log
0659:                                            .debug("[findAllProviders] Provider name: "
0660:                                                    + bi.getNameString());
0661:                                }
0662:                            }
0663:                            createProviderInfos(businessKeys, serviceKey,
0664:                                    state.step4, state.proxy);
0665:                        }
0666:                    };
0667:
0668:                    // step4: consume and result providers
0669:                    state.step4 = new CallbackDelegate(callback) {
0670:                        public void invoke(Object result) {
0671:                            super .invoke(result);
0672:                        }
0673:                    };
0674:
0675:                    state.step1.invoke(null);
0676:                }
0677:
0678:                /** @note Callback.invoke(Collection) **/
0679:                private void findServiceByNames(final RegistryQuery rq,
0680:                        Callback callback, YPProxy proxy) {
0681:                    class State {
0682:                        Collection providers = new ArrayList();
0683:                        CategoryBag bag = null;
0684:                        FindQualifiers fq = null;
0685:                        Vector providerNames = null;
0686:                        BusinessList bzList;
0687:                        Vector businessKeys = new Vector();
0688:                        Callback step1, step2, step3, step4;
0689:                        YPProxy proxy;
0690:                    }
0691:                    final State state = new State();
0692:
0693:                    state.proxy = proxy;
0694:
0695:                    // step1 create category bag 
0696:                    state.step1 = new CallbackDelegate(callback) {
0697:                        public void invoke(Object result) {
0698:                            if (rq.getBusinessClassifications() != null) {
0699:                                createCategoryBag(rq
0700:                                        .getBusinessClassifications(),
0701:                                        state.step2, state.proxy);
0702:                            } else {
0703:                                state.step2.invoke(null);
0704:                            }
0705:                        }
0706:                    };
0707:
0708:                    // step2: consume category bag, do FQ and providernames, launch findBusiness
0709:                    state.step2 = new CallbackDelegate(callback) {
0710:                        public void invoke(Object result) {
0711:                            state.bag = (CategoryBag) result;
0712:
0713:                            if (rq.getFindQualifiers() != null) {
0714:                                String qualifier = (String) rq
0715:                                        .getFindQualifiers().iterator().next();
0716:                                state.fq = new FindQualifiers();
0717:                                state.fq.getFindQualifierVector().add(
0718:                                        new FindQualifier(qualifier));
0719:                            }
0720:
0721:                            if (rq.getProviderName() != null) {
0722:                                state.providerNames = new Vector();
0723:                                state.providerNames.add(new Name(rq
0724:                                        .getProviderName()));
0725:                            }
0726:
0727:                            findBusiness(state.proxy, state.providerNames,
0728:                                    null, null, state.bag, null, state.fq,
0729:                                    maxRows, state.step3);
0730:                        }
0731:                    };
0732:
0733:                    // step3: consume findBusiness, invoke createProviderInfos
0734:                    state.step3 = new CallbackDelegate(callback) {
0735:                        public void invoke(Object result) {
0736:                            state.bzList = (BusinessList) result;
0737:                            for (Iterator it = state.bzList.getBusinessInfos()
0738:                                    .getBusinessInfoVector().iterator(); it
0739:                                    .hasNext();) {
0740:                                org.uddi4j.response.BusinessInfo bi = (org.uddi4j.response.BusinessInfo) it
0741:                                        .next();
0742:                                state.businessKeys.add(bi.getBusinessKey());
0743:                                if (log.isDebugEnabled()) {
0744:                                    log
0745:                                            .debug("[findAllProviders] Provider name: "
0746:                                                    + bi.getNameString());
0747:                                    log
0748:                                            .debug("[findServiceByName] Service name: "
0749:                                                    + rq.getServiceName());
0750:                                }
0751:                            }
0752:                            if (!state.businessKeys.isEmpty()) {
0753:                                createProviderInfos(state.businessKeys, rq
0754:                                        .getServiceName(), state.step4,
0755:                                        state.proxy);
0756:                            } else {
0757:                                if (log.isDebugEnabled()) {
0758:                                    log
0759:                                            .debug("No providers of that service were found ");
0760:                                }
0761:                                state.step4.invoke(Collections.EMPTY_LIST);
0762:                            }
0763:                        }
0764:                    };
0765:
0766:                    state.step4 = new CallbackDelegate(callback) {
0767:                        public void invoke(Object result) {
0768:                            super .invoke(result);
0769:                        }
0770:                    };
0771:                    state.step1.invoke(null);
0772:                }
0773:
0774:                /**
0775:                 * Returns all services matching the attributes in the RegistryQuery object.
0776:                 * @param query RegistryQuery containing the attributes to be matched.
0777:                 * @note callback.invoke(Collection) of lightweight ServiceInfo objects.
0778:                 * If no matches, returns empty list.
0779:                 */
0780:                private void findServiceAndBinding(final RegistryQuery query,
0781:                        final Callback callback, YPProxy proxy) {
0782:
0783:                    class State {
0784:                        Collection services = new ArrayList();
0785:                        CategoryBag bag = null;
0786:                        FindQualifiers fq = null;
0787:                        Vector serviceNames = null;
0788:                        Vector serviceKeys = new Vector();
0789:                        Callback step1, step2, step3, sub1, step4, step5;
0790:                        YPProxy proxy;
0791:                    }
0792:                    final State state = new State();
0793:
0794:                    state.proxy = proxy;
0795:                    // step 1
0796:                    state.step1 = new CallbackDelegate(callback) {
0797:                        public void invoke(Object result) {
0798:                            Collection scs = query.getServiceClassifications();
0799:                            if (scs != null) {
0800:                                createCategoryBag(scs, state.step2, state.proxy);
0801:                            } else {
0802:                                state.step2.invoke(null);
0803:                            }
0804:                        }
0805:                    };
0806:
0807:                    // step 2: consume CategoryBag, start FQ
0808:                    state.step2 = new CallbackDelegate(callback) {
0809:                        public void invoke(Object result) {
0810:                            state.bag = (CategoryBag) result;
0811:
0812:                            if (query.getFindQualifiers() != null) {
0813:                                state.fq = new FindQualifiers();
0814:                                for (Iterator it = query.getFindQualifiers()
0815:                                        .iterator(); it.hasNext();) {
0816:                                    String qualifier = (String) it.next();
0817:                                    state.fq.getFindQualifierVector().add(
0818:                                            new FindQualifier(qualifier));
0819:                                }
0820:                            }
0821:
0822:                            if (query.getServiceName() != null) {
0823:                                state.serviceNames = new Vector();
0824:                                state.serviceNames.add(new Name(query
0825:                                        .getServiceName()));
0826:                            }
0827:
0828:                            findService(state.proxy, null, state.serviceNames,
0829:                                    state.bag, null, state.fq, maxRows,
0830:                                    state.step3);
0831:                        }
0832:                    };
0833:
0834:                    // step 3: consume service
0835:                    state.step3 = new CallbackDelegate(callback) {
0836:                        public void invoke(Object result) {
0837:                            ServiceList serviceList = (ServiceList) result;
0838:                            loop(serviceList.getServiceInfos()
0839:                                    .getServiceInfoVector(), state.sub1,
0840:                                    state.step4);
0841:                        }
0842:                    };
0843:
0844:                    state.sub1 = new CallbackDelegate(callback) {
0845:                        public void invoke(Object args) {
0846:                            Object result = ((Object[]) args)[0];
0847:                            Callback next = (Callback) ((Object[]) args)[1];
0848:                            org.uddi4j.response.ServiceInfo si = (org.uddi4j.response.ServiceInfo) result;
0849:                            state.serviceKeys.add(si.getServiceKey());
0850:                            if (log.isDebugEnabled()) {
0851:                                log
0852:                                        .debug("[findServiceAndBinding]ServiceName : "
0853:                                                + si.getNameString());
0854:                            }
0855:                            next.invoke(null); // pop back up
0856:                        }
0857:                    };
0858:
0859:                    state.step4 = new CallbackDelegate(callback) {
0860:                        public void invoke(Object result) {
0861:                            if (!state.serviceKeys.isEmpty()) {
0862:                                createSimpleServiceInfos(state.serviceKeys,
0863:                                        state.step5, state.proxy);
0864:                            } else {
0865:                                if (log.isDebugEnabled()) {
0866:                                    log.debug("No services were found ");
0867:                                }
0868:                                super .invoke(Collections.EMPTY_LIST);
0869:                            }
0870:                        }
0871:                    };
0872:
0873:                    state.step5 = new CallbackDelegate(callback) {
0874:                        public void invoke(Object result) {
0875:                            super .invoke((Collection) result);
0876:                        }
0877:                    };
0878:
0879:                    state.step1.invoke(null);
0880:                }
0881:
0882:                /** @note Callback.invoke(Collection) **/
0883:                private void createProviderInfos(Vector businessKeys,
0884:                        final String serviceName, Callback callback,
0885:                        YPProxy proxy) {
0886:                    final Collection providers = new ArrayList();
0887:
0888:                    class State {
0889:                        Callback step2, step3, sub1, sub2;
0890:                        Callback jump;
0891:                        YPProxy proxy;
0892:                    }
0893:                    ;
0894:
0895:                    final State state = new State();
0896:
0897:                    state.proxy = proxy;
0898:                    // step 1 at end...
0899:
0900:                    // step 2 consumes the business detail and then loops, ending in step 3
0901:                    state.step2 = new CallbackDelegate(callback) {
0902:                        public void invoke(Object result) {
0903:                            BusinessDetail bd = (BusinessDetail) result;
0904:                            loop(bd.getBusinessEntityVector(), state.sub1,
0905:                                    state.step3);
0906:                        }
0907:                    };
0908:
0909:                    // nesting for documentation purposes...
0910:                    {
0911:                        state.sub1 = new CallbackDelegate(callback) {
0912:                            public void invoke(Object args) {
0913:                                Object result = ((Object[]) args)[0];
0914:                                state.jump = (Callback) ((Object[]) args)[1];
0915:
0916:                                BusinessEntity be = (BusinessEntity) result;
0917:                                createProviderInfo1(be, serviceName,
0918:                                        state.sub2, state.proxy);
0919:                            }
0920:                        };
0921:
0922:                        state.sub2 = new CallbackDelegate(callback) {
0923:                            public void invoke(Object result) {
0924:                                ProviderInfo pi = (ProviderInfo) result;
0925:                                providers.add(pi);
0926:                                // return back up...
0927:                                state.jump.invoke(null);
0928:                            }
0929:                        };
0930:                    }
0931:
0932:                    state.step3 = new CallbackDelegate(callback) {
0933:                        public void invoke(Object result) {
0934:                            // result==step1
0935:                            super .invoke(providers);
0936:                        }
0937:                    };
0938:
0939:                    // step 1
0940:                    getBusinessDetail(state.proxy, businessKeys, state.step2);
0941:                }
0942:
0943:                private void createProviderInfo1(final BusinessEntity be,
0944:                        final String serviceName, Callback callback,
0945:                        YPProxy proxy) {
0946:                    class State {
0947:                        Collection bzClass;
0948:                        BusinessService bs;
0949:                        Callback step2, step3, step4, step5, stepA;
0950:                        Collection scs;
0951:                        YPProxy proxy;
0952:                    }
0953:                    ;
0954:                    final State state = new State();
0955:                    state.proxy = proxy;
0956:                    // step 1 below
0957:
0958:                    state.step2 = new CallbackDelegate(callback) {
0959:                        public void invoke(Object result) {
0960:                            if (serviceName != null) {
0961:                                // only retrieve the specified service (darn - I thought it needed a callback)
0962:                                state.step3.invoke(getBusinessService(be
0963:                                        .getBusinessServices()
0964:                                        .getBusinessServiceVector(),
0965:                                        serviceName));
0966:                            } else {
0967:                                // get them all
0968:                                if (be.getBusinessServices() != null) {
0969:                                    createServiceInfos(
0970:                                            be.getBusinessServices(), be
0971:                                                    .getDefaultNameString(),
0972:                                            state.bzClass, state.stepA,
0973:                                            state.proxy);
0974:                                } else {
0975:                                    if (log.isDebugEnabled()) {
0976:                                        log
0977:                                                .debug("No services registered with provider "
0978:                                                        + be
0979:                                                                .getDefaultNameString());
0980:                                    }
0981:                                    state.stepA.invoke(Collections.EMPTY_LIST);
0982:                                }
0983:                            }
0984:                        }
0985:                    };
0986:
0987:                    // step3 consumes the business service and gets the SCs (to step4)n
0988:                    state.step3 = new CallbackDelegate(callback) {
0989:                        public void invoke(Object result) {
0990:                            state.bs = (BusinessService) result;
0991:                            getServiceClassifications(
0992:                                    state.bs.getCategoryBag(), state.step4,
0993:                                    state.proxy);
0994:                        }
0995:                    };
0996:                    state.step4 = new CallbackDelegate(callback) {
0997:                        public void invoke(Object result) {
0998:                            state.scs = (Collection) result;
0999:                            getServiceBindings(state.bs.getBindingTemplates(),
1000:                                    state.step5, state.proxy);
1001:                        }
1002:                    };
1003:                    state.step5 = new CallbackDelegate(callback) {
1004:                        public void invoke(Object result) {
1005:                            Collection sbs = (Collection) result;
1006:                            ServiceInfo si = new ServiceInfo(state.bs
1007:                                    .getDefaultNameString(), state.bs
1008:                                    .getServiceKey(), state.scs, sbs, be
1009:                                    .getDefaultNameString(), state.bzClass);
1010:                            ArrayList l = new ArrayList(1);
1011:                            l.add(si);
1012:                            state.stepA.invoke(l);
1013:                        }
1014:                    };
1015:
1016:                    // this had nested incorrectly.
1017:                    state.stepA = new CallbackDelegate(callback) {
1018:                        public void invoke(Object result) {
1019:                            Collection serviceInfos = (Collection) result;
1020:                            super .invoke(new ProviderInfo(be
1021:                                    .getDefaultNameString(), state.bzClass,
1022:                                    serviceInfos));
1023:                        }
1024:                    };
1025:
1026:                    // step 1
1027:                    getBusinessClassifications(be.getCategoryBag(),
1028:                            state.step2, state.proxy);
1029:                }
1030:
1031:                /** find the service in the vector with the correct name **/
1032:                private BusinessService getBusinessService(Vector services,
1033:                        String serviceName) {
1034:                    Enumeration e = services.elements();
1035:                    BusinessService businessService = null;
1036:                    while (e.hasMoreElements()) {
1037:                        BusinessService bs = (BusinessService) e.nextElement();
1038:                        if (bs.getDefaultNameString().equals(serviceName)) {
1039:                            businessService = bs;
1040:                        }
1041:                    }
1042:                    return businessService;
1043:                }
1044:
1045:                /** @note Callback.invoke(Collection) **/
1046:                private void createServiceInfos(Vector serviceKeys,
1047:                        Callback callback, YPProxy proxy) {
1048:
1049:                    final Collection serviceInfos = new ArrayList();
1050:                    class State {
1051:                        Enumeration e;
1052:                        Callback step2, step3, step4, step5, step6;
1053:                        ServiceInfo serviceInfo;
1054:                        BusinessService bs;
1055:                        YPProxy proxy;
1056:                    }
1057:                    ;
1058:                    final State state = new State();
1059:
1060:                    state.proxy = proxy;
1061:                    // step1 is below
1062:
1063:                    // step2 catches the ServiceDetail and invokes the loop
1064:                    state.step2 = new CallbackDelegate(callback) {
1065:                        public void invoke(Object result) {
1066:                            ServiceDetail sd = (ServiceDetail) result;
1067:                            state.e = sd.getBusinessServiceVector().elements();
1068:                            state.step3.invoke(null);
1069:                        }
1070:                    };
1071:
1072:                    // step 3 starts the loop.
1073:                    state.step3 = new CallbackDelegate(callback) {
1074:                        public void invoke(Object result) {
1075:                            if (result != null) {
1076:                                Collection sbs = (Collection) result;
1077:                                state.serviceInfo.setServiceBindings(sbs);
1078:                                serviceInfos.add(state.serviceInfo);
1079:                            }
1080:                            if (state.e.hasMoreElements()) {
1081:                                state.bs = (BusinessService) state.e
1082:                                        .nextElement();
1083:                                state.serviceInfo = new ServiceInfo();
1084:                                state.serviceInfo.setServiceId(state.bs
1085:                                        .getServiceKey());
1086:                                state.serviceInfo.setServiceName(state.bs
1087:                                        .getDefaultNameString());
1088:                                getServiceClassifications(state.bs
1089:                                        .getCategoryBag(), state.step4,
1090:                                        state.proxy);
1091:                            } else {
1092:                                super .invoke(serviceInfos);
1093:                            }
1094:                        }
1095:                    };
1096:
1097:                    // step 4 consumes ServiceClassifications and gets the BusinessDetails
1098:                    state.step4 = new CallbackDelegate(callback) {
1099:                        public void invoke(Object result) {
1100:                            state.serviceInfo
1101:                                    .setServiceClassifications((Collection) result);
1102:                            getBusinessDetail(state.proxy, state.bs
1103:                                    .getBusinessKey(), state.step5);
1104:                        }
1105:                    };
1106:                    // step 5 consumes the BusinessDetail and fills it out, ending in step6
1107:                    state.step5 = new CallbackDelegate(callback) {
1108:                        public void invoke(Object result) {
1109:                            BusinessDetail bd = (BusinessDetail) result;
1110:                            addBusinessDetail(state.serviceInfo, bd,
1111:                                    state.step6, state.proxy);
1112:                        }
1113:                    };
1114:
1115:                    // step 6 adds the SCs
1116:                    state.step6 = new CallbackDelegate(callback) {
1117:                        public void invoke(Object result) {
1118:                            //consumes ???
1119:                            getServiceBindings(state.bs.getBindingTemplates(),
1120:                                    state.step3, state.proxy);
1121:                        }
1122:                    };
1123:
1124:                    getServiceDetail(state.proxy, serviceKeys, state.step2); // step1
1125:                }
1126:
1127:                private void addBusinessDetail(final ServiceInfo serviceInfo,
1128:                        BusinessDetail bd, Callback callback,
1129:                        final YPProxy proxy) {
1130:                    final Enumeration businessEnum = bd
1131:                            .getBusinessEntityVector().elements();
1132:                    BusinessEntity be = null;
1133:                    while (businessEnum.hasMoreElements()) {
1134:                        // Ugh!  Just duplicating the logic here, but this looks wrong to me!
1135:                        be = (BusinessEntity) businessEnum.nextElement();
1136:                    }
1137:
1138:                    if (be == null) {
1139:                        callback.invoke(serviceInfo);
1140:                    } else {
1141:                        serviceInfo.setProviderName(be.getDefaultNameString());
1142:                        getBusinessClassifications(be.getCategoryBag(),
1143:                                new CallbackDelegate(callback) {
1144:                                    public void invoke(Object result) {
1145:                                        serviceInfo
1146:                                                .setBusinessClassifications((Collection) result);
1147:                                        super .invoke(serviceInfo);
1148:                                    }
1149:                                }, proxy);
1150:                    }
1151:                }
1152:
1153:                /** @note Callback.invoke(Collection) **/
1154:                private void createSimpleServiceInfos(Vector serviceKeys,
1155:                        Callback callback, YPProxy proxy) {
1156:                    final Collection serviceInfos = new ArrayList();
1157:                    class State {
1158:                        Enumeration e;
1159:                        Callback step2, step3, step4;
1160:                        ServiceInfo serviceInfo;
1161:                        BusinessService bs;
1162:                        YPProxy proxy;
1163:                    }
1164:                    ;
1165:
1166:                    final State state = new State();
1167:                    state.proxy = proxy;
1168:                    // step1 is below
1169:
1170:                    // step2 catches the ServiceDetail and invokes the loop
1171:                    state.step2 = new CallbackDelegate(callback) {
1172:                        public void invoke(Object result) {
1173:                            ServiceDetail sd = (ServiceDetail) result;
1174:                            state.e = sd.getBusinessServiceVector().elements();
1175:                            state.step3.invoke(null);
1176:                        }
1177:                    };
1178:
1179:                    // step 3 starts the loop.
1180:                    state.step3 = new CallbackDelegate(callback) {
1181:                        public void invoke(Object result) {
1182:                            if (result != null) {
1183:                                Collection sbs = (Collection) result;
1184:                                state.serviceInfo.setServiceBindings(sbs);
1185:                                serviceInfos.add(state.serviceInfo);
1186:                            }
1187:                            if (state.e.hasMoreElements()) {
1188:                                state.bs = (BusinessService) state.e
1189:                                        .nextElement();
1190:                                state.serviceInfo = new ServiceInfo();
1191:                                state.serviceInfo.setServiceId(state.bs
1192:                                        .getServiceKey());
1193:                                state.serviceInfo.setServiceName(state.bs
1194:                                        .getDefaultNameString());
1195:                                getServiceClassifications(state.bs
1196:                                        .getCategoryBag(), state.step4,
1197:                                        state.proxy);
1198:                            } else {
1199:                                super .invoke(serviceInfos);
1200:                            }
1201:                        }
1202:                    };
1203:
1204:                    // step 4 adds the SCs
1205:                    state.step4 = new CallbackDelegate(callback) {
1206:                        public void invoke(Object result) {
1207:                            state.serviceInfo
1208:                                    .setServiceClassifications((Collection) result);
1209:                            getServiceBindings(state.bs.getBindingTemplates(),
1210:                                    state.step3, state.proxy);
1211:                        }
1212:                    };
1213:
1214:                    getServiceDetail(state.proxy, serviceKeys, state.step2); // step1
1215:
1216:                }
1217:
1218:                /** @note Callback.invoke(Collection) **/
1219:                private void createServiceInfos(BusinessServices bs,
1220:                        final String providerName, final Collection bzClass,
1221:                        Callback callback, YPProxy proxy) {
1222:                    final Enumeration e = bs.getBusinessServiceVector()
1223:                            .elements();
1224:                    final Collection serviceInfos = new ArrayList();
1225:                    class State {
1226:                        BusinessService svc;
1227:                        Collection scs;
1228:                        Callback chain1;
1229:                        Callback chain2;
1230:                        YPProxy proxy;
1231:                    }
1232:                    ;
1233:                    final State state = new State();
1234:
1235:                    state.proxy = proxy;
1236:
1237:                    // two-step iteration.  ugh.
1238:                    state.chain1 = new CallbackDelegate(callback) {
1239:                        public void invoke(Object result) {
1240:                            if (result != null) {
1241:                                // called from getServiceBindings
1242:                                Collection sbs = (Collection) result;
1243:                                BusinessService svc = state.svc;
1244:                                ServiceInfo serviceInfo = new ServiceInfo(svc
1245:                                        .getDefaultNameString(), svc
1246:                                        .getServiceKey(), state.scs, sbs,
1247:                                        providerName, bzClass);
1248:                                serviceInfos.add(serviceInfo);
1249:                            } // else first time through - nothing to do here
1250:
1251:                            if (e.hasMoreElements()) {
1252:                                // more work to do - ho hum
1253:                                state.svc = (BusinessService) e.nextElement(); // grab svc
1254:                                getServiceClassifications(state.svc
1255:                                        .getCategoryBag(), state.chain2,
1256:                                        state.proxy); // continue in chain2
1257:                            } else {
1258:                                // done, finish the job
1259:                                super .invoke(serviceInfos);
1260:                            }
1261:                        }
1262:                    };
1263:
1264:                    state.chain2 = new CallbackDelegate(callback) {
1265:                        public void invoke(Object result) {
1266:                            state.scs = (Collection) result;
1267:                            getServiceBindings(state.svc.getBindingTemplates(),
1268:                                    state.chain1, state.proxy);
1269:                        }
1270:                    };
1271:
1272:                    state.chain1.invoke(null);
1273:                }
1274:
1275:                /**
1276:                 * Have to create a transient scheme in order to query
1277:                 * based on a classification
1278:                 * @note Callback.invoke(CategoryBag)
1279:                 */
1280:                private void createCategoryBag(Collection classifications,
1281:                        Callback callback, final YPProxy proxy) {
1282:                    final CategoryBag bag = new CategoryBag();
1283:                    final Iterator i = classifications.iterator();
1284:
1285:                    Callback chain = new CallbackDelegate(callback) {
1286:                        public void invoke(Object result) {
1287:                            if (result != null) {
1288:                                bag.getKeyedReferenceVector().add(result);
1289:                            }
1290:                            if (i.hasNext()) {
1291:                                Classification rc = (Classification) i.next();
1292:                                getKeyedReference(proxy, rc
1293:                                        .getClassificationSchemeName(), rc
1294:                                        .getClassificationName(), rc
1295:                                        .getClassificationCode(), this );
1296:                            } else {
1297:                                super .invoke(bag);
1298:                            }
1299:                        }
1300:                    };
1301:                    chain.invoke(null);
1302:                }
1303:
1304:                //
1305:                // utilities
1306:                //
1307:
1308:                // Note - we use this chaining callback to iterate for the next few calls.
1309:                //
1310:                private void getServiceBindings(
1311:                        BindingTemplates bindingTemplates, Callback callback,
1312:                        final YPProxy proxy) {
1313:                    final Collection serviceBindings = new ArrayList();
1314:                    final Enumeration e = bindingTemplates
1315:                            .getBindingTemplateVector().elements();
1316:
1317:                    // this iterates via tail-recursion... shouldn't be a problem, but we could unwind it 
1318:                    Callback chain = new CallbackDelegate(callback) {
1319:                        public void invoke(Object result) {
1320:                            if (result != null) {
1321:                                serviceBindings.add(result);
1322:                            } // first call is null to get the loop going
1323:                            if (e.hasMoreElements()) {
1324:                                BindingTemplate binding = (BindingTemplate) e
1325:                                        .nextElement();
1326:                                getServiceBinding(binding, this , proxy); // (heh heh heh)
1327:                            } else {
1328:                                super .invoke(serviceBindings);
1329:                            }
1330:                        }
1331:                    };
1332:                    chain.invoke(null);
1333:                }
1334:
1335:                /** @note Callback.invoke(Collection) **/
1336:                private void getServiceClassifications(CategoryBag bag,
1337:                        Callback callback, final YPProxy proxy) {
1338:                    final Collection serviceClassifications = new ArrayList();
1339:                    final Enumeration e = bag.getKeyedReferenceVector()
1340:                            .elements();
1341:                    Callback chain = new CallbackDelegate(callback) {
1342:                        public void invoke(Object result) {
1343:                            if (result != null) {
1344:                                serviceClassifications.add(result);
1345:                            }
1346:                            if (e.hasMoreElements()) {
1347:                                KeyedReference kr = (KeyedReference) e
1348:                                        .nextElement();
1349:                                createClassification(
1350:                                        new ServiceClassificationImpl(), kr,
1351:                                        this , proxy);
1352:                            } else {
1353:                                super .invoke(serviceClassifications);
1354:                            }
1355:                        }
1356:                    };
1357:                    chain.invoke(null);
1358:                }
1359:
1360:                /** @note Callback.invoke(Collection) **/
1361:                private void getBusinessClassifications(CategoryBag bag,
1362:                        Callback callback, final YPProxy proxy) {
1363:                    final Collection businessClassifications = new ArrayList();
1364:                    final Enumeration e = bag.getKeyedReferenceVector()
1365:                            .elements();
1366:
1367:                    Callback chain = new CallbackDelegate(callback) {
1368:                        public void invoke(Object result) {
1369:                            if (result != null) {
1370:                                businessClassifications.add(result);
1371:                            }
1372:                            if (e.hasMoreElements()) {
1373:                                KeyedReference kr = (KeyedReference) e
1374:                                        .nextElement();
1375:                                createClassification(
1376:                                        new BusinessClassificationImpl(), kr,
1377:                                        this , proxy);
1378:                            } else {
1379:                                super .invoke(businessClassifications);
1380:                            }
1381:                        }
1382:                    };
1383:                    chain.invoke(null);
1384:                }
1385:
1386:                /** @note Callback.invoke(Classification) **/
1387:                private void createClassification(
1388:                        final Classification classification,
1389:                        final KeyedReference kr, Callback callback,
1390:                        YPProxy proxy) {
1391:                    findTModelName(proxy, kr.getTModelKey(),
1392:                            new CallbackDelegate(callback) {
1393:                                public void invoke(Object result) {
1394:                                    String tModelName = (String) result;
1395:                                    if (tModelName != null) {
1396:                                        classification.setClassificationCode(kr
1397:                                                .getKeyValue());
1398:                                        classification.setClassificationName(kr
1399:                                                .getKeyName());
1400:                                        classification
1401:                                                .setClassificationSchemeName(tModelName);
1402:                                    } else {
1403:                                        log
1404:                                                .error("A serious error occured, tModelName is null for "
1405:                                                        + kr);
1406:                                    }
1407:                                    super .invoke(classification);
1408:                                }
1409:                            });
1410:                }
1411:
1412:                private void getServiceBinding(final BindingTemplate binding,
1413:                        Callback callback, YPProxy proxy) {
1414:                    Enumeration e = binding.getTModelInstanceDetails()
1415:                            .getTModelInstanceInfoVector().elements();
1416:                    if (!e.hasMoreElements()) {
1417:                        callback.handle(new RuntimeException(
1418:                                "No service binding for " + binding));
1419:                        return;
1420:                    }
1421:
1422:                    final TModelInstanceInfo tio = (TModelInstanceInfo) e
1423:                            .nextElement();
1424:                    findTModelName(proxy, tio.getTModelKey(),
1425:                            new CallbackDelegate(callback) {
1426:                                public void invoke(Object result) {
1427:                                    String bindingType = (String) result;
1428:                                    InstanceParms ip = tio.getInstanceDetails()
1429:                                            .getInstanceParms();
1430:                                    ServiceBinding sb = new ServiceBinding(
1431:                                            binding.getAccessPoint().getText(),
1432:                                            bindingType, ip.getText());
1433:                                    super .invoke(sb);
1434:                                }
1435:                            });
1436:                }
1437:
1438:            }
1439:
1440:            private YPProxy makeProxy(Object ypContext) {
1441:                YPProxy proxy = null;
1442:
1443:                if (ypContext == null) {
1444:                    proxy = ypService.getYP();
1445:                } else if (ypContext instanceof  String) {
1446:                    proxy = ypService.getYP((String) ypContext);
1447:                } else if (ypContext instanceof  MessageAddress) {
1448:                    proxy = ypService.getYP((MessageAddress) ypContext);
1449:                } else if (ypContext instanceof  Community) {
1450:                    proxy = ypService.getYP((Community) ypContext,
1451:                            YPProxy.SearchMode.HIERARCHICAL_COMMUNITY_SEARCH);
1452:                } else {
1453:                    throw new IllegalArgumentException(
1454:                            "Invalid datatype for ypContext - "
1455:                                    + ypContext.getClass()
1456:                                    + " - must be String, MessageAddress, or Community.");
1457:                }
1458:
1459:                return proxy;
1460:            }
1461:
1462:            private YPProxy makeProxy(Object ypContext, int searchMode) {
1463:                YPProxy proxy = null;
1464:
1465:                if (ypContext == null) {
1466:                    proxy = ypService.getYP(searchMode);
1467:                } else if (ypContext instanceof  Community) {
1468:                    proxy = ypService.getYP((Community) ypContext, searchMode);
1469:                } else {
1470:                    throw new IllegalArgumentException(
1471:                            "Invalid datatype for ypContext "
1472:                                    + " with YPProxy.SearchMode - "
1473:                                    + ypContext.getClass()
1474:                                    + " - must be Community");
1475:                }
1476:
1477:                return proxy;
1478:            }
1479:
1480:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.