Module: Muml_Element
- Defined in:
- lib/ontomde-java/java/enumAssignable.rb,
lib/ontomde-java/vmware/vso.rb,
lib/ontomde-java/java/apache.rb,
lib/ontomde-java/struts/form.rb,
lib/ontomde-java/struts/form.rb,
lib/ontomde-java/struts/action.rb,
lib/ontomde-java/kbjava/rdfToJava.rb,
lib/ontomde-java/java/annotationOntoMDE.rb,
lib/ontomde-java/struts/exceptionHandling.rb
Overview
For each model class, create an enum containing a list of assignable type.
Constant Summary collapse
- STRUTS_LVB =
Struts LabelValueBean class qualified name.
'org.apache.struts.util.LabelValueBean'
- NIL_LVB_KEY =
LVB used for null object
"nil"
- NIL_LVB_RES_KEY =
"obj_nil"
- STRUTS_FORM_HELPER =
"xmda.struts.FormHelper"
- STRUTS_FORM_HELPER_ENUMTOLVB =
"enumToLvb"
- STRUTS_DATE_FORMATER_INSTANCE =
STRUTS_FORM_HELPER+'.DfCalendar'
- STRUTS_TIMESTAMP_FORMATER_INSTANCE =
STRUTS_FORM_HELPER+'.DfTimestamp'
- STRUTS_FORM_HELPER_CODE =
<<ENDCODE public static final java.text.SimpleDateFormat DfTimestamp=new java.text.SimpleDateFormat("yyyy/MM/dd HH:mm:ss",java.util.Locale.ENGLISH); public static final java.text.SimpleDateFormat DfCalendar=new java.text.SimpleDateFormat("yyyy/MM/dd",java.util.Locale.ENGLISH); /** * Transform a timestamp date to its GMT equivalent date. * * @param fromTimeZone * @param timestampToTransform * @return date in GMT */ public static java.util.Date transformFromCurrentTZToGMT(final java.util.TimeZone fromTimeZone,final java.util.Date timestampToTransform) { // the offset of this time zone from UTC. int offset = fromTimeZone.getRawOffset(); java.util.GregorianCalendar gregCal = new java.util.GregorianCalendar(); gregCal.setTime(timestampToTransform); gregCal.add(java.util.Calendar.HOUR_OF_DAY, (-offset / 3600000)); return gregCal.getTime(); } public static java.util.Date transformFromGMTToCurrentTZ(final java.util.TimeZone currentTimeZone,final java.util.Date timestampToTransform) { // the offset of this time zone from UTC. int offset = currentTimeZone.getRawOffset(); java.util.GregorianCalendar gregorianCalendar = new java.util.GregorianCalendar(); gregorianCalendar.setTime(timestampToTransform); gregorianCalendar.add(java.util.Calendar.HOUR_OF_DAY, (offset / 3600000)); return gregorianCalendar.getTime(); } public static java.util.List<#{STRUTS_LVB}> #{STRUTS_FORM_HELPER_ENUMTOLVB}(final Class<?> enumType,final xmda.java.JavaEnumSig typeCheck, final java.util.List<?> enums) { return #{STRUTS_FORM_HELPER_ENUMTOLVB}(enumType,typeCheck,enums,false); } // addNullItem is used for example to add a "add element" in creator selection. public static java.util.List<#{STRUTS_LVB}> #{STRUTS_FORM_HELPER_ENUMTOLVB}(final Class<?> enumType,final xmda.java.JavaEnumSig typeCheck, final java.util.List<?> enums,final boolean addNullItem) { try { java.util.List<#{STRUTS_LVB}> ret=new java.util.ArrayList<#{STRUTS_LVB}>(); String prefix=enumType.getCanonicalName()+"."; #{STRUTS_LVB} lvb=null; if(addNullItem) { ret.add(new #{STRUTS_LVB}(prefix+"obj_nil", "nil"));} for ( Object itemObj : enums) { xmda.java.JavaEnumSig item=(#{JAVA_ENUM_INTERFACE_QNAME})itemObj; if(item!=null) { //value is a localization resource key lvb=new #{STRUTS_LVB}(prefix+item.name(),item.name()); } else { lvb=new #{STRUTS_LVB}(prefix+"obj_nil", "nil"); } ret.add(lvb); } return ret; } catch (RuntimeException e) { log.error(e); throw(e); } } @SuppressWarnings("unchecked") public static <T> java.util.Set<T> toBean(T[] t, java.util.Set<T> nullCast) { java.util.Set<T> ret = null; if (t != null) { ret = (java.util.Set<T>) new java.util.HashSet<T>(); for (int i = 0; i < t.length; i++) { ret.add(t[i]); } } return ret; } @SuppressWarnings("unchecked") public static <T> java.util.List<T> toBean(T[] t, java.util.List<T> nullCast) { java.util.List<T> ret = null; if (t != null) { // alternative: java.util.Arrays.asList ret = (java.util.List<T>) new java.util.ArrayList<T>(); for (int i = 0; i < t.length; i++) { ret.add(t[i]); } } return ret; } public static boolean toBean(String t, boolean nullCast) { return t.compareTo("true") == 0; } public static String toForm(boolean t) { return t ? "true" : "false"; } @SuppressWarnings("unchecked") public static <T> T[] toForm(java.util.Set<T> t) { return (T[]) t.toArray(); } @SuppressWarnings("unchecked") public static <T> T[] toForm(java.util.List<T> t) { return (T[]) t.toArray(); } /** * Map an array of value to a multi-line text * (meant for string[]) * @param <T> * @param t * @return */ @SuppressWarnings("unchecked") public static <T> String toFormArrayAsStringLine(java.util.Collection<T> t) { java.lang.StringBuffer sb=new java.lang.StringBuffer(); for (java.util.Iterator iterator = t.iterator(); iterator.hasNext();) { T t2 = (T) iterator.next(); sb.append(t2.toString()); sb.append(ARRAY_SEPARATOR); } return sb.toString(); } public static String ARRAY_SEPARATOR="\\n"; @SuppressWarnings("unchecked") public static java.util.Set<String> toBean(String t, java.util.Set<String> nullCast) { java.util.Set<String> ret = null; if (t != null) { String[] tline=t.split(ARRAY_SEPARATOR); ret = (java.util.Set<String>) new java.util.HashSet<String>(); for (int i = 0; i < tline.length; i++) { ret.add(tline[i]); } } return ret; } ENDCODE
- STRUTS_ACTION_HELPER =
"xmda.struts.ActionHelper"
- JAVA_ENUM_INTERFACE_QNAME =
"xmda.java.JavaEnumSig"
- JAVA_ENUM_ASSIGN_INTERFACE_QNAME =
"xmda.java.JavaEnumAssignSig"
- JAVA_ANNO_ONTOMDE_QNAME =
"xmda.annotationOntoMDE.OntoMDE"
- STRUTS_FUNCTIONAL_EXCEPTION =
"xmda.struts.exceptions.FunctionalException"
Instance Method Summary collapse
- #db_tx_none(java_code) ⇒ Object
- #java_debug(msg) ⇒ Object
- #java_error(msg) ⇒ Object
- #java_info(msg) ⇒ Object
- #java_warn(msg) ⇒ Object
- #struts_getActionHelper ⇒ Object
- #struts_getExceptionHandlerClass ⇒ Object
- #struts_getFormHelper ⇒ Object
- #struts_getFunctionalException ⇒ Object
- #vso_writeJavadoc(tab) ⇒ Object
- #vso_writeObject(tab, params) {|tab2| ... } ⇒ Object
Instance Method Details
#db_tx_none(java_code) ⇒ Object
727 728 729 |
# File 'lib/ontomde-java/struts/action.rb', line 727 def db_tx_none(java_code) return java_code end |
#java_debug(msg) ⇒ Object
24 25 26 |
# File 'lib/ontomde-java/java/apache.rb', line 24 def java_debug(msg) return "if(log.isDebugEnabled()){log.debug(#{msg});}" end |
#java_error(msg) ⇒ Object
27 28 29 |
# File 'lib/ontomde-java/java/apache.rb', line 27 def java_error(msg) return "if(log.isErrorEnabled()){log.error(#{msg});}" end |
#java_info(msg) ⇒ Object
30 31 32 |
# File 'lib/ontomde-java/java/apache.rb', line 30 def java_info(msg) return "if(log.isInfoEnabled()){log.info(#{msg});}" end |
#java_warn(msg) ⇒ Object
21 22 23 |
# File 'lib/ontomde-java/java/apache.rb', line 21 def java_warn(msg) return "if(log.isWarnEnabled()){log.warn(#{msg});}" end |
#struts_getActionHelper ⇒ Object
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 |
# File 'lib/ontomde-java/struts/action.rb', line 733 def struts_getActionHelper helper=umlx_getOrCreateClass(STRUTS_ACTION_HELPER) if(helper.java_customCode.empty?) helper.apaCom_addLogger! helper.umlx_external=RDF_FALSE #helper.java_import_add(STRUTS_LVB) helper.db_isTransient=RDF_TRUE helper.struts_isForm=RDF_FALSE helper.java_customCode= <<ENDCODE public static final String STRUTS_INPUT_FWD="#{::Muml_Classifier::STRUTS_INPUT_FWD}"; public static void changeTimeZoneAction_s1(final #{::Muml_Classifier::STRUTS_FORM_INTERFACE} form,final org.apache.struts.action.ActionMapping mapping,final javax.servlet.http.HttpServletRequest request,final String newTimeZoneId) { String oldTimeZoneId = xmda.tags.helpers.XMDARequestUtils.getUserTimeZone(request, null).getID(); //String newTimeZoneId = form.get#{Muml_Classifier::STRUTS_SETTIMEZONE_BEAN}(); // we change the the timezone. xmda.struts.ActionHelper.changeTimeZone(mapping, java.util.TimeZone.getDefault(),request,newTimeZoneId); // We transform the current timestamp dates in the form to the GMT // format // using the old time zone id in the method "copyToReference". form.set#{Muml_Classifier::STRUTS_SETTIMEZONE_BEAN}(oldTimeZoneId); form.copyToReference(); } public static org.apache.struts.action.ActionForward changeTimeZoneAction_s2(final #{::Muml_Classifier::STRUTS_FORM_INTERFACE} form,final org.apache.struts.action.ActionMapping mapping,final javax.servlet.http.HttpServletRequest request,final String newTimeZoneId) { //String newTimeZoneId = form.get#{Muml_Classifier::STRUTS_SETTIMEZONE_BEAN}(); form.set#{Muml_Classifier::STRUTS_SETTIMEZONE_BEAN}(newTimeZoneId); form.initFromReference(); return mapping.findForward(STRUTS_INPUT_FWD); } public static void changeTimeZone( final org.apache.struts.action.ActionMapping mapping, java.util.TimeZone timeZone, final javax.servlet.http.HttpServletRequest request, final String timeZoneDisplayName) { boolean isTimeZone = ((timeZoneDisplayName != null) && (timeZoneDisplayName.length() > 0)); if (isTimeZone) { timeZone = java.util.TimeZone.getTimeZone(timeZoneDisplayName); } request.getSession().setAttribute(xmda.tags.helpers.XMDAStrutsGlobals.TIMEZONE_KEY, timeZone); log.debug("selected timeZone = " + timeZone.getDisplayName()); // return mapping.findForward("inputfw"); } public static String getCurrentTab(final org.apache.struts.action.ActionMapping mapping,final String bizClassName) { String path=mapping.findForward(STRUTS_INPUT_FWD).getPath(); // path=/pages/comftpass/application/form/Applicationall.jsp String s=bizClassName; //int i=path.indexOf(s); int bi=path.indexOf(s)+s.length(); int ei=path.indexOf(".jsp"); String currentTab=path.substring(bi,ei); #{java_debug(%{"currentTab= >"+currentTab+"< path="+path})} return currentTab; } public static org.apache.struts.action.ActionForward changeLocaleAction(final org.apache.struts.action.ActionMapping mapping,java.util.Locale locale,final javax.servlet.http.HttpServletRequest request,final String language,final String country) { boolean isLanguage = ((language != null) && (language.length() > 0)); boolean isCountry = ((country != null) && (country.length() > 0)); if ((isLanguage) && (isCountry)) { locale = new java.util.Locale(language, country); } else if (isLanguage) { locale = new java.util.Locale(language, ""); } request.getSession().setAttribute(org.apache.struts.Globals.LOCALE_KEY, locale); return mapping.findForward("#{Muml_Classifier::STRUTS_INPUT_FWD}"); } public static org.apache.struts.action.ActionForward transferToStartEditAction(final org.apache.struts.action.ActionMapping mapping,final javax.servlet.http.HttpServletRequest request,final Object alienElement,final String parentFwd) { javax.servlet.http.HttpSession session = request.getSession(); String currentTab = getCurrentTab(mapping, parentFwd); // an extraneous "/" is added for forward (not needed for redirect) String returnTo = "/"+parentFwd + currentTab + "-submit.do?doWhat=#{Muml_Classifier::STRUTS_RESUME_ACTION}"; session.setAttribute("#{Muml_Classifier::STRUTS_SESSION_KEY_EditAction}", alienElement); session.setAttribute( alienElement.getClass().getName() + "_returnTo", returnTo); return mapping.findForward(alienElement.getClass().getSimpleName()+"#{Muml_Class::STRUTS_EDIT_FWD_POSTFIX}"); } public static void checkNotNull(final Object elt, #{struts_getFunctionalException.java_qualifiedName} exceptionToFire) { if (elt == null) { throw exceptionToFire; } } /* * dump image contained in image variable to web browser. * Forward to #{Muml_Class::NOGIF_FORWARD} if image is null. */ public static org.apache.struts.action.ActionForward writeGif(final org.apache.struts.action.ActionMapping mapping,final javax.servlet.http.HttpServletResponse response, byte image[]) { if (image != null) { response.setContentType("image/gif"); try { response.getOutputStream().write(image); } catch (java.io.IOException ioe) { throw new RuntimeException(ioe); } return null; } else { // image will display as text if loaded directly // ie: not trough <img src=> response.setContentType("image/gif"); return mapping.findForward("#{Muml_Class::NOGIF_FORWARD}"); } } /* * dump image contained in image variable to web browser. * Forward to #{Muml_Class::NOGIF_FORWARD} if image is null. */ public static org.apache.struts.action.ActionForward writeGraphviz(final org.apache.struts.action.ActionMapping mapping,final javax.servlet.http.HttpServletResponse response,final String graphvizDotFile) { if (graphvizDotFile!= null) { response.setContentType("image/gif"); try { com.ft.cil.graphe.Graphe graphe=new com.ft.cil.graphe.Graphe(graphvizDotFile); //note: function renaming : (Stream is a byte array) response.getOutputStream().write(graphe.getImageStream()); } catch (java.io.IOException ioe) { throw new RuntimeException(ioe); } return null; } else { // image will display as text if loaded directly // ie: not trough <img src=> response.setContentType("image/gif"); return mapping.findForward("#{Muml_Class::NOGIF_FORWARD}"); } } /* * dump image contained in image variable to web browser. * Forward to #{Muml_Class::NOGIF_FORWARD} if image is null. */ public static org.apache.struts.action.ActionForward writeGraphvizMap(final org.apache.struts.action.ActionMapping mapping,final javax.servlet.http.HttpServletResponse response,final String graphvizDotFile) { response.setContentType("text/html"); if (graphvizDotFile!= null) { try { com.ft.cil.graphe.Graphe graphe=new com.ft.cil.graphe.Graphe(graphvizDotFile); //note: function renaming : (Stream is a byte array) javax.servlet.ServletOutputStream out=response.getOutputStream(); out.write("<html><head><title>usemap</title></head><body><map name=\\"myMap\\">\\n".getBytes()); out.write(graphe.getImageMap()); out.write("</map></body></html>\\n".getBytes()); } catch (java.io.IOException ioe) { throw new RuntimeException(ioe); } } else { // image will display as text if loaded directly // ie: not trough <img src=> } // do not forward to a jsp, output has already been written. return null; } ENDCODE end return helper; end |
#struts_getExceptionHandlerClass ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/ontomde-java/struts/exceptionHandling.rb', line 20 def struts_getExceptionHandlerClass m=umlx_getOrCreateClass("xmda.struts.exceptions.XMDAExceptionHandler") if(m.java_import.empty?) ['org.apache.struts.Globals', 'org.apache.struts.action.ActionForm', 'org.apache.struts.action.ActionForward', 'org.apache.struts.action.ActionMapping', 'org.apache.struts.action.ActionMessage', 'org.apache.struts.action.ExceptionHandler', 'org.apache.struts.config.ExceptionConfig', 'org.apache.struts.util.ModuleException', 'javax.servlet.http.HttpServletResponse','javax.servlet.ServletException','javax.servlet.http.HttpServletRequest'].each { |c| m.java_import_add(c); } m.apaCom_addLogger! m.umlx_external=RDF_FALSE #m.java_import_add(STRUTS_LVB) m.db_isTransient=RDF_TRUE m.struts_isForm=RDF_FALSE m.java_extends_add(umlx_reserved_model.umlx_getOrCreateClass("org.apache.struts.action.ExceptionHandler")) m.java_customCode= <<ENDCODE /** * <p> Handle the Exception. Return the ActionForward instance (if any) * returned by the called ExceptionHandler. </p> * * @param ex The exception to handle * @param ae The ExceptionConfig corresponding to the exception * @param mapping The ActionMapping we are processing * @param formInstance The ActionForm we are processing * @param request The servlet request we are processing * @param response The servlet response we are creating * @return The <code>ActionForward</code> instance (if any) returned by * the called <code>ExceptionHandler</code>. * @throws ServletException if a servlet exception occurs * @since Struts 1.1 */ public ActionForward execute(Exception ex, ExceptionConfig ae, ActionMapping mapping, ActionForm formInstance, HttpServletRequest request, HttpServletResponse response) throws ServletException { log.debug("ExceptionHandler executing for exception " + ex); ActionForward forward; ActionMessage error; String property; // Build the forward from the exception mapping if it exists // or from the form input if (ex instanceof FunctionalException && ((FunctionalException)ex).getFwPath()!= null) { String fwPath = ((FunctionalException)ex).getFwPath(); forward = new ActionForward(fwPath); } else if (ae.getPath() != null) { forward = new ActionForward(ae.getPath()); } else { forward = mapping.getInputForward(); } // Figure out the error if (ex instanceof ModuleException) { error = ((ModuleException) ex).getActionMessage(); property = ((ModuleException) ex).getProperty(); } else { error = new ActionMessage(ae.getKey(), ex.getMessage()); property = error.getKey(); } this.logException(ex); // Store the exception request.setAttribute(Globals.EXCEPTION_KEY, ex); this.storeException(request, property, error, forward, ae.getScope()); if (!response.isCommitted()) { return forward; } log.debug("Response is already committed, so forwarding will not work." + " Attempt alternate handling."); if (!silent(ae)) { handleCommittedResponse(ex, ae, mapping, formInstance, request, response, forward); } else { log.warn("ExceptionHandler configured with " + SILENT_IF_COMMITTED + " and response is committed.", ex); } return null; } /** * <p>Indicate whether this Handler has been configured to be silent. In * the base implementation, this is done by specifying the value * <code>"true"</code> for the property "SILENT_IF_COMMITTED" in the * ExceptionConfig.</p> * * @param config The ExceptionConfiguration we are handling * @return True if Handler is silent * @since Struts 1.3 */ private boolean silent(ExceptionConfig config) { return "true".equals(config.getProperty(SILENT_IF_COMMITTED)); } ENDCODE end return m end |
#struts_getFormHelper ⇒ Object
526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/ontomde-java/struts/form.rb', line 526 def struts_getFormHelper helper=umlx_getOrCreateClass(STRUTS_FORM_HELPER) if(helper.java_customCode.empty?) helper.apaCom_addLogger! helper.umlx_external=RDF_FALSE #helper.java_import_add(STRUTS_LVB) helper.db_isTransient=RDF_TRUE helper.struts_isForm=RDF_FALSE helper.java_customCode= STRUTS_FORM_HELPER_CODE end return helper; end |
#struts_getFunctionalException ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/ontomde-java/struts/exceptionHandling.rb', line 125 def struts_getFunctionalException m=umlx_getOrCreateClass(STRUTS_FUNCTIONAL_EXCEPTION) if(m.java_customCode.empty?) m.java_annotation_add(%{@SuppressWarnings("serial")}) m.apaCom_addLogger! m.umlx_external=RDF_FALSE #m.java_import_add(STRUTS_LVB) m.db_isTransient=RDF_TRUE m.struts_isForm=RDF_FALSE m.java_extends_add(umlx_getOrCreateClass("java.lang.RuntimeException")) m.java_customCode= <<ENDCODEend private String fwPath =null; public #{m.java_Name}() { super(); } public #{m.java_Name}(String mesg) { super(mesg); } public #{m.java_Name}(String fwPath, String mesg) { super(mesg); this.fwPath = fwPath; } public #{m.java_Name}(String mesg, Throwable th) { super(mesg, th); } public String getFwPath() { return fwPath; } public void setFwPath(String fwPath) { this.fwPath = fwPath; } ENDCODEend end return m end |
#vso_writeJavadoc(tab) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ontomde-java/vmware/vso.rb', line 130 def vso_writeJavadoc(tab) m=mtk_stss { java_writeJavadoc } uml_raisedException.each { |exception| m=m+"\nthrows:#{exception.java_qualifiedName}" } if respond_to?(:uml_raisedException) if (!m.nil? && !m.empty?) m=m.gsub(/[ \t]*@.*$/,'').gsub(/^[\t *\/]*/,'').gsub(/\n\n*/,"\n").strip end if m.nil? || m.empty? || m=="\n" write "#{tab}<description/>\n" else write "#{tab}<description>#{m}</description>\n" end end |
#vso_writeObject(tab, params) {|tab2| ... } ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/ontomde-java/vmware/vso.rb', line 146 def vso_writeObject(tab,params,&block) write(%{#{tab}<object script-name="#{java_Name}" java-class="#{java_qualifiedName}"#{" " unless params.empty?}#{params}#{%{ create="false"} if uml_isAbstract?}>\n}) tab2=tab.tab vso_writeJavadoc(tab2) yield(tab2) write(%{#{tab}</object>\n}) end |