use of com.sun.enterprise.deployment.AdminObject in project Payara by payara.
the class CheckAdminObjectJavaBean method check.
/**
* <p>
* Test for each adminobject, that "adminobject-class" is a Java Bean.
* </p>
*
* @param descriptor deployment descriptor for the rar file
* @return result object containing the result of the individual test
* performed
*/
public Result check(ConnectorDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (!descriptor.hasAdminObjects()) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.admin.notApp", "Resource Adapter does not define any administered objects"));
return result;
}
Set adminObjects = descriptor.getAdminObjects();
boolean oneFailed = false;
Iterator iter = adminObjects.iterator();
while (iter.hasNext()) {
AdminObject adminObj = (AdminObject) iter.next();
String impl = adminObj.getAdminObjectClass();
Class implClass = null;
try {
implClass = Class.forName(impl, false, getVerifierContext().getClassLoader());
} catch (ClassNotFoundException e) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.admin.nonexist", "Error: The class [ {0} ] as defined under adminobject-class in the deployment descriptor does not exist", new Object[] { impl }));
return result;
}
Set configProps = adminObj.getConfigProperties();
Iterator propIter = configProps.iterator();
BeanInfo bi = null;
try {
bi = Introspector.getBeanInfo(implClass, Object.class);
} catch (IntrospectionException ie) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: The adminobject-class [ {0} ] is not JavaBeans compliant", new Object[] { impl }));
return result;
}
PropertyDescriptor[] properties = bi.getPropertyDescriptors();
Hashtable<String, PropertyDescriptor> props = new Hashtable<String, PropertyDescriptor>();
for (int i = 0; i < properties.length; i++) {
props.put(properties[i].getName(), properties[i]);
}
while (propIter.hasNext()) {
EnvironmentProperty envProp = (EnvironmentProperty) propIter.next();
String name = Introspector.decapitalize(envProp.getName());
String type = envProp.getType();
PropertyDescriptor propDesc = props.get(name);
if (propDesc != null) {
if (propDesc.getReadMethod() == null || propDesc.getWriteMethod() == null) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed1", "Error: The adminobject-class [ {0} ] does not provide accessor methods for [ {1} ].", new Object[] { impl, name }));
return result;
}
} else {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed1", "Error: The adminobject-class [ {0} ] does not provide accessor methods for [ {1} ].", new Object[] { impl, name }));
return result;
}
}
}
if (!oneFailed) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Success: Each adminobject-class is a Java Bean"));
}
return result;
}
use of com.sun.enterprise.deployment.AdminObject in project Payara by payara.
the class AdministeredObjectHandler method processAdminObjectInterface.
private void processAdminObjectInterface(String adminObjectClassName, String adminObjectInterfaceName, ConnectorDescriptor desc) {
Set ddAdminObjects = desc.getAdminObjects();
// merge DD and annotation values of admin-objects
// merge involves simple union
boolean ignore = false;
for (Object o : ddAdminObjects) {
AdminObject ddAdminObject = (AdminObject) o;
if (ddAdminObject.getAdminObjectInterface().equals(adminObjectInterfaceName) && ddAdminObject.getAdminObjectClass().equals(adminObjectClassName)) {
ignore = true;
break;
}
}
if (!ignore) {
AdminObject ao = new AdminObject(adminObjectInterfaceName, adminObjectClassName);
desc.addAdminObject(ao);
} else {
if (logger.isLoggable(Level.FINEST)) {
logger.log(Level.FINEST, "Ignoring administered object annotation " + "[ " + adminObjectInterfaceName + "," + adminObjectClassName + "] as it is already defined ");
}
}
}
use of com.sun.enterprise.deployment.AdminObject in project Payara by payara.
the class CheckAdminObjectImpl method check.
/**
* <p>
* Test for each adminobject, that "adminobject-class"
* implements "adminobject-interface".
* </p>
*
* @param descriptor deployment descriptor for the rar file
* @return result object containing the result of the individual test
* performed
*/
public Result check(ConnectorDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (!descriptor.hasAdminObjects()) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.admin.notApp", "Resource Adapter does not define any administered objects"));
return result;
}
Set adminObjects = descriptor.getAdminObjects();
boolean oneFailed = false;
Iterator iter = adminObjects.iterator();
while (iter.hasNext()) {
AdminObject adminObj = (AdminObject) iter.next();
String intf = adminObj.getAdminObjectInterface();
String impl = adminObj.getAdminObjectClass();
Class implClass = null;
try {
implClass = Class.forName(impl, false, getVerifierContext().getClassLoader());
} catch (ClassNotFoundException e) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.admin.nonexist", "Error: The class [ {0} ] as defined under adminobject-class in the deployment descriptor does not exist", new Object[] { impl }));
return result;
}
if (!isImplementorOf(implClass, intf)) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: adminobject-class [ {0} ] does not implement adminobject-interface [ {1} ].", new Object[] { impl, intf }));
return result;
}
}
if (!oneFailed) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Success: all adminobject-class implement their corresponding adminobject-interface"));
}
return result;
}
use of com.sun.enterprise.deployment.AdminObject in project Payara by payara.
the class CheckAdminObjectSerializable method check.
/**
* <p>
* Test for each adminobject, that "adminobject-class"
* implements "java.io.Serializable".
* </p>
*
* @param descriptor deployment descriptor for the rar file
* @return result object containing the result of the individual test
* performed
*/
public Result check(ConnectorDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (!descriptor.hasAdminObjects()) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.admin.notApp", "Resource Adapter does not define any administered objects"));
return result;
}
Set adminObjects = descriptor.getAdminObjects();
boolean oneFailed = false;
Iterator iter = adminObjects.iterator();
while (iter.hasNext()) {
AdminObject adminObj = (AdminObject) iter.next();
String impl = adminObj.getAdminObjectClass();
Class implClass = null;
try {
implClass = Class.forName(impl, false, getVerifierContext().getClassLoader());
} catch (ClassNotFoundException e) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.admin.nonexist", "Error: The class [ {0} ] as defined under adminobject-class in the deployment descriptor does not exist", new Object[] { impl }));
return result;
}
if (!isImplementorOf(implClass, "java.io.Serializable")) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: adminobject-class [ {0} ] does not implement java.io.Serializable", new Object[] { impl }));
return result;
}
}
if (!oneFailed) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Success: all adminobject-class implement java.io.Serializable"));
}
return result;
}
use of com.sun.enterprise.deployment.AdminObject in project Payara by payara.
the class ActiveOutboundResourceAdapter method addAdminObject.
/**
* Creates an admin object.
*
* @param appName Name of application, in case of embedded rar.
* @param connectorName Module name of the resource adapter.
* @param jndiName JNDI name to be registered.
* @param adminObjectType Interface name of the admin object.
* @param props <code>Properties</code> object containing name/value
* pairs of properties.
*/
public void addAdminObject(String appName, String connectorName, ResourceInfo resourceInfo, String adminObjectType, String adminObjectClassName, Properties props) throws ConnectorRuntimeException {
if (props == null) {
// empty properties
props = new Properties();
}
ConnectorRegistry registry = ConnectorRegistry.getInstance();
ConnectorDescriptor desc = registry.getDescriptor(connectorName);
AdminObject aoDesc = null;
// or the combination of the both names.
if (adminObjectClassName == null || adminObjectClassName.trim().equals("")) {
// get AO through interface name
List<AdminObject> adminObjects = desc.getAdminObjectsByType(adminObjectType);
if (adminObjects.size() > 1) {
String msg = localStrings.getString("aor.could_not_determine_aor_type", adminObjectType);
throw new ConnectorRuntimeException(msg);
} else {
aoDesc = adminObjects.get(0);
}
} else if (adminObjectType == null || adminObjectType.trim().equals("")) {
// get AO through class name
List<AdminObject> adminObjects = desc.getAdminObjectsByClass(adminObjectClassName);
if (adminObjects.size() > 1) {
String msg = localStrings.getString("aor.could_not_determine_aor_class", adminObjectClassName);
throw new ConnectorRuntimeException(msg);
} else {
aoDesc = adminObjects.get(0);
}
} else {
// get AO through interface name and class name
aoDesc = desc.getAdminObject(adminObjectType, adminObjectClassName);
}
if (aoDesc == null) {
String msg = localStrings.getString("aor.could_not_determine_aor", adminObjectType, adminObjectClassName);
throw new ConnectorRuntimeException(msg);
}
AdministeredObjectResource aor = new AdministeredObjectResource(resourceInfo);
aor.initialize(aoDesc);
aor.setResourceAdapter(connectorName);
Object[] envProps = aoDesc.getConfigProperties().toArray();
// Override them if same config properties are provided by the user
for (int i = 0; i < envProps.length; i++) {
ConnectorConfigProperty envProp = (ConnectorConfigProperty) envProps[i];
String name = envProp.getName();
String userValue = (String) props.remove(name);
if (userValue != null)
aor.addConfigProperty(new ConnectorConfigProperty(name, userValue, userValue, envProp.getType()));
else
aor.addConfigProperty(envProp);
}
// Add non-default config properties provided by the user to aor
Iterator iter = props.keySet().iterator();
while (iter.hasNext()) {
String name = (String) iter.next();
String userValue = props.getProperty(name);
if (userValue != null)
aor.addConfigProperty(new ConnectorConfigProperty(name, userValue, userValue));
}
// bind to JNDI namespace
try {
Reference ref = aor.createAdminObjectReference();
connectorRuntime_.getResourceNamingService().publishObject(resourceInfo, ref, true);
} catch (NamingException ex) {
String i18nMsg = localStrings.getString("aira.cannot_bind_admin_obj");
throw new ConnectorRuntimeException(i18nMsg, ex);
}
}
Aggregations