/* 365 */ return o;
/* */ }
/* */
/* */ private Object startElement(Object parent, QName elementName, ParticleBinding particle)
/* */ {
/* 372 */ TermBinding term = particle.getTerm();
/* 373 */ if (term.isSkip())
/* */ {
/* 375 */ return parent;
/* */ }
/* */
/* 378 */ boolean trace = log.isTraceEnabled();
/* 379 */ if (trace)
/* */ {
/* 381 */ log.trace("startElement " + elementName + " parent=" + parent + " term=" + term);
/* */ }
/* */
/* 384 */ ClassMetaData classMetaData = term.getClassMetaData();
/* 385 */ MapEntryMetaData mapEntryMetaData = term.getMapEntryMetaData();
/* */
/* 387 */ if (!term.isModelGroup())
/* */ {
/* 389 */ TypeBinding type = ((ElementBinding)term).getType();
/* 390 */ if ((type.isSimple()) || ((classMetaData == null) && (mapEntryMetaData == null) && ((!type.isStartElementCreatesObject()) || (Constants.QNAME_ANYTYPE.equals(type.getQName())))))
/* */ {
/* 395 */ if (trace)
/* */ {
/* 397 */ log.trace("startElement " + elementName + " does not create an object");
/* */ }
/* 399 */ return null;
/* */ }
/* */
/* */ }
/* */
/* 405 */ ElementBinding arrayItem = null;
/* 406 */ if (!term.isModelGroup())
/* */ {
/* 408 */ TypeBinding type = ((ElementBinding)term).getType();
/* 409 */ if (type.getAttributes().isEmpty())
/* */ {
/* 411 */ ParticleBinding typeParticle = type.getParticle();
/* 412 */ ModelGroupBinding modelGroup = (ModelGroupBinding)(typeParticle == null ? null : typeParticle.getTerm());
/* 413 */ arrayItem = modelGroup == null ? null : modelGroup.getArrayItem();
/* */
/* 416 */ if ((arrayItem != null) && ((arrayItem.isSkip()) || (arrayItem.getMapEntryMetaData() != null) || (arrayItem.getPutMethodMetaData() != null) || (arrayItem.getAddMethodMetaData() != null)))
/* */ {
/* 423 */ arrayItem = null;
/* */ }
/* */ }
/* */ }
/* */
/* 428 */ if (arrayItem != null)
/* */ {
/* 430 */ Class wrapperType = null;
/* 431 */ if (classMetaData != null)
/* */ {
/* 433 */ wrapperType = loadClassForTerm(classMetaData.getImpl(), term.getSchema().isIgnoreUnresolvedFieldOrClass(), elementName);
/* */
/* 438 */ if ((GenericValueContainer.class.isAssignableFrom(wrapperType)) || (Collection.class.isAssignableFrom(wrapperType)) || (Map.class.isAssignableFrom(wrapperType)))
/* */ {
/* 442 */ return newInstance(wrapperType, elementName, term.getSchema().isUseNoArgCtorIfFound());
/* */ }
/* */ }
/* */
/* 446 */ if ((wrapperType == null) && (parent == null))
/* */ {
/* 448 */ Class itemType = classForElement(arrayItem, null);
/* 449 */ if (itemType != null)
/* */ {
/* 451 */ if (trace)
/* */ {
/* 453 */ log.trace("startElement " + elementName + " new array " + itemType.getName());
/* */ }
/* 455 */ return GenericValueContainer.FACTORY.array(itemType);
/* */ }
/* */ }
/* */ else
/* */ {
/* 460 */ PropertyMetaData propertyMetaData = wrapperType == null ? term.getPropertyMetaData() : arrayItem.getPropertyMetaData();
/* */ String propName;
/* */ String propName;
/* 464 */ if (propertyMetaData == null)
/* */ {
/* 466 */ propName = Util.xmlNameToFieldName(wrapperType == null ? elementName.getLocalPart() : arrayItem.getQName().getLocalPart(), term.getSchema().isIgnoreLowLine());
/* */ }
/* */ else
/* */ {
/* 473 */ propName = propertyMetaData.getName();
/* */ }
/* */
/* 476 */ if (trace)
/* */ {
/* 478 */ log.trace("startElement " + elementName + " property=" + propName + " wrapper=" + wrapperType);
/* */ }
/* */
/* 481 */ Class parentClass = wrapperType;
/* 482 */ if (wrapperType == null)
/* */ {
/* 484 */ if ((parent instanceof GenericValueContainer))
/* */ {
/* 486 */ parentClass = ((GenericValueContainer)parent).getTargetClass();
/* */ }
/* 488 */ else if ((parent instanceof ValueList))
/* */ {
/* 490 */ parentClass = ((ValueList)parent).getTargetClass();
/* */ }
/* */ else
/* */ {
/* 494 */ parentClass = parent.getClass();
/* */ }
/* */ }
/* */
/* 498 */ Class fieldType = null;
/* 499 */ if (parentClass.isArray())
/* */ {
/* 501 */ fieldType = parentClass.getComponentType();
/* */ }
/* */ else
/* */ {
/* 509 */ FieldInfo fieldInfo = FieldInfo.getFieldInfo(parentClass, propName, false);
/* 510 */ if (fieldInfo != null)
/* */ {
/* 512 */ fieldType = fieldInfo.getType();
/* 513 */ if ((particle.isRepeatable()) && (fieldType.isArray()))
/* */ {
/* 515 */ fieldType = fieldType.getComponentType();
/* */ }
/* */ }
/* 518 */ else if ((((ElementBinding)term).getType().getInterceptors(arrayItem.getQName()).isEmpty()) && (arrayItem.getInterceptors().isEmpty()))
/* */ {
/* 521 */ QName typeName = ((ElementBinding)term).getType().getQName();
/* 522 */ throw new JBossXBRuntimeException("Couldn't apply 'array wrapper' pattern for element " + elementName + " of type " + (typeName == null ? "anonymous" : typeName.toString()) + ": failed to resolve property " + propName + " and no interceptors applied to override handler.setParent(...)");
/* */ }
/* */
/* */ }
/* */
/* 531 */ if (fieldType != null)
/* */ {
/* 534 */ if (fieldType.isArray())
/* */ {
/* 536 */ return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType.getComponentType());
/* */ }
/* 538 */ if (Collection.class.isAssignableFrom(fieldType))
/* */ {
/* 540 */ if (wrapperType == null)
/* */ {
/* 542 */ return new ValueListInitializer().newValueList(ValueListHandler.FACTORY.child(), Collection.class);
/* */ }
/* */
/* */ }
/* */ else
/* */ {
/* 548 */ return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType);
/* */ }
/* */ }
/* */ }
/* */ }
/* */
/* 554 */ Object o = null;
/* 555 */ if (mapEntryMetaData != null)
/* */ {
/* 557 */ if (mapEntryMetaData.getImpl() != null)
/* */ {
/* 559 */ Class cls = loadClassForTerm(mapEntryMetaData.getImpl(), term.getSchema().isIgnoreUnresolvedFieldOrClass(), elementName);
/* */
/* 561 */ if (trace)
/* */ {
/* 563 */ log.trace("startElement " + elementName + " new map entry " + cls.getName());
/* */ }
/* */
/* 566 */ o = newInstance(cls, elementName, term.getSchema().isUseNoArgCtorIfFound());
/* */ }
/* */ else
/* */ {
/* 570 */ o = new MapEntry();
/* 571 */ if (trace)
/* */ {
/* 573 */ log.trace("startElement " + elementName + " new map entry");
/* */ }
/* */ }
/* */
/* 577 */ if ((mapEntryMetaData.isNonNullValue()) && (mapEntryMetaData.getValueType() != null))
/* */ {
/* */ Class mapValueType;
/* */ try {
/* 582 */ mapValueType = Thread.currentThread().getContextClassLoader().loadClass(mapEntryMetaData.getValueType());
/* */ }
/* */ catch (ClassNotFoundException e)
/* */ {
/* 586 */ throw new JBossXBRuntimeException("startElement failed for " + elementName + ": failed to load class " + mapEntryMetaData.getValueType() + " for map entry value.");
/* */ }
/* */
/* */ Object value;
/* */ try
/* */ {
/* 593 */ if (trace)
/* */ {
/* 595 */ log.trace("startElement " + elementName + " map value type " + mapEntryMetaData.getValueType());
/* */ }
/* 597 */ value = mapValueType.newInstance();
/* */ }
/* */ catch (Exception e)
/* */ {
/* 601 */ throw new JBossXBRuntimeException("startElement failed for " + elementName + ": failed to create an instance of " + mapValueType + " for map entry value.");
/* */ }
/* */
/* 605 */ if ((o instanceof MapEntry))
/* */ {
/* 607 */ ((MapEntry)o).setValue(value);
/* */ }
/* */ else
/* */ {
/* 611 */ String getValueMethodName = mapEntryMetaData.getGetValueMethod();
/* 612 */ if (getValueMethodName == null)
/* */ {
/* 614 */ getValueMethodName = "getValue";
/* */ }
/* */
/* 617 */ String setValueMethodName = mapEntryMetaData.getSetValueMethod();
/* 618 */ if (setValueMethodName == null)
/* */ {
/* 620 */ setValueMethodName = "setValue";
/* */ }
/* */ Method getValueMethod;
/* */ try
/* */ {
/* 626 */ getValueMethod = o.getClass().getMethod(getValueMethodName, null);
/* */ }
/* */ catch (NoSuchMethodException e)
/* */ {
/* 630 */ throw new JBossXBRuntimeException("getValueMethod=" + getValueMethodName + " is not found in map entry " + o.getClass());
/* */ }
/* */
/* */ Method setValueMethod;
/* */ try
/* */ {
/* 637 */ setValueMethod = o.getClass().getMethod(setValueMethodName, new Class[] { getValueMethod.getReturnType() });
/* */ }
/* */ catch (NoSuchMethodException e)
/* */ {
/* 641 */ throw new JBossXBRuntimeException("setValueMethod=" + setValueMethodName + "(" + getValueMethod.getReturnType().getName() + " value) is not found in map entry " + o.getClass());
/* */ }
/* */
/* */ try
/* */ {
/* 648 */ setValueMethod.invoke(o, new Object[] { value });
/* */ }
/* */ catch (Exception e)
/* */ {
/* 653 */ throw new JBossXBRuntimeException("setValueMethod=" + setValueMethodName + " failed: owner=" + o + ", value=" + value + ", msg=" + e.getMessage(), e);
/* */ }
/* */
/* */ }
/* */
/* */ }
/* */
/* */ }
/* */ else
/* */ {
/* 663 */ Class parentClass = null;
/* 664 */ if (parent != null)
/* */ {
/* 666 */ if ((parent instanceof GenericValueContainer))
/* */ {
/* 668 */ parentClass = ((GenericValueContainer)parent).getTargetClass();
/* */ }
/* 670 */ else if ((parent instanceof ValueList))
/* */ {
/* 672 */ parentClass = ((ValueList)parent).getTargetClass();
/* */ }
/* */ else
/* */ {
/* 676 */ parentClass = parent.getClass();
/* */ }
/* */ }
/* */ Class cls;
/* */ Class cls;
/* 681 */ if (term.isModelGroup())
/* */ {
/* 683 */ if (classMetaData == null)
/* */ {
/* 685 */ throw new JBossXBRuntimeException("Model groups should be annotated with 'class' annotation to be bound.");
/* */ }
/* */
/* 688 */ cls = loadClassForTerm(classMetaData.getImpl(), term.getSchema().isIgnoreUnresolvedFieldOrClass(), elementName);
/* */ }
/* */ else
/* */ {
/* 692 */ ElementBinding element = (ElementBinding)term;
/* 693 */ cls = classForNonArrayItem(element, parentClass);
/* 694 */ if (cls != null)
/* */ {
/* 697 */ TypeBinding simpleType = element.getType().getSimpleType();
/* 698 */ if (simpleType != null)
/* */ {
/* 700 */ Class simpleCls = classForSimpleType(simpleType, element.isNillable());
/* 701 */ if ((cls.equals(simpleCls)) || ((cls.isPrimitive()) && (Classes.getPrimitiveWrapper(cls) == simpleCls)) || ((simpleCls.isPrimitive()) && (Classes.getPrimitiveWrapper(simpleCls) == cls)))
/* */ {
/* 704 */ cls = null;
/* */ }
/* */ }
/* */ }
/* */ }
/* */
/* 710 */ if (cls != null)
/* */ {
/* */ boolean noArgCtor;
/* */ boolean noArgCtor;
/* 713 */ if (classMetaData == null)
/* */ {
/* 715 */ noArgCtor = term.getSchema().isUseNoArgCtorIfFound();
/* */ }
/* */ else
/* */ {
/* 719 */ Boolean termUsesNoArgCtor = classMetaData.isUseNoArgCtor();
/* 720 */ noArgCtor = termUsesNoArgCtor == null ? term.getSchema().isUseNoArgCtorIfFound() : termUsesNoArgCtor.booleanValue();
/* */ }
/* */
/* 724 */ if (trace)
/* */ {
/* 726 */ log.trace("startElement " + elementName + " new " + cls.getName() + ", noArgCtor=" + noArgCtor);