Source Code Cross Referenced for AddonServiceBroker.java in  » Science » Cougaar12_4 » org » cougaar » core » component » 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.core.component 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 2000-2004 BBNT Solutions, LLC
005:         *  under sponsorship of the Defense Advanced Research Projects
006:         *  Agency (DARPA).
007:         * 
008:         *  You can redistribute this software and/or modify it under the
009:         *  terms of the Cougaar Open Source License as published on the
010:         *  Cougaar Open Source Website (www.cougaar.org).
011:         * 
012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023:         *  
024:         * </copyright>
025:         */
026:        package org.cougaar.core.component;
027:
028:        import java.util.Iterator;
029:
030:        import org.cougaar.util.ChainingIterator;
031:
032:        /** A Simple ServiceBroker which does a simple delegation
033:         * of service requests for most purposes, except that it has
034:         * an escape hatch where extending classes may, in effect, themselves
035:         * offer services directly to the requestors.
036:         * <p>
037:         * @note Unlike DelegatingServiceBroker, no attempt at hiding the delegate is made.
038:         **/
039:
040:        public class AddonServiceBroker implements  ExtendedServiceBroker {
041:            public AddonServiceBroker(ServiceBroker delegate) {
042:                if (delegate == null)
043:                    throw new IllegalArgumentException(
044:                            "Delegate must be non-null");
045:                this .delegate = delegate;
046:            }
047:
048:            private ServiceBroker delegate;
049:
050:            protected final ServiceBroker getDelegate() {
051:                return delegate;
052:            }
053:
054:            public final void addServiceListener(final ServiceListener sl) {
055:                delegate.addServiceListener(sl);
056:            }
057:
058:            public final void removeServiceListener(ServiceListener sl) {
059:                delegate.removeServiceListener(sl);
060:            }
061:
062:            public final boolean addService(Class serviceClass,
063:                    ServiceProvider serviceProvider) {
064:                return addService(serviceClass, serviceProvider, 0, null);
065:            }
066:
067:            public final boolean addService(Class serviceClass,
068:                    ServiceProvider serviceProvider, int providerId,
069:                    ComponentDescription providerDesc) {
070:                if (delegate instanceof  ExtendedServiceBroker) {
071:                    ExtendedServiceBroker esb = (ExtendedServiceBroker) delegate;
072:                    return esb.addService(serviceClass, serviceProvider,
073:                            providerId, providerDesc);
074:                } else {
075:                    return delegate.addService(serviceClass, serviceProvider);
076:                }
077:            }
078:
079:            public final void revokeService(Class serviceClass,
080:                    ServiceProvider serviceProvider) {
081:                delegate.revokeService(serviceClass, serviceProvider);
082:            }
083:
084:            public final void revokeService(Class serviceClass,
085:                    ServiceProvider serviceProvider, int providerId,
086:                    ComponentDescription providerDesc) {
087:                if (delegate instanceof  ExtendedServiceBroker) {
088:                    ExtendedServiceBroker esb = (ExtendedServiceBroker) delegate;
089:                    esb.revokeService(serviceClass, serviceProvider,
090:                            providerId, providerDesc);
091:                } else {
092:                    delegate.revokeService(serviceClass, serviceProvider);
093:                }
094:            }
095:
096:            public final boolean hasService(Class serviceClass) {
097:                return hasLocalService(serviceClass)
098:                        || delegate.hasService(serviceClass);
099:            }
100:
101:            public final Iterator getCurrentServiceClasses() {
102:                return new ChainingIterator(new Iterator[] {
103:                        getCurrentLocalServiceClasses(),
104:                        delegate.getCurrentServiceClasses() });
105:            }
106:
107:            public final <T> T getService(Object requestor,
108:                    final Class<T> serviceClass,
109:                    final ServiceRevokedListener srl) {
110:                ServiceResult sr = getService(0, null, requestor, serviceClass,
111:                        srl, true);
112:                return (sr == null ? null : (T) sr.getService());
113:            }
114:
115:            public final ServiceResult getService(int requestorId,
116:                    ComponentDescription requestorDesc, Object requestor,
117:                    Class serviceClass, ServiceRevokedListener srl,
118:                    boolean recordInView) {
119:                Object s = getLocalService(requestor, serviceClass, srl);
120:                if (s != null) {
121:                    if (s instanceof  NullService) {
122:                        s = null;
123:                    }
124:                } else if (delegate instanceof  ExtendedServiceBroker) {
125:                    ExtendedServiceBroker esb = (ExtendedServiceBroker) delegate;
126:                    ServiceResult sr = esb.getService(requestorId,
127:                            requestorDesc, requestor, serviceClass, srl,
128:                            recordInView);
129:                    if (sr != null) {
130:                        if (sr.getService() instanceof  NullService) {
131:                            sr = new ServiceResult(sr.getProviderId(), sr
132:                                    .getProviderComponentDescription(), null);
133:                        }
134:                        return sr;
135:                    }
136:                    s = null;
137:                } else {
138:                    s = delegate.getService(requestor, serviceClass, srl);
139:                }
140:                return (s == null ? null : new ServiceResult(0, null, s));
141:            }
142:
143:            public final void releaseService(Object requestor,
144:                    Class serviceClass, Object service) {
145:                releaseService(0, null, requestor, serviceClass, service, true);
146:            }
147:
148:            public final void releaseService(int requestorId,
149:                    ComponentDescription requestorDesc, Object requestor,
150:                    Class serviceClass, Object service, boolean recordInView) {
151:                boolean wasReleased = releaseLocalService(requestor,
152:                        serviceClass, service);
153:                if (!wasReleased) {
154:                    if (delegate instanceof  ExtendedServiceBroker) {
155:                        ExtendedServiceBroker esb = (ExtendedServiceBroker) delegate;
156:                        esb.releaseService(requestorId, requestorDesc,
157:                                requestor, serviceClass, service, recordInView);
158:                    } else {
159:                        delegate.releaseService(requestor, serviceClass,
160:                                service);
161:                    }
162:                }
163:            }
164:
165:            /** Defined by extending classes to respond to hasService calls from 
166:             * clients.  A service need not be advertised here for getLocalService
167:             * to work.  The default implementation just returns false.
168:             **/
169:            protected boolean hasLocalService(Class serviceClass) {
170:                return false;
171:            }
172:
173:            /** Defined by extending classes to advertise a service to the
174:             * clients.  A service need not be advertised here for getLocalService
175:             * to work.  The default implementation returns null.
176:             **/
177:            protected Iterator getCurrentLocalServiceClasses() {
178:                return null;
179:            }
180:
181:            /** Defined by extending classes to provide services to 
182:             * clients.  The default implementation returns null.
183:             **/
184:            protected Object getLocalService(Object requestor,
185:                    final Class serviceClass, final ServiceRevokedListener srl) {
186:                return null;
187:            }
188:
189:            /** Defined by extending classes to release previously granted
190:             * services.  Should return true IFF the service was released.
191:             * The default implementation returns false.
192:             **/
193:            protected boolean releaseLocalService(Object requestor,
194:                    Class serviceClass, Object service) {
195:                return false;
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.