Java源码示例:com.sun.tools.xjc.model.CElementInfo

示例1
private MContainer getContainer(CClassInfoParent parent) {
	return parent.accept(new Visitor<MContainer>() {

		public MContainer onBean(CClassInfo bean) {
			return getTypeInfo(bean);
		}

		public MContainer onPackage(JPackage pkg) {
			return getPackage(pkg);
		}

		public MContainer onElement(CElementInfo element) {
			return getElementInfo(element);
		}
	});
}
 
示例2
private MPackageInfo getPackage(CClassInfoParent parent) {

		return parent.accept(new Visitor<MPackageInfo>() {

			public MPackageInfo onBean(CClassInfo bean) {
				return getPackage(bean.parent());
			}

			public MPackageInfo onPackage(JPackage pkg) {
				return getPackage(pkg);
			}

			public MPackageInfo onElement(CElementInfo element) {
				return getPackage(element.parent);
			}
		});

	}
 
示例3
public static Set<JType> getPossibleTypes(Outline outline, Aspect aspect,
		CTypeInfo typeInfo) {

	final Set<JType> types = new HashSet<JType>();

	types.add(typeInfo.getType().toType(outline, aspect));
	if (typeInfo instanceof CElementInfo) {

		final CElementInfo elementInfo = (CElementInfo) typeInfo;
		for (CElementInfo substitutionMember : elementInfo
				.getSubstitutionMembers()) {
			types.addAll(getPossibleTypes(outline, aspect,
					substitutionMember));
		}
	}
	return types;
}
 
示例4
@Override
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {
	for (final ClassOutline classOutline : outline.getClasses()) {
		if (classOutline.target.getElementName() != null) {
			processGlobalElement(classOutline);
		} else {
			processGlobalComplexType(classOutline);
		}
	}
	for (final CElementInfo elementInfo : outline.getModel()
			.getAllElements()) {
		final ElementOutline elementOutline = outline
				.getElement(elementInfo);
		if (elementOutline != null) {
			processGlobalJAXBElement(elementOutline);
		}
	}
	return true;
}
 
示例5
public static TypeUse getTypeUse(ProcessModel processModel,
		CPropertyInfo propertyInfo) {
	if (propertyInfo instanceof CValuePropertyInfo) {
		return ((CValuePropertyInfo) propertyInfo).getTarget();
	} else if (propertyInfo instanceof CAttributePropertyInfo) {
		return ((CAttributePropertyInfo) propertyInfo).getTarget();
	} else {
		final CTypeInfo type = propertyInfo.ref().iterator().next();
		if (type instanceof CBuiltinLeafInfo) {
			if (propertyInfo.getAdapter() != null) {
				return TypeUseFactory.adapt((CBuiltinLeafInfo) type,
						propertyInfo.getAdapter());
			} else {
				return (CBuiltinLeafInfo) type;
			}
		} else if (type instanceof CElementInfo) {
			final CElementInfo elementInfo = (CElementInfo) type;
			return getTypeUse(processModel, elementInfo.getProperty());
		} else {
			throw new AssertionError("Unexpected type.");
		}
	}

}
 
示例6
public TypeUse getTypeUse(C context, CPropertyInfo propertyInfo) {
	if (propertyInfo instanceof CValuePropertyInfo) {
		return ((CValuePropertyInfo) propertyInfo).getTarget();
	} else if (propertyInfo instanceof CAttributePropertyInfo) {
		return ((CAttributePropertyInfo) propertyInfo).getTarget();
	} else {
		final CTypeInfo type = propertyInfo.ref().iterator().next();
		if (type instanceof CBuiltinLeafInfo) {
			if (propertyInfo.getAdapter() != null) {
				return TypeUseFactory.adapt((CBuiltinLeafInfo) type,
						propertyInfo.getAdapter());
			} else {
				return (CBuiltinLeafInfo) type;
			}
		} else if (type instanceof CElementInfo) {
			final CElementInfo elementInfo = (CElementInfo) type;
			return getTypeUse(context, elementInfo.getProperty());
		} else {
			throw new AssertionError("Unexpected type.");
		}
	}

}
 
示例7
public static List<CPluginCustomization> findCustomizations(CElementInfo elementInfo, QName name) {
	final CCustomizations customizations = CustomizationUtils.getCustomizations(elementInfo);

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

	for (CPluginCustomization pluginCustomization : customizations) {
		if (fixNull(pluginCustomization.element.getNamespaceURI()).equals(name.getNamespaceURI())
				&& fixNull(pluginCustomization.element.getLocalName()).equals(name.getLocalPart())) {
			pluginCustomization.markAsAcknowledged();
			pluginCustomizations.add(pluginCustomization);
		}
	}

	return pluginCustomizations;
}
 
示例8
public static CPluginCustomization findCustomization(CElementInfo elementInfo, QName name) {
	final CCustomizations customizations = CustomizationUtils.getCustomizations(elementInfo);
	final CPluginCustomization customization = customizations.find(name.getNamespaceURI(), name.getLocalPart());
	if (customization != null) {
		customization.markAsAcknowledged();
	}
	return customization;
}
 
示例9
protected CElementInfo getElementInfo() {
	final CReferencePropertyInfo referencePropertyInfo = (CReferencePropertyInfo) core;

	final Collection<CElement> elements = referencePropertyInfo
			.getElements();

	final CElement element = elements.iterator().next();

	final CElementInfo elementInfo = (CElementInfo) element.getType();
	return elementInfo;
}
 
示例10
@Override
public JExpression unwrapCondifiton(JExpression source) {

	final CReferencePropertyInfo core = (CReferencePropertyInfo) this.core;

	JExpression predicate = null;
	if (core.getElements().isEmpty()) {
		predicate = null;
	} else {
		for (CElement element : core.getElements()) {
			if (element instanceof CElementInfo) {
				CElementInfo elementinfo = (CElementInfo) element;

				final SingleWrappingReferenceElementInfoField field = new SingleWrappingReferenceElementInfoField(
						outline, prop, core, elementinfo);
				final JExpression condition = field
						.unwrapCondifiton(source);
				predicate = (predicate == null) ? condition : JOp.cor(
						predicate, condition);
			} else {
				// TODO Other cases currently not supported.
			}
		}
	}

	final JExpression isElement = codeModel.ref(JAXBContextUtils.class)
			.staticInvoke("isElement").arg(contextPath).arg(source);
	return predicate == null ? isElement : JOp.cand(JOp.not(predicate),
			isElement);
}
 
示例11
public CElementInfo getElementInfo(ProcessModel context,
		final CReferencePropertyInfo referencePropertyInfo) {
	final CElement element = context.getGetTypes()
			.getElements(context, referencePropertyInfo).iterator().next();
	assert element instanceof CElementInfo;

	final CElementInfo elementInfo = (CElementInfo) element;
	return elementInfo;
}
 
示例12
public CBuiltinLeafInfo getTypeUse(ProcessModel context,
		CPropertyInfo propertyInfo) {
	
	final Collection<? extends CTypeInfo> types = context.getGetTypes().process(
			context, propertyInfo);

	final CElementInfo elementInfo = ((CElementInfo) types
			.iterator().next());

	final CBuiltinLeafInfo type = (CBuiltinLeafInfo) elementInfo
			.getContentType();

	return type;
}
 
示例13
private CClassInfoParent.Package getPackageInfo(CClassInfoParent parent) {
	if (parent instanceof CClassInfoParent.Package) {
		return (Package) parent;
	} else if (parent instanceof CClassInfo) {
		return getPackageInfo(((CClassInfo) parent).parent());
	} else if (parent instanceof CElementInfo) {
		return getPackageInfo(((CElementInfo) parent).parent);
	} else {
		throw new AssertionError("Unexpexted class info parent [" + parent
				+ "].");
	}

}
 
示例14
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;
}
 
示例15
/**
 * Build class name to element name mapping
 * 
 * @param outline, JAXB schema/code model
 * @return class name to element name map
 */
private static Map<String, QName> buildClass2ElementMapping(Outline outline) {
	Map<String, QName> mapping = new HashMap<String, QName>();
	for(CElementInfo ei : outline.getModel().getAllElements()) {
        JType exposedType = ei.getContentInMemoryType().toType(outline,Aspect.EXPOSED);
        mapping.put(exposedType.fullName(), ei.getElementName());
	}
	return mapping;
}
 
示例16
public CMElementOutlineGenerator(Outline outline, CElementInfo elementInfo) {
	Validate.notNull(outline);
	Validate.notNull(elementInfo);
	this.outline = outline;
	this.elementInfo = elementInfo;
}
 
示例17
@Override
protected MPackageInfo getPackage(CElementInfo info) {
	return getPackage(info.parent);
}
 
示例18
@Override
protected MContainer getContainer(CElementInfo info) {
	final CClassInfoParent parent = info.parent;
	return parent == null ? null : getContainer(parent);
}
 
示例19
@Override
protected String getLocalName(CElementInfo info) {
	return info.shortName();
}
 
示例20
@Override
protected MElementInfoOrigin createElementInfoOrigin(CElementInfo info) {
	return new XJCCMElementInfoOrigin(info);
}
 
示例21
public XJCCMElementInfoOrigin(CElementInfo source) {
	super(source);
	component = source.getSchemaComponent() != null ? source
			.getSchemaComponent() : source.getProperty()
			.getSchemaComponent();
}
 
示例22
public static CCustomizations getCustomizations(final CElementInfo elementInfo) {
	return elementInfo.getCustomizations();
}
 
示例23
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);
	}
}
 
示例24
@Override
protected CElementInfo getElementInfo() {
	return elementInfo;
}
 
示例25
public SingleWrappingReferenceElementInfoField(ClassOutlineImpl context,
		CPropertyInfo property, CReferencePropertyInfo core, CElementInfo elementInfo) {
	super(context, property, core);
	this.elementInfo = elementInfo;
}
 
示例26
@Override
	protected JExpression wrap(JExpression target) {

		final CReferencePropertyInfo referencePropertyInfo = (CReferencePropertyInfo) core;

		final Collection<CElement> elements = referencePropertyInfo
				.getElements();

		final CElement element = elements.iterator().next();

		final CElementInfo elementInfo = (CElementInfo) element.getType();

//		final CNonElement type = elementInfo.getProperty().ref().iterator()
//				.next();

		final JClass scope = getScope(elementInfo.getScope());

		final QName name = elementInfo.getElementName();

		return codeModel.ref(JAXBContextUtils.class).staticInvoke(
				"unmarshalJAXBElement").arg(contextPath).arg(
				JExprUtils.newQName(codeModel, name)).arg(scope.dotclass())
				.arg(target);
	}
 
示例27
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;
}