Inter
nals of the Adobe ColdFusion Runtime
Elliott Spr
ehn
elliott@teratech.com
http://enfinitystudios.thaposse.net/blog/
1
What
is
ColdFusion?
•
A
s
et of languages (CFML,CFScript)
•
A compiler for the languages
•
Generates Java Bytecode
•
A runtime envir
onment
•
An interpr
eter for expr
essions
2
The Basic Pr
ocess
•
Parse and compile cfml/cfscript on first
r
equest
•
Java Classes (inter
esting packages):
•
coldfusion.runtime.*
•
coldfusion.tagext.*
•
Cache r
esulting bytecode for next r
equest
•
Execute.
3
V
ariables
•
coldfusion.runtime.V
ariable
•
Generic container
, holds any value.
•
Not generally useful inside CF code.
•
Every named variable has an instance.
•
Automatically unwrapped by the runtime.
<cfset myVar = createObject
(“java”,”coldfusion.runtime.Variable”).init(“myVar”)>
<cfif not myVar.isDefined()>
...
</cfif>
Code Sample:
4
T
ypes
•
T
ypes map to runtime classes
•
Query:
coldfusion.runtime.QueryV
ector
!
!
!
!
!
•
Struct:
java.util.Map: coldfusion.runtime.Struct
!
!
!
!
•
Array:
java.util.List: coldfusion.runtime.Array
!
!
!
!
•
List:
java.lang.String
!
!
!
!
!
!
!
!
!
•
String:
java.lang.String
!
!
!
!
!
!
!
!
•
Number:
java.lang.String, int, double
•
Date:
java.util.Date
•
Component:
coldfusion.runtime.T
emplatePr
oxy (mor
e about this later)
•
Java Object:
coldfusion.runtime.java.JavaPr
oxy
•
Casting Handled by coldfusion.runtime.Cast
5
Scopes
•
Implemented by various classes
•
V
ariables:
coldfusion.runtime.V
ariableScope
•
Ar
guments:
coldfusion.runtime.Ar
gumentsCollection
•
Client:
coldfusion.runtime.ClientScope
•
Server:
coldfusion.runtime.ServerScope
•
Application:
coldfusion.runtime.ApplicationScope
•
Session:
coldfusion.runtime.MemorySessionScope
•
Super:
coldfusion.runtime.SuperScope
•
Local:
coldfusion.runtime.LocalScope
•
Some scopes have extra behavior not normally exposed because of
member access rules.
Code Sample:
application.getEventInvoker().getThisScope()
6
Functions
•
Implemented by coldfusion.runtime.UDFMethod
•
Compiled to static inner classes on pages.
•
Requir
es
•
PageContext
•
LocalScope
•
Ar
gumentCollection
•
LocalScope variables
ar
e
actually stack local.
•
Still stor
ed in a LocalScope collection.
•
Faster to access because they’r
e local.
•
Not discar
ded when function finished in conventional
Java manner
.
7
Java Objects
•
Pr
oxied by coldfusion.runtime.java.JavaPr
oxy
•
Adds lots of overhead to invocation.
•
Uses Java r
eflection
•
very
expensive
•
CF does some method caching to r
educe the
performance hit.
•
Real pain to invoke some method signatur
es.
•
Use Java r
eflection yourself, avoid CF method lookup.
8
T
ags
•
Implemented as JSP T
ags
•
Some ar
e CF Code (ex. cfsavecontent)
•
Map to a coldfusion.tagext.* class.
•
coldfusion.tagext.sql.QueryParamT
ag
•
coldfusion.tagext.lang.Thr
owT
ag
•
coldfusion.tagext.io.Dir
ectoryT
ag
•
T
ags implement javax.servlet.jsp.tagext.T
ag
•
Execution
1.
setXXXX(value) (attributes)
2.
doStartT
ag()
3.
doEndT
ag()
4.
r
elease()
9
Pages, Includes, Custom T
ags, Components
•
Everything is a coldfusion.runtime.CFPage
•
No r
eal dif
fer
ence between a custom tag and a r
egular page.
•
Components ar
e just wrapped up pages.
•
Everyone has their own PageContext.
•
Page is exposed though getPageContext().getPage()
•
Contains all your custom functions, variables, etc.
•
Not r
eal useful without special code.
•
Component cr
eation is expensive.
•
Lots of work to cr
eate a Page.
•
Requir
es separate output buf
fer
, PageContext, scopes, ...
•
Inheritance!
10
Pages, Includes, Custom T
ags, Components (cont.)
11
Code Samples / Implementation Details
•
Cr
eate and execute queries that use cfqueryparam fr
om cfscript.
•
Cr
eate a function like CF8 to get database info for a datasour
ce.
•
Add global mappings by appending to a structur
e like this.mappings in
CF8.
•
Call functions and component methods and inspect the local scope after
their execution.
•
Access the Application.cfc anywher
e in an application.
•
Allow passing arrays of values in the url scope instead of lists when ther
e
ar
e duplicate keys.
12
Questions
?
13
Enter the password to open this PDF file:
File name:
-
File size:
-
Title:
-
Author:
-
Subject:
-
Keywords:
-
Creation Date:
-
Modification Date:
-
Creator:
-
PDF Producer:
-
PDF Version:
-
Page Count:
-
Preparing document for printing…
0%
Σχόλια 0
Συνδεθείτε για να κοινοποιήσετε σχόλιο