public SingleWrappingClassInfoField(
      ClassOutlineImpl context, CPropertyInfo prop, CPropertyInfo core, CClassInfo classInfo) {
    super(context, prop, core);

    // assert prop instanceof CElementPropertyInfo;
    //
    // final CElementPropertyInfo elementPropertyInfo =
    // (CElementPropertyInfo) prop;
    //
    // assert elementPropertyInfo.getTypes().size() == 1;
    //
    // final CTypeRef typeRef = elementPropertyInfo.getTypes().get(0);

    this.classInfo = classInfo;
    this._class = classInfo.toType(context.parent(), Aspect.EXPOSED);
  }
Пример #2
0
  public Collection<CPropertyInfo> process(ProcessModel context, final CPropertyInfo propertyInfo) {

    assert propertyInfo instanceof CValuePropertyInfo;

    final CValuePropertyInfo wrappedPropertyInfo = (CValuePropertyInfo) propertyInfo;

    final CClassInfo classInfo = (CClassInfo) wrappedPropertyInfo.parent();

    final String propertyName = wrappedPropertyInfo.getName(true);

    logger.debug("Property [" + propertyName + "] is a simple homogeneous collection property.");

    final CClassInfoParent parent =
        Ring.get(BGMBuilder.class).getGlobalBinding().getFlattenClasses() == LocalScoping.NESTED
            ? classInfo
            : classInfo.parent();

    final CClassInfo itemClassInfo =
        new CClassInfo(
            classInfo.model,
            parent,
            classInfo.shortName + propertyName + "Item",
            null,
            new QName(propertyName),
            null,
            propertyInfo.getSchemaComponent(),
            new CCustomizations());

    Customizations.markGenerated(itemClassInfo);

    final CElementPropertyInfo itemPropertyInfo =
        new CElementPropertyInfo(
            "Item",
            CollectionMode.NOT_REPEATED,
            ID.NONE,
            wrappedPropertyInfo.getExpectedMimeType(),
            wrappedPropertyInfo.getSchemaComponent(),
            new CCustomizations(CustomizationUtils.getCustomizations(wrappedPropertyInfo)),
            wrappedPropertyInfo.getLocator(),
            false);

    final CTypeRef typeRef =
        new CTypeRef(
            context.getGetTypes().getTarget(context, wrappedPropertyInfo),
            new QName(propertyName),
            wrappedPropertyInfo.getSchemaType(),
            false,
            null);

    itemPropertyInfo.getTypes().add(typeRef);
    if (wrappedPropertyInfo.getAdapter() != null) {
      itemPropertyInfo.setAdapter(wrappedPropertyInfo.getAdapter());
    }

    final FieldRenderer fieldRenderer =
        new FieldRenderer() {
          public FieldOutline generate(ClassOutlineImpl classOutline, CPropertyInfo propertyInfo) {
            final FieldOutline fieldOutline =
                new SingleField(classOutline, propertyInfo) {
                  @Override
                  protected String getGetterMethod() {
                    return "get" + prop.getName(true);
                  }

                  protected JType getType(Aspect aspect) {
                    return super.getType(aspect).boxify();
                  }
                };

            final JClass itemClass =
                classOutline
                    .implClass
                    .owner()
                    .ref(Item.class)
                    .narrow(fieldOutline.getRawType().boxify());
            classOutline.implClass._implements(itemClass);
            if (classOutline.parent().getModel().serializable) {
              classOutline.implClass._implements(Serializable.class);
            }

            final JMethod isGetter = FieldAccessorUtils.getter(fieldOutline);

            if (isGetter.name().startsWith("is")) {
              final JMethod getter =
                  classOutline.implClass.method(
                      JMod.PUBLIC, isGetter.type(), "get" + isGetter.name().substring(2));

              getter.body()._return(JExpr._this().invoke(isGetter));
            }

            return fieldOutline;
          }
        };

    itemPropertyInfo.realization = fieldRenderer;
    itemClassInfo.addProperty(itemPropertyInfo);

    context.getProcessClassInfo().process(context, itemClassInfo);

    final CElementPropertyInfo wrappingPropertyInfo =
        new CElementPropertyInfo(
            propertyName + "Items",
            CollectionMode.REPEATED_ELEMENT,
            ID.NONE,
            wrappedPropertyInfo.getExpectedMimeType(),
            null,
            new CCustomizations(),
            null,
            false);

    //		for (final CTypeRef typeRef : wrappedPropertyInfo.getTypes()) {

    wrappingPropertyInfo
        .getTypes()
        .add(
            new CTypeRef(
                itemClassInfo,
                new QName(
                    typeRef.getTagName().getNamespaceURI(),
                    typeRef.getTagName().getLocalPart() + "Items"),
                null,
                false,
                null));
    //		}

    wrappingPropertyInfo.realization =
        new FieldRenderer() {
          public FieldOutline generate(
              ClassOutlineImpl outline, CPropertyInfo wrappingPropertyInfo) {
            return new WrappingCollectionField(outline, wrappedPropertyInfo, wrappingPropertyInfo);
          }
        };

    wrappedPropertyInfo.realization =
        new FieldRenderer() {
          public FieldOutline generate(
              ClassOutlineImpl outline, CPropertyInfo wrappedPropertyInfo) {
            return new WrappedCollectionField(outline, wrappedPropertyInfo, wrappingPropertyInfo);
          }
        };

    Customizations.markGenerated(wrappingPropertyInfo);
    Customizations.markIgnored(wrappedPropertyInfo);

    final List<CPropertyInfo> a = new ArrayList<CPropertyInfo>(1);
    a.add(wrappingPropertyInfo);
    a.add(itemPropertyInfo);
    return a;
  }