use of org.apache.openejb.jee.InjectionTarget$JAXB.writeInjectionTarget in project tomee by apache.
the class LegacyProcessor method process.
public static void process(final Class<?> clazz, final EnterpriseBean bean) {
if (bean instanceof SessionBean) {
final SessionBean sessionBean = (SessionBean) bean;
if (sessionBean.getSessionType() == STATEFUL && SessionSynchronization.class.isAssignableFrom(clazz)) {
try {
sessionBean.getAfterBegin().add(new LifecycleCallback(clazz.getMethod("afterBegin")));
sessionBean.getBeforeCompletion().add(new LifecycleCallback(clazz.getMethod("beforeCompletion")));
sessionBean.getAfterCompletion().add(new LifecycleCallback(clazz.getMethod("afterCompletion", boolean.class)));
} catch (final NoSuchMethodException e) {
// Ignore, should never happen
}
}
if (javax.ejb.SessionBean.class.isAssignableFrom(clazz)) {
final ResourceEnvRef ref = new ResourceEnvRef("javax.ejb.SessionBean/sessionContext", SessionContext.class);
final InjectionTarget target = new InjectionTarget();
target.setInjectionTargetClass(clazz);
target.setInjectionTargetName("sessionContext");
ref.getInjectionTarget().add(target);
sessionBean.getResourceEnvRef().add(ref);
}
}
if (bean instanceof MessageDrivenBean) {
final MessageDrivenBean messageDrivenBean = (MessageDrivenBean) bean;
if (javax.ejb.MessageDrivenBean.class.isAssignableFrom(clazz)) {
final ResourceEnvRef ref = new ResourceEnvRef("javax.ejb.MessageDrivenBean/messageDrivenContext", MessageDrivenContext.class);
final InjectionTarget target = new InjectionTarget();
target.setInjectionTargetClass(clazz);
target.setInjectionTargetName("messageDrivenContext");
ref.getInjectionTarget().add(target);
messageDrivenBean.getResourceEnvRef().add(ref);
}
}
}
use of org.apache.openejb.jee.InjectionTarget$JAXB.writeInjectionTarget in project tomee by apache.
the class AutoConfig method getType.
private String getType(final JndiReference ref, final ClassLoader classLoader) throws OpenEJBException {
final String refType = ref.getType();
if (refType != null) {
return refType;
}
if (classLoader != null) {
final Set<InjectionTarget> injections = ref.getInjectionTarget();
for (final InjectionTarget injection : injections) {
try {
final Class target = classLoader.loadClass(injection.getInjectionTargetClass().trim());
final Class type = IntrospectionSupport.getPropertyType(target, injection.getInjectionTargetName().trim());
return type.getName();
} catch (final ClassNotFoundException | NoSuchFieldException e) {
// ignore
}
}
}
throw new OpenEJBException("Unable to infer type for " + ref.getKey());
}
use of org.apache.openejb.jee.InjectionTarget$JAXB.writeInjectionTarget in project tomee by apache.
the class CleanEnvEntries method fillInMissingType.
private void fillInMissingType(final ClassLoader loader, final EnvEntry entry) {
if (entry.getType() != null) {
return;
}
// If it has the lookup supplied we don't care if there is no type
if (entry.getLookupName() != null) {
return;
}
// We can't imply type without at least one injection point
if (entry.getInjectionTarget().size() == 0) {
return;
}
final Set<Class> types = new HashSet<Class>();
for (final InjectionTarget target : entry.getInjectionTarget()) {
if (target.getInjectionTargetClass() == null) {
continue;
}
if (target.getInjectionTargetName() == null) {
continue;
}
types.add(getType(loader, target));
}
normalize(types);
final Class<?> type = types.size() == 1 ? types.iterator().next() : String.class;
entry.setType(type.getName());
}
use of org.apache.openejb.jee.InjectionTarget$JAXB.writeInjectionTarget in project tomee by apache.
the class CheckInjectionTargets method validate.
public void validate(final EjbModule ejbModule) {
for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
final List<JndiReference> entries = new ArrayList<JndiReference>();
entries.addAll(bean.getEjbLocalRef());
entries.addAll(bean.getEjbRef());
entries.addAll(bean.getEnvEntry());
entries.addAll(bean.getMessageDestinationRef());
entries.addAll(bean.getPersistenceContextRef());
entries.addAll(bean.getPersistenceUnitRef());
entries.addAll(bean.getResourceEnvRef());
entries.addAll(bean.getResourceRef());
entries.addAll(bean.getServiceRef());
for (final JndiReference reference : entries) {
// check injection target
for (final InjectionTarget target : reference.getInjectionTarget()) {
boolean classPrefix = false;
String name = target.getInjectionTargetName();
if (name.startsWith(target.getInjectionTargetClass() + "/")) {
classPrefix = true;
name = name.substring(target.getInjectionTargetClass().length() + 1);
}
final String shortNameInvalid = name;
if (name.startsWith("set") && name.length() >= 4 && Character.isUpperCase(name.charAt(3))) {
final StringBuilder correctName = new StringBuilder(name);
correctName.delete(0, 3);
correctName.setCharAt(0, Character.toLowerCase(correctName.charAt(0)));
final String shortNameCorrect = correctName.toString();
if (classPrefix) {
correctName.insert(0, target.getInjectionTargetClass() + "/");
}
warn(bean, "injectionTarget.nameContainsSet", target.getInjectionTargetName(), shortNameInvalid, shortNameCorrect, correctName, reference.getName(), reference.getClass().getSimpleName());
target.setInjectionTargetName(correctName.toString());
}
}
}
}
}
use of org.apache.openejb.jee.InjectionTarget$JAXB.writeInjectionTarget in project tomee by apache.
the class EjbLocalRef$JAXB method _write.
public static final void _write(final XoXMLStreamWriter writer, final EjbLocalRef ejbLocalRef, RuntimeContext context) throws Exception {
if (ejbLocalRef == null) {
writer.writeXsiNil();
return;
}
if (context == null) {
context = new RuntimeContext();
}
final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
if (EjbLocalRef.class != ejbLocalRef.getClass()) {
context.unexpectedSubclass(writer, ejbLocalRef, EjbLocalRef.class);
return;
}
context.beforeMarshal(ejbLocalRef, LifecycleCallback.NONE);
// ATTRIBUTE: id
final String idRaw = ejbLocalRef.id;
if (idRaw != null) {
String id = null;
try {
id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
} catch (final Exception e) {
context.xmlAdapterError(ejbLocalRef, "id", CollapsedStringAdapter.class, String.class, String.class, e);
}
writer.writeAttribute("", "", "id", id);
}
// ELEMENT: descriptions
Text[] descriptions = null;
try {
descriptions = ejbLocalRef.getDescriptions();
} catch (final Exception e) {
context.getterError(ejbLocalRef, "descriptions", EjbLocalRef.class, "getDescriptions", e);
}
if (descriptions != null) {
for (final Text descriptionsItem : descriptions) {
if (descriptionsItem != null) {
writer.writeStartElement(prefix, "description", "http://java.sun.com/xml/ns/javaee");
writeText(writer, descriptionsItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(ejbLocalRef, "descriptions");
}
}
}
// ELEMENT: ejbRefName
final String ejbRefNameRaw = ejbLocalRef.ejbRefName;
String ejbRefName = null;
try {
ejbRefName = Adapters.collapsedStringAdapterAdapter.marshal(ejbRefNameRaw);
} catch (final Exception e) {
context.xmlAdapterError(ejbLocalRef, "ejbRefName", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (ejbRefName != null) {
writer.writeStartElement(prefix, "ejb-ref-name", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(ejbRefName);
writer.writeEndElement();
} else {
context.unexpectedNullValue(ejbLocalRef, "ejbRefName");
}
// ELEMENT: ejbRefType
final EjbRefType ejbRefType = ejbLocalRef.ejbRefType;
if (ejbRefType != null) {
writer.writeStartElement(prefix, "ejb-ref-type", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(toStringEjbRefType(ejbLocalRef, null, context, ejbRefType));
writer.writeEndElement();
}
// ELEMENT: localHome
final String localHomeRaw = ejbLocalRef.localHome;
String localHome = null;
try {
localHome = Adapters.collapsedStringAdapterAdapter.marshal(localHomeRaw);
} catch (final Exception e) {
context.xmlAdapterError(ejbLocalRef, "localHome", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (localHome != null) {
writer.writeStartElement(prefix, "local-home", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(localHome);
writer.writeEndElement();
}
// ELEMENT: local
final String localRaw = ejbLocalRef.local;
String local = null;
try {
local = Adapters.collapsedStringAdapterAdapter.marshal(localRaw);
} catch (final Exception e) {
context.xmlAdapterError(ejbLocalRef, "local", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (local != null) {
writer.writeStartElement(prefix, "local", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(local);
writer.writeEndElement();
}
// ELEMENT: ejbLink
final String ejbLinkRaw = ejbLocalRef.ejbLink;
String ejbLink = null;
try {
ejbLink = Adapters.collapsedStringAdapterAdapter.marshal(ejbLinkRaw);
} catch (final Exception e) {
context.xmlAdapterError(ejbLocalRef, "ejbLink", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (ejbLink != null) {
writer.writeStartElement(prefix, "ejb-link", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(ejbLink);
writer.writeEndElement();
}
// ELEMENT: mappedName
final String mappedNameRaw = ejbLocalRef.mappedName;
String mappedName = null;
try {
mappedName = Adapters.collapsedStringAdapterAdapter.marshal(mappedNameRaw);
} catch (final Exception e) {
context.xmlAdapterError(ejbLocalRef, "mappedName", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (mappedName != null) {
writer.writeStartElement(prefix, "mapped-name", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(mappedName);
writer.writeEndElement();
}
// ELEMENT: injectionTarget
final Set<InjectionTarget> injectionTarget = ejbLocalRef.injectionTarget;
if (injectionTarget != null) {
for (final InjectionTarget injectionTargetItem : injectionTarget) {
if (injectionTargetItem != null) {
writer.writeStartElement(prefix, "injection-target", "http://java.sun.com/xml/ns/javaee");
writeInjectionTarget(writer, injectionTargetItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(ejbLocalRef, "injectionTarget");
}
}
}
// ELEMENT: lookupName
final String lookupNameRaw = ejbLocalRef.lookupName;
String lookupName = null;
try {
lookupName = Adapters.collapsedStringAdapterAdapter.marshal(lookupNameRaw);
} catch (final Exception e) {
context.xmlAdapterError(ejbLocalRef, "lookupName", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (lookupName != null) {
writer.writeStartElement(prefix, "lookup-name", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(lookupName);
writer.writeEndElement();
}
context.afterMarshal(ejbLocalRef, LifecycleCallback.NONE);
}
Aggregations