001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.engines.call.v1;
009:
010: //base classes
011: import java.math.BigDecimal;
012: import java.util.ArrayList;
013:
014: //project specific classes
015: import org.jfolder.common.UnexpectedSystemException;
016: import org.jfolder.common.entity.SystemEntityTag;
017: import org.jfolder.common.tagging.AppraiseConceptTagContext;
018: import org.jfolder.common.tagging.CompoundConceptTagConstraintContext;
019: import org.jfolder.common.tagging.ConceptTag;
020: import org.jfolder.common.tagging.ConceptTagCharacteristic;
021: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
022: import org.jfolder.common.tagging.ConceptTagConstraint;
023: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
024: import org.jfolder.common.tagging.ConceptTagConstraintTemplate;
025: import org.jfolder.common.tagging.ConceptTagHelper;
026: import org.jfolder.common.tagging.ConceptTagMenuBranch;
027: import org.jfolder.common.tagging.ConceptTagMenuContext;
028: import org.jfolder.common.tagging.ConceptTagProperties;
029: import org.jfolder.common.tagging.ConceptTagSetContext;
030: import org.jfolder.common.tagging.ConceptTagSetHolder;
031: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
032: import org.jfolder.common.tagging.InitializeConceptTagContext;
033: import org.jfolder.common.tagging.RootConceptTagHolder;
034: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
035: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
036: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
037: import org.jfolder.common.utils.misc.MiscHelper;
038: import org.jfolder.common.utils.xml.LinearXPath;
039: import org.jfolder.engines.call.GovernorCall;
040:
041: //other classes
042:
043: public class RootV1GovernorCallTag implements SystemEntityTag,
044: GovernorCall {
045:
046: private final static String CALL_REQUEST = "REQUEST";
047: private final static String CALL_RESPONSE = "RESPONSE";
048:
049: private final static String TYPE_DECIMAL = "DECIMAL";
050: private final static String TYPE_BOOLEAN = "BOOLEAN";
051: private final static String TYPE_LSTRING = "LSTRING";
052: private final static String TYPE_BOBJECT = "BOBJECT";
053: private final static String TYPE_SENTITY = "SENTITY";
054:
055: //characteristics
056: private ConceptTagCharacteristic callTypeCtchar = null;
057: private ConceptTagCharacteristic serviceTypeCtchar = null;
058: private ConceptTagCharacteristic callNameCtchar = null;
059: private ConceptTagCharacteristic argumentCtchar = null;
060: private ConceptTagCharacteristic callSecretCtchar = null;
061: private ConceptTagCharacteristic callCredentialsCtchar = null;
062:
063: //
064: //call-type details
065: private final static String CALL_TYPE_CTCON = "call-type";
066: private final static String CALL_TYPE_TITLE = "Call Type";
067: private final static String CALL_TYPE_SHORT_DESCRIPTION = "Call Type";
068:
069: //service-type details
070: private final static String SERVICE_TYPE_CTCON = "service-type";
071: private final static String SERVICE_TYPE_TITLE = "Service Type";
072: private final static String SERVICE_TYPE_SHORT_DESCRIPTION = "Service Type";
073:
074: //call-name details
075: private final static String CALL_NAME_CTCON = "call-name";
076: private final static String CALL_NAME_TITLE = "Call Name";
077: private final static String CALL_NAME_SHORT_DESCRIPTION = "Call Name";
078:
079: //argument details
080: private final static String ARGUMENT_CTCON = "argument";
081: private final static String ARGUMENT_TITLE = "Argument";
082: private final static String ARGUMENT_SHORT_DESCRIPTION = "Argument";
083: //type of argument details
084: private final static String ARGUMENT_CTCON_TYPE_CTCTEMP = "type";
085: private final static String ARGUMENT_CTCON_TYPE_TITLE = "Type";
086: private final static String ARGUMENT_CTCON_TYPE_SHORT_DESCRIPTION = "Type";
087: //value of argument details
088: private final static String ARGUMENT_CTCON_VALUE_CTCTEMP = "value";
089: private final static String ARGUMENT_CTCON_VALUE_TITLE = "Value";
090: private final static String ARGUMENT_CTCON_VALUE_SHORT_DESCRIPTION = "Value";
091:
092: //call-secret details
093: private final static String CALL_SECRET_CTCON = "call-secret";
094: private final static String CALL_SECRET_TITLE = "Call Secret";
095: private final static String CALL_SECRET_SHORT_DESCRIPTION = "Call Secret";
096:
097: //call-credentials details
098: private final static String CALL_CREDENTIALS_CTCON = "call-credentials";
099: private final static String CALL_CREDENTIALS_TITLE = "Call Credentials";
100: private final static String CALL_CREDENTIALS_SHORT_DESCRIPTION = "Call Credentials";
101:
102: ///////////////////////////////////
103:
104: public void initialize(InitializeConceptTagContext inIctc) {
105:
106: //
107: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
108: .newInstance(inIctc);
109:
110: //constrain "call-type"
111: ConceptTagConstraint callTypeCtcon = ConceptTagConstraint
112: .newInstance(CALL_TYPE_CTCON, rootCtconh);
113: callTypeCtcon.setMinimumLength(1);
114: callTypeCtcon.setMaximumLength(1);
115: //
116: StaticConceptTagConstraintContext callTypeSctcc = StaticConceptTagConstraintContext
117: .newInstance(callTypeCtcon);
118:
119: //constrain "service-type"
120: ConceptTagConstraint serviceTypeCtcon = ConceptTagConstraint
121: .newInstance(SERVICE_TYPE_CTCON, rootCtconh);
122: serviceTypeCtcon.setMinimumLength(1);
123: serviceTypeCtcon.setMaximumLength(1);
124: //
125: StaticConceptTagConstraintContext serviceTypeSctcc = StaticConceptTagConstraintContext
126: .newInstance(serviceTypeCtcon);
127:
128: //constrain "call-name"
129: ConceptTagConstraint callNameCtcon = ConceptTagConstraint
130: .newInstance(CALL_NAME_CTCON, rootCtconh);
131: callNameCtcon.setMinimumLength(1);
132: callNameCtcon.setMaximumLength(1);
133: //
134: StaticConceptTagConstraintContext callNameSctcc = StaticConceptTagConstraintContext
135: .newInstance(callNameCtcon);
136:
137: //constrain "argument"
138: ConceptTagConstraint argumentCtcon = ConceptTagConstraint
139: .newInstance(ARGUMENT_CTCON, rootCtconh);
140: argumentCtcon.setMinimumLength(0);
141: argumentCtcon.setLengthUnbounded(true);
142: //
143: CompoundConceptTagConstraintContext argumentCctcc = CompoundConceptTagConstraintContext
144: .newInstance(argumentCtcon);
145: //
146: //constrain "type" of "argument"
147: ConceptTagConstraintTemplate argumentCtconTypeCtctemp = ConceptTagConstraintTemplate
148: .newInstance(ARGUMENT_CTCON_TYPE_CTCTEMP, argumentCctcc);
149: argumentCtconTypeCtctemp.setMinimumLength(1);
150: argumentCtconTypeCtctemp.setMaximumLength(1);
151: //
152: StaticConceptTagConstraintContext argumentCtconTypeSctcc = StaticConceptTagConstraintContext
153: .newInstance(argumentCtconTypeCtctemp);
154: //
155: //constrain "value" of "argument"
156: ConceptTagConstraintTemplate argumentCtconValueCtctemp = ConceptTagConstraintTemplate
157: .newInstance(ARGUMENT_CTCON_VALUE_CTCTEMP,
158: argumentCctcc);
159: argumentCtconValueCtctemp.setMinimumLength(1);
160: argumentCtconValueCtctemp.setMaximumLength(1);
161: //
162: StaticConceptTagConstraintContext argumentCtconValueSctcc = StaticConceptTagConstraintContext
163: .newInstance(argumentCtconValueCtctemp);
164: DynamicConceptTagConstraintContext argumentCtconValueDctcc = DynamicConceptTagConstraintContext
165: .newInstance(argumentCtconValueCtctemp);
166:
167: //constrain "call-secret"
168: ConceptTagConstraint callSecretCtcon = ConceptTagConstraint
169: .newInstance(CALL_SECRET_CTCON, rootCtconh);
170: callSecretCtcon.setMinimumLength(0);
171: callSecretCtcon.setMaximumLength(1);
172: //
173: StaticConceptTagConstraintContext callSecretSctcc = StaticConceptTagConstraintContext
174: .newInstance(callSecretCtcon);
175:
176: //constrain "call-credentials"
177: ConceptTagConstraint callCredentialsCtcon = ConceptTagConstraint
178: .newInstance(CALL_CREDENTIALS_CTCON, rootCtconh);
179: callCredentialsCtcon.setMinimumLength(0);
180: callCredentialsCtcon.setMaximumLength(1);
181: //
182: StaticConceptTagConstraintContext callCredentialsSctcc = StaticConceptTagConstraintContext
183: .newInstance(callCredentialsCtcon);
184:
185: //
186: inIctc.initialize();
187:
188: //
189: this .callTypeCtchar = callTypeCtcon.getCharacteristic();
190: this .serviceTypeCtchar = serviceTypeCtcon.getCharacteristic();
191: this .callNameCtchar = callNameCtcon.getCharacteristic();
192: this .argumentCtchar = argumentCtcon.getCharacteristic();
193: this .callSecretCtchar = callSecretCtcon.getCharacteristic();
194: this .callCredentialsCtchar = callCredentialsCtcon
195: .getCharacteristic();
196: }
197:
198: public void appraise(AppraiseConceptTagContext inCtic) {
199: if (inCtic instanceof StudioConceptTagInstanceInfoContext) {
200: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inCtic;
201: sctiic.setInstanceTitle("Governor Call");
202: sctiic.setInstanceDescription("Governor Call");
203: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
204: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inCtic;
205: scttic.setTypeTitle("Governor Call");
206: scttic.setTypeDescription("Governor Call");
207: }
208: }
209:
210: //
211: public boolean isCallRequest() {
212:
213: boolean outValue = false;
214:
215: if (this .callTypeCtchar.getValueLength() > 0) {
216: String value = this .callTypeCtchar
217: .getValueAsString(0, null);
218: outValue = value.equals(CALL_REQUEST);
219: } else {
220: throw UnexpectedSystemException.unknownState();
221: }
222:
223: return outValue;
224: }
225:
226: public boolean isCallResponse() {
227:
228: boolean outValue = false;
229:
230: if (this .callTypeCtchar.getValueLength() > 0) {
231: String value = this .callTypeCtchar
232: .getValueAsString(0, null);
233: outValue = value.equals(CALL_RESPONSE);
234: } else {
235: throw UnexpectedSystemException.unknownState();
236: }
237:
238: return outValue;
239: }
240:
241: public void setCallAsRequest() {
242: if (this .callTypeCtchar.getValueLength() > 0) {
243: this .callTypeCtchar.replaceValueAndRemoveLocalFiles(0,
244: CALL_REQUEST);
245: } else {
246: this .callTypeCtchar.addValue(0, CALL_REQUEST);
247: }
248: }
249:
250: public void setCallAsResponse() {
251: if (this .callTypeCtchar.getValueLength() > 0) {
252: this .callTypeCtchar.replaceValueAndRemoveLocalFiles(0,
253: CALL_RESPONSE);
254: } else {
255: this .callTypeCtchar.addValue(0, CALL_RESPONSE);
256: }
257: }
258:
259: //
260: public String getServiceType() {
261:
262: String outValue = null;
263:
264: if (this .serviceTypeCtchar.getValueLength() > 0) {
265: outValue = this .serviceTypeCtchar.getValueAsString(0, null);
266: } else {
267: throw UnexpectedSystemException.unknownState();
268: }
269:
270: return outValue;
271: }
272:
273: public String getCallName() {
274:
275: String outValue = null;
276:
277: if (this .callNameCtchar.getValueLength() > 0) {
278: outValue = this .callNameCtchar.getValueAsString(0, null);
279: } else {
280: throw UnexpectedSystemException.unknownState();
281: }
282:
283: return outValue;
284: }
285:
286: public void setServiceType(String inServiceType) {
287: if (this .serviceTypeCtchar.getValueLength() > 0) {
288: this .serviceTypeCtchar.replaceValueAndRemoveLocalFiles(0,
289: inServiceType);
290: } else {
291: this .serviceTypeCtchar.addValue(0, inServiceType);
292: }
293: }
294:
295: public void setCallName(String inCallName) {
296: if (this .callNameCtchar.getValueLength() > 0) {
297: this .callNameCtchar.replaceValueAndRemoveLocalFiles(0,
298: inCallName);
299: } else {
300: this .callNameCtchar.addValue(0, inCallName);
301: }
302: }
303:
304: //
305: public int getArgumentCount() {
306: return this .argumentCtchar.getValueLength();
307: }
308:
309: //
310: public BigDecimal getArgumentAsDecimal(int inIndex) {
311:
312: BigDecimal outValue = null;
313:
314: validateType(inIndex, TYPE_DECIMAL);
315:
316: ConceptTagCharacteristic valueCtchar = getValueCtchar(inIndex);
317:
318: if (valueCtchar.getValueLength() > 0) {
319: String s = valueCtchar.getValueAsString(0, null);
320:
321: outValue = new BigDecimal(s);
322: }
323:
324: return outValue;
325: }
326:
327: public Boolean getArgumentAsBoolean(int inIndex) {
328:
329: Boolean outValue = null;
330:
331: validateType(inIndex, TYPE_BOOLEAN);
332:
333: ConceptTagCharacteristic valueCtchar = getValueCtchar(inIndex);
334:
335: if (valueCtchar.getValueLength() > 0) {
336: String s = valueCtchar.getValueAsString(0, null);
337:
338: outValue = new Boolean(s);
339: }
340:
341: return outValue;
342: }
343:
344: public String getArgumentAsLString(int inIndex) {
345:
346: String outValue = null;
347:
348: validateType(inIndex, TYPE_LSTRING);
349:
350: ConceptTagCharacteristic valueCtchar = getValueCtchar(inIndex);
351:
352: if (valueCtchar.getValueLength() > 0) {
353: String s = valueCtchar.getValueAsString(0, null);
354:
355: outValue = s;
356: }
357:
358: return outValue;
359: }
360:
361: public SystemEntityTag getArgumentAsSEntity(int inIndex) {
362:
363: SystemEntityTag outValue = null;
364:
365: validateType(inIndex, TYPE_SENTITY);
366:
367: ConceptTagCharacteristic valueCtchar = getValueCtchar(inIndex);
368:
369: if (valueCtchar.getValueLength() > 0) {
370: ConceptTag ct = valueCtchar.getValueAsConceptTag(0, null);
371:
372: outValue = (SystemEntityTag) ct;
373: }
374:
375: return outValue;
376: }
377:
378: public byte[] getArgumentAsBObject(int inIndex) {
379:
380: byte[] outValue = null;
381:
382: validateType(inIndex, TYPE_BOBJECT);
383:
384: ConceptTagCharacteristic valueCtchar = getValueCtchar(inIndex);
385:
386: if (valueCtchar.getValueLength() > 0) {
387: String s = valueCtchar.getValueAsString(0, null);
388:
389: outValue = MiscHelper.fromCDataToSerializedData(s);
390: }
391:
392: return outValue;
393: }
394:
395: //
396: private ConceptTagCharacteristic getValueCtchar(int inIndex) {
397:
398: ConceptTagCharacteristic outValue = null;
399:
400: //int nextIndex = this.argumentCtchar.getValueLength();
401: ConceptTagCharacteristicHolder argumentCtcharh = this .argumentCtchar
402: .getValueAsHolder(inIndex, null);
403:
404: outValue = argumentCtcharh
405: .getCharacteristic(ARGUMENT_CTCON_VALUE_CTCTEMP);
406:
407: return outValue;
408: }
409:
410: private ConceptTagCharacteristic getTypeCtchar(int inIndex) {
411:
412: ConceptTagCharacteristic outValue = null;
413:
414: //int nextIndex = this.argumentCtchar.getValueLength();
415: ConceptTagCharacteristicHolder argumentCtcharh = this .argumentCtchar
416: .getValueAsHolder(inIndex, null);
417:
418: outValue = argumentCtcharh
419: .getCharacteristic(ARGUMENT_CTCON_TYPE_CTCTEMP);
420:
421: return outValue;
422: }
423:
424: private void validateType(int inIndex, String inType) {
425:
426: ConceptTagCharacteristic typeCtchar = getTypeCtchar(inIndex);
427:
428: String type = typeCtchar.getValueAsString(0, null);
429:
430: if (!type.equals(inType)) {
431: throw new UnexpectedSystemException("Desired type '"
432: + inType + "' is different than actual type '"
433: + type + "'");
434: }
435: }
436:
437: //
438: public void addArgumentAsDecimal(BigDecimal inValue) {
439: addArgument(TYPE_DECIMAL, toString(inValue));
440: }
441:
442: public void addArgumentAsBoolean(Boolean inValue) {
443: addArgument(TYPE_BOOLEAN, toString(inValue));
444: }
445:
446: public void addArgumentAsLString(String inValue) {
447: addArgument(TYPE_LSTRING, toString(inValue));
448: }
449:
450: public void addArgumentAsBObject(byte inValue[]) {
451:
452: String s = null;
453: if (inValue != null) {
454: s = MiscHelper.fromSerializedDataToCData(inValue);
455: }
456:
457: addArgument(TYPE_BOBJECT, s);
458: }
459:
460: public ConceptTagCharacteristic addPrepareArgumentAsSEntity() {
461:
462: return createValueCtchar(TYPE_SENTITY);
463: }
464:
465: ////
466: private void addArgument(String inType, String inValue) {
467:
468: ConceptTagCharacteristic ctchar = createValueCtchar(inType);
469:
470: if (inValue != null) {
471: ctchar.addValue(0, inValue);
472: }
473: }
474:
475: //public ConceptTagCharacteristic getArguments() {
476: // return this.argumentCtchar;
477: //}
478:
479: private ConceptTagCharacteristic createValueCtchar(String inType) {
480:
481: ConceptTagCharacteristic outValue = null;
482:
483: int nextIndex = this .argumentCtchar.getValueLength();
484: ConceptTagCharacteristicHolder argumentCtcharh = this .argumentCtchar
485: .createRegisteredHolder(nextIndex, true);
486: //
487: ConceptTagCharacteristic typeCtchar = argumentCtcharh
488: .registerCharacteristic(ARGUMENT_CTCON_TYPE_CTCTEMP);
489: typeCtchar.addValue(0, inType);
490: //
491: outValue = argumentCtcharh
492: .registerCharacteristic(ARGUMENT_CTCON_VALUE_CTCTEMP);
493: //
494:
495: return outValue;
496: }
497:
498: private final static String toString(Object inObject) {
499:
500: String outValue = null;
501:
502: if (inObject != null) {
503: outValue = inObject.toString();
504: }
505:
506: return outValue;
507: }
508:
509: //
510: public String getCallSecret() {
511:
512: String outValue = null;
513:
514: if (this .callSecretCtchar.getValueLength() > 0) {
515: outValue = this .callSecretCtchar.getValueAsString(0, null);
516: }
517:
518: return outValue;
519: }
520:
521: public String getCallCredentials() {
522:
523: String outValue = null;
524:
525: if (this .callCredentialsCtchar.getValueLength() > 0) {
526: outValue = this .callCredentialsCtchar.getValueAsString(0,
527: null);
528: }
529:
530: return outValue;
531: }
532:
533: //
534: public void setCallSecret(String inCallSecret) {
535: if (this .callSecretCtchar.getValueLength() > 0) {
536: this .callSecretCtchar.replaceValueAndRemoveLocalFiles(0,
537: inCallSecret);
538: } else {
539: this .callSecretCtchar.addValue(0, inCallSecret);
540: }
541: }
542:
543: public void setCallCredentials(String inCallCredentials) {
544: if (this .callCredentialsCtchar.getValueLength() > 0) {
545: this .callCredentialsCtchar.replaceValueAndRemoveLocalFiles(
546: 0, inCallCredentials);
547: } else {
548: this .callCredentialsCtchar.addValue(0, inCallCredentials);
549: }
550: }
551:
552: }
|