📄 modelservicereader.java
字号:
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")); // set the max retry field String maxRetryStr = UtilXml.checkEmpty(serviceElement.getAttribute("max-retry")); int maxRetry = -1; if (!UtilValidate.isEmpty(maxRetryStr)) { try { maxRetry = Integer.parseInt(maxRetryStr); } catch (NumberFormatException e) { Debug.logWarning(e, "Setting maxRetry to -1 (default)", module); maxRetry = -1; } } service.maxRetry = maxRetry; // get the timeout and convert to int String timeoutStr = UtilXml.checkEmpty(serviceElement.getAttribute("transaction-timout")); int timeout = 0; if (!UtilValidate.isEmpty(timeoutStr)) { 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 = FastMap.newInstance(); 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 LinkedMap(); try { ModelEntity entity = delegator.getModelEntity(entityName); if (entity == null) { throw new GeneralException("Could not find entity with name [" + entityName + "]"); } Iterator fieldsIter = entity.getFieldsIterator(); 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -