/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.ejb3.dd;

import java.util.StringTokenizer;
import org.jboss.logging.Logger;
import org.jboss.xb.binding.ObjectModelFactory;
import org.jboss.xb.binding.UnmarshallingContext;
import org.xml.sax.Attributes;

/**
 * org.jboss.xb.binding.ObjectModelFactory implementation that accepts data
 * chuncks from unmarshaller and assembles them into an EjbJarDD instance.
 *
 * @author <a href="mailto:bdecoste@jboss.com">William DeCoste</a>
 * @version <tt>$Revision: 1.19.2.4 $</tt>
 */
public class EjbJarDDObjectFactory implements ObjectModelFactory
{

   private static final Logger log = Logger
           .getLogger(EjbJarDDObjectFactory.class);

   /**
    * Return the root.
    */
   public Object newRoot(Object root, UnmarshallingContext navigator,
                         String namespaceURI, String localName, Attributes attrs)
   {

      final EjbJarDD dd;
      if (root == null)
      {
         root = dd = new EjbJarDD();
      }
      else
      {
         dd = (EjbJarDD) root;
      }

      if (attrs.getLength() > 0)
      {
         for (int i = 0; i < attrs.getLength(); ++i)
         {
            if (attrs.getLocalName(i).equals("version"))
            {
               dd.setVersion(attrs.getValue(i));
            }
         }
      }

      return root;
   }

   public Object completeRoot(Object root, UnmarshallingContext ctx,
                              String uri, String name)
   {
      return root;
   }

   // Methods discovered by introspection

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(EjbJarDD dd, UnmarshallingContext navigator,
                          String namespaceURI, String localName, Attributes attrs)
   {
      Object child = null;

      if (localName.equals("enterprise-beans"))
      {
         child = new EnterpriseBeans();
      }
      else if (localName.equals("relationships"))
      {
         child = new Relationships();
      }
      else if (localName.equals("assembly-descriptor"))
      {
         child = new AssemblyDescriptor();
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(EnterpriseBeans ejbs, UnmarshallingContext navigator,
                          String namespaceURI, String localName, Attributes attrs)
   {
      Object child = null;

      if (localName.equals("session"))
      {
         child = new SessionEnterpriseBean();
      }
      else if (localName.equals("entity"))
      {
         child = new EntityEnterpriseBean();
      }
      else if (localName.equals("message-driven"))
      {
         child = new MessageDrivenBean();
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   private Object newEjbChild(EnterpriseBean parent, String localName)
   {
      Object child = null;

      if (localName.equals("ejb-local-ref"))
      {
         child = new EjbLocalRef();
      }
      else if (localName.equals("ejb-ref"))
      {
         child = new EjbRef();
      }
      else if (localName.equals("resource-ref"))
      {
         child = new ResourceRef();
      }
      else if (localName.equals("env-entry"))
      {
         child = new EnvEntry();
      }
      else if (localName.equals("message-destination-ref"))
      {
         child = new MessageDestinationRef();
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(MessageDrivenBean parent,
                          UnmarshallingContext navigator, String namespaceURI, String localName,
                          Attributes attrs)
   {
      Object child = null;

      child = newEjbChild(parent, localName);
      if (child == null)
      {
         if (localName.equals("message-driven-destination"))
         {
            child = new MessageDrivenDestination();
         }
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(SessionEnterpriseBean parent,
                          UnmarshallingContext navigator, String namespaceURI, String localName,
                          Attributes attrs)
   {
      Object child = null;

      child = newEjbChild(parent, localName);
      if (child == null)
      {
         if (localName.equals("security-identity"))
         {
            child = new SecurityIdentity();
         }
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(EntityEnterpriseBean parent,
                          UnmarshallingContext navigator, String namespaceURI, String localName,
                          Attributes attrs)
   {
      Object child = null;

      child = newEjbChild(parent, localName);
      if (child == null)
      {
         if (localName.equals("cmp-field"))
         {
            child = new CmpField();
         }
         else if (localName.equals("query"))
         {
            child = new Query();
         }
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(SecurityIdentity parent,
                          UnmarshallingContext navigator, String namespaceURI, String localName,
                          Attributes attrs)
   {
      Object child = null;

      if (localName.equals("use-caller-identity"))
      {
         parent.setUseCallerIdentity(true);
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(Relationships relationships,
                          UnmarshallingContext navigator, String namespaceURI, String localName,
                          Attributes attrs)
   {
      Object child = null;

      if (localName.equals("ejb-relation"))
      {
         child = new EjbRelation();
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(EjbRelation relation, UnmarshallingContext navigator,
                          String namespaceURI, String localName, Attributes attrs)
   {
      Object child = null;

      if (localName.equals("ejb-relationship-role"))
      {
         child = new EjbRelationshipRole();
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(EjbRelationshipRole parent,
                          UnmarshallingContext navigator, String namespaceURI, String localName,
                          Attributes attrs)
   {
      Object child = null;

      if (localName.equals("cascade-delete"))
      {
         parent.setCascadeDelete(true);
      }
      else if (localName.equals("relationship-role-source"))
      {
         child = new RelationshipRoleSource();
      }
      else if (localName.equals("cmr-field"))
      {
         child = new CmrField();
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(AssemblyDescriptor relationships,
                          UnmarshallingContext navigator, String namespaceURI, String localName,
                          Attributes attrs)
   {
      Object child = null;

      if (localName.equals("security-role"))
      {
         child = new SecurityRole();
      }
      else if (localName.equals("method-permission"))
      {
         child = new MethodPermission();
      }
      if (localName.equals("container-transaction"))
      {
         child = new ContainerTransaction();
      }
      else if (localName.equals("inject"))
      {
         child = new Inject();
      }
      else if (localName.equals("callback"))
      {
         child = new Callback();
      }
      else if (localName.equals("exclude-list"))
      {
         child = new ExcludeList();
      }
      else if (localName.equals("remove-list"))
      {
         child = new RemoveList();
      }
      else if (localName.equals("init-list"))
      {
         child = new InitList();
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(Inject inject,
                          UnmarshallingContext navigator, String namespaceURI, String localName,
                          Attributes attrs)
   {
      Object child = null;

      if (localName.equals("method"))
      {
         child = new Method();
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(Callback callback,
                          UnmarshallingContext navigator, String namespaceURI, String localName,
                          Attributes attrs)
   {
      Object child = null;

      if (localName.equals("method"))
      {
         child = new Method();
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(MethodPermission permission,
                          UnmarshallingContext navigator, String namespaceURI, String localName,
                          Attributes attrs)
   {
      Object child = null;

      if (localName.equals("method"))
      {
         child = new Method();
      }
      else if (localName.equals("unchecked"))
      {
         permission.setUnchecked(true);
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(ExcludeList list,
                          UnmarshallingContext navigator, String namespaceURI, String localName,
                          Attributes attrs)
   {
      Object child = null;

      if (localName.equals("method"))
      {
         child = new Method();
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(RemoveList list,
                          UnmarshallingContext navigator, String namespaceURI, String localName,
                          Attributes attrs)
   {
      Object child = null;

      if (localName.equals("method"))
      {
         child = new Method();
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(InitList list,
                          UnmarshallingContext navigator, String namespaceURI, String localName,
                          Attributes attrs)
   {
      Object child = null;

      if (localName.equals("method"))
      {
         child = new Method();
      }

      return child;
   }

   /**
    * Called when parsing of a new element started.
    */
   public Object newChild(ContainerTransaction transaction,
                          UnmarshallingContext navigator, String namespaceURI, String localName,
                          Attributes attrs)
   {
      Object child = null;

      if (localName.equals("method"))
      {
         child = new Method();
      }

      return child;
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(EjbJarDD parent, EnterpriseBeans ejbs,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.setEnterpriseBeans(ejbs);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(EnterpriseBeans parent, EnterpriseBean ejb,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addEnterpriseBean(ejb);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(SessionEnterpriseBean parent, SecurityIdentity si,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.setSecurityIdentity(si);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(SessionEnterpriseBean parent, EjbLocalRef ref,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addEjbLocalRef(ref);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(SessionEnterpriseBean parent, EjbRef ref,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addEjbRef(ref);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(SessionEnterpriseBean parent, MessageDestinationRef ref,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addMessageDestinationRef(ref);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(SessionEnterpriseBean parent, EnvEntry entry,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addEnvEntry(entry);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(SessionEnterpriseBean parent, ResourceRef ref,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addResourceRef(ref);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(EntityEnterpriseBean parent, CmpField field,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addCmpField(field);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(EntityEnterpriseBean parent, Query query,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addQuery(query);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(EjbJarDD parent, Relationships relationships,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.setRelationships(relationships);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(Relationships parent, EjbRelation relation,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addEjbRelation(relation);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(EjbRelation parent, EjbRelationshipRole role,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addEjbRelationshipRole(role);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(EjbRelationshipRole parent,
                        RelationshipRoleSource source, UnmarshallingContext navigator,
                        String namespaceURI, String localName)
   {
      parent.setRelationshipRoleSource(source);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(EjbRelationshipRole parent, CmrField field,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.setCmrField(field);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(EjbJarDD parent, AssemblyDescriptor descriptor,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.setAssemblyDescriptor(descriptor);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(AssemblyDescriptor parent, SecurityRole role,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addSecurityRole(role);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(AssemblyDescriptor parent, MethodPermission permission,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addMethodPermission(permission);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(AssemblyDescriptor parent, ExcludeList list,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.setExcludeList(list);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(AssemblyDescriptor parent, RemoveList list,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.setRemoveList(list);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(AssemblyDescriptor parent, InitList list,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.setInitList(list);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(AssemblyDescriptor parent, Inject inject,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addInject(inject);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(AssemblyDescriptor parent, Callback callback,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addCallback(callback);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(ExcludeList parent, Method method,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addMethod(method);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(RemoveList parent, Method method,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addMethod(method);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(InitList parent, Method method,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addMethod(method);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(MethodPermission parent, Method method,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addMethod(method);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(Inject parent, Method method,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addMethod(method);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(Callback parent, Method method,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.addMethod(method);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(AssemblyDescriptor parent,
                        ContainerTransaction transaction, UnmarshallingContext navigator,
                        String namespaceURI, String localName)
   {
      parent.addContainerTransaction(transaction);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(ContainerTransaction parent, Method method,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.setMethod(method);
   }

   /**
    * Called when parsing character is complete.
    */
   public void addChild(MessageDrivenBean parent, MessageDrivenDestination destination,
                        UnmarshallingContext navigator, String namespaceURI, String localName)
   {
      parent.setMessageDrivenDestination(destination);
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(EjbJarDD dd, UnmarshallingContext navigator,
                        String namespaceURI, String localName, String value)
   {
      if (localName.equals("display-name"))
      {
         dd.setDisplayName(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   private boolean isEjbParentName(EnterpriseBean ejb, String localName,
                                   String value)
   {
      if (localName.equals("ejb-name"))
      {
         ejb.setEjbName(value);
         return true;
      }
      else if (localName.equals("home"))
      {
         ejb.setHome(value);
         return true;
      }
      else if (localName.equals("remote"))
      {
         ejb.setRemote(value);
         return true;
      }
      else if (localName.equals("local-home"))
      {
         ejb.setLocalHome(value);
         return true;
      }
      else if (localName.equals("local"))
      {
         ejb.setLocal(value);
         return true;
      }
      else if (localName.equals("ejb-class"))
      {
         ejb.setEjbClass(value);
         return true;
      }
      else if (localName.equals("callback-listener"))
      {
         ejb.addCallbackListener(value);
         return true;
      }
      else if (localName.equals("interceptor"))
      {
         ejb.addInterceptor(value);
         return true;
      }
      else if (localName.equals("interceptors"))
      {
         StringTokenizer tokenizer = new StringTokenizer(value, ",");
         while (tokenizer.hasMoreTokens())
         {
            String interceptor = tokenizer.nextToken();
            ejb.addInterceptor(interceptor);
         }
         return true;
      }

      return false;
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(MessageDrivenBean ejb,
                        UnmarshallingContext navigator, String namespaceURI, String localName,
                        String value)
   {

      if (!isEjbParentName(ejb, localName, value))
      {
         if (localName.equals("acknowledge-mode"))
         {
            ejb.setAcknowledgeMode(value);
         }
         else if (localName.equals("transaction-type"))
         {
            ejb.setTransactionType(value);
         }
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(MessageDrivenDestination destination,
                        UnmarshallingContext navigator, String namespaceURI, String localName,
                        String value)
   {
      if (localName.equals("destination-type"))
      {
         destination.setDestinationType(value);
      }
      else if (localName.equals("subscription-durability"))
      {
         destination.setSubscriptionDurability(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(SessionEnterpriseBean ejb,
                        UnmarshallingContext navigator, String namespaceURI, String localName,
                        String value)
   {

      if (!isEjbParentName(ejb, localName, value))
      {
         if (localName.equals("session-type"))
         {
            ejb.setSessionType(value);
         }
         else if (localName.equals("transaction-type"))
         {
            ejb.setTransactionType(value);
         }
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(EntityEnterpriseBean ejb,
                        UnmarshallingContext navigator, String namespaceURI, String localName,
                        String value)
   {
      if (!isEjbParentName(ejb, localName, value))
      {
         if (localName.equals("persistence-type"))
         {
            ejb.setPersistenceType(value);
         }
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(SecurityIdentity si, UnmarshallingContext navigator,
                        String namespaceURI, String localName, String value)
   {
      if (localName.equals("use-caller-identity"))
      {
         si.setUseCallerIdentity(true);
      }
      else if (localName.equals("role-name"))
      {
         si.setRunAs(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(EjbLocalRef ref, UnmarshallingContext navigator,
                        String namespaceURI, String localName, String value)
   {
      if (localName.equals("ejb-ref-name"))
      {
         ref.setEjbRefName(value);
      }
      else if (localName.equals("ejb-ref-type"))
      {
         ref.setEjbRefType(value);
      }
      else if (localName.equals("local-home"))
      {
         ref.setLocalHome(value);
      }
      else if (localName.equals("local"))
      {
         ref.setLocal(value);
      }
      else if (localName.equals("ejb-link"))
      {
         ref.setEjbLink(value);
      }
      else if (localName.equals("injection-target"))
      {
         ref.setInjectionTarget(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(EjbRef ref, UnmarshallingContext navigator,
                        String namespaceURI, String localName, String value)
   {
      if (localName.equals("ejb-ref-name"))
      {
         ref.setEjbRefName(value);
      }
      else if (localName.equals("ejb-ref-type"))
      {
         ref.setEjbRefType(value);
      }
      else if (localName.equals("local-home"))
      {
         ref.setLocalHome(value);
      }
      else if (localName.equals("local"))
      {
         ref.setLocal(value);
      }
      else if (localName.equals("remote"))
      {
         ref.setRemote(value);
      }
      else if (localName.equals("ejb-link"))
      {
         ref.setEjbLink(value);
      }
      else if (localName.equals("injection-target"))
      {
         ref.setInjectionTarget(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(MessageDestinationRef ref, UnmarshallingContext navigator,
                        String namespaceURI, String localName, String value)
   {
      if (localName.equals("description"))
      {
         ref.setDescription(value);
      }
      else if (localName.equals("message-destination-ref-name"))
      {
         ref.setMessageDestinationRefName(value);
      }
      else if (localName.equals("message-destination-type"))
      {
         ref.setMessageDestinationType(value);
      }
      else if (localName.equals("message-destination-usage"))
      {
         ref.setMessageDestinationUsage(value);
      }
      else if (localName.equals("message-destination-link"))
      {
         ref.setMessageDestinationLink(value);
      }
      else if (localName.equals("injection-target"))
      {
         ref.setInjectionTarget(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(EnvEntry entry, UnmarshallingContext navigator,
                        String namespaceURI, String localName, String value)
   {
      if (localName.equals("description"))
      {
         entry.setDescription(value);
      }
      else if (localName.equals("env-entry-name"))
      {
         entry.setEnvEntryName(value);
      }
      else if (localName.equals("env-entry-type"))
      {
         entry.setEnvEntryType(value);
      }
      else if (localName.equals("env-entry-value"))
      {
         entry.setEnvEntryValue(value);
      }
      else if (localName.equals("injection-target"))
      {
         entry.setInjectionTarget(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(ResourceRef ref, UnmarshallingContext navigator,
                        String namespaceURI, String localName, String value)
   {
      if (localName.equals("res-ref-name"))
      {
         ref.setResRefName(value);
      }
      else if (localName.equals("res-type"))
      {
         ref.setResType(value);
      }
      else if (localName.equals("res-auth"))
      {
         ref.setResAuth(value);
      }
      else if (localName.equals("res-sharing-scope"))
      {
         ref.setResSharingScope(value);
      }
      else if (localName.equals("injection-target"))
      {
         ref.setInjectionTarget(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(EjbRelation relation, UnmarshallingContext navigator,
                        String namespaceURI, String localName, String value)
   {
      if (localName.equals("ejb-relation-name"))
      {
         relation.setEjbRelationName(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(EjbRelationshipRole role,
                        UnmarshallingContext navigator, String namespaceURI, String localName,
                        String value)
   {
      if (localName.equals("ejb-relationship-role-name"))
      {
         role.setEjbRelationshipRoleName(value);
      }
      else if (localName.equals("multiplicity"))
      {
         role.setMultiplicity(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(RelationshipRoleSource source,
                        UnmarshallingContext navigator, String namespaceURI, String localName,
                        String value)
   {
      if (localName.equals("ejb-name"))
      {
         source.setEjbName(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(CmrField field, UnmarshallingContext navigator,
                        String namespaceURI, String localName, String value)
   {
      if (localName.equals("cmr-field-name"))
      {
         field.setCmrFieldName(value);
      }
      else if (localName.equals("cmr-field-type"))
      {
         field.setCmrFieldType(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(SecurityRole role, UnmarshallingContext navigator,
                        String namespaceURI, String localName, String value)
   {
      if (localName.equals("role-name"))
      {
         role.setRoleName(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(MethodPermission permission,
                        UnmarshallingContext navigator, String namespaceURI, String localName,
                        String value)
   {
      if (localName.equals("role-name"))
      {
         permission.addRoleName(value);
      }
      else if (localName.equals("unchecked"))
      {
         permission.setUnchecked(true);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(ContainerTransaction transaction,
                        UnmarshallingContext navigator, String namespaceURI, String localName,
                        String value)
   {
      if (localName.equals("trans-attribute"))
      {
         transaction.setTransAttribute(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(Method method, UnmarshallingContext navigator,
                        String namespaceURI, String localName, String value)
   {
      if (localName.equals("ejb-name"))
      {
         method.setEjbName(value);
      }
      else if (localName.equals("method-name"))
      {
         method.setMethodName(value);
      }
      else if (localName.equals("method-param"))
      {
         method.addMethodParam(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(Inject inject, UnmarshallingContext navigator,
                        String namespaceURI, String localName, String value)
   {
      if (localName.equals("jndi-name"))
      {
         inject.setJndiName(value);
      }
   }

   /**
    * Called when a child element with simple content is read for DD.
    */
   public void setValue(Callback callback, UnmarshallingContext navigator,
                        String namespaceURI, String localName, String value)
   {
      if (localName.equals("annotation"))
      {
         callback.setAnnotation(value);
      }
   }
}
