📄 modelservicereader.java
字号:
} else {
Debug.logWarning("No child nodes found.", module);
}
if (this.isFromURL) {
utilTimer.timerString("Finished file " + readerURL + " - Total Services: " + i + " FINISHED");
Debug.logImportant("Loaded " + i + " Service definitions from " + readerURL, module);
} else {
utilTimer.timerString("Finished document in " + handler + " - Total Services: " + i + " FINISHED");
if (Debug.importantOn()) {
String resourceLocation = handler.getLocation();
try {
resourceLocation = handler.getURL().toExternalForm();
} catch (GenericConfigException e) {
Debug.logError(e, "Could not get resource URL", module);
}
Debug.logImportant("Loaded " + i + " Service definitions from " + resourceLocation, module);
}
}
}
}
}
return modelServices;
}
/**
* Gets an Service object based on a definition from the specified XML Service descriptor file.
* @param serviceName The serviceName of the Service definition to use.
* @return An Service object describing the specified service of the specified descriptor file.
*/
public ModelService getModelService(String serviceName) {
Map ec = getModelServices();
if (ec != null)
return (ModelService) ec.get(serviceName);
else
return null;
}
/**
* Creates a Iterator with the serviceName of each Service defined in the specified XML Service Descriptor file.
* @return A Iterator of serviceName Strings
*/
public Iterator getServiceNamesIterator() {
Collection collection = getServiceNames();
if (collection != null) {
return collection.iterator();
} else {
return null;
}
}
/**
* Creates a Collection with the serviceName of each Service defined in the specified XML Service Descriptor file.
* @return A Collection of serviceName Strings
*/
public Collection getServiceNames() {
Map ec = getModelServices();
return ec.keySet();
}
protected ModelService createModelService(Element serviceElement) {
ModelService service = new ModelService();
service.name = UtilXml.checkEmpty(serviceElement.getAttribute("name"));
service.engineName = UtilXml.checkEmpty(serviceElement.getAttribute("engine"));
service.location = UtilXml.checkEmpty(serviceElement.getAttribute("location"));
service.invoke = UtilXml.checkEmpty(serviceElement.getAttribute("invoke"));
service.defaultEntityName = UtilXml.checkEmpty(serviceElement.getAttribute("default-entity-name"));
// these default to true; if anything but true, make false
service.auth = "true".equalsIgnoreCase(serviceElement.getAttribute("auth"));
service.export = "true".equalsIgnoreCase(serviceElement.getAttribute("export"));
service.debug = "true".equalsIgnoreCase(serviceElement.getAttribute("debug"));
// this defaults to true; if anything but false, make it true
service.validate = !"false".equalsIgnoreCase(serviceElement.getAttribute("validate"));
service.useTransaction = !"false".equalsIgnoreCase(serviceElement.getAttribute("use-transaction"));
service.requireNewTransaction = !"false".equalsIgnoreCase(serviceElement.getAttribute("require-new-transaction"));
// get the timeout and convert to int
String timeoutStr = UtilXml.checkEmpty(serviceElement.getAttribute("transaction-timout"));
if (timeoutStr == null || timeoutStr.length() == 0) {
timeoutStr = "0";
}
int timeout = 0;
try {
timeout = Integer.parseInt(timeoutStr);
} catch (NumberFormatException e) {
Debug.logWarning(e, "Setting timeout to 0 (default)", module);
timeout = 0;
}
service.transactionTimeout = timeout;
service.description = getCDATADef(serviceElement, "description");
service.nameSpace = getCDATADef(serviceElement, "namespace");
service.contextInfo = new HashMap();
this.createPermGroups(serviceElement, service);
this.createImplDefs(serviceElement, service);
this.createAutoAttrDefs(serviceElement, service);
this.createAttrDefs(serviceElement, service);
this.createOverrideDefs(serviceElement, service);
return service;
}
protected String getCDATADef(Element baseElement, String tagName) {
String value = "";
NodeList nl = baseElement.getElementsByTagName(tagName);
// if there are more then one decriptions we will use only the first one
if (nl.getLength() > 0) {
Node n = nl.item(0);
NodeList childNodes = n.getChildNodes();
if (childNodes.getLength() > 0) {
Node cdata = childNodes.item(0);
value = UtilXml.checkEmpty(cdata.getNodeValue());
}
}
return value;
}
protected void createPermGroups(Element baseElement, ModelService model) {
List permGroups = UtilXml.childElementList(baseElement, "required-permissions");
Iterator permIter = permGroups.iterator();
while (permIter.hasNext()) {
Element element = (Element) permIter.next();
ModelPermGroup group = new ModelPermGroup();
group.joinType = element.getAttribute("join-type");
createPermissions(element, group, model);
model.permissionGroups.add(group);
}
}
protected void createPermissions(Element baseElement, ModelPermGroup group, ModelService service) {
List permElements = UtilXml.childElementList(baseElement, "check-permission");
List rolePermElements = UtilXml.childElementList(baseElement, "check-role-member");
// create the simple permissions
Iterator si = permElements.iterator();
while (si.hasNext()) {
Element element = (Element) si.next();
ModelPermission perm = new ModelPermission();
perm.nameOrRole = element.getAttribute("permission");
perm.action = element.getAttribute("action");
if (perm.action != null && perm.action.length() > 0) {
perm.permissionType = ModelPermission.ENTITY_PERMISSION;
} else {
perm.permissionType = ModelPermission.PERMISSION;
}
perm.serviceModel = service;
group.permissions.add(perm);
}
// create the role member permissions
Iterator ri = rolePermElements.iterator();
while (ri.hasNext()) {
Element element = (Element) ri.next();
ModelPermission perm = new ModelPermission();
perm.permissionType = ModelPermission.ROLE_MEMBER;
perm.nameOrRole = element.getAttribute("role-type");
perm.serviceModel = service;
group.permissions.add(perm);
}
}
protected void createImplDefs(Element baseElement, ModelService service) {
List implElements = UtilXml.childElementList(baseElement, "implements");
Iterator implIter = implElements.iterator();
while (implIter.hasNext()) {
Element implement = (Element) implIter.next();
String serviceName = UtilXml.checkEmpty(implement.getAttribute("service"));
if (serviceName.length() > 0)
service.implServices.add(serviceName);
}
}
protected void createAutoAttrDefs(Element baseElement, ModelService service) {
List autoElement = UtilXml.childElementList(baseElement, "auto-attributes");
Iterator autoIter = autoElement.iterator();
while (autoIter.hasNext()) {
Element element = (Element) autoIter.next();
createAutoAttrDef(element, service);
}
}
protected void createAutoAttrDef(Element autoElement, ModelService service) {
// get the entity name; first from the auto-attributes then from the service def
String entityName = UtilXml.checkEmpty(autoElement.getAttribute("entity-name"));
if (entityName == null || entityName.length() == 0) {
entityName = service.defaultEntityName;
if (entityName == null || entityName.length() == 0) {
Debug.logWarning("Auto-Attribute does not specify an entity-name; not default-entity on service definition", module);
}
}
// get the include type 'pk|nonpk|all'
String includeType = UtilXml.checkEmpty(autoElement.getAttribute("include"));
boolean includePk = "pk".equals(includeType) || "all".equals(includeType);
boolean includeNonPk = "nonpk".equals(includeType) || "all".equals(includeType);
// need a delegator for this
GenericDelegator delegator = dctx.getDelegator();
if (delegator == null) {
Debug.logWarning("Cannot use auto-attribute fields with a null delegator", module);
}
if (delegator != null && entityName != null) {
Map modelParamMap = new OrderedMap();
try {
ModelEntity entity = delegator.getModelEntity(entityName);
if (entity == null) {
throw new GeneralException("Could not find entity with name [" + entityName + "]");
}
Iterator fieldsIter = entity.getFieldsIterator();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -