Skip to content

Commit 9ec0ffb

Browse files
JihoonKim1004JihoonKim1004
authored andcommitted
Changed the package for ComponentValueMapper.as and JavaScriptLogger.as. Also separated the code for Javascript portion of Flash to JavaScript logging to jsfFlexCommunicatorLogger.js. This is so to provide flexibility in the future when possibly improving the implementation of the logging [i.e. possibly might consider simulating messageQueue].
1 parent b50e5b3 commit 9ec0ffb

File tree

12 files changed

+181
-97
lines changed

12 files changed

+181
-97
lines changed

jsf-flex-shared/core/src/main/java/com/googlecode/jsfFlex/shared/util/MXMLConstants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public final class MXMLConstants {
5151
public static final String MXMLCONSTANTS_XML = "mxmlConstants.xml";
5252

5353
public static final String FLEX_SDK_ZIP = "flexSDK.zip";
54-
public static final String JSF_FLEX_COMMUNICATOR_JS = "jsfFlexCommunicator.js";
54+
public static final String JSF_FLEX_COMMUNICATOR_CORE_JS = "jsfFlexCommunicatorCore.js";
55+
public static final String JSF_FLEX_COMMUNICATOR_LOGGER_JS = "jsfFlexCommunicatorLogger.js";
5556
public static final String DEFAULT_SWC_LIBRARY_SWF_NAME = "library.swf";
5657
public static final String JSF_FLEX_MAIN_SWC_CONFIGURATIONFILE = "jsfFlexMainSwcConfigurationFile.xml";
5758
public static final String JSF_FLEX_MAIN_SWC_DIRECTORY_NAME = "jsfFlexMainSwcFileSystem";

jsf-flex-shared/core/src/main/resources/com/googlecode/jsfFlex/shared/actionScript/com/googlecode/jsfFlex/communication/ComponentValueMapper.as renamed to jsf-flex-shared/core/src/main/resources/com/googlecode/jsfFlex/shared/actionScript/com/googlecode/jsfFlex/communication/core/ComponentValueMapper.as

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/**
2121
* @author Ji Hoon Kim
2222
*/
23-
package com.googlecode.jsfFlex.communication
23+
package com.googlecode.jsfFlex.communication.core
2424
{
2525
import flash.external.ExternalInterface;
2626
import flash.events.Event;
@@ -32,12 +32,22 @@ package com.googlecode.jsfFlex.communication
3232
import mx.collections.ArrayCollection;
3333
import mx.core.UIComponent;
3434

35-
public class ComponentValueMapper extends JavaScriptLogger{
35+
import com.googlecode.jsfFlex.communication.logger.JavaScriptLogger;
36+
37+
public class ComponentValueMapper extends JavaScriptLogger {
3638

3739
private static const LINE_FEED:String = "\n";
3840
private static const LINE_FEED_ESCAPER:RegExp = /LINE_FEED/g;
3941

42+
private static const APPEND_E4X_ATTR:String = "@append";
43+
private static const NESTED_E4X_ATTR:String = "@nested";
44+
private static const DYNAMIC_E4X_ATTR:String = "@dynamic";
45+
46+
private static const AS_GET_COMP_VALUE_FUNCTION:String = "getCompValue";
4047
private static const COMP_VALUE_MAPPER:String = "swf/componentValueMapper.xml";
48+
private static const NULL_STRING:String = "null";
49+
private static const VALUE_ASSIGNMENT_STATEMENT:String = "value=";
50+
private static const VALUE_ATTR:String = "VALUE";
4151

4252
private static var _compValueMapper:XML;
4353

@@ -65,7 +75,7 @@ package com.googlecode.jsfFlex.communication
6575
}
6676

6777
try{
68-
ExternalInterface.addCallback("getCompValue", this.getCompValue);
78+
ExternalInterface.addCallback(AS_GET_COMP_VALUE_FUNCTION, this.getCompValue);
6979
}catch(callBackError:Error){
7080
trace("Failure in setting up of getCompValue callBack");
7181
logInfo("Failure in setting up of getCompValue callBack");
@@ -101,7 +111,7 @@ package com.googlecode.jsfFlex.communication
101111
if(currValue is String){
102112

103113
currValueString = currValue as String;
104-
if(currValueString != "null"){
114+
if(currValueString != NULL_STRING){
105115
objectRef = _refApp[currId];
106116
currValueString = unEscapeCharacters(currValueString);
107117
objectRef[currAttr] = currValueString;
@@ -124,7 +134,7 @@ package com.googlecode.jsfFlex.communication
124134
//TODO : implement this better later
125135
var toReturn:String = toUnEscape.replace(LINE_FEED_ESCAPER, LINE_FEED);
126136
var toEscape:URLVariables = new URLVariables();
127-
var toDecode:String = "value=" + toReturn;
137+
var toDecode:String = VALUE_ASSIGNMENT_STATEMENT + toReturn;
128138
toEscape.decode(toDecode);
129139
return toEscape.value;
130140
}
@@ -158,7 +168,7 @@ package com.googlecode.jsfFlex.communication
158168
classInfoNodeAttributes = classInfoNode.attribute_list.attribute;
159169

160170
for each (var attribute:XML in classInfoNodeAttributes){
161-
if(attribute.name.toString() == "VALUE"){
171+
if(attribute.name.toString() == VALUE_ATTR){
162172

163173
attributeValueObject = getAttributeValue(attribute, objectRef);
164174

@@ -186,12 +196,12 @@ package com.googlecode.jsfFlex.communication
186196
var attributeCheck:XMLList;
187197
var nestedObjects:XMLList;
188198

189-
attributeCheck = attribute.value.(hasOwnProperty("@append"));
199+
attributeCheck = attribute.value.(hasOwnProperty(APPEND_E4X_ATTR));
190200
toAppend = (attributeCheck != null && attributeCheck.length() > 0) ? attribute.value.@append.toString() : new String();
191201

192-
attributeCheck = attribute.value.(hasOwnProperty("@nested"));
202+
attributeCheck = attribute.value.(hasOwnProperty(NESTED_E4X_ATTR));
193203
isNested = (attributeCheck != null && attributeCheck.length() > 0 && attribute.value.@nested.toString() == "true");
194-
attributeCheck = attribute.value.(hasOwnProperty("@dynamic"));
204+
attributeCheck = attribute.value.(hasOwnProperty(DYNAMIC_E4X_ATTR));
195205
isDynamic = (attributeCheck != null && attributeCheck.length() > 0 && attribute.value.@dynamic.toString() == "true");
196206

197207
if(isNested){
@@ -217,6 +227,7 @@ package com.googlecode.jsfFlex.communication
217227
attributeId = null;
218228
attributeValue = null;
219229
trace("Failure in getting access to reference " + nestedObjects[k].toString());
230+
logInfo("Failure in getting access to reference " + nestedObjects[k].toString());
220231
break;
221232
}
222233
}

jsf-flex-shared/core/src/main/resources/com/googlecode/jsfFlex/shared/actionScript/com/googlecode/jsfFlex/communication/JavaScriptLogger.as renamed to jsf-flex-shared/core/src/main/resources/com/googlecode/jsfFlex/shared/actionScript/com/googlecode/jsfFlex/communication/logger/JavaScriptLogger.as

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@
1919

2020
/**
2121
* This class will be used for browser logging by all ActionScript classes
22+
* In future there exists consideration to implement the messaging whereas to simulate messageQueue
2223
* @author Ji Hoon Kim
2324
*/
24-
package com.googlecode.jsfFlex.communication
25+
package com.googlecode.jsfFlex.communication.logger
2526
{
2627
import flash.external.ExternalInterface;
2728
import flash.utils.getQualifiedClassName;
2829

29-
internal class JavaScriptLogger{
30+
public class JavaScriptLogger{
31+
32+
private static const CLASS_NAME_DELIM:String = ":";
33+
private static const JS_COMMUNICATION_LOG_FLASH_MESSAGE_FUNCTION:String = "com.googlecode.jsfFlex.communication.logger.logFlashMessage";
3034

3135
private static var CLASS_NAME:String = new String();
3236

@@ -35,7 +39,7 @@ package com.googlecode.jsfFlex.communication
3539
//TODO implement it better later
3640
var runTimeObjectName:String = getQualifiedClassName(this);
3741
if(runTimeObjectName != null){
38-
var qualifiedClassName:Array = runTimeObjectName.split(":");
42+
var qualifiedClassName:Array = runTimeObjectName.split(CLASS_NAME_DELIM);
3943
if(qualifiedClassName != null){
4044
CLASS_NAME = qualifiedClassName[qualifiedClassName.length - 1];
4145
}
@@ -64,7 +68,7 @@ package com.googlecode.jsfFlex.communication
6468

6569
private function logMessage(message:String, severity:int):void {
6670
message = CLASS_NAME + " : " + message;
67-
ExternalInterface.call("com.googlecode.jsfFlex.communication.logFlashMessage", message, severity);
71+
ExternalInterface.call(JS_COMMUNICATION_LOG_FLASH_MESSAGE_FUNCTION, message, severity);
6872
}
6973

7074
}

jsf-flex-shared/core/src/main/resources/com/googlecode/jsfFlex/shared/util/mxmlConstants.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<plugins-page>http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash</plugins-page>
1212
</swf-html-attibute>
1313
<swc-source-files>
14-
<source-file>com/googlecode/jsfFlex/shared/actionScript/com/googlecode/jsfFlex/communication/ComponentValueMapper.as</source-file>
15-
<source-file>com/googlecode/jsfFlex/shared/actionScript/com/googlecode/jsfFlex/communication/JavaScriptLogger.as</source-file>
14+
<source-file>com/googlecode/jsfFlex/shared/actionScript/com/googlecode/jsfFlex/communication/core/ComponentValueMapper.as</source-file>
15+
<source-file>com/googlecode/jsfFlex/shared/actionScript/com/googlecode/jsfFlex/communication/logger/JavaScriptLogger.as</source-file>
1616
</swc-source-files>
1717
<swf-source-files>
1818
<source-file>com/googlecode/jsfFlex/shared/swfSourceFiles/componentValueMapper.xml</source-file>

jsf-flex/core/src/main/java/com/googlecode/jsfFlex/component/ext/AbstractMXMLUIApplication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ public void encodeEnd(FacesContext context) throws IOException {
337337

338338
JsfFlexDojoResource _jsfFlexDojoResource = JsfFlexDojoResource.getDojoInstance();
339339
_jsfFlexDojoResource.addDojoMain();
340-
_jsfFlexDojoResource.addResource(getClass(), MXMLConstants.JSF_FLEX_COMMUNICATOR_JS);
340+
_jsfFlexDojoResource.addResource(getClass(), MXMLConstants.JSF_FLEX_COMMUNICATOR_CORE_JS);
341+
_jsfFlexDojoResource.addResource(getClass(), MXMLConstants.JSF_FLEX_COMMUNICATOR_LOGGER_JS);
341342

342343
super.encodeEnd(context);
343344
}

jsf-flex/core/src/main/resources/com/googlecode/jsfFlex/component/ext/resource/jsfFlexCommunicator.js renamed to jsf-flex/core/src/main/resources/com/googlecode/jsfFlex/component/ext/resource/jsfFlexCommunicatorCore.js

Lines changed: 39 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -36,53 +36,59 @@ if(!com.googlecode){
3636
throw new Error("com.googlecode exists but is not of type object");
3737
}
3838

39-
if(com.googlecode.jsfFlex){
40-
throw new Error("com.googlecode.jsfFlex namespace already exists");
39+
if(!com.googlecode.jsfFlex){
40+
com.googlecode.jsfFlex = {};
41+
}else if(typeof com.googlecode.jsfFlex != "object"){
42+
throw new Error("com.googlecode.jsfFlex exists but is not of type object");
4143
}
4244

43-
com.googlecode.jsfFlex = {
45+
if(!com.googlecode.jsfFlex.communication){
46+
com.googlecode.jsfFlex.communication = {};
47+
}else if(typeof com.googlecode.jsfFlex.communication != "object"){
48+
throw new Error("com.googlecode.jsfFlex.communication exists but is not of type object");
49+
}
50+
51+
if(!com.googlecode.jsfFlex.communication.core){
52+
com.googlecode.jsfFlex.communication.core = {};
53+
}else if(typeof com.googlecode.jsfFlex.communication.core != "object"){
54+
throw new Error("com.googlecode.jsfFlex.communication.core exists but is not of type object");
55+
}
56+
57+
com.googlecode.jsfFlex.communication.core = {
58+
data : {
59+
flashAppsKeyNamingContainer: new dojox.collections.Dictionary(),
60+
flashAppsKeyAppId: new dojox.collections.Dictionary()
61+
},
62+
4463
addFlashApp: function(_flashApp){
45-
var _namingContainerPrefixList = com.googlecode.jsfFlex.flashAppsKeyNamingContainer.item(_flashApp.namingContainerPrefix);
64+
var _namingContainerPrefixList = com.googlecode.jsfFlex.communication.core.data.flashAppsKeyNamingContainer.item(_flashApp.namingContainerPrefix);
4665
if(_namingContainerPrefixList == null){
4766
_namingContainerPrefixList = new Array();
48-
com.googlecode.jsfFlex.flashAppsKeyNamingContainer.add( _flashApp.namingContainerPrefix, _namingContainerPrefixList );
67+
com.googlecode.jsfFlex.communication.core.data.flashAppsKeyNamingContainer.add( _flashApp.namingContainerPrefix, _namingContainerPrefixList );
4968
}
50-
com.googlecode.jsfFlex.flashAppsKeyAppId.add( _flashApp.appId, _flashApp );
69+
com.googlecode.jsfFlex.communication.core.data.flashAppsKeyAppId.add( _flashApp.appId, _flashApp );
5170
_namingContainerPrefixList.push(_flashApp);
5271
},
53-
flashAppsKeyNamingContainer: new dojox.collections.Dictionary(),
54-
flashAppsKeyAppId: new dojox.collections.Dictionary(),
55-
5672
getApplication: function(_appId){
5773
if (navigator.appName.indexOf("Microsoft") != -1) {
5874
return document.getElementById(_appId);
5975
}else{
6076
return document[_appId];
6177
}
62-
}
63-
};
64-
65-
if(com.googlecode.jsfFlex.communication){
66-
throw new Error("com.googlecode.jsfFlex.communication namespace already exists");
67-
}
68-
69-
com.googlecode.jsfFlex.communication = {
70-
78+
},
7179
getCompValue: function(_appId, _objectId){
72-
var _access = com.googlecode.jsfFlex.getApplication(_appId);
80+
var _access = com.googlecode.jsfFlex.communication.core.getApplication(_appId);
7381
if(_access == null){
7482
throw new Error("appId [" + _appId + "] returned a null value during lookup");
7583
}
7684
var _value;
77-
7885
try{
7986
_value = _access.getCompValue(_objectId);
8087
}catch(error){
8188
throw new Error("Error while invoking getCompValue for appId, objectId [" + _appId + ", " + _objectId + "]");
8289
}
8390
return _value;
8491
}
85-
8692
};
8793

8894
//private namespace
@@ -93,29 +99,27 @@ com.googlecode.jsfFlex.communication = {
9399
var currUnloaded = 0;
94100

95101
function amReady(_readyAmI){
96-
var _flashApp = com.googlecode.jsfFlex.flashAppsKeyAppId.item( _readyAmI );
102+
var _flashApp = com.googlecode.jsfFlex.communication.core.data.flashAppsKeyAppId.item( _readyAmI );
97103
if(_flashApp){
98104
if(_flashApp.arrayOfIds){
99105
return _flashApp;
100106
}
101107
}else{
102-
/* Must not have been added yet, so simply connect a function to com.googlecode.jsfFlex.addFlashApp */
103-
var _handle = dojo.connect(com.googlecode.jsfFlex, "addFlashApp", function(){
104-
var _flashApp = com.googlecode.jsfFlex.flashAppsKeyAppId.item( _readyAmI );
108+
/* Must not have been added yet, so simply connect a function to com.googlecode.jsfFlex.communication.core.addFlashApp */
109+
var _handle = dojo.connect(com.googlecode.jsfFlexcommunication.core, "addFlashApp", function(){
110+
var _flashApp = com.googlecode.jsfFlex.communication.core.data.flashAppsKeyAppId.item( _readyAmI );
105111
if(_flashApp){
106112
if(_flashApp.arrayOfIds){
107-
var _access = com.googlecode.jsfFlex.getApplication( _readyAmI );
113+
var _access = com.googlecode.jsfFlex.communication.core.getApplication( _readyAmI );
108114
_access.populateInitValues( _flashApp );
109115
}
110116
dojo.disconnect(_handle);
111117
}
112-
});
113-
118+
});
114119
}
115120
}
116121

117122
function appendElement(_jsonNodes){
118-
119123
var _htmlType;
120124
var _attributeArray;
121125
var _ele;
@@ -133,7 +137,6 @@ com.googlecode.jsfFlex.communication = {
133137
formSubmit.appendChild(_ele);
134138
}
135139
}
136-
137140
}
138141

139142
function checkUnLoadStatus(){
@@ -151,21 +154,6 @@ com.googlecode.jsfFlex.communication = {
151154
return (_event.target) ? _event.target : _event.srcElement;
152155
}
153156

154-
function logFlashMessage(_logMessage, _severity){
155-
/*
156-
* For simplicity, currently is supported for FireFox:FireBug only
157-
* TODO: Consider supporting other browsers in the future
158-
*/
159-
switch(_severity){
160-
case 1 : if(console) console.log(_logMessage); return;
161-
case 2 : if(console) console.debug(_logMessage); return;
162-
case 3 : if(console) console.info(_logMessage); return;
163-
case 4 : if(console) console.warn(_logMessage); return;
164-
case 5 : if(console) console.error(_logMessage); return;
165-
}
166-
167-
}
168-
169157
function pageLoad(){
170158
for(var i=0; i < document.forms.length; i++){
171159
dojo.connect(document.forms[i], "onsubmit", pageUnload);
@@ -189,7 +177,7 @@ com.googlecode.jsfFlex.communication = {
189177
var _src = getSrcElement( getEvent(_event) );
190178
formSubmit = dojo.byId(_src.id);
191179

192-
var _namingContainerPrefixList = com.googlecode.jsfFlex.flashAppsKeyNamingContainer.item(_src.id);
180+
var _namingContainerPrefixList = com.googlecode.jsfFlex.communication.core.data.flashAppsKeyNamingContainer.item(_src.id);
193181
flashAppsToUpdateCount = _namingContainerPrefixList.length;
194182
var _access;
195183
for(var i=0; i < _namingContainerPrefixList.length; i++){
@@ -198,7 +186,7 @@ com.googlecode.jsfFlex.communication = {
198186
currUnloaded++;
199187
continue;
200188
}
201-
_access = com.googlecode.jsfFlex.getApplication(_namingContainerPrefixList[i].appId);
189+
_access = com.googlecode.jsfFlex.communication.core.getApplication(_namingContainerPrefixList[i].appId);
202190
try{
203191
_access.pageUnloading(_namingContainerPrefixList[i]);
204192
}catch(error){
@@ -228,9 +216,8 @@ com.googlecode.jsfFlex.communication = {
228216
}
229217

230218
//callers
231-
com.googlecode.jsfFlex.communication.amReady = amReady;
232-
com.googlecode.jsfFlex.communication.logFlashMessage = logFlashMessage;
233-
com.googlecode.jsfFlex.communication.pageLoad = pageLoad;
234-
com.googlecode.jsfFlex.communication.updateValues = updateValues;
219+
com.googlecode.jsfFlex.communication.core.amReady = amReady;
220+
com.googlecode.jsfFlex.communication.core.pageLoad = pageLoad;
221+
com.googlecode.jsfFlex.communication.core.updateValues = updateValues;
235222

236-
})();
223+
})();

0 commit comments

Comments
 (0)