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

The following examples show how to use com.sun.tools.xjc.model.CElementInfo. 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: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private MContainer getContainer(CClassInfoParent parent) {
	return parent.accept(new Visitor<MContainer>() {

		public MContainer onBean(CClassInfo bean) {
			return getTypeInfo(bean);
		}

		public MContainer onPackage(JPackage pkg) {
			return getPackage(pkg);
		}

		public MContainer onElement(CElementInfo element) {
			return getElementInfo(element);
		}
	});
}
 
Example #2
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private MPackageInfo getPackage(CClassInfoParent parent) {

		return parent.accept(new Visitor<MPackageInfo>() {

			public MPackageInfo onBean(CClassInfo bean) {
				return getPackage(bean.parent());
			}

			public MPackageInfo onPackage(JPackage pkg) {
				return getPackage(pkg);
			}

			public MPackageInfo onElement(CElementInfo element) {
				return getPackage(element.parent);
			}
		});

	}
 
Example #3
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 #4
Source File: FieldUtils.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Set<JType> getPossibleTypes(Outline outline, Aspect aspect,
		CTypeInfo typeInfo) {

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

	types.add(typeInfo.getType().toType(outline, aspect));
	if (typeInfo instanceof CElementInfo) {

		final CElementInfo elementInfo = (CElementInfo) typeInfo;
		for (CElementInfo substitutionMember : elementInfo
				.getSubstitutionMembers()) {
			types.addAll(getPossibleTypes(outline, aspect,
					substitutionMember));
		}
	}
	return types;
}
 
Example #5
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 #6
Source File: AutoInheritancePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {
	for (final ClassOutline classOutline : outline.getClasses()) {
		if (classOutline.target.getElementName() != null) {
			processGlobalElement(classOutline);
		} else {
			processGlobalComplexType(classOutline);
		}
	}
	for (final CElementInfo elementInfo : outline.getModel()
			.getAllElements()) {
		final ElementOutline elementOutline = outline
				.getElement(elementInfo);
		if (elementOutline != null) {
			processGlobalJAXBElement(elementOutline);
		}
	}
	return true;
}
 
Example #7
Source File: ClassModelBuilder.java    From mxjc with MIT License 5 votes vote down vote up
/**
 * Build class name to element name mapping
 * 
 * @param outline, JAXB schema/code model
 * @return class name to element name map
 */
private static Map<String, QName> buildClass2ElementMapping(Outline outline) {
	Map<String, QName> mapping = new HashMap<String, QName>();
	for(CElementInfo ei : outline.getModel().getAllElements()) {
        JType exposedType = ei.getContentInMemoryType().toType(outline,Aspect.EXPOSED);
        mapping.put(exposedType.fullName(), ei.getElementName());
	}
	return mapping;
}
 
Example #8
Source File: BuilderGenerator.java    From jaxb2-rich-contract-plugin with MIT License 5 votes vote down vote up
private JType getTagRefType(final PropertyOutline.TagRef tagRef, final Outline outline, final Aspect aspect) {
	final TypeInfo<NType, NClass> typeInfo = tagRef.getTypeInfo();
	final JType type;
	if (typeInfo instanceof CClassInfo) {
		type = ((CClassInfo) typeInfo).toType(outline, aspect);
	} else if (typeInfo instanceof CElementInfo) {
		final List<CNonElement> refs = ((CElementInfo) typeInfo).getProperty().ref();
		// This feels dirty but am not sure what we do if we get multiple refs
		if (refs.size() == 1) {
			try {
				type = ((CClassInfo) refs.get(0)).toType(outline, aspect);
			} catch (Exception e) {
				throw new RuntimeException(String.format("Unexpected type %s for tagRef %s",
						refs.get(0).getClass().getCanonicalName(),
						tagRef.getTagName()));
			}
		} else {
			throw new RuntimeException(String.format("Expecting one ref type for tagRef %s, found %s",
					tagRef.getTagName(),
					refs.size()));
		}
	} else {
		throw new RuntimeException(String.format("Unexpected type %s for tagRef %s",
				typeInfo.getClass().getCanonicalName(),
				tagRef.getTagName()));
	}
	return type;
}
 
Example #9
Source File: DefaultIgnoring.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private CClassInfoParent.Package getPackageInfo(CClassInfoParent parent) {
	if (parent instanceof CClassInfoParent.Package) {
		return (Package) parent;
	} else if (parent instanceof CClassInfo) {
		return getPackageInfo(((CClassInfo) parent).parent());
	} else if (parent instanceof CElementInfo) {
		return getPackageInfo(((CElementInfo) parent).parent);
	} else {
		throw new AssertionError("Unexpexted class info parent [" + parent
				+ "].");
	}

}
 
Example #10
Source File: WrapSingleBuiltinReference.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CBuiltinLeafInfo getTypeUse(ProcessModel context,
		CPropertyInfo propertyInfo) {
	
	final Collection<? extends CTypeInfo> types = context.getGetTypes().process(
			context, propertyInfo);

	final CElementInfo elementInfo = ((CElementInfo) types
			.iterator().next());

	final CBuiltinLeafInfo type = (CBuiltinLeafInfo) elementInfo
			.getContentType();

	return type;
}
 
Example #11
Source File: WrapSingleSubstitutedElementReference.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CElementInfo getElementInfo(ProcessModel context,
		final CReferencePropertyInfo referencePropertyInfo) {
	final CElement element = context.getGetTypes()
			.getElements(context, referencePropertyInfo).iterator().next();
	assert element instanceof CElementInfo;

	final CElementInfo elementInfo = (CElementInfo) element;
	return elementInfo;
}
 
Example #12
Source File: SingleWrappingReferenceObjectField.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public JExpression unwrapCondifiton(JExpression source) {

	final CReferencePropertyInfo core = (CReferencePropertyInfo) this.core;

	JExpression predicate = null;
	if (core.getElements().isEmpty()) {
		predicate = null;
	} else {
		for (CElement element : core.getElements()) {
			if (element instanceof CElementInfo) {
				CElementInfo elementinfo = (CElementInfo) element;

				final SingleWrappingReferenceElementInfoField field = new SingleWrappingReferenceElementInfoField(
						outline, prop, core, elementinfo);
				final JExpression condition = field
						.unwrapCondifiton(source);
				predicate = (predicate == null) ? condition : JOp.cor(
						predicate, condition);
			} else {
				// TODO Other cases currently not supported.
			}
		}
	}

	final JExpression isElement = codeModel.ref(JAXBContextUtils.class)
			.staticInvoke("isElement").arg(contextPath).arg(source);
	return predicate == null ? isElement : JOp.cand(JOp.not(predicate),
			isElement);
}
 
Example #13
Source File: SingleWrappingReferenceField.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected CElementInfo getElementInfo() {
	final CReferencePropertyInfo referencePropertyInfo = (CReferencePropertyInfo) core;

	final Collection<CElement> elements = referencePropertyInfo
			.getElements();

	final CElement element = elements.iterator().next();

	final CElementInfo elementInfo = (CElementInfo) element.getType();
	return elementInfo;
}
 
Example #14
Source File: CustomizationUtils.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static CPluginCustomization findCustomization(CElementInfo elementInfo, QName name) {
	final CCustomizations customizations = CustomizationUtils.getCustomizations(elementInfo);
	final CPluginCustomization customization = customizations.find(name.getNamespaceURI(), name.getLocalPart());
	if (customization != null) {
		customization.markAsAcknowledged();
	}
	return customization;
}
 
Example #15
Source File: CustomizationUtils.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static List<CPluginCustomization> findCustomizations(CElementInfo elementInfo, QName name) {
	final CCustomizations customizations = CustomizationUtils.getCustomizations(elementInfo);

	final List<CPluginCustomization> pluginCustomizations = new LinkedList<CPluginCustomization>();

	for (CPluginCustomization pluginCustomization : customizations) {
		if (fixNull(pluginCustomization.element.getNamespaceURI()).equals(name.getNamespaceURI())
				&& fixNull(pluginCustomization.element.getLocalName()).equals(name.getLocalPart())) {
			pluginCustomization.markAsAcknowledged();
			pluginCustomizations.add(pluginCustomization);
		}
	}

	return pluginCustomizations;
}
 
Example #16
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);
	}
}
 
Example #17
Source File: SingleWrappingReferenceElementInfoField.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected CElementInfo getElementInfo() {
	return elementInfo;
}
 
Example #18
Source File: SingleWrappingReferenceElementInfoField.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public SingleWrappingReferenceElementInfoField(ClassOutlineImpl context,
		CPropertyInfo property, CReferencePropertyInfo core, CElementInfo elementInfo) {
	super(context, property, core);
	this.elementInfo = elementInfo;
}
 
Example #19
Source File: CustomizationUtils.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static CCustomizations getCustomizations(final CElementInfo elementInfo) {
	return elementInfo.getCustomizations();
}
 
Example #20
Source File: SingleMarshallingReferenceField.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
	protected JExpression wrap(JExpression target) {

		final CReferencePropertyInfo referencePropertyInfo = (CReferencePropertyInfo) core;

		final Collection<CElement> elements = referencePropertyInfo
				.getElements();

		final CElement element = elements.iterator().next();

		final CElementInfo elementInfo = (CElementInfo) element.getType();

//		final CNonElement type = elementInfo.getProperty().ref().iterator()
//				.next();

		final JClass scope = getScope(elementInfo.getScope());

		final QName name = elementInfo.getElementName();

		return codeModel.ref(JAXBContextUtils.class).staticInvoke(
				"unmarshalJAXBElement").arg(contextPath).arg(
				JExprUtils.newQName(codeModel, name)).arg(scope.dotclass())
				.arg(target);
	}
 
Example #21
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 #22
Source File: XJCCMElementInfoOrigin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public XJCCMElementInfoOrigin(CElementInfo source) {
	super(source);
	component = source.getSchemaComponent() != null ? source
			.getSchemaComponent() : source.getProperty()
			.getSchemaComponent();
}
 
Example #23
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected MElementInfoOrigin createElementInfoOrigin(CElementInfo info) {
	return new XJCCMElementInfoOrigin(info);
}
 
Example #24
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected String getLocalName(CElementInfo info) {
	return info.shortName();
}
 
Example #25
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected MContainer getContainer(CElementInfo info) {
	final CClassInfoParent parent = info.parent;
	return parent == null ? null : getContainer(parent);
}
 
Example #26
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected MPackageInfo getPackage(CElementInfo info) {
	return getPackage(info.parent);
}
 
Example #27
Source File: CMElementOutlineGenerator.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CMElementOutlineGenerator(Outline outline, CElementInfo elementInfo) {
	Validate.notNull(outline);
	Validate.notNull(elementInfo);
	this.outline = outline;
	this.elementInfo = elementInfo;
}