下面列出了javax.xml.bind.annotation.XmlAnyAttribute#com.sun.tools.xjc.model.nav.NClass 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
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;
}
@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) {
}
}
}
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;
}
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;
}
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;
}
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);
}
}
}
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);
}
}
}
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;
}
};
}
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;
}
};
}
@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;
}
};
}
@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;
}
@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));
}
}
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();
}
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);
}
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);
}
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));
}
}
protected void processWrappedElementsPropertyInfo(
final MModelInfo<NType, NClass> mmodel,
final MClassInfo<NType, NClass> rootClassInfo,
final MElementPropertyInfo<NType, NClass> wrapperPropertyInfo,
final MClassInfo<NType, NClass> wrapperClassInfo,
final MElementsPropertyInfo<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 CMElementsPropertyInfo<NType, NClass>(
new DummyPropertyInfoOrigin(), wrapperClassInfo,
wrapperPropertyInfo.getPrivateName(),
wrappedPropertyInfo.isCollection(),
wrappedPropertyInfo.isRequired(),
wrappedPropertyInfo.getElementTypeInfos(),
wrapperPropertyInfo.getElementName());
rootClassInfo.addProperty(propertyInfo);
// TODO
rootClassInfo.removeProperty(wrapperPropertyInfo);
mmodel.removeClassInfo(wrapperClassInfo);
}
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;
}
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;
}
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();
}
});
}
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;
}
}
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);
}
}
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);
}
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);
}
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;
}
@Override
protected MTypeInfo<NType, NClass> getTypeInfo(CTypeInfo typeInfo) {
if (typeInfo instanceof CClassRef) {
return getTypeInfo((CClassRef) typeInfo);
} else {
return super.getTypeInfo(typeInfo);
}
}
@Override
public void writeProgram(Module<NType, NClass> module,
JSProgram program, Output output) {
try {
writePrograms(targetDirectory, output.getDirectory(),
output.getFileName(), program);
} catch (IOException ioex) {
errorReceiver.error(new SAXParseException(MessageFormat.format(
"Could not create the code for the module [{0}].",
module.getName()), null, ioex));
}
}
@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;
}
}
@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());
}