com.sun.tools.xjc.model.CElementPropertyInfo Java Examples

The following examples show how to use com.sun.tools.xjc.model.CElementPropertyInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CClassifyingVisitor.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public U onElement(CElementPropertyInfo elementPropertyInfo) {
	final Collection<? extends CTypeInfo> types = context.getGetTypes()
			.process(context, elementPropertyInfo);
	if (types.size() == 1) {
		final CTypeInfo type = types.iterator().next();
		if (type instanceof CBuiltinLeafInfo) {
			return onBuiltinElement(elementPropertyInfo);
		} else if (type instanceof CEnumLeafInfo) {
			return onEnumElement(elementPropertyInfo);
		} else if (type instanceof CArrayInfo) {
			return onArrayElement(elementPropertyInfo);
		} else if (type instanceof CClass) {
			return onClassElement(elementPropertyInfo);
		} else {
			throw new UnsupportedOperationException("Unexpected type.");
		}
	} else {
		return onHeteroElement(elementPropertyInfo);
	}
}
 
Example #2
Source File: AbstractAdaptPropertyInfo.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public CPropertyInfo createElementPropertyInfo(String propertyName,
		XSComponent source, TypeUse propertyType, QName propertyQName,
		CollectionMode collectionMode, CCustomizations customizations) {

	final CNonElement propertyTypeInfo = propertyType.getInfo();

	final CElementPropertyInfo propertyInfo = new CElementPropertyInfo(
			propertyName, collectionMode, propertyTypeInfo.idUse(),
			propertyTypeInfo.getExpectedMimeType(), source, customizations,
			null, true);

	final CTypeRef typeRef = new CTypeRef(propertyTypeInfo, propertyQName,
			propertyTypeInfo.getTypeName(), false, null);

	propertyInfo.setAdapter(propertyType.getAdapterUse());

	propertyInfo.getTypes().add(typeRef);
	return propertyInfo;
}
 
Example #3
Source File: SimplifyPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void simplifyElementPropertyInfoAsElementPropertyInfo(
		final Model model, final CClassInfo classInfo,
		CElementPropertyInfo property) {
	if (property.getTypes().size() > 1) {
		logger.debug(MessageFormat
				.format("Element property [{0}] has several types and will be simplified.",
						property.getName(false)));
		int index = classInfo.getProperties().indexOf(property);
		for (CTypeRef typeRef : property.getTypes()) {
			final CElementPropertyInfo elementPropertyInfo = createElementPropertyInfo(
					model, property, typeRef);
			classInfo.getProperties().add(index++, elementPropertyInfo);
		}
		classInfo.getProperties().remove(property);
	} else {
		logger.warn(MessageFormat
				.format("Element property [{0}] will not be simplified as it does not contain multiple types.",
						property.getName(false)));
	}
}
 
Example #4
Source File: JaxbValidationsPlugins.java    From krasa-jaxb-tools with Apache License 2.0 6 votes vote down vote up
public boolean run(Outline model, Options opt, ErrorHandler errorHandler) {
	try {
		for (ClassOutline co : model.getClasses()) {
			List<CPropertyInfo> properties = co.target.getProperties();
			for (CPropertyInfo property : properties) {
				if (property instanceof CElementPropertyInfo) {
					processElement((CElementPropertyInfo) property, co, model);
				} else if (property instanceof CAttributePropertyInfo) {
					processAttribute((CAttributePropertyInfo) property, co, model);
				} else if (property instanceof CValuePropertyInfo) {
					processAttribute((CValuePropertyInfo) property, co, model);
				}
			}
		}
		return true;
	} catch (Exception e) {
		log(e);
		return false;
	}
}
 
Example #5
Source File: SimplifyPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private CElementPropertyInfo createElementPropertyInfo(final Model model,
		CElementPropertyInfo property, CTypeRef typeRef) {
	final String propertyName = createPropertyName(model, property, typeRef);
	boolean required = false;
	final CElementPropertyInfo elementPropertyInfo = new CElementPropertyInfo(
			propertyName,
			property.isCollection() ? CollectionMode.REPEATED_ELEMENT
					: CollectionMode.NOT_REPEATED, typeRef.getTarget()
					.idUse(), typeRef.getTarget().getExpectedMimeType(),
			property.getSchemaComponent(), property.getCustomizations(),
			property.getLocator(), required);
	final CAdapter adapter = property.getAdapter();
	if (adapter != null) {
		elementPropertyInfo.setAdapter(adapter);
	}
	elementPropertyInfo.getTypes().add(typeRef);
	return elementPropertyInfo;
}
 
Example #6
Source File: AbstractField.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate( JAnnotatable field ) {

    assert(field!=null);

    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }

    outline.parent().generateAdapterIfNecessary(prop,field);
}
 
Example #7
Source File: SingleWrappingReferenceField.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected JClass getDeclaredType() {

		final CElementPropertyInfo property = getElementInfo().getProperty();

		if (property.getAdapter() == null) {
			@SuppressWarnings("unused")
			final CNonElement type = property.ref().iterator().next();
			final JClass declaredType = (JClass) getType().toType(
					outline.parent(), Aspect.EXPOSED);
			return declaredType;
		}
		else
		{
			return (JClass) property.getAdapter().customType.toType(outline.parent(), Aspect.EXPOSED);
			
		}
	}
 
Example #8
Source File: XJCCMElementTypeRefOrigin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public XJCCMElementTypeRefOrigin(CElementPropertyInfo source,
		CTypeRef typeRef) {
	super(source, typeRef);
	final XSComponent schemaComponent = source.getSchemaComponent();
	if (schemaComponent != null) {
		final FindXSElementDeclVisitor visitor = new FindXSElementDeclVisitor(
				typeRef.getTagName());
		schemaComponent.visit(visitor);
		this.component = visitor.getElementDecl();
	} else {
		this.component = null;
	}
}
 
Example #9
Source File: SchemaAnnotationUtils.java    From jaxb2-rich-contract-plugin with MIT License 5 votes vote down vote up
public static String getFieldAnnotationDescription(CPropertyInfo propertyInfo) {
    XSAnnotation annotation = resolveXSAnnotation(propertyInfo.getSchemaComponent());
    String annotationText = resolveDescription(annotation);

    // if there is no annotation on the element itself then see if there is an annotation for the type
    // of that element (e.g. its anonymous or named type)

    //<xs:element name="SomeElement">
    //   <xs:annotation>
    //      <xs:documentation>This is the annotation for the element so will be considered first.</xs:documentation>
    //   </xs:annotation>
    //   <xs:complexType>
    //      <xs:annotation>
    //         <xs:documentation>This is the annotation for the type so will be considered second</xs:documentation>
    //      </xs:annotation>
    if (annotationText.isEmpty()) {
        if (propertyInfo instanceof CElementPropertyInfo) {
            CElementPropertyInfo elementPropertyInfo = (CElementPropertyInfo) propertyInfo;
            if (elementPropertyInfo.getTypes() != null && !elementPropertyInfo.getTypes().isEmpty()) {
                CNonElement target = elementPropertyInfo.getTypes().get(0).getTarget();
                if (target instanceof CClassInfo) {
                    annotationText = getClassAnnotationDescription((CClassInfo) target);
                }
            }
        }
    }
    return annotationText;
}
 
Example #10
Source File: SimplifyPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void postProcessElementPropertyInfo(final Model model,
		final CClassInfo classInfo, CElementPropertyInfo property) {
	if (CustomizationUtils
			.containsPropertyCustomizationInPropertyOrClass(
					property,
					org.jvnet.jaxb2_commons.plugin.simplify.Customizations.PROPERTY_ELEMENT_NAME,
					org.jvnet.jaxb2_commons.plugin.simplify.Customizations.AS_ELEMENT_PROPERTY_ELEMENT_NAME)) {
		simplifyElementPropertyInfoAsElementPropertyInfo(model, classInfo,
				property);
	}
}
 
Example #11
Source File: SimplifyPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void postProcessClassInfo(final Model model,
		final CClassInfo classInfo) {
	final List<CPropertyInfo> properties = new ArrayList<CPropertyInfo>(
			classInfo.getProperties());
	for (CPropertyInfo property : properties) {
		property.accept(new CPropertyVisitor<Void>() {

			public Void onElement(CElementPropertyInfo elementProperty) {
				postProcessElementPropertyInfo(model, classInfo,
						elementProperty);
				return null;
			}

			public Void onAttribute(CAttributePropertyInfo attributeProperty) {
				// TODO Auto-generated method stub
				return null;
			}

			public Void onValue(CValuePropertyInfo valueProperty) {
				// TODO Auto-generated method stub
				return null;
			}

			public Void onReference(CReferencePropertyInfo p) {
				postProcessReferencePropertyInfo(model, classInfo, p);
				return null;
			}

		});
	}
}
 
Example #12
Source File: JaxbValidationsPlugins.java    From krasa-jaxb-tools with Apache License 2.0 5 votes vote down vote up
private void processElement(CElementPropertyInfo property, ClassOutline clase, JFieldVar var, ElementDecl element) {
	String propertyName = propertyName(property);
	String className = clase.implClass.name();
	XSType elementType = element.getType();

	validAnnotation(elementType, var, propertyName, className);

	if (elementType instanceof XSSimpleType) {
		processType((XSSimpleType) elementType, var, propertyName, className);
	} else if (elementType.getBaseType() instanceof XSSimpleType) {
		processType((XSSimpleType) elementType.getBaseType(), var, propertyName, className);
	}
}
 
Example #13
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onCollectionEnumElement(
		CElementPropertyInfo elementPropertyInfo) {
	return context.getWrapCollectionEnumElement().process(context,
			elementPropertyInfo);
}
 
Example #14
Source File: WrapSingleHeteroElement.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected Collection<CPropertyInfo> createTypeProperties(
		final ProcessModel context, final CElementPropertyInfo propertyInfo) {

	final Collection<? extends CTypeRef> types = context.getGetTypes().getTypes(context, propertyInfo);
	// Set<CElement> elements = propertyInfo.getElements();

	final Collection<CPropertyInfo> properties = new ArrayList<CPropertyInfo>(
			types.size());

	for (final CTypeRef type : types) {
		final CElementPropertyInfo itemPropertyInfo = new CElementPropertyInfo(
				propertyInfo.getName(true)
						+ ((CClassInfo) propertyInfo.parent()).model
								.getNameConverter().toPropertyName(
										type.getTagName().getLocalPart()),
				CollectionMode.NOT_REPEATED, ID.NONE, propertyInfo
						.getExpectedMimeType(), propertyInfo
						.getSchemaComponent(),
				new CCustomizations(CustomizationUtils
						.getCustomizations(propertyInfo)), propertyInfo
						.getLocator(), false);

		itemPropertyInfo.getTypes().add(type);

		itemPropertyInfo.realization = new FieldRenderer() {
			public FieldOutline generate(ClassOutlineImpl classOutline,
					CPropertyInfo p) {
				final SingleWrappingElementField field = new SingleWrappingElementField(
						classOutline, p, propertyInfo, type);
				field.generateAccessors();
				return field;
			}
		};

		Customizations.markGenerated(itemPropertyInfo);
		properties.add(itemPropertyInfo);

		Collection<CPropertyInfo> newProperties = context
				.getProcessPropertyInfos().process(context,
						itemPropertyInfo);
		if (newProperties != null) {
			properties.addAll(newProperties);
		}

	}

	return properties;
}
 
Example #15
Source File: DefaultGetTypes.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<? extends CTypeRef> getTypes(C context,
		CElementPropertyInfo propertyInfo) {
	return propertyInfo.getTypes();
}
 
Example #16
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onSingleBuiltinElement(
		CElementPropertyInfo elementPropertyInfo) {
	return context.getWrapSingleBuiltinElement().process(context,
			elementPropertyInfo);
}
 
Example #17
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onSingleEnumElement(
		CElementPropertyInfo elementPropertyInfo) {
	return context.getWrapSingleEnumElement().process(context,
			elementPropertyInfo);
}
 
Example #18
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onSingleArrayElement(
		CElementPropertyInfo elementPropertyInfo) {
	throw new UnsupportedOperationException("Arrays are not supported.");
}
 
Example #19
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onSingleClassElement(
		CElementPropertyInfo elementPropertyInfo) {
	return Collections.emptyList();
}
 
Example #20
Source File: JaxbValidationsPlugins.java    From krasa-jaxb-tools with Apache License 2.0 4 votes vote down vote up
private String propertyName(CElementPropertyInfo property) {
	return property.getName(false);
}
 
Example #21
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onSingleHeteroElement(
		CElementPropertyInfo elementPropertyInfo) {
	return context.getWrapSingleHeteroElement().process(context,
			elementPropertyInfo);
}
 
Example #22
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onCollectionBuiltinElement(
		CElementPropertyInfo elementPropertyInfo) {
	return context.getWrapCollectionBuiltinElement().process(context,
			elementPropertyInfo);
}
 
Example #23
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onCollectionArrayElement(
		CElementPropertyInfo elementPropertyInfo) {
	throw new UnsupportedOperationException("Arrays are not supported.");
}
 
Example #24
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onCollectionClassElement(
		CElementPropertyInfo elementPropertyInfo) {
	return Collections.emptyList();
}
 
Example #25
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onCollectionHeteroElement(
		CElementPropertyInfo elementPropertyInfo) {
	return context.getWrapCollectionHeteroElement().process(context,
			elementPropertyInfo);
}
 
Example #26
Source File: GetTypes.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<? extends CTypeRef> getTypes(C context,
CElementPropertyInfo propertyInfo);
 
Example #27
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected MElementTypeRefOrigin createElementTypeRefOrigin(
		CElementPropertyInfo ep, CTypeRef typeRef) {
	return new XJCCMElementTypeRefOrigin(ep, typeRef);
}
 
Example #28
Source File: JaxbValidationsPlugins.java    From krasa-jaxb-tools with Apache License 2.0 4 votes vote down vote up
/**
 * XS:Element
 */
public void processElement(CElementPropertyInfo property, ClassOutline classOutline, Outline model) {
	XSComponent schemaComponent = property.getSchemaComponent();
	ParticleImpl particle = (ParticleImpl) schemaComponent;
	// must be reflection because of cxf-codegen
	int maxOccurs = toInt(Utils.getField("maxOccurs", particle));
	int minOccurs = toInt(Utils.getField("minOccurs", particle));
	boolean nillable = toBoolean(Utils.getField("nillable",particle.getTerm())); 
	JFieldVar field = classOutline.implClass.fields().get(propertyName(property));

	// workaround for choices
	boolean required = property.isRequired();
	if (minOccurs < 0 || minOccurs >= 1 && required && !nillable) {
		if (!hasAnnotation(field, NotNull.class)) {
			processNotNull(classOutline, field);
		}
	}
	if (maxOccurs > 1) {
		if (!hasAnnotation(field, Size.class)) {
			log("@Size (" + minOccurs + "," + maxOccurs + ") " + propertyName(property)
					+ " added to class " + classOutline.implClass.name());

			field.annotate(Size.class).param("min", minOccurs).param("max", maxOccurs);
		}
	}
	if (maxOccurs == -1 && minOccurs > 0) { // maxOccurs="unbounded"
		if (!hasAnnotation(field, Size.class)) {
			log("@Size (" + minOccurs + ") " + propertyName(property) + " added to class "
					+ classOutline.implClass.name());
			field.annotate(Size.class).param("min", minOccurs);
		}
	}

	XSTerm term = particle.getTerm();
	if (term instanceof ElementDecl) {
		processElement(property, classOutline, field, (ElementDecl) term);
	} else if (term instanceof DelayedRef.Element) {
		XSElementDecl xsElementDecl = ((DelayedRef.Element) term).get();
		processElement(property, classOutline, field, (ElementDecl) xsElementDecl);
	}

}
 
Example #29
Source File: CClassifyingVisitor.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public U onHeteroElement(CElementPropertyInfo elementPropertyInfo) {
	return !elementPropertyInfo.isCollection() ? classifier
			.onSingleHeteroElement(elementPropertyInfo) : classifier
			.onCollectionHeteroElement(elementPropertyInfo);
}
 
Example #30
Source File: SimplifyPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void simplifyReferencePropertyInfoAsElementPropertyInfo(
		final Model model, final CClassInfo classInfo,
		CReferencePropertyInfo property) {

	if (property.getElements().size() <= 1 && !property.isMixed()) {
		logger.warn(MessageFormat
				.format("Element reference property [{0}] will not be simplified as it does not contain multiple elements and is not mixed.",
						property.getName(false)));
	} else {
		logger.debug(MessageFormat
				.format("Element reference property [{0}] contains multiple elements or is mixed and will be simplified.",
						property.getName(false)));
		int index = classInfo.getProperties().indexOf(property);
		for (CElement element : property.getElements()) {
			final CElementPropertyInfo elementPropertyInfo;
			if (element instanceof CElementInfo) {
				elementPropertyInfo = createElementPropertyInfo(model,
						property, element, (CElementInfo) element);
			} else if (element instanceof CClassInfo) {
				elementPropertyInfo = createElementPropertyInfo(model,
						property, element, (CClassInfo) element);

			} else if (element instanceof CClassRef) {
				logger.error(MessageFormat
						.format("Element reference property [{0}] contains a class reference type [{1}] and therefore cannot be fully simplified as element property.",
								property.getName(false),
								((CClassRef) element).fullName()));
				elementPropertyInfo = null;
				// createElementPropertyInfo(model,
				// property, element, (CClassRef) element);
			} else {
				// TODO WARN
				elementPropertyInfo = null;
				logger.error(MessageFormat.format(
						"Unsupported CElement type [{0}].", element));
			}
			if (elementPropertyInfo != null) {
				classInfo.getProperties().add(index++, elementPropertyInfo);
			}
		}
		if (property.isMixed()) {
			classInfo.getProperties().add(index++,
					createContentReferencePropertyInfo(model, property));
		}
		classInfo.getProperties().remove(property);
	}
}