Skip to content

Commit a4e6b23

Browse files
committed
Made bulk of the changes for SubmitFromEventHandler. Finalize and clean up the code this week during vc.
1 parent 595f6d7 commit a4e6b23

File tree

42 files changed

+634
-230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+634
-230
lines changed

jsf-flex-shared/core/src/main/java/com/googlecode/jsfFlex/renderkit/annotationDocletParser/_AnnotationDocletParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static String getErrorMessage(String caller, String parameter){
6363
public abstract void mapComponentFields(Class mapClass, Object componentObj,
6464
String replaceMappingXML);
6565

66-
enum MXMLMapper {
66+
enum MXML_MAPPER {
6767

6868
MXML_ATTRIBUTE_MAPPER {
6969
TokenValue mapField(String tokenName, Object componentObj) {

jsf-flex-shared/core/src/main/java/com/googlecode/jsfFlex/shared/beans/additionalScriptContent/AdditionalApplicationScriptContent.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,32 @@
2525
import java.util.Set;
2626

2727
import com.googlecode.jsfFlex.shared.adapter._MXMLApplicationContract;
28+
import com.googlecode.jsfFlex.shared.beans.additionalScriptContent.EventHandler.EVENT_HANDLER_TYPE;
2829

2930
/**
3031
* @author Ji Hoon Kim
3132
*/
3233
public final class AdditionalApplicationScriptContent {
3334

3435
private final Set<String> _actionScriptImports;
35-
private final Set<SimpleDataProviderSetter> _simpleDataProviderSetter;
36-
private final Map<String, DataGridScriptContent> _dataGridScriptContent;
36+
private final Map<String, DataGridScriptContent> _dataGridScriptContent;
37+
private final Set<EventHandler> _eventHandlers;
38+
private final Set<SimpleDataProviderSetter> _simpleDataProviderSetter;
3739
private final ValidationManagerScriptContent _validationManagerScriptContent;
3840

3941
public AdditionalApplicationScriptContent(String currMxml, _MXMLApplicationContract currApplicationContract){
4042
super();
4143
_actionScriptImports = new LinkedHashSet<String>();
42-
_simpleDataProviderSetter = new LinkedHashSet<SimpleDataProviderSetter>();
43-
_dataGridScriptContent = new HashMap<String, DataGridScriptContent>();
44+
_dataGridScriptContent = new HashMap<String, DataGridScriptContent>();
45+
_eventHandlers = new LinkedHashSet<EventHandler>();
46+
_simpleDataProviderSetter = new LinkedHashSet<SimpleDataProviderSetter>();
4447
_validationManagerScriptContent = new ValidationManagerScriptContent(currMxml, currApplicationContract);
4548
}
4649

4750
public void addActionScriptImport(String actionScriptImport){
4851
_actionScriptImports.add(actionScriptImport);
4952
}
5053

51-
public void addSimpleDataProviderSetter(String componentId, String dataProviderContent){
52-
_simpleDataProviderSetter.add(new SimpleDataProviderSetter(componentId, dataProviderContent));
53-
}
54-
5554
public void addDataGridScriptContent(String dataGridId, Integer batchColumnDataRetrievalSize, Integer maxDataPartitionIndex){
5655
_dataGridScriptContent.put(dataGridId, new DataGridScriptContent(dataGridId, batchColumnDataRetrievalSize, maxDataPartitionIndex));
5756
}
@@ -65,20 +64,31 @@ public void addDataGridColumnToDataGridScriptContent(String dataGridId, String d
6564

6665
dataGridScriptContentInstance.addDataGridColumnContent(dataGridColumnId, dataField, columnEditable);
6766
}
68-
69-
public void addValidationManagerValidatorId(String validatorId){
67+
68+
public void addEventHandler(String srcId, String tgtId, EVENT_HANDLER_TYPE eventType, String eventName){
69+
_eventHandlers.add(new EventHandler(srcId, tgtId, eventType, eventName));
70+
}
71+
72+
public void addSimpleDataProviderSetter(String componentId, String dataProviderContent){
73+
_simpleDataProviderSetter.add(new SimpleDataProviderSetter(componentId, dataProviderContent));
74+
}
75+
76+
public void addValidationManagerValidatorId(String validatorId){
7077
_validationManagerScriptContent.addValidationManagerValidatorId(validatorId);
7178
}
7279

7380
public Set<String> getActionScriptImports() {
7481
return new HashSet<String>(_actionScriptImports);
7582
}
76-
public Set<SimpleDataProviderSetter> getSimpleDataProviderSetter() {
77-
return new HashSet<SimpleDataProviderSetter>(_simpleDataProviderSetter);
78-
}
7983
public Map<String, DataGridScriptContent> getDataGridScriptContent() {
8084
return new HashMap<String, DataGridScriptContent>(_dataGridScriptContent);
8185
}
86+
public Set<EventHandler> getEventHandler() {
87+
return new HashSet<EventHandler>(_eventHandlers);
88+
}
89+
public Set<SimpleDataProviderSetter> getSimpleDataProviderSetter() {
90+
return new HashSet<SimpleDataProviderSetter>(_simpleDataProviderSetter);
91+
}
8292
public ValidationManagerScriptContent getValidationManagerScriptContent() {
8393
return _validationManagerScriptContent;
8494
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package com.googlecode.jsfFlex.shared.beans.additionalScriptContent;
20+
21+
import com.googlecode.jsfFlex.shared.util.MXMLConstants;
22+
23+
/**
24+
* @author Ji Hoon Kim
25+
*/
26+
public final class EventHandler {
27+
28+
public enum EVENT_HANDLER_TYPE {
29+
SUBMIT_FORM_EVENT_HANDLER("SubmitFormEventHandler");
30+
31+
private final String _actionScriptConstructor;
32+
33+
private EVENT_HANDLER_TYPE(String actionScriptConstructor){
34+
_actionScriptConstructor = actionScriptConstructor;
35+
}
36+
37+
private String getActionScriptConstructor(){
38+
return _actionScriptConstructor;
39+
}
40+
}
41+
42+
private static final char DELIM_CHARACTER = '_';
43+
44+
private final String _srcId;
45+
private final String _tgtId;
46+
private final EVENT_HANDLER_TYPE _eventType;
47+
private final String _eventName;
48+
private final String _collectedUniqueId;
49+
50+
EventHandler(String srcId, String tgtId, EVENT_HANDLER_TYPE eventType, String eventName){
51+
super();
52+
_srcId = srcId;
53+
_tgtId = tgtId;
54+
_eventName = eventName;
55+
_eventType = eventType;
56+
_collectedUniqueId = _srcId + DELIM_CHARACTER + _tgtId + DELIM_CHARACTER + _eventName + DELIM_CHARACTER + _eventType;
57+
}
58+
59+
public String getActionScriptConstructor(){
60+
return _eventType.getActionScriptConstructor();
61+
}
62+
public String getCollectedUniqueId(){
63+
return _collectedUniqueId;
64+
}
65+
public String getEventName(){
66+
return _eventName;
67+
}
68+
public EVENT_HANDLER_TYPE getEventType(){
69+
return _eventType;
70+
}
71+
public String getSrcId(){
72+
return _srcId;
73+
}
74+
public String getTgtId(){
75+
return _tgtId;
76+
}
77+
78+
@Override
79+
public boolean equals(Object instance) {
80+
if(!(instance instanceof EventHandler)){
81+
return false;
82+
}
83+
84+
EventHandler evtHandlerInstance = EventHandler.class.cast( instance );
85+
return _srcId.equals(evtHandlerInstance._srcId) && _tgtId.equals(evtHandlerInstance._tgtId) &&
86+
_eventType == evtHandlerInstance._eventType && _eventName.equals(evtHandlerInstance._eventName);
87+
}
88+
89+
@Override
90+
public int hashCode() {
91+
int hashCodeVal = MXMLConstants.HASH_CODE_INIT_VALUE;
92+
hashCodeVal = MXMLConstants.HASH_CODE_MULTIPLY_VALUE * hashCodeVal + _srcId.hashCode();
93+
hashCodeVal = MXMLConstants.HASH_CODE_MULTIPLY_VALUE * hashCodeVal + _tgtId.hashCode();
94+
hashCodeVal = MXMLConstants.HASH_CODE_MULTIPLY_VALUE * hashCodeVal + _eventType.toString().hashCode();
95+
hashCodeVal = MXMLConstants.HASH_CODE_MULTIPLY_VALUE * hashCodeVal + _eventName.hashCode();
96+
97+
return super.hashCode();
98+
}
99+
100+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package com.googlecode.jsfFlex.shared.util;
20+
21+
import java.util.Calendar;
22+
23+
import org.json.JSONArray;
24+
25+
import com.googlecode.jsfFlex.shared.exception.ComponentBuildException;
26+
import com.googlecode.jsfFlex.shared.util.MXMLConstants;
27+
28+
/**
29+
* This Util class will provide functionalities that are need by JSF Flex classes
30+
*
31+
* @author Ji Hoon Kim
32+
*/
33+
public final class MXMLJsfUtil {
34+
35+
private final static String WINDOWS_LINE_FEED = "\r\n";
36+
private final static String UNIX_LINE_FEED = "\n";
37+
38+
private final static String LINE_FEED_ESCAPER = "LINE_FEED";
39+
40+
private MXMLJsfUtil(){
41+
super();
42+
}
43+
44+
public static JSONArray convertJavaDateToASDateConstructorArguments(Calendar toConvert){
45+
JSONArray dateConstructorArguments = new JSONArray();
46+
47+
dateConstructorArguments.put(toConvert.get(Calendar.YEAR));
48+
dateConstructorArguments.put(toConvert.get(Calendar.MONTH));
49+
dateConstructorArguments.put(toConvert.get(Calendar.DATE));
50+
dateConstructorArguments.put(toConvert.get(Calendar.HOUR_OF_DAY));
51+
dateConstructorArguments.put(toConvert.get(Calendar.MINUTE));
52+
dateConstructorArguments.put(toConvert.get(Calendar.SECOND));
53+
dateConstructorArguments.put(toConvert.get(Calendar.MILLISECOND));
54+
55+
return dateConstructorArguments;
56+
}
57+
58+
/**
59+
* This method will take the argument and return an encoded version in UTF-8. Also it will replace<br>
60+
* line feeds ("\r\n", "\n") with the "LINE_FEED" string [due to how Flash interprets these two line feeds<br>
61+
* differently. Then the conversion back to its non-replaced and encoded value will be made on the Flash side.<br>
62+
*
63+
* @param toEscape
64+
* @return Encoded version of toEscape
65+
*/
66+
public static String escapeCharacters(String toEscape) {
67+
if(toEscape == null){
68+
return "";
69+
}
70+
71+
/*
72+
* TODO : implement this better
73+
* special case for line feeds, since otherwise it is replaced with two
74+
* line feeds on the flash side
75+
*/
76+
toEscape = toEscape.replaceAll(WINDOWS_LINE_FEED, LINE_FEED_ESCAPER);
77+
toEscape = toEscape.replaceAll(UNIX_LINE_FEED, LINE_FEED_ESCAPER);
78+
79+
try{
80+
81+
return java.net.URLEncoder.encode(toEscape, MXMLConstants.UTF_8_ENCODING);
82+
}catch(java.io.UnsupportedEncodingException unsupportedEncodingExcept){
83+
throw new ComponentBuildException("UnsupportedEncoding of " + MXMLConstants.UTF_8_ENCODING + ", in another words this " +
84+
"shouldn't happen", unsupportedEncodingExcept);
85+
}
86+
87+
}
88+
89+
public static String retrieveFormId(String componentId){
90+
int endIndex = componentId.lastIndexOf(':');
91+
return endIndex < 0 ? componentId : componentId.substring(0, componentId.lastIndexOf(':'));
92+
}
93+
94+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package com.googlecode.jsfFlex.shared.util;
20+
21+
import java.lang.reflect.InvocationTargetException;
22+
import java.lang.reflect.Method;
23+
24+
/**
25+
*
26+
* Helper class for performing reflection related tasks
27+
*
28+
* @author Ji Hoon Kim
29+
*/
30+
public final class ReflectionHelperUtil {
31+
32+
private ReflectionHelperUtil(){
33+
super();
34+
}
35+
36+
public static Object getValue(Object objectInstance, String methodToInvoke) throws NoSuchMethodException, InvocationTargetException,
37+
IllegalAccessException {
38+
39+
Method method = objectInstance.getClass().getMethod(methodToInvoke);
40+
Object retVal = method.invoke(objectInstance);
41+
42+
return retVal;
43+
}
44+
45+
public static Object invokeMethod(Object objectInstance, String methodToInvoke, Class[] parameterTypes, Object[] instanceParameters)
46+
throws NoSuchMethodException, InvocationTargetException,
47+
IllegalAccessException {
48+
49+
Method method = objectInstance.getClass().getMethod(methodToInvoke, parameterTypes);
50+
Object retVal = method.invoke(objectInstance, instanceParameters);
51+
52+
return retVal;
53+
}
54+
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
/**
21+
* TODO : Implement better later
22+
* @author Ji Hoon Kim
23+
*/
24+
package com.googlecode.jsfFlex.communication.event
25+
{
26+
import flash.errors.IllegalOperationError;
27+
import flash.events.Event;
28+
import flash.events.EventDispatcher;
29+
30+
public class AbstractEventHandler {
31+
32+
private var _componentInstance:Object;
33+
private var _eventName:String;
34+
35+
public function AbstractEventHandler(componentInstance:Object, eventName:String) {
36+
super();
37+
38+
_componentInstance = componentInstance;
39+
_eventName = eventName;
40+
}
41+
42+
public function activateListener():void {
43+
var componentToListenFor:EventDispatcher = _componentInstance as EventDispatcher;
44+
componentToListenFor.addEventListener(_eventName, handleEvent);
45+
}
46+
47+
public function deActivateListener():void {
48+
var componentToListenFor:EventDispatcher = _componentInstance as EventDispatcher;
49+
componentToListenFor.removeEventListener(_eventName, handleEvent);
50+
}
51+
52+
public function handleEvent(event:Event):void {
53+
throw new IllegalOperationError("handleEvent must be implemented by the sub class");
54+
}
55+
56+
}
57+
58+
}

0 commit comments

Comments
 (0)