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


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         * 
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         * 
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common Development
008:         * and Distribution License("CDDL") (collectively, the "License").  You
009:         * may not use this file except in compliance with the License. You can obtain
010:         * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011:         * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
012:         * language governing permissions and limitations under the License.
013:         * 
014:         * When distributing the software, include this License Header Notice in each
015:         * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016:         * Sun designates this particular file as subject to the "Classpath" exception
017:         * as provided by Sun in the GPL Version 2 section of the License file that
018:         * accompanied this code.  If applicable, add the following below the License
019:         * Header, with the fields enclosed by brackets [] replaced by your own
020:         * identifying information: "Portions Copyrighted [year]
021:         * [name of copyright owner]"
022:         * 
023:         * Contributor(s):
024:         * 
025:         * If you wish your version of this file to be governed by only the CDDL or
026:         * only the GPL Version 2, indicate your decision by adding "[Contributor]
027:         * elects to include this software in this distribution under the [CDDL or GPL
028:         * Version 2] license."  If you don't indicate a single choice of license, a
029:         * recipient has the option to distribute your version of this file under
030:         * either the CDDL, the GPL Version 2 or to extend the choice of license to
031:         * its licensees as provided above.  However, if you add GPL Version 2 code
032:         * and therefore, elected the GPL Version 2 license, then the option applies
033:         * only if the new code is made subject to such option by the copyright
034:         * holder.
035:         */
036:
037:        package com.sun.jbi.jsf.handlers;
038:
039:        import com.sun.appserv.management.config.ClusteredServerConfig;
040:        import com.sun.appserv.management.j2ee.J2EEServer;
041:        import com.sun.enterprise.tools.admingui.handlers.ConfigurationHandlers;
042:        import com.sun.enterprise.tools.admingui.util.AMXUtil;
043:        import com.sun.enterprise.tools.admingui.util.GuiUtil;
044:        import com.sun.jbi.jsf.bean.AlertBean;
045:        import com.sun.jbi.jsf.util.BeanUtilities;
046:        import com.sun.jbi.jsf.util.ClusterUtilities;
047:        import com.sun.jbi.jsf.util.I18nUtilities;
048:        import com.sun.jbi.jsf.util.JBIConstants;
049:        import com.sun.jbi.jsf.util.JBILogger;
050:        import com.sun.jbi.jsf.util.SharedConstants;
051:        import com.sun.jsftemplating.annotation.Handler;
052:        import com.sun.jsftemplating.annotation.HandlerInput;
053:        import com.sun.jsftemplating.annotation.HandlerOutput;
054:        import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
055:        import java.util.ArrayList;
056:        import java.util.Collections;
057:        import java.util.Iterator;
058:        import java.util.List;
059:        import java.util.Map;
060:        import java.util.Properties;
061:        import java.util.logging.Logger;
062:        import javax.faces.model.SelectItem;
063:
064:        /**
065:         * Provides jsftemplating handlers for instance selection.
066:         */
067:        public class InstanceSelectionHandlers {
068:
069:            private static Logger sLog = JBILogger.getInstance();
070:
071:            /**
072:             *  <p> Returns the values for runtime instances list
073:             *  <p> Output value: "InstancesList" -- Type: <code>SelectItem[]</code></p>
074:             *  @param  context The HandlerContext.
075:             */
076:            @Handler(id="jbiGetRuntimeInstances",input={@HandlerInput(name="addDomainFlag",type=Boolean.class,required=false)},output={@HandlerOutput(name="instancesList",type=SelectItem[].class)})
077:            public static void jbiGetRuntimeInstances(HandlerContext handlerCtx) {
078:                List targetsList = ClusterUtilities.findAllNonDomainTargets();
079:
080:                List allInstancesList = getAllInstances(targetsList);
081:
082:                Collections.sort(allInstancesList);
083:
084:                String[] instancesArray = new String[0];
085:                instancesArray = (String[]) allInstancesList
086:                        .toArray(instancesArray);
087:                SelectItem[] options = ConfigurationHandlers
088:                        .getOptions(instancesArray);
089:
090:                handlerCtx.setOutputValue("instancesList", options);
091:                sLog
092:                        .fine("InstanceSelectionHandlers.jbiGetRuntimeInstances(), options.length="
093:                                + options.length);
094:            }
095:
096:            /**
097:             *  <p> Returns the values for runtime configuration targets list
098:             *  <p> Input value: "addDomainFlag" <code>Boolean</code> true if "domain" should
099:             *  appear in the returned list of targets
100:             *  <p> Output value: "TargetsList" -- Type: <code>SelectItem[]</code></p>
101:             *  @param  context The HandlerContext.
102:             */
103:            @Handler(id="jbiGetRuntimeTargets",input={@HandlerInput(name="addDomainFlag",type=Boolean.class,required=false)},output={@HandlerOutput(name="targetsList",type=SelectItem[].class)})
104:            public static void jbiGetRuntimeTargets(HandlerContext handlerCtx) {
105:                boolean addDomain = true;
106:                Boolean addDomainFlag = (Boolean) handlerCtx
107:                        .getInputValue("addDomainFlag");
108:                if (addDomainFlag != null) {
109:                    addDomain = addDomainFlag;
110:                }
111:
112:                List targetsList = ClusterUtilities.findAllNonDomainTargets();
113:                Collections.sort(targetsList);
114:                if (addDomain) {
115:                    targetsList.add(0, "domain");
116:                }
117:
118:                String[] targetsArray = new String[0];
119:                targetsArray = (String[]) targetsList.toArray(targetsArray);
120:                SelectItem[] options = ConfigurationHandlers
121:                        .getOptions(targetsArray);
122:
123:                handlerCtx.setOutputValue("targetsList", options);
124:                sLog
125:                        .fine("InstanceSelectionHandlers.jbiGetRuntimeTargets(), options.length="
126:                                + options.length);
127:            }
128:
129:            /**
130:             * <p> Returns the values for instances in configureComponent page
131:             * <p> Input value: "type" -- Type: <code>String</code></p> one of:
132:             * <code>binding-component</code>, <code>service-engine</code>, or
133:             * <code>service-assembly</code>
134:             * <p> Input value: "compOrSaName" -- Type: <code>String</code></p>
135:             * <p> Output value: "InstanceList" -- Type: <code>SelectItem[]</code></p>
136:             * <p> Output value: "isAlertNeeded" -- Type: <code>Boolean</code></p>
137:             * <p> Output value: "alertSummary" -- Type: <code>String</code></p>
138:             * <p> Output value: "alertDetails" -- Type: <code>String</code></p>
139:             * @param handlerCtx the context used for inputs and outputs
140:             */
141:            @Handler(id="jbiGetInstances",input={@HandlerInput(name="type",type=String.class,required=true),@HandlerInput(name="compOrSaName",type=String.class,required=true)},output={@HandlerOutput(name="instancesList",type=SelectItem[].class),@HandlerOutput(name="isAlertNeeded",type=Boolean.class),@HandlerOutput(name="alertSummary",type=String.class),@HandlerOutput(name="alertDetails",type=String.class)})
142:            public static void jbiGetInstances(HandlerContext handlerCtx) {
143:                String type = (String) handlerCtx.getInputValue("type");
144:                String compOrSaName = (String) handlerCtx
145:                        .getInputValue("compOrSaName");
146:                sLog.fine("InstanceSelectionHandlers.jbiGetInstances(), type="
147:                        + type + ", compOrSaName=" + compOrSaName);
148:
149:                List installedTargetsList = new ArrayList();
150:                List installedList = ClusterUtilities.findTargetsForNameByType(
151:                        compOrSaName, type);
152:                // Construct the installedTargetsList
153:                Iterator targetsIterator = installedList.iterator();
154:                while (targetsIterator.hasNext()) {
155:                    Properties targetProp = (Properties) targetsIterator.next();
156:                    String target = targetProp
157:                            .getProperty(SharedConstants.KEY_NAME);
158:                    installedTargetsList.add(target);
159:                }
160:
161:                List installedInstancesList = getAllInstances(installedTargetsList);
162:                Collections.sort(installedInstancesList);
163:
164:                // Construct the warning message if component is not installed on any target
165:                String alertType = "";
166:                String alertDetails = "";
167:                String alertSummary = "";
168:                boolean isAlertNeeded = false;
169:                if (installedInstancesList.size() == 0) {
170:                    isAlertNeeded = true;
171:                    alertType = "warning";
172:                    if ("service-assembly".equals(type)) {
173:                        alertSummary = I18nUtilities
174:                                .getResourceString("jbi.sa.not.installed.to.target.summary");
175:                    } else {
176:                        alertSummary = I18nUtilities
177:                                .getResourceString("jbi.component.not.installed.to.target.summary");
178:                    }
179:                    if (null == compOrSaName) {
180:                        compOrSaName = ""; // prevent NPE in GuiUtil
181:                    }
182:                    Object[] args = { compOrSaName };
183:                    alertDetails = GuiUtil
184:                            .getMessage(
185:                                    I18nUtilities
186:                                            .getResourceString("jbi.component.not.installed.to.target.details"),
187:                                    args);
188:                    AlertBean alertBean = BeanUtilities.getAlertBean();
189:                    alertBean.setAlertType(alertType);
190:                }
191:
192:                // Return the options list
193:                String[] instances = new String[0];
194:                instances = (String[]) installedInstancesList
195:                        .toArray(instances);
196:                SelectItem[] options = ConfigurationHandlers
197:                        .getOptions(instances);
198:
199:                handlerCtx.setOutputValue("instancesList", options);
200:                handlerCtx.setOutputValue("isAlertNeeded", isAlertNeeded);
201:                handlerCtx.setOutputValue("alertSummary", alertSummary);
202:                handlerCtx.setOutputValue("alertDetails", alertDetails);
203:                sLog
204:                        .fine("InstanceSelectionHandlers.jbiGetInstances(), options.length="
205:                                + options.length);
206:            }
207:
208:            /**
209:             *  <p> This handler sets the values for instances to be updated in configureComponent page
210:             *  <p> Input value: "fromInstance" -- Type: <code>java.lang.String</code></p>
211:             *  <p> Output value: "toInstances" -- Type: <code>java.lang.String[]</code></p>
212:             *  @param  context The HandlerContext.
213:             */
214:            @Handler(id="jbiSetDefaultSelectedInstances",input={@HandlerInput(name="fromInstance",type=String.class,required=true)},output={@HandlerOutput(name="toInstances",type=String[].class)})
215:            public static void jbiSetDefaultSelectedInstances(
216:                    HandlerContext handlerCtx) {
217:                String[] result = new String[0];
218:                String fromInstance = (String) handlerCtx
219:                        .getInputValue("fromInstance");
220:                result[0] = fromInstance;
221:                sLog
222:                        .fine("InstanceSelectionHandlers.jbiSetDefaultSelectedInstances("
223:                                + fromInstance
224:                                + "), result.length="
225:                                + result.length);
226:                handlerCtx.setOutputValue("toInstances", result);
227:            }
228:
229:            /**
230:             *  <p> This converts an object array (containing strings) to a string array
231:             *  <p> Input value: "fromObjectArray" -- Type: <code>java.lang.Object[]</code></p>
232:             *  <p> Output value: "toStringArray" -- Type: <code>java.lang.String[]</code></p>
233:             *  @param  context The HandlerContext.
234:             */
235:            @Handler(id="jbiObjectArrayToStringArray",input={@HandlerInput(name="fromObjectArray",type=Object[].class,required=true)},output={@HandlerOutput(name="toStringArray",type=String[].class)})
236:            public static void jbiObjectArrayToStringArray(
237:                    HandlerContext handlerCtx) {
238:                String[] result;
239:                Object[] fromObjectArray = (Object[]) handlerCtx
240:                        .getInputValue("fromObjectArray");
241:                if (null != fromObjectArray) {
242:                    result = new String[fromObjectArray.length];
243:                    for (int i = 0; i < result.length; ++i) {
244:                        result[i] = (String) fromObjectArray[i];
245:                    }
246:                } else {
247:                    result = new String[0];
248:                }
249:                sLog
250:                        .fine("InstanceSelectionHandlers.jbiObjectArrayToStringArray("
251:                                + fromObjectArray
252:                                + "), result.length="
253:                                + result.length);
254:                handlerCtx.setOutputValue("toStringArray", result);
255:            }
256:
257:            /**
258:             *  <p> This handler converts an array of strings to a printable comma separated list in one string
259:             *  <p> Input value: "fromStringArray" -- Type: <code>java.lang.String[]</code></p>
260:             *  <p> Output value: "toStringWithCommas" -- Type: <code>java.lang.String</code></p>
261:             *  @param  context The HandlerContext.
262:             */
263:            @Handler(id="jbiListArrayStrings",input={@HandlerInput(name="fromStringArray",type=Object[].class,required=true)},output={@HandlerOutput(name="toStringWithCommas",type=String.class)})
264:            public static void jbiListArrayStrings(HandlerContext handlerCtx) {
265:                String result = "list: [";
266:                Object[] fromStringArray = (Object[]) handlerCtx
267:                        .getInputValue("fromStringArray");
268:                for (int i = 0; i < fromStringArray.length; ++i) {
269:                    result += (String) fromStringArray[i];
270:                    result += ", ";
271:                }
272:                result += " ]";
273:
274:                sLog.fine("InstanceSelectionHandlers.jbiListArrayStrings("
275:                        + fromStringArray + "), result=" + result);
276:                handlerCtx.setOutputValue("toStringWithCommas", result);
277:            }
278:
279:            /**
280:             * Gets a list of all instances from the specified list of targets
281:             * @param aTargetsArray contains cluster target names and standalone
282:             * server target names
283:             * @return all instances in each cluster specified and all standalone
284:             * instances that were in the original target list
285:             */
286:            private static List getAllInstances(List aTargetsArray) {
287:                ArrayList result = new ArrayList();
288:
289:                Iterator targetsIterator = aTargetsArray.iterator();
290:
291:                Iterator targetIt = aTargetsArray.iterator();
292:                while (targetIt.hasNext()) {
293:                    String target = (String) targetIt.next();
294:
295:                    // for each cluster target, add all of its instances (if any)
296:                    if (ClusterUtilities.isCluster(target)) {
297:                        sLog
298:                                .fine("InstanceSelectionHandlers.jbiGetInstances(), cluster target="
299:                                        + target);
300:
301:                        Map<String, ClusteredServerConfig> serverMap = AMXUtil
302:                                .getDomainConfig().getClusterConfigMap().get(
303:                                        target).getClusteredServerConfigMap();
304:
305:                        List instancesForOneCluster = new ArrayList();
306:
307:                        if (null != serverMap) {
308:                            for (String key : serverMap.keySet()) {
309:                                String name = serverMap.get(key).getName();
310:
311:                                J2EEServer server = AMXUtil.getJ2EEDomain()
312:                                        .getJ2EEServerMap().get(name);
313:
314:                                int state = server.getstate();
315:                                if (state == 1) {
316:                                    instancesForOneCluster.add(name);
317:                                }
318:                                sLog
319:                                        .fine("InstanceSelectionHandlers.jbiGetInstances(), cluster target="
320:                                                + target
321:                                                + ", instanceName="
322:                                                + name + ", state=" + state);
323:                            }
324:                        }
325:
326:                        Iterator instanceIt = instancesForOneCluster.iterator();
327:                        while (instanceIt.hasNext()) {
328:                            String instance = (String) instanceIt.next();
329:                            result.add(instance);
330:                        }
331:                    }
332:                    // for each stand-alone server target, add it as an instance
333:                    else {
334:                        J2EEServer server = AMXUtil.getJ2EEDomain()
335:                                .getJ2EEServerMap().get(target);
336:
337:                        int state = server.getstate();
338:
339:                        if (state == 1) {
340:                            result.add(target);
341:                        }
342:                        sLog
343:                                .fine("InstanceSelectionHandlers.jbiGetInstances(), stand-alone server target="
344:                                        + target + ", state=" + state);
345:                    }
346:                }
347:
348:                return result;
349:            }
350:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.