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

The following examples show how to use com.sun.tools.xjc.model.CClassRef. 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: DefaultProcessPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public boolean isSelfOrAncestorRootClass(ProcessModel context,
		CClassRef classRef) {

	final String className = classRef.fullName();

	try {
		final Class<?> referencedClass = Class.forName(className);
		return isSelfOrAncestorRootClass(referencedClass);

	} catch (ClassNotFoundException cnfex) {
		logger.warn("Referenced class ["
				+ className
				+ "] could not be found, this may lead to incorrect generation of the identifier fields.");
		return true;
	}
}
 
Example #2
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected MClassRef<NType, NClass> getTypeInfo(CClassRef info) {

		MClassRef<NType, NClass> classInfo = classRefs.get(info);

		if (classInfo == null) {

			classInfo = createClassRef(info);
			classRefs.put(info, classInfo);
		}
		return classInfo;
	}
 
Example #3
Source File: InheritancePlugin.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void postProcessModel(Model model, ErrorHandler errorHandler){
	super.postProcessModel(model, errorHandler);

	Map<String, CClassRef> classRefCache = new HashMap<>();

	CClassRef defaultBaseClazz = getClassRef(classRefCache, model, "org.dmg.pmml.PMMLObject");

	Collection<CClassInfo> classInfos = (model.beans()).values();
	for(CClassInfo classInfo : classInfos){
		CClassRef baseClazz = defaultBaseClazz;

		CPluginCustomization extendsCustomization = CustomizationUtils.findCustomization(classInfo, Customizations.EXTENDS_ELEMENT_NAME);
		if(extendsCustomization != null){
			ExtendsClass extendsClass = (ExtendsClass)CustomizationUtils.unmarshall(Customizations.getContext(), extendsCustomization);

			String name = getClassName(extendsClass);

			int lt = name.indexOf('<');
			if(lt > -1){
				name = name.substring(0, lt);
			}

			baseClazz = getClassRef(classRefCache, model, name);
		}

		classInfo.setBaseClass(baseClazz);
	}
}
 
Example #4
Source File: SimplifyPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String createPropertyName(final Model model,
		CPropertyInfo propertyInfo, CElement element) {
	final String localPart;
	if (element instanceof CClassRef) {
		final CClassRef classRef = (CClassRef) element;
		final String fullName = classRef.fullName();
		localPart = fullName.substring(fullName.lastIndexOf('.') + 1);
	} else {
		localPart = element.getElementName().getLocalPart();
	}
	final String propertyName = model.getNameConverter().toPropertyName(
			pluralizeIfNecessary(propertyInfo, localPart));
	return propertyName;
}
 
Example #5
Source File: InheritancePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private JClass generateExtends(ClassOutline classOutline,
		Map<String, JClass> knownClasses,
		Map<JClass, CClassInfo> knownClassInfos) {
	final JDefinedClass theClass = classOutline.implClass;
	final CPluginCustomization extendsClassCustomization = CustomizationUtils
			.findCustomization(classOutline,
					Customizations.EXTENDS_ELEMENT_NAME);
	JClass targetClass = generateExtends(theClass,
			extendsClassCustomization, knownClasses);

	final CClassInfo classInfo = classOutline.target;
	if (targetClass != null && classInfo.getBaseClass() == null
			&& classInfo.getRefBaseClass() == null) {
		final CClassInfo targetClassInfo = knownClassInfos.get(targetClass);
		if (targetClassInfo == null && classInfo.getRefBaseClass() == null) {
			final Model model = classInfo.model;
			// BIEnum as BIClass is protected too much
			final BIEnum decl = new BIEnum();
			decl.ref = targetClass.fullName();
			final CClassRef baseClass = new CClassRef(model,
					classInfo.getSchemaComponent(), decl,
					new CCustomizations());
			classInfo.setBaseClass(baseClass);
		} else if (targetClassInfo != null
				&& classInfo.getBaseClass() == null) {
			classInfo.setBaseClass(targetClassInfo);
		}
	}
	return targetClass;
}
 
Example #6
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected String getLocalName(CClassRef info) {
	final String fullName = info.fullName();
	try {
		final Class<?> _class = Class.forName(fullName);
		return getLocalName(_class);
	} catch (ClassNotFoundException cnfex) {
		return getLocalName(fullName);
	}
}
 
Example #7
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private MContainer getContainer(final Class<?> _class) {
	final Class<?> enclosingClass = _class.getEnclosingClass();
	if (enclosingClass == null) {
		return getPackage(_class);
	} else {
		final BIEnum decl = new BIEnum();
		decl.ref = _class.getName();
		final CClassRef enclosingClassRef = new CClassRef(getTypeInfoSet(),
				null, decl, new CCustomizations());
		return createClassRef(enclosingClassRef);
	}
}
 
Example #8
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected MContainer getContainer(CClassRef info) {
	final String fullName = info.fullName();
	try {
		final Class<?> _class = Class.forName(fullName);
		return getContainer(_class);
	} catch (ClassNotFoundException cnfex) {
		return getPackage(info);
	}
}
 
Example #9
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected MTypeInfo<NType, NClass> getTypeInfo(CTypeInfo typeInfo) {
	if (typeInfo instanceof CClassRef) {
		return getTypeInfo((CClassRef) typeInfo);
	} else {
		return super.getTypeInfo(typeInfo);
	}
}
 
Example #10
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected MClassRefOrigin createClassRefOrigin(CClassRef info) {
	return new XJCCMClassRefOrigin(info);
}
 
Example #11
Source File: XJCCMClassRefOrigin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public XJCCMClassRefOrigin(CClassRef source) {
	Validate.notNull(source);
	this.source = source;
}
 
Example #12
Source File: XJCCMClassRefOrigin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CClassRef getSource() {
	return source;
}
 
Example #13
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected MPackageInfo getPackage(CClassRef info) {
	final String fullName = info.fullName();
	return getPackage(fullName);
}
 
Example #14
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 #15
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 #16
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected MClassRef<NType, NClass> createClassRef(CClassRef info) {
	final NClass targetType = getClazz(info);
	return new CMClassRef<NType, NClass>(createClassRefOrigin(info),
			targetType, loadClass(targetType), getPackage(info),
			getContainer(info), getLocalName(info));
}
 
Example #17
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected NClass getClazz(CClassRef info) {
	return info;
}