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

The following examples show how to use com.sun.tools.xjc.model.CPluginCustomization. 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: EjbPlugin.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void checkCustomizations(CClassInfo classInfo,
		CPropertyInfo customizable) {

	for (CPluginCustomization pluginCustomization : CustomizationUtils
			.getCustomizations(customizable)) {
		if (!pluginCustomization.isAcknowledged()
				&& Customizations.NAMESPACE_URI
						.equals(pluginCustomization.element
								.getNamespaceURI())) {
			logger.warn("Unacknowledged customization [" +

			getName(pluginCustomization.element) + "] in the property ["
					+ classInfo.getName() + "."
					+ customizable.getName(true) + "].");

			pluginCustomization.markAsAcknowledged();
		}
	}

}
 
Example #2
Source File: CustomizationUtils.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static List<CPluginCustomization> findPropertyCustomizationsInProperty(CPropertyInfo propertyInfo,
		QName name) {

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

	final List<CPluginCustomization> propertyCustomizations = CustomizationUtils.getCustomizations(propertyInfo);

	for (CPluginCustomization propertyCustomization : propertyCustomizations) {
		if (fixNull(propertyCustomization.element.getNamespaceURI()).equals(name.getNamespaceURI())
				&& fixNull(propertyCustomization.element.getLocalName()).equals(name.getLocalPart())) {
			propertyCustomization.markAsAcknowledged();
			foundPropertyCustomizations.add(propertyCustomization);
		}
	}
	return foundPropertyCustomizations;
}
 
Example #3
Source File: EjbPlugin.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void checkCustomizations(CClassInfo customizable) {

		for (final CPluginCustomization pluginCustomization : CustomizationUtils
				.getCustomizations(customizable)) {
			final Element element = pluginCustomization.element;

			if (!pluginCustomization.isAcknowledged()
			// && Customizations.NAMESPACE_URI.equals(element
			// .getNamespaceURI())
			) {
				logger.warn("Unacknowledged customization [" +

				getName(element) + "] in the class [" + customizable.getName()
						+ "].");

				pluginCustomization.markAsAcknowledged();

			}
		}

	}
 
Example #4
Source File: InheritancePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private List<JClass> generateImplements(final JDefinedClass theClass,
		final List<CPluginCustomization> implementsInterfaceCustomizations,
		Map<String, JClass> knownClasses) throws AssertionError {
	final List<JClass> implementedInterfaces = new ArrayList<JClass>(
			implementsInterfaceCustomizations.size());
	for (final CPluginCustomization implementsInterfaceCustomization : implementsInterfaceCustomizations) {
		if (implementsInterfaceCustomization != null) {

			final ImplementsInterface implementsInterface = (ImplementsInterface) org.jvnet.jaxb2_commons.util.CustomizationUtils
					.unmarshall(Customizations.getContext(),
							implementsInterfaceCustomization);

			final JClass implementedInterface = generateImplements(
					theClass, implementsInterface, knownClasses);
			if (implementedInterface != null) {
				implementedInterfaces.add(implementedInterface);
			}
		}
	}
	return implementedInterfaces;
}
 
Example #5
Source File: AbstractAdaptPropertyInfo.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public final CCustomizations createCustomizations(ProcessModel context,
		CPropertyInfo propertyInfo) {
	final CCustomizations customizations = CustomizationUtils
			.getCustomizations(propertyInfo);

	final CCustomizations newCustomizations = new CCustomizations();
	if (customizations != null) {
		for (final CPluginCustomization customization : customizations) {
			if (Customizations.NAMESPACE_URI.equals(customization.element
					.getNamespaceURI())) {
				newCustomizations.add(customization);
			}
		}
	}
	return newCustomizations;
}
 
Example #6
Source File: Customizations.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static CPluginCustomization createCustomization$Ignored() {

		final CPluginCustomization customization = CustomizationUtils
				.createCustomization(Customizations.IGNORED_ELEMENT_NAME);
		customization.markAsAcknowledged();
		return customization;
	}
 
Example #7
Source File: CustomizationsPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void postProcessEnumLeafInfo(Model model, CEnumLeafInfo enumLeafInfo) {
	final String packagedClassName = ClassUtils.getPackagedClassName(enumLeafInfo);
	final String customizationsFileName = packagedClassName.replace(".", "/") + ".xml";
	
	final List<CPluginCustomization> customizations = readCustomizations(customizationsFileName);
	
	enumLeafInfo.getCustomizations().addAll(customizations);
	for (CEnumConstant enumConstant : enumLeafInfo.getConstants()) {
		postProcessEnumConstant(model, enumLeafInfo, enumConstant);
	}
}
 
Example #8
Source File: DefaultCustomizing.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> T unmarshalCustomization(
		final CPluginCustomization customization, T defaultValue,
		Merge<T> merge) throws AssertionError {
	if (customization == null) {
		return null;
	} else {
		final T value = (T) this.customizationsMap.get(customization);

		if (value != null)

		{
			// return value instanceof CopyTo ? (T) ((CopyTo) value)
			// .copyTo(((CopyTo) value).createNewInstance()) : value;
			return value;

		} else {
			final T t = (T) CustomizationUtils.unmarshall(
					Customizations.getContext(), customization);
			if (defaultValue != null) {
				Validate.notNull(merge);
				merge.merge(t, defaultValue);
			}
			this.customizationsMap.put(customization, t);
			return t;
			// return t instanceof CopyTo ? (T) ((CopyTo) t)
			// .copyTo(((CopyTo) t).createNewInstance()) : t;
		}
	}
}
 
Example #9
Source File: DefaultCustomizing.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private <T> Collection<T> unmarshalCustomizations(
		final Collection<CPluginCustomization> customizations)
		throws AssertionError {

	final List<T> unmarshalledCustomizations = new ArrayList<T>(
			customizations.size());
	for (CPluginCustomization customization : customizations) {
		unmarshalledCustomizations.add(this.<T> unmarshalCustomization(
				customization, null, null));
	}
	return unmarshalledCustomizations;

}
 
Example #10
Source File: DefaultCustomizing.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void addCustomization(CCustomizable customizable, QName name,
		Object customization) {
	final CPluginCustomization pluginCustomization = CustomizationUtils
			.addCustomization(customizable, Customizations.getContext(),
					name, customization);
	this.customizationsMap.put(pluginCustomization, customization);
}
 
Example #11
Source File: DefaultCustomizing.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> T findCustomization(CPropertyInfo propertyInfo, QName name) {
	final CPluginCustomization customization = CustomizationUtils
			.findCustomization(propertyInfo, name);
	final T t = (T) unmarshalCustomization(customization);
	return t;
}
 
Example #12
Source File: DefaultCustomizing.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private <T> T findCustomization(CPropertyInfo propertyInfo, QName name,
		T defaultValue, Merge<T> merge) {
	final CPluginCustomization customization = CustomizationUtils
			.findCustomization(propertyInfo, name);
	final T t = (T) unmarshalCustomization(customization, defaultValue,
			merge);
	return t;
}
 
Example #13
Source File: Customizations.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void markAsAcknowledged(
		final CPluginCustomization customization) {

	if (customization != null
			&& NAMESPACE_URI
					.equals(customization.element.getNamespaceURI())) {
		customization.markAsAcknowledged();

	}
}
 
Example #14
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 #15
Source File: Customizations.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static CPluginCustomization createCustomization$Generated() {

		final CPluginCustomization customization = CustomizationUtils
				.createCustomization(GENERATED_ELEMENT_NAME);
		customization.markAsAcknowledged();
		return customization;
	}
 
Example #16
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 #17
Source File: DefaultCreateDefaultVersionPropertyInfos.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CPluginCustomization createVersionCustomization(ProcessModel context,
		GeneratedVersion cversion) {
	final Version version = new Version();
	version.mergeFrom(cversion, version);
	final JAXBElement<Version> versionElement = Customizations
			.getCustomizationsObjectFactory().createVersion(version);

	return Customizations.createCustomization(versionElement);

}
 
Example #18
Source File: Customizations.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void _extends(CClassInfo classInfo, String className) {
	final ExtendsClass extendsClass = new ExtendsClass();
	extendsClass.setClassName(className);
	final CPluginCustomization customization = CustomizationUtils
			.marshal(getContext(), Customizations.EXTENDS_ELEMENT_NAME,
					extendsClass);
	classInfo.getCustomizations().add(customization);
	customization.markAsAcknowledged();

}
 
Example #19
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 #20
Source File: CustomizationsPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void postProcessClassInfo(Model model, CClassInfo classInfo) {
	final String packagedClassName = ClassUtils.getPackagedClassName(classInfo);
	final String customizationsFileName = packagedClassName.replace(".", "/") + ".xml";
	
	final List<CPluginCustomization> customizations = readCustomizations(customizationsFileName);
	
	classInfo.getCustomizations().addAll(customizations);
	
	for (CPropertyInfo propertyInfo: classInfo.getProperties())
	{
		postProcessPropertyInfo(model, classInfo, propertyInfo);
	}
}
 
Example #21
Source File: InheritancePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private List<JClass> generateImplements(ElementOutline elementOutline,
		Map<String, JClass> knownClasses) {
	final JDefinedClass theClass = elementOutline.implClass;
	final List<CPluginCustomization> implementsInterfaceCustomizations = CustomizationUtils
			.findCustomizations(elementOutline,
					Customizations.IMPLEMENTS_ELEMENT_NAME);
	return generateImplements(theClass, implementsInterfaceCustomizations,
			knownClasses);
}
 
Example #22
Source File: InheritancePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private List<JClass> generateImplements(EnumOutline enumOutline,
		Map<String, JClass> knownClasses) {
	final JDefinedClass theClass = enumOutline.clazz;
	final List<CPluginCustomization> implementsInterfaceCustomizations = CustomizationUtils
			.findCustomizations(enumOutline,
					Customizations.IMPLEMENTS_ELEMENT_NAME);
	return generateImplements(theClass, implementsInterfaceCustomizations,
			knownClasses);
}
 
Example #23
Source File: InheritancePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private List<JClass> generateImplements(ClassOutline classOutline,
		Map<String, JClass> knownClasses) {
	final JDefinedClass theClass = classOutline.implClass;
	final List<CPluginCustomization> implementsInterfaceCustomizations = CustomizationUtils
			.findCustomizations(classOutline,
					Customizations.IMPLEMENTS_ELEMENT_NAME);
	return generateImplements(theClass, implementsInterfaceCustomizations,
			knownClasses);
}
 
Example #24
Source File: InheritancePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private JClass generateExtends(final JDefinedClass theClass,
		final CPluginCustomization extendsClassCustomization,
		Map<String, JClass> knownClasses) throws AssertionError {
	if (extendsClassCustomization != null) {

		final ExtendsClass extendsClass = (ExtendsClass) CustomizationUtils
				.unmarshall(Customizations.getContext(),
						extendsClassCustomization);

		return generateExtends(theClass, extendsClass, knownClasses);
	} else {
		return null;
	}
}
 
Example #25
Source File: InheritancePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private JClass generateExtends(ElementOutline elementOutline,
		Map<String, JClass> knownClasses) {
	final JDefinedClass theClass = elementOutline.implClass;
	final CPluginCustomization extendsClassCustomization = CustomizationUtils
			.findCustomization(elementOutline,
					Customizations.EXTENDS_ELEMENT_NAME);
	return generateExtends(theClass, extendsClassCustomization,
			knownClasses);
}
 
Example #26
Source File: InheritancePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private JClass generateExtends(EnumOutline enumOutline,
		Map<String, JClass> knownClasses) {
	final JDefinedClass theClass = enumOutline.clazz;
	final CPluginCustomization extendsClassCustomization = CustomizationUtils
			.findCustomization(enumOutline,
					Customizations.EXTENDS_ELEMENT_NAME);
	return generateExtends(theClass, extendsClassCustomization,
			knownClasses);
}
 
Example #27
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 #28
Source File: InheritancePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void processPackageOutlines(Outline outline,
		Map<String, JClass> knownClasses) {
	List<CPluginCustomization> customizations = CustomizationUtils
			.findCustomizations(outline,
					Customizations.OBJECT_FACTORY_ELEMENT_NAME);

	for (CPluginCustomization customization : customizations) {
		final ObjectFactoryCustomization objectFactoryCustomization = (ObjectFactoryCustomization) CustomizationUtils
				.unmarshall(Customizations.getContext(), customization);

		final String packageName = objectFactoryCustomization
				.getPackageName();

		if (packageName != null) {
			for (PackageOutline packageOutline : outline
					.getAllPackageContexts()) {
				final JDefinedClass theClass = packageOutline
						.objectFactory();
				if (packageName.equals(packageOutline._package().name())) {
					ExtendsClass extendsClass = objectFactoryCustomization
							.getExtendsClass();
					if (extendsClass != null) {
						generateExtends(theClass, extendsClass,
								knownClasses);
					}
					List<ImplementsInterface> implementsInterfaces = objectFactoryCustomization
							.getImplementsInterface();
					if (implementsInterfaces != null) {
						for (ImplementsInterface implementsInterface : implementsInterfaces) {
							if (implementsInterface != null) {
								generateImplements(theClass,
										implementsInterface, knownClasses);
							}
						}
					}
				}
			}
		}
	}
}
 
Example #29
Source File: Customizations.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void _implements(CClassInfo classInfo,
		String... interfaceNames) {
	for (String interfaceName : interfaceNames) {
		final ImplementsInterface implementsInterface = new ImplementsInterface();
		implementsInterface.setInterfaceName(interfaceName);
		final CPluginCustomization customization = CustomizationUtils
				.marshal(getContext(),
						Customizations.IMPLEMENTS_ELEMENT_NAME,
						implementsInterface);
		customization.markAsAcknowledged();
		classInfo.getCustomizations().add(customization);
	}

}
 
Example #30
Source File: CustomizationUtils.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static CPropertyInfo findPropertyWithCustomization(CClassInfo classInfo, final QName name) {

		for (final CPropertyInfo propertyInfo : classInfo.getProperties()) {
			final CCustomizations customizations = getCustomizations(propertyInfo);
			final CPluginCustomization customization = customizations.find(name.getNamespaceURI(), name.getLocalPart());
			if (customization != null)
				return propertyInfo;
		}
		return null;
	}