|
Glassfish example source code file (JdbcTempHandler.java)
This example Glassfish source code file (JdbcTempHandler.java) is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.
The Glassfish JdbcTempHandler.java source code
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2009-2011 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/*
* JdbcHandler.java
*
* Created on August 10, 2006, 2:32 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author anilam
*/
package org.glassfish.admingui.common.handlers;
import com.sun.jsftemplating.annotation.Handler;
import com.sun.jsftemplating.annotation.HandlerInput;
import com.sun.jsftemplating.annotation.HandlerOutput;
import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.glassfish.admingui.common.util.GuiUtil;
import org.glassfish.admingui.common.util.RestUtil;
public class JdbcTempHandler {
/** Creates a new instance of JdbcHandler */
public JdbcTempHandler() {
}
/**
* <p> This handler gets the default values and resource type and puts them in session
*/
@Handler(id = "setJDBCPoolWizard",
input = {
@HandlerInput(name = "fromStep2", type = Boolean.class),
@HandlerInput(name = "attrMap", type = Map.class)},
output = {
@HandlerOutput(name = "ResTypeList", type = java.util.List.class),
@HandlerOutput(name = "DBVendorList", type = java.util.List.class)
})
public static void setJDBCPoolWizard(HandlerContext handlerCtx) {
//We need to use 2 maps for JDBC Connection Pool creation because there are extra info we need to keep track in
//the wizard, but cannot be passed to the creation API.
Boolean fromStep2 = (Boolean) handlerCtx.getInputValue("fromStep2");
if ((fromStep2 != null) && fromStep2) {
//wizardPool is already in session map
} else {
Map attrMap = (Map) handlerCtx.getInputValue("attrMap");
Map sessionMap = handlerCtx.getFacesContext().getExternalContext().getSessionMap();
sessionMap.put("wizardMap", attrMap);
sessionMap.put("wizardPoolExtra", new HashMap());
//sessionMap.put("wizardPoolProperties", new HashMap());
}
handlerCtx.setOutputValue("ResTypeList", resTypeList);
handlerCtx.setOutputValue("DBVendorList", dbVendorList);
}
/**
* <p> This handler gets the datasource classname and properties and sets them in session
*/
@Handler(id = "gf.updateJDBCPoolWizardStep1")
public static void updateJDBCPoolWizardStep1(HandlerContext handlerCtx) {
//Map pool = (Map) handlerCtx.getFacesContext().getExternalContext().getSessionMap().get("wizardPool");
Map extra = (Map) handlerCtx.getFacesContext().getExternalContext().getSessionMap().get("wizardPoolExtra");
String resType = (String) extra.get("resType");
String dbVendorBox = (String) extra.get("DBVendorBox");
String dbVendorField = (String) extra.get("DBVendorField");
String dbVendor = (GuiUtil.isEmpty(dbVendorField)) ? dbVendorBox : dbVendorField;
extra.put("DBVendor", dbVendor);
String previousResType = (String) extra.get("PreviousResType");
String previousDB = (String) extra.get("PreviousDB");
if (resType.equals(previousResType) && dbVendor.equals(previousDB)) {
//&& !GuiUtil.isEmpty((String) extra.get("DatasourceClassname"))) {
//User didn't change type and DB, keep the datasource classname as the same.
} else {
if (!GuiUtil.isEmpty(resType) && !GuiUtil.isEmpty(dbVendor)) {
List dsl = new ArrayList();
try {
String classname = "";
dsl = getJdbcDriverClassNames(dbVendor, resType, false);
if (guiLogger.isLoggable(Level.FINE)) {
guiLogger.fine("======= getJdbcDriverClassNames(" + dbVendor + ", " + resType + ")");
guiLogger.fine("======= # of items for JDBC_DRIVER_CLASS_NAMES_KEY " + dsl.size());
for (int i = 0; i < dsl.size(); i++) {
guiLogger.fine("classname[" + i + "] : " + dsl.get(i));
}
}
List<Map noprops = new ArrayList
Other Glassfish examples (source code examples)
Here is a short list of links related to this Glassfish JdbcTempHandler.java source code file:
|