|
Glassfish example source code file (StaticRmiStubGenerator.java)
The Glassfish StaticRmiStubGenerator.java source code/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 1997-2010 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. */ package com.sun.ejb.codegen; import java.lang.reflect.Method; import java.io.*; import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; import org.glassfish.api.deployment.DeploymentContext; import org.glassfish.deployment.common.ClientArtifactsManager; import org.glassfish.ejb.spi.CMPDeployer; import com.sun.enterprise.util.i18n.StringManager; import com.sun.logging.LogDomains; import org.jvnet.hk2.component.Habitat; import com.sun.enterprise.config.serverbeans.JavaConfig; import com.sun.enterprise.deployment.Application; import com.sun.enterprise.deployment.EjbDescriptor; import com.sun.enterprise.deployment.EjbBundleDescriptor; import com.sun.enterprise.deployment.util.TypeUtil; import com.sun.enterprise.util.OS; /** * This class is used to generate the RMI-IIOP version of a * remote business interface. */ public class StaticRmiStubGenerator { private static final StringManager localStrings = StringManager.getManager(StaticRmiStubGenerator.class); private static final Logger _logger = LogDomains.getLogger(StaticRmiStubGenerator.class, LogDomains.EJB_LOGGER); private static final String ORG_OMG_STUB_PREFIX = "org.omg.stub."; private final String toolsJarPath; private List<String> rmicOptionsList; /** * This class is only instantiated internally. */ public StaticRmiStubGenerator(Habitat h) { // Find java path and tools.jar //Try this jre's parent String jreHome = System.getProperty("java.home"); File jdkDir = null; if(jreHome != null) { // on the mac the java.home does not point to the jre // subdirectory. if (OS.isDarwin()) { jdkDir = new File(jreHome); } else { jdkDir = (new File(jreHome)).getParentFile(); //jdk_dir/jre/.. } jdkDir = getValidDirectory(jdkDir); } if(jdkDir == null) { // Check for "JAVA_HOME" -- which is set via Server.xml during initialization // of the Server that is calling us. String jh = System.getProperty("JAVA_HOME"); if(jh != null) { jdkDir = getValidDirectory(new File(jh)); // e.g. c:/ias7/jdk } } if(jdkDir == null) { //Somehow, JAVA_HOME is not set. Try the "well-known" location... /** XXX ??? if(installRoot != null) { jdkDir = getValidDirectory(new File(installRoot + "/jdk")); } ** XXX **/ } if(jdkDir == null) { _logger.warning("Cannot identify JDK location."); toolsJarPath = null; } else { String javaName = (OS.isWindows())? "java.exe" : "java"; File javaExe = new File(jdkDir + "/bin/" + javaName); File toolsJar = new File(jdkDir + "/lib/tools.jar" ); if (toolsJar != null && toolsJar.exists()) { toolsJarPath = toolsJar.getPath(); } else { toolsJarPath = null; } } JavaConfig jc = h.getComponent(JavaConfig.class); String rmicOptions = jc.getRmicOptions(); rmicOptionsList = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(rmicOptions, " "); while (st.hasMoreTokens()) { String op = (String) st.nextToken(); rmicOptionsList.add(op); _logger.log(Level.INFO, "Detected Rmic option: " + op); } } /** * Generates and compiles the necessary impl classes, stubs and skels. * * <pre> * * This method makes the following assumptions: * - the deployment descriptor xmls are registered with Config * - the class paths are registered with Config * * @@@ * In case of re-deployment, the following steps should happen before: * - rename the src dir from previous deployment (ex. /app/pet-old) * - rename the stubs dir from previous deployment (ex. /stub/pet-old) * - explode the ear file (ex. /app/petstore) * - register the deployment descriptor xml with config * - register the class path with config * * After successful completion of this method, the old src and sutbs * directories may be deleted. * * </pre> * * @param deploymentCtx * * @return array of the client stubs files as zip items or empty array * */ public void ejbc(DeploymentContext deploymentCtx) throws Exception { // stubs dir for the current deployment File stubsDir = deploymentCtx.getScratchDir("ejb"); String explodedDir = deploymentCtx.getSource().getURI().getSchemeSpecificPart(); // deployment descriptor object representation EjbBundleDescriptor ejbBundle = deploymentCtx.getModuleMetaData(EjbBundleDescriptor.class); long startTime = now(); // class path to be used for this application during javac & rmic String classPath = deploymentCtx.getTransientAppMetaData(CMPDeployer.MODULE_CLASSPATH, String.class); // getClassPath(ejbcCtx.getClasspathUrls(), stubsDir); // Warning: A class loader is passed in while constructing the // application object final ClassLoader jcl = ejbBundle.getClassLoader(); // stubs dir is used as repository for code generator final String gnrtrTMP = stubsDir.getCanonicalPath(); // ---- EJB DEPLOYMENT DESCRIPTORS ------------------------------- // The main use-case we want to support is the one where existing // stand-alone java clients that access ejbs hosted in our appserver // directly through CosNaming need the generated stubs. We don't want to // force them to run rmic themselves so it's better for them // just to tell us during the deployment of an ejb client app // or ejb app that we should run rmic and put the stubs in the // client.jar. Turning on the deployment-time rmic flag ONLY // controls the generation of rmic stubs. Dynamic stubs will be used // in the server, in the Application Client container, and in // stand-alone clients that instantiate our naming provider. progress(localStrings.getStringWithDefault ("generator.processing_beans", "Processing beans...")); // ---- END OF EJB DEPLOYMENT DESCRIPTORS -------------------------- // ---- RMIC ALL STUB CLASSES -------------------------------------- Set<String> allStubClasses = new HashSet Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish StaticRmiStubGenerator.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.