Java Code Examples for com.sun.tools.xjc.outline.FieldOutline#getPropertyInfo()

The following examples show how to use com.sun.tools.xjc.outline.FieldOutline#getPropertyInfo() . 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: FieldUtils.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Set<JType> getPossibleTypes(FieldOutline fieldOutline,
		Aspect aspect) {
	Validate.notNull(fieldOutline);
	final ClassOutline classOutline = fieldOutline.parent();
	final Outline outline = classOutline.parent();
	final CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo();

	final Set<JType> types = new HashSet<JType>();

	if (propertyInfo.getAdapter() != null) {
		types.add(propertyInfo.getAdapter().customType.toType(fieldOutline
				.parent().parent(), aspect));
	} else if (propertyInfo.baseType != null) {
		types.add(propertyInfo.baseType);
	} else {
		Collection<? extends CTypeInfo> typeInfos = propertyInfo.ref();
		for (CTypeInfo typeInfo : typeInfos) {
			types.addAll(getPossibleTypes(outline, aspect, typeInfo));
		}
	}
	return types;
}
 
Example 2
Source File: EmbeddedAssociationMappingWrapper.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Collection<FieldOutline> getIdFieldsOutline(
		final ClassOutline classOutline) {
	final Collection<FieldOutline> idFieldOutlines = new ArrayList<FieldOutline>();
	ClassOutline current = classOutline;

	while (current != null) {
		for (FieldOutline idFieldOutline : current.getDeclaredFields()) {
			final CPropertyInfo propertyInfo = idFieldOutline
					.getPropertyInfo();
			if ((CustomizationUtils.containsCustomization(propertyInfo,
					Customizations.ID_ELEMENT_NAME) || CustomizationUtils
					.containsCustomization(propertyInfo,
							Customizations.EMBEDDED_ID_ELEMENT_NAME))
					&& !CustomizationUtils.containsCustomization(
							propertyInfo,
							Customizations.IGNORED_ELEMENT_NAME)) {
				idFieldOutlines.add(idFieldOutline);
			}
		}
		current = current.getSuperClass();
	}

	return idFieldOutlines;
}
 
Example 3
Source File: DefaultAssociationMapping.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Collection<FieldOutline> getIdFieldsOutline(
		final ClassOutline classOutline) {
	final Collection<FieldOutline> idFieldOutlines = new ArrayList<FieldOutline>();
	ClassOutline current = classOutline;

	while (current != null) {
		for (FieldOutline idFieldOutline : current.getDeclaredFields()) {
			final CPropertyInfo propertyInfo = idFieldOutline
					.getPropertyInfo();
			if ((CustomizationUtils.containsCustomization(propertyInfo,
					Customizations.ID_ELEMENT_NAME) || CustomizationUtils
					.containsCustomization(propertyInfo,
							Customizations.EMBEDDED_ID_ELEMENT_NAME))
					&& !CustomizationUtils.containsCustomization(
							propertyInfo,
							Customizations.IGNORED_ELEMENT_NAME)) {
				idFieldOutlines.add(idFieldOutline);
			}
		}
		current = current.getSuperClass();
	}

	return idFieldOutlines;
}
 
Example 4
Source File: AttributesMapping.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public boolean isFieldOutlineEnumerated(Mapping context,
		FieldOutline fieldOutline) {
	final CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo();

	final Collection<? extends CTypeInfo> types = context.getGetTypes()
			.process(context, propertyInfo);

	if (types.size() == 1) {

		final CTypeInfo type = types.iterator().next();

		return type instanceof CEnumLeafInfo;
	} else {
		return false;
	}
}
 
Example 5
Source File: PMMLPlugin.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
static
private FieldOutline getExtensionsField(ClassOutline classOutline){
	Predicate<FieldOutline> predicate = new Predicate<FieldOutline>(){

		@Override
		public boolean test(FieldOutline fieldOutline){
			CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo();

			if(("extensions").equals(propertyInfo.getName(false)) && propertyInfo.isCollection()){
				JType elementType = CodeModelUtil.getElementType(fieldOutline.getRawType());

				return checkType(elementType, "org.dmg.pmml.Extension");
			}

			return false;
		}
	};

	return XJCUtil.findSingletonField(classOutline.getDeclaredFields(), predicate);
}
 
Example 6
Source File: EmbeddableAttributesMapping.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean isFieldOutlineEnumerated(Mapping context,
		FieldOutline fieldOutline) {
	final CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo();

	final Collection<? extends CTypeInfo> types = context.getGetTypes()
			.process(context, propertyInfo);
	if (types.size() == 1) {

		final CTypeInfo type = types.iterator().next();

		return type instanceof CEnumLeafInfo;
	} else {
		return false;
	}
}
 
Example 7
Source File: AttributesMapping.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CTypeInfo getCommonBaseTypeInfo(Mapping context,
		FieldOutline fieldOutline) {
	final CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo();

	final Collection<? extends CTypeInfo> types = context.getGetTypes()
			.process(context, propertyInfo);

	return CTypeInfoUtils.getCommonBaseTypeInfo(types);
}
 
Example 8
Source File: ClassDiscoverer.java    From jaxb-visitor with Apache License 2.0 5 votes vote down vote up
/**
 * Finds all external class references
 * @param outline root of the generated code
 * @param classes set of generated classes
 * @return set of external classes
 * @throws IllegalAccessException throw if there's an error introspecting the annotations
 */
static Set<JClass> discoverDirectClasses(Outline outline, Set<ClassOutline> classes) throws IllegalAccessException {

    Set<String> directClassNames = new LinkedHashSet<>();
    for(ClassOutline classOutline : classes) {
        // for each field, if it's a bean, then visit it
        List<FieldOutline> fields = findAllDeclaredAndInheritedFields(classOutline);
        for(FieldOutline fieldOutline : fields) {
            JType rawType = fieldOutline.getRawType();
            CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo();
            boolean isCollection = propertyInfo.isCollection();
            if (isCollection) {
                JClass collClazz = (JClass) rawType;
                JClass collType = collClazz.getTypeParameters().get(0);
                addIfDirectClass(directClassNames, collType);
            } else {
                addIfDirectClass(directClassNames, rawType);
            }
            parseXmlAnnotations(outline, fieldOutline, directClassNames);
        }
    }

    Set<JClass> direct = directClassNames
            .stream()
            .map(cn -> outline.getCodeModel().directClass(cn))
            .collect(Collectors.toCollection(LinkedHashSet::new));

    return direct;

}
 
Example 9
Source File: AnnotatePlugin.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean run(Outline outline, Options options, ErrorHandler errorHandler){
	JCodeModel codeModel = outline.getCodeModel();

	Collection<? extends ClassOutline> classOutlines = outline.getClasses();
	for(ClassOutline classOutline : classOutlines){
		JDefinedClass beanClazz = classOutline.implClass;

		CPluginCustomization classCustomization = CustomizationUtils.findCustomization(classOutline, AnnotatePlugin.ANNOTATE_CLASS_QNAME);
		if(classCustomization != null){
			annotate(codeModel, beanClazz, classCustomization);
		}

		Map<String, JFieldVar> fieldVars = beanClazz.fields();

		FieldOutline[] fieldOutlines = classOutline.getDeclaredFields();
		for(FieldOutline fieldOutline : fieldOutlines){
			CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo();

			List<CPluginCustomization> propertyCustomizations = CustomizationUtils.findPropertyCustomizationsInProperty(propertyInfo, AnnotatePlugin.ANNOTATE_PROPERTY_QNAME);
			for(CPluginCustomization propertyCustomization : propertyCustomizations){
				JFieldVar fieldVar = fieldVars.get(propertyInfo.getName(false));

				annotate(codeModel, fieldVar, propertyCustomization);
			}
		}
	}

	Collection<? extends EnumOutline> enumOutlines = outline.getEnums();
	for(EnumOutline enumOutline : enumOutlines){
		JDefinedClass clazz = enumOutline.clazz;

		CPluginCustomization enumCustomization = CustomizationUtils.findCustomization(enumOutline, AnnotatePlugin.ANNOTATE_ENUM_QNAME);
		if(enumCustomization != null){
			annotate(codeModel, clazz, enumCustomization);
		}

		List<EnumConstantOutline> enumConstantOutlines = enumOutline.constants;
		for(EnumConstantOutline enumConstantOutline : enumConstantOutlines){
			CCustomizations enumConstantCustomizations = enumConstantOutline.target.getCustomizations();

			for(CPluginCustomization enumConstantCustomization : enumConstantCustomizations){
				Element element = enumConstantCustomization.element;

				if((AnnotatePlugin.ANNOTATE_ENUM_CONSTANT_QNAME.getNamespaceURI()).equals(element.getNamespaceURI()) && (AnnotatePlugin.ANNOTATE_ENUM_CONSTANT_QNAME.getLocalPart()).equals(element.getLocalName())){
					annotate(codeModel, enumConstantOutline.constRef, enumConstantCustomization);

					enumConstantCustomization.markAsAcknowledged();
				}
			}
		}
	}

	return true;
}