com.sun.enterprise.connectors.util.ConnectorConfigParserUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of payara-micro Show documentation
Show all versions of payara-micro Show documentation
Micro Distribution of the Payara Project
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2012 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.enterprise.connectors.util;
import com.sun.enterprise.deployment.*;
import com.sun.enterprise.connectors.*;
import com.sun.enterprise.connectors.ConnectorRuntime;
import com.sun.enterprise.connectors.module.ConnectorApplication;
import com.sun.logging.LogDomains;
import com.sun.appserv.connectors.internal.api.*;
import java.util.logging.*;
import java.util.*;
import java.lang.*;
import java.lang.reflect.*;
import jakarta.resource.spi.ResourceAdapter;
import jakarta.resource.spi.ResourceAdapterAssociation;
/**
* This is an util class containing methods for parsing connector
* configurations present in ra.xml.
*
* @author Srikanth P
*
*/
public class ConnectorConfigParserUtils {
private final static Logger _logger = LogDomains.getLogger(ConnectorConfigParserUtils.class, LogDomains.RSR_LOGGER);
/**
* Default constructor.
*
*/
public ConnectorConfigParserUtils() {
}
/**
* Merges the properties obtained by introspecting the javabean and the
* properties present in ra.xml for the corresponding javabean.
*
* @param ddVals Properties obtained from ra.xml for the javabean
* @param introspectedVals Properties obtained by introspecting javabean
* @return Merged Properties present in ra.xml and introspected properties
* of javabean.
*
*/
public Properties mergeProps(Set ddVals,
Properties introspectedVals)
{
Properties mergedVals = new Properties(introspectedVals);
if(ddVals != null) {
Object[] ddProps = ddVals.toArray();
String name = null;
String value = null;
for (int i = 0; i < ddProps.length; i++) {
name = ((ConnectorConfigProperty )ddProps[i]).getName();
value =((ConnectorConfigProperty )ddProps[i]).getValue();
mergedVals.setProperty(name,value);
}
}
return mergedVals;
}
/**
* Merges the datatype of properties obtained by introspecting the
* javabean and the datatypes of properties present in ra.xml for
* the corresponding javabean. It is a Properties object consisting of
* property name and the property data type.
*
* @param ddVals Properties obtained from ra.xml for the javabean
* @param introspectedVals Properties obtained by
* introspecting javabean which consist of property name as key
* and datatype as the value.
* @return Merged Properties present in ra.xml and introspected properties
* of javabean. Properties consist of property name as the key
* and datatype as the value.
*
*/
public Properties mergePropsReturnTypes(Set ddVals,
Properties introspectedVals)
{
Properties mergedVals = new Properties(introspectedVals);
if(ddVals != null) {
Object[] ddProps = ddVals.toArray();
String name = null;
String value = null;
for (int i = 0; i < ddProps.length; i++) {
name = ((ConnectorConfigProperty )ddProps[i]).getName();
value = ((ConnectorConfigProperty )ddProps[i]).getType();
mergedVals.setProperty(name,value);
}
}
return mergedVals;
}
public Properties introspectJavaBean(String className, Set ddPropsSet)
throws ConnectorRuntimeException {
return introspectJavaBean(className, ddPropsSet, false, null);
}
public Properties introspectJavaBean(String className, Set ddPropsSet,
boolean associateResourceAdapter, String resourceAdapterName)
throws ConnectorRuntimeException {
Class loadedClass = loadClass(className, resourceAdapterName);
Object loadedInstance = instantiate(loadedClass);
try {
if (associateResourceAdapter) {
ActiveResourceAdapter activeRA = ConnectorRegistry.getInstance().
getActiveResourceAdapter(resourceAdapterName);
if (activeRA == null) {
//Check and Load RAR
ConnectorRuntime.getRuntime().loadDeferredResourceAdapter(
resourceAdapterName);
activeRA = ConnectorRegistry.getInstance().
getActiveResourceAdapter(resourceAdapterName);
}
//Associate RAR
if (activeRA instanceof ActiveOutboundResourceAdapter) {
ResourceAdapter raInstance = activeRA.getResourceAdapter();
if (loadedInstance instanceof ResourceAdapterAssociation) {
((ResourceAdapterAssociation)loadedInstance).
setResourceAdapter(raInstance);
}
}
}
} catch (Exception e) {
_logger.log(Level.WARNING,
"rardeployment.error_associating_ra",e);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE,
"Exception while associating the resource adapter"
+ "to the JavaBean", e);
}
}
return introspectJavaBean(loadedInstance, ddPropsSet);
}
/**
* Introspects the javabean and returns only the introspected properties
* not present in the configuration in ra.xml for the corresponding
* javabean. If no definite value is obtained while introspection of
* a method empty string is taken as the value.
*
* @param javaBeanInstance bean
* @param ddPropsSet Set of Properties present in configuration in ra.xml for
* the corresponding javabean.
* @return Introspected properties not present in the configuration in
* ra.xml for the corresponding javabean.
* @throws ConnectorRuntimeException if the Class could not be loaded
* or instantiated.
*/
public Properties introspectJavaBean(
Object javaBeanInstance ,Set ddPropsSet) throws ConnectorRuntimeException
{
Class loadedClass = javaBeanInstance.getClass();
Method[] methods = loadedClass.getMethods();
Properties props = new Properties();
String name = null;
String value = null;
Object[] ddProps = null;
if(ddPropsSet != null) {
ddProps = ddPropsSet.toArray();
}
for(int i=0; i " + methods[i].getName() + ":" + methods[i].getReturnType());
}
if(isProperty(methods[i]) && !presentInDDProps(methods[i],ddProps)
&& isValid(methods[i], loadedClass)) {
name = getPropName(methods[i]);
value = getPropValue(methods[i], loadedClass, javaBeanInstance);
props.setProperty(name,value);
}
}
return props;
}
/**
* Introspects the javabean and returns only the introspected properties
* and their datatypes not present in the configuration in ra.xml for
* the corresponding javabean.
*
* @param className Name of the class to be introspected.
* @param ddPropsSet Set of Properties present in configuration in ra.xml for
* the corresponding javabean.
* @return Introspected properties and their datatype not present in the
* configuration in ra.xml for the corresponding javabean. The
* properties consist of property name as the key and datatype as
* the value
* @throws ConnectorRuntimeException if the Class could not be loaded
*/
public Properties introspectJavaBeanReturnTypes(
String className,Set ddPropsSet, String rarName) throws ConnectorRuntimeException
{
Class loadedClass = loadClass(className, rarName);
Method[] methods = loadedClass.getMethods();
Properties props = new Properties();
String name = null;
String value = null;
Object[] ddProps = null;
if(ddPropsSet != null) {
ddProps = ddPropsSet.toArray();
}
for(int i=0; i