use of com.sun.tools.xjc.model.CAttributePropertyInfo in project jaxb-ri by eclipse-ee4j.
the class PackageOutlineImpl method calcDefaultValues.
/**
* Compute the most common namespace URI in this package
* (to put into {@link XmlSchema#namespace()} and what value
* we should put into {@link XmlSchema#elementFormDefault()}.
*
* This method is called after {@link #classes} field is filled up.
*/
public void calcDefaultValues() {
// package-info.java
if (!_model.isPackageLevelAnnotations()) {
mostUsedNamespaceURI = "";
elementFormDefault = XmlNsForm.UNQUALIFIED;
return;
}
// used to visit properties
CPropertyVisitor<Void> propVisitor = new CPropertyVisitor<>() {
@Override
public Void onElement(CElementPropertyInfo p) {
for (CTypeRef tr : p.getTypes()) {
countURI(propUriCountMap, tr.getTagName());
}
return null;
}
@Override
public Void onReference(CReferencePropertyInfo p) {
for (CElement e : p.getElements()) {
countURI(propUriCountMap, e.getElementName());
}
return null;
}
@Override
public Void onAttribute(CAttributePropertyInfo p) {
return null;
}
@Override
public Void onValue(CValuePropertyInfo p) {
return null;
}
};
for (ClassOutlineImpl co : classes) {
CClassInfo ci = co.target;
countURI(uriCountMap, ci.getTypeName());
countURI(uriCountMap, ci.getElementName());
for (CPropertyInfo p : ci.getProperties()) p.accept(propVisitor);
}
mostUsedNamespaceURI = getMostUsedURI(uriCountMap);
elementFormDefault = getFormDefault();
attributeFormDefault = XmlNsForm.UNQUALIFIED;
try {
XmlNsForm modelValue = _model.getAttributeFormDefault(mostUsedNamespaceURI);
attributeFormDefault = modelValue;
} catch (Exception e) {
// ignore and accept default
}
// we won't get this far if the user specified -npa
if (!mostUsedNamespaceURI.equals("") || elementFormDefault == XmlNsForm.QUALIFIED || (attributeFormDefault == XmlNsForm.QUALIFIED)) {
XmlSchemaWriter w = _model.strategy.getPackage(_package, Aspect.IMPLEMENTATION).annotate2(XmlSchemaWriter.class);
if (!mostUsedNamespaceURI.equals(""))
w.namespace(mostUsedNamespaceURI);
if (elementFormDefault == XmlNsForm.QUALIFIED)
w.elementFormDefault(elementFormDefault);
if (attributeFormDefault == XmlNsForm.QUALIFIED)
w.attributeFormDefault(attributeFormDefault);
}
}
use of com.sun.tools.xjc.model.CAttributePropertyInfo in project jaxb-ri by eclipse-ee4j.
the class BIProperty method createAttributeProperty.
public CAttributePropertyInfo createAttributeProperty(XSAttributeUse use, TypeUse tu) {
boolean forConstant = getCustomization(use).isConstantProperty() && use.getFixedValue() != null;
String name = getPropertyName(forConstant);
if (name == null) {
NameConverter conv = getBuilder().getNameConverter();
if (forConstant)
name = conv.toConstantName(use.getDecl().getName());
else
name = conv.toPropertyName(use.getDecl().getName());
if (tu.isCollection() && getBuilder().getGlobalBinding().isSimpleMode())
name = JJavaName.getPluralForm(name);
}
markAsAcknowledged();
constantPropertyErrorCheck();
return wrapUp(new CAttributePropertyInfo(name, use, getCustomizations(use), use.getLocator(), BGMBuilder.getName(use.getDecl()), tu, BGMBuilder.getName(use.getDecl().getType()), use.isRequired()), use);
}
use of com.sun.tools.xjc.model.CAttributePropertyInfo in project jaxb-ri by eclipse-ee4j.
the class ContentModelBinder method onAttribute.
@Override
public Void onAttribute(DAttributePattern p) {
// TODO: support multiple names
QName name = p.getName().listNames().iterator().next();
CAttributePropertyInfo ap = new CAttributePropertyInfo(calcName(p), null, null, /*TODO*/
p.getLocation(), name, p.getChild().accept(compiler.typeUseBinder), null, !insideOptional);
clazz.addProperty(ap);
return null;
}
use of com.sun.tools.xjc.model.CAttributePropertyInfo in project jaxb-ri by eclipse-ee4j.
the class BeanGenerator method generateClassBody.
/**
* Generates the body of a class.
*/
private void generateClassBody(ClassOutlineImpl cc) {
CClassInfo target = cc.target;
// used to simplify the generated annotations
String mostUsedNamespaceURI = cc._package().getMostUsedNamespaceURI();
// [RESULT]
// @XmlType(name="foo", targetNamespace="bar://baz")
XmlTypeWriter xtw = cc.implClass.annotate2(XmlTypeWriter.class);
writeTypeName(cc.target.getTypeName(), xtw, mostUsedNamespaceURI);
// @XmlSeeAlso
Iterator<CClassInfo> subclasses = cc.target.listSubclasses();
if (subclasses.hasNext()) {
XmlSeeAlsoWriter saw = cc.implClass.annotate2(XmlSeeAlsoWriter.class);
while (subclasses.hasNext()) {
CClassInfo s = subclasses.next();
saw.value(getClazz(s).implRef);
}
}
if (target.isElement()) {
String namespaceURI = target.getElementName().getNamespaceURI();
String localPart = target.getElementName().getLocalPart();
// [RESULT]
// @XmlRootElement(name="foo", targetNamespace="bar://baz")
XmlRootElementWriter xrew = cc.implClass.annotate2(XmlRootElementWriter.class);
xrew.name(localPart);
if (// only generate if necessary
!namespaceURI.equals(mostUsedNamespaceURI)) {
xrew.namespace(namespaceURI);
}
}
if (target.isOrdered()) {
for (CPropertyInfo p : target.getProperties()) {
if (!(p instanceof CAttributePropertyInfo)) {
if (!((p instanceof CReferencePropertyInfo) && ((CReferencePropertyInfo) p).isDummy())) {
xtw.propOrder(p.getName(false));
}
}
}
} else {
// produce empty array
xtw.getAnnotationUse().paramArray("propOrder");
}
for (CPropertyInfo prop : target.getProperties()) {
generateFieldDecl(cc, prop);
}
if (target.declaresAttributeWildcard()) {
generateAttributeWildcard(cc);
}
// generate some class level javadoc
cc.ref.javadoc().append(target.javadoc);
cc._package().objectFactoryGenerator().populate(cc);
}
use of com.sun.tools.xjc.model.CAttributePropertyInfo in project jaxb-ri by eclipse-ee4j.
the class AbstractField method annotateAttribute.
/**
* 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)) || !generatedName.equals(ap.getName(true)) || (outline.parent().getModel().getNameConverter() != NameConverter.standard)) {
xaw.name(generatedName);
}
// generate namespace property?
if (!generatedNS.equals("")) {
// assume attributeFormDefault == unqualified
xaw.namespace(generatedNS);
}
// generate required property?
if (ap.isRequired()) {
xaw.required(true);
}
}
Aggregations