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

The following examples show how to use com.sun.tools.xjc.model.nav.NClass. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected NClass getClazz(final Class<?> _clas) {
	return new NClass() {

		@Override
		public boolean isBoxedType() {
			return false;
		}

		@Override
		public String fullName() {
			return _clas.getName();
		}

		@Override
		public JClass toType(Outline o, Aspect aspect) {
			return o.getCodeModel().ref(_clas);
		}

		@Override
		public boolean isAbstract() {
			return false;
		}
	};
}
 
Example #8
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 #9
Source File: CodeModelProgramWriter.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void writeProgram(Module<NType, NClass> module, JSProgram program,
		Output output) {
	try {
		final JPackage _package = codeModel._package(output
				.getOutputPackageName());
		_package.addResourceFile(createTextFile(output.getFileName(),
				program));
	} catch (IOException ioex) {
		try {
			errorHandler.error(new SAXParseException(MessageFormat.format(
					"Could not create the code for the module [{0}].",
					module.getName()), null, ioex));
		} catch (SAXException ignored) {

		}
	}
}
 
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: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected NClass getClazz(final String className) {
	return new NClass() {

		@Override
		public boolean isBoxedType() {
			return false;
		}

		@Override
		public String fullName() {
			return className;
		}

		@Override
		public JClass toType(Outline o, Aspect aspect) {
			return o.getCodeModel().ref(className);
		}

		@Override
		public boolean isAbstract() {
			return false;
		}
	};
}
 
Example #12
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 #13
Source File: MultiplicityCounterElements01Test.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void es02aOrB() throws Exception {

	final MClassInfo<NType, NClass> eType = model.getClassInfo("test.Es02");
	final MPropertyInfo<NType, NClass> a = eType.getProperty("aOrB");
	final Multiplicity multiplicity = new XSFunctionApplier<Multiplicity>(
			ParticleMultiplicityCounter.INSTANCE).apply(a.getOrigin());

	Assert.assertEquals(50, multiplicity.min.intValue());
	Assert.assertEquals(400, multiplicity.max.intValue());

}
 
Example #14
Source File: ElementWrapperPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void processWrappedElementRefPropertyInfo(
		final MModelInfo<NType, NClass> mmodel,
		final MClassInfo<NType, NClass> rootClassInfo,
		final MElementPropertyInfo<NType, NClass> wrapperPropertyInfo,
		final MClassInfo<NType, NClass> wrapperClassInfo,
		final MElementRefPropertyInfo<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 CMElementRefPropertyInfo<NType, NClass>(
			new DummyPropertyInfoOrigin(), wrapperClassInfo,
			wrapperPropertyInfo.getPrivateName(),
			wrappedPropertyInfo.isCollection(),
			wrappedPropertyInfo.isRequired(),
			wrappedPropertyInfo.getTypeInfo(),
			wrappedPropertyInfo.getElementName(),
			wrapperPropertyInfo.getElementName(),
			wrappedPropertyInfo.isMixed(),
			wrappedPropertyInfo.isDomAllowed(),
			wrappedPropertyInfo.isTypedObjectAllowed(),
			wrappedPropertyInfo.getDefaultValue(),
			wrappedPropertyInfo.getDefaultValueNamespaceContext());

	rootClassInfo.addProperty(propertyInfo);

	// TODO
	rootClassInfo.removeProperty(wrapperPropertyInfo);
	mmodel.removeClassInfo(wrapperClassInfo);
}
 
Example #15
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 #16
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 #17
Source File: AlphaMInfoFactoryTest.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void createsCorrectTypeNameForNamedComplexType() {
	final MClassInfo<NType, NClass> classInfo = MODEL_INFO
			.getClassInfo(getClass().getPackage().getName() + "."
					+ "NamedComplexType");
	Assert.assertEquals(new QName("urn:test", "NamedComplexType"),
			classInfo.getTypeName());
}
 
Example #18
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 #19
Source File: AlphaMInfoFactoryTest.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void createsCorrectTypeNameForKnownReferencedType() {
	final QName typeName = new QName("urn:test", "KnownReferencedType",
			"test");
	final MElementInfo<NType, NClass> elementInfo = MODEL_INFO
			.getGlobalElementInfo(new QName("urn:test",
					"KnownReferencedTypeElement"));
	final MTypeInfo<NType, NClass> typeInfo = elementInfo.getTypeInfo();
	Assert.assertNotNull(typeInfo);
	Assert.assertEquals(QNameUtils.getKey(typeName),
			QNameUtils.getKey(typeInfo.getTypeName()));
}
 
Example #20
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 #21
Source File: TargetDirectoryJsonStructureWriter.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void writeJsonStructure(Module<NType, NClass> module,
		JsonStructure schema, String fileName) {
	try {
		writeStructure(targetDirectory, "", fileName, schema);
	} catch (IOException ioex) {
		errorReceiver.error(new SAXParseException(MessageFormat.format(
				"Could not create the code for the module [{0}].",
				module.getName()), null, ioex));
	}
}
 
Example #22
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 #23
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 #24
Source File: CMPropertyOutlineGenerator.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) {

	final FieldOutline fieldOutline = outline.getField(this.propertyInfo);

	final MPropertyAccessorFactory propertyAccessorFactory = new CMPropertyAccessorFactory(
			this.fieldAccessorFactory, fieldOutline);
	return new CMPropertyOutline(classOutline, propertyInfo,
			propertyAccessorFactory);
}
 
Example #25
Source File: CMPackageOutlineGenerator.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public MPackageOutline generate(MModelOutline parent,
		MModelInfo<NType, NClass> modelInfo, MPackageInfo packageInfo) {
	final PackageOutline packageOutline = outline
			.getPackageContext(this.packageInfo);
	Validate.notNull(packageOutline);
	return new CMPackageOutline(parent, packageInfo, packageOutline);
}
 
Example #26
Source File: CMEnumOutline.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CMEnumOutline(MModelOutline parent, MPackageOutline packageOutline,
		MEnumLeafInfo<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 #27
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 #28
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 #29
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 #30
Source File: ConstantPropertyOutline.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ConstantPropertyOutline(Outline outline, MClassOutline classOutline,
		MPropertyInfo<NType, NClass> target, final JExpression value) {
	super(outline, classOutline, target);
	Validate.notNull(value);
	this.value = value;
	this.field = generateField();
}