Package org.jboss.beans.info.spi

Examples of org.jboss.beans.info.spi.BeanInfo


      }
      catch(ClassNotFoundException e)
      {
         throw new IllegalStateException(e);
      }
      BeanInfo beanInfo = configuration.getBeanInfo(moClass);

      Object componentName = null;
      Map<String, ManagedProperty> properties = managedObject.getProperties();
      if (properties != null && properties.size() > 0)
      {
View Full Code Here


            return transformer;

         TypeInfo rcntType = configuration.getTypeInfo(RuntimeComponentNameTransformer.class);
         if (rcntType.isAssignableFrom(type))
         {
            BeanInfo beanInfo = configuration.getBeanInfo(type);
            RuntimeComponentNameTransformer newTransformer = (RuntimeComponentNameTransformer)beanInfo.newInstance();
            transformers.put(type, newTransformer);
            return newTransformer;
         }

         return null;
View Full Code Here

    *    it does not have a ManagementObject annotation.
    */
   public ManagedObject buildManagedObject(Class<? extends Serializable> clazz)
   {
      boolean trace = log.isTraceEnabled();
      BeanInfo beanInfo = configuration.getBeanInfo(clazz);
      ClassInfo classInfo = beanInfo.getClassInfo();

      ManagementObject managementObject = classInfo.getUnderlyingAnnotation(ManagementObject.class);
      if( managementObject == null )
      {
         if (trace)
            log.trace("No ManagementObject annotation, skipping ManagedObject for class: "+clazz);
         // Skip the ManagedObject creation
         return null;
      }

      HashMap<String, Annotation> moAnnotations = new HashMap<String, Annotation>();
      moAnnotations.put(ManagementObject.class.getName(), managementObject);
      ManagementObjectID moID = classInfo.getUnderlyingAnnotation(ManagementObjectID.class);
      if (moID != null)
         moAnnotations.put(ManagementObjectID.class.getName(), moID);

      // Process the ManagementObject fields
      boolean isRuntime = managementObject.isRuntime();
      String name = classInfo.getName();
      String nameType = null;
      String attachmentName = classInfo.getName();
      Class<? extends Fields> moFieldsFactory = null;
      Class<? extends ManagedPropertyConstraintsPopulatorFactory> moConstraintsFactory = null;
      Class<? extends ManagedProperty> moPropertyFactory = null;
      if (managementObject != null)
      {
         name = managementObject.name();
         if (name.length() == 0 || name.equals(ManagementConstants.GENERATED))
            name = classInfo.getName();
         nameType = managementObject.type();
         if (nameType.length() == 0)
            nameType = null;
         attachmentName = managementObject.attachmentName();
         if (attachmentName.length() == 0)
            attachmentName = classInfo.getName();
         // Check for a component specification
         ManagementComponent mc = managementObject.componentType();
         if (mc.equals(AnnotationDefaults.COMP_TYPE) == false)
            moAnnotations.put(ManagementComponent.class.getName(), mc);
         // ManagementObject level default factory classes
         moFieldsFactory = managementObject.fieldsFactory();
         moConstraintsFactory = managementObject.constraintsFactory();
         moPropertyFactory = managementObject.propertyFactory();
      }

      if (trace)
      {
         log.trace("Building MangedObject(name="+name+",nameType="+nameType
               +",attachmentName="+attachmentName+",isRuntime="+isRuntime+")");
      }

      ManagementProperties propertyType = ManagementProperties.ALL;
      if (managementObject != null)
         propertyType = managementObject.properties();

      // Build the ManagedProperties
      Set<ManagedProperty> properties = new HashSet<ManagedProperty>();

      Set<PropertyInfo> propertyInfos = beanInfo.getProperties();
      if (propertyInfos != null && propertyInfos.isEmpty() == false)
      {
         for (PropertyInfo propertyInfo : propertyInfos)
         {
            // Ignore the "class" property
            if ("class".equals(propertyInfo.getName()))
               continue;

            ManagementProperty managementProperty = propertyInfo.getUnderlyingAnnotation(ManagementProperty.class);
            ManagementObjectID id = propertyInfo.getUnderlyingAnnotation(ManagementObjectID.class);
            ManagementObjectRef ref = propertyInfo.getUnderlyingAnnotation(ManagementObjectRef.class);
            ManagementRuntimeRef runtimeRef = propertyInfo.getUnderlyingAnnotation(ManagementRuntimeRef.class);
            HashMap<String, Annotation> propAnnotations = new HashMap<String, Annotation>();
            if (managementProperty != null)
               propAnnotations.put(ManagementProperty.class.getName(), managementProperty);
            if (id != null)
            {
               propAnnotations.put(ManagementObjectID.class.getName(), id);
               // This overrides the MO nameType
               nameType = id.type();
            }
            if (ref != null)
               propAnnotations.put(ManagementObjectRef.class.getName(), ref);
            if (runtimeRef != null)
               propAnnotations.put(ManagementRuntimeRef.class.getName(), runtimeRef);

            // Check for a simple property
            boolean includeProperty = (propertyType == ManagementProperties.ALL);
            if (managementProperty != null)
               includeProperty = (managementProperty.ignored() == false);

            if (includeProperty)
            {
               Fields fields = null;
               if (managementProperty != null)
               {
                  Class<? extends Fields> factory = moFieldsFactory;
                  if (factory == ManagementProperty.NULL_FIELDS_FACTORY.class)
                     factory = managementProperty.fieldsFactory();
                  if (factory != ManagementProperty.NULL_FIELDS_FACTORY.class)
                  {
                     try
                     {
                        fields = factory.newInstance();
                     }
                     catch (Exception e)
                     {
                        log.debug("Failed to created Fields", e);
                     }
                  }
               }
               if (fields == null)
                  fields = new DefaultFieldsImpl();

               if( propertyInfo instanceof Serializable )
               {
                  Serializable info = Serializable.class.cast(propertyInfo);
                  fields.setField(Fields.PROPERTY_INFO, info);
               }

               String propertyName = propertyInfo.getName();
               if (managementProperty != null)
                  propertyName = managementProperty.name();
               if( propertyName.length() == 0 )
                  propertyName = propertyInfo.getName();
               fields.setField(Fields.NAME, propertyName);

               // This should probably always the the propertyInfo name?
               String mappedName = propertyInfo.getName();
               if (managementProperty != null)
                  mappedName = managementProperty.mappedName();
               if( mappedName.length() == 0 )
                  mappedName = propertyInfo.getName();
               fields.setField(Fields.MAPPED_NAME, mappedName);

               String description = ManagementConstants.GENERATED;
               if (managementProperty != null)
                  description = managementProperty.description();
               if (description.equals(ManagementConstants.GENERATED))
                  description = propertyName;
               fields.setField(Fields.DESCRIPTION, description);

               if (trace)
               {
                  log.trace("Building MangedProperty(name="+propertyName
                        +",mappedName="+mappedName
                        +") ,annotations="+propAnnotations);
               }

               boolean mandatory = false;
               if (managementProperty != null)
                  mandatory = managementProperty.mandatory();
               if (mandatory)
                  fields.setField(Fields.MANDATORY, Boolean.TRUE);
              
               boolean managed = false;
               if (managementProperty != null)
                  managed = managementProperty.managed();
              
               MetaType metaType;
               if (managed)
               {
                  TypeInfo typeInfo = propertyInfo.getType();
                  if(typeInfo.isArray())
                     metaType = new ArrayMetaType(1, MANAGED_OBJECT_META_TYPE);
                  else if (typeInfo.isCollection())
                     metaType = new CollectionMetaType(typeInfo.getName(), MANAGED_OBJECT_META_TYPE);
                  else
                     metaType = MANAGED_OBJECT_META_TYPE;
               }
               else
               {
                  metaType = metaTypeFactory.resolve(propertyInfo.getType());
               }
               fields.setField(Fields.META_TYPE, metaType);
               if (propAnnotations.isEmpty() == false)
                  fields.setField(Fields.ANNOTATIONS, propAnnotations);

               // Delegate others (legal values, min/max etc.) to the constraints factory
               try
               {
                  Class<? extends ManagedPropertyConstraintsPopulatorFactory> factoryClass = moConstraintsFactory;
                  if (factoryClass == ManagementProperty.NULL_CONSTRAINTS.class)
                  {
                     if (managementProperty != null)
                        factoryClass = managementProperty.constraintsFactory();
                  }
                  ManagedPropertyConstraintsPopulatorFactory factory = factoryClass.newInstance();
                  ManagedPropertyConstraintsPopulator populator = factory.newInstance();
                  if (populator != null)
                     populator.populateManagedProperty(clazz, propertyInfo, fields);
               }
               catch(Exception e)
               {
                  log.debug("Failed to populate constraints for: "+propertyInfo, e);
               }

               ManagedProperty property = null;
               if (managementProperty != null)
               {
                  Class<? extends ManagedProperty> factory = moPropertyFactory;
                  if (factory == ManagementProperty.NULL_PROPERTY_FACTORY.class)
                     factory = managementProperty.propertyFactory();
                  if (factory != ManagementProperty.NULL_PROPERTY_FACTORY.class)
                     property = getManagedProperty(factory, fields);
               }
               // we should have write-through by default
               // use factory to change this default behavior
               if (property == null)
                  property = createDefaultManagedProperty(fields);
               properties.add(property);
            }
            else if (trace)
               log.trace("Ignoring property: " + propertyInfo);
         }
      }

      /* TODO: Operations. In general the bean metadata does not contain
         operation information.
      */
      Set<ManagedOperation> operations = new HashSet<ManagedOperation>();
     
      Set<MethodInfo> methodInfos = beanInfo.getMethods();
      if (methodInfos != null && methodInfos.isEmpty() == false)
      {
         for (MethodInfo methodInfo : methodInfos)
         {
            ManagementOperation managementOp = methodInfo.getUnderlyingAnnotation(ManagementOperation.class);
View Full Code Here

    * @param clazz the class
    * @return the object
    */
   protected Serializable createUnderlyingObject(ManagedObjectImpl managedObject, Class<? extends Serializable> clazz)
   {
      BeanInfo beanInfo = configuration.getBeanInfo(clazz);
      try
      {
         Object result = beanInfo.newInstance();
         return Serializable.class.cast(result);
      }
      catch (Throwable t)
      {
         throw new RuntimeException("Unable to create new object for " + managedObject + " clazz=" + clazz, t);
View Full Code Here

      }
      catch(ClassNotFoundException e)
      {
         throw new IllegalStateException(e);
      }
      BeanInfo beanInfo = configuration.getBeanInfo(moClass);

      Object componentName = null;
      Map<String, ManagedProperty> properties = managedObject.getProperties();
      if (properties != null && properties.size() > 0)
      {
View Full Code Here

            return transformer;

         TypeInfo rcntType = configuration.getTypeInfo(RuntimeComponentNameTransformer.class);
         if (rcntType.isAssignableFrom(type))
         {
            BeanInfo beanInfo = configuration.getBeanInfo(type);
            RuntimeComponentNameTransformer newTransformer = (RuntimeComponentNameTransformer)beanInfo.newInstance();
            transformers.put(type, newTransformer);
            return newTransformer;
         }

         return null;
View Full Code Here

               metaValue = (MetaValue)value;

            if (metaValue == null || metaValue.getMetaType().isTable() == false)
            {
               InstanceClassFactory icf = getObjectFactory().getInstanceClassFactory(attachment.getClass());
               BeanInfo beanInfo = propertyInfo.getBeanInfo();
               icf.setValue(beanInfo, this, attachment, metaValue);
            }
         }
      }
   }
View Full Code Here

      Class<? extends ValueAdapter> adapter = adaptedType.valueAdapter();
      try
      {

         TypeInfo typeInfo = JBossXBBuilder.configuration.getTypeInfo(type);
         BeanInfo adapterInfo = JBossXBBuilder.configuration.getBeanInfo(adapter);

         ValueAdapter valueAdapter = (ValueAdapter) adapterInfo.newInstance();

         QName qName = generateXmlName(typeInfo, XmlNsForm.QUALIFIED, overrideNamespace, overrideName);

         TypeInfo parentType = typeInfo.getTypeInfoFactory().getTypeInfo(String.class);
         TypeBinding parent = getSimpleType(parentType);
View Full Code Here

      MethodInfo factory = null;
      if (factoryMethod != null && factoryMethod.length() > 0)
         factory = Config.findMethodInfo(factoryClassInfo, factoryMethod, null, true, true);

      // Create the handler
      BeanInfo beanInfo = JBossXBBuilder.configuration.getBeanInfo(typeInfo);
      BeanAdapterFactory beanAdapterFactory = createAdapterFactory(beanAdapterBuilderClass, beanInfo, factory);
      BeanHandler handler = new BeanHandler(beanInfo.getName(), beanAdapterFactory);
      typeBinding.setHandler(handler);
      if (trace)
         log.trace("Created BeanHandler for type=" + beanInfo.getName() + " factory=" + factory);

      // Look through the properties
      JBossXmlNoElements jbossXmlNoElements = typeInfo.getUnderlyingAnnotation(JBossXmlNoElements.class);
      boolean noElements = jbossXmlNoElements != null;
      PropertyInfo valueProperty = null;
      PropertyInfo wildcardProperty = null;
      boolean allBinding = propertyOrder.length == 0;
      boolean determinePropertyOrder = allBinding || (propertyOrder.length == 1 && propertyOrder[0].length() == 0);
      ArrayList<String> propertyNames = new ArrayList<String>();
      Set<PropertyInfo> properties = beanInfo.getProperties();
      if (properties != null && properties.isEmpty() == false)
      {
         boolean seenXmlAnyElement = false;
         for (PropertyInfo property : properties)
         {
            push(typeInfo, property.getName());

            if (trace)
               log.trace("Checking property " + property.getName() + " for " + beanInfo.getName() + " type=" + property.getType().getName());

            // Is this the value property?
            XmlValue xmlValue = property.getUnderlyingAnnotation(XmlValue.class);
            if (xmlValue != null)
            {
               if (trace)
                  log.trace("Seen @XmlValue for type=" + beanInfo.getName() + " property=" + property.getName());
               if (valueProperty != null)
                  throw new RuntimeException("@XmlValue seen on two properties: " + property.getName() + " and " + valueProperty.getName());
               valueProperty = property;
            }

            // Is this the wildcard property?
            boolean ignoreXmlAnyElement = false;
            XmlAnyElement xmlAnyElement = property.getUnderlyingAnnotation(XmlAnyElement.class);
            if (xmlAnyElement != null)
            {
               if (trace)
                  log.trace("Seen @XmlAnyElement for type=" + beanInfo.getName() + " property=" + property.getName());
               if (wildcardProperty != null && seenXmlAnyElement)
                  throw new RuntimeException("@XmlAnyElement seen on two properties: " + property.getName() + " and " + wildcardProperty.getName());
               wildcardProperty = property;
               seenXmlAnyElement = true;
              
               // should we ignore it
               if(property.getUnderlyingAnnotation(XmlElements.class) == null &&
                  property.getUnderlyingAnnotation(XmlElementRefs.class) == null)
                  ignoreXmlAnyElement = true;
            }
            else if (!seenXmlAnyElement && wildcardProperty == null && property.getType().getName().equals(org.w3c.dom.Element.class.getName()))
            {
               if (trace)
                  log.trace("Using type=" + beanInfo.getName() + " property=" + property.getName() + " as the base wildcard");
               if (wildcardProperty != null)
                  throw new RuntimeException("@XmlAnyElement seen on two properties: " + property.getName() + " and " + wildcardProperty.getName());
               wildcardProperty = property;
            }

            // Is this an attribute
            XmlAttribute xmlAttribute = property.getUnderlyingAnnotation(XmlAttribute.class);
            if (xmlAttribute != null)
            {
               JBossXmlAttribute jbossXmlAttribute = property.getUnderlyingAnnotation(JBossXmlAttribute.class);
               // Determine the name
               QName qName = generateXmlName(property.getName(), attributeForm, xmlAttribute.namespace(), xmlAttribute.name());
               // Resolve the type
               TypeInfo attributeTypeInfo = property.getType();
               if (jbossXmlAttribute != null && jbossXmlAttribute.type() != Object.class)
                  attributeTypeInfo = attributeTypeInfo.getTypeInfoFactory().getTypeInfo(jbossXmlAttribute.type());
               TypeBinding attributeType = resolveTypeBinding(attributeTypeInfo);
               // Create the attribute handler
               AttributeHandler attributeHandler = new PropertyHandler(property, attributeTypeInfo);
               // Create the attributre and bind it to the type
               AttributeBinding attribute = new AttributeBinding(schemaBinding, qName, attributeType, attributeHandler);
               attribute.setRequired(xmlAttribute.required());
               typeBinding.addAttribute(attribute);
               if (trace)
                  log.trace("Bound attribute " + qName + " type=" + beanInfo.getName() + " property=" + property.getName() + " propertyType=" + attributeTypeInfo);
            }

            // Are we determining the property order?
            if (determinePropertyOrder)
            {
               // Value property
               if (xmlValue != null)
               {
                  if (trace)
                     log.trace("Ignore not element @XmlValue for type=" + beanInfo.getName() + " property=" + property.getName());
                  pop();
                  continue;
               }
               // Wildcard property
               if (ignoreXmlAnyElement)
               {
                  if (trace)
                     log.trace("Ignore not element @XmlAnyElement for type=" + beanInfo.getName() + " property=" + property.getName());
                  pop();
                  continue;
               }
               // Ignore xml attribute
               if (xmlAttribute != null)
               {
                  if (trace)
                     log.trace("Ignore not element @XmlAttribute for type=" + beanInfo.getName() + " property=" + property.getName());
                  pop();
                  continue;
               }
               // Ignore xml tranient
               XmlTransient xmlTransient = property.getUnderlyingAnnotation(XmlTransient.class);
               if (xmlTransient != null)
               {
                  if (trace)
                     log.trace("Ignore not element @XmlTransient for type=" + beanInfo.getName() + " property=" + property.getName());
                  pop();
                  continue;
               }
               // Ignore the class property
               String name = property.getName();
               if ("class".equals(name))
               {
                  pop();
                  continue;
               }

               if (noElements)
               {
                  pop();
                  continue;
               }

               if (trace)
                  log.trace("Element for type=" + beanInfo.getName() + " property=" + property.getName());
               propertyNames.add(property.getName());
            }

            pop();
         }
         // Apply any access order
         if (determinePropertyOrder)
         {
            if (accessOrder == XmlAccessOrder.ALPHABETICAL)
               Collections.sort(propertyNames);
            propertyOrder = propertyNames.toArray(new String[propertyNames.size()]);
         }
      }

      // No value property, see if we have a default one
      //if (valueProperty == null)
      //{
      //   try
      //   {
      //      valueProperty = beanInfo.getProperty("value");
      //   }
      //   catch (Exception ignored)
      //   {
            // Nope.
      //   }
      //}

      // Bind the value
      if (valueProperty != null)
      {
         CharactersHandler charactersHandler = new ValueHandler(valueProperty);
         typeBinding.setSimpleType(charactersHandler);
      }
      else if (trace)
         log.trace("No value for type=" + beanInfo.getName());

      if (trace)
         log.trace("PropertyOrder " + Arrays.asList(propertyOrder) + " for type=" + beanInfo.getName());

      // Determine the model
      // TODO simple types/content when no properties other than @XmlValue and @XmlAttribute
      typeBinding.setSimple(false);
      ModelGroupBinding model = null;
      if (allBinding)
      {
         if (trace)
            log.trace("AllBinding for type=" + beanInfo.getName());
         model = new AllBinding(schemaBinding);
      }
      else
      {
         if (trace)
            log.trace("SequenceBinding for type=" + beanInfo.getName());
         model = new SequenceBinding(schemaBinding);
      }
      model.setHandler(BuilderParticleHandler.INSTANCE);
      ParticleBinding typeParticle = new ParticleBinding(model);
      typeParticle.setMinOccurs(1);
      typeParticle.setMaxOccurs(1);
      typeBinding.setParticle(typeParticle);

      if (typeInfo.isCollection())
      {
         TypeInfo memberBaseType = ((ClassInfo)typeInfo).getComponentType();
         JBossXmlModelGroup xmlModelGroup = ((ClassInfo) memberBaseType)
               .getUnderlyingAnnotation(JBossXmlModelGroup.class);
         if (xmlModelGroup != null && xmlModelGroup.particles().length > 0)
         {
            if (trace)
               log.trace("Item base type for " + typeInfo.getName() + " is " + memberBaseType.getName()
                     + " and bound to repeatable choice");

            // it's choice by default based on the idea that the
            // type parameter is a base class for items
            ModelGroupBinding choiceGroup = null;
            QName choiceName = null;
            if(!JBossXmlConstants.DEFAULT.equals(xmlModelGroup.name()))
            {
               choiceName = new QName(defaultNamespace, xmlModelGroup.name());
               choiceGroup = schemaBinding.getGroup(choiceName);
            }
           
            if(choiceGroup == null)
            {
               choiceGroup = new ChoiceBinding(schemaBinding);
               choiceGroup.setHandler(BuilderParticleHandler.INSTANCE);
               if (choiceName != null)
               {
                  choiceGroup.setQName(choiceName);
                  schemaBinding.addGroup(choiceGroup.getQName(), choiceGroup);
               }

               ParticleBinding choiceParticle = new ParticleBinding(choiceGroup, 0, 1, true);
               model.addParticle(choiceParticle);

               for (JBossXmlModelGroup.Particle member : xmlModelGroup.particles())
               {
                  XmlElement element = member.element();
                  QName memberQName = generateXmlName(element.name(), XmlNsForm.QUALIFIED, element.namespace(), null);
                  TypeInfo memberTypeInfo = typeInfo.getTypeInfoFactory().getTypeInfo(member.type());

                  boolean isCol = false;
                  if (memberTypeInfo.isCollection())
                  {
                     memberTypeInfo = ((ClassInfo) memberTypeInfo).getComponentType();
                     isCol = true;
                  }

                  TypeBinding memberTypeBinding = resolveTypeBinding(memberTypeInfo);
                  ElementBinding memberElement = createElementBinding(memberTypeInfo, memberTypeBinding, memberQName, false);
                  memberElement.setNillable(true);
                  ParticleBinding memberParticle = new ParticleBinding(memberElement, 0, 1, isCol);
                  choiceGroup.addParticle(memberParticle);

                  typeBinding.pushInterceptor(memberQName, ChildCollectionInterceptor.SINGLETON);
               }
            }
            else
            {
               ParticleBinding choiceParticle = new ParticleBinding(choiceGroup, 0, 1, true);
               model.addParticle(choiceParticle);
            }
           
            if (trace)
               log.trace("choices for " + typeBinding.getQName() + ": " + choiceGroup.getParticles());
         }
      }

      // Determine the wildcard handler
      AbstractPropertyHandler wildcardHandler = null;
      if (wildcardProperty != null)
      {
         TypeInfo wildcardType = wildcardProperty.getType();
         if (wildcardType.isCollection())
            wildcardHandler = new CollectionPropertyWildcardHandler(wildcardProperty, wildcardType);
         else
            wildcardHandler = new PropertyWildcardHandler(wildcardProperty, wildcardType);
      }

      // Look through the properties
      for (String name : propertyOrder)
      {
         // Setup the error stack
         push(typeInfo, name);
         // Get the property
         PropertyInfo property = beanInfo.getProperty(name);
         bindProperty(property, typeBinding, model, beanAdapterFactory, propertyOrder);
         pop();
      }

      // Bind the children
      JBossXmlChild[] children = null;
      JBossXmlChildren jbossXmlChildren = typeInfo.getUnderlyingAnnotation(JBossXmlChildren.class);
      if (jbossXmlChildren != null)
         children = jbossXmlChildren.value();
      else
      {
         JBossXmlChild jbossXmlChild = typeInfo.getUnderlyingAnnotation(JBossXmlChild.class);
         if (jbossXmlChild != null)
            children = new JBossXmlChild[] { jbossXmlChild };
      }

      if (children != null && children.length > 0)
      {
         for (JBossXmlChild child : children)
         {
            QName qName = generateXmlName(child.name(), elementForm, child.namespace(), child.name());
            TypeInfo childType = JBossXBBuilder.configuration.getTypeInfo(child.type());

            TypeBinding elementTypeBinding = resolveTypeBinding(childType);
            ElementBinding elementBinding = createElementBinding(childType, elementTypeBinding, qName, false);

            // Bind it to the model
            ParticleBinding particle = new ParticleBinding(elementBinding, child.minOccurs(), child.maxOccurs(), child.unbounded());
            model.addParticle(particle);

            if(childType.isMap())
               bindMapProperty(null, (ClassInfo) childType, elementTypeBinding.getQName(), (ModelGroupBinding) elementTypeBinding.getParticle().getTerm());
           
            DefaultElementInterceptor interceptor = null;
            if (typeInfo.isCollection())
               interceptor = ChildCollectionInterceptor.SINGLETON;
            else
            {
               // Expect a type with a value property to accept the child value
               PropertyInfo property = beanInfo.getProperty("value");
               if (property == null)
                  throw new UnsupportedOperationException("Expected a value property for non-collection type with JBossXmlChildren");
               TypeInfo propertyType = property.getType();
               interceptor = new PropertyInterceptor(property, propertyType);
            }
            typeBinding.pushInterceptor(qName, interceptor);
            if (trace)
               log.trace("Added interceptor " + qName + " for type=" + childType + " interceptor=" + interceptor);
         }
      }

      // Bind the wildcard
      if (wildcardProperty != null)
      {
         if (trace)
            log.trace("Processing WildcardProperty for type=" + beanInfo.getName() + " property=" + wildcardProperty.getName());
         ModelGroupBinding localModel = model;
         TypeInfo wildcardType = wildcardProperty.getType();
         TypeInfo type = wildcardType;

         // Setup any new model and determine the wildcard type
         if (wildcardType.isArray())
         {
            localModel = createArray(localModel);
            type = ((ArrayInfo) wildcardType).getComponentType();
            if (trace)
               log.trace("Wildcard " + wildcardProperty.getName() + " is an array of type " + type.getName());
         }
         else if (wildcardType.isCollection())
         {
            localModel = createCollection(localModel);
            type = ((ClassInfo)wildcardProperty.getType()).getComponentType();
            if (trace)
               log.trace("Wildcard " + wildcardProperty.getName() + " is a collection of type " + type.getName());
         }

         XmlAnyElement xmlAnyElement = wildcardProperty.getUnderlyingAnnotation(XmlAnyElement.class);
         boolean isLax = xmlAnyElement == null ? true : xmlAnyElement.lax();
         WildcardBinding wildcard = new WildcardBinding(schemaBinding);
         if (isLax)
            wildcard.setProcessContents((short) 3); // Lax
         else
            wildcard.setProcessContents((short) 1); // Strict

         // Dom element?
         if (Element.class.getName().equals(type.getName()))
         {
            wildcard.setUnresolvedElementHandler(DOMHandler.INSTANCE);
            wildcard.setUnresolvedCharactersHandler(DOMHandler.INSTANCE);
         }

         // Bind the particle to the model
         ParticleBinding particleBinding = new ParticleBinding(wildcard);
         particleBinding.setMinOccurs(0);
         particleBinding.setMaxOccurs(1);
         localModel.addParticle(particleBinding);
         typeBinding.getWildcard().setWildcardHandler((ParticleHandler) wildcardHandler);
         beanAdapterFactory.setWildcardHandler(wildcardHandler);
      }

      JBossXmlChildWildcard childWildcard = typeInfo.getUnderlyingAnnotation(JBossXmlChildWildcard.class);
      if (childWildcard != null)
      {
         if (beanAdapterFactory.getWildcardHandler() != null)
            throw new RuntimeException("Cannot have both @JBossXmlChildWildcard and @XmlAnyElement");

         ParticleHandler childWildcardHandler = null;
         if (typeInfo.isCollection())
         {
            if (childWildcard.wrapper() != Object.class)
            {
               BeanInfo wrapperInfo = JBossXBBuilder.configuration.getBeanInfo(childWildcard.wrapper());
               childWildcardHandler = new ChildCollectionWildcardHandler(wrapperInfo, childWildcard.property());
            }
            else
               childWildcardHandler = ChildCollectionWildcardHandler.SINGLETON;
         }
View Full Code Here

               }

               propertyGroup.setSkip(Boolean.FALSE);

               // handler for the model group members
               BeanInfo propBeanInfo = JBossXBBuilder.configuration.getBeanInfo(propClassInfo);
               BeanAdapterFactory propBeanAdapterFactory = createAdapterFactory(DefaultBeanAdapterBuilder.class, propBeanInfo, null);
               BeanHandler propHandler = new BeanHandler(propBeanInfo.getName(), propBeanAdapterFactory);
               propertyGroup.setHandler(propHandler);

               String[] memberOrder = xmlModelGroup.propOrder();
               if (memberOrder.length == 0 || memberOrder[0].length() == 0)
               {
                  List<String> propNames = new ArrayList<String>();
                  for (PropertyInfo prop : propBeanInfo.getProperties())
                  {
                     propNames.add(prop.getName());
                  }
                  memberOrder = propNames.toArray(new String[propNames.size()]);
               }

               if (trace)
                  log.trace("Property order for " + xmlModelGroup.kind() + " property " + property.getName() + ": "
                        + Arrays.asList(memberOrder));

               // bind model group members
               for (String memberPropName : memberOrder)
               {
                  if ("class".equals(memberPropName))
                  {
                     continue;
                  }

                  PropertyInfo memberProp = propBeanInfo.getProperty(memberPropName);
                  TypeInfo memberTypeInfo = memberProp.getType();
                  String memberNamespace = null;

                  JBossXmlNsPrefix nsPrefix = memberProp.getUnderlyingAnnotation(JBossXmlNsPrefix.class);
                  if (nsPrefix != null)
                  {
                     memberNamespace = schemaBinding.getNamespace(nsPrefix.prefix());
                     if (memberNamespace == null && nsPrefix.schemaTargetIfNotMapped())
                     {
                        throw new IllegalStateException("Prefix '" + nsPrefix.prefix()
                              + "' is not mapped to any namespace!");
                     }
                  }

                  String memberName = null;
                  XmlElement memberXmlElement = memberProp.getUnderlyingAnnotation(XmlElement.class);
                  if (memberXmlElement != null)
                  {
                     if (!XmlElement.DEFAULT.class.equals(memberXmlElement.type()))
                     {
                        memberTypeInfo = memberTypeInfo.getTypeInfoFactory().getTypeInfo(memberXmlElement.type());
                     }

                     if (memberNamespace == null)
                        memberNamespace = memberXmlElement.namespace();
                     memberName = memberXmlElement.name();
                  }

                  if (memberNamespace == null)
                  {
                     memberNamespace = defaultNamespace;
                  }

                  boolean isCol = false;
                  AbstractPropertyHandler memberPropertyHandler = null;
                  if (memberProp.getType().isCollection())
                  {
                     memberPropertyHandler = new CollectionPropertyHandler(memberProp, memberProp.getType());
                     isCol = true;
                     // if memberXmlElement is present then the collection item type is set explicitly
                     if (memberXmlElement == null || XmlElement.DEFAULT.class.equals(memberXmlElement.type()))
                     {
                        JBossXmlCollection jbossXmlCollection = memberProp
                              .getUnderlyingAnnotation(JBossXmlCollection.class);
                        if (jbossXmlCollection != null)
                        {
                           memberTypeInfo = memberTypeInfo.getTypeInfoFactory().getTypeInfo(jbossXmlCollection.type());
                        }
                        memberTypeInfo = ((ClassInfo) memberTypeInfo).getComponentType();
                     }
                  }
                  // if it is bound with XmlElement.type to a collection
                  else if (memberTypeInfo.isCollection())
                  {
                     memberPropertyHandler = new CollectionPropertyHandler(memberProp, memberTypeInfo);
                     isCol = true;
                     memberTypeInfo = ((ClassInfo) memberTypeInfo).getComponentType();
                  }
                  else
                  {
                     memberPropertyHandler = new PropertyHandler(memberProp, memberTypeInfo);
                  }

                  QName memberQName = generateXmlName(memberProp.getName(), elementForm, memberNamespace, memberName);
                  propBeanAdapterFactory.addProperty(memberQName, memberPropertyHandler);

                  XBValueAdapter valueAdapter = null;
                  XmlJavaTypeAdapter xmlTypeAdapter = memberProp.getUnderlyingAnnotation(XmlJavaTypeAdapter.class);
                  if (xmlTypeAdapter != null)
                  {
                     valueAdapter = new XBValueAdapter(xmlTypeAdapter.value(), memberTypeInfo.getTypeInfoFactory());
                     memberTypeInfo = valueAdapter.getAdaptedTypeInfo();
                  }

                  TypeBinding memberTypeBinding = resolveTypeBinding(memberTypeInfo);
                  ElementBinding memberElement = createElementBinding(memberTypeInfo, memberTypeBinding, memberQName,
                        false);
                  memberElement.setNillable(true);
                  memberElement.setValueAdapter(valueAdapter);
                  ParticleBinding memberParticle = new ParticleBinding(memberElement, 0, 1, isCol);
                  propertyGroup.addParticle(memberParticle);

                  if (trace)
                     log.trace("added " + memberParticle + " to " + xmlModelGroup.kind() + ", property "
                           + property.getName());
               }
            }

            model.addParticle(new ParticleBinding(propertyGroup));

            // model group value handler based on the model group name
            // TODO what if it doesn't have a name?
            AbstractPropertyHandler propertyHandler = null;
            if (propertyType.isCollection())
               propertyHandler = new CollectionPropertyHandler(property, propClassInfo);
            else
            {
               propertyHandler = new PropertyHandler(property, propClassInfo);
            }
            beanAdapterFactory.addProperty(propertyGroup.getQName(), propertyHandler);
            return;
         }
      }

      // So this is element(s)
      XmlElement[] elements = null;
      XmlElement xmlElement = property.getUnderlyingAnnotation(XmlElement.class);
      if (xmlElement != null)
      {
         // A single element annotated
         elements = new XmlElement[]
         {xmlElement};
      }
      else
      {
         // Mutlple elements
         XmlElements xmlElements = property.getUnderlyingAnnotation(XmlElements.class);
         if (xmlElements != null)
            elements = xmlElements.value();
      }

      // A single element not annotated
      if (elements == null || elements.length == 0)
         elements = new XmlElement[1];

      // for now support just one JBossXmlNsPrefix
      JBossXmlNsPrefix xmlNsPrefix = property.getUnderlyingAnnotation(JBossXmlNsPrefix.class);

      // support for @XmlElementWrapper
      // the wrapping element is ignored in this case
      XmlElementWrapper xmlWrapper = property.getUnderlyingAnnotation(XmlElementWrapper.class);
      if (xmlWrapper != null)
      {        
         String wrapperNamespace = xmlWrapper.namespace();
         String wrapperName = xmlWrapper.name();
         QName wrapperQName = generateXmlName(property.getName(), elementForm, wrapperNamespace, wrapperName);
         localModel = bindXmlElementWrapper(propertyType, localModel, xmlWrapper.nillable(), wrapperQName);
         if (trace)
            log.trace("Added property " + wrapperQName + " for type=" + property.getBeanInfo().getName() + " property="
                  + property.getName() + " as a wrapper element");
      }

      // Setup a choice
      if (elements.length > 1)
      {
         ChoiceBinding choice = new ChoiceBinding(schemaBinding);
         choice.setHandler(BuilderParticleHandler.INSTANCE);
         ParticleBinding particleBinding = new ParticleBinding(choice);
         particleBinding.setMinOccurs(0);
         particleBinding.setMaxOccurs(1);
         localModel.addParticle(particleBinding);
         localModel = choice;
         if (trace)
            log.trace("XmlElements seen adding choice for type=" + property.getBeanInfo().getName() + " property="
                  + property.getName());
      }

      for (int i = 0; i < elements.length; ++i)
      {
         XmlElement element = elements[i];
         if (trace)
            log.trace("Processing " + element + " for type=" + property.getBeanInfo().getName() + " property="
                  + property.getName());

         // Determine the parameters
         String overrideNamespace = null;
         String overrideName = null;
         boolean nillable = false;
         boolean required = false;

         TypeInfo localPropertyType = propertyType;

         if (element != null)
         {
            overrideNamespace = element.namespace();
            overrideName = element.name();
            nillable = element.nillable();
            required = element.required();
            Class<?> elementType = element.type();
            if (elementType != XmlElement.DEFAULT.class)
               localPropertyType = propertyType.getTypeInfoFactory().getTypeInfo(elementType);
         }

         if (xmlNsPrefix != null)
         {
            overrideNamespace = schemaBinding.getNamespace(xmlNsPrefix.prefix());
            if (overrideNamespace == null)
            {
               if (xmlNsPrefix.schemaTargetIfNotMapped())
               {
                  overrideNamespace = defaultNamespace;
               }
               else
               {
                  throw new IllegalStateException("Prefix '" + xmlNsPrefix.prefix()
                        + "' is not mapped to any namespace!");
               }
            }
         }

         // Determine the name
         QName propertyQName = generateXmlName(property.getName(), elementForm, overrideNamespace, overrideName);

         // Create the element
         JBossXmlGroup jbossXmlGroup = null;
         if (!propertyType.isPrimitive())
            jbossXmlGroup = ((ClassInfo) propertyType).getUnderlyingAnnotation(JBossXmlGroup.class);
         if (element == null && jbossXmlGroup != null)
         {
            if (trace)
               log.trace("Processing group for property " + property.getName() + " in "
                     + property.getBeanInfo().getName() + " " + jbossXmlGroup);
            JBossXmlChild[] children = jbossXmlGroup.value();
            if (children != null && children.length > 0)
            {
               TypeBinding elementTypeBinding = new TypeBinding();
               elementTypeBinding.setSchemaBinding(schemaBinding);
               elementTypeBinding.setHandler(BuilderParticleHandler.INSTANCE);
               ElementBinding elementBinding = createElementBinding(localPropertyType, elementTypeBinding, propertyQName, false);

               // Bind it to the model
               ParticleBinding particle = new ParticleBinding(elementBinding, 1, 1, false);
               if (required == false)
                  particle.setMinOccurs(0);
               localModel.addParticle(particle);

               // Can it take text?
               JBossXmlGroupText groupText = ((ClassInfo) propertyType)
                     .getUnderlyingAnnotation(JBossXmlGroupText.class);
               if (groupText != null)
               {
                  CharactersHandler textHandler;
                  if (groupText.wrapper() != Object.class)
                  {
                     BeanInfo wrapperInfo = JBossXBBuilder.configuration.getBeanInfo(groupText.wrapper());
                     textHandler = new ValueHandler(property, wrapperInfo, groupText.property());
                  }
                  else
                     textHandler = new ValueHandler(property);
                  elementTypeBinding.setSimpleType(textHandler);
               }

               // Setup the child model
               ChoiceBinding childModel = new ChoiceBinding(schemaBinding);
               childModel.setHandler(BuilderParticleHandler.INSTANCE);
               ParticleBinding particleBinding = new ParticleBinding(childModel);
               particleBinding.setMinOccurs(0);
               particleBinding.setMaxOccurs(1);
               elementTypeBinding.setParticle(particleBinding);

               for (JBossXmlChild child : children)
               {
                  QName childName = generateXmlName(child.name(), elementForm, child.namespace(), child.name());
                  TypeInfo childType = JBossXBBuilder.configuration.getTypeInfo(child.type());

                  TypeBinding childTypeBinding = resolveTypeBinding(childType);
                  ElementBinding childBinding = createElementBinding(childType, childTypeBinding, childName, false);
                  childBinding.setNillable(nillable);

                  // Bind it to the model
                  particle = new ParticleBinding(childBinding, child.minOccurs(), child.maxOccurs(), child.unbounded());
                  particle.setMinOccurs(0);
                  childModel.addParticle(particle);

                  if(childType.isMap())
                     bindMapProperty(property, (ClassInfo) childType, childName, (ModelGroupBinding) childTypeBinding.getParticle().getTerm());
                                   
                  DefaultElementInterceptor interceptor = new PropertyInterceptor(property, propertyType);
                  elementTypeBinding.pushInterceptor(childName, interceptor);
                  if (trace)
                     log.trace("Added interceptor " + childName + " for type=" + property.getBeanInfo().getName()
                           + " property=" + property.getName() + " interceptor=" + interceptor + " " + childType.getName());

                  beanAdapterFactory.addProperty(propertyQName, new NoopPropertyHandler(property, propertyType));

                  JBossXmlGroupWildcard groupWildcard = ((ClassInfo) propertyType)
                        .getUnderlyingAnnotation(JBossXmlGroupWildcard.class);

                  if (groupWildcard != null)
                  {
                     ChildWildcardHandler groupWildcardHandler;
                     if (groupWildcard.wrapper() != Object.class)
                     {
                        BeanInfo wrapperInfo = JBossXBBuilder.configuration.getBeanInfo(groupWildcard.wrapper());
                        groupWildcardHandler = new ChildWildcardHandler(property, wrapperInfo, groupWildcard.property());
                     }
                     else
                        groupWildcardHandler = new ChildWildcardHandler(property);
View Full Code Here

TOP

Related Classes of org.jboss.beans.info.spi.BeanInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.