use of org.glassfish.jaxb.core.v2.model.core.ClassInfo in project jaxb-ri by eclipse-ee4j.
the class XmlSchemaGenerator method add.
/**
* Adds a new class to the list of classes to be written.
*
* <p>
* A {@link ClassInfo} may have two namespaces --- one for the element name
* and the other for the type name. If they are different, we put the same
* {@link ClassInfo} to two {@link Namespace}s.
*/
public void add(ClassInfo<T, C> clazz) {
assert clazz != null;
String nsUri = null;
if (clazz.getClazz() == navigator.asDecl(CompositeStructure.class))
// this is a special class we introduced for JAX-WS that we *don't* want in the schema
return;
if (clazz.isElement()) {
// put element -> type reference
nsUri = clazz.getElementName().getNamespaceURI();
Namespace ns = getNamespace(nsUri);
ns.classes.add(clazz);
ns.addDependencyTo(clazz.getTypeName());
// schedule writing this global element
add(clazz.getElementName(), false, clazz);
}
QName tn = clazz.getTypeName();
if (tn != null) {
nsUri = tn.getNamespaceURI();
} else {
// anonymous type
if (nsUri == null)
return;
}
Namespace n = getNamespace(nsUri);
n.classes.add(clazz);
// search properties for foreign namespace references
for (PropertyInfo<T, C> p : clazz.getProperties()) {
n.processForeignNamespaces(p, 1);
if (p instanceof AttributePropertyInfo) {
AttributePropertyInfo<T, C> ap = (AttributePropertyInfo<T, C>) p;
String aUri = ap.getXmlName().getNamespaceURI();
if (aUri.length() > 0) {
// global attribute
getNamespace(aUri).addGlobalAttribute(ap);
n.addDependencyTo(ap.getXmlName());
}
}
if (p instanceof ElementPropertyInfo) {
ElementPropertyInfo<T, C> ep = (ElementPropertyInfo<T, C>) p;
for (TypeRef<T, C> tref : ep.getTypes()) {
String eUri = tref.getTagName().getNamespaceURI();
if (eUri.length() > 0 && !eUri.equals(n.uri)) {
getNamespace(eUri).addGlobalElement(tref);
n.addDependencyTo(tref.getTagName());
}
}
}
if (generateSwaRefAdapter(p))
n.useSwaRef = true;
MimeType mimeType = p.getExpectedMimeType();
if (mimeType != null) {
n.useMimeNs = true;
}
}
// recurse on baseTypes to make sure that we can refer to them in the schema
ClassInfo<T, C> bc = clazz.getBaseClass();
if (bc != null) {
add(bc);
n.addDependencyTo(bc.getTypeName());
}
}
use of org.glassfish.jaxb.core.v2.model.core.ClassInfo in project jaxb-ri by eclipse-ee4j.
the class AbstractMappingImpl method buildDrilldown.
/**
* Derived classes can use this method to implement {@link #calcDrilldown}.
*/
protected List<Property> buildDrilldown(CClassInfo typeBean) {
// they must not contain xsd:choice
if (containingChoice(typeBean)) {
return null;
}
List<Property> result;
CClassInfo bc = typeBean.getBaseClass();
if (bc != null) {
result = buildDrilldown(bc);
if (result == null) {
// aborted
return null;
}
} else {
result = new ArrayList<>();
}
for (CPropertyInfo p : typeBean.getProperties()) {
if (p instanceof CElementPropertyInfo) {
CElementPropertyInfo ep = (CElementPropertyInfo) p;
// wrong. A+,B,C is eligible for drill-down.
// if(ep.isCollection())
// // content model like A+,B,C is not eligible
// return null;
List<? extends CTypeRef> ref = ep.getTypes();
if (ref.size() != 1) {
// content model like (A|B),C is not eligible
return null;
}
result.add(createPropertyImpl(ep, ref.get(0).getTagName()));
} else if (p instanceof ReferencePropertyInfo) {
CReferencePropertyInfo rp = (CReferencePropertyInfo) p;
Collection<CElement> elements = rp.getElements();
if (elements.size() != 1) {
return null;
}
CElement ref = elements.iterator().next();
if (ref instanceof ClassInfo) {
result.add(createPropertyImpl(rp, ref.getElementName()));
} else {
CElementInfo eref = (CElementInfo) ref;
if (!eref.getSubstitutionMembers().isEmpty()) {
// elements with a substitution group isn't qualified for the wrapper style
return null;
}
// JAX-WS doesn't want to see JAXBElement, so we have to hide it for them.
ElementAdapter fr;
if (rp.isCollection()) {
fr = new ElementCollectionAdapter(parent.outline.getField(rp), eref);
} else {
fr = new ElementSingleAdapter(parent.outline.getField(rp), eref);
}
result.add(new PropertyImpl(this, fr, eref.getElementName()));
}
} else {
// according to the JAX-RPC spec 2.3.1.2, element refs are disallowed
return null;
}
}
return result;
}
use of org.glassfish.jaxb.core.v2.model.core.ClassInfo in project jaxb-ri by eclipse-ee4j.
the class XmlSchemaGenerator method writeEpisodeFile.
/**
* Writes out the episode file.
*/
public void writeEpisodeFile(XmlSerializer out) {
Bindings root = TXW.create(Bindings.class, out);
if (// otherwise jaxb binding NS should be the default namespace
namespaces.containsKey(""))
root._namespace(WellKnownNamespace.JAXB, "jaxb");
root.version("2.1");
// generate listing per schema
for (Map.Entry<String, Namespace> e : namespaces.entrySet()) {
Bindings group = root.bindings();
String prefix;
String tns = e.getKey();
if (!tns.equals("")) {
group._namespace(tns, "tns");
prefix = "tns:";
} else {
prefix = "";
}
group.scd("x-schema::" + (tns.equals("") ? "" : "tns"));
group.schemaBindings().map(false);
for (ClassInfo<T, C> ci : e.getValue().classes) {
// local type
if (ci.getTypeName() == null)
continue;
if (ci.getTypeName().getNamespaceURI().equals(tns)) {
Bindings child = group.bindings();
child.scd('~' + prefix + ci.getTypeName().getLocalPart());
child.klass().ref(ci.getName());
}
if (ci.isElement() && ci.getElementName().getNamespaceURI().equals(tns)) {
Bindings child = group.bindings();
child.scd(prefix + ci.getElementName().getLocalPart());
child.klass().ref(ci.getName());
}
}
for (EnumLeafInfo<T, C> en : e.getValue().enums) {
// local type
if (en.getTypeName() == null)
continue;
Bindings child = group.bindings();
child.scd('~' + prefix + en.getTypeName().getLocalPart());
child.klass().ref(navigator.getClassName(en.getClazz()));
}
group.commit(true);
}
root.commit();
}
Aggregations