}
}
protected JavaSource getObjectFactory(SchemaSG pController, String pPackageName, List pContextList) {
JavaQName qName = JavaQNameImpl.getInstance(pPackageName, "ObjectFactory");
JavaSource js = pController.getJavaSourceFactory().newJavaSource(qName, "public");
JavaField jf = js.newJavaField("jaxbContext", JAXBContextImpl.class, "private");
JavaField properties = js.newJavaField("properties", Map.class, "private");
JavaConstructor jcon = js.newJavaConstructor("public");
jcon.addThrows(JAXBException.class);
jcon.addLine(jf, " = (", JAXBContextImpl.class, ") ",
JAXBContext.class, ".newInstance(",
JavaSource.getQuoted(pPackageName), ");");
JavaMethod newInstanceMethod = js.newJavaMethod("newInstance", Object.class, "public");
newInstanceMethod.addThrows(JAXBException.class);
Parameter pElementInterface = newInstanceMethod.addParam(Class.class, "pElementInterface");
newInstanceMethod.addLine("return ", jf, ".getElement(", pElementInterface, ");");
{
JavaMethod getPropertyMethod = js.newJavaMethod("getProperty", Object.class, "public");
Parameter pName = getPropertyMethod.addParam(String.class, "pName");
getPropertyMethod.addIf(properties, " == null");
getPropertyMethod.addLine("return null;");
getPropertyMethod.addEndIf();
getPropertyMethod.addLine("return ", properties, ".get(", pName, ");");
}
{
JavaMethod setPropertyMethod = js.newJavaMethod("setProperty", void.class, "public");
Parameter pName = setPropertyMethod.addParam(String.class, "pName");
Parameter pValue = setPropertyMethod.addParam(Object.class, "pValue");
setPropertyMethod.addIf(properties, " == null");
setPropertyMethod.addLine(properties, " = new ", HashMap.class, "();");
setPropertyMethod.addEndIf();
setPropertyMethod.addLine(properties, ".put(", pName, ", ", pValue, ");");
}
for (Iterator iter = pContextList.iterator(); iter.hasNext(); ) {
Object o = iter.next();
if (!(o instanceof ObjectSG)) {
continue;
}
ObjectSG objectSG = (ObjectSG) o;
TypeSG typeSG = objectSG.getTypeSG();
if (!typeSG.isComplex()) {
continue;
}
ComplexTypeSG complexTypeSG = typeSG.getComplexTypeSG();
JavaQName resultName = complexTypeSG.getClassContext().getXMLInterfaceName();
String className = resultName.getClassName();
String methodName = "create" + Character.toUpperCase(className.charAt(0)) + className.substring(1);
JavaMethod createMethod = js.newJavaMethod(methodName, resultName, "public");
createMethod.addThrows(JAXBException.class);
createMethod.addLine("return (", resultName, ") newInstance(", resultName, ".class);");
}
return js;