com.sun.tools.xjc.model.nav.NType Java Examples

The following examples show how to use com.sun.tools.xjc.model.nav.NType. 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: ElementWrapperPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected void processWrapperElementPropertyInfo(
		final MModelInfo<NType, NClass> mmodel,
		final MClassInfo<NType, NClass> rootClassInfo,
		final MElementPropertyInfo<NType, NClass> wrapperPropertyInfo) {
	wrapperPropertyInfo.getTypeInfo().acceptTypeInfoVisitor(
			new DefaultTypeInfoVisitor<NType, NClass, Void>() {
				@Override
				public Void visitClassInfo(
						final MClassInfo<NType, NClass> wrapperClassInfo) {
					if (/*
						 * TODO !getIgnoring ( ).isIgnored ( classInfo ) &&
						 */wrapperClassInfo.getProperties().size() == 1) {
						final MPropertyInfo<NType, NClass> wrappedPropertyInfo = wrapperClassInfo
								.getProperties().get(0);

						if (wrappedPropertyInfo.isCollection()) {
							processWrappedPropertyInfo(mmodel,
									rootClassInfo, wrapperPropertyInfo,
									wrapperClassInfo, wrappedPropertyInfo);
						}
					}
					return null;
				}
			});
}
 
Example #2
Source File: CMClassOutline.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public CMClassOutline(MModelOutline parent, MPackageOutline packageOutline,
		MClassInfo<NType, NClass> target, MClassOutline superClassOutline,
		JDefinedClass referenceCode, JDefinedClass implementationCode,
		JClass implementationReferenceCode) {
	Validate.notNull(parent);
	Validate.notNull(packageOutline);
	Validate.notNull(target);
	Validate.notNull(referenceCode);
	Validate.notNull(implementationCode);
	Validate.notNull(implementationReferenceCode);
	this.parent = parent;
	this.packageOutline = packageOutline;
	this.target = target;
	this.superClassOutline = superClassOutline;
	this.referenceCode = referenceCode;
	this.implementationCode = implementationCode;
	this.implementationReferenceCode = implementationReferenceCode;
}
 
Example #3
Source File: JsonixPlugin.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public boolean run(Outline outline, Options opt,
		final ErrorHandler errorHandler) throws SAXException {

	final Model model = outline.getModel();
	final JCodeModel codeModel = outline.getCodeModel();

	final ProgramWriter<NType, NClass> programWriter = new CodeModelProgramWriter(
			codeModel, errorHandler);

	final JsonStructureWriter<NType, NClass> jsonStructureWriter = new CodeModelJsonStructureWriter(
			codeModel, errorHandler);

	new JsonixInvoker().execute(getSettings(), model, programWriter,
			jsonStructureWriter);

	return true;
}
 
Example #4
Source File: CMModelOutlineGenerator.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void generateEnumOutline(CMModelOutline modelOutline,
		MModelInfo<NType, NClass> modelInfo,
		MEnumLeafInfo<NType, NClass> enumLeafInfo)

{
	if (enumLeafInfo.getOrigin() instanceof EnumOutlineGeneratorFactory) {
		final MEnumOutlineGenerator generator = ((EnumOutlineGeneratorFactory) enumLeafInfo
				.getOrigin()).createGenerator(outline);
		final MEnumOutline enumOutline = generator.generate(modelOutline
				.getPackageOutline(enumLeafInfo.getPackageInfo()),
				modelInfo, enumLeafInfo);
		if (enumOutline != null) {
			modelOutline.addEnumOutline(enumOutline);
		}
	}
}
 
Example #5
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected NType createListType(final NType elementType) {

	return new NClass() {

		public boolean isBoxedType() {
			return false;
		}

		public String fullName() {
			return List.class.getName();
		}

		public JClass toType(Outline o, Aspect aspect) {
			return o.getCodeModel().ref(List.class)
					.narrow(elementType.toType(o, aspect).boxify());
		}

		public boolean isAbstract() {
			return false;
		}
	};
}
 
Example #6
Source File: AnnotatePropertyVisitor.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Void visitAttributePropertyInfo(
		MAttributePropertyInfo<NType, NClass> info) {

	JAnnotationUse annotation = this.annotatable
			.annotate(XmlAttribute.class);

	final String name = info.getAttributeName().getLocalPart();
	final String namespace = info.getAttributeName().getNamespaceURI();

	annotation.param("name", name);

	// generate namespace property?
	if (!namespace.equals("")) { // assume attributeFormDefault ==
									// unqualified
		annotation.param("namespace", namespace);
	}

	// TODO
	// if(info.isRequired()) {
	// xaw.required(true);
	// }

	return null;
}
 
Example #7
Source File: CMEnumOutlineGenerator.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public MEnumOutline generate(MPackageOutline parent,
		MModelInfo<NType, NClass> modelInfo,
		MEnumLeafInfo<NType, NClass> enumLeafInfo) {
	final EnumOutline eo = outline.getEnum(this.enumLeafInfo);

	final CMEnumOutline enumOutline = new CMEnumOutline(parent.getParent(),
			parent, enumLeafInfo, eo.clazz);

	for (MEnumConstantInfo<NType, NClass> enumConstantInfo : enumLeafInfo
			.getConstants()) {

		if (enumConstantInfo.getOrigin() instanceof EnumConstantOutlineGeneratorFactory) {
			final MEnumConstantOutlineGenerator generator = ((EnumConstantOutlineGeneratorFactory) enumConstantInfo
					.getOrigin()).createGenerator(outline);
			final MEnumConstantOutline enumConstantOutline = generator
					.generate(enumOutline, modelInfo, enumConstantInfo);
			if (enumConstantOutline != null) {
				enumOutline.addEnumConstantOutline(enumConstantOutline);
			}
		}
	}
	return enumOutline;
}
 
Example #8
Source File: AbstractPropertyOutline.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public AbstractPropertyOutline(Outline outline, MClassOutline classOutline,
		MPropertyInfo<NType, NClass> target) {
	Validate.notNull(outline);
	Validate.notNull(classOutline);
	Validate.notNull(target);
	this.outline = outline;
	this.modelOutline = classOutline.getParent();
	this.classOutline = classOutline;
	this.propertyInfo = target;
	this.codeModel = classOutline.getParent().getCode();

	this.referenceClass = classOutline.getReferenceCode();
	this.implementationClass = classOutline.getImplementationCode();
	this.implementationReferenceClass = classOutline
			.getImplementationReferenceCode();

	this.type = generateType();
}
 
Example #9
Source File: CMEnumConstantOutlineGenerator.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public MEnumConstantOutline generate(MEnumOutline parent,
		MModelInfo<NType, NClass> modelInfo,
		MEnumConstantInfo<NType, NClass> enumConstantInfo) {

	final CEnumLeafInfo eli = enumConstant.getEnclosingClass();

	final EnumOutline enumOutline = outline.getEnum(eli);

	for (EnumConstantOutline enumConstantOutline : enumOutline.constants) {
		if (enumConstantOutline.target == enumConstant) {
			return new CMEnumConstantOutline(parent, enumConstantInfo,
					enumConstantOutline.constRef);
		}
	}
	return null;
}
 
Example #10
Source File: CMModelOutlineGenerator.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void generateElementOutline(CMModelOutline modelOutline,
		MModelInfo<NType, NClass> modelInfo,
		MElementInfo<NType, NClass> elementInfo)

{
	if (elementInfo.getOrigin() instanceof ElementOutlineGeneratorFactory) {
		final MElementOutlineGenerator generator = ((ElementOutlineGeneratorFactory) elementInfo
				.getOrigin()).createGenerator(outline);
		final MElementOutline elementOutline = generator
				.generate(modelOutline.getPackageOutline(elementInfo
						.getPackageInfo()), modelInfo, elementInfo);
		if (elementOutline != null) {
			modelOutline.addElementOutline(elementOutline);
		}
	}
}
 
Example #11
Source File: ElementWrapperPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void postProcessModel(Model model,
		final MModelInfo<NType, NClass> mmodel, ErrorHandler errorHandler) {

	final Collection<MClassInfo<NType, NClass>> classInfos = new ArrayList<MClassInfo<NType, NClass>>(
			mmodel.getClassInfos());
	for (final MClassInfo<NType, NClass> rootClassInfo : classInfos) {
		if (/*
			 * TODO !getIgnoring().isIgnored(classInfo) &&
			 */true) {
			List<MPropertyInfo<NType, NClass>> properties = new ArrayList<MPropertyInfo<NType, NClass>>(
					rootClassInfo.getProperties());
			for (MPropertyInfo<NType, NClass> propertyInfo0 : properties) {

				propertyInfo0
						.acceptPropertyInfoVisitor(new DefaultPropertyInfoVisitor<NType, NClass, Void>() {

							@Override
							public Void visitElementPropertyInfo(
									final MElementPropertyInfo<NType, NClass> wrapperPropertyInfo) {

								processWrapperElementPropertyInfo(mmodel,
										rootClassInfo, wrapperPropertyInfo);
								return null;

							}
						});
			}
		}
	}

}
 
Example #12
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected Class<?> loadClass(NType referencedType) {
	final String name = referencedType.fullName();
	try {
		return Class.forName(name);
	} catch (ClassNotFoundException cnfex) {
		return null;
	}
}
 
Example #13
Source File: AbstractModelPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected MModelInfo<NType, NClass> getModel(Model model) {
	try {
		@SuppressWarnings("unchecked")
		final MModelInfo<NType, NClass> modelInfo = (MModelInfo<NType, NClass>) Ring
				.get(MModelInfo.class);
		return modelInfo;
	} catch (Throwable t) {
		final MModelInfo<NType, NClass> mmodel = new XJCCMInfoFactory(model)
				.createModel();
		Ring.add(MModelInfo.class, mmodel);
		return mmodel;
	}
}
 
Example #14
Source File: AlphaMInfoFactoryTest.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void createsCorrectTypeNameForUnnownReferencedType() {
	final MElementInfo<NType, NClass> elementInfo = MODEL_INFO
			.getGlobalElementInfo(new QName("urn:test",
					"UnknownReferencedTypeElement"));
	final MTypeInfo<NType, NClass> typeInfo = elementInfo.getTypeInfo();
	Assert.assertNotNull(typeInfo);
	Assert.assertNull(typeInfo.getTypeName());
}
 
Example #15
Source File: AlphaMInfoFactoryTest.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void createsCorrectTypeNameForStringElementType() {
	final MElementInfo<NType, NClass> elementInfo = MODEL_INFO
			.getGlobalElementInfo(new QName("urn:test", "StringElement"));
	Assert.assertNotNull(elementInfo);
	Assert.assertEquals(XmlSchemaConstants.STRING, elementInfo
			.getTypeInfo().getTypeName());
}
 
Example #16
Source File: AlphaMInfoFactoryTest.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void createsCorrectTypeNameForUnnamedSimpleType() {
	final MElementInfo<NType, NClass> elementInfo = MODEL_INFO
			.getGlobalElementInfo(new QName("urn:test",
					"UnnamedSimpleTypeElement"));
	Assert.assertNotNull(elementInfo);
	Assert.assertNull(elementInfo.getTypeInfo().getTypeName());
}
 
Example #17
Source File: AlphaMInfoFactoryTest.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void createsCorrectTypeNameForNamedSimpleType() {
	final MElementInfo<NType, NClass> elementInfo = MODEL_INFO
			.getGlobalElementInfo(new QName("urn:test",
					"NamedSimpleTypeElement"));
	Assert.assertNotNull(elementInfo);
	Assert.assertEquals(new QName("urn:test", "NamedSimpleType"),
			elementInfo.getTypeInfo().getTypeName());
}
 
Example #18
Source File: AbstractSinglePropertyOutline.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public AbstractSinglePropertyOutline(Outline outline,
		MClassOutline classOutline, MPropertyInfo<NType, NClass> target) {
	super(outline, classOutline, target);
	this.field = generateField();
	this.getter = generateGetter();
	this.setter = generateSetter();
}
 
Example #19
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected MClassTypeInfo<NType, NClass, ?> createBaseTypeInfo(
		CClassInfo info) {
	if (info.getBaseClass() != null) {
		return getTypeInfo(info.getBaseClass());
	} else if (info.getRefBaseClass() != null) {
		return getTypeInfo(info.getRefBaseClass());
	} else {
		return null;
	}
}
 
Example #20
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 #21
Source File: ElementWrapperPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void processWrappedElementPropertyInfo(
		final MModelInfo<NType, NClass> mmodel,
		final MClassInfo<NType, NClass> rootClassInfo,
		final MElementPropertyInfo<NType, NClass> wrapperPropertyInfo,
		final MClassInfo<NType, NClass> wrapperClassInfo,
		final MElementPropertyInfo<NType, NClass> wrappedPropertyInfo) {
	System.out.println("Class info:" + rootClassInfo.getName());
	System.out.println("Wrapper property info:"
			+ wrapperPropertyInfo.getPrivateName());
	System.out.println("Wrapper class info :" + wrapperClassInfo.getName());
	System.out.println("Wrapped property info:"
			+ wrappedPropertyInfo.getPrivateName());

	final MPropertyInfo<NType, NClass> propertyInfo = new CMElementPropertyInfo<NType, NClass>(
			new DummyPropertyInfoOrigin(), wrapperClassInfo,
			wrapperPropertyInfo.getPrivateName(),
			wrappedPropertyInfo.isCollection(),
			wrappedPropertyInfo.isRequired(),
			wrappedPropertyInfo.getTypeInfo(),
			wrappedPropertyInfo.getElementName(),
			wrapperPropertyInfo.getWrapperElementName(),
			wrappedPropertyInfo.isNillable(),
			wrappedPropertyInfo.getDefaultValue(),
			wrappedPropertyInfo.getDefaultValueNamespaceContext());

	rootClassInfo.addProperty(propertyInfo);

	// TODO
	rootClassInfo.removeProperty(wrapperPropertyInfo);
	mmodel.removeClassInfo(wrapperClassInfo);
}
 
Example #22
Source File: AlphaMInfoFactoryTest.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void createsCorrectTypeNameForUnnamedComplexType() {
	final MElementInfo<NType, NClass> elementInfo = MODEL_INFO
			.getGlobalElementInfo(new QName("urn:test",
					"UnnamedComplexTypeElement"));
	Assert.assertNotNull(elementInfo);
	Assert.assertNull(elementInfo.getTypeInfo().getTypeName());
}
 
Example #23
Source File: BuilderGenerator.java    From jaxb2-rich-contract-plugin with MIT License 5 votes vote down vote up
private void generateCollectionChoiceProperty(final PropertyOutline propertyOutline) {
	for (final PropertyOutline.TagRef tagRef : propertyOutline.getChoiceProperties()) {
		final TypeInfo<NType,NClass> typeInfo = tagRef.getTypeInfo();
		final QName elementName = tagRef.getTagName();
		final JType elementType = typeInfo.getType().toType(this.pluginContext.outline, Aspect.EXPOSED);
		generateAddMethods(
				propertyOutline,
				elementName,
				elementType,
				propertyOutline.getSchemaAnnotationText(tagRef).orElse(null));
	}
}
 
Example #24
Source File: CMModelOutlineGenerator.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void generatePackageOutline(CMModelOutline modelOutline,
		MModelInfo<NType, NClass> modelInfo, MPackageInfo packageInfo) {
	if (modelOutline.getPackageOutline(packageInfo) == null &&

	packageInfo.getOrigin() instanceof PackageOutlineGeneratorFactory) {
		final MPackageOutlineGenerator generator = ((PackageOutlineGeneratorFactory) packageInfo
				.getOrigin()).createGenerator(outline);
		final MPackageOutline packageOutline = generator.generate(
				modelOutline, modelInfo, packageInfo);
		modelOutline.addPackageOutline(packageOutline);

	}
}
 
Example #25
Source File: CMElementOutlineGenerator.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public MElementOutline generate(MPackageOutline parent,
		MModelInfo<NType, NClass> modelInfo,
		MElementInfo<NType, NClass> elementInfo) {
	final ElementOutline elementOutline = outline
			.getElement(this.elementInfo);
	if (elementOutline != null) {
		return new CMElementOutline(parent.getParent(), parent,
				elementInfo, elementOutline.implClass);
	} else {
		return null;
	}
}
 
Example #26
Source File: ElementWrapperPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void processWrappedElementRefsPropertyInfo(
		final MModelInfo<NType, NClass> mmodel,
		final MClassInfo<NType, NClass> rootClassInfo,
		final MElementPropertyInfo<NType, NClass> wrapperPropertyInfo,
		final MClassInfo<NType, NClass> wrapperClassInfo,
		final MElementRefsPropertyInfo<NType, NClass> wrappedPropertyInfo) {
	System.out.println("Class info:" + rootClassInfo.getName());
	System.out.println("Wrapper property info:"
			+ wrapperPropertyInfo.getPrivateName());
	System.out.println("Wrapper class info :" + wrapperClassInfo.getName());
	System.out.println("Wrapped property info:"
			+ wrappedPropertyInfo.getPrivateName());

	final MPropertyInfo<NType, NClass> propertyInfo = new CMElementRefsPropertyInfo<NType, NClass>(
			new DummyPropertyInfoOrigin(), wrapperClassInfo,
			wrapperPropertyInfo.getPrivateName(),
			wrappedPropertyInfo.isCollection(),
			wrappedPropertyInfo.isRequired(),
			wrappedPropertyInfo.getElementTypeInfos(),
			wrapperPropertyInfo.getElementName(),
			wrappedPropertyInfo.isMixed(),
			wrappedPropertyInfo.isDomAllowed(),
			wrappedPropertyInfo.isTypedObjectAllowed());

	rootClassInfo.addProperty(propertyInfo);

	// TODO
	rootClassInfo.removeProperty(wrapperPropertyInfo);
	mmodel.removeClassInfo(wrapperClassInfo);
}
 
Example #27
Source File: WrapperPropertyOutlineGenerator.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public MPropertyOutline generate(MClassOutline classOutline,
		MModelInfo<NType, NClass> modelInfo,
		MPropertyInfo<NType, NClass> propertyInfo) {
	return new CMPropertyOutline(classOutline, propertyInfo,
			new MPropertyAccessorFactory() {

				public MPropertyAccessor createPropertyAccessor(
						JExpression target) {
					// TODO
					throw new UnsupportedOperationException();
				}
			});
}
 
Example #28
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 #29
Source File: CMElementOutline.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CMElementOutline(MModelOutline parent,
		MPackageOutline packageOutline, MElementInfo<NType, NClass> target,
		JDefinedClass code) {
	Validate.notNull(parent);
	Validate.notNull(packageOutline);
	Validate.notNull(target);
	Validate.notNull(code);
	this.parent = parent;
	this.packageOutline = packageOutline;
	this.target = target;
	this.code = code;
}
 
Example #30
Source File: CMPropertyOutline.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CMPropertyOutline(MClassOutline classOutline,
		MPropertyInfo<NType, NClass> target,
		MPropertyAccessorFactory propertyAccessorFactory) {
	Validate.notNull(classOutline);
	Validate.notNull(target);
	Validate.notNull(propertyAccessorFactory);
	this.classOutline = classOutline;
	this.target = target;
	this.propertyAccessorFactory = propertyAccessorFactory;
}