use of org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor in project Payara by payara.
the class ASCmpMappingTest method check.
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
try {
if (descriptor instanceof IASEjbCMPEntityDescriptor) {
Collection col = null;
if (getVerifierContext().getJDOException() != null) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed1", "Error: Exception [ {0} ] while initializing JDOCodeGenerator. Please check your descriptors and mapping files for consistency ", new Object[] { getVerifierContext().getJDOException().getMessage() }));
return result;
} else {
try {
JDOCodeGenerator jdc = getVerifierContext().getJDOCodeGenerator();
col = jdc.validate((IASEjbCMPEntityDescriptor) descriptor);
} catch (Exception ex) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Exception [ {0} ] when calling JDOCodeGenerator.validate().", new Object[] { ex.getMessage() }));
return result;
}
}
if (col.isEmpty()) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "The mappings for the cmp beans (if any) are correct."));
} else {
// collect all the cmpmapping related errors
String allErrors = null;
Iterator it = col.iterator();
while (it.hasNext()) {
Exception e = (Exception) it.next();
if (!(e instanceof EJBQLException)) {
allErrors = e.getMessage() + "\n\n";
}
}
if (allErrors != null) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".parseError", "Error: Entity bean [ {0} ] has the following error(s) [ {1} ].", new Object[] { descriptor.getEjbClassName(), "\n" + allErrors }));
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "The mappings for the cmp beans (if any) are correct."));
}
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "Not applicable: Test only applies to container managed EJBs"));
}
} catch (Exception e) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Exception [ {0} ] when calling JDOCodeGenerator.validate().", new Object[] { e.getMessage() }));
}
return result;
}
use of org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor in project Payara by payara.
the class EjbNode method writeDescriptor.
/**
* write the descriptor class to a DOM tree and return it
*
* @param parent node for the DOM tree
* @param node name for the descriptor
* @param the descriptor to write
* @return the DOM tree top node
*/
@Override
public Node writeDescriptor(Node parent, String nodeName, EjbDescriptor ejbDescriptor) {
Element ejbNode = (Element) super.writeDescriptor(parent, nodeName, ejbDescriptor);
appendTextChild(ejbNode, RuntimeTagNames.EJB_NAME, ejbDescriptor.getName());
appendTextChild(ejbNode, RuntimeTagNames.JNDI_NAME, ejbDescriptor.getJndiName());
RuntimeDescriptorNode.writeCommonComponentInfo(ejbNode, ejbDescriptor);
appendTextChild(ejbNode, RuntimeTagNames.PASS_BY_REFERENCE, String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().getPassByReference()));
if (ejbDescriptor instanceof IASEjbCMPEntityDescriptor) {
CmpNode cmpNode = new CmpNode();
cmpNode.writeDescriptor(ejbNode, RuntimeTagNames.CMP, (IASEjbCMPEntityDescriptor) ejbDescriptor);
}
// principal
if (Boolean.FALSE.equals(ejbDescriptor.getUsesCallerIdentity())) {
RunAsIdentityDescriptor raid = ejbDescriptor.getRunAsIdentity();
if (raid != null && raid.getPrincipal() != null) {
Node principalNode = appendChild(ejbNode, RuntimeTagNames.PRINCIPAL);
appendTextChild(principalNode, RuntimeTagNames.NAME, raid.getPrincipal());
}
}
if (ejbDescriptor instanceof EjbMessageBeanDescriptor) {
EjbMessageBeanDescriptor msgBeanDesc = (EjbMessageBeanDescriptor) ejbDescriptor;
// mdb-connection-factory?
if (ejbDescriptor.getIASEjbExtraDescriptors().getMdbConnectionFactory() != null) {
MDBConnectionFactoryNode mcfNode = new MDBConnectionFactoryNode();
mcfNode.writeDescriptor(ejbNode, RuntimeTagNames.MDB_CONNECTION_FACTORY, ejbDescriptor.getIASEjbExtraDescriptors().getMdbConnectionFactory());
}
// jms-durable-subscription-name
if (msgBeanDesc.hasDurableSubscription()) {
appendTextChild(ejbNode, RuntimeTagNames.DURABLE_SUBSCRIPTION, msgBeanDesc.getDurableSubscriptionName());
}
appendTextChild(ejbNode, RuntimeTagNames.JMS_MAX_MESSAGES_LOAD, String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().getJmsMaxMessagesLoad()));
}
// ior-configuration
IORConfigurationNode iorNode = new IORConfigurationNode();
for (EjbIORConfigurationDescriptor iorConf : ejbDescriptor.getIORConfigurationDescriptors()) {
iorNode.writeDescriptor(ejbNode, RuntimeTagNames.IOR_CONFIG, iorConf);
}
appendTextChild(ejbNode, RuntimeTagNames.IS_READ_ONLY_BEAN, String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().isIsReadOnlyBean()));
appendTextChild(ejbNode, RuntimeTagNames.REFRESH_PERIOD_IN_SECONDS, String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().getRefreshPeriodInSeconds()));
appendTextChild(ejbNode, RuntimeTagNames.COMMIT_OPTION, ejbDescriptor.getIASEjbExtraDescriptors().getCommitOption());
appendTextChild(ejbNode, RuntimeTagNames.CMT_TIMEOUT_IN_SECONDS, String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().getCmtTimeoutInSeconds()));
appendTextChild(ejbNode, RuntimeTagNames.USE_THREAD_POOL_ID, ejbDescriptor.getIASEjbExtraDescriptors().getUseThreadPoolId());
// gen-classes
writeGenClasses(ejbNode, ejbDescriptor);
// bean-pool
BeanPoolDescriptor beanPoolDesc = ejbDescriptor.getIASEjbExtraDescriptors().getBeanPool();
if (beanPoolDesc != null) {
BeanPoolNode bpNode = new BeanPoolNode();
bpNode.writeDescriptor(ejbNode, RuntimeTagNames.BEAN_POOL, beanPoolDesc);
}
// bean-cache
BeanCacheDescriptor beanCacheDesc = ejbDescriptor.getIASEjbExtraDescriptors().getBeanCache();
if (beanCacheDesc != null) {
BeanCacheNode bcNode = new BeanCacheNode();
bcNode.writeDescriptor(ejbNode, RuntimeTagNames.BEAN_CACHE, beanCacheDesc);
}
if (ejbDescriptor instanceof EjbMessageBeanDescriptor) {
EjbMessageBeanDescriptor msgBeanDesc = (EjbMessageBeanDescriptor) ejbDescriptor;
if (msgBeanDesc.hasResourceAdapterMid()) {
MDBResourceAdapterNode mdb = new MDBResourceAdapterNode();
mdb.writeDescriptor(ejbNode, RuntimeTagNames.MDB_RESOURCE_ADAPTER, msgBeanDesc);
}
} else if (ejbDescriptor instanceof EjbSessionDescriptor) {
// web-services
WebServiceEndpointRuntimeNode wsRuntime = new WebServiceEndpointRuntimeNode();
wsRuntime.writeWebServiceEndpointInfo(ejbNode, ejbDescriptor);
}
// flush-at-end-of-method
FlushAtEndOfMethodDescriptor flushMethodDesc = ejbDescriptor.getIASEjbExtraDescriptors().getFlushAtEndOfMethodDescriptor();
if (flushMethodDesc != null) {
FlushAtEndOfMethodNode flushNode = new FlushAtEndOfMethodNode();
flushNode.writeDescriptor(ejbNode, RuntimeTagNames.FLUSH_AT_END_OF_METHOD, flushMethodDesc);
}
// checkpointed-methods
// checkpoint-at-end-of-method
CheckpointAtEndOfMethodDescriptor checkpointMethodDesc = ejbDescriptor.getIASEjbExtraDescriptors().getCheckpointAtEndOfMethodDescriptor();
if (checkpointMethodDesc != null) {
CheckpointAtEndOfMethodNode checkpointNode = new CheckpointAtEndOfMethodNode();
checkpointNode.writeDescriptor(ejbNode, RuntimeTagNames.CHECKPOINT_AT_END_OF_METHOD, checkpointMethodDesc);
}
if (ejbDescriptor.getIASEjbExtraDescriptors().getPerRequestLoadBalancing() != null) {
appendTextChild(ejbNode, RuntimeTagNames.PER_REQUEST_LOAD_BALANCING, String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().getPerRequestLoadBalancing()));
}
// availability-enabled
setAttribute(ejbNode, RuntimeTagNames.AVAILABILITY_ENABLED, ejbDescriptor.getIASEjbExtraDescriptors().getAttributeValue(IASEjbExtraDescriptors.AVAILABILITY_ENABLED));
return ejbNode;
}
use of org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor in project Payara by payara.
the class MethodHelper method getFinder.
private IASEjbCMPFinder getFinder(Method method) {
IASEjbCMPEntityDescriptor cmpDescriptor = (IASEjbCMPEntityDescriptor) getDescriptor();
IASEjbCMPFinder finder = cmpDescriptor.getIASEjbCMPFinder(method);
if (finder == null) {
String methodSignature = cmpDescriptor.getName() + '.' + method.getName() + JavaClassWriterHelper.parenleft_ + JavaClassWriterHelper.getParameterTypesList(method) + JavaClassWriterHelper.parenright_;
String msg = I18NHelper.getMessage(messages, "EXC_MissingCMP11Finder", // NOI18N
methodSignature);
throw new RuntimeException(msg);
}
return finder;
}
use of org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor in project Payara by payara.
the class NameMapper method initMap.
private void initMap() {
Iterator iterator = getBundleDescriptor().getEjbs().iterator();
Map ejbMap = new HashMap();
Map persistenceClassMap = new HashMap();
Set localNames = new HashSet();
Set remoteNames = new HashSet();
Map abstractSchemaMap = new HashMap();
_nameTypeToNameMap = new HashMap();
while (iterator.hasNext()) {
Object next = iterator.next();
if (next instanceof IASEjbCMPEntityDescriptor) {
IASEjbCMPEntityDescriptor descriptor = (IASEjbCMPEntityDescriptor) next;
String ejbName = descriptor.getName();
ejbMap.put(ejbName, descriptor);
safePut(persistenceClassMap, getPersistenceClassForDescriptor(descriptor), ejbName);
safeAdd(localNames, descriptor.getLocalClassName());
safeAdd(remoteNames, descriptor.getRemoteClassName());
safePut(abstractSchemaMap, descriptor.getAbstractSchemaName(), ejbName);
}
}
_nameTypeToNameMap.put(EJB_NAME, ejbMap);
_nameTypeToNameMap.put(PERSISTENCE_NAME, persistenceClassMap);
_nameTypeToNameMap.put(LOCAL_NAME, localNames);
_nameTypeToNameMap.put(REMOTE_NAME, remoteNames);
_nameTypeToNameMap.put(ABSTRACT_SCHEMA_NAME, abstractSchemaMap);
}
use of org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor in project Payara by payara.
the class CMPDeployerImpl method deploy.
/**
* Generates the concrete impls for all CMPs in the application.
*
* @throws DeploymentException if this exception was thrown while generating concrete impls
*/
public void deploy(DeploymentContext ctx) throws DeploymentException {
// deployment descriptor object representation for the archive
Application application = null;
// deployment descriptor object representation for each module
EjbBundleDescriptorImpl bundle = null;
// ejb name
String beanName = null;
// GeneratorException message if any
StringBuffer generatorExceptionMsg = null;
try {
CMPGenerator gen = new JDOCodeGenerator();
// stubs dir for the current deployment (generated/ejb)
// NOI18N
File stubsDir = ctx.getScratchDir("ejb");
application = ctx.getModuleMetaData(Application.class);
if (_logger.isLoggable(Logger.FINE)) {
// NOI18N
_logger.fine(// NOI18N
"cmpc.processing_cmp", application.getRegistrationName());
}
List<File> cmpFiles = new ArrayList<File>();
final ClassLoader jcl = application.getClassLoader();
bundle = ctx.getModuleMetaData(EjbBundleDescriptorImpl.class);
// This gives the dir where application is exploded
String archiveUri = ctx.getSource().getURI().getSchemeSpecificPart();
if (_logger.isLoggable(Logger.FINE)) {
_logger.fine(// NOI18N
"[CMPC] Module Dir name is " + archiveUri);
}
// xml dir for the current deployment (generated/xml)
String generatedXmlsPath = ctx.getScratchDir("xml").getCanonicalPath();
if (_logger.isLoggable(Logger.FINE)) {
_logger.fine(// NOI18N
"[CMPC] Generated XML Dir name is " + generatedXmlsPath);
}
try {
long start = System.currentTimeMillis();
gen.init(bundle, ctx, archiveUri, generatedXmlsPath);
Iterator ejbs = bundle.getEjbs().iterator();
while (ejbs.hasNext()) {
EjbDescriptor desc = (EjbDescriptor) ejbs.next();
beanName = desc.getName();
if (_logger.isLoggable(Logger.FINE)) {
_logger.fine(// NOI18N
"[CMPC] Ejb Class Name: " + desc.getEjbClassName());
}
if (desc instanceof IASEjbCMPEntityDescriptor) {
// generate concrete CMP class implementation
IASEjbCMPEntityDescriptor entd = (IASEjbCMPEntityDescriptor) desc;
if (_logger.isLoggable(Logger.FINE)) {
_logger.fine(// NOI18N
"[CMPC] Home Object Impl name is " + entd.getLocalHomeImplClassName());
}
// The classloader needs to be set else we fail down the road.
ClassLoader ocl = entd.getClassLoader();
entd.setClassLoader(jcl);
try {
gen.generate(entd, stubsDir, stubsDir);
} catch (GeneratorException e) {
String msg = e.getMessage();
_logger.warning(msg);
generatorExceptionMsg = addGeneratorExceptionMessage(msg, generatorExceptionMsg);
} finally {
entd.setClassLoader(ocl);
}
/* WARNING: IASRI 4683195
* JDO Code failed when there was a relationship involved
* because it depends upon the orginal ejbclasname and hence
* this code is shifted to just before the Remote Impl is
* generated.Remote/Home Impl generation depends upon this
* value
*/
}
}
// end while ejbs.hasNext()
beanName = null;
cmpFiles.addAll(gen.cleanup());
long end = System.currentTimeMillis();
_logger.fine("CMP Generation: " + (end - start) + " msec");
} catch (GeneratorException e) {
String msg = e.getMessage();
_logger.warning(msg);
generatorExceptionMsg = addGeneratorExceptionMessage(msg, generatorExceptionMsg);
}
// Used in exception processing
bundle = null;
// Compile the generated classes
if (generatorExceptionMsg == null) {
long start = System.currentTimeMillis();
compileClasses(ctx, cmpFiles, stubsDir);
long end = System.currentTimeMillis();
_logger.fine("Java Compilation: " + (end - start) + " msec");
// Do Java2DB if needed
start = System.currentTimeMillis();
CMPProcessor processor = new CMPProcessor(ctx);
processor.process();
end = System.currentTimeMillis();
_logger.fine("Java2DB processing: " + (end - start) + " msec");
_logger.fine("cmpc.done_processing_cmp", application.getRegistrationName());
}
} catch (GeneratorException e) {
_logger.warning(e.getMessage());
throw new DeploymentException(e);
} catch (Throwable e) {
String eType = e.getClass().getName();
String appName = application.getRegistrationName();
String exMsg = e.getMessage();
String msg = null;
if (bundle == null) {
// Application or compilation error
msg = I18NHelper.getMessage(messages, "cmpc.cmp_app_error", eType, appName, exMsg);
} else {
String bundleName = bundle.getModuleDescriptor().getArchiveUri();
if (beanName == null) {
// Module processing error
msg = I18NHelper.getMessage(messages, "cmpc.cmp_module_error", new Object[] { eType, appName, bundleName, exMsg });
} else {
// CMP bean generation error
msg = I18NHelper.getMessage(messages, "cmpc.cmp_bean_error", new Object[] { eType, beanName, appName, bundleName, exMsg });
}
}
_logger.log(Logger.SEVERE, msg, e);
throw new DeploymentException(msg);
}
if (generatorExceptionMsg != null) {
// We already logged each separate part.
throw new DeploymentException(generatorExceptionMsg.toString());
}
}
Aggregations