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

The following examples show how to use com.sun.tools.xjc.model.CAttributePropertyInfo. 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: ClassModelBuilder.java    From mxjc with MIT License 6 votes vote down vote up
private static AttributeAnnotation getAttributeAnnotation(ClassOutline parent, CPropertyInfo prop) {
    CAttributePropertyInfo ap = (CAttributePropertyInfo) prop;
    QName attName = ap.getXmlName();
    
    AttributeAnnotation attributeAnnotation = new AttributeAnnotation();
    
    final String generatedName = attName.getLocalPart();
    
    // Issue 570; always force generating name="" when do it when globalBindings underscoreBinding is set to non default value
    // generate name property?
    if(!generatedName.equals(ap.getName(false)) || (parent.parent().getModel().getNameConverter() != NameConverter.standard)) {
    	attributeAnnotation.setName(generatedName);
    }
    
    return attributeAnnotation;
}
 
Example #2
Source File: JaxbValidationsPlugins.java    From krasa-jaxb-tools with Apache License 2.0 6 votes vote down vote up
/**
 * XS:Attribute
 */
public void processAttribute(CAttributePropertyInfo property, ClassOutline clase, Outline model) {
	FieldOutline field = model.getField(property);
	String propertyName = property.getName(false);
	String className = clase.implClass.name();

	log("Attribute " + propertyName + " added to class " + className);
	XSComponent definition = property.getSchemaComponent();
	AttributeUseImpl particle = (AttributeUseImpl) definition;
	XSSimpleType type = particle.getDecl().getType();

	JFieldVar var = clase.implClass.fields().get(propertyName);
	if (particle.isRequired()) {
		if (!hasAnnotation(var, NotNull.class)) {
			processNotNull(clase, var);
		}
	}

	validAnnotation(type, var, propertyName, className);
	processType(type, var, propertyName, className);
}
 
Example #3
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 #4
Source File: AbstractAdaptPropertyInfo.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public CPropertyInfo createAttributePropertyInfo(String propertyName,
		XSComponent source, TypeUse propertyType, QName propertyQName,
		CollectionMode collectionMode, CCustomizations customizations) {

	final TypeUse typeUse = collectionMode.isRepeated() ?

	new DefaultTypeUse(propertyType.getInfo(), true,
			propertyType.idUse(), propertyType.getExpectedMimeType(),
			propertyType.getAdapterUse()) : propertyType;

	final CAttributePropertyInfo propertyInfo = new CAttributePropertyInfo(
			propertyName, source,

			customizations, null, propertyQName, typeUse, typeUse.getInfo()
					.getTypeName(), false);
	return propertyInfo;
}
 
Example #5
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 #6
Source File: TypeUseUtils.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static TypeUse getTypeUse(ProcessModel processModel,
		CPropertyInfo propertyInfo) {
	if (propertyInfo instanceof CValuePropertyInfo) {
		return ((CValuePropertyInfo) propertyInfo).getTarget();
	} else if (propertyInfo instanceof CAttributePropertyInfo) {
		return ((CAttributePropertyInfo) propertyInfo).getTarget();
	} else {
		final CTypeInfo type = propertyInfo.ref().iterator().next();
		if (type instanceof CBuiltinLeafInfo) {
			if (propertyInfo.getAdapter() != null) {
				return TypeUseFactory.adapt((CBuiltinLeafInfo) type,
						propertyInfo.getAdapter());
			} else {
				return (CBuiltinLeafInfo) type;
			}
		} else if (type instanceof CElementInfo) {
			final CElementInfo elementInfo = (CElementInfo) type;
			return getTypeUse(processModel, elementInfo.getProperty());
		} else {
			throw new AssertionError("Unexpected type.");
		}
	}

}
 
Example #7
Source File: DefaultGetTypes.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public TypeUse getTypeUse(C context, CPropertyInfo propertyInfo) {
	if (propertyInfo instanceof CValuePropertyInfo) {
		return ((CValuePropertyInfo) propertyInfo).getTarget();
	} else if (propertyInfo instanceof CAttributePropertyInfo) {
		return ((CAttributePropertyInfo) propertyInfo).getTarget();
	} else {
		final CTypeInfo type = propertyInfo.ref().iterator().next();
		if (type instanceof CBuiltinLeafInfo) {
			if (propertyInfo.getAdapter() != null) {
				return TypeUseFactory.adapt((CBuiltinLeafInfo) type,
						propertyInfo.getAdapter());
			} else {
				return (CBuiltinLeafInfo) type;
			}
		} else if (type instanceof CElementInfo) {
			final CElementInfo elementInfo = (CElementInfo) type;
			return getTypeUse(context, elementInfo.getProperty());
		} else {
			throw new AssertionError("Unexpected type.");
		}
	}

}
 
Example #8
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected String getDefaultValue(CAttributePropertyInfo propertyInfo) {

		final XSAttributeUse attributeUse = getAttributeUse(propertyInfo);
		if (attributeUse != null) {
			final XmlString defaultValue = attributeUse.getDefaultValue();
			if (defaultValue != null) {
				return defaultValue.value;
			}
		}
		return null;
	}
 
Example #9
Source File: DefaultCreateDefaultIdPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected CPropertyInfo createPropertyInfo(ProcessModel context,
		CClassInfo classInfo) {
	final GeneratedId cid = context.getCustomizing().getGeneratedId(
			classInfo);
	final String propertyName = getPropertyName(context, cid);
	final QName attributeName = getAttributeName(context, cid);
	final CNonElement propertyTypeInfo = getPropertyTypeInfo(context, cid);
	final CCustomizations customizations = new CCustomizations();
	final CPluginCustomization id = createIdCustomization(context, cid);
	customizations.add(id);
	//		
	// CPluginCustomization generated = CustomizationUtils
	// .createCustomization(org.jvnet.jaxb2_commons.plugin.Customizations.GENERATED_ELEMENT_NAME);
	// generated.markAsAcknowledged();
	// customizations.add(generated);

	final CPropertyInfo propertyInfo = new CAttributePropertyInfo(
			propertyName, null, customizations, null, attributeName,
			propertyTypeInfo, propertyTypeInfo.getTypeName(), false);

	if (cid.isTransient() != null && cid.isTransient()) {
		propertyInfo.realization = new GenericFieldRenderer(
				TransientSingleField.class);
	}

	Customizations.markGenerated(propertyInfo);

	return propertyInfo;
}
 
Example #10
Source File: DefaultCreateDefaultVersionPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected CPropertyInfo createPropertyInfo(ProcessModel context,
		CClassInfo classInfo, GeneratedVersion cversion) {
	final String propertyName = getPropertyName(context, cversion);
	final QName attributeName = getAttributeName(context, cversion);
	final CNonElement propertyTypeInfo = getPropertyTypeInfo(context,
			cversion);
	final CCustomizations customizations = new CCustomizations();
	final CPluginCustomization version = createVersionCustomization(context, cversion);
	customizations.add(version);
	//
	// CPluginCustomization generated = CustomizationUtils
	// .createCustomization(org.jvnet.jaxb2_commons.plugin.Customizations.GENERATED_ELEMENT_NAME);
	// generated.markAsAcknowledged();
	// customizations.add(generated);

	final CPropertyInfo propertyInfo = new CAttributePropertyInfo(
			propertyName, null, customizations, null, attributeName,
			propertyTypeInfo, propertyTypeInfo.getTypeName(), false);

	if (cversion.isTransient() != null && cversion.isTransient()) {
		propertyInfo.realization = new GenericFieldRenderer(
				TransientSingleField.class);
	}

	Customizations.markGenerated(propertyInfo);

	return propertyInfo;
}
 
Example #11
Source File: CClassifyingVisitor.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public U onAttribute(CAttributePropertyInfo attributePropertyInfo) {

		final CNonElement type = context.getGetTypes().getTarget(context,
				attributePropertyInfo);
		if (type instanceof CBuiltinLeafInfo) {
			return onBuiltinAttribute(attributePropertyInfo);
		} else if (type instanceof CEnumLeafInfo) {
			return onEnumAttribute(attributePropertyInfo);
		} else {
			return onOtherAttribute(attributePropertyInfo);
		}
	}
 
Example #12
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private XSAttributeUse getAttributeUse(CAttributePropertyInfo propertyInfo) {
	final XSComponent schemaComponent = propertyInfo.getSchemaComponent();
	if (schemaComponent instanceof XSAttributeUse) {
		return (XSAttributeUse) schemaComponent;
	} else {
		return null;
	}
}
 
Example #13
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected NamespaceContext getDefaultValueNamespaceContext(
		CAttributePropertyInfo propertyInfo) {
	final XSAttributeUse attributeUse = getAttributeUse(propertyInfo);
	if (attributeUse != null) {
		final XmlString defaultValue = attributeUse.getDefaultValue();
		if (defaultValue != null) {
			return new NamespaceContextAdapter(defaultValue);
		}
	}
	return null;

}
 
Example #14
Source File: FieldUtils.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static FieldOutline createAttributeField(
		ClassOutlineImpl classOutline, String name, final QName attName,
		final CNonElement typeInfo, final boolean required
// ,
// final XSDatatype datatype,
// final JType type
) {

	final CPropertyInfo propertyInfo = new CAttributePropertyInfo(
	// name
			name,
			// source
			null, new CCustomizations(),
			// locator
			null,
			// attName
			attName,
			// typeUse
			typeInfo,
			// typeName
			typeInfo.getTypeName(),
			// required
			required);

	propertyInfo.realization = new FieldRendererFactory().getDefault();
	final FieldOutline fieldOutline =

	propertyInfo.realization.generate(classOutline, propertyInfo);

	return fieldOutline;

}
 
Example #15
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 #16
Source File: AbstractField.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Annotate the attribute property 'field'
 */
private void annotateAttribute(JAnnotatable field) {
    CAttributePropertyInfo ap = (CAttributePropertyInfo) prop;
    QName attName = ap.getXmlName();

    // [RESULT]
    // @XmlAttribute(name="foo", required=true, namespace="bar://baz")
    XmlAttributeWriter xaw = field.annotate2(XmlAttributeWriter.class);

    final String generatedName = attName.getLocalPart();
    final String generatedNS = attName.getNamespaceURI();

    // generate name property?
    if(!generatedName.equals(ap.getName(false))) {
        xaw.name(generatedName);
    }

    // generate namespace property?
    if(!generatedNS.equals("")) { // assume attributeFormDefault == unqualified
        xaw.namespace(generatedNS);
    }

    // generate required property?
    if(ap.isRequired()) {
        xaw.required(true);
    }
}
 
Example #17
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onSingleOtherAttribute(
		CAttributePropertyInfo attributePropertyInfo) {
	logger.error("[" + attributePropertyInfo.getName(true)
			+ "] is a single other attribute. See issue #56.");
	return Collections.emptyList();
}
 
Example #18
Source File: CClassifier.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public V onSingleBuiltinAttribute(
CAttributePropertyInfo attributePropertyInfo);
 
Example #19
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onCollectionOtherAttribute(
		CAttributePropertyInfo attributePropertyInfo) {
	logger.error("[" + attributePropertyInfo.getName(true)
			+ "] is a collection other attribute. See issue #59.");
	return Collections.emptyList();
}
 
Example #20
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onCollectionEnumAttribute(
		CAttributePropertyInfo attributePropertyInfo) {
	return context.getWrapCollectionEnumAttribute().process(context,
			attributePropertyInfo);
}
 
Example #21
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onCollectionBuiltinAttribute(
		CAttributePropertyInfo attributePropertyInfo) {
	return context.getWrapCollectionBuiltinAttribute().process(context,
			attributePropertyInfo);
}
 
Example #22
Source File: CClassifier.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public V onCollectionBuiltinAttribute(
CAttributePropertyInfo attributePropertyInfo);
 
Example #23
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onSingleEnumAttribute(
		CAttributePropertyInfo attributePropertyInfo) {
	return context.getWrapSingleEnumAttribute().process(context,
			attributePropertyInfo);
}
 
Example #24
Source File: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Collection<CPropertyInfo> onSingleBuiltinAttribute(
		CAttributePropertyInfo attributePropertyInfo) {
	return context.getWrapSingleBuiltinAttribute().process(context,
			attributePropertyInfo);
}
 
Example #25
Source File: DefaultGetTypes.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CNonElement getTarget(C context, CAttributePropertyInfo propertyInfo) {
	return propertyInfo.getTarget();
}
 
Example #26
Source File: CClassifyingVisitor.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public U onOtherAttribute(CAttributePropertyInfo attributePropertyInfo) {
	return !attributePropertyInfo.isCollection() ? classifier
			.onSingleOtherAttribute(attributePropertyInfo) : classifier
			.onCollectionOtherAttribute(attributePropertyInfo);
}
 
Example #27
Source File: CClassifyingVisitor.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public U onEnumAttribute(CAttributePropertyInfo attributePropertyInfo) {
	return !attributePropertyInfo.isCollection() ? classifier
			.onSingleEnumAttribute(attributePropertyInfo) : classifier
			.onCollectionEnumAttribute(attributePropertyInfo);
}
 
Example #28
Source File: CClassifyingVisitor.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public U onBuiltinAttribute(CAttributePropertyInfo attributePropertyInfo) {
	return !attributePropertyInfo.isCollection() ? classifier
			.onSingleBuiltinAttribute(attributePropertyInfo) : classifier
			.onCollectionBuiltinAttribute(attributePropertyInfo);
}
 
Example #29
Source File: CClassifier.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public V onCollectionOtherAttribute(
CAttributePropertyInfo attributePropertyInfo);
 
Example #30
Source File: CClassifier.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public V onCollectionEnumAttribute(
CAttributePropertyInfo attributePropertyInfo);