001: /*
002: * $Id: ModelServiceReader.java,v 1.8 2004/02/11 16:49:36 ajzeneski Exp $
003: *
004: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: *
024: */
025: package org.ofbiz.service;
026:
027: import java.io.IOException;
028: import java.net.URL;
029: import java.util.Collection;
030: import java.util.HashMap;
031: import java.util.Iterator;
032: import java.util.List;
033: import java.util.Map;
034: import java.util.Set;
035:
036: import javax.xml.parsers.ParserConfigurationException;
037:
038: import org.ofbiz.base.config.GenericConfigException;
039: import org.ofbiz.base.config.ResourceHandler;
040: import org.ofbiz.entity.*;
041: import org.ofbiz.entity.model.*;
042: import org.ofbiz.base.util.Debug;
043: import org.ofbiz.base.util.GeneralException;
044: import org.ofbiz.base.util.OrderedMap;
045: import org.ofbiz.base.util.UtilCache;
046: import org.ofbiz.base.util.UtilTimer;
047: import org.ofbiz.base.util.UtilXml;
048: import org.w3c.dom.Document;
049: import org.w3c.dom.Element;
050: import org.w3c.dom.Node;
051: import org.w3c.dom.NodeList;
052: import org.xml.sax.SAXException;
053:
054: /**
055: * Generic Service - Service Definition Reader
056: *
057: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
058: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
059: * @version $Revision: 1.8 $
060: * @since 2.0
061: */
062:
063: public class ModelServiceReader {
064:
065: public static final String module = ModelServiceReader.class
066: .getName();
067:
068: protected static UtilCache readersUrl = new UtilCache(
069: "service.ModelServiceReader.ByURL", 0, 0);
070: protected static UtilCache readersLoader = new UtilCache(
071: "service.ModelServiceReader.ByResourceLoader", 0, 0);
072:
073: /** is either from a URL or from a ResourceLoader (through the ResourceHandler) */
074: protected boolean isFromURL;
075: protected URL readerURL = null;
076: protected ResourceHandler handler = null;
077: protected Map modelServices = null;
078: protected DispatchContext dctx = null;
079:
080: public static ModelServiceReader getModelServiceReader(
081: URL readerURL, DispatchContext dctx) {
082: ModelServiceReader reader = null;
083:
084: // if ( readersUrl.containsKey(readerURL) ) <-- this is unnecessary as it will return null below if not found
085: reader = (ModelServiceReader) readersUrl.get(readerURL);
086: if (reader == null) { // don't want to block here
087: synchronized (ModelServiceReader.class) {
088: // must check if null again as one of the blocked threads can still enter
089: reader = (ModelServiceReader) readersUrl.get(readerURL);
090: if (reader == null) {
091: // if (Debug.infoOn()) Debug.logInfo("[Creating reader]: " + readerURL.toExternalForm(), module);
092: reader = new ModelServiceReader(readerURL, dctx);
093: readersUrl.put(readerURL, reader);
094: }
095: }
096: }
097: return reader;
098: }
099:
100: public static ModelServiceReader getModelServiceReader(
101: ResourceHandler handler, DispatchContext dctx) {
102: ModelServiceReader reader = null;
103:
104: reader = (ModelServiceReader) readersLoader.get(handler);
105: if (reader == null) { // don't want to block here
106: synchronized (ModelServiceReader.class) {
107: // must check if null again as one of the blocked threads can still enter
108: reader = (ModelServiceReader) readersLoader
109: .get(handler);
110: if (reader == null) {
111: // if (Debug.infoOn()) Debug.logInfo("[Creating reader]: " + handler, module);
112: reader = new ModelServiceReader(handler, dctx);
113: readersLoader.put(handler, reader);
114: }
115: }
116: }
117: return reader;
118: }
119:
120: protected ModelServiceReader(URL readerURL, DispatchContext dctx) {
121: this .isFromURL = true;
122: this .readerURL = readerURL;
123: this .handler = null;
124: this .dctx = dctx;
125: // preload models...
126: getModelServices();
127: }
128:
129: protected ModelServiceReader(ResourceHandler handler,
130: DispatchContext dctx) {
131: this .isFromURL = false;
132: this .readerURL = null;
133: this .handler = handler;
134: this .dctx = dctx;
135: // preload models...
136: getModelServices();
137: }
138:
139: public Map getModelServices() {
140: if (modelServices == null) { // don't want to block here
141: synchronized (ModelServiceReader.class) {
142: // must check if null again as one of the blocked threads can still enter
143: if (modelServices == null) { // now it's safe
144: modelServices = new HashMap();
145:
146: UtilTimer utilTimer = new UtilTimer();
147:
148: Document document = null;
149:
150: if (this .isFromURL) {
151: // utilTimer.timerString("Before getDocument in file " + readerURL);
152: document = getDocument(readerURL);
153:
154: if (document == null) {
155: modelServices = null;
156: return null;
157: }
158: } else {
159: // utilTimer.timerString("Before getDocument in " + handler);
160: try {
161: document = handler.getDocument();
162: } catch (GenericConfigException e) {
163: Debug
164: .logError(
165: e,
166: "Error getting XML document from resource",
167: module);
168: return null;
169: }
170: }
171:
172: if (this .isFromURL) {// utilTimer.timerString("Before getDocumentElement in file " + readerURL);
173: } else {// utilTimer.timerString("Before getDocumentElement in " + handler);
174: }
175:
176: Element docElement = document.getDocumentElement();
177: if (docElement == null) {
178: modelServices = null;
179: return null;
180: }
181:
182: docElement.normalize();
183:
184: int i = 0;
185: Node curChild = docElement.getFirstChild();
186: if (curChild != null) {
187: if (this .isFromURL) {
188: utilTimer
189: .timerString("Before start of service loop in file "
190: + readerURL);
191: } else {
192: utilTimer
193: .timerString("Before start of service loop in "
194: + handler);
195: }
196: int servicesLoaded = 0;
197:
198: do {
199: if (curChild.getNodeType() == Node.ELEMENT_NODE
200: && "service".equals(curChild
201: .getNodeName())) {
202: i++;
203: Element curService = (Element) curChild;
204: String serviceName = UtilXml
205: .checkEmpty(curService
206: .getAttribute("name"));
207:
208: // check to see if service with same name has already been read
209: if (modelServices
210: .containsKey(serviceName)) {
211: Debug
212: .logWarning(
213: "WARNING: Service "
214: + serviceName
215: + " is defined more than once, "
216: + "most recent will over-write previous definition(s)",
217: module);
218: }
219:
220: // utilTimer.timerString(" After serviceName -- " + i + " --");
221: ModelService service = createModelService(curService);
222:
223: // utilTimer.timerString(" After createModelService -- " + i + " --");
224: if (service != null) {
225: modelServices.put(serviceName,
226: service);
227: // utilTimer.timerString(" After modelServices.put -- " + i + " --");
228: /*
229: int reqIn = service.getParameterNames(ModelService.IN_PARAM, false).size();
230: int optIn = service.getParameterNames(ModelService.IN_PARAM, true).size() - reqIn;
231: int reqOut = service.getParameterNames(ModelService.OUT_PARAM, false).size();
232: int optOut = service.getParameterNames(ModelService.OUT_PARAM, true).size() - reqOut;
233:
234: if (Debug.verboseOn()) {
235: String msg = "-- getModelService: # " + i + " Loaded service: " + serviceName +
236: " (IN) " + reqIn + "/" + optIn + " (OUT) " + reqOut + "/" + optOut;
237:
238: Debug.logVerbose(msg, module);
239: }
240: */
241: } else {
242: Debug
243: .logWarning(
244: "-- -- SERVICE ERROR:getModelService: Could not create service for serviceName: "
245: + serviceName,
246: module);
247: }
248:
249: }
250: } while ((curChild = curChild.getNextSibling()) != null);
251: } else {
252: Debug.logWarning("No child nodes found.",
253: module);
254: }
255: if (this .isFromURL) {
256: utilTimer.timerString("Finished file "
257: + readerURL + " - Total Services: " + i
258: + " FINISHED");
259: Debug.logImportant("Loaded " + i
260: + " Service definitions from "
261: + readerURL, module);
262: } else {
263: utilTimer.timerString("Finished document in "
264: + handler + " - Total Services: " + i
265: + " FINISHED");
266: if (Debug.importantOn()) {
267: String resourceLocation = handler
268: .getLocation();
269: try {
270: resourceLocation = handler.getURL()
271: .toExternalForm();
272: } catch (GenericConfigException e) {
273: Debug.logError(e,
274: "Could not get resource URL",
275: module);
276: }
277: Debug.logImportant("Loaded " + i
278: + " Service definitions from "
279: + resourceLocation, module);
280: }
281: }
282: }
283: }
284: }
285: return modelServices;
286: }
287:
288: /**
289: * Gets an Service object based on a definition from the specified XML Service descriptor file.
290: * @param serviceName The serviceName of the Service definition to use.
291: * @return An Service object describing the specified service of the specified descriptor file.
292: */
293: public ModelService getModelService(String serviceName) {
294: Map ec = getModelServices();
295:
296: if (ec != null)
297: return (ModelService) ec.get(serviceName);
298: else
299: return null;
300: }
301:
302: /**
303: * Creates a Iterator with the serviceName of each Service defined in the specified XML Service Descriptor file.
304: * @return A Iterator of serviceName Strings
305: */
306: public Iterator getServiceNamesIterator() {
307: Collection collection = getServiceNames();
308:
309: if (collection != null) {
310: return collection.iterator();
311: } else {
312: return null;
313: }
314: }
315:
316: /**
317: * Creates a Collection with the serviceName of each Service defined in the specified XML Service Descriptor file.
318: * @return A Collection of serviceName Strings
319: */
320: public Collection getServiceNames() {
321: Map ec = getModelServices();
322:
323: return ec.keySet();
324: }
325:
326: protected ModelService createModelService(Element serviceElement) {
327: ModelService service = new ModelService();
328:
329: service.name = UtilXml.checkEmpty(serviceElement
330: .getAttribute("name"));
331: service.engineName = UtilXml.checkEmpty(serviceElement
332: .getAttribute("engine"));
333: service.location = UtilXml.checkEmpty(serviceElement
334: .getAttribute("location"));
335: service.invoke = UtilXml.checkEmpty(serviceElement
336: .getAttribute("invoke"));
337: service.defaultEntityName = UtilXml.checkEmpty(serviceElement
338: .getAttribute("default-entity-name"));
339:
340: // these default to true; if anything but true, make false
341: service.auth = "true".equalsIgnoreCase(serviceElement
342: .getAttribute("auth"));
343: service.export = "true".equalsIgnoreCase(serviceElement
344: .getAttribute("export"));
345: service.debug = "true".equalsIgnoreCase(serviceElement
346: .getAttribute("debug"));
347:
348: // this defaults to true; if anything but false, make it true
349: service.validate = !"false".equalsIgnoreCase(serviceElement
350: .getAttribute("validate"));
351: service.useTransaction = !"false"
352: .equalsIgnoreCase(serviceElement
353: .getAttribute("use-transaction"));
354: service.requireNewTransaction = !"false"
355: .equalsIgnoreCase(serviceElement
356: .getAttribute("require-new-transaction"));
357:
358: // get the timeout and convert to int
359: String timeoutStr = UtilXml.checkEmpty(serviceElement
360: .getAttribute("transaction-timout"));
361: if (timeoutStr == null || timeoutStr.length() == 0) {
362: timeoutStr = "0";
363: }
364: int timeout = 0;
365: try {
366: timeout = Integer.parseInt(timeoutStr);
367: } catch (NumberFormatException e) {
368: Debug.logWarning(e, "Setting timeout to 0 (default)",
369: module);
370: timeout = 0;
371: }
372: service.transactionTimeout = timeout;
373:
374: service.description = getCDATADef(serviceElement, "description");
375: service.nameSpace = getCDATADef(serviceElement, "namespace");
376:
377: service.contextInfo = new HashMap();
378: this .createPermGroups(serviceElement, service);
379: this .createImplDefs(serviceElement, service);
380: this .createAutoAttrDefs(serviceElement, service);
381: this .createAttrDefs(serviceElement, service);
382: this .createOverrideDefs(serviceElement, service);
383:
384: return service;
385: }
386:
387: protected String getCDATADef(Element baseElement, String tagName) {
388: String value = "";
389: NodeList nl = baseElement.getElementsByTagName(tagName);
390:
391: // if there are more then one decriptions we will use only the first one
392: if (nl.getLength() > 0) {
393: Node n = nl.item(0);
394: NodeList childNodes = n.getChildNodes();
395:
396: if (childNodes.getLength() > 0) {
397: Node cdata = childNodes.item(0);
398:
399: value = UtilXml.checkEmpty(cdata.getNodeValue());
400: }
401: }
402: return value;
403: }
404:
405: protected void createPermGroups(Element baseElement,
406: ModelService model) {
407: List permGroups = UtilXml.childElementList(baseElement,
408: "required-permissions");
409: Iterator permIter = permGroups.iterator();
410:
411: while (permIter.hasNext()) {
412: Element element = (Element) permIter.next();
413: ModelPermGroup group = new ModelPermGroup();
414: group.joinType = element.getAttribute("join-type");
415: createPermissions(element, group, model);
416: model.permissionGroups.add(group);
417: }
418: }
419:
420: protected void createPermissions(Element baseElement,
421: ModelPermGroup group, ModelService service) {
422: List permElements = UtilXml.childElementList(baseElement,
423: "check-permission");
424: List rolePermElements = UtilXml.childElementList(baseElement,
425: "check-role-member");
426:
427: // create the simple permissions
428: Iterator si = permElements.iterator();
429: while (si.hasNext()) {
430: Element element = (Element) si.next();
431: ModelPermission perm = new ModelPermission();
432: perm.nameOrRole = element.getAttribute("permission");
433: perm.action = element.getAttribute("action");
434: if (perm.action != null && perm.action.length() > 0) {
435: perm.permissionType = ModelPermission.ENTITY_PERMISSION;
436: } else {
437: perm.permissionType = ModelPermission.PERMISSION;
438: }
439: perm.serviceModel = service;
440: group.permissions.add(perm);
441: }
442:
443: // create the role member permissions
444: Iterator ri = rolePermElements.iterator();
445: while (ri.hasNext()) {
446: Element element = (Element) ri.next();
447: ModelPermission perm = new ModelPermission();
448: perm.permissionType = ModelPermission.ROLE_MEMBER;
449: perm.nameOrRole = element.getAttribute("role-type");
450: perm.serviceModel = service;
451: group.permissions.add(perm);
452: }
453: }
454:
455: protected void createImplDefs(Element baseElement,
456: ModelService service) {
457: List implElements = UtilXml.childElementList(baseElement,
458: "implements");
459: Iterator implIter = implElements.iterator();
460:
461: while (implIter.hasNext()) {
462: Element implement = (Element) implIter.next();
463: String serviceName = UtilXml.checkEmpty(implement
464: .getAttribute("service"));
465: if (serviceName.length() > 0)
466: service.implServices.add(serviceName);
467: }
468: }
469:
470: protected void createAutoAttrDefs(Element baseElement,
471: ModelService service) {
472: List autoElement = UtilXml.childElementList(baseElement,
473: "auto-attributes");
474: Iterator autoIter = autoElement.iterator();
475:
476: while (autoIter.hasNext()) {
477: Element element = (Element) autoIter.next();
478: createAutoAttrDef(element, service);
479: }
480: }
481:
482: protected void createAutoAttrDef(Element autoElement,
483: ModelService service) {
484: // get the entity name; first from the auto-attributes then from the service def
485: String entityName = UtilXml.checkEmpty(autoElement
486: .getAttribute("entity-name"));
487: if (entityName == null || entityName.length() == 0) {
488: entityName = service.defaultEntityName;
489: if (entityName == null || entityName.length() == 0) {
490: Debug
491: .logWarning(
492: "Auto-Attribute does not specify an entity-name; not default-entity on service definition",
493: module);
494: }
495: }
496:
497: // get the include type 'pk|nonpk|all'
498: String includeType = UtilXml.checkEmpty(autoElement
499: .getAttribute("include"));
500: boolean includePk = "pk".equals(includeType)
501: || "all".equals(includeType);
502: boolean includeNonPk = "nonpk".equals(includeType)
503: || "all".equals(includeType);
504:
505: // need a delegator for this
506: GenericDelegator delegator = dctx.getDelegator();
507: if (delegator == null) {
508: Debug
509: .logWarning(
510: "Cannot use auto-attribute fields with a null delegator",
511: module);
512: }
513:
514: if (delegator != null && entityName != null) {
515: Map modelParamMap = new OrderedMap();
516: try {
517: ModelEntity entity = delegator
518: .getModelEntity(entityName);
519: if (entity == null) {
520: throw new GeneralException(
521: "Could not find entity with name ["
522: + entityName + "]");
523: }
524: Iterator fieldsIter = entity.getFieldsIterator();
525: if (fieldsIter != null) {
526: while (fieldsIter.hasNext()) {
527: ModelField field = (ModelField) fieldsIter
528: .next();
529: if ((!field.getIsAutoCreatedInternal())
530: && ((field.getIsPk() && includePk) || (!field
531: .getIsPk() && includeNonPk))) {
532: ModelFieldType fieldType = delegator
533: .getEntityFieldType(entity, field
534: .getType());
535: if (fieldType == null) {
536: throw new GeneralException(
537: "Null field type from delegator for entity ["
538: + entityName + "]");
539: }
540: ModelParam param = new ModelParam();
541: param.entityName = entityName;
542: param.fieldName = field.getName();
543: param.name = field.getName();
544: param.type = fieldType.getJavaType();
545: param.mode = UtilXml.checkEmpty(autoElement
546: .getAttribute("mode"));
547: param.optional = "true"
548: .equalsIgnoreCase(autoElement
549: .getAttribute("optional")); // default to true
550: param.formDisplay = !"false"
551: .equalsIgnoreCase(autoElement
552: .getAttribute("form-display")); // default to false
553: modelParamMap.put(field.getName(), param);
554: }
555: }
556:
557: // get the excludes list; and remove those from the map
558: List excludes = UtilXml.childElementList(
559: autoElement, "exclude");
560: if (excludes != null) {
561: Iterator excludesIter = excludes.iterator();
562: while (excludesIter.hasNext()) {
563: Element exclude = (Element) excludesIter
564: .next();
565: modelParamMap
566: .remove(UtilXml
567: .checkEmpty(exclude
568: .getAttribute("field-name")));
569: }
570: }
571:
572: // now add in all the remaining params
573: Set keySet = modelParamMap.keySet();
574: Iterator setIter = keySet.iterator();
575: while (setIter.hasNext()) {
576: ModelParam this Param = (ModelParam) modelParamMap
577: .get(setIter.next());
578: //Debug.logInfo("Adding Param to " + service.name + ": " + thisParam.name + " [" + thisParam.mode + "] " + thisParam.type + " (" + thisParam.optional + ")", module);
579: service.addParam(this Param);
580: }
581: }
582: } catch (GenericEntityException e) {
583: Debug.logError(e, "Problem loading auto-attributes ["
584: + entityName + "] for " + service.name, module);
585: } catch (GeneralException e) {
586: Debug.logError(e, "Cannot load auto-attributes : "
587: + e.getMessage() + " for " + service.name,
588: module);
589: }
590: }
591: }
592:
593: protected void createAttrDefs(Element baseElement,
594: ModelService service) {
595: // Add in the defined attributes (override the above defaults if specified)
596: List paramElements = UtilXml.childElementList(baseElement,
597: "attribute");
598: Iterator paramIter = paramElements.iterator();
599:
600: while (paramIter.hasNext()) {
601: Element attribute = (Element) paramIter.next();
602: ModelParam param = new ModelParam();
603:
604: param.name = UtilXml.checkEmpty(attribute
605: .getAttribute("name"));
606: param.type = UtilXml.checkEmpty(attribute
607: .getAttribute("type"));
608: param.mode = UtilXml.checkEmpty(attribute
609: .getAttribute("mode"));
610: param.entityName = UtilXml.checkEmpty(attribute
611: .getAttribute("entity-name"));
612: param.fieldName = UtilXml.checkEmpty(attribute
613: .getAttribute("field-name"));
614: param.stringMapPrefix = UtilXml.checkEmpty(attribute
615: .getAttribute("string-map-prefix"));
616: param.stringListSuffix = UtilXml.checkEmpty(attribute
617: .getAttribute("string-list-suffix"));
618: param.formLabel = UtilXml.checkEmpty(attribute
619: .getAttribute("form-label"));
620: param.optional = "true".equalsIgnoreCase(attribute
621: .getAttribute("optional")); // default to true
622: param.formDisplay = !"false".equalsIgnoreCase(attribute
623: .getAttribute("form-display")); // default to false
624:
625: // set the entity name to the default if not specified
626: if (param.entityName.length() == 0) {
627: param.entityName = service.defaultEntityName;
628: }
629:
630: // set the field-name to the name if entity name is specified but no field-name
631: if (param.fieldName.length() == 0
632: && param.entityName.length() > 0) {
633: param.fieldName = param.name;
634: }
635:
636: service.addParam(param);
637: }
638:
639: // Add the default optional parameters
640: ModelParam def = null;
641:
642: // responseMessage
643: def = new ModelParam();
644: def.name = ModelService.RESPONSE_MESSAGE;
645: def.type = "String";
646: def.mode = "OUT";
647: def.optional = true;
648: def.internal = true;
649: service.addParam(def);
650: // errorMessage
651: def = new ModelParam();
652: def.name = ModelService.ERROR_MESSAGE;
653: def.type = "String";
654: def.mode = "OUT";
655: def.optional = true;
656: def.internal = true;
657: service.addParam(def);
658: // errorMessageList
659: def = new ModelParam();
660: def.name = ModelService.ERROR_MESSAGE_LIST;
661: def.type = "java.util.List";
662: def.mode = "OUT";
663: def.optional = true;
664: def.internal = true;
665: service.addParam(def);
666: // successMessage
667: def = new ModelParam();
668: def.name = ModelService.SUCCESS_MESSAGE;
669: def.type = "String";
670: def.mode = "OUT";
671: def.optional = true;
672: def.internal = true;
673: service.addParam(def);
674: // successMessageList
675: def = new ModelParam();
676: def.name = ModelService.SUCCESS_MESSAGE_LIST;
677: def.type = "java.util.List";
678: def.mode = "OUT";
679: def.optional = true;
680: def.internal = true;
681: service.addParam(def);
682: // userLogin
683: def = new ModelParam();
684: def.name = "userLogin";
685: def.type = "org.ofbiz.entity.GenericValue";
686: def.mode = "INOUT";
687: def.optional = true;
688: def.internal = true;
689: service.addParam(def);
690: // Locale
691: def = new ModelParam();
692: def.name = "locale";
693: def.type = "java.util.Locale";
694: def.mode = "INOUT";
695: def.optional = true;
696: def.internal = true;
697: service.addParam(def);
698: }
699:
700: protected void createOverrideDefs(Element baseElement,
701: ModelService service) {
702: List paramElements = UtilXml.childElementList(baseElement,
703: "override");
704: Iterator paramIter = paramElements.iterator();
705:
706: while (paramIter.hasNext()) {
707: Element attribute = (Element) paramIter.next();
708: String name = UtilXml.checkEmpty(attribute
709: .getAttribute("name"));
710: ModelParam param = service.getParam(name);
711: boolean directToParams = true;
712: if (param == null) {
713: if (service.implServices.size() > 0
714: && !service.inheritedParameters) {
715: // create a temp def to place in the ModelService
716: // this will get read when we read implemented services
717: directToParams = false;
718: param = new ModelParam();
719: param.name = name;
720: } else {
721: Debug.logWarning(
722: "No parameter found for override parameter named: "
723: + name, module);
724: }
725: }
726:
727: if (param != null) {
728: // set only modified values
729: if (attribute.getAttribute("type") != null
730: && attribute.getAttribute("type").length() > 0) {
731: param.name = UtilXml.checkEmpty(attribute
732: .getAttribute("type"));
733: }
734: if (attribute.getAttribute("mode") != null
735: && attribute.getAttribute("mode").length() > 0) {
736: param.mode = UtilXml.checkEmpty(attribute
737: .getAttribute("mode"));
738: }
739: if (attribute.getAttribute("entity-name") != null
740: && attribute.getAttribute("entity-name")
741: .length() > 0) {
742: param.entityName = UtilXml.checkEmpty(attribute
743: .getAttribute("entity-name"));
744: }
745: if (attribute.getAttribute("field-name") != null
746: && attribute.getAttribute("field-name")
747: .length() > 0) {
748: param.fieldName = UtilXml.checkEmpty(attribute
749: .getAttribute("field-name"));
750: }
751: if (attribute.getAttribute("form-label") != null
752: && attribute.getAttribute("form-label")
753: .length() > 0) {
754: param.formLabel = UtilXml.checkEmpty(attribute
755: .getAttribute("form-label"));
756: }
757: if (attribute.getAttribute("optional") != null
758: && attribute.getAttribute("optional").length() > 0) {
759: param.optional = "true".equalsIgnoreCase(attribute
760: .getAttribute("optional")); // default to true
761: param.overrideOptional = true;
762: }
763: if (attribute.getAttribute("form-display") != null
764: && attribute.getAttribute("form-display")
765: .length() > 0) {
766: param.formDisplay = !"false"
767: .equalsIgnoreCase(attribute
768: .getAttribute("form-display")); // default to false
769: param.overrideFormDisplay = true;
770: }
771:
772: if (directToParams) {
773: service.addParam(param);
774: } else {
775: service.overrideParameters.add(param);
776: }
777: }
778: }
779: }
780:
781: protected Document getDocument(URL url) {
782: if (url == null)
783: return null;
784: Document document = null;
785:
786: try {
787: document = UtilXml.readXmlDocument(url, true);
788: } catch (SAXException sxe) {
789: // Error generated during parsing)
790: Exception x = sxe;
791:
792: if (sxe.getException() != null)
793: x = sxe.getException();
794: x.printStackTrace();
795: } catch (ParserConfigurationException pce) {
796: // Parser with specified options can't be built
797: pce.printStackTrace();
798: } catch (IOException ioe) {
799: ioe.printStackTrace();
800: }
801:
802: return document;
803: }
804: }
|