isClassGlobal = !type.isSimple() && (type.isGlobal() || global);
} else {
throw new IllegalStateException("Unknown object type: " + pObject.getClass().getName());
}
Context myClassContext;
final boolean useTypesContext = pClassContext != null;
if (useTypesContext) {
myClassContext = pClassContext;
} else {
XSObject contextObject = pObject;
if (pObject instanceof XSElement) {
XSElement element = (XSElement) pObject;
if (element.isReference()) {
contextObject = pObject.getXSSchema().getElement(name);
}
}
myClassContext = new GlobalContext(name, contextObject, null, null, pSchema);
}
final JAXBProperty.BaseType baseType;
if (pObject instanceof JAXBPropertyOwner) {
JAXBProperty property = ((JAXBPropertyOwner) pObject).getJAXBProperty();
baseType = property == null ? null : property.getBaseType();
} else {
baseType = null;
}
if (isClassGlobal) {
if (type.isGlobal()) {
typeSG = pFactory.getTypeSG(type, baseType);
} else {
typeSG = pFactory.getTypeSG(type, myClassContext.getName(), baseType);
}
} else {
typeSG = pFactory.getTypeSG(type, myClassContext, name, baseType);
}
if (useTypesContext) {
if (typeSG.isComplex()) {
classContext = typeSG.getComplexTypeSG().getClassContext();
} else {
classContext = pClassContext;
}
} else if (typeSG.isComplex()) {
classContext = myClassContext;
Context tctx = typeSG.getComplexTypeSG().getClassContext();
AbstractContext ctx = (AbstractContext) classContext;
ctx.setPMName(tctx.getPMName());
ctx.setXMLSerializerName(tctx.getXMLSerializerName());
ctx.setXMLValidatorName(tctx.getXMLValidatorName());
} else {
classContext = null;
}
log.finest(mName, "<-", new Object[]{typeSG, classContext});
}