Source Code Cross Referenced for ServiceAssemblyQueryImpl.java in  » ESB » open-esb » com » sun » jbi » management » registry » xml » 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 » ESB » open esb » com.sun.jbi.management.registry.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)ServiceAssemblyQueryImpl.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        /**
030:         *  ServiceAssemblyQueryImpl.java
031:         *
032:         *  SUN PROPRIETARY/CONFIDENTIAL.
033:         *  This software is the proprietary information of Sun Microsystems, Inc.
034:         *  Use is subject to license terms.
035:         *
036:         *  Created on August 23, 2006, 5:17 PM
037:         */package com.sun.jbi.management.registry.xml;
038:
039:        import java.util.List;
040:        import java.util.ArrayList;
041:        import java.util.Map;
042:        import java.util.HashMap;
043:        import java.util.logging.Logger;
044:
045:        import com.sun.jbi.StringTranslator;
046:        import com.sun.jbi.management.registry.Registry;
047:        import com.sun.jbi.management.registry.RegistryException;
048:        import com.sun.jbi.management.repository.ArchiveType;
049:        import com.sun.jbi.management.LocalStringKeys;
050:        import com.sun.jbi.management.system.ManagementContext;
051:
052:        import com.sun.jbi.ComponentInfo;
053:        import com.sun.jbi.ComponentState;
054:        import com.sun.jbi.ComponentType;
055:        import com.sun.jbi.ServiceUnitInfo;
056:        import com.sun.jbi.ServiceAssemblyInfo;
057:        import com.sun.jbi.ServiceAssemblyState;
058:        import com.sun.jbi.ServiceUnitState;
059:        import com.sun.jbi.management.registry.data.ServiceAssemblyInfoImpl;
060:        import com.sun.jbi.management.registry.data.ServiceUnitInfoImpl;
061:        import com.sun.jbi.management.descriptor.ServiceAssemblyDescriptor;
062:
063:        import javax.xml.bind.JAXBException;
064:
065:        /**
066:         * This class encapsulates queries which are common to 
067:         * all targets ( domain / server / cluster ).
068:         *
069:         * @author Sun Microsystems, Inc.
070:         */
071:        public class ServiceAssemblyQueryImpl implements 
072:                com.sun.jbi.ServiceAssemblyQuery {
073:
074:            private Jbi mJbiRegistry;
075:            private Registry mRegistry;
076:            private boolean mValidate;
077:            private ManagementContext mMgtCtx;
078:            private Logger mLogger;
079:            private StringTranslator mTranslator;
080:            private GenericQueryImpl mGenQuery;
081:            private ObjectFactory mObjectFactory;
082:            private String mTarget;
083:            private ComponentQueryImpl mComponentQuery;
084:
085:            private static final String DOMAIN = "domain";
086:
087:            public ServiceAssemblyQueryImpl(Jbi jbi, ManagementContext mgtCtx,
088:                    boolean validate, String targetName, Registry registry)
089:                    throws RegistryException {
090:                mTarget = targetName;
091:                mJbiRegistry = jbi;
092:                mRegistry = registry;
093:                mValidate = validate;
094:                mMgtCtx = mgtCtx;
095:                mLogger = mMgtCtx.getLogger();
096:                mTranslator = mMgtCtx.getEnvironmentContext()
097:                        .getStringTranslator("com.sun.jbi.management");
098:
099:                mGenQuery = (GenericQueryImpl) mRegistry.getGenericQuery();
100:                mComponentQuery = (ComponentQueryImpl) mRegistry
101:                        .getComponentQuery(mTarget);
102:
103:                mObjectFactory = new ObjectFactory();
104:            }
105:
106:            /*--------------------------------------------------------------------------------*\
107:             *                          Query Ops                                             *
108:            \*--------------------------------------------------------------------------------*/
109:
110:            /**
111:             * Get a list of all deployed service assembly names.
112:             *
113:             * @return A List<String> of all deployed service assemblies.
114:             */
115:            public List<String> getServiceAssemblies()
116:
117:            {
118:                List<String> serviceAssemblies = new ArrayList();
119:                try {
120:                    if (mTarget.equals(DOMAIN)) {
121:                        serviceAssemblies = mGenQuery
122:                                .getRegisteredServiceAssemblies();
123:                    } else {
124:
125:                        InstalledComponentsListType target = null;
126:                        try {
127:                            target = mGenQuery.getInstalledEntities(mTarget);
128:                        } catch (RegistryException rex) {
129:                            throw rex;
130:                        }
131:
132:                        List<ServiceAssemblyRefType> saRefs = target
133:                                .getServiceAssemblyRef();
134:                        for (ServiceAssemblyRefType saRef : saRefs) {
135:                            String saName = saRef.getNameRef();
136:                            serviceAssemblies.add(saName);
137:                        }
138:                    }
139:                } catch (RegistryException rex) {
140:                    mLogger.warning(rex.getMessage());
141:                } finally {
142:                    return serviceAssemblies;
143:                }
144:            }
145:
146:            /**
147:             * Get the ServiceAssemblyInfo for a particular Service Assembly.
148:             * @param serviceAssemblyName The unique name of the service assembly being retrieved.
149:             * @return The ServiceAssemblyInfo for the requested service assembly or null if the
150:             * service assembly is not registered.
151:             */
152:            public ServiceAssemblyInfo getServiceAssemblyInfo(
153:                    String serviceAssemblyName) {
154:                try {
155:                    if (mGenQuery
156:                            .isServiceAssemblyRegistered(serviceAssemblyName)) {
157:
158:                        mLogger
159:                                .finest("Getting Service Assembly "
160:                                        + serviceAssemblyName + " on target "
161:                                        + mTarget);
162:
163:                        ServiceAssemblyInfoImpl saInfo = new ServiceAssemblyInfoImpl();
164:
165:                        saInfo.setName(serviceAssemblyName);
166:                        com.sun.jbi.management.descriptor.Jbi jbi = mGenQuery
167:                                .getServiceAssemblyJbi(serviceAssemblyName);
168:                        if (jbi == null) {
169:                            return (saInfo);
170:                        }
171:
172:                        ServiceAssemblyDescriptor descr = new ServiceAssemblyDescriptor(
173:                                jbi);
174:
175:                        saInfo.setDescription(descr.getDescription());
176:                        List<ServiceUnitInfo> resultSus = new ArrayList();
177:
178:                        if (mTarget != DOMAIN) {
179:                            List<ServiceUnitInfo> suList = descr
180:                                    .getServiceUnits();
181:                            List<ServiceUnitState> suStates = new ArrayList();
182:
183:                            for (ServiceUnitInfo su : suList) {
184:
185:                                ComponentInfo compInfo = mComponentQuery
186:                                        .getComponentInfo(su
187:                                                .getTargetComponent());
188:
189:                                if (compInfo != null) {
190:                                    List<ServiceUnitInfo> compSus = compInfo
191:                                            .getServiceUnitList();
192:                                    for (ServiceUnitInfo suInfo : compSus) {
193:
194:                                        if (suInfo.getName().equals(
195:                                                su.getName())
196:                                                && suInfo
197:                                                        .getServiceAssemblyName()
198:                                                        .equals(
199:                                                                serviceAssemblyName)) {
200:                                            resultSus.add(suInfo);
201:                                            suStates.add(suInfo.getState());
202:                                        }
203:                                    }
204:                                }
205:                            }
206:
207:                            if (!suStates.isEmpty()) {
208:                                ServiceAssemblyState saState = ServiceAssemblyState
209:                                        .computeServiceAssemblyState(suStates);
210:                                saInfo.setStatus(saState);
211:                            } else {
212:                                ServiceAssemblyRefType saRef = mGenQuery
213:                                        .getServiceAssembly(
214:                                                serviceAssemblyName, mTarget);
215:                                if (saRef != null && saRef.getState() != null) {
216:                                    // Service assembly deployed with zero service units
217:                                    saInfo
218:                                            .setStatus(ServiceAssemblyState
219:                                                    .valueOfDeploymentServiceState(saRef
220:                                                            .getState().value()));
221:                                } else {
222:                                    // -- Service assembly is not deployed to the target
223:                                    saInfo
224:                                            .setStatus(ServiceAssemblyState.UNKNOWN);
225:                                }
226:                            }
227:
228:                        } else {
229:                            // Create a Service Unit list based on information from  the jbi.xml
230:                            List<ServiceUnitInfo> suList = descr
231:                                    .getServiceUnits();
232:
233:                            for (ServiceUnitInfo su : suList) {
234:                                ServiceUnitInfoImpl suInfo = (ServiceUnitInfoImpl) su;
235:
236:                                // Set the path to the archive
237:                                String suRelPath = serviceAssemblyName
238:                                        + java.io.File.separator + su.getName();
239:                                ;
240:
241:                                String suArchiveDir = mRegistry.getRepository()
242:                                        .findArchiveDirectory(
243:                                                ArchiveType.SERVICE_UNIT,
244:                                                suRelPath);
245:
246:                                String filePath = suArchiveDir
247:                                        + java.io.File.separator
248:                                        + su.getTargetComponent();
249:                                suInfo.setFilePath(filePath);
250:                                resultSus.add(suInfo);
251:                            }
252:
253:                            List<ServiceAssemblyState> saStates = getAllServiceAssemblyStates(serviceAssemblyName);
254:                            saInfo
255:                                    .setStatus(ServiceAssemblyState
256:                                            .getEffectiveServiceAssemblyState(saStates));
257:                        }
258:                        saInfo.setServiceUnitList(resultSus);
259:                        return saInfo;
260:                    } else {
261:                        mLogger.finest("Service Assembly "
262:                                + serviceAssemblyName
263:                                + " not registered in domain");
264:                    }
265:
266:                } catch (Exception rex) {
267:                    rex.printStackTrace();
268:                    mLogger.severe(rex.getMessage());
269:                }
270:                return null;
271:            }
272:
273:            /**
274:             * Get the current status of a service assembly.
275:             *
276:             * @param serviceAssemblyName The unique service assembly name.
277:             * @return The current status of the service assembly: ServiceAssemblyState 
278:             *         {SHUTDOWN, STOPPED, STARTED, UNKNOWN}
279:             * @throws javax.jbi.JBIException if the service assembly is not registered.
280:             */
281:            public com.sun.jbi.ServiceAssemblyState getStatus(
282:                    String serviceAssemblyName) throws javax.jbi.JBIException {
283:                return getServiceAssemblyInfo(serviceAssemblyName).getStatus();
284:            }
285:
286:            /**
287:             * @return a List conating the state of the service assembly on each server/
288:             * custer in the domain.
289:             * @param saName - service assembly name
290:             */
291:            private List<ServiceAssemblyState> getAllServiceAssemblyStates(
292:                    String saName) throws RegistryException {
293:                List<String> servers = mGenQuery.getServers();
294:                List<String> clusters = mGenQuery.getClusters();
295:                List<ServiceAssemblyState> saStates = new ArrayList();
296:
297:                for (String server : servers) {
298:                    ServiceAssemblyState saState = getServiceAssemblyStateOnTarget(
299:                            saName, server);
300:
301:                    if (!(ServiceAssemblyState.UNKNOWN == saState)) {
302:                        saStates.add(saState);
303:                    }
304:                }
305:
306:                for (String cluster : clusters) {
307:
308:                    ServiceAssemblyState saState = getServiceAssemblyStateOnTarget(
309:                            saName, cluster);
310:
311:                    if (!(ServiceAssemblyState.UNKNOWN == saState)) {
312:                        saStates.add(saState);
313:                    }
314:                }
315:
316:                return saStates;
317:            }
318:
319:            /**
320:             * Query the state of the service assembly on a server / cluster.
321:             *
322:             * @return the service assembly state.
323:             */
324:            private ServiceAssemblyState getServiceAssemblyStateOnTarget(
325:                    String saName, String target) throws RegistryException {
326:                com.sun.jbi.ServiceAssemblyQuery saQuery = mRegistry
327:                        .getServiceAssemblyQuery(target);
328:
329:                ServiceAssemblyInfo saInfo = saQuery
330:                        .getServiceAssemblyInfo(saName);
331:
332:                if (saInfo != null) {
333:                    return saInfo.getStatus();
334:                }
335:
336:                return ServiceAssemblyState.UNKNOWN;
337:            }
338:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.