Download - Powerpoint
Enterprise-Level Code Generation
Matthew Fowler
Agenda
1. Introduction• JeeWiz V4 - Process and Techniques• What's changed• JeeWiz V5 Worked Example
NT/e
• NT/e– New Technology / enterprise– Formed 1996
• 1998 - Server-side Java. BEA Partners• 2006-7: £2.5m turnover, £100k profit• JeeWiz Version 1.0: March 2002• JeeWiz Version 5.0.9: June 2008• Key relationships: DeutschePost/SOPERA,
BEA, GigaSpaces
What's ELCG
• Java, XML, Ant, Scripting– Develop on Windows, deploy on UNIX
• Commercial/industrial– As opposed to defense/telecom (MDA)– Microsoft different too
• Commercial drivers: – Opportunity: ROI, cost reduction, business agility– Defensive: stability, buy products, multiple
stakeholders
2. JeeWiz V4 Process & Techniques
1. Meta-model
2. Build profiles
3. Model
4. XMI → Simple XML
5. Generation
6. Writing code
(2.1) Meta-modelling Features
• Meta-model, meta-class, properties, lists• Validation - required, unique, Java expr• Factors - sort of mix-ins• Automatic generation of getters/setters/lists• Multi-level: i.e. "metaModel:metaClass" to
reference across models• Add special methods in Java as XML CDATA• Lists for all descendants - class, b-o, entity
Sample Meta-model
<meta-class name="entity"
extends="attribute-collection"
factor="security-factor" >
<description>...</description>
<property name="table-name" />
<property name="container" />
<list name="query /">
<validator expression="!getStatic()" message="An Entity must not be static"
/>
<![CDATA[
public int getPositionWithinParent()
{
return 30;
}
]]>
</meta-class>
Bottom line
• Quick - 1-2% of effort on meta-modelling• Powerful• HTML/Eclipse docs generation• Even better when you don't have to use it
– JeeWiz can generate without a meta-model
(2.2) Build Profiles
Base
Java
Bizobject
Screen
Collapse
1-levelMeta-model
Universal Automated
Powerful
Flexible
filter.xml
CustomisedMeta-model
Filter
RSM: JeeWiz.epx
Universal Automated
Powerful
Flexible
Universal Automated
Powerful
Flexible
Format
Build Profiles (cont.)
• Filter allows – easy customisation– consistency with meta-model enhancements
• Phase 3 changes for different modelling tool– same modelling profile across tools
(2.3) Modelling
• Logical-level concepts: e.g. page; event– All the platform representation is generated
• High-value "styles"– multi-patterns for generating look/behaviour– intention hints, cross-cutting
• RSM: automatic of deduction of stereotypes– Saves lots of fiddling and finger-trouble– Rewrite back to model possible
• Tolerance: fill in the blanks with M2M
Modelling Tolerance:Entity Key Generation
#if( $keys.size() == 0 ) ### if there are no keys### generate an autokey object on this entity
<this><attribute name="oid" autokey="true" type="Integer" />
</this>#end
• An example of technique + best practice
Page Modelling in RSM
Entity Modelling in RSM
Modelling In Gigaspaces
(2.4) XMI → Simple XML <entity name="Customer"/>
<attribute name="AcctID" type="String"/></entity>
• As simple as possible - it's all intentional• Lowest common denominator - for exchange
– Use JeeWiz on any XML– On read-in, no meta-model needed
• #foreach( $attribute in $entity.attributeList ) $attribute.name ...#end
• CDATA in <class> carries code
(2.5) Generation 1 - M2M
Model(text)
Model(Java objects)
M2Text
CodeConfig
M2M
+Velocity+
Velocity+
– Automated design patterns, plus code
– Same Enhanced Velocity: M2M Language = Velocity + XML
– Output is Simple XML - feedback loop
• No PIM/PSM dichotomy, no separate stage
– Automatic building of result - no configuration
– Separation of M2M from rendering to platform
– 30:1 to 50:1 expansion of model
+
Entity Key Generation - application of M2M
#if( $keys.size() == 0 ) ### if there are no keys### generate an autokey object on this entity
<this><attribute name="oid" autokey="true" type="Integer" />
</this>#end
Generation 2 - Automatic Build
• "Visitor" Tree Walk– Manufacturing assemblies– Run ant if build.xml exists– No further configuration– Automatic build of M2M output
• Ant - Model Integration– Read properties– Direct output to model– Side effects on model
• Builds become components
application name="Accounting"
ejb-jar name="Accounting1"
entity name="Account"bean-managed="false"
attribute name="accountId"type="int"
ejbJarList
attribute name="title"type="String"
entityList
attributeList1 2
3
4
5
Generation 3 - M2Text
• Called with special Ant task from a give object <jwVelocity template="applicationXml.vm"
file ="${staging}/META-INF/application.xml"
/>
• Velocity script language– Well known, easy to use– Links to Java
• JeeWiz additions: – Velocity methods– 240 Java helper methods
Generated Architecture
• HTML, CSS, JSP, Struts, some JavaScript• Session EJBs and Web Services• EJB 2.1 CMP• Application servers:
– JBoss, Websphere, WebLogic, WebSphere
• Databases: Oracle, SQL Server, MySQL
(2.6) Writing Code• 3-7% by volume in WebApps• Written in base language - Java• Uses 'extends' strategy• Pluggable weaving
implementationsImplementation Code
class Impl extends Base {
}
/* UID: ... */int mImpl {... }
Generated Code
class Base {
}
int mBase {... mImpl();}
Application Page
Application Page 2
And Another Thing
• CRUD generation– Relatively simple patterns
• Data-views– Intermediate objects between DB and
user/GUI or service API– Trees of objects, map to multiple database: a "view"– 25% of effort/volume
• Antlr V3 Example - using JeeWiz as a compiler backend
Summary: JeeWiz V4 - Process and Techniques
• Modelling - precise, high-level, smart defaults• Fast iterations - supports reqts. discovery• Encoding of techniques, architecture, custom
conventions, best practice• Automatic UI generation from abstract models• Coordinated multi-tier - 93-97% generation
– Struts, J2EE, Web Services, mid-tier views
• Commercial license, per-seat charge• Fundamentals known by millions of developers
3. What's Changed?
• Version 5: Taking pluggability to another level– R&D grant commitment
• Changes in the external world:– Virtualisation, clouds, SOA, grid computing– Hibernate/lightweight containers– Ajax, more Web frameworks than programmer
• No longer "One UI"
• Sopera - Eclipse "Swordfish" includes JeeWiz
Problems
• Cost of integration– New stack: Trinidad, JSF, Spring, Hibernate– The 500-page books are just the starting point
• Multiple viable UI frameworks– Struts, Struts2, JSF, Javascript libraries, Seam– No clear winner
• Making money - the value chain– Too much technology, too little time
Ecosystem relationships
Technology ProviderPartner
JeeWiz.com End-user
Language/region Partner
Add-onTechnology
ProviderPartner
Value-addPartner
(SI, Appln Product)
JeeWiz.org
e.g. Hibernate
e.g. Ajax Library
4. JeeWiz V5 Worked Example
(4.1) A Framework for Software Factories
Base
Java
Business Objects
Persistence
Hibernate
Database
Screen
JBoss4
JSF
Demo
Custom
Meta-ModelSystem Properties
Per-objectProperties M2M M2Text Controls
What is a control?• A non-model object• Properties• Velocity methods• Normal overriding/inheriting• Used for details
Ant representationtemplateDir=${basedir}/control,
${jwhome}/resources/demo/control,
${jwhome}/resources/jsf/control,
${jwhome}/resources/jboss4/control,
${jwhome}/resources/screen/control,
${jwhome}/resources/${database}/control,
${jwhome}/resources/hibernate/control,
${jwhome}/resources/persistence/control,
${jwhome}/resources/bizobject/control,
${jwhome}/resources/java/control,
${jwhome}/resources/base/control
• Abstract layers versus implementation layers– Factor out PIM-level implementation
• Other aspects of configuration pulled in from know files
(4.2) Problem Statement
Attribute
type=String
DB Column
BigInt
Presentation-
(nnnnn) mmm mmm
User View
Programmer View
ORM View
?
DatabaseView
Java-to-SQL-typeString Long
The Framework Angle
Base
Java
Business Objects
Persistence
Hibernate
Database
Screen
JBoss4
JSF
Demo
Custom
Meta-ModelSystem Properties
Per-objectProperties M2M M2Text Controls
javaSqlType
javaSqlType
javaSqlTypeConverter
javaSqlTypeStringLong
Split of Reponsibities
Persistence javaSqlType
ORM-independent knowledge
based on datatype
Hibernate javaSqlType
Mapping datatype->ORMtype
Persistence javaSqlTypeConverter
Wrap expressions in statements
Custom javaSqlTypeStringLong
Map String to Long
The Custom Control#extends( javaSqlTypeConverter )
languageType = Long
isNumeric = ${booleanTrue}
toSqlException = NumberFormatException
#method( toSqlExpression- $attribute $var )
#return( "Long.parseLong( $var )" )
#end
#method( fromSqlExpression- $attribute $var )
## flesh this out to 11 characters - use String formatter
#return( "String.format( ${q}%011d${q}, $var )" )
#end
#method (getInternalTypeFromRS $resultsSet $col $attribute)
#return( "${q}${q} + ${resultsSet}.getLong( $col )" )
#end
(There's not much fluff here)
Control Types
PhysicalDataTypes
LogicalDataTypes
Java-SQL Types
Logging
Database
Java-SQL Types(Hibernate Extn)
Language
Database(Hibernate Extn)
UI Field UI Search Field UI Navigation
Lookups - Style, datatype
UI State
Conversation management,stacking
UI Field(JSF/Trinidad)
UI Search Field(JSF/Trinidad)
UI Navigation(JSF/Trinidad)
UI State(JSF/Trinidad)
UI End...
Attribute
type=String
DB Column
BigInt
Presentation-
(nnnnn) mmm mmm
User View
Programmer View
ORM View
?
DatabaseView
(00000) 000 000 00000000000
The uiFieldPhoneNumber Control
• Similarity to java-Sql converter:
#extends(uiFieldDisplayConverter )
toUiException = RuntimeException
#method(toUiStatements- $attribute $var )
...
#end
#method( fromUiStatements- $attribute $var )
...
#end
• Minimal amount for enhancer to write• Easy basics; easy to copy - commercially viable
(4.3) Commercial
• What we're doing is building a framework so that people can add in their own set of controls– JeeWiz: Generic UI Controls Architecture
• e.g. selection by name, or datatype, or style
– JSF Guru: JSF basic; Custom converters etc.– Apache Trinidad: Trinidad controls– Ajax Library: Ajax controls, Javascript Library– VARs/End users: Override with local style
• On the Web today - jeewiz.org
End