📄 modelservicereader.java
字号:
if (fieldsIter != null) {
while (fieldsIter.hasNext()) {
ModelField field = (ModelField) fieldsIter.next();
if ((!field.getIsAutoCreatedInternal()) && ((field.getIsPk() && includePk) || (!field.getIsPk() && includeNonPk))) {
ModelFieldType fieldType = delegator.getEntityFieldType(entity, field.getType());
if (fieldType == null) {
throw new GeneralException("Null field type from delegator for entity [" + entityName + "]");
}
ModelParam param = new ModelParam();
param.entityName = entityName;
param.fieldName = field.getName();
param.name = field.getName();
param.type = fieldType.getJavaType();
param.mode = UtilXml.checkEmpty(autoElement.getAttribute("mode"));
param.optional = "true".equalsIgnoreCase(autoElement.getAttribute("optional")); // default to true
param.formDisplay = !"false".equalsIgnoreCase(autoElement.getAttribute("form-display")); // default to false
modelParamMap.put(field.getName(), param);
}
}
// get the excludes list; and remove those from the map
List excludes = UtilXml.childElementList(autoElement, "exclude");
if (excludes != null) {
Iterator excludesIter = excludes.iterator();
while (excludesIter.hasNext()) {
Element exclude = (Element) excludesIter.next();
modelParamMap.remove(UtilXml.checkEmpty(exclude.getAttribute("field-name")));
}
}
// now add in all the remaining params
Set keySet = modelParamMap.keySet();
Iterator setIter = keySet.iterator();
while (setIter.hasNext()) {
ModelParam thisParam = (ModelParam) modelParamMap.get(setIter.next());
//Debug.logInfo("Adding Param to " + service.name + ": " + thisParam.name + " [" + thisParam.mode + "] " + thisParam.type + " (" + thisParam.optional + ")", module);
service.addParam(thisParam);
}
}
} catch (GenericEntityException e) {
Debug.logError(e, "Problem loading auto-attributes [" + entityName + "] for " + service.name, module);
} catch (GeneralException e) {
Debug.logError(e, "Cannot load auto-attributes : " + e.getMessage() + " for " + service.name, module);
}
}
}
protected void createAttrDefs(Element baseElement, ModelService service) {
// Add in the defined attributes (override the above defaults if specified)
List paramElements = UtilXml.childElementList(baseElement, "attribute");
Iterator paramIter = paramElements.iterator();
while (paramIter.hasNext()) {
Element attribute = (Element) paramIter.next();
ModelParam param = new ModelParam();
param.name = UtilXml.checkEmpty(attribute.getAttribute("name"));
param.type = UtilXml.checkEmpty(attribute.getAttribute("type"));
param.mode = UtilXml.checkEmpty(attribute.getAttribute("mode"));
param.entityName = UtilXml.checkEmpty(attribute.getAttribute("entity-name"));
param.fieldName = UtilXml.checkEmpty(attribute.getAttribute("field-name"));
param.stringMapPrefix = UtilXml.checkEmpty(attribute.getAttribute("string-map-prefix"));
param.stringListSuffix = UtilXml.checkEmpty(attribute.getAttribute("string-list-suffix"));
param.formLabel = UtilXml.checkEmpty(attribute.getAttribute("form-label"));
param.optional = "true".equalsIgnoreCase(attribute.getAttribute("optional")); // default to true
param.formDisplay = !"false".equalsIgnoreCase(attribute.getAttribute("form-display")); // default to false
// set the entity name to the default if not specified
if (param.entityName.length() == 0) {
param.entityName = service.defaultEntityName;
}
// set the field-name to the name if entity name is specified but no field-name
if (param.fieldName.length() == 0 && param.entityName.length() > 0) {
param.fieldName = param.name;
}
service.addParam(param);
}
// Add the default optional parameters
ModelParam def = null;
// responseMessage
def = new ModelParam();
def.name = ModelService.RESPONSE_MESSAGE;
def.type = "String";
def.mode = "OUT";
def.optional = true;
def.internal = true;
service.addParam(def);
// errorMessage
def = new ModelParam();
def.name = ModelService.ERROR_MESSAGE;
def.type = "String";
def.mode = "OUT";
def.optional = true;
def.internal = true;
service.addParam(def);
// errorMessageList
def = new ModelParam();
def.name = ModelService.ERROR_MESSAGE_LIST;
def.type = "java.util.List";
def.mode = "OUT";
def.optional = true;
def.internal = true;
service.addParam(def);
// successMessage
def = new ModelParam();
def.name = ModelService.SUCCESS_MESSAGE;
def.type = "String";
def.mode = "OUT";
def.optional = true;
def.internal = true;
service.addParam(def);
// successMessageList
def = new ModelParam();
def.name = ModelService.SUCCESS_MESSAGE_LIST;
def.type = "java.util.List";
def.mode = "OUT";
def.optional = true;
def.internal = true;
service.addParam(def);
// userLogin
def = new ModelParam();
def.name = "userLogin";
def.type = "org.ofbiz.entity.GenericValue";
def.mode = "INOUT";
def.optional = true;
def.internal = true;
service.addParam(def);
// Locale
def = new ModelParam();
def.name = "locale";
def.type = "java.util.Locale";
def.mode = "INOUT";
def.optional = true;
def.internal = true;
service.addParam(def);
}
protected void createOverrideDefs(Element baseElement, ModelService service) {
List paramElements = UtilXml.childElementList(baseElement, "override");
Iterator paramIter = paramElements.iterator();
while (paramIter.hasNext()) {
Element attribute = (Element) paramIter.next();
String name = UtilXml.checkEmpty(attribute.getAttribute("name"));
ModelParam param = service.getParam(name);
boolean directToParams = true;
if (param == null) {
if (service.implServices.size() > 0 && !service.inheritedParameters) {
// create a temp def to place in the ModelService
// this will get read when we read implemented services
directToParams = false;
param = new ModelParam();
param.name = name;
} else {
Debug.logWarning("No parameter found for override parameter named: " + name, module);
}
}
if (param != null) {
// set only modified values
if (attribute.getAttribute("type") != null && attribute.getAttribute("type").length() > 0) {
param.name = UtilXml.checkEmpty(attribute.getAttribute("type"));
}
if (attribute.getAttribute("mode") != null && attribute.getAttribute("mode").length() > 0) {
param.mode = UtilXml.checkEmpty(attribute.getAttribute("mode"));
}
if (attribute.getAttribute("entity-name") != null && attribute.getAttribute("entity-name").length() > 0) {
param.entityName = UtilXml.checkEmpty(attribute.getAttribute("entity-name"));
}
if (attribute.getAttribute("field-name") != null && attribute.getAttribute("field-name").length() > 0) {
param.fieldName = UtilXml.checkEmpty(attribute.getAttribute("field-name"));
}
if (attribute.getAttribute("form-label") != null && attribute.getAttribute("form-label").length() > 0) {
param.formLabel = UtilXml.checkEmpty(attribute.getAttribute("form-label"));
}
if (attribute.getAttribute("optional") != null && attribute.getAttribute("optional").length() > 0) {
param.optional = "true".equalsIgnoreCase(attribute.getAttribute("optional")); // default to true
param.overrideOptional = true;
}
if (attribute.getAttribute("form-display") != null && attribute.getAttribute("form-display").length() > 0) {
param.formDisplay = !"false".equalsIgnoreCase(attribute.getAttribute("form-display")); // default to false
param.overrideFormDisplay = true;
}
if (directToParams) {
service.addParam(param);
} else {
service.overrideParameters.add(param);
}
}
}
}
protected Document getDocument(URL url) {
if (url == null)
return null;
Document document = null;
try {
document = UtilXml.readXmlDocument(url, true);
} catch (SAXException sxe) {
// Error generated during parsing)
Exception x = sxe;
if (sxe.getException() != null)
x = sxe.getException();
x.printStackTrace();
} catch (ParserConfigurationException pce) {
// Parser with specified options can't be built
pce.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return document;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -