Source Code Cross Referenced for CommonFunctionMathDivideTag.java in  » Workflow-Engines » JFolder » org » jfolder » common » function » v1 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Workflow Engines » JFolder » org.jfolder.common.function.v1 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.common.function.v1;
009:
010:        //base classes
011:        import java.math.BigDecimal;
012:
013:        //project specific classes
014:        import org.jfolder.common.SelfArgumentlessConstructor;
015:        import org.jfolder.common.StandardDataTypes;
016:        import org.jfolder.common.UnexpectedSystemException;
017:        import org.jfolder.common.function.BaseCommonFunctionCompatibilityTag;
018:        import org.jfolder.common.function.WebPageTagInstanceViewContext;
019:        import org.jfolder.common.function.WebPageTagInstanceViewContextInfo;
020:        import org.jfolder.common.tagging.AppraiseConceptTagContext;
021:        import org.jfolder.common.tagging.ConceptTag;
022:        import org.jfolder.common.tagging.ConceptTagCharacteristic;
023:        import org.jfolder.common.tagging.ConceptTagConstraint;
024:        import org.jfolder.common.tagging.ConceptTagConstraintHolder;
025:        import org.jfolder.common.tagging.ConceptTagFlagsHelper;
026:        import org.jfolder.common.tagging.ConceptTagHelper;
027:        import org.jfolder.common.tagging.DetermineClassConceptTagContext;
028:        import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
029:        import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
030:        import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
031:        import org.jfolder.common.tagging.InitializeConceptTagContext;
032:        import org.jfolder.common.tagging.ReturnableConceptTag;
033:        import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
034:        import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
035:        import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
036:        import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
037:        import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
038:        import org.jfolder.common.tagging.ValueAndClassForConceptTag;
039:        import org.jfolder.common.utils.misc.CommonExpressions;
040:        import org.jfolder.common.utils.misc.MiscHelper;
041:
042:        //other classes
043:
044:        public class CommonFunctionMathDivideTag extends
045:                BaseCommonFunctionCompatibilityTag implements 
046:                SelfArgumentlessConstructor {
047:
048:            //characteristics
049:            private ConceptTagCharacteristic dividendCtchar = null;
050:            private ConceptTagCharacteristic divisorCtchar = null;
051:
052:            //dividend details
053:            private final static String DIVIDEND_CTCON = "dividend";
054:            private final static String DIVIDEND_TITLE = "Dividend";
055:            private final static String DIVIDEND_SHORT_DESCRIPTION = "The number to be divided by the divisor to get the result "
056:                    + "('Dividend' is a fancy term for this)";
057:
058:            //divisor details
059:            private final static String DIVISOR_CTCON = "divisor";
060:            private final static String DIVISOR_TITLE = "Divisor";
061:            private final static String DIVISOR_SHORT_DESCRIPTION = "The number used to divide "
062:                    + "('Divisor' is a fancy term for this)";
063:
064:            public void initialize(InitializeConceptTagContext inIctc) {
065:
066:                //
067:                ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
068:                        .newInstance(inIctc);
069:
070:                //constrain "dividend"
071:                ConceptTagConstraint dividendCtcon = ConceptTagConstraint
072:                        .newInstance(DIVIDEND_CTCON, rootCtconh);
073:                dividendCtcon.setTitle(DIVIDEND_TITLE);
074:                dividendCtcon.setShortDescription(DIVIDEND_SHORT_DESCRIPTION);
075:                //
076:                StaticConceptTagConstraintContext dividendSctcc = StaticConceptTagConstraintContext
077:                        .newInstance(dividendCtcon);
078:                dividendSctcc.setRegularExpression(CommonExpressions.DECIMAL);
079:                //
080:                DynamicConceptTagConstraintContext dividendDctcc = DynamicConceptTagConstraintContext
081:                        .newInstance(dividendCtcon);
082:                dividendDctcc.getValidator().allowReturnOfOnlyDecimal();
083:                dividendDctcc.getValidator().filterDirectChildOfRootAndHtml();
084:                //
085:                dividendSctcc.addDefaultValue("1");
086:
087:                //constrain "divisor"
088:                ConceptTagConstraint divisorCtcon = ConceptTagConstraint
089:                        .newInstance(DIVISOR_CTCON, rootCtconh);
090:                divisorCtcon.setTitle(DIVISOR_TITLE);
091:                divisorCtcon.setShortDescription(DIVISOR_SHORT_DESCRIPTION);
092:                //
093:                StaticConceptTagConstraintContext divisorSctcc = StaticConceptTagConstraintContext
094:                        .newInstance(divisorCtcon);
095:                divisorSctcc.setRegularExpression(CommonExpressions.DECIMAL);
096:                //
097:                DynamicConceptTagConstraintContext divisorDctcc = DynamicConceptTagConstraintContext
098:                        .newInstance(divisorCtcon);
099:                divisorDctcc.getValidator().allowReturnOfOnlyDecimal();
100:                divisorDctcc.getValidator().filterDirectChildOfRootAndHtml();
101:                //
102:                divisorSctcc.addDefaultValue("1");
103:
104:                //
105:                ConceptTagFlagsHelper
106:                        .pushNonIterativeCommonFunctionDepth(inIctc);
107:                inIctc.initialize();
108:                ConceptTagFlagsHelper
109:                        .popNonIterativeCommonFunctionDepth(inIctc);
110:
111:                //initialize characteristics
112:                this .dividendCtchar = dividendCtcon.getCharacteristic();
113:                this .divisorCtchar = divisorCtcon.getCharacteristic();
114:            }
115:
116:            public void appraise(AppraiseConceptTagContext inActc) {
117:
118:                if (inActc instanceof  StudioConceptTagInstanceInfoContext) {
119:
120:                    StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
121:
122:                    if (this .dividendCtchar.getValueLength() == 1
123:                            && this .divisorCtchar.getValueLength() == 1) {
124:                        //initialize first operand
125:                        String operandTitle1 = "";
126:                        String operandDesc1 = "";
127:                        if (this .dividendCtchar.isStatic(0, inActc)) {
128:                            operandTitle1 = this .dividendCtchar
129:                                    .getValueAsString(0, inActc);
130:                            operandDesc1 = this .dividendCtchar
131:                                    .getValueAsString(0, inActc);
132:                        } else if (this .dividendCtchar.isHolderWithConceptTag(
133:                                0, inActc)) {
134:                            //
135:                            StudioConceptTagInstanceInfoContext nextStiic = this .dividendCtchar
136:                                    .getInstanceInformation(0);
137:                            operandTitle1 = nextStiic.getInstanceTitle();
138:                            operandDesc1 = nextStiic.getInstanceDescription();
139:                        }
140:                        //initialize second operand
141:                        String operandTitle2 = "";
142:                        String operandDesc2 = "";
143:                        if (this .divisorCtchar.isStatic(0, inActc)) {
144:                            operandTitle2 = this .divisorCtchar
145:                                    .getValueAsString(0, inActc);
146:                            operandDesc2 = this .divisorCtchar.getValueAsString(
147:                                    0, inActc);
148:                        } else if (this .divisorCtchar.isHolderWithConceptTag(0,
149:                                inActc)) {
150:                            StudioConceptTagInstanceInfoContext nextStiic = this .divisorCtchar
151:                                    .getInstanceInformation(0);
152:                            operandTitle2 = nextStiic.getInstanceTitle();
153:                            operandDesc2 = nextStiic.getInstanceDescription();
154:                        }
155:
156:                        //set title and description
157:                        sctiic.setInstanceTitle("((" + operandTitle1 + ") / ("
158:                                + operandTitle2 + "))");
159:                        sctiic.setInstanceDescription("((" + operandDesc1
160:                                + ") / (" + operandDesc2 + "))");
161:                    } else {
162:                        sctiic.setInstanceTitle("(Error)");
163:                        sctiic.setInstanceDescription("(Error)");
164:                    }
165:                } else if (inActc instanceof  StudioConceptTagTypeInfoContext) {
166:
167:                    StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
168:
169:                    scttic.setTypeTitle("Divide");
170:                    scttic
171:                            .setTypeDescription("Divides one number from another");
172:                } else if (inActc instanceof  WebPageTagInstanceViewContext) {
173:
174:                    WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
175:
176:                    WebPageTagInstanceViewContextInfo info = wptivc
177:                            .getInfoAsNonHtml();
178:                    info.setNonHtmlContent("Divide - Not Impl");
179:                    //wptivc.getInfo().setStartContent("");
180:                    //wptivc.getInfo().setMiddleContent("");
181:                    //wptivc.getInfo().setEndContent("");
182:                } else if (inActc instanceof  SelectionCriteriaForReturnableConceptTag) {
183:
184:                    SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
185:
186:                    scfrct.canReturnDecimal();
187:                    scfrct.declareFormatAsPlain();
188:                } else if (inActc instanceof  StudioConceptTagCreParInfoContext) {
189:
190:                    StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
191:                }
192:            }
193:
194:            public void determineValueAndClass(
195:                    DetermineValueAndClassConceptTagContext inDvacctc) {
196:
197:                try {
198:                    ValueAndClassForConceptTag vacfct = null;
199:
200:                    //ComponentsForReturnableScriptTag wcfrt =
201:                    //    ScriptTagHelper.getComponentsForReturnableScriptTag(inRvacc);
202:
203:                    //dividend
204:                    BigDecimal dividend = null;
205:                    if (this .dividendCtchar.isStatic(0, inDvacctc)) {
206:                        dividend = new BigDecimal(this .dividendCtchar
207:                                .getValueAsString(0, inDvacctc));
208:                    } else {
209:                        ValueAndClassForConceptTag dividendVac = this .dividendCtchar
210:                                .getDetermineValueAndClass(0, inDvacctc);
211:                        Object v = dividendVac.getValue();
212:                        dividend = MiscHelper.fromNumberToBigDecimal(v);
213:                    }
214:
215:                    //divisor
216:                    BigDecimal divisor = null;
217:                    if (this .divisorCtchar.isStatic(0, inDvacctc)) {
218:                        divisor = new BigDecimal(this .divisorCtchar
219:                                .getValueAsString(0, inDvacctc));
220:                    } else {
221:                        ValueAndClassForConceptTag divisorVac = this .divisorCtchar
222:                                .getDetermineValueAndClass(0, inDvacctc);
223:                        Object v = divisorVac.getValue();
224:                        divisor = MiscHelper.fromNumberToBigDecimal(v);
225:                    }
226:
227:                    BigDecimal quotient = dividend.divide(divisor,
228:                            BigDecimal.ROUND_HALF_EVEN);
229:
230:                    vacfct = ValueAndClassForConceptTag.newDecimal(quotient);
231:
232:                    inDvacctc.setDetermineValueAndClass(vacfct);
233:                } catch (DetermineValueAndClassConceptTagException dvaccte) {
234:                    inDvacctc.setDetermineException(dvaccte);
235:                }
236:            }
237:
238:            public void determineClass(DetermineClassConceptTagContext inDcctc) {
239:                inDcctc.setDetermineClass(StandardDataTypes.getDecimalClass());
240:            }
241:
242:            public Object createUninitializedSelf() {
243:                return new CommonFunctionMathDivideTag();
244:            }
245:
246:            /*
247:            public void getConceptTagSummary(ConceptTagSummaryDescriptor tsd) {
248:                //TO DO: placeholder, put meaningful description
249:                if (tsd.getMimeType().equals(ConceptTagSummaryMimeType.TEXT_HTML)) {
250:                    tsd.appendData("( ");
251:                    for (int i = 0; i < this.returnableConceptTags.size(); i++) {
252:                        if (i != 0) {
253:                            tsd.appendData(" / ");
254:                        }
255:                        ((ConceptTag)(this.returnableConceptTags.get(i))).
256:                        getConceptTagSummary(tsd);
257:                    }
258:                    tsd.appendData(" )");
259:                }
260:            }
261:             */
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.