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

The following examples show how to use com.sun.tools.xjc.model.CTypeRef. 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: 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 #2
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 #3
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 #4
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected NamespaceContext getDefaultValueNamespaceContext(
		TypeRef<NType, NClass> typeRef) {
	if (typeRef instanceof CTypeRef) {
		final CTypeRef cTypeRef = (CTypeRef) typeRef;
		return new NamespaceContextAdapter(cTypeRef.defaultValue);
	} else {
		return null;
	}
}
 
Example #5
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 #6
Source File: ClassModelBuilder.java    From mxjc with MIT License 5 votes vote down vote up
private static ElementAnnotation getElementAnnotation(ClassOutline parent, CPropertyInfo prop, CTypeRef ctype) {
	ElementAnnotation elementAnnotation = null;
	
    String propName = prop.getName(false);
    
    // generate the name property?
    String generatedName = ctype.getTagName().getLocalPart();
    if(!generatedName.equals(propName)) {
    	elementAnnotation = new ElementAnnotation();
    	elementAnnotation.setName(generatedName);
    }
	
	return elementAnnotation;
}
 
Example #7
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 #8
Source File: SimplifyPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private String createPropertyName(final Model model,
		CPropertyInfo propertyInfo, CTypeRef element) {
	final String propertyName = model.getNameConverter().toPropertyName(
			pluralizeIfNecessary(propertyInfo, element.getTagName().getLocalPart()));
	return propertyName;
}
 
Example #9
Source File: AbstractField.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Generate the simplest XmlElement annotation possible taking all semantic optimizations
 * into account.  This method is essentially equivalent to:
 *
 *     xew.name(ctype.getTagName().getLocalPart())
 *        .namespace(ctype.getTagName().getNamespaceURI())
 *        .type(jtype)
 *        .defaultValue(ctype.getDefaultValue());
 *
 * @param field
 * @param ctype
 * @param jtype
 * @param checkWrapper true if the method might need to generate XmlElements
 */
private void writeXmlElementAnnotation( JAnnotatable field, CTypeRef ctype, JType jtype,
                                        boolean checkWrapper ) {

    // lazily create - we don't know if we need to generate anything yet
    XmlElementWriter xew = null;

    // these values are used to determine how to optimize the generated annotation
    XmlNsForm formDefault = parent()._package().getElementFormDefault();
    String mostUsedURI = parent()._package().getMostUsedNamespaceURI();
    String propName = prop.getName(false);

    // generate the name property?
    String generatedName = ctype.getTagName().getLocalPart();
    if(!generatedName.equals(propName)) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.name(generatedName);
    }

    // generate the namespace property?
    String generatedNS = ctype.getTagName().getNamespaceURI();
    if (((formDefault == XmlNsForm.QUALIFIED) && !generatedNS.equals(mostUsedURI)) ||
            ((formDefault == XmlNsForm.UNQUALIFIED) && !generatedNS.equals(""))) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.namespace(generatedNS);
    }

    // generate the required() property?
    CElementPropertyInfo ep = (CElementPropertyInfo) prop;
    if(ep.isRequired() && exposedType.isReference()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.required(true);
    }

    // generate the type property?

    // I'm not too sure if this is the right place to handle this, but
    // if the schema definition is requiring this element, we should point to a primitive type,
    // not wrapper type (to correctly carry forward the required semantics.)
    // if it's a collection, we can't use a primitive, however.
    if(ep.isRequired() && !prop.isCollection())
        jtype = jtype.unboxify();

    // when generating code for 1.4, the runtime can't infer that ArrayList<Foo> derives
    // from Collection<Foo> (because List isn't parameterized), so always expclitly
    // generate @XmlElement(type=...)
    if( !jtype.equals(exposedType) || (parent().parent().getModel().options.runtime14 && prop.isCollection())) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.type(jtype);
    }

    // generate defaultValue property?
    final String defaultValue = ctype.getDefaultValue();
    if (defaultValue!=null) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.defaultValue(defaultValue);
    }

    // generate the nillable property?
    if (ctype.isNillable()) {
        if(xew == null) xew = getXew(checkWrapper, field);
        xew.nillable(true);
    }
}
 
Example #10
Source File: AbstractField.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * return the Java type for the given type reference in the model.
 */
private JType resolve(CTypeRef typeRef,Aspect a) {
    return outline.parent().resolve(typeRef,a);
}
 
Example #11
Source File: SingleWrappingElementField.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public SingleWrappingElementField(ClassOutlineImpl context,
		CPropertyInfo prop, CPropertyInfo core, CTypeRef typeRef) {
	super(context, prop, core);
	this.typeRef = typeRef;
}
 
Example #12
Source File: SingleWrappingElementField.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CTypeRef getTypeRef() {
	return typeRef;
}
 
Example #13
Source File: WrapSingleHeteroReference.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected Collection<CPropertyInfo> createElementProperties(
		ProcessModel context, final CReferencePropertyInfo propertyInfo) {

	Set<CElement> elements = context.getGetTypes().getElements(context,
			propertyInfo);

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

	for (CElement element : elements) {

		final CElementPropertyInfo itemPropertyInfo = new CElementPropertyInfo(
				propertyInfo.getName(true)
						+ ((CClassInfo) propertyInfo.parent()).model
								.getNameConverter().toPropertyName(
										element.getElementName()
												.getLocalPart()),
				CollectionMode.NOT_REPEATED, ID.NONE,
				propertyInfo.getExpectedMimeType(),
				propertyInfo.getSchemaComponent(),
				new CCustomizations(CustomizationUtils
						.getCustomizations(propertyInfo)),
				propertyInfo.getLocator(), false);

		if (element instanceof CElementInfo) {
			final CElementInfo elementInfo = (CElementInfo) element;
			if (!elementInfo.getSubstitutionMembers().isEmpty()) {
				logger.error("["
						+ ((CClassInfo) propertyInfo.parent()).getName()
						+ "."
						+ propertyInfo.getName(true)
						+ "] is a single hetero reference containing element ["
						+ elementInfo.getSqueezedName()
						+ "] which is a substitution group head. See issue #95.");
			} else {
				itemPropertyInfo.getTypes().addAll(
						context.getGetTypes().getTypes(context,
								((CElementInfo) element).getProperty()));

				itemPropertyInfo.realization = new FieldRenderer() {
					public FieldOutline generate(
							ClassOutlineImpl classOutline, CPropertyInfo p) {
						SingleWrappingReferenceElementInfoField field = new SingleWrappingReferenceElementInfoField(
								classOutline, p, propertyInfo, elementInfo);
						field.generateAccessors();
						return field;
					}
				};
				Customizations.markGenerated(itemPropertyInfo);

				properties.add(itemPropertyInfo);
			}
		} else if (element instanceof CClassInfo) {

			final CClassInfo classInfo = (CClassInfo) element;

			final QName elementName = classInfo.getElementName();
			final QName typeName = classInfo.getTypeName();
			final CTypeRef typeRef = new CTypeRef(classInfo, elementName,
					typeName, false, null);

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

			itemPropertyInfo.getTypes().add(typeRef);

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

		} else if (element instanceof CClassRef) {
			final CClassRef classRef = (CClassRef) element;
			logger.error("CClassRef elements are not supported yet.");

			logger.error("["
					+ ((CClassInfo) propertyInfo.parent()).getName()
					+ "."
					+ propertyInfo.getName(true)
					+ "] is a single hetero reference containing unsupported CClassRef element ["
					+ classRef.fullName() + "]. See issue #94.");

		}
	}
	return properties;
}
 
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: 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);